changeset 1145:ed73c0796267

Add shortcut to close Overlay panel in HeapDumper review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-June/007083.html reviewed-by: vanaltj
author Mario Torre <neugens.limasoftware@gmail.com>
date Mon, 24 Jun 2013 16:44:23 +0200
parents e34e65e36bc9
children d3a24826cf5d
files client/swing/src/main/java/com/redhat/thermostat/client/swing/components/HeaderPanel.java client/swing/src/main/java/com/redhat/thermostat/client/swing/components/OverlayPanel.java vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingView.java vm-heap-analysis/client-swing/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingViewTest.java
diffstat 4 files changed, 58 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/HeaderPanel.java	Mon Jun 24 16:06:24 2013 +0200
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/HeaderPanel.java	Mon Jun 24 16:44:23 2013 +0200
@@ -97,6 +97,8 @@
         
         setLayout(new BorderLayout(0, 0));
 
+        setName(HeaderPanel.class.getName());
+        
         headerLabel = new ShadowLabel(header, new EmptyIcon(5, 5));
         headerPanel = new GradientPanel(Color.WHITE, getBackground());
         headerPanel.setName("clickableArea");
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/OverlayPanel.java	Mon Jun 24 16:06:24 2013 +0200
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/components/OverlayPanel.java	Mon Jun 24 16:44:23 2013 +0200
@@ -44,6 +44,7 @@
 import java.awt.Rectangle;
 import java.awt.RenderingHints;
 import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseMotionAdapter;
 import java.awt.geom.Area;
@@ -98,6 +99,8 @@
         setBorder(new OverlayBorder());
         setLayout(new BorderLayout(0, 10));
         
+        setName(OverlayPanel.class.getName());
+        
         titlePane = new JPanel();
         titlePane.setOpaque(true);
 
@@ -120,13 +123,18 @@
         
         setOverlayVisible(false);
         
-        // filter events, we don't want them to reach components below us
+        installListeners();
+    }
+    
+    private void installListeners() {
+        
+        // filter events, we don't want them to reach components through us
         addMouseListener(new MouseAdapter() {});
         addMouseMotionListener(new MouseMotionAdapter() {});
         addKeyListener(new KeyAdapter() {});
         setFocusTraversalKeysEnabled(false);
     }
-    
+
     @Override
     public Component add(Component comp) {
         return content.add(comp);
--- a/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingView.java	Mon Jun 24 16:06:24 2013 +0200
+++ b/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingView.java	Mon Jun 24 16:44:23 2013 +0200
@@ -40,11 +40,15 @@
 import java.awt.EventQueue;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
 import java.util.List;
 
+import javax.swing.AbstractAction;
 import javax.swing.BoxLayout;
+import javax.swing.JComponent;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.KeyStroke;
 import javax.swing.OverlayLayout;
 import javax.swing.SwingUtilities;
 
@@ -107,6 +111,7 @@
         
         visiblePane = new JPanel();
         visiblePane.setLayout(new BoxLayout(visiblePane, BoxLayout.X_AXIS));
+        visiblePane.setName(HeapSwingView.class.getName());
         
         heapDetailPanel = new HeapPanel();
         
@@ -137,7 +142,7 @@
             }
         });
         overview.addToolBarButton(takeDumpIconButton);
-        
+                
         Icon listDumpIcon = IconResource.HISTORY.getIcon();
         showHeapListButton = new ActionToggleButton(listDumpIcon, translator.localize(LocaleResources.LIST_DUMPS_ACTION));
         showHeapListButton.setToolTipText(translator.localize(LocaleResources.LIST_DUMPS_ACTION).getContents());
@@ -153,6 +158,17 @@
                 }
             }
         });
+        KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
+        @SuppressWarnings("serial")
+        javax.swing.Action closeOverlay = new AbstractAction() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                closeDumpListView();
+            }
+        };
+        overlay.getActionMap().put("close", closeOverlay);
+        overlay.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "close");
+        
         overview.addToolBarButton(showHeapListButton);
         
         // at the beginning, only the overview is visible
@@ -324,7 +340,9 @@
         SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
-                showHeapListButton.getToolbarButton().doClick();
+                if (overview.isVisible()) {
+                    showHeapListButton.getToolbarButton().doClick();
+                }
             }
         });
     }
--- a/vm-heap-analysis/client-swing/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingViewTest.java	Mon Jun 24 16:06:24 2013 +0200
+++ b/vm-heap-analysis/client-swing/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapSwingViewTest.java	Mon Jun 24 16:44:23 2013 +0200
@@ -41,6 +41,7 @@
 import static org.mockito.Mockito.when;
 
 import java.awt.Container;
+import java.awt.event.KeyEvent;
 import java.util.concurrent.CountDownLatch;
 
 import net.java.openjdk.cacio.ctc.junit.CacioFESTRunner;
@@ -62,6 +63,8 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.redhat.thermostat.client.swing.components.HeaderPanel;
+import com.redhat.thermostat.client.swing.components.OverlayPanel;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.vm.heap.analysis.client.core.HeapView;
@@ -210,7 +213,7 @@
         
         latch.await();
         
-        JLabelFixture overlay =  panel.label(OverlayComponent.class.getName());
+        JLabelFixture overlay = panel.label(OverlayComponent.class.getName());
         overlay.doubleClick();
         
         OverlayComponent overlayComponent = (OverlayComponent) overlay.component();
@@ -270,5 +273,27 @@
 
         assertTrue(result[0]);
     }
+    
+    @GUITest
+    @Test
+    public void testOverlayClosed() {
+        
+        frame.show();
+        
+        final JPanelFixture panel = frame.panel(HeapSwingView.class.getName());
+        GuiActionRunner.execute(new GuiTask() {
+            @Override
+            protected void executeInEDT() throws Throwable {
+                view.openDumpListView(new SwingHeapDumpListView());
+            }
+        });
+        
+        JPanelFixture overlay = frame.panel(OverlayPanel.class.getName());
+        overlay.requireVisible();
+        
+        panel.robot.pressAndReleaseKey(KeyEvent.VK_ESCAPE, 0);
+        
+        overlay.requireNotVisible();
+    }
 }