rename configuration tab
[jSite2.git] / src / net / pterodactylus / jsite / gui / SwingInterface.java
index ecd8612..b5d651b 100644 (file)
@@ -34,13 +34,14 @@ import javax.swing.JOptionPane;
 import net.pterodactylus.jsite.core.Core;
 import net.pterodactylus.jsite.core.CoreListener;
 import net.pterodactylus.jsite.core.Node;
+import net.pterodactylus.jsite.core.Project;
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.gui.I18nAction;
 import net.pterodactylus.util.io.Closer;
 
 /**
- * TODO
- * 
+ * The Swing user interface.
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  * @version $Id$
  */
@@ -85,6 +86,12 @@ public class SwingInterface implements CoreListener {
        /** The “add project” action. */
        private I18nAction addProjectAction;
 
+       /** The “clone project” action. */
+       private I18nAction cloneProjectAction;
+
+       /** The “delete project” action. */
+       private I18nAction deleteProjectAction;
+
        /** The “about” dialog. */
        private AboutDialog aboutDialog;
 
@@ -98,12 +105,18 @@ public class SwingInterface implements CoreListener {
        // CONFIGURATION
        //
 
-       /** Whether to beautify the GUI. */
-       private boolean beautify;
+       /** Whether to antialias the GUI. */
+       private boolean antialias;
+
+       /** 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
@@ -114,10 +127,14 @@ public class SwingInterface implements CoreListener {
                this.configDirectory = configDirectory;
                I18n.setLocale(Locale.ENGLISH);
                loadConfig();
-               if (beautify) {
+               if (antialias) {
                        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();
@@ -129,7 +146,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the core that is controlled by the Swing interface.
-        * 
+        *
         * @return The core
         */
        Core getCore() {
@@ -138,7 +155,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the main window of the Swing interface.
-        * 
+        *
         * @return The main window
         */
        MainWindow getMainWindow() {
@@ -147,7 +164,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “configure” action.
-        * 
+        *
         * @return The “configure” action
         */
        I18nAction getConfigureAction() {
@@ -156,7 +173,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “import config” action.
-        * 
+        *
         * @return The “import config” action
         */
        I18nAction getImportConfigAction() {
@@ -165,7 +182,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “quit” action.
-        * 
+        *
         * @return The “quit” action
         */
        I18nAction getQuitAction() {
@@ -174,7 +191,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “manage nodes” action.
-        * 
+        *
         * @return The “manage nodes” action
         */
        I18nAction getManageNodesAction() {
@@ -183,7 +200,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “connect to node” action.
-        * 
+        *
         * @return The “connect to node” action
         */
        I18nAction getNodeConnectAction() {
@@ -192,7 +209,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “disconnect from node” action.
-        * 
+        *
         * @return The “disconnect from node” action
         */
        I18nAction getNodeDisconnectAction() {
@@ -201,7 +218,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns all language actions.
-        * 
+        *
         * @return All language actions
         */
        List<I18nAction> getLanguageActions() {
@@ -210,7 +227,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “about” action.
-        * 
+        *
         * @return The “about” action
         */
        I18nAction getHelpAboutAction() {
@@ -219,13 +236,31 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “add project” action.
-        * 
+        *
         * @return The “add project” action
         */
        I18nAction getAddProjectAction() {
                return addProjectAction;
        }
 
+       /**
+        * Returns the “clone project” action.
+        *
+        * @return The “clone project” action
+        */
+       I18nAction getCloneProjectAction() {
+               return cloneProjectAction;
+       }
+
+       /**
+        * Returns the “delete project” action.
+        *
+        * @return The “delete project” action
+        */
+       I18nAction getDeleteProjectAction() {
+               return deleteProjectAction;
+       }
+
        //
        // ACTIONS
        //
@@ -250,9 +285,8 @@ public class SwingInterface implements CoreListener {
         */
        private void loadConfig() {
                /* initialize default stuff. */
-               beautify = false;
+               antialias = false;
                /* now read config. */
-               System.out.println("configDirectory: “" + configDirectory + "”");
                File configFile = new File(configDirectory, "swing-interface.properties");
                if (!configFile.exists() || !configFile.canRead() || !configFile.isFile()) {
                        System.err.println("could not find “" + configFile.getAbsolutePath() + "”!");
@@ -268,8 +302,14 @@ public class SwingInterface implements CoreListener {
                } finally {
                        Closer.close(configInputStream);
                }
-               if (configProperties.containsKey("beautify")) {
-                       beautify = Boolean.valueOf(configProperties.getProperty("beautify"));
+               if (configProperties.containsKey("antialias")) {
+                       antialias = Boolean.valueOf(configProperties.getProperty("antialias"));
+               }
+               if (configProperties.containsKey("controlFont")) {
+                       controlFont = configProperties.getProperty("controlFont");
+               }
+               if (configProperties.containsKey("userFont")) {
+                       userFont = configProperties.getProperty("userFont");
                }
        }
 
@@ -290,7 +330,13 @@ public class SwingInterface implements CoreListener {
                }
                File configFile = new File(configDirectory, "swing-interface.properties");
                Properties configProperties = new Properties();
-               configProperties.setProperty("beautify", String.valueOf(beautify));
+               configProperties.setProperty("antialias", String.valueOf(antialias));
+               if (controlFont != null) {
+                       configProperties.setProperty("controlFont", controlFont);
+               }
+               if (userFont != null) {
+                       configProperties.setProperty("userFont", userFont);
+               }
                FileOutputStream configOutputStream = null;
                try {
                        configOutputStream = new FileOutputStream(configFile);
@@ -399,6 +445,26 @@ public class SwingInterface implements CoreListener {
                                addProject();
                        }
                };
+               cloneProjectAction = new I18nAction("mainWindow.button.cloneProject") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               cloneProject();
+                       }
+               };
+               deleteProjectAction = new I18nAction("mainWindow.button.deleteProject") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               deleteProject();
+                       }
+               };
        }
 
        /**
@@ -418,10 +484,14 @@ public class SwingInterface implements CoreListener {
         * Shows the configuration dialog.
         */
        private void configure() {
-               configurationDialog.setBeautify(beautify);
+               configurationDialog.setAntialias(antialias);
+               configurationDialog.setControlFont(controlFont);
+               configurationDialog.setUserFont(userFont);
                configurationDialog.setVisible(true);
                if (!configurationDialog.wasCancelled()) {
-                       beautify = configurationDialog.getBeautify();
+                       antialias = configurationDialog.isAntialias();
+                       controlFont = configurationDialog.getControlFont();
+                       userFont = configurationDialog.getUserFont();
                        saveConfig();
                }
        }
@@ -464,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
@@ -488,6 +558,21 @@ public class SwingInterface implements CoreListener {
         * Adds a project.
         */
        private void addProject() {
+               Project project = new Project();
+               project.setName("New Project");
+               project.setDescription("");
+       }
+
+       /**
+        * Clones a project.
+        */
+       private void cloneProject() {
+       }
+
+       /**
+        * Deletes a project.
+        */
+       private void deleteProject() {
        }
 
        //