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
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<I18nAction> languageActions = new ArrayList<I18nAction>();
+
/** The list of all defined nodes. */
private List<Node> nodeList;
*/
public SwingInterface(Core core) {
this.core = core;
+ I18n.setLocale(Locale.ENGLISH); /* TODO - load config */
initActions();
initDialogs();
}
//
/**
+ * 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;
}
*
* @return The “connect to node” action
*/
- public Action getNodeConnectAction() {
+ I18nAction getNodeConnectAction() {
return nodeConnectAction;
}
*
* @return The “disconnect from node” action
*/
- public Action getNodeDisconnectAction() {
+ I18nAction getNodeDisconnectAction() {
return nodeDisconnectAction;
}
+ /**
+ * Returns all language actions.
+ *
+ * @return All language actions
+ */
+ List<I18nAction> getLanguageActions() {
+ return languageActions;
+ }
+
//
// ACTIONS
//
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);
+ }
+
}
/**
* Initializes all child dialogs.
*/
private void initDialogs() {
- manageNodesDialog = new ManageNodesDialog(mainWindow);
+ manageNodesDialog = new ManageNodesDialog(this);
}
+ //
+ // PRIVATE ACTIONS
+ //
+
/**
* Pops up the “manage nodes” dialog.
*/
* Connects to the node.
*/
private void nodeConnect() {
- core.connectToNode(null); // FIXME
}
/**
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
//
* {@inheritDoc}
*/
public void coreLoaded() {
- this.nodeList = core.getNodeList();
+ this.nodeList = core.getNodes();
manageNodesDialog.setNodeList(nodeList);
mainWindow.setVisible(true);
mainWindow.setStatusBarText("Core loaded.");