remove debug output
[jSite2.git] / src / net / pterodactylus / jsite / gui / SwingInterface.java
index 4a0c97f..e55fffa 100644 (file)
 package net.pterodactylus.jsite.gui;
 
 import java.awt.event.ActionEvent;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 import net.pterodactylus.jsite.core.Core;
 import net.pterodactylus.jsite.core.CoreListener;
 import net.pterodactylus.jsite.core.Node;
+import net.pterodactylus.jsite.i18n.I18n;
 
 /**
  * TODO
@@ -52,6 +55,9 @@ public class SwingInterface implements CoreListener {
        /** The node manager dialog. */
        private ManageNodesDialog manageNodesDialog;
 
+       /** All lanugage menu items. */
+       private List<I18nAction> languageActions = new ArrayList<I18nAction>();
+
        /** The list of all defined nodes. */
        private List<Node> nodeList;
 
@@ -63,6 +69,7 @@ public class SwingInterface implements CoreListener {
         */
        public SwingInterface(Core core) {
                this.core = core;
+               I18n.setLocale(Locale.ENGLISH); /* TODO - load config */
                initActions();
                initDialogs();
        }
@@ -116,6 +123,15 @@ public class SwingInterface implements CoreListener {
                return nodeDisconnectAction;
        }
 
+       /**
+        * Returns all language actions.
+        * 
+        * @return All language actions
+        */
+       List<I18nAction> getLanguageActions() {
+               return languageActions;
+       }
+
        //
        // ACTIONS
        //
@@ -167,6 +183,22 @@ public class SwingInterface implements CoreListener {
                                nodeDisconnect();
                        }
                };
+               List<Locale> availableLanguages = I18n.findAvailableLanguages();
+               for (final Locale locale: availableLanguages) {
+                       I18nAction languageAction = new I18nAction("general.language." + locale.getLanguage()) {
+
+                               @SuppressWarnings("synthetic-access")
+                               public void actionPerformed(ActionEvent e) {
+                                       changeLanguage(locale, this);
+                               }
+
+                       };
+                       if (I18n.getLocale().getLanguage().equals(locale.getLanguage())) {
+                               languageAction.setEnabled(false);
+                       }
+                       languageActions.add(languageAction);
+               }
+
        }
 
        /**
@@ -176,6 +208,10 @@ public class SwingInterface implements CoreListener {
                manageNodesDialog = new ManageNodesDialog(this);
        }
 
+       //
+       // PRIVATE ACTIONS
+       //
+
        /**
         * Pops up the “manage nodes” dialog.
         */
@@ -197,6 +233,22 @@ public class SwingInterface implements CoreListener {
        private void nodeDisconnect() {
        }
 
+       /**
+        * 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
+        *            The action that triggered the change
+        */
+       private void changeLanguage(Locale newLocale, I18nAction languageAction) {
+               for (I18nAction i18nAction: languageActions) {
+                       i18nAction.setEnabled(i18nAction != languageAction);
+               }
+               I18n.setLocale(newLocale);
+       }
+
        //
        // INTERFACE CoreListener
        //