/*******************************************************************************
- * 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
* Contributors:
* Francois Chouinard - Initial API and implementation
* Francois Chouinard - Moved from LTTng to TMF
+ * Patrick Tasse - Update for mouse wheel zoom
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.views.histogram;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseWheelListener;
-import org.eclipse.swt.widgets.Canvas;
/**
* Class to handle zooming within histogram windows..
// ------------------------------------------------------------------------
private final Histogram fHistogram;
- private final Canvas fCanvas;
private long fAbsoluteStartTime;
private long fAbsoluteEndTime;
private long fRangeStartTime;
private long fRangeDuration;
- private MouseScrollCounter fScrollCounter;
-
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
*
* @param histogram
* The parent histogram object
- * @param canvas
- * The canvas
* @param start
* The start time of the zoom area
* @param end
* The end time of the zoom area
+ * @since 2.0
*/
- public HistogramZoom(Histogram histogram, Canvas canvas, long start,
- long end) {
+ public HistogramZoom(Histogram histogram, long start, long end) {
fHistogram = histogram;
- fCanvas = canvas;
fAbsoluteStartTime = start;
fAbsoluteEndTime = end;
- fMinWindowSize = fCanvas.getBounds().x;
+ fMinWindowSize = 0;
fRangeStartTime = fAbsoluteStartTime;
fRangeDuration = fAbsoluteStartTime + fMinWindowSize;
-
- canvas.addMouseWheelListener(this);
}
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- /**
- * Stops the zooming (multiple consecutive execution)
- */
- public synchronized void stop() {
- if (fScrollCounter != null) {
- fScrollCounter.interrupt();
- fScrollCounter = null;
- }
- }
-
/**
* The the full time range of the histogram
*
@Override
public synchronized void mouseScrolled(MouseEvent event) {
- if (fScrollCounter == null) {
- fScrollCounter = new MouseScrollCounter(this);
- fScrollCounter.start();
- }
- fScrollCounter.incrementMouseScroll(event.count);
+ zoom(event.count);
}
private synchronized void zoom(int nbClicks) {
- // The job is finished
- fScrollCounter = null;
-
// Compute the new time range
long requestedRange = (nbClicks > 0) ? Math.round(ZOOM_FACTOR * fRangeDuration) : (long) Math.ceil(fRangeDuration * (1.0 / ZOOM_FACTOR));
}
return realEnd;
}
-
- // ------------------------------------------------------------------------
- // DelayedMouseScroll
- // ------------------------------------------------------------------------
-
- private static class MouseScrollCounter extends Thread {
-
- // --------------------------------------------------------------------
- // Constants
- // --------------------------------------------------------------------
-
- private final static long QUIET_TIME = 100L;
- private final static long POLLING_INTERVAL = 10L;
-
- // --------------------------------------------------------------------
- // Attributes
- // --------------------------------------------------------------------
-
- private HistogramZoom fZoom = null;
-
- private long fLastPoolTime = 0L;
- private int nbScrollClick = 0;
-
- // --------------------------------------------------------------------
- // Constructors
- // --------------------------------------------------------------------
-
- /**
- * Constructor of inner class to handle consecutive scrolls of mouse wheel.
- * @param zoom the histogram zoom reference
- */
- public MouseScrollCounter(HistogramZoom zoom) {
- fZoom = zoom;
- fLastPoolTime = System.currentTimeMillis();
- }
-
- // --------------------------------------------------------------------
- // Operation
- // --------------------------------------------------------------------
-
- /**
- * Increments the number of scroll clicks.
- * @param nbScrolls the number to add to the current value
- */
- public void incrementMouseScroll(int nbScrolls) {
- fLastPoolTime = System.currentTimeMillis();
- nbScrollClick += nbScrolls;
- }
-
- // --------------------------------------------------------------------
- // Thread
- // --------------------------------------------------------------------
-
- @Override
- public void run() {
- while ((System.currentTimeMillis() - fLastPoolTime) < QUIET_TIME) {
- try {
- Thread.sleep(POLLING_INTERVAL);
- } catch (Exception e) {
- return;
- }
- }
- // Done waiting. Notify the histogram.
- if (!isInterrupted()) {
- fZoom.zoom(nbScrollClick);
- }
- }
- }
-
}