X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FSwingInterface.java;h=e98fa80bbce456fbb2bfb274a0fd0b7fcc696483;hb=c74ea301cd9c71a434685bb75de2b7a2bb2440e4;hp=fab1bc95c51eadb3f3a18ce867c30396c02b5791;hpb=b97d649800f285ca81e79cb880b21a6db4240328;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index fab1bc9..e98fa80 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -20,13 +20,17 @@ 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 @@ -42,24 +46,42 @@ public class SwingInterface implements CoreListener { /** 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 languageActions = new ArrayList(); + + /** 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 nodeList; - /** The current default node. */ - private Node defaultNode; - /** * Creates a new swing interface. * @@ -68,6 +90,10 @@ public class SwingInterface implements CoreListener { */ 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(); } @@ -77,11 +103,56 @@ 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 “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 */ - public Action getManageNodesAction() { + I18nAction getManageNodesAction() { return manageNodesAction; } @@ -90,7 +161,7 @@ public class SwingInterface implements CoreListener { * * @return The “connect to node” action */ - public Action getNodeConnectAction() { + I18nAction getNodeConnectAction() { return nodeConnectAction; } @@ -99,10 +170,37 @@ 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; + } + + /** + * 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 // @@ -126,20 +224,50 @@ public class SwingInterface implements CoreListener { * 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(); } @@ -154,27 +282,87 @@ 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); + } + 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(); + } + }; } /** * Initializes all child dialogs. */ private void initDialogs() { - manageNodesDialog = new ManageNodesDialog(mainWindow); + 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); } /** * Pops up the “manage nodes” dialog. */ private void manageNodes() { + manageNodesDialog.setNodeList(nodeList); manageNodesDialog.setVisible(true); + nodeList = manageNodesDialog.getNodeList(); } /** * Connects to the node. */ private void nodeConnect() { - core.connectToNode(null); // FIXME } /** @@ -183,6 +371,35 @@ 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); + } + + /** + * Shows the “about” dialog. + */ + private void helpAbout() { + aboutDialog.setVisible(true); + } + + /** + * Adds a project. + */ + private void addProject() { + } + // // INTERFACE CoreListener // @@ -190,11 +407,16 @@ public class SwingInterface implements 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.getNodeList(); - this.defaultNode = core.getDefaultNode(); + this.nodeList = core.getNodes(); manageNodesDialog.setNodeList(nodeList); - manageNodesDialog.setDefaultNode(defaultNode); mainWindow.setVisible(true); mainWindow.setStatusBarText("Core loaded."); }