enhance configuration dialog with font selection
[jSite2.git] / src / net / pterodactylus / jsite / gui / ConfigurationDialog.java
index a64e845..4444868 100644 (file)
@@ -1,10 +1,14 @@
 /**
  * © 2008 INA Service GmbH
  */
+
 package net.pterodactylus.jsite.gui;
 
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
 import java.awt.event.ActionEvent;
 
 import javax.swing.BorderFactory;
@@ -23,7 +27,7 @@ import net.pterodactylus.util.swing.SwingUtils;
 
 /**
  * The configuration dialog.
- * 
+ *
  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
  * @version $Id$
  */
@@ -38,15 +42,33 @@ public class ConfigurationDialog extends JDialog implements I18nable {
        /** The “beautify GUI” action. */
        private I18nAction beautifyAction;
 
+       /** The “use custom control font” action. */
+       private I18nAction useCustomControlFontAction;
+
+       /** The “use custom user font” action. */
+       private I18nAction useCustomUserFontAction;
+
        /** The “beautify” checkbox. */
        private JCheckBox beautifyCheckBox;
 
+       /** The “use custom” fonts checkbox. */
+       private JCheckBox useCustomControlFontCheckBox;
+
+       /** The control font list. */
+       private FontComboBox controlFontList;
+
+       /** The checkbox for “use same as control font”. */
+       private JCheckBox useCustomUserFontCheckBox;
+
+       /** The user font list. */
+       private FontComboBox userFontList;
+
        /** Whether the dialog was cancelled. */
        private boolean cancelled;
 
        /**
         * Creates a new configuration dialog.
-        * 
+        *
         * @param swingInterface
         *            The Swing interface
         */
@@ -66,7 +88,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
        /**
         * Returns whether the dialog was cancelled or confirmed. If the dialog was
         * cancelled, no further processing should be done.
-        * 
+        *
         * @return <code>true</code> if the dialog was cancelled,
         *         <code>false</code> otherwise
         */
@@ -78,7 +100,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
         * Returns whether the “beautify” checkbox has been selected. The result of
         * this method should not be used if {@link #wasCancelled()} returned
         * <code>true</code>!
-        * 
+        *
         * @return <code>true</code> if the checkbox was selected,
         *         <code>false</code> otherwise
         */
@@ -88,12 +110,62 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Sets the state of the “beautify” checkbox.
-        * 
+        *
         * @param beautify
         *            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());
+       }
+
+       /**
+        * Returns the font for the controls.
+        *
+        * @return The control font, or <code>null</code> if no custom control
+        *         font is to be used
+        */
+       public String getControlFont() {
+               return (String) ((beautifyCheckBox.isSelected() && useCustomControlFontCheckBox.isSelected()) ? controlFontList.getSelectedItem() : null);
+       }
+
+       /**
+        * Sets the font for the controls.
+        *
+        * @param controlFont
+        *            The control font, or <code>null</code> if no custom control
+        *            font is to be used
+        */
+       public void setControlFont(String controlFont) {
+               useCustomControlFontCheckBox.setSelected(controlFont != null);
+               controlFontList.setEnabled(beautifyCheckBox.isSelected() && (controlFont != null));
+               controlFontList.setSelectedItem(controlFont);
+       }
+
+       /**
+        * Returns the font for user input.
+        *
+        * @return The font for user input, or <code>null</code> if no custom user
+        *         input font is to be used
+        */
+       public String getUserFont() {
+               return (String) ((beautifyCheckBox.isSelected() && useCustomUserFontCheckBox.isSelected()) ? userFontList.getSelectedItem() : null);
+       }
+
+       /**
+        * Sets the font for user input.
+        *
+        * @param userFont
+        *            The font for user input, or <code>null</code> if no custom
+        *            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);
        }
 
        //
@@ -105,6 +177,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
         */
        private void initActions() {
                okayAction = new I18nAction("general.button.okay") {
+
                        /**
                         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
                         */
@@ -114,6 +187,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
                        }
                };
                cancelAction = new I18nAction("general.button.cancel") {
+
                        /**
                         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
                         */
@@ -123,11 +197,33 @@ public class ConfigurationDialog extends JDialog implements I18nable {
                        }
                };
                beautifyAction = new I18nAction("configurationDialog.page.interface.item.beautify") {
+
                        /**
                         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
                         */
+                       @SuppressWarnings("synthetic-access")
                        public void actionPerformed(ActionEvent actionEvent) {
-                               /* don't do anything. */
+                               setBeautify(beautifyCheckBox.isSelected());
+                       }
+               };
+               useCustomControlFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomControlFont") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent e) {
+                               controlFontList.setEnabled(useCustomControlFontCheckBox.isSelected());
+                       }
+               };
+               useCustomUserFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomUserFont") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent e) {
+                               userFontList.setEnabled(useCustomUserFontCheckBox.isSelected());
                        }
                };
        }
@@ -158,15 +254,29 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Creates the panel for the interface configuration.
-        * 
+        *
         * @return The interface configuration panel
         */
        private JComponent createInterfaceConfig() {
-               JPanel interfaceConfigPanel = new JPanel(new BorderLayout(12, 12));
+               JPanel interfaceConfigPanel = new JPanel(new GridBagLayout());
                interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
 
                beautifyCheckBox = new JCheckBox(beautifyAction);
-               interfaceConfigPanel.add(beautifyCheckBox, BorderLayout.PAGE_START);
+               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));
+
+               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));
+
+               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));
+
+               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));
+
+               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));
+
+               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));
 
                return interfaceConfigPanel;
        }