Deleting the selected node will now selected another node.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 9 Jun 2011 19:54:23 +0000 (21:54 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 3 Nov 2011 07:45:18 +0000 (08:45 +0100)
This fixes #184.

src/de/todesbaum/jsite/gui/NodeManagerListener.java
src/de/todesbaum/jsite/gui/NodeManagerPage.java
src/de/todesbaum/jsite/main/Main.java

index d6a9404..c01c57b 100644 (file)
@@ -39,4 +39,12 @@ public interface NodeManagerListener extends EventListener {
         */
        public void nodesUpdated(Node[] nodes);
 
+       /**
+        * Notifies a listener that the selected node has changed.
+        *
+        * @param node
+        *            The new selected node
+        */
+       public void nodeSelected(Node node);
+
 }
index 0f38a55..23fafe6 100644 (file)
@@ -144,6 +144,18 @@ public class NodeManagerPage extends TWizardPage implements ListSelectionListene
        }
 
        /**
+        * Notifies all listeners that a new node was selected.
+        *
+        * @param node
+        *            The newly selected node
+        */
+       protected void fireNodeSelected(Node node) {
+               for (NodeManagerListener nodeManagerListener : nodeManagerListeners) {
+                       nodeManagerListener.nodeSelected(node);
+               }
+       }
+
+       /**
         * Creates all actions.
         */
        private void createActions() {
@@ -347,8 +359,10 @@ public class NodeManagerPage extends TWizardPage implements ListSelectionListene
                if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.node-manager.delete-node.warning"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.CANCEL_OPTION) {
                        return;
                }
+               int nodeIndex = nodeListModel.indexOf(node);
                nodeListModel.removeElement(node);
                nodeList.repaint();
+               fireNodeSelected((Node) nodeListModel.get(Math.min(nodeIndex, nodeListModel.size() - 1)));
                fireNodesUpdated(getNodes());
                deleteNodeAction.setEnabled(nodeListModel.size() > 1);
                wizard.setNextEnabled(nodeListModel.size() > 0);
index af921cf..195e603 100644 (file)
@@ -19,6 +19,7 @@
 
 package de.todesbaum.jsite.main;
 
+import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.IOException;
@@ -39,6 +40,7 @@ import javax.swing.Icon;
 import javax.swing.JList;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JRadioButtonMenuItem;
@@ -617,6 +619,21 @@ public class Main implements ActionListener, ListSelectionListener, WizardListen
        /**
         * {@inheritDoc}
         */
+       public void nodeSelected(Node node) {
+               for (Component menuItem : nodeMenu.getMenuComponents()) {
+                       if (menuItem instanceof JMenuItem) {
+                               if (node.equals(((JMenuItem) menuItem).getClientProperty("Node"))) {
+                                       ((JMenuItem) menuItem).setSelected(true);
+                               }
+                       }
+               }
+               freenetInterface.setNode(node);
+               selectedNode = node;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public void actionPerformed(ActionEvent e) {
                Object source = e.getSource();
                if (source instanceof JRadioButtonMenuItem) {