package net.pterodactylus.jsite.gui;
import java.awt.event.ActionEvent;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
-import javax.swing.Action;
+import javax.swing.JOptionPane;
import net.pterodactylus.jsite.core.Core;
import net.pterodactylus.jsite.core.CoreListener;
import net.pterodactylus.jsite.core.Node;
+import net.pterodactylus.jsite.i18n.I18n;
+import net.pterodactylus.jsite.i18n.gui.I18nAction;
/**
* TODO
/** The main window. */
private MainWindow mainWindow;
+ /** The “configure” action. */
+ private I18nAction configureAction;
+
+ /** The “import config” action. */
+ private I18nAction importConfigAction;
+
+ /** The “quit” action. */
+ private I18nAction quitAction;
+
/** 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 “about” action. */
+ private I18nAction helpAboutAction;
+
+ /** The “add project” action. */
+ private I18nAction addProjectAction;
+
+ /** The “about” dialog. */
+ private AboutDialog aboutDialog;
+
/** The list of all defined nodes. */
private List<Node> nodeList;
*/
public SwingInterface(Core core) {
this.core = core;
+ I18n.setLocale(Locale.ENGLISH); /* TODO - load config */
+ System.setProperty("swing.aatext", "true");
+ System.setProperty("swing.plaf.metal.controlFont", "Tahoma");
+ System.setProperty("swing.plaf.metal.userFont", "Tahoma");
initActions();
initDialogs();
}
}
/**
+ * Returns the “configure” action.
+ *
+ * @return The “configure” action
+ */
+ I18nAction getConfigureAction() {
+ return configureAction;
+ }
+
+ /**
+ * Returns the “import config” action.
+ *
+ * @return The “import config” action
+ */
+ I18nAction getImportConfigAction() {
+ return importConfigAction;
+ }
+
+ /**
+ * Returns the “quit” action.
+ *
+ * @return The “quit” action
+ */
+ I18nAction getQuitAction() {
+ return quitAction;
+ }
+
+ /**
* Returns the “manage nodes” action.
*
* @return The “manage nodes” action
*/
- Action getManageNodesAction() {
+ I18nAction getManageNodesAction() {
return manageNodesAction;
}
*
* @return The “connect to node” action
*/
- Action getNodeConnectAction() {
+ I18nAction getNodeConnectAction() {
return nodeConnectAction;
}
*
* @return The “disconnect from node” action
*/
- Action getNodeDisconnectAction() {
+ I18nAction getNodeDisconnectAction() {
return nodeDisconnectAction;
}
+ /**
+ * Returns all language actions.
+ *
+ * @return All language actions
+ */
+ List<I18nAction> getLanguageActions() {
+ return languageActions;
+ }
+
+ /**
+ * Returns the “about” action.
+ *
+ * @return The “about” action
+ */
+ I18nAction getHelpAboutAction() {
+ return helpAboutAction;
+ }
+
+ /**
+ * Returns the “add project” action.
+ *
+ * @return The “add project” action
+ */
+ I18nAction getAddProjectAction() {
+ return addProjectAction;
+ }
+
//
// ACTIONS
//
* Initializes all actions.
*/
private void initActions() {
+ configureAction = new I18nAction("mainWindow.menu.jSite.configure") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ configure();
+ }
+ };
+ importConfigAction = new I18nAction("mainWindow.menu.jSite.importConfig") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ importConfig();
+ }
+ };
+ quitAction = new I18nAction("mainWindow.menu.jSite.quit") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ quit();
+ }
+ };
manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") {
/**
* {@inheritDoc}
*/
@SuppressWarnings("synthetic-access")
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent actionEvent) {
manageNodes();
}
};
nodeConnectAction = new I18nAction("mainWindow.menu.node.item.connect", false) {
@SuppressWarnings("synthetic-access")
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent actionEvent) {
nodeConnect();
}
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);
+ }
+ helpAboutAction = new I18nAction("mainWindow.menu.help.item.about") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ helpAbout();
+ }
+ };
+ addProjectAction = new I18nAction("mainWindow.button.addProject") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ addProject();
+ }
+ };
}
/**
*/
private void initDialogs() {
manageNodesDialog = new ManageNodesDialog(this);
+ aboutDialog = new AboutDialog(this);
+ }
+
+ //
+ // PRIVATE ACTIONS
+ //
+
+ /**
+ * Shows the configuration dialog.
+ */
+ private void configure() {
+ }
+
+ /**
+ * Imports old jSite configuration.
+ */
+ private void importConfig() {
+ }
+
+ /**
+ * Quits jSite.
+ */
+ private void quit() {
+ System.exit(0);
}
/**
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);
+ }
+
+ /**
+ * Shows the “about” dialog.
+ */
+ private void helpAbout() {
+ aboutDialog.setVisible(true);
+ }
+
+ /**
+ * Adds a project.
+ */
+ private void addProject() {
+ }
+
//
// INTERFACE CoreListener
//
/**
* {@inheritDoc}
*/
+ public void loadingProjectsFailed(String directory) {
+ JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.projectLoadingFailed.message", directory), I18n.get("mainWindow.error.projectLoadingFailed.title"), JOptionPane.ERROR_MESSAGE);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void coreLoaded() {
this.nodeList = core.getNodes();
manageNodesDialog.setNodeList(nodeList);