add look & feel selector into configuration dialog
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 8 May 2008 22:33:35 +0000 (22:33 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 8 May 2008 22:33:35 +0000 (22:33 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@793 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/gui/ConfigurationDialog.java
src/net/pterodactylus/jsite/gui/SwingInterface.java
src/net/pterodactylus/jsite/i18n/jSite.properties
src/net/pterodactylus/jsite/i18n/jSite_de.properties

index a5a6c88..00c0776 100644 (file)
@@ -11,17 +11,23 @@ import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
 import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.swing.BorderFactory;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
 import javax.swing.JComponent;
 import javax.swing.JDialog;
 import javax.swing.JPanel;
 import javax.swing.JSpinner;
 import javax.swing.JTabbedPane;
+import javax.swing.LookAndFeel;
 import javax.swing.SpinnerNumberModel;
 import javax.swing.SwingConstants;
+import javax.swing.UIManager;
+import javax.swing.UIManager.LookAndFeelInfo;
 
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.I18nable;
@@ -31,7 +37,7 @@ import net.pterodactylus.util.swing.SwingUtils;
 
 /**
  * The configuration dialog.
- *
+ * 
  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
  * @version $Id$
  */
@@ -58,6 +64,9 @@ public class ConfigurationDialog extends JDialog implements I18nable {
        /** The “use custom user font” action. */
        private I18nAction useCustomUserFontAction;
 
+       /** The “use custom L&F” action. */
+       private I18nAction useCustomLAFAction;
+
        /** The “restart required” warning label. */
        private I18nLabel restartRequiredLabel;
 
@@ -82,12 +91,18 @@ public class ConfigurationDialog extends JDialog implements I18nable {
        /** The user font size spinner. */
        private JSpinner userFontSizeSpinner;
 
+       /** The checkbox for custom L&F. */
+       private JCheckBox useCustomLAFCheckBox;
+
+       /** The combo box for the L&Fs. */
+       private JComboBox customLAFComboBox;
+
        /** Whether the dialog was cancelled. */
        private boolean cancelled;
 
        /**
         * Creates a new configuration dialog.
-        *
+        * 
         * @param swingInterface
         *            The Swing interface
         */
@@ -107,7 +122,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
         */
@@ -117,7 +132,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Returns whether the advanced mode is selected.
-        *
+        * 
         * @return <code>true</code> if the advanced mode is selected,
         *         <code>false</code> otherwise
         */
@@ -127,7 +142,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Sets whether the advanced mode is selected.
-        *
+        * 
         * @param advancedMode
         *            <code>true</code> if the advanced mode is selected,
         *            <code>false</code> otherwise
@@ -140,7 +155,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
         */
@@ -150,7 +165,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Sets the state of the “antialias” checkbox.
-        *
+        * 
         * @param antialias
         *            The state of the checkbox
         */
@@ -160,7 +175,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Returns the font for the controls.
-        *
+        * 
         * @return The control font, or <code>null</code> if no custom control
         *         font is to be used
         */
@@ -170,7 +185,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Sets the font for the controls.
-        *
+        * 
         * @param controlFont
         *            The control font, or <code>null</code> if no custom control
         *            font is to be used
@@ -192,7 +207,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * 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
         */
@@ -202,7 +217,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * 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
@@ -222,6 +237,43 @@ public class ConfigurationDialog extends JDialog implements I18nable {
                }
        }
 
+       /**
+        * Returns the class name of the selected look and feel, if a custom look
+        * and feel is selected.
+        * 
+        * @return The class name of the look and feel to load, or <code>null</code>
+        *         if no special look and feel should be used
+        */
+       public String getLookAndFeel() {
+               if (!useCustomLAFCheckBox.isSelected()) {
+                       return null;
+               }
+               return ((LookAndFeelWrapper) customLAFComboBox.getSelectedItem()).getClassName();
+       }
+
+       /**
+        * Sets the given look and feel.
+        * 
+        * @param lookAndFeel
+        *            The class name of the look and feel, or <code>null</code> to
+        *            not select a custom look and feel
+        */
+       public void setLookAndFeel(String lookAndFeel) {
+               useCustomLAFCheckBox.setSelected(false);
+               customLAFComboBox.setEnabled(false);
+               if (lookAndFeel == null) {
+                       return;
+               }
+               for (int lookAndFeelIndex = 0; lookAndFeelIndex < customLAFComboBox.getItemCount(); lookAndFeelIndex++) {
+                       LookAndFeelWrapper lookAndFeelWrapper = (LookAndFeelWrapper) customLAFComboBox.getItemAt(lookAndFeelIndex);
+                       if (lookAndFeelWrapper.getClassName().equals(lookAndFeel)) {
+                               customLAFComboBox.setSelectedIndex(lookAndFeelIndex);
+                               useCustomLAFCheckBox.setSelected(true);
+                               break;
+                       }
+               }
+       }
+
        //
        // PRIVATE METHODS
        //
@@ -292,6 +344,16 @@ public class ConfigurationDialog extends JDialog implements I18nable {
                                userFontSizeSpinner.setEnabled(selected);
                        }
                };
+               useCustomLAFAction = new I18nAction("configurationDialog.page.interfaceTweaks.item.useCustomLAF") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent e) {
+                               customLAFComboBox.setEnabled(useCustomLAFCheckBox.isSelected());
+                       }
+               };
        }
 
        /**
@@ -323,7 +385,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Creates the interface configuration panel.
-        *
+        * 
         * @return The interface configuration panel
         */
        private JComponent createInterfaceConfig() {
@@ -339,7 +401,7 @@ public class ConfigurationDialog extends JDialog implements I18nable {
 
        /**
         * Creates the panel for the interface tweaks configuration.
-        *
+        * 
         * @return The interface tweaks configuration panel
         */
        private JComponent createInterfaceTweaksConfig() {
@@ -370,7 +432,18 @@ public class ConfigurationDialog extends JDialog implements I18nable {
                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));
 
-               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));
+               useCustomLAFCheckBox = new JCheckBox(useCustomLAFAction);
+               interfaceTweaksConfigPanel.add(useCustomLAFCheckBox, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0));
+
+               LookAndFeelInfo[] lookAndFeelInfos = UIManager.getInstalledLookAndFeels();
+               List<LookAndFeelWrapper> lookAndFeelWrappers = new ArrayList<LookAndFeelWrapper>();
+               for (LookAndFeelInfo lookAndFeelInfo: lookAndFeelInfos) {
+                       lookAndFeelWrappers.add(new LookAndFeelWrapper(lookAndFeelInfo.getClassName(), lookAndFeelInfo.getName()));
+               }
+               customLAFComboBox = new JComboBox(lookAndFeelWrappers.toArray(new LookAndFeelWrapper[0]));
+               interfaceTweaksConfigPanel.add(customLAFComboBox, new GridBagConstraints(1, 4, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
+
+               interfaceTweaksConfigPanel.add(new JPanel(), new GridBagConstraints(0, 5, 3, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
 
                return interfaceTweaksConfigPanel;
        }
@@ -412,4 +485,51 @@ public class ConfigurationDialog extends JDialog implements I18nable {
                SwingUtils.repackCentered(this);
        }
 
+       /**
+        * Wrapper around class name and name of a {@link LookAndFeel}.
+        * 
+        * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+        * @version $Id$
+        */
+       private static class LookAndFeelWrapper {
+
+               /** The class name of the look and feel. */
+               private final String className;
+
+               /** The name of a look and feel. */
+               private final String lookAndFeelName;
+
+               /**
+                * Creates a new wrapper around the given class name and name of a look
+                * and feel.
+                * 
+                * @param className
+                *            The class name of the look and feel
+                * @param lookAndFeelName
+                *            The name of the look and feel
+                */
+               public LookAndFeelWrapper(String className, String lookAndFeelName) {
+                       this.className = className;
+                       this.lookAndFeelName = lookAndFeelName;
+               }
+
+               /**
+                * Returns the class name of the look and feel.
+                * 
+                * @return The class name of the look and feel
+                */
+               public String getClassName() {
+                       return className;
+               }
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public String toString() {
+                       return lookAndFeelName;
+               }
+
+       }
+
 }
index b2c7c92..dff6f3a 100644 (file)
@@ -40,6 +40,8 @@ import java.util.logging.Logger;
 import javax.swing.AbstractAction;
 import javax.swing.Action;
 import javax.swing.JOptionPane;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
 
 import net.pterodactylus.jsite.core.Core;
 import net.pterodactylus.jsite.core.CoreListener;
@@ -156,6 +158,9 @@ public class SwingInterface implements CoreListener, LoggingListener {
        /** The user font. */
        private String userFont;
 
+       /** The class name of the look and feel. */
+       private String lookAndFeel;
+
        /**
         * Creates a new swing interface.
         * 
@@ -169,6 +174,19 @@ public class SwingInterface implements CoreListener, LoggingListener {
                this.configDirectory = configDirectory;
                I18n.setLocale(Locale.ENGLISH);
                loadConfig();
+               if (lookAndFeel != null) {
+                       try {
+                               UIManager.setLookAndFeel(lookAndFeel);
+                       } catch (ClassNotFoundException cnfe1) {
+                               logger.log(Level.WARNING, "could not load look and feel", cnfe1);
+                       } catch (InstantiationException ie1) {
+                               logger.log(Level.WARNING, "could not load look and feel", ie1);
+                       } catch (IllegalAccessException iae1) {
+                               logger.log(Level.WARNING, "could not load look and feel", iae1);
+                       } catch (UnsupportedLookAndFeelException ulafe1) {
+                               logger.log(Level.WARNING, "could not load look and feel", ulafe1);
+                       }
+               }
                if (antialias) {
                        System.setProperty("swing.aatext", "true");
                }
@@ -380,6 +398,9 @@ public class SwingInterface implements CoreListener, LoggingListener {
                if (configProperties.containsKey("userFont")) {
                        userFont = configProperties.getProperty("userFont");
                }
+               if (configProperties.containsKey("lookAndFeel")) {
+                       lookAndFeel = configProperties.getProperty("lookAndFeel");
+               }
                if (configProperties.containsKey("language")) {
                        I18n.setLocale(new Locale(configProperties.getProperty("language")));
                }
@@ -410,6 +431,9 @@ public class SwingInterface implements CoreListener, LoggingListener {
                if (userFont != null) {
                        configProperties.setProperty("userFont", userFont);
                }
+               if (lookAndFeel != null) {
+                       configProperties.setProperty("lookAndFeel", lookAndFeel);
+               }
                configProperties.setProperty("language", I18n.getLocale().getLanguage());
                FileOutputStream configOutputStream = null;
                try {
@@ -571,6 +595,7 @@ public class SwingInterface implements CoreListener, LoggingListener {
                configurationDialog.setAntialias(antialias);
                configurationDialog.setControlFont(controlFont);
                configurationDialog.setUserFont(userFont);
+               configurationDialog.setLookAndFeel(lookAndFeel);
                configurationDialog.setVisible(true);
                if (!configurationDialog.wasCancelled()) {
                        advancedMode = configurationDialog.isAdvancedMode();
@@ -581,6 +606,7 @@ public class SwingInterface implements CoreListener, LoggingListener {
                        antialias = configurationDialog.isAntialias();
                        controlFont = configurationDialog.getControlFont();
                        userFont = configurationDialog.getUserFont();
+                       lookAndFeel = configurationDialog.getLookAndFeel();
                        saveConfig();
                }
        }
index cb4c5b8..178988f 100644 (file)
@@ -263,6 +263,12 @@ configurationDialog.page.interfaceTweaks.item.useCustomUserFont.accelerator: Alt
 configurationDialog.page.interfaceTweaks.item.useCustomUserFont.shortDescription: Use custom text font for the GUI
 configurationDialog.page.interfaceTweaks.item.useCustomUserFont.longDescription: Use custom text font for the GUI
 
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.name: Use custom Look & Feel
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.mnemonic: VK_L
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.accelerator: Alt-VK_L
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.shortDescription: Use a custom Look & Feel
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.longDescription: Use a custom Look & Feel
+
 #
 # the log window
 #
index aaf486b..ea21938 100644 (file)
@@ -263,6 +263,12 @@ configurationDialog.page.interfaceTweaks.item.useCustomUserFont.accelerator: Alt
 configurationDialog.page.interfaceTweaks.item.useCustomUserFont.shortDescription: Eine andere Schriftart f\u00fcr Texteingabefelder benutzen
 configurationDialog.page.interfaceTweaks.item.useCustomUserFont.longDescription: Eine andere Schriftart f\u00fcr Texteingabefelder benutzen
 
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.name: Anderes Look & Feel benutzen
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.mnemonic: VK_L
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.accelerator: Alt-VK_L
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.shortDescription: Ein anderes Look & Feel benutzen
+configurationDialog.page.interfaceTweaks.item.useCustomLAF.longDescription: Ein anderes Look & Feel benutzen
+
 #
 # the log window
 #