add more status notifications to core listener
[jSite2.git] / src / net / pterodactylus / jsite / gui / SwingInterface.java
index d00ebe1..e022cf1 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$
  */
@@ -105,12 +105,21 @@ public class SwingInterface implements CoreListener {
        // CONFIGURATION
        //
 
-       /** Whether to beautify the GUI. */
-       private boolean beautify;
+       /** The advanced mode. */
+       private boolean advancedMode;
+
+       /** 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
@@ -121,10 +130,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();
@@ -136,7 +149,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the core that is controlled by the Swing interface.
-        * 
+        *
         * @return The core
         */
        Core getCore() {
@@ -145,7 +158,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the main window of the Swing interface.
-        * 
+        *
         * @return The main window
         */
        MainWindow getMainWindow() {
@@ -154,7 +167,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “configure” action.
-        * 
+        *
         * @return The “configure” action
         */
        I18nAction getConfigureAction() {
@@ -163,7 +176,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “import config” action.
-        * 
+        *
         * @return The “import config” action
         */
        I18nAction getImportConfigAction() {
@@ -172,7 +185,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “quit” action.
-        * 
+        *
         * @return The “quit” action
         */
        I18nAction getQuitAction() {
@@ -181,7 +194,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “manage nodes” action.
-        * 
+        *
         * @return The “manage nodes” action
         */
        I18nAction getManageNodesAction() {
@@ -190,7 +203,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “connect to node” action.
-        * 
+        *
         * @return The “connect to node” action
         */
        I18nAction getNodeConnectAction() {
@@ -199,7 +212,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “disconnect from node” action.
-        * 
+        *
         * @return The “disconnect from node” action
         */
        I18nAction getNodeDisconnectAction() {
@@ -208,7 +221,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns all language actions.
-        * 
+        *
         * @return All language actions
         */
        List<I18nAction> getLanguageActions() {
@@ -217,7 +230,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “about” action.
-        * 
+        *
         * @return The “about” action
         */
        I18nAction getHelpAboutAction() {
@@ -226,7 +239,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “add project” action.
-        * 
+        *
         * @return The “add project” action
         */
        I18nAction getAddProjectAction() {
@@ -235,7 +248,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “clone project” action.
-        * 
+        *
         * @return The “clone project” action
         */
        I18nAction getCloneProjectAction() {
@@ -244,7 +257,7 @@ public class SwingInterface implements CoreListener {
 
        /**
         * Returns the “delete project” action.
-        * 
+        *
         * @return The “delete project” action
         */
        I18nAction getDeleteProjectAction() {
@@ -275,7 +288,7 @@ public class SwingInterface implements CoreListener {
         */
        private void loadConfig() {
                /* initialize default stuff. */
-               beautify = false;
+               antialias = false;
                /* now read config. */
                File configFile = new File(configDirectory, "swing-interface.properties");
                if (!configFile.exists() || !configFile.canRead() || !configFile.isFile()) {
@@ -292,8 +305,20 @@ public class SwingInterface implements CoreListener {
                } finally {
                        Closer.close(configInputStream);
                }
-               if (configProperties.containsKey("beautify")) {
-                       beautify = Boolean.valueOf(configProperties.getProperty("beautify"));
+               if (configProperties.containsKey("advancedMode")) {
+                       advancedMode = Boolean.valueOf(configProperties.getProperty("advancedMode"));
+               }
+               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");
+               }
+               if (configProperties.containsKey("language")) {
+                       I18n.setLocale(new Locale(configProperties.getProperty("language")));
                }
        }
 
@@ -314,7 +339,15 @@ 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("advancedMode", String.valueOf(advancedMode));
+               configProperties.setProperty("antialias", String.valueOf(antialias));
+               if (controlFont != null) {
+                       configProperties.setProperty("controlFont", controlFont);
+               }
+               if (userFont != null) {
+                       configProperties.setProperty("userFont", userFont);
+               }
+               configProperties.setProperty("language", I18n.getLocale().getLanguage());
                FileOutputStream configOutputStream = null;
                try {
                        configOutputStream = new FileOutputStream(configFile);
@@ -462,10 +495,19 @@ public class SwingInterface implements CoreListener {
         * Shows the configuration dialog.
         */
        private void configure() {
-               configurationDialog.setBeautify(beautify);
+               configurationDialog.setAdvancedMode(advancedMode);
+               configurationDialog.setAntialias(antialias);
+               configurationDialog.setControlFont(controlFont);
+               configurationDialog.setUserFont(userFont);
                configurationDialog.setVisible(true);
                if (!configurationDialog.wasCancelled()) {
-                       beautify = configurationDialog.getBeautify();
+                       advancedMode = configurationDialog.isAdvancedMode();
+                       if (!advancedMode && (nodeList.size() > 1)) {
+                               JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.warning.multipleNodesNotAdvancedMode.message"), I18n.get("mainWindow.warning.multipleNodesNotAdvancedMode.title"), JOptionPane.WARNING_MESSAGE);
+                       }
+                       antialias = configurationDialog.isAntialias();
+                       controlFont = configurationDialog.getControlFont();
+                       userFont = configurationDialog.getUserFont();
                        saveConfig();
                }
        }
@@ -474,6 +516,7 @@ public class SwingInterface implements CoreListener {
         * Imports old jSite configuration.
         */
        private void importConfig() {
+               /* TODO */
        }
 
        /**
@@ -488,27 +531,51 @@ public class SwingInterface implements CoreListener {
         * Pops up the “manage nodes” dialog.
         */
        private void manageNodes() {
-               manageNodesDialog.setNodeList(nodeList);
-               manageNodesDialog.setVisible(true);
-               nodeList = manageNodesDialog.getNodeList();
+               if (advancedMode) {
+                       manageNodesDialog.setNodeList(nodeList);
+                       manageNodesDialog.setVisible(true);
+                       nodeList = manageNodesDialog.getNodeList();
+               } else {
+                       if (nodeList.isEmpty()) {
+                               Node newNode = new Node();
+                               newNode.setName(I18n.get("general.defaultNode.name"));
+                               newNode.setHostname("localhost");
+                               newNode.setPort(9481);
+                               nodeList.add(newNode);
+                       }
+                       Node firstNode = nodeList.get(0);
+                       EditNodeDialog editNodeDialog = manageNodesDialog.getEditNodeDialog();
+                       editNodeDialog.setNodeName(firstNode.getName());
+                       editNodeDialog.setNodeHostname(firstNode.getHostname());
+                       editNodeDialog.setNodePort(firstNode.getPort());
+                       editNodeDialog.setVisible(true);
+                       if (!editNodeDialog.wasCancelled()) {
+                               firstNode.setName(editNodeDialog.getNodeName());
+                               firstNode.setHostname(editNodeDialog.getNodeHostname());
+                               firstNode.setPort(editNodeDialog.getNodePort());
+                               /* TODO - give to core. */
+                       }
+               }
        }
 
        /**
         * Connects to the node.
         */
        private void nodeConnect() {
+               /* TODO */
        }
 
        /**
         * Disconnects from the node.
         */
        private void nodeDisconnect() {
+               /* TODO */
        }
 
        /**
         * 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
@@ -541,51 +608,113 @@ public class SwingInterface implements CoreListener {
         * Clones a project.
         */
        private void cloneProject() {
+               /* TODO */
        }
 
        /**
         * Deletes a project.
         */
        private void deleteProject() {
+               /* TODO */
        }
 
        //
        // INTERFACE CoreListener
        //
 
+
+       /**
+        * {@inheritDoc}
+        */
+       public void loadingProjectsDone(String directory) {
+               mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.projectLoadingDone"));
+       }
+
        /**
         * {@inheritDoc}
         */
-       public void loadingProjectsFailed(String directory) {
+       public void loadingProjectsFailed(String directory, Throwable throwable) {
                JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.projectLoadingFailed.message", directory), I18n.get("mainWindow.error.projectLoadingFailed.title"), JOptionPane.ERROR_MESSAGE);
        }
 
        /**
         * {@inheritDoc}
         */
+       public void savingProjectsDone(String directory) {
+               mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.projectSavingDone"));
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void savingProjectsFailed(String directory, Throwable throwabled) {
+               /* TODO */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void loadingNodesDone(String directory) {
+               mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.loadingNodesDone"));
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void loadingNodesFailed(String directory, Throwable throwable) {
+               /* TODO */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void savingNodesDone(String directory) {
+               mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.savingNodesDone"));
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void savingNodesFailed(String directory, Throwable throwable) {
+               /* TODO */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public void coreLoaded() {
                this.nodeList = core.getNodes();
                manageNodesDialog.setNodeList(nodeList);
                mainWindow.setVisible(true);
-               mainWindow.setStatusBarText("Core loaded.");
+               mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.coreLoaded"));
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public void coreStopped() {
+               mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.coreStopped"));
        }
 
        /**
         * {@inheritDoc}
         */
        public void nodeConnected(Node node) {
+               /* TODO */
        }
 
        /**
         * {@inheritDoc}
         */
        public void nodeConnecting(Node node) {
+               /* TODO */
        }
 
        /**
         * {@inheritDoc}
         */
        public void nodeDisconnected(Node node) {
+               /* TODO */
        }
 
 }