enhance configuration dialog with font selection
[jSite2.git] / src / net / pterodactylus / jsite / gui / SwingInterface.java
index d00ebe1..09205bc 100644 (file)
@@ -41,7 +41,7 @@ import net.pterodactylus.util.io.Closer;
 
 /**
  * The Swing user interface.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  * @version $Id$
  */
@@ -108,9 +108,15 @@ public class SwingInterface implements CoreListener {
        /** Whether to beautify the GUI. */
        private boolean beautify;
 
+       /** The control font. */
+       private String controlFont;
+
+       /** The user font. */
+       private String userFont;
+
        /**
         * Creates a new swing interface.
-        * 
+        *
         * @param core
         *            The core to operate on
         * @param configDirectory
@@ -123,8 +129,12 @@ public class SwingInterface implements CoreListener {
                loadConfig();
                if (beautify) {
                        System.setProperty("swing.aatext", "true");
-                       System.setProperty("swing.plaf.metal.controlFont", "Tahoma");
-                       System.setProperty("swing.plaf.metal.userFont", "Tahoma");
+                       if (controlFont != null) {
+                               System.setProperty("swing.plaf.metal.controlFont", controlFont);
+                       }
+                       if (userFont != null) {
+                               System.setProperty("swing.plaf.metal.userFont", userFont);
+                       }
                }
                initActions();
                initDialogs();
@@ -136,7 +146,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the core that is controlled by the Swing interface.
-        * 
+        *
         * @return The core
         */
        Core getCore() {
@@ -145,7 +155,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the main window of the Swing interface.
-        * 
+        *
         * @return The main window
         */
        MainWindow getMainWindow() {
@@ -154,7 +164,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “configure” action.
-        * 
+        *
         * @return The “configure” action
         */
        I18nAction getConfigureAction() {
@@ -163,7 +173,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “import config” action.
-        * 
+        *
         * @return The “import config” action
         */
        I18nAction getImportConfigAction() {
@@ -172,7 +182,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “quit” action.
-        * 
+        *
         * @return The “quit” action
         */
        I18nAction getQuitAction() {
@@ -181,7 +191,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “manage nodes” action.
-        * 
+        *
         * @return The “manage nodes” action
         */
        I18nAction getManageNodesAction() {
@@ -190,7 +200,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “connect to node” action.
-        * 
+        *
         * @return The “connect to node” action
         */
        I18nAction getNodeConnectAction() {
@@ -199,7 +209,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “disconnect from node” action.
-        * 
+        *
         * @return The “disconnect from node” action
         */
        I18nAction getNodeDisconnectAction() {
@@ -208,7 +218,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns all language actions.
-        * 
+        *
         * @return All language actions
         */
        List<I18nAction> getLanguageActions() {
@@ -217,7 +227,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “about” action.
-        * 
+        *
         * @return The “about” action
         */
        I18nAction getHelpAboutAction() {
@@ -226,7 +236,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “add project” action.
-        * 
+        *
         * @return The “add project” action
         */
        I18nAction getAddProjectAction() {
@@ -235,7 +245,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “clone project” action.
-        * 
+        *
         * @return The “clone project” action
         */
        I18nAction getCloneProjectAction() {
@@ -244,7 +254,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “delete project” action.
-        * 
+        *
         * @return The “delete project” action
         */
        I18nAction getDeleteProjectAction() {
@@ -295,6 +305,12 @@ public class SwingInterface implements CoreListener {
                if (configProperties.containsKey("beautify")) {
                        beautify = Boolean.valueOf(configProperties.getProperty("beautify"));
                }
+               if (configProperties.containsKey("controlFont")) {
+                       controlFont = configProperties.getProperty("controlFont");
+               }
+               if (configProperties.containsKey("userFont")) {
+                       userFont = configProperties.getProperty("userFont");
+               }
        }
 
        /**
@@ -315,6 +331,12 @@ public class SwingInterface implements CoreListener {
                File configFile = new File(configDirectory, "swing-interface.properties");
                Properties configProperties = new Properties();
                configProperties.setProperty("beautify", String.valueOf(beautify));
+               if (controlFont != null) {
+                       configProperties.setProperty("controlFont", controlFont);
+               }
+               if (userFont != null) {
+                       configProperties.setProperty("userFont", userFont);
+               }
                FileOutputStream configOutputStream = null;
                try {
                        configOutputStream = new FileOutputStream(configFile);
@@ -463,9 +485,13 @@ public class SwingInterface implements CoreListener {
         */
        private void configure() {
                configurationDialog.setBeautify(beautify);
+               configurationDialog.setControlFont(controlFont);
+               configurationDialog.setUserFont(userFont);
                configurationDialog.setVisible(true);
                if (!configurationDialog.wasCancelled()) {
                        beautify = configurationDialog.getBeautify();
+                       controlFont = configurationDialog.getControlFont();
+                       userFont = configurationDialog.getUserFont();
                        saveConfig();
                }
        }
@@ -508,7 +534,7 @@ public class SwingInterface implements CoreListener {
        /**
         * Changes the language of the interface. This method also disables the
         * action for the newly set language and enables all others.
-        * 
+        *
         * @param newLocale
         *            The new language
         * @param languageAction