X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FSwingInterface.java;h=e55fffa6e8d29721fcf9baa07b60fbadf28fca6b;hb=76b527b370cd0c22bbdad4c1c9c677dea887a170;hp=4a0c97fa0a95e63ef2ae5606f16893312f02a830;hpb=b71f4f4aeb7440b88dd82a252cd296506427c440;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index 4a0c97f..e55fffa 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -20,11 +20,14 @@ 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 languageActions = new ArrayList(); + /** The list of all defined nodes. */ private List 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 getLanguageActions() { + return languageActions; + } + // // ACTIONS // @@ -167,6 +183,22 @@ 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); + } + } /** @@ -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 //