extend core listener
[jSite2.git] / src / net / pterodactylus / jsite / gui / ManageNodesDialog.java
index 9d993a0..ea2b6c5 100644 (file)
@@ -28,7 +28,6 @@ import java.util.Iterator;
 import java.util.List;
 
 import javax.swing.AbstractListModel;
-import javax.swing.Action;
 import javax.swing.BorderFactory;
 import javax.swing.JButton;
 import javax.swing.JDialog;
@@ -43,16 +42,18 @@ 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.main.Version;
 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 {
+public class ManageNodesDialog extends JDialog implements ListSelectionListener, I18nable {
 
        /** The core. */
        private final Core core;
@@ -61,19 +62,19 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
        private List<Node> originalNodeList;
 
        /** The “add node” action. */
-       private Action addNodeAction;
+       private I18nAction addNodeAction;
 
        /** The “edit node” action. */
-       private Action editNodeAction;
+       private I18nAction editNodeAction;
 
        /** The “delete node” action. */
-       private Action deleteNodeAction;
+       private I18nAction deleteNodeAction;
 
        /** The “okay” action. */
-       private Action okayAction;
+       private I18nAction okayAction;
 
        /** The “cancel” action. */
-       private Action cancelAction;
+       private I18nAction cancelAction;
 
        /** The “edit node” dialog. */
        private EditNodeDialog editNodeDialog;
@@ -86,7 +87,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
 
        /**
         * Creates a new node manager dialog.
-        * 
+        *
         * @param swingInterface
         *            The Swing interface
         */
@@ -97,6 +98,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
                initComponents();
                initDialogs();
                pack();
+               I18n.registerI18nable(this);
                SwingUtils.center(this);
        }
 
@@ -105,8 +107,17 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
        //
 
        /**
+        * 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<Node> getNodeList() {
@@ -115,12 +126,12 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
 
        /**
         * Sets the list of nodes.
-        * 
+        *
         * @param nodeList
         *            The list of nodes
         */
        public void setNodeList(List<Node> nodeList) {
-               originalNodeList = nodeList;
+               originalNodeList = new ArrayList<Node>(nodeList);
                nodeListModel.clear();
                for (Node node: nodeList) {
                        nodeListModel.addNode(node);
@@ -236,10 +247,9 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
         * Adds a new node via {@link #editNodeDialog}.
         */
        private void addNode() {
-               editNodeDialog.setNodeName("New Node");
+               editNodeDialog.setNodeName(I18n.get("general.newNode.name"));
                editNodeDialog.setNodeHostname("localhost");
                editNodeDialog.setNodePort(9481);
-               editNodeDialog.setNodeOnSameMachine(true);
                editNodeDialog.setVisible(true);
                if (!editNodeDialog.wasCancelled()) {
                        Node newNode = new Node();
@@ -258,13 +268,11 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
                editNodeDialog.setNodeName(selectedNode.getName());
                editNodeDialog.setNodeHostname(selectedNode.getHostname());
                editNodeDialog.setNodePort(selectedNode.getPort());
-               editNodeDialog.setNodeOnSameMachine(selectedNode.isSameMachine());
                editNodeDialog.setVisible(true);
                if (!editNodeDialog.wasCancelled()) {
                        selectedNode.setName(editNodeDialog.getNodeName());
                        selectedNode.setHostname(editNodeDialog.getNodeHostname());
                        selectedNode.setPort(editNodeDialog.getNodePort());
-                       selectedNode.setSameMachine(editNodeDialog.isNodeOnSameMachine());
                        nodeList.repaint();
                }
        }
@@ -291,7 +299,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
 
        /**
         * Checks whether the list of nodes is not empty.
-        * 
+        *
         * @return <code>true</code> if there is at least one node defined,
         *         <code>false</code> otherwise
         */
@@ -338,9 +346,26 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
                deleteNodeAction.setEnabled(selectCount >= 1);
        }
 
+       //
+       // INTERFACE I18nable
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       public void updateI18n() {
+               okayAction.updateI18n();
+               cancelAction.updateI18n();
+               addNodeAction.updateI18n();
+               editNodeAction.updateI18n();
+               deleteNodeAction.updateI18n();
+               setTitle(I18n.get("manageNodesDialog.title") + " – jSite " + Version.getVersion());
+               SwingUtils.repackCentered(this);
+       }
+
        /**
         * List model for the {@link ManageNodesDialog#nodeList}. TODO
-        * 
+        *
         * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
         * @version $Id$
         */
@@ -354,11 +379,12 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
                 * 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
@@ -370,7 +396,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
 
                /**
                 * Removes the given node from the list model.
-                * 
+                *
                 * @see Collection#remove(Object)
                 * @param node
                 *            The node to remove
@@ -383,7 +409,7 @@ public class ManageNodesDialog extends JDialog implements ListSelectionListener
 
                /**
                 * Removes all nodes from the list model.
-                * 
+                *
                 * @see Collection#clear()
                 */
                public void clear() {