tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / HistogramZoom.java
index 1b2d88d6944ae28a12fb32ebb3d5dd81a623be07..dc4c806dc2e5ce839ee16c47c81252def52bfe19 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2012 Ericsson
+ * Copyright (c) 2011, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -137,36 +137,35 @@ public class HistogramZoom implements MouseWheelListener {
      * @param duration the duration
      */
     public synchronized void setNewRange(long startTime, long duration) {
-        if (startTime < fAbsoluteStartTime) {
-            startTime = fAbsoluteStartTime;
+        long realStart = startTime;
+
+        if (realStart < fAbsoluteStartTime) {
+            realStart = fAbsoluteStartTime;
         }
 
-        long endTime = startTime + duration;
+        long endTime = realStart + duration;
         if (endTime > fAbsoluteEndTime) {
             endTime = fAbsoluteEndTime;
             if (endTime - duration > fAbsoluteStartTime) {
-                startTime = endTime - duration;
+                realStart = endTime - duration;
             } else {
-                startTime = fAbsoluteStartTime;
+                realStart = fAbsoluteStartTime;
             }
         }
 
-        fRangeStartTime = startTime;
-        fRangeDuration = endTime - startTime;
+        fRangeStartTime = realStart;
+        fRangeDuration = endTime - realStart;
     }
 
     // ------------------------------------------------------------------------
     // MouseWheelListener
     // ------------------------------------------------------------------------
 
-    private long fMouseTimestamp = 0;
-
     @Override
     public synchronized void mouseScrolled(MouseEvent event) {
         if (fScrollCounter == null) {
             fScrollCounter = new MouseScrollCounter(this);
             fScrollCounter.start();
-            fMouseTimestamp = fHistogram.getTimestamp(event.x);
         }
         fScrollCounter.incrementMouseScroll(event.count);
     }
@@ -178,9 +177,8 @@ public class HistogramZoom implements MouseWheelListener {
         // Compute the new time range
         long requestedRange = (nbClicks > 0) ? Math.round(ZOOM_FACTOR * fRangeDuration) : (long) Math.ceil(fRangeDuration * (1.0 / ZOOM_FACTOR));
 
-        // Perform a proportional zoom wrt the mouse position
-        double ratio = ((double) (fMouseTimestamp - fRangeStartTime)) / fRangeDuration;
-        long requestedStart = validateStart(fRangeStartTime + (long) ((fRangeDuration - requestedRange) * ratio));
+        // Distribute delta and adjust for boundaries
+        long requestedStart = validateStart(fRangeStartTime + (fRangeDuration - requestedRange) / 2);
         long requestedEnd = validateEnd(requestedStart, requestedStart + requestedRange);
         requestedStart = validateStart(requestedEnd - requestedRange);
 
@@ -188,23 +186,27 @@ public class HistogramZoom implements MouseWheelListener {
     }
 
     private long validateStart(long start) {
-        if (start < fAbsoluteStartTime) {
-            start = fAbsoluteStartTime;
+        long realStart = start;
+
+        if (realStart < fAbsoluteStartTime) {
+            realStart = fAbsoluteStartTime;
         }
-        if (start > fAbsoluteEndTime) {
-            start = fAbsoluteEndTime - fMinWindowSize;
+        if (realStart > fAbsoluteEndTime) {
+            realStart = fAbsoluteEndTime - fMinWindowSize;
         }
-        return start;
+        return realStart;
     }
 
     private long validateEnd(long start, long end) {
-        if (end > fAbsoluteEndTime) {
-            end = fAbsoluteEndTime;
+        long realEnd = end;
+
+        if (realEnd > fAbsoluteEndTime) {
+            realEnd = fAbsoluteEndTime;
         }
-        if (end < start + fMinWindowSize) {
-            end = start + fMinWindowSize;
+        if (realEnd < start + fMinWindowSize) {
+            realEnd = start + fMinWindowSize;
         }
-        return end;
+        return realEnd;
     }
 
     // ------------------------------------------------------------------------
This page took 0.024878 seconds and 5 git commands to generate.