From 0fb6af2eeecf591148346548855b4834ece81e18 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 25 May 2008 12:57:22 +0200 Subject: [PATCH] complete new node management --- .../pterodactylus/jsite/gui/EditNodeDialog.java | 9 +- src/net/pterodactylus/jsite/gui/MainWindow.java | 11 +- .../pterodactylus/jsite/gui/ManageNodesDialog.java | 474 --------------------- src/net/pterodactylus/jsite/gui/NodeLabel.java | 3 + .../pterodactylus/jsite/gui/SwingInterface.java | 172 +++++--- src/net/pterodactylus/jsite/i18n/jSite.properties | 117 ++--- .../pterodactylus/jsite/i18n/jSite_de.properties | 117 ++--- 7 files changed, 218 insertions(+), 685 deletions(-) delete mode 100644 src/net/pterodactylus/jsite/gui/ManageNodesDialog.java diff --git a/src/net/pterodactylus/jsite/gui/EditNodeDialog.java b/src/net/pterodactylus/jsite/gui/EditNodeDialog.java index 3d46cf0..bbb5224 100644 --- a/src/net/pterodactylus/jsite/gui/EditNodeDialog.java +++ b/src/net/pterodactylus/jsite/gui/EditNodeDialog.java @@ -29,6 +29,7 @@ import java.awt.event.ActionEvent; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JDialog; +import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; @@ -89,11 +90,11 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Creates a new node edit dialog with the given parent. * - * @param parentDialog - * The parent dialog of this dialog + * @param parentFrame + * The parent frame of this dialog */ - public EditNodeDialog(JDialog parentDialog) { - super(parentDialog, I18n.get("editNodeDialog.title") + " – jSite " + Version.getVersion(), true); + public EditNodeDialog(JFrame parentFrame) { + super(parentFrame, I18n.get("editNodeDialog.title") + " – jSite " + Version.getVersion(), true); initActions(); initComponents(); pack(); diff --git a/src/net/pterodactylus/jsite/gui/MainWindow.java b/src/net/pterodactylus/jsite/gui/MainWindow.java index 61a61c6..2e04224 100644 --- a/src/net/pterodactylus/jsite/gui/MainWindow.java +++ b/src/net/pterodactylus/jsite/gui/MainWindow.java @@ -231,6 +231,9 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop nodeMenus.put(node, newNodeMenu); newNodeMenu.add(swingInterface.getNodeConnectAction(node)); newNodeMenu.add(swingInterface.getNodeDisconnectAction(node)); + newNodeMenu.addSeparator(); + newNodeMenu.add(swingInterface.getNodeEditAction(node)); + newNodeMenu.add(swingInterface.getNodeDeleteAction(node)); nodeMenu.add(newNodeMenu); NodeLabel nodeLabel = new NodeLabel(swingInterface, node, onlineIcon, offlineIcon, errorIcon); nodeLabels.put(node, nodeLabel); @@ -364,7 +367,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop nodeMenu = new I18nMenu("mainWindow.menu.node"); menuBar.add(nodeMenu); - nodeMenu.add(new FixedJMenuItem(swingInterface.getManageNodesAction())); + nodeMenu.add(new FixedJMenuItem(swingInterface.getAddNodeAction())); nodeMenu.addSeparator(); languageMenu = new I18nMenu("mainWindow.menu.language"); @@ -384,7 +387,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop setJMenuBar(menuBar); JToolBar toolBar = new JToolBar(I18n.get("mainWindow.toolbar.name")); - toolBar.add(swingInterface.getManageNodesAction()); + toolBar.add(swingInterface.getAddNodeAction()); toolBar.addSeparator(); toolBar.add(swingInterface.getQuitAction()); super.getContentPane().add(toolBar, BorderLayout.PAGE_START); @@ -438,7 +441,7 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop swingInterface.getConfigureAction().updateI18n(); swingInterface.getImportConfigAction().updateI18n(); swingInterface.getQuitAction().updateI18n(); - swingInterface.getManageNodesAction().updateI18n(); + swingInterface.getAddNodeAction().updateI18n(); swingInterface.getAddProjectAction().updateI18n(); swingInterface.getCloneProjectAction().updateI18n(); swingInterface.getDeleteProjectAction().updateI18n(); @@ -449,6 +452,8 @@ public class MainWindow extends JFrame implements WindowListener, I18nable, Prop for (Node node: swingInterface.getNodes()) { swingInterface.getNodeConnectAction(node).updateI18n(); swingInterface.getNodeDisconnectAction(node).updateI18n(); + swingInterface.getNodeEditAction(node).updateI18n(); + swingInterface.getNodeDeleteAction(node).updateI18n(); } for (I18nAction languageAction: swingInterface.getLanguageActions()) { languageAction.updateI18n(); diff --git a/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java b/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java deleted file mode 100644 index 0598144..0000000 --- a/src/net/pterodactylus/jsite/gui/ManageNodesDialog.java +++ /dev/null @@ -1,474 +0,0 @@ -/* - * jSite2 - ManageNodeDialog.java - - * Copyright © 2008 David Roden - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package net.pterodactylus.jsite.gui; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.event.ActionEvent; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Logger; - -import javax.swing.AbstractListModel; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.border.EtchedBorder; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -import net.pterodactylus.jsite.core.Core; -import net.pterodactylus.jsite.core.Node; -import net.pterodactylus.jsite.i18n.I18n; -import net.pterodactylus.jsite.i18n.I18nable; -import net.pterodactylus.jsite.i18n.gui.I18nAction; -import net.pterodactylus.jsite.i18n.gui.I18nLabel; -import net.pterodactylus.jsite.main.Version; -import net.pterodactylus.util.logging.Logging; -import net.pterodactylus.util.swing.SwingUtils; - -/** - * Dialog that lets the user manage her nodes. - * - * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - * @version $Id$ - */ -public class ManageNodesDialog extends JDialog implements ListSelectionListener, I18nable { - - /** The logger.  */ - @SuppressWarnings("unused") - private static final Logger logger = Logging.getLogger(ManageNodesDialog.class.getName()); - - /** The core. */ - private final Core core; - - /** The original list of nodes. */ - private List originalNodeList; - - /** The “add node” action. */ - private I18nAction addNodeAction; - - /** The “edit node” action. */ - private I18nAction editNodeAction; - - /** The “delete node” action. */ - private I18nAction deleteNodeAction; - - /** The “okay” action. */ - private I18nAction okayAction; - - /** The “cancel” action. */ - private I18nAction cancelAction; - - /** The “edit node” dialog. */ - private EditNodeDialog editNodeDialog; - - /** The warning label. */ - private I18nLabel immediatelyEffectiveLabel; - - /** The node list. */ - private JList nodeList; - - /** The mode for the node list. */ - private NodeListModel nodeListModel = new NodeListModel(); - - /** - * Creates a new node manager dialog. - * - * @param swingInterface - * The Swing interface - */ - public ManageNodesDialog(SwingInterface swingInterface) { - super(swingInterface.getMainWindow(), I18n.get("manageNodesDialog.title") + " – jSite " + Version.getVersion(), true); - this.core = swingInterface.getCore(); - initActions(); - initComponents(); - initDialogs(); - pack(); - I18n.registerI18nable(this); - SwingUtils.center(this); - } - - // - // ACCESSORS - // - - /** - * Expose the edit node dialog for the simple mode. - * - * @return The edit node dialog - */ - EditNodeDialog getEditNodeDialog() { - return editNodeDialog; - } - - /** - * Returns the list of nodes. - * - * @return The list of nodes - */ - public List getNodeList() { - return originalNodeList; - } - - /** - * Sets the list of nodes. - * - * @param nodeList - * The list of nodes - */ - public void setNodeList(List nodeList) { - originalNodeList = new ArrayList(nodeList); - nodeListModel.clear(); - for (Node node: nodeList) { - nodeListModel.addNode(node); - } - } - - // - // PRIVATE METHODS - // - - /** - * Initializes all actions. - */ - private void initActions() { - okayAction = new I18nAction("general.button.okay") { - - /** - * {@inheritDoc} - */ - @SuppressWarnings("synthetic-access") - public void actionPerformed(ActionEvent e) { - confirm(); - } - }; - cancelAction = new I18nAction("general.button.cancel") { - - /** - * {@inheritDoc} - */ - @SuppressWarnings("synthetic-access") - public void actionPerformed(ActionEvent e) { - cancel(); - } - }; - addNodeAction = new I18nAction("manageNodesDialog.button.addNode") { - - /** - * {@inheritDoc} - */ - @SuppressWarnings("synthetic-access") - public void actionPerformed(ActionEvent e) { - addNode(); - } - }; - editNodeAction = new I18nAction("manageNodesDialog.button.editNode", false) { - - /** - * {@inheritDoc} - */ - @SuppressWarnings("synthetic-access") - public void actionPerformed(ActionEvent e) { - editNode(); - } - }; - deleteNodeAction = new I18nAction("manageNodesDialog.button.deleteNode", false) { - - /** - * {@inheritDoc} - */ - @SuppressWarnings("synthetic-access") - public void actionPerformed(ActionEvent e) { - deleteNodes(); - } - }; - } - - /** - * Initializes all components. - */ - private void initComponents() { - JPanel rootPanel = new JPanel(new BorderLayout(12, 12)); - rootPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); - - JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12)); - rootPanel.add(buttonPanel, BorderLayout.PAGE_END); - buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12)); - - buttonPanel.add(new JButton(cancelAction)); - JButton okayButton = new JButton(okayAction); - getRootPane().setDefaultButton(okayButton); - buttonPanel.add(okayButton); - - JPanel contentPanel = new JPanel(new BorderLayout(12, 12)); - rootPanel.add(contentPanel, BorderLayout.CENTER); - contentPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(12, 12, 12, 12))); - - JPanel warningPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 12, 12)); - warningPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12)); - warningPanel.add(immediatelyEffectiveLabel = new I18nLabel("manageNodesDialog.label.immediatelyEffective")); - contentPanel.add(warningPanel, BorderLayout.PAGE_START); - - JPanel listButtonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 12, 12)); - contentPanel.add(listButtonPanel, BorderLayout.PAGE_END); - listButtonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12)); - listButtonPanel.add(new JButton(addNodeAction)); - listButtonPanel.add(new JButton(editNodeAction)); - listButtonPanel.add(new JButton(deleteNodeAction)); - - nodeList = new JList(nodeListModel); - nodeList.addListSelectionListener(this); - contentPanel.add(new JScrollPane(nodeList), BorderLayout.CENTER); - - setContentPane(rootPanel); - } - - /** - * Initializes all child dialogs. - */ - private void initDialogs() { - editNodeDialog = new EditNodeDialog(this); - } - - // - // PRIVATE ACTIONS - // - - /** - * Adds a new node via {@link #editNodeDialog}. - */ - private void addNode() { - editNodeDialog.setNodeName(I18n.get("general.newNode.name")); - editNodeDialog.setNodeHostname("localhost"); - editNodeDialog.setNodePort(9481); - editNodeDialog.setVisible(true); - if (!editNodeDialog.wasCancelled()) { - Node newNode = new Node(); - newNode.setName(editNodeDialog.getNodeName()); - newNode.setHostname(editNodeDialog.getNodeHostname()); - newNode.setPort(editNodeDialog.getNodePort()); - try { - if (!core.addNode(newNode)) { - JOptionPane.showMessageDialog(this, I18n.get("manageNodesDialog.error.nodeAlreadyKnown.message", newNode.getHostname(), newNode.getPort()), I18n.get("manageNodesDialog.error.nodeAlreadyKnown.title"), JOptionPane.ERROR_MESSAGE); - } - } catch (UnknownHostException e) { - /* - * normally this shouldn't throw because the node editor catches - * it. - */ - JOptionPane.showMessageDialog(this, I18n.get("manageNodesDialog.error.nodeUnresolvable.message", newNode.getHostname()), I18n.get("manageNodesDialog.error.nodeUnresolvable.title"), JOptionPane.ERROR_MESSAGE); - } - } - } - - /** - * Edits a node via {@link #editNodeDialog}. - */ - private void editNode() { - Node selectedNode = (Node) nodeList.getSelectedValue(); - editNodeDialog.setNodeName(selectedNode.getName()); - editNodeDialog.setNodeHostname(selectedNode.getHostname()); - editNodeDialog.setNodePort(selectedNode.getPort()); - editNodeDialog.setVisible(true); - if (!editNodeDialog.wasCancelled()) { - selectedNode.setName(editNodeDialog.getNodeName()); - selectedNode.setHostname(editNodeDialog.getNodeHostname()); - selectedNode.setPort(editNodeDialog.getNodePort()); - nodeList.repaint(); - } - } - - /** - * Deletes the selected node. - */ - private void deleteNodes() { - Object[] selectedNodes = nodeList.getSelectedValues(); - for (Object node: selectedNodes) { - Node selectedNode = (Node) node; - if (core.isNodeConnected(selectedNode)) { - int response = JOptionPane.showConfirmDialog(this, I18n.get("manageNodesDialog.error.nodeConnected.message", selectedNode.getName()), I18n.get("manageNodesDialog.error.nodeConnected.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); - if (response == JOptionPane.CANCEL_OPTION) { - break; - } else if (response == JOptionPane.NO_OPTION) { - continue; - } - } - nodeListModel.removeNode(selectedNode); - } - nodeList.clearSelection(); - } - - /** - * Checks whether the list of nodes is not empty. - * - * @return true if there is at least one node defined, - * false otherwise - */ - private boolean verifyNodesExist() { - return nodeListModel.getSize() > 0; - } - - /** - * This method is called when the “okay” button is pressed. The nodes from - * the list are read and the {@link #originalNodeList} member is set so that - * the calling code can use {@link #getNodeList()} to get the changed - * values. - */ - private void confirm() { - if (!verifyNodesExist()) { - JOptionPane.showMessageDialog(this, I18n.get("manageNodesDialog.error.nodeListEmpty.message"), I18n.get("manageNodesDialog.error.nodeListEmpty.title"), JOptionPane.ERROR_MESSAGE); - return; - } - originalNodeList.clear(); - for (Node node: nodeListModel) { - originalNodeList.add(node); - } - setVisible(false); - } - - /** - * Cancels the dialog. - */ - private void cancel() { - setVisible(false); - } - - // - // INTERFACE ListSelectionListener - // - - /** - * {@inheritDoc} - */ - public void valueChanged(ListSelectionEvent listSelectionEvent) { - JList list = (JList) listSelectionEvent.getSource(); - int selectCount = list.getSelectedIndices().length; - editNodeAction.setEnabled(selectCount == 1); - deleteNodeAction.setEnabled(selectCount >= 1); - } - - // - // INTERFACE I18nable - // - - /** - * {@inheritDoc} - */ - public void updateI18n() { - okayAction.updateI18n(); - cancelAction.updateI18n(); - addNodeAction.updateI18n(); - editNodeAction.updateI18n(); - deleteNodeAction.updateI18n(); - immediatelyEffectiveLabel.updateI18n(); - setTitle(I18n.get("manageNodesDialog.title") + " – jSite " + Version.getVersion()); - SwingUtils.repackCentered(this); - } - - /** - * List model for the {@link ManageNodesDialog#nodeList}. - * - * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - * @version $Id$ - */ - private class NodeListModel extends AbstractListModel implements Iterable { - - /** The list of nodes. */ - @SuppressWarnings("hiding") - private final List nodeList = new ArrayList(); - - /** - * Creates a new node list model. - */ - public NodeListModel() { - /* do nothing. */ - } - - /** - * Adds the given node to the list model. - * - * @see Collection#add(Object) - * @param node - * The node to add - */ - public void addNode(Node node) { - nodeList.add(node); - fireIntervalAdded(this, nodeList.size() - 1, nodeList.size() - 1); - } - - /** - * Removes the given node from the list model. - * - * @see Collection#remove(Object) - * @param node - * The node to remove - */ - public void removeNode(Node node) { - int nodeIndex = nodeList.indexOf(node); - nodeList.remove(node); - fireIntervalRemoved(this, nodeIndex, nodeIndex); - } - - /** - * Removes all nodes from the list model. - * - * @see Collection#clear() - */ - public void clear() { - int nodeCount = nodeList.size(); - if (nodeCount > 0) { - nodeList.clear(); - fireIntervalRemoved(this, 0, nodeCount - 1); - } - } - - /** - * {@inheritDoc} - */ - public Iterator iterator() { - return nodeList.iterator(); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("synthetic-access") - public Object getElementAt(int index) { - return nodeList.get(index); - } - - /** - * {@inheritDoc} - */ - public int getSize() { - return nodeList.size(); - } - - } - -} diff --git a/src/net/pterodactylus/jsite/gui/NodeLabel.java b/src/net/pterodactylus/jsite/gui/NodeLabel.java index 46e8be1..cd4092e 100644 --- a/src/net/pterodactylus/jsite/gui/NodeLabel.java +++ b/src/net/pterodactylus/jsite/gui/NodeLabel.java @@ -136,6 +136,9 @@ public class NodeLabel extends JLabel implements PropertyChangeListener, MouseLi contextMenu.addSeparator(); contextMenu.add(swingInterface.getNodeConnectAction(node)); contextMenu.add(swingInterface.getNodeDisconnectAction(node)); + contextMenu.addSeparator(); + contextMenu.add(swingInterface.getNodeEditAction(node)); + contextMenu.add(swingInterface.getNodeDeleteAction(node)); addMouseListener(this); } diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index eb67d27..eb5ff26 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -91,8 +92,8 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh /** The “quit” action. */ private I18nAction quitAction; - /** The “manage nodes” action. */ - private I18nAction manageNodesAction; + /** The “add node” action. */ + private I18nAction addNodeAction; /** All node menu items. */ private Map nodeConnectActions = Collections.synchronizedMap(new HashMap()); @@ -100,8 +101,11 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh /** All node disconnect actions. */ private Map nodeDisconnectActions = Collections.synchronizedMap(new HashMap()); - /** The node manager dialog. */ - private ManageNodesDialog manageNodesDialog; + /** All node edit actions. */ + private Map nodeEditActions = Collections.synchronizedMap(new HashMap()); + + /** All node removal actions. */ + private Map nodeDeleteActions = Collections.synchronizedMap(new HashMap()); /** All lanugage menu items. */ private List languageActions = new ArrayList(); @@ -124,6 +128,9 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh /** The configuration dialog. */ private ConfigurationDialog configurationDialog; + /** The node editor dialog. */ + private EditNodeDialog editNodeDialog; + /** The list of all defined nodes. */ private List nodeList = Collections.synchronizedList(new ArrayList()); @@ -264,12 +271,12 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh } /** - * Returns the “manage nodes” action. + * Returns the “add node” action. * - * @return The “manage nodes” action + * @return The “add node” action */ - I18nAction getManageNodesAction() { - return manageNodesAction; + I18nAction getAddNodeAction() { + return addNodeAction; } /** @@ -295,6 +302,28 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh } /** + * Returns the “edit node” action for the given node. + * + * @param node + * The node to edit + * @return The “edit node” action + */ + I18nAction getNodeEditAction(Node node) { + return nodeEditActions.get(node); + } + + /** + * Returns the “delete node” action for the given node. + * + * @param node + * The node to delete + * @return The “delete node” action + */ + I18nAction getNodeDeleteAction(Node node) { + return nodeDeleteActions.get(node); + } + + /** * Returns all language actions. * * @return All language actions @@ -501,16 +530,6 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh quit(); } }; - manageNodesAction = new I18nAction("mainWindow.menu.node.item.manageNodes") { - - /** - * {@inheritDoc} - */ - @SuppressWarnings("synthetic-access") - public void actionPerformed(ActionEvent actionEvent) { - manageNodes(); - } - }; List availableLanguages = I18n.findAvailableLanguages(); for (final Locale locale: availableLanguages) { I18nAction languageAction = new I18nAction("general.language." + locale.getLanguage()) { @@ -526,6 +545,16 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh } languageActions.add(languageAction); } + addNodeAction = new I18nAction("mainWindow.menu.node.item.addNode") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + addNode(); + } + }; helpAboutAction = new I18nAction("mainWindow.menu.help.item.about") { /** @@ -572,9 +601,9 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh * Initializes all child dialogs. */ private void initDialogs() { - manageNodesDialog = new ManageNodesDialog(this); aboutDialog = new AboutDialog(this); configurationDialog = new ConfigurationDialog(this); + editNodeDialog = new EditNodeDialog(mainWindow); } // @@ -627,38 +656,58 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh } /** - * Pops up the “manage nodes” dialog. + * Adds a node. */ - private void manageNodes() { - if (advancedMode) { - manageNodesDialog.setNodeList(nodeList); - manageNodesDialog.setVisible(true); - nodeList = manageNodesDialog.getNodeList(); - /* TODO - notify main window of changes */ - } else { - if (nodeList.isEmpty()) { - Node newNode = new Node(); - newNode.setName(I18n.get("general.defaultNode.name")); - newNode.setHostname("localhost"); - newNode.setPort(9481); - nodeList.add(newNode); - } - Node firstNode = nodeList.get(0); - EditNodeDialog editNodeDialog = manageNodesDialog.getEditNodeDialog(); - editNodeDialog.setNodeName(firstNode.getName()); - editNodeDialog.setNodeHostname(firstNode.getHostname()); - editNodeDialog.setNodePort(firstNode.getPort()); - editNodeDialog.setVisible(true); - if (!editNodeDialog.wasCancelled()) { - firstNode.setName(editNodeDialog.getNodeName()); - firstNode.setHostname(editNodeDialog.getNodeHostname()); - firstNode.setPort(editNodeDialog.getNodePort()); - /* TODO - give to core. */ + private void addNode() { + editNodeDialog.setNodeName(I18n.get(nodeList.isEmpty() ? "general.defaultNode.name" : "general.newNode.name")); + editNodeDialog.setNodeHostname("localhost"); + editNodeDialog.setNodePort(9481); + editNodeDialog.setVisible(true); + if (!editNodeDialog.wasCancelled()) { + Node newNode = new Node(); + newNode.setName(editNodeDialog.getNodeName()); + newNode.setHostname(editNodeDialog.getNodeHostname()); + newNode.setPort(editNodeDialog.getNodePort()); + try { + core.addNode(newNode); + } catch (UnknownHostException e) { + JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.hostnameUnresolvable.message"), I18n.get("mainWindow.error.hostnameUnresolvable.title"), JOptionPane.ERROR_MESSAGE); } } } /** + * Edits the given node. + * + * @param node + * The node to edit + */ + private void editNode(Node node) { + editNodeDialog.setNodeName(node.getName()); + editNodeDialog.setNodeHostname(node.getHostname()); + editNodeDialog.setNodePort(node.getPort()); + editNodeDialog.setVisible(true); + if (!editNodeDialog.wasCancelled()) { + node.setName(editNodeDialog.getNodeName()); + node.setHostname(editNodeDialog.getNodeHostname()); + node.setPort(editNodeDialog.getNodePort()); + } + } + + /** + * Deletes the given node. + * + * @param node + * The node to delete + */ + private void deleteNode(Node node) { + int option = JOptionPane.showConfirmDialog(mainWindow, I18n.get("mainWindow.question.deleteNode.message", node.getName()), I18n.get("mainWindow.question.deleteNode.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); + if (option == JOptionPane.OK_OPTION) { + core.removeNode(node); + } + } + + /** * Connects to the node. * * @param node @@ -831,8 +880,7 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh nodeList.add(node); node.addPropertyChangeListener(this); logger.log(Level.FINE, "nodeList.size(): " + nodeList.size()); - manageNodesDialog.setNodeList(nodeList); - nodeConnectActions.put(node, new I18nAction("mainWindow.menu.connect") { + nodeConnectActions.put(node, new I18nAction("mainWindow.menu.node.item.connect") { /** * {@inheritDoc} @@ -842,7 +890,7 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh nodeConnect(node); } }); - nodeDisconnectActions.put(node, new I18nAction("mainWindow.menu.disconnect") { + nodeDisconnectActions.put(node, new I18nAction("mainWindow.menu.node.item.disconnect") { /** * {@inheritDoc} @@ -853,6 +901,26 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh } }); nodeDisconnectActions.get(node).setEnabled(false); + nodeEditActions.put(node, new I18nAction("mainWindow.menu.node.item.edit") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + editNode(node); + } + }); + nodeDeleteActions.put(node, new I18nAction("mainWindow.menu.node.item.remove") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + deleteNode(node); + } + }); mainWindow.addNode(node); } @@ -865,6 +933,8 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh node.removePropertyChangeListener(this); nodeConnectActions.remove(node); nodeDisconnectActions.remove(node); + nodeEditActions.remove(node); + nodeDeleteActions.remove(node); mainWindow.removeNode(node); } @@ -873,6 +943,8 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh */ public void nodeConnecting(Node node) { nodeConnectActions.get(node).setEnabled(false); + nodeEditActions.get(node).setEnabled(false); + nodeDeleteActions.get(node).setEnabled(false); mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.connectingToNode", node.getName(), node.getHostname(), node.getPort())); } @@ -889,6 +961,8 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh */ public void nodeConnectionFailed(Node node, Throwable cause) { nodeConnectActions.get(node).setEnabled(true); + nodeEditActions.get(node).setEnabled(true); + nodeDeleteActions.get(node).setEnabled(true); mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.connectionToNodeFailed", node.getName(), node.getHostname(), node.getPort(), (cause != null) ? cause.getMessage() : "no reason given")); JOptionPane.showMessageDialog(mainWindow, I18n.get("mainWindow.error.nodeConnectionFailed.message", node.getName(), node.getHostname(), node.getPort(), (cause != null) ? cause.getMessage() : "no reason given"), I18n.get("mainWindow.error.nodeConnectionFailed.title"), JOptionPane.ERROR_MESSAGE); } @@ -899,6 +973,8 @@ public class SwingInterface implements CoreListener, LoggingListener, PropertyCh public void nodeDisconnected(Node node, Throwable throwable) { nodeDisconnectActions.get(node).setEnabled(false); nodeConnectActions.get(node).setEnabled(true); + nodeEditActions.get(node).setEnabled(true); + nodeDeleteActions.get(node).setEnabled(true); mainWindow.setStatusBarText(I18n.get("mainWindow.statusBar.disconnectedFromNode", node.getName(), node.getHostname(), node.getPort())); } diff --git a/src/net/pterodactylus/jsite/i18n/jSite.properties b/src/net/pterodactylus/jsite/i18n/jSite.properties index 9a05422..e8d25b3 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite.properties @@ -48,6 +48,12 @@ mainWindow.error.projectLoadingFailed.message: Loading the projects from \u201c{ mainWindow.error.nodeConnectionFailed.title: Connecting to Node Failed mainWindow.error.nodeConnectionFailed.message: Connecting to node \u201c{0}\u201d (at {1}:{2,number,#}) has failed: {3} +mainWindow.error.hostnameUnresolvable.title: Could Not Resolve Hostname +mainWindow.error.hostnameUnresolvable.message: The hostname \u201c{0}\u201d can not be resolved! + +mainWindow.question.deleteNode.title: Really Remove Node? +mainWindow.question.deleteNode.message: You are about to remove the node \u201c{0}\u201d! Do you want to continue? + mainWindow.statusBar.coreLoaded: Core loaded. mainWindow.statusBar.coreStopped: Core stopped. mainWindow.statusBar.projectLoadingDone: Projects loaded. @@ -69,21 +75,6 @@ mainWindow.menu.jSite.mnemonic: VK_J mainWindow.menu.node.name: Node mainWindow.menu.node.mnemonic: VK_N -mainWindow.menu.connect.name: Connect -mainWindow.menu.connect.mnemonic: VK_C -mainWindow.menu.connect.accelerator: VK_UNDEFINED -mainWindow.menu.connect.shortDescription: Connects to the node -mainWindow.menu.connect.longDescription: Connects to the node - -mainWindow.menu.disconnect.name: Disconnect -mainWindow.menu.disconnect.mnemonic: VK_D -mainWindow.menu.disconnect.accelerator: VK_UNDEFINED -mainWindow.menu.disconnect.shortDescription: Disconnects from the node -mainWindow.menu.disconnect.longDescription: Disconnects from the node - -mainWindow.menu.connectNoNodeAvailable.name: No node available -mainWindow.menu.disconnectNoNodeAvailable.name: No node connected - mainWindow.menu.language.name: Languages mainWindow.menu.language.mnemonic: VK_L @@ -91,6 +82,39 @@ mainWindow.menu.help.name: Help mainWindow.menu.help.mnemonic: VK_H # +# the node menus +# +mainWindow.menu.node.item.addNode.name: Add node +mainWindow.menu.node.item.addNode.mnemonic: VK_A +mainWindow.menu.node.item.addNode.accelerator: Ctrl-VK_A +mainWindow.menu.node.item.addNode.shortDescription: Add a node +mainWindow.menu.node.item.addNode.longDescription: Add a node + +mainWindow.menu.node.item.connect.name: Connect +mainWindow.menu.node.item.connect.mnemonic: VK_C +mainWindow.menu.node.item.connect.accelerator: VK_UNDEFINED +mainWindow.menu.node.item.connect.shortDescription: Connects to the node +mainWindow.menu.node.item.connect.longDescription: Connects to the node + +mainWindow.menu.node.item.disconnect.name: Disconnect +mainWindow.menu.node.item.disconnect.mnemonic: VK_D +mainWindow.menu.node.item.disconnect.accelerator: VK_UNDEFINED +mainWindow.menu.node.item.disconnect.shortDescription: Disconnects from the node +mainWindow.menu.node.item.disconnect.longDescription: Disconnects from the node + +mainWindow.menu.node.item.edit.name: Edit +mainWindow.menu.node.item.edit.mnemonic: VK_E +mainWindow.menu.node.item.edit.accelerator: VK_UNDEFINED +mainWindow.menu.node.item.edit.shortDescription: Edits the node +mainWindow.menu.node.item.edit.longDescription: Edits the node + +mainWindow.menu.node.item.remove.name: Remove +mainWindow.menu.node.item.remove.mnemonic: VK_R +mainWindow.menu.node.item.remove.accelerator: VK_UNDEFINED +mainWindow.menu.node.item.remove.shortDescription: Removes the node +mainWindow.menu.node.item.remove.longDescription: Removes the node + +# # the jSite menu # mainWindow.menu.jSite.configure.name: Configure @@ -112,31 +136,6 @@ mainWindow.menu.jSite.quit.shortDescription: Quits jSite mainWindow.menu.jSite.quit.longDescription: Quits jSite # -# the node menu -# - -#manage nodes -mainWindow.menu.node.item.manageNodes.name: Manage Nodes -mainWindow.menu.node.item.manageNodes.mnemonic: VK_M -mainWindow.menu.node.item.manageNodes.accelerator: Ctrl-VK_M -mainWindow.menu.node.item.manageNodes.shortDescription: Manage nodes -mainWindow.menu.node.item.manageNodes.longDescription: Manage your nodes - -# connect to node -mainWindow.menu.node.item.connect.name: Connect -mainWindow.menu.node.item.connect.mnemonic: VK_C -mainWindow.menu.node.item.connect.accelerator: Ctrl-VK_C -mainWindow.menu.node.item.connect.shortDescription: Connect to node -mainWindow.menu.node.item.connect.longDescription: Connect to the selected node - -#disconnect from node -mainWindow.menu.node.item.disconnect.name: Disconnect -mainWindow.menu.node.item.disconnect.mnemonic: VK_D -mainWindow.menu.node.item.disconnect.accelerator: Ctrl-VK_D -mainWindow.menu.node.item.disconnect.shortDescription: Disconnect from node -mainWindow.menu.node.item.disconnect.longDescription: Disconnect from the currently connected node - -# # the help menu # @@ -197,44 +196,6 @@ projectPanel.button.changeBasePath.accelerator: Ctrl-VK_C projectPanel.button.changeBasePath.shortDescription: Changes the path the files are read from projectPanel.button.changeBasePath.longDescription: Changes the path the files are read from -# -# the "manage nodes" dialog -# - -manageNodesDialog.title: Manage Nodes - -manageNodesDialog.label.immediatelyEffective.name: Any changes you make on this page will immediately be effective! - -manageNodesDialog.button.addNode.name: Add Node -manageNodesDialog.button.addNode.mnemonic: VK_A -manageNodesDialog.button.addNode.accelerator: Ctrl-VK_A -manageNodesDialog.button.addNode.shortDescription: Add a node -manageNodesDialog.button.addNode.longDescription: Add a node - -manageNodesDialog.button.editNode.name: Edit Node -manageNodesDialog.button.editNode.mnemonic: VK_E -manageNodesDialog.button.editNode.accelerator: Ctrl-VK_E -manageNodesDialog.button.editNode.shortDescription: Edit selected node -manageNodesDialog.button.editNode.longDescription: Edit the selected node - -manageNodesDialog.button.deleteNode.name: Delete Node -manageNodesDialog.button.deleteNode.mnemonic: VK_D -manageNodesDialog.button.deleteNode.accelerator: Ctrl-VK_D -manageNodesDialog.button.deleteNode.shortDescription: Delete selected node(s) -manageNodesDialog.button.deleteNode.longDescription: Delete the selected node(s) - -manageNodesDialog.error.nodeListEmpty.title: Node List Empty -manageNodesDialog.error.nodeListEmpty.message: The node list is empty. - -manageNodesDialog.error.nodeConnected.title: Node Is Connected -manageNodesDialog.error.nodeConnected.message: The Node \u201c{0}\u201d is still connected. Do you really want to delete it? - -manageNodesDialog.error.nodeUnresolvable.title: Node hostname can not be resolved -manageNodesDialog.error.nodeUnresolvable.message: The hostname of the node (\u201c{0}\u201d) can not be resolved. - -manageNodesDialog.error.nodeAlreadyKnown.title: Node Already Known -manageNodesDialog.error.nodeAlreadyKnown.message: There already is a node with the hostname (\u201c{0}\u201d) and port ({1,number,#}). - # the "edit node" dialog editNodeDialog.title: Edit Node diff --git a/src/net/pterodactylus/jsite/i18n/jSite_de.properties b/src/net/pterodactylus/jsite/i18n/jSite_de.properties index ef2b8f9..6a648ff 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite_de.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite_de.properties @@ -48,6 +48,12 @@ mainWindow.error.projectLoadingFailed.message: Die Projekte aus \u201e{0}\u201c mainWindow.error.nodeConnectionFailed.title: Verbindung mit Node fehlgeschlagen mainWindow.error.nodeConnectionFailed.message: Die Verbindung zum Node \u201e{0}\u201c ({1}:{2,number,#}) konnte nicht hergestellt werden: {3} +mainWindow.error.hostnameUnresolvable.title: Hostname unbekannt +mainWindow.error.hostnameUnresolvable.message: Der Hostname \u201e{0}\u201e kann nicht aufgel\u00f6st werden! + +mainWindow.question.deleteNode.title: Node wirklich l\u00f6schen? +mainWindow.question.deleteNode.message: Den Node \u201e{0}\u201c wirklich l\u00f6schen? + mainWindow.statusBar.coreLoaded: Kern geladen. mainWindow.statusBar.coreStopped: Kern angehalten. mainWindow.statusBar.projectLoadingDone: Projekte geladen. @@ -69,21 +75,6 @@ mainWindow.menu.jSite.mnemonic: VK_J mainWindow.menu.node.name: Node mainWindow.menu.node.mnemonic: VK_N -mainWindow.menu.connect.name: Verbindung herstellen -mainWindow.menu.connect.mnemonic: VK_H -mainWindow.menu.connect.accelerator: VK_UNDEFINED -mainWindow.menu.connect.shortDescription: Stellt eine Verbindung zum Node her -mainWindow.menu.connect.longDescription: Stellt eine Verbindung zum Node her - -mainWindow.menu.disconnect.name: Verbindung trennen -mainWindow.menu.disconnect.mnemonic: VK_T -mainWindow.menu.disconnect.accelerator: VK_UNDEFINED -mainWindow.menu.disconnect.shortDescription: Trennt die Verbindung vom Node -mainWindow.menu.disconnect.longDescription: Trennt die Verbindung vom Node - -mainWindow.menu.connectNoNodeAvailable.name: Kein Node verf\u00fcgbar -mainWindow.menu.disconnectNoNodeAvailable.name: Kein Node verbunden - mainWindow.menu.languages.name: Sprachen mainWindow.menu.languages.mnemonic: VK_S @@ -91,6 +82,39 @@ mainWindow.menu.help.name: Hilfe mainWindow.menu.help.mnemonic: VK_H # +# the node menus +# +mainWindow.menu.node.item.addNode.name: Node hinzuf\u00fcgen +mainWindow.menu.node.item.addNode.mnemonic: VK_H +mainWindow.menu.node.item.addNode.accelerator: Ctrl-VK_H +mainWindow.menu.node.item.addNode.shortDescription: Einen Node hinzuf\u00fcgen +mainWindow.menu.node.item.addNode.longDescription: Einen Node hinzuf\u00fcgen + +mainWindow.menu.node.item.connect.name: Verbinden +mainWindow.menu.node.item.connect.mnemonic: VK_V +mainWindow.menu.node.item.connect.accelerator: VK_UNDEFINED +mainWindow.menu.node.item.connect.shortDescription: Stellt eine Verbindung mit dem Node her +mainWindow.menu.node.item.connect.longDescription: Stellt eine Verbindung mit dem Node her + +mainWindow.menu.node.item.disconnect.name: Verbindung trennen +mainWindow.menu.node.item.disconnect.mnemonic: VK_T +mainWindow.menu.node.item.disconnect.accelerator: VK_UNDEFINED +mainWindow.menu.node.item.disconnect.shortDescription: Trennt die Verbindung mit dem Node +mainWindow.menu.node.item.disconnect.longDescription: Trennt die Verbindung mit dem Node + +mainWindow.menu.node.item.edit.name: \u00c4ndern +mainWindow.menu.node.item.edit.mnemonic: VK_N +mainWindow.menu.node.item.edit.accelerator: VK_UNDEFINED +mainWindow.menu.node.item.edit.shortDescription: \u00c4ndert die Parameter des Nodes +mainWindow.menu.node.item.edit.longDescription: \u00c4ndert die Parameter des Nodes + +mainWindow.menu.node.item.remove.name: L\u00f6schen +mainWindow.menu.node.item.remove.mnemonic: VK_L +mainWindow.menu.node.item.remove.accelerator: VK_UNDEFINED +mainWindow.menu.node.item.remove.shortDescription: Entfernt den Node +mainWindow.menu.node.item.remove.longDescription: Entfernt den Node + +# # the jSite menu # mainWindow.menu.jSite.configure.name: Einstellungen @@ -112,31 +136,6 @@ mainWindow.menu.jSite.quit.shortDescription: Beendet jSite mainWindow.menu.jSite.quit.longDescription: Beendet jSite # -# the node menu -# - -#manage nodes -mainWindow.menu.node.item.manageNodes.name: Nodes verwalten -mainWindow.menu.node.item.manageNodes.mnemonic: VK_N -mainWindow.menu.node.item.manageNodes.accelerator: Ctrl-VK_N -mainWindow.menu.node.item.manageNodes.shortDescription: Nodes verwalten -mainWindow.menu.node.item.manageNodes.longDescription: Nodes verwalten - -# connect to node -mainWindow.menu.node.item.connect.name: Verbinden -mainWindow.menu.node.item.connect.mnemonic: VK_V -mainWindow.menu.node.item.connect.accelerator: Ctrl-VK_V -mainWindow.menu.node.item.connect.shortDescription: Mit Node verbinden -mainWindow.menu.node.item.connect.longDescription: Verbindung zum Node herstellen - -#disconnect from node -mainWindow.menu.node.item.disconnect.name: Verbindung trennen -mainWindow.menu.node.item.disconnect.mnemonic: VK_T -mainWindow.menu.node.item.disconnect.accelerator: Ctrl-VK_T -mainWindow.menu.node.item.disconnect.shortDescription: Von Node trennen -mainWindow.menu.node.item.disconnect.longDescription: Verbindung zum Node trennen - -# # the help menu # @@ -197,44 +196,6 @@ projectPanel.button.changeBasePath.accelerator: Ctrl-VK_N projectPanel.button.changeBasePath.shortDescription: \u00c4ndert den Basispfad, aus dem die Dateien gelesen werden projectPanel.button.changeBasePath.longDescription: \u00c4ndert den Basispfad, aus dem die Dateien gelesen werden -# -# the "manage nodes" dialog -# - -manageNodesDialog.title: Nodes verwalten - -manageNodesDialog.label.immediatelyEffective.name: Alle hier gemachten \u00c4nderungen treten sofort in Kraft! - -manageNodesDialog.button.addNode.name: Node hinzuf\u00fcgen -manageNodesDialog.button.addNode.mnemonic: VK_H -manageNodesDialog.button.addNode.accelerator: Ctrl-VK_H -manageNodesDialog.button.addNode.shortDescription: Node hinzuf\u00fcgen -manageNodesDialog.button.addNode.longDescription: Einen Node hinzuf\u00fcgen - -manageNodesDialog.button.editNode.name: Node editiren -manageNodesDialog.button.editNode.mnemonic: VK_E -manageNodesDialog.button.editNode.accelerator: Ctrl-VK_E -manageNodesDialog.button.editNode.shortDescription: Den ausgew\u00e4hlten Node editieren -manageNodesDialog.button.editNode.longDescription: Den ausgew\u00e4hlten Node editieren - -manageNodesDialog.button.deleteNode.name: Node l\u00f6schen -manageNodesDialog.button.deleteNode.mnemonic: VK_L -manageNodesDialog.button.deleteNode.accelerator: Ctrl-VK_L -manageNodesDialog.button.deleteNode.shortDescription: Den ausgew\u00e4hlten Node l\u00f6schen -manageNodesDialog.button.deleteNode.longDescription: Den ausgew\u00e4hlten Node l\u00f6schen - -manageNodesDialog.error.nodeListEmpty.title: Keine Nodes konfiguriert -manageNodesDialog.error.nodeListEmpty.message: Es wurden keine Nodes konfiguriert. - -manageNodesDialog.error.nodeConnected.title: Node ist verbunden -manageNodesDialog.error.nodeConnected.message: Mit dem Node \u201e{0}\u201c besteht momentan eine Verbindung. Wollen Sie ihn wirklich l\u00f6schen? - -manageNodesDialog.error.nodeUnresolvable.title: Hostname des Nodes ung\u00fcltig -manageNodesDialog.error.nodeUnresolvable.message: Der Hostname des Nodes (\u201e{0}\u201c) kann nicht aufgel\u00f6st werden. - -manageNodesDialog.error.nodeAlreadyKnown.title: Node schon bekannt -manageNodesDialog.error.nodeAlreadyKnown.message: Es gibt bereits einen Node mit diesem Hostnamen (\u201e{0}\u201c) und Port ({1,number,#}). - # the "edit node" dialog editNodeDialog.title: Edit Node -- 2.7.4