X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fgui%2FPipelinePanel.java;h=8c5fa1555d2158df9b72c5f2ca54c6c559d4dae2;hb=fa5196e029c48636f0c318311244395cfae49953;hp=ab1c484fbc2bcd4d63c768c53d673b9ae682ef91;hpb=45f83831984a48fefacb09f3754502f530fc158e;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java b/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java index ab1c484..8c5fa15 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java @@ -22,12 +22,16 @@ import static javax.swing.BorderFactory.createEtchedBorder; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.Collection; +import java.util.EventListener; import java.util.List; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.event.EventListenerList; -import net.pterodactylus.sonitus.data.Controlled; +import net.pterodactylus.sonitus.data.ControlledComponent; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Pipeline; import net.pterodactylus.sonitus.data.Sink; @@ -45,6 +49,9 @@ public class PipelinePanel extends JPanel { /** The pipeline being displayed. */ private final Pipeline pipeline; + /** The component hover listeners. */ + private final EventListenerList componentHoverListeners = new EventListenerList(); + /** * Creates a new pipeline panel displaying the given pipeline. * @@ -58,6 +65,20 @@ public class PipelinePanel extends JPanel { } // + // LISTENER MANAGEMENT + // + + /** + * Adds the given component hover listener to this panel. + * + * @param componentHoverListener + * The component hover listener to add + */ + public void addComponentHoverListener(ComponentHoverListener componentHoverListener) { + componentHoverListeners.add(ComponentHoverListener.class, componentHoverListener); + } + + // // PRIVATE METHODS // @@ -94,7 +115,7 @@ public class PipelinePanel extends JPanel { /** * Displays the given component. * - * @param controlled + * @param controlledComponent * The component to add this panel. * @param level * The level at which to show the component (the source is level {@code 0}) @@ -103,21 +124,30 @@ public class PipelinePanel extends JPanel { * @param width * The width of the component in grid cells */ - private void addControlled(Controlled controlled, int level, int position, int width) { + private void addControlled(final ControlledComponent controlledComponent, int level, int position, int width) { /* create a GUI component that displays the component. */ - JLabel sourceLabel = new JLabel(controlled.name()); + JLabel sourceLabel = new JLabel(controlledComponent.name()); sourceLabel.setBorder(createEtchedBorder()); + sourceLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseEntered(MouseEvent mouseEvent) { + for (ComponentHoverListener componentHoverListener : componentHoverListeners.getListeners(ComponentHoverListener.class)) { + componentHoverListener.componentEntered(controlledComponent); + } + } + }); /* show component. */ add(sourceLabel, new GridBagConstraints(position, level, width, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); /* if the component does not have connected sinks, exit here. */ - if (!(controlled instanceof Source)) { + if (!(controlledComponent instanceof Source)) { return; } /* iterate over the component’s sinks. */ - Collection sinks = pipeline.sinks((Source) controlled); + Collection sinks = pipeline.sinks((Source) controlledComponent); int sinkWidth = width / sinks.size(); int sinkIndex = 0; for (Sink connectedSink : sinks) { @@ -127,4 +157,23 @@ public class PipelinePanel extends JPanel { } } + /** + * Interface for objects that want to be notified if the user moves the mouse + * cursor over a controlled component. + * + * @author David ‘Bombe’ Roden + */ + public static interface ComponentHoverListener extends EventListener { + + /** + * Notifies the listener that the mouse is now over the given controlled + * component. + * + * @param controlledComponent + * The controlled component now under the mouse + */ + void componentEntered(ControlledComponent controlledComponent); + + } + }