changeset 1628:421d652d113d

Smaller UI fixes in new Thread Monitor review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-December/012162.html reviewed-by: omajid
author Mario Torre <neugens.limasoftware@gmail.com>
date Thu, 11 Dec 2014 11:45:07 +0100
parents 14e6eef84acf
children 4552784dedb6
files thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/locale/LocaleResources.java thread/client-common/src/main/resources/com/redhat/thermostat/thread/client/common/locale/strings.properties thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/RangeComponentHeader.java thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/TimelineViewComponent.java thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo.java thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo2.java thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo3.java
diffstat 7 files changed, 95 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/locale/LocaleResources.java	Thu Dec 11 11:45:07 2014 +0100
+++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/locale/LocaleResources.java	Thu Dec 11 11:45:07 2014 +0100
@@ -72,6 +72,12 @@
     THREAD_DETAILS_EMTPY,
 
     CHECK_FOR_DEADLOCKS,
+
+
+    RESTORE_ZOOM,
+    ZOOM_IN,
+    ZOOM_OUT,
+
     ;
 
     public static final String RESOURCE_BUNDLE =
--- a/thread/client-common/src/main/resources/com/redhat/thermostat/thread/client/common/locale/strings.properties	Thu Dec 11 11:45:07 2014 +0100
+++ b/thread/client-common/src/main/resources/com/redhat/thermostat/thread/client/common/locale/strings.properties	Thu Dec 11 11:45:07 2014 +0100
@@ -31,3 +31,7 @@
 THREAD_DETAILS_EMTPY = Please double-click on a thread in the thread table
 
 CHECK_FOR_DEADLOCKS = Check
+
+RESTORE_ZOOM = Restore Content Size
+ZOOM_IN = Magnify Content
+ZOOM_OUT = Reduce Content Size
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/RangeComponentHeader.java	Thu Dec 11 11:45:07 2014 +0100
+++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/RangeComponentHeader.java	Thu Dec 11 11:45:07 2014 +0100
@@ -38,7 +38,11 @@
 
 import com.redhat.thermostat.client.swing.UIDefaults;
 import com.redhat.thermostat.client.swing.components.FontAwesomeIcon;
+import com.redhat.thermostat.client.swing.components.Icon;
+import com.redhat.thermostat.shared.locale.Translate;
+import com.redhat.thermostat.thread.client.common.locale.LocaleResources;
 import com.redhat.thermostat.thread.client.swing.experimental.components.ContentPane;
+import com.redhat.thermostat.thread.client.swing.experimental.components.DataPane;
 import com.redhat.thermostat.thread.client.swing.impl.timeline.model.TimelineModel;
 import java.awt.BorderLayout;
 import java.awt.GridLayout;
@@ -51,9 +55,15 @@
  */
 public class RangeComponentHeader extends ContentPane {
 
+    private static final Translate<LocaleResources> t = LocaleResources.createLocalizer();
+
     private final TimelineModel model;
     private final UIDefaults defaults;
-    private ContentPane controls;
+    private DataPane controls;
+
+    private JLabel zoomOut;
+    private JLabel restoreZoom;
+    private JLabel zoomIn;
 
     public RangeComponentHeader(TimelineModel model, UIDefaults defaults) {
         this.model = model;
@@ -61,11 +71,15 @@
     }
 
     public void initComponents() {
-        controls = new ContentPane();
+        controls = new DataPane();
         controls.setLayout(new GridLayout(1, 0, 5, 5));
 
-        JLabel zoomOut = new JLabel(new FontAwesomeIcon('\uf066', 15,
-                                                        defaults.getIconColor()));
+        Icon baseIcon = new FontAwesomeIcon('\uf066', 15, defaults.getIconColor());
+        Icon hoverIcon = new FontAwesomeIcon('\uf066', 15,
+                                             defaults.getSelectedComponentBGColor());
+        zoomOut = new JLabel(baseIcon);
+        zoomOut.setToolTipText(t.localize(LocaleResources.ZOOM_OUT).getContents());
+        zoomOut.addMouseListener(new Hover(zoomOut, baseIcon, hoverIcon));
         zoomOut.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseClicked(MouseEvent e) {
@@ -75,8 +89,12 @@
         });
         controls.add(zoomOut);
 
-        JLabel restoreZoom = new JLabel(new FontAwesomeIcon('\uf03b', 15,
-                                                        defaults.getIconColor()));
+        baseIcon = new FontAwesomeIcon('\uf03b', 15, defaults.getIconColor());
+        hoverIcon = new FontAwesomeIcon('\uf03b', 15,
+                                        defaults.getSelectedComponentBGColor());
+        restoreZoom = new JLabel(baseIcon);
+        restoreZoom.setToolTipText(t.localize(LocaleResources.RESTORE_ZOOM).getContents());
+        restoreZoom.addMouseListener(new Hover(restoreZoom, baseIcon, hoverIcon));
         restoreZoom.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseClicked(MouseEvent e) {
@@ -85,8 +103,12 @@
         });
         controls.add(restoreZoom);
 
-        JLabel zoomIn = new JLabel(new FontAwesomeIcon('\uf065', 15,
-                                                       defaults.getIconColor()));
+        baseIcon = new FontAwesomeIcon('\uf065', 15, defaults.getIconColor());
+        hoverIcon = new FontAwesomeIcon('\uf065', 15,
+                                        defaults.getSelectedComponentBGColor());
+        zoomIn = new JLabel(baseIcon);
+        zoomIn.setToolTipText(t.localize(LocaleResources.ZOOM_IN).getContents());
+        zoomIn.addMouseListener(new Hover(zoomIn, baseIcon, hoverIcon));
         zoomIn.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseClicked(MouseEvent e) {
@@ -98,4 +120,39 @@
 
         add(controls, BorderLayout.EAST);
     }
+
+    public void setControlsEnabled(boolean b) {
+        zoomIn.setEnabled(b);
+        zoomOut.setEnabled(b);
+        restoreZoom.setEnabled(b);
+    }
+
+    private class Hover extends MouseAdapter {
+
+        private final JLabel label;
+        private final Icon baseIcon;
+        private final Icon hoverIcon;
+
+        public Hover(JLabel label, Icon baseIcon, Icon hoverIcon) {
+
+            this.label = label;
+            this.baseIcon = baseIcon;
+            this.hoverIcon = hoverIcon;
+        }
+
+        @Override
+        public void mouseEntered(MouseEvent e) {
+            onMouseHover(true);
+        }
+
+        @Override
+        public void mouseExited(MouseEvent e) {
+            onMouseHover(false);
+        }
+
+        public void onMouseHover(boolean hover) {
+            label.setIcon(hover ? hoverIcon : baseIcon);
+            repaint();
+        }
+    }
 }
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/TimelineViewComponent.java	Thu Dec 11 11:45:07 2014 +0100
+++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/TimelineViewComponent.java	Thu Dec 11 11:45:07 2014 +0100
@@ -60,6 +60,7 @@
 
     private ThermostatScrollBar scrollBar;
     private UIDefaults uiDefaults;
+    private RangeComponentHeader header;
 
     public TimelineViewComponent(UIDefaults uiDefaults) {
         this.uiDefaults = uiDefaults;
@@ -75,7 +76,7 @@
         scrollPane.setVerticalScrollBarPolicy(ThermostatScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
         scrollPane.setHorizontalScrollBarPolicy(ThermostatScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
 
-        RangeComponentHeader header = new RangeComponentHeader(model, uiDefaults);
+        header = new RangeComponentHeader(model, uiDefaults);
         header.initComponents();
         scrollPane.setColumnHeaderView(header);
 
@@ -90,6 +91,8 @@
         scrollBar.setEnabled(false);
         scrollBar.setVisible(false);
 
+        header.setControlsEnabled(false);
+
         model.addRatioChangeListener(new RatioChangeListener() {
             @Override
             public void ratioChanged(RatioChangeEvent event) {
@@ -106,6 +109,13 @@
 
     private void checkEnableScrollbar() {
         Range<Long> range = model.getRange();
+        // no data, so no scrolling
+        if (range == null) {
+            scrollBar.setVisible(false);
+            scrollBar.setEnabled(false);
+            return;
+        }
+
         Rectangle bounds = getBounds();
         long length = bounds.x + bounds.width;
         length = Math.round(length / model.getMagnificationRatio());
@@ -121,10 +131,8 @@
 
     public void addTimeline(TimelineComponent timeline) {
         viewport.add(timeline);
+        header.setControlsEnabled(true);
         checkEnableScrollbar();
-
-        timeline.
-
         revalidate();
         repaint();
     }
--- a/thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo.java	Thu Dec 11 11:45:07 2014 +0100
+++ b/thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo.java	Thu Dec 11 11:45:07 2014 +0100
@@ -54,6 +54,8 @@
 import javax.swing.SwingWorker;
 import org.mockito.Mockito;
 
+import static org.mockito.Mockito.when;
+
 /**
  *
  */
@@ -167,7 +169,10 @@
 
     private static UIDefaults createUIDefaults() {
         UIDefaults defaults = Mockito.mock(UIDefaults.class);
-        Mockito.when(defaults.getDefaultFont()).thenReturn(new JLabel().getFont());
+        when(defaults.getDefaultFont()).thenReturn(new JLabel().getFont());
+        when(defaults.getIconColor()).thenReturn(Palette.EARL_GRAY.getColor());
+        when(defaults.getSelectedComponentBGColor()).thenReturn(Palette.ADWAITA_BLU.getColor());
+
         return defaults;
     }
 }
--- a/thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo2.java	Thu Dec 11 11:45:07 2014 +0100
+++ b/thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo2.java	Thu Dec 11 11:45:07 2014 +0100
@@ -179,6 +179,7 @@
         UIDefaults defaults = mock(UIDefaults.class);
         when(defaults.getDefaultFont()).thenReturn(new JLabel().getFont());
         when(defaults.getIconColor()).thenReturn(Palette.EARL_GRAY.getColor());
+        when(defaults.getSelectedComponentBGColor()).thenReturn(Palette.ADWAITA_BLU.getColor());
 
         return defaults;
     }
--- a/thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo3.java	Thu Dec 11 11:45:07 2014 +0100
+++ b/thread/client-swing/src/test/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadViewDemo3.java	Thu Dec 11 11:45:07 2014 +0100
@@ -175,6 +175,7 @@
         UIDefaults defaults = mock(UIDefaults.class);
         when(defaults.getDefaultFont()).thenReturn(new JLabel().getFont());
         when(defaults.getIconColor()).thenReturn(Palette.EARL_GRAY.getColor());
+        when(defaults.getSelectedComponentBGColor()).thenReturn(Palette.ADWAITA_BLU.getColor());
 
         return defaults;
     }