From c312becee5e66f399304efa8f56eb2bce79f99ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 28 May 2013 15:51:56 +0200 Subject: [PATCH] Turn hover listener into a selection listener. --- .../net/pterodactylus/sonitus/gui/MainWindow.java | 6 +++--- .../pterodactylus/sonitus/gui/PipelinePanel.java | 25 +++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java index aa358c3..bb69578 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java @@ -32,7 +32,7 @@ import javax.swing.WindowConstants; import net.pterodactylus.sonitus.data.ControlledComponent; import net.pterodactylus.sonitus.data.Pipeline; -import net.pterodactylus.sonitus.gui.PipelinePanel.ComponentHoverListener; +import net.pterodactylus.sonitus.gui.PipelinePanel.ComponentSelectionListener; import net.pterodactylus.sonitus.main.Version; import com.google.common.base.Optional; @@ -72,10 +72,10 @@ public class MainWindow extends JFrame { tabbedPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); final JPanel pipelineInfoPanel = new JPanel(new BorderLayout(12, 12)); PipelinePanel pipelinePanel = new PipelinePanel(pipeline); - pipelinePanel.addComponentHoverListener(new ComponentHoverListener() { + pipelinePanel.addComponentHoverListener(new ComponentSelectionListener() { @Override - public void componentEntered(ControlledComponent controlledComponent) { + public void componentSelected(ControlledComponent controlledComponent) { infoPanelCardLayout.show(infoPanel, controlledComponent.name()); } }); diff --git a/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java b/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java index 4b1527c..14c0b77 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java @@ -55,7 +55,7 @@ public class PipelinePanel extends JPanel { private final Pipeline pipeline; /** The component hover listeners. */ - private final EventListenerList componentHoverListeners = new EventListenerList(); + private final EventListenerList componentSelectionListeners = new EventListenerList(); /** * Creates a new pipeline panel displaying the given pipeline. @@ -74,13 +74,13 @@ public class PipelinePanel extends JPanel { // /** - * Adds the given component hover listener to this panel. + * Adds the given component selection listener to this panel. * - * @param componentHoverListener - * The component hover listener to add + * @param componentSelectionListener + * The component selection listener to add */ - public void addComponentHoverListener(ComponentHoverListener componentHoverListener) { - componentHoverListeners.add(ComponentHoverListener.class, componentHoverListener); + public void addComponentHoverListener(ComponentSelectionListener componentSelectionListener) { + componentSelectionListeners.add(ComponentSelectionListener.class, componentSelectionListener); } // @@ -131,14 +131,15 @@ public class PipelinePanel extends JPanel { */ private void addControlled(final ControlledComponent controlledComponent, int level, int position, int width, ControlledComponent parentComponent) { /* create a GUI component that displays the component. */ - JPanel componentPanel = createComponentPanel(controlledComponent, parentComponent); + final JPanel componentPanel = createComponentPanel(controlledComponent, parentComponent); componentPanel.addMouseListener(new MouseAdapter() { @Override - public void mouseEntered(MouseEvent mouseEvent) { - for (ComponentHoverListener componentHoverListener : componentHoverListeners.getListeners(ComponentHoverListener.class)) { - componentHoverListener.componentEntered(controlledComponent); + public void mouseClicked(MouseEvent e) { + for (ComponentSelectionListener componentSelectionListener : componentSelectionListeners.getListeners(ComponentSelectionListener.class)) { + componentSelectionListener.componentSelected(controlledComponent); } + selectedComponent = componentPanel; } }); @@ -198,7 +199,7 @@ public class PipelinePanel extends JPanel { * * @author David ‘Bombe’ Roden */ - public static interface ComponentHoverListener extends EventListener { + public static interface ComponentSelectionListener extends EventListener { /** * Notifies the listener that the mouse is now over the given controlled @@ -207,7 +208,7 @@ public class PipelinePanel extends JPanel { * @param controlledComponent * The controlled component now under the mouse */ - void componentEntered(ControlledComponent controlledComponent); + void componentSelected(ControlledComponent controlledComponent); } -- 2.7.4