add look & feel selector into configuration dialog
[jSite2.git] / src / net / pterodactylus / jsite / gui / SwingInterface.java
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();
                }
        }