X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FSwingInterface.java;h=e55fffa6e8d29721fcf9baa07b60fbadf28fca6b;hb=e5c7a1609ef6d0878f98c3e8c2819bc1430f96f7;hp=cb5d24c0eb8443b615b61c3698426aef6186545a;hpb=d1caba447262a4b183242ce0ffc3c95a51cd7277;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index cb5d24c..e55fffa 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -20,13 +20,14 @@ package net.pterodactylus.jsite.gui; import java.awt.event.ActionEvent; +import java.util.ArrayList; import java.util.List; - -import javax.swing.Action; +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 @@ -43,17 +44,20 @@ public class SwingInterface implements CoreListener { private MainWindow mainWindow; /** The “manage nodes” action. */ - private Action manageNodesAction; + private I18nAction manageNodesAction; /** The “connect to node” action. */ - private Action nodeConnectAction; + private I18nAction nodeConnectAction; /** The “disconnect from node” action. */ - private Action nodeDisconnectAction; + private I18nAction nodeDisconnectAction; /** The node manager dialog. */ private ManageNodesDialog manageNodesDialog; + /** All lanugage menu items. */ + private List languageActions = new ArrayList(); + /** The list of all defined nodes. */ private List nodeList; @@ -65,6 +69,7 @@ public class SwingInterface implements CoreListener { */ public SwingInterface(Core core) { this.core = core; + I18n.setLocale(Locale.ENGLISH); /* TODO - load config */ initActions(); initDialogs(); } @@ -74,11 +79,29 @@ public class SwingInterface implements CoreListener { // /** + * Returns the core that is controlled by the Swing interface. + * + * @return The core + */ + Core getCore() { + return core; + } + + /** + * Returns the main window of the Swing interface. + * + * @return The main window + */ + MainWindow getMainWindow() { + return mainWindow; + } + + /** * Returns the “manage nodes” action. * * @return The “manage nodes” action */ - public Action getManageNodesAction() { + I18nAction getManageNodesAction() { return manageNodesAction; } @@ -87,7 +110,7 @@ public class SwingInterface implements CoreListener { * * @return The “connect to node” action */ - public Action getNodeConnectAction() { + I18nAction getNodeConnectAction() { return nodeConnectAction; } @@ -96,10 +119,19 @@ public class SwingInterface implements CoreListener { * * @return The “disconnect from node” action */ - public Action getNodeDisconnectAction() { + I18nAction getNodeDisconnectAction() { return nodeDisconnectAction; } + /** + * Returns all language actions. + * + * @return All language actions + */ + List getLanguageActions() { + return languageActions; + } + // // ACTIONS // @@ -151,15 +183,35 @@ public class SwingInterface implements CoreListener { nodeDisconnect(); } }; + List 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); + } + } /** * Initializes all child dialogs. */ private void initDialogs() { - manageNodesDialog = new ManageNodesDialog(mainWindow); + manageNodesDialog = new ManageNodesDialog(this); } + // + // PRIVATE ACTIONS + // + /** * Pops up the “manage nodes” dialog. */ @@ -181,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 //