tmf: Support + and - keys for histogram zoom
authorPatrick Tasse <patrick.tasse@gmail.com>
Fri, 15 Aug 2014 18:05:19 +0000 (14:05 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Mon, 18 Aug 2014 13:18:58 +0000 (09:18 -0400)
Change-Id: I9b4edffb70743a7421fd6040d8b1525da59cebe1
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/31773
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Hudson CI
org.eclipse.linuxtools.lttng.help/doc/User-Guide.mediawiki
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/FullTraceHistogram.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramZoom.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java

index 0257a7bf1bc59d88ecdc031c754a0d1c7abcc5b6..4c0c1c70a81bb0e628f638ebf8cf47036757292e 100644 (file)
@@ -580,6 +580,8 @@ In each histogram, the following keys are handled:
 * '''Right Arrow''': Moves the current event to the next non-empty bar
 * '''Home''': Sets the current time to the first non-empty bar
 * '''End''': Sets the current time to the last non-empty histogram bar
+* '''Plus (+)''': Zoom in
+* '''Minus (-)''': Zoom out
 
 == Statistics View ==
 
index 6e6adc08057ac851be5cf6da176092df4c65674d..1fa533bc8cbc4d4e9cdbb839b4cfcf6c1710f2c9 100644 (file)
@@ -53,7 +53,6 @@ public class FullTraceHistogram extends Histogram {
     public FullTraceHistogram(HistogramView view, Composite parent) {
         super(view, parent);
         fZoom = new HistogramZoom(this, getStartTime(), getTimeLimit());
-        addMouseWheelListener(fZoom);
     }
 
     @Override
index ab10c5a800f36861a6be1070147b4222ad019bb8..de0f720aeb4692824a3b2779587f14af31a8596b 100644 (file)
@@ -651,6 +651,24 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
         fCanvas.removeMouseWheelListener(listener);
     }
 
+    /**
+     * Add a key listener to the histogram
+     * @param listener the key listener
+     * @since 3.1
+     */
+    public void addKeyListener(KeyListener listener) {
+        fCanvas.addKeyListener(listener);
+    }
+
+    /**
+     * Remove a key listener from the histogram
+     * @param listener the key listener
+     * @since 3.1
+     */
+    public void removeKeyListener(KeyListener listener) {
+        fCanvas.removeKeyListener(listener);
+    }
+
     // ------------------------------------------------------------------------
     // Helper functions
     // ------------------------------------------------------------------------
index 8c5ae0dd25bdf0022af619af9ac21563914cfae2..d839fb72ca402efe0cf411c3b7bf7376674b0f77 100644 (file)
@@ -14,6 +14,8 @@
 
 package org.eclipse.linuxtools.tmf.ui.views.histogram;
 
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.MouseWheelListener;
 
@@ -24,7 +26,7 @@ import org.eclipse.swt.events.MouseWheelListener;
  * @author Francois Chouinard
  * <p>
  */
-public class HistogramZoom implements MouseWheelListener {
+public class HistogramZoom implements MouseWheelListener, KeyListener {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -68,6 +70,9 @@ public class HistogramZoom implements MouseWheelListener {
 
         fRangeStartTime = fAbsoluteStartTime;
         fRangeDuration = fAbsoluteStartTime + fMinWindowSize;
+
+        histogram.addMouseWheelListener(this);
+        histogram.addKeyListener(this);
     }
 
     // ------------------------------------------------------------------------
@@ -144,10 +149,29 @@ public class HistogramZoom implements MouseWheelListener {
     // ------------------------------------------------------------------------
 
     @Override
-    public synchronized void mouseScrolled(MouseEvent event) {
+    public void mouseScrolled(MouseEvent event) {
         zoom(event.count);
     }
 
+    /**
+     * @since 3.1
+     */
+    @Override
+    public void keyPressed(KeyEvent e) {
+        if (e.character == '+') {
+            zoom(1);
+        } else if (e.character == '-') {
+            zoom(-1);
+        }
+    }
+
+    /**
+     * @since 3.1
+     */
+    @Override
+    public void keyReleased(KeyEvent e) {
+    }
+
     private synchronized void zoom(int nbClicks) {
         // Compute the new time range
         long requestedRange = (nbClicks > 0) ? Math.round(ZOOM_FACTOR * fRangeDuration) : (long) Math.ceil(fRangeDuration * (1.0 / ZOOM_FACTOR));
index b9876f72cdffc4732b285c8d044ba5940cb8f5fb..f3226adc82c91bab59d55b229e3f9f0c7af63e15 100644 (file)
@@ -57,7 +57,6 @@ public class TimeRangeHistogram extends Histogram {
     public TimeRangeHistogram(HistogramView view, Composite parent) {
         super(view, parent);
         fZoom = new HistogramZoom(this, getStartTime(), getTimeLimit());
-        addMouseWheelListener(fZoom);
     }
 
     // ------------------------------------------------------------------------
This page took 0.031819 seconds and 5 git commands to generate.