Highlight component panels on hover and selection.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 28 May 2013 13:52:18 +0000 (15:52 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 28 May 2013 13:52:18 +0000 (15:52 +0200)
src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java

index 14c0b77..d47003d 100644 (file)
@@ -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. */