From cad21ef42edbedab7193b68a0d927097bb956ec0 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:52:18 +0200 Subject: [PATCH] Highlight component panels on hover and selection. --- .../pterodactylus/sonitus/gui/PipelinePanel.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java b/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java index 14c0b77..d47003d 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java @@ -22,6 +22,8 @@ import static javax.swing.BorderFactory.createEmptyBorder; import static javax.swing.BorderFactory.createEtchedBorder; import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -30,8 +32,10 @@ import java.awt.event.MouseEvent; import java.util.Collection; import java.util.EventListener; import java.util.logging.Logger; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.UIManager; import javax.swing.event.EventListenerList; import net.pterodactylus.sonitus.data.ControlledComponent; @@ -57,6 +61,9 @@ public class PipelinePanel extends JPanel { /** The component hover listeners. */ private final EventListenerList componentSelectionListeners = new EventListenerList(); + /** The currently selected component. */ + private JComponent selectedComponent; + /** * Creates a new pipeline panel displaying the given pipeline. * @@ -136,11 +143,29 @@ public class PipelinePanel extends JPanel { @Override public void mouseClicked(MouseEvent e) { + for (Component component : getComponents()) { + component.setBackground(UIManager.getColor("Panel.background")); + } for (ComponentSelectionListener componentSelectionListener : componentSelectionListeners.getListeners(ComponentSelectionListener.class)) { + componentPanel.setBackground(Color.LIGHT_GRAY); componentSelectionListener.componentSelected(controlledComponent); } selectedComponent = componentPanel; } + + @Override + public void mouseEntered(MouseEvent mouseEvent) { + if (componentPanel != selectedComponent) { + componentPanel.setBackground(Color.white); + } + } + + @Override + public void mouseExited(MouseEvent mouseEvent) { + if (componentPanel != selectedComponent) { + componentPanel.setBackground(UIManager.getColor("Panel.background")); + } + } }); /* show component. */ -- 2.7.4