From 728fbd0eb74f6b7bd9ae0fdf2a6ab13b98ea45b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 9 Jun 2011 21:54:23 +0200 Subject: [PATCH] Deleting the selected node will now selected another node. This fixes #184. --- src/de/todesbaum/jsite/gui/NodeManagerListener.java | 8 ++++++++ src/de/todesbaum/jsite/gui/NodeManagerPage.java | 14 ++++++++++++++ src/de/todesbaum/jsite/main/Main.java | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/de/todesbaum/jsite/gui/NodeManagerListener.java b/src/de/todesbaum/jsite/gui/NodeManagerListener.java index d6a9404..c01c57b 100644 --- a/src/de/todesbaum/jsite/gui/NodeManagerListener.java +++ b/src/de/todesbaum/jsite/gui/NodeManagerListener.java @@ -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); + } diff --git a/src/de/todesbaum/jsite/gui/NodeManagerPage.java b/src/de/todesbaum/jsite/gui/NodeManagerPage.java index 0f38a55..23fafe6 100644 --- a/src/de/todesbaum/jsite/gui/NodeManagerPage.java +++ b/src/de/todesbaum/jsite/gui/NodeManagerPage.java @@ -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); diff --git a/src/de/todesbaum/jsite/main/Main.java b/src/de/todesbaum/jsite/main/Main.java index af921cf..195e603 100644 --- a/src/de/todesbaum/jsite/main/Main.java +++ b/src/de/todesbaum/jsite/main/Main.java @@ -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) { -- 2.7.4