X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FConfigurationDialog.java;h=a5a6c882c3c8ed558c1c5c36a10172eef893f705;hb=238ddd807f329f3bca74572a2be011dd42167f73;hp=4444868a1adef89b64ab6c611b1f75d464b14d97;hpb=08de64294b855fe7abab3b5520be1b151af7f135;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java index 4444868..a5a6c88 100644 --- a/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java +++ b/src/net/pterodactylus/jsite/gui/ConfigurationDialog.java @@ -6,6 +6,7 @@ package net.pterodactylus.jsite.gui; import java.awt.BorderLayout; import java.awt.FlowLayout; +import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -17,12 +18,15 @@ import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JPanel; +import javax.swing.JSpinner; import javax.swing.JTabbedPane; +import javax.swing.SpinnerNumberModel; import javax.swing.SwingConstants; import net.pterodactylus.jsite.i18n.I18n; import net.pterodactylus.jsite.i18n.I18nable; import net.pterodactylus.jsite.i18n.gui.I18nAction; +import net.pterodactylus.jsite.i18n.gui.I18nLabel; import net.pterodactylus.util.swing.SwingUtils; /** @@ -39,8 +43,14 @@ public class ConfigurationDialog extends JDialog implements I18nable { /** The “cancel” action. */ private I18nAction cancelAction; + /** The “advanced mode” action. */ + private I18nAction advancedModeAction; + + /** The “advanced mode” checkbox. */ + private JCheckBox advancedModeCheckBox; + /** The “beautify GUI” action. */ - private I18nAction beautifyAction; + private I18nAction antialiasAction; /** The “use custom control font” action. */ private I18nAction useCustomControlFontAction; @@ -48,8 +58,11 @@ public class ConfigurationDialog extends JDialog implements I18nable { /** The “use custom user font” action. */ private I18nAction useCustomUserFontAction; + /** The “restart required” warning label. */ + private I18nLabel restartRequiredLabel; + /** The “beautify” checkbox. */ - private JCheckBox beautifyCheckBox; + private JCheckBox antialiasCheckBox; /** The “use custom” fonts checkbox. */ private JCheckBox useCustomControlFontCheckBox; @@ -57,12 +70,18 @@ public class ConfigurationDialog extends JDialog implements I18nable { /** The control font list. */ private FontComboBox controlFontList; + /** The control font size spinner. */ + private JSpinner controlFontSizeSpinner; + /** The checkbox for “use same as control font”. */ private JCheckBox useCustomUserFontCheckBox; /** The user font list. */ private FontComboBox userFontList; + /** The user font size spinner. */ + private JSpinner userFontSizeSpinner; + /** Whether the dialog was cancelled. */ private boolean cancelled; @@ -97,6 +116,27 @@ public class ConfigurationDialog extends JDialog implements I18nable { } /** + * Returns whether the advanced mode is selected. + * + * @return true if the advanced mode is selected, + * false otherwise + */ + public boolean isAdvancedMode() { + return advancedModeCheckBox.isSelected(); + } + + /** + * Sets whether the advanced mode is selected. + * + * @param advancedMode + * true if the advanced mode is selected, + * false otherwise + */ + public void setAdvancedMode(boolean advancedMode) { + advancedModeCheckBox.setSelected(advancedMode); + } + + /** * Returns whether the “beautify” checkbox has been selected. The result of * this method should not be used if {@link #wasCancelled()} returned * true! @@ -104,22 +144,18 @@ public class ConfigurationDialog extends JDialog implements I18nable { * @return true if the checkbox was selected, * false otherwise */ - public boolean getBeautify() { - return beautifyCheckBox.isSelected(); + public boolean isAntialias() { + return antialiasCheckBox.isSelected(); } /** - * Sets the state of the “beautify” checkbox. + * Sets the state of the “antialias” checkbox. * - * @param beautify + * @param antialias * The state of the checkbox */ - public void setBeautify(boolean beautify) { - beautifyCheckBox.setSelected(beautify); - useCustomControlFontCheckBox.setEnabled(beautify); - controlFontList.setEnabled(beautify && useCustomControlFontCheckBox.isSelected()); - useCustomUserFontCheckBox.setEnabled(beautify); - userFontList.setEnabled(beautify && useCustomUserFontCheckBox.isSelected()); + public void setAntialias(boolean antialias) { + antialiasCheckBox.setSelected(antialias); } /** @@ -129,7 +165,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { * font is to be used */ public String getControlFont() { - return (String) ((beautifyCheckBox.isSelected() && useCustomControlFontCheckBox.isSelected()) ? controlFontList.getSelectedItem() : null); + return useCustomControlFontCheckBox.isSelected() ? controlFontList.getSelectedItem() + "-" + controlFontSizeSpinner.getValue() : null; } /** @@ -140,9 +176,18 @@ public class ConfigurationDialog extends JDialog implements I18nable { * font is to be used */ public void setControlFont(String controlFont) { - useCustomControlFontCheckBox.setSelected(controlFont != null); - controlFontList.setEnabled(beautifyCheckBox.isSelected() && (controlFont != null)); - controlFontList.setSelectedItem(controlFont); + boolean hasControlFont = controlFont != null; + useCustomControlFontCheckBox.setSelected(hasControlFont); + controlFontList.setEnabled(hasControlFont); + controlFontSizeSpinner.setEnabled(hasControlFont); + if (hasControlFont) { + Font font = Font.decode(controlFont); + controlFontSizeSpinner.setValue(font.getSize()); + controlFontList.setSelectedItem(font.getName()); + } else { + controlFontSizeSpinner.setValue(12); + controlFontList.setSelectedItem(null); + } } /** @@ -152,7 +197,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { * input font is to be used */ public String getUserFont() { - return (String) ((beautifyCheckBox.isSelected() && useCustomUserFontCheckBox.isSelected()) ? userFontList.getSelectedItem() : null); + return useCustomUserFontCheckBox.isSelected() ? userFontList.getSelectedItem() + "-" + userFontSizeSpinner.getValue() : null; } /** @@ -163,9 +208,18 @@ public class ConfigurationDialog extends JDialog implements I18nable { * user input font is to be used */ public void setUserFont(String userFont) { - useCustomUserFontCheckBox.setSelected(userFont != null); - userFontList.setEnabled(beautifyCheckBox.isSelected() && (userFont != null)); - userFontList.setSelectedItem(userFont); + boolean hasUserFont = userFont != null; + useCustomUserFontCheckBox.setSelected(hasUserFont); + userFontList.setEnabled(hasUserFont); + userFontSizeSpinner.setEnabled(hasUserFont); + if (hasUserFont) { + Font font = Font.decode(userFont); + userFontSizeSpinner.setValue(font.getSize()); + userFontList.setSelectedItem(font.getName()); + } else { + userFontSizeSpinner.setValue(12); + userFontList.setSelectedItem(null); + } } // @@ -196,34 +250,46 @@ public class ConfigurationDialog extends JDialog implements I18nable { actionCancel(); } }; - beautifyAction = new I18nAction("configurationDialog.page.interface.item.beautify") { + advancedModeAction = new I18nAction("configurationDialog.page.interface.item.advancedMode") { + + /** + * {@inheritDoc} + */ + public void actionPerformed(ActionEvent e) { + /* do nothing. */ + } + }; + antialiasAction = new I18nAction("configurationDialog.page.interfaceTweaks.item.antialias") { /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ - @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { - setBeautify(beautifyCheckBox.isSelected()); + /* do nothing. */ } }; - useCustomControlFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomControlFont") { + useCustomControlFontAction = new I18nAction("configurationDialog.page.interfaceTweaks.item.useCustomControlFont") { /** * {@inheritDoc} */ @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent e) { - controlFontList.setEnabled(useCustomControlFontCheckBox.isSelected()); + boolean selected = useCustomControlFontCheckBox.isSelected(); + controlFontList.setEnabled(selected); + controlFontSizeSpinner.setEnabled(selected); } }; - useCustomUserFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomUserFont") { + useCustomUserFontAction = new I18nAction("configurationDialog.page.interfaceTweaks.item.useCustomUserFont") { /** * {@inheritDoc} */ @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent e) { - userFontList.setEnabled(useCustomUserFontCheckBox.isSelected()); + boolean selected = useCustomUserFontCheckBox.isSelected(); + userFontList.setEnabled(selected); + userFontSizeSpinner.setEnabled(selected); } }; } @@ -239,7 +305,10 @@ public class ConfigurationDialog extends JDialog implements I18nable { contentPane.add(tabbedPane, BorderLayout.CENTER); JComponent interfaceConfig = createInterfaceConfig(); - tabbedPane.add("Swing Interface", interfaceConfig); + tabbedPane.add(I18n.get("configurationDialog.page.interface.name"), interfaceConfig); + + JComponent interfaceTweaksConfig = createInterfaceTweaksConfig(); + tabbedPane.add(I18n.get("configurationDialog.page.interfaceTweaks.name"), interfaceTweaksConfig); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12)); contentPane.add(buttonPanel, BorderLayout.PAGE_END); @@ -253,7 +322,7 @@ public class ConfigurationDialog extends JDialog implements I18nable { } /** - * Creates the panel for the interface configuration. + * Creates the interface configuration panel. * * @return The interface configuration panel */ @@ -261,24 +330,49 @@ public class ConfigurationDialog extends JDialog implements I18nable { JPanel interfaceConfigPanel = new JPanel(new GridBagLayout()); interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); - beautifyCheckBox = new JCheckBox(beautifyAction); - interfaceConfigPanel.add(beautifyCheckBox, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + advancedModeCheckBox = new JCheckBox(advancedModeAction); + interfaceConfigPanel.add(advancedModeCheckBox, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + + interfaceConfigPanel.add(new JPanel(), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + return interfaceConfigPanel; + } + + /** + * Creates the panel for the interface tweaks configuration. + * + * @return The interface tweaks configuration panel + */ + private JComponent createInterfaceTweaksConfig() { + JPanel interfaceTweaksConfigPanel = new JPanel(new GridBagLayout()); + interfaceTweaksConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); + + restartRequiredLabel = new I18nLabel("configurationDialog.page.interfaceTweaks.item.restartRequired"); + interfaceTweaksConfigPanel.add(restartRequiredLabel, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); + + antialiasCheckBox = new JCheckBox(antialiasAction); + interfaceTweaksConfigPanel.add(antialiasCheckBox, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(18, 0, 0, 0), 0, 0)); useCustomControlFontCheckBox = new JCheckBox(useCustomControlFontAction); - interfaceConfigPanel.add(useCustomControlFontCheckBox, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 18, 0, 0), 0, 0)); + interfaceTweaksConfigPanel.add(useCustomControlFontCheckBox, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0)); controlFontList = new FontComboBox(); - interfaceConfigPanel.add(controlFontList, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); + interfaceTweaksConfigPanel.add(controlFontList, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); + + controlFontSizeSpinner = new JSpinner(new SpinnerNumberModel(12, 6, 80, 1)); + interfaceTweaksConfigPanel.add(controlFontSizeSpinner, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); useCustomUserFontCheckBox = new JCheckBox(useCustomUserFontAction); - interfaceConfigPanel.add(useCustomUserFontCheckBox, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0)); + interfaceTweaksConfigPanel.add(useCustomUserFontCheckBox, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0)); userFontList = new FontComboBox(); - interfaceConfigPanel.add(userFontList, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); + interfaceTweaksConfigPanel.add(userFontList, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); - interfaceConfigPanel.add(new JPanel(), new GridBagConstraints(0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + userFontSizeSpinner = new JSpinner(new SpinnerNumberModel(12, 6, 80, 1)); + interfaceTweaksConfigPanel.add(userFontSizeSpinner, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0)); - return interfaceConfigPanel; + interfaceTweaksConfigPanel.add(new JPanel(), new GridBagConstraints(0, 4, 3, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + + return interfaceTweaksConfigPanel; } // @@ -311,7 +405,10 @@ public class ConfigurationDialog extends JDialog implements I18nable { public void updateI18n() { okayAction.updateI18n(); cancelAction.updateI18n(); - beautifyAction.updateI18n(); + restartRequiredLabel.updateI18n(); + antialiasAction.updateI18n(); + useCustomControlFontAction.updateI18n(); + useCustomUserFontAction.updateI18n(); SwingUtils.repackCentered(this); }