tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / histogram / FullTraceHistogram.java
index c8f915aee213a12adf01fa918effd0e6c1882f51..9560e297d5fdeaa0a1634b329ad78cc241f76d7e 100644 (file)
@@ -1,15 +1,14 @@
 /*******************************************************************************
- * 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
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  * Contributors:
  *   Francois Chouinard - Initial API and implementation
  *   Bernd Hufmann - Changed to updated histogram data model
- *   Francois Chouinard - Initial API and implementation
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.views.histogram;
@@ -25,11 +24,12 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 
 /**
- * <b><u>FullTraceHistogram</u></b>
- * <p>
- * A histogram that displays the full trace.
+ * A histogram widget that displays the event distribution of a whole trace.
  * <p>
  * It also features a selected range window that can be dragged and zoomed.
+ *
+ * @version 1.1
+ * @author Francois Chouinard
  */
 public class FullTraceHistogram extends Histogram implements MouseMoveListener {
 
@@ -46,13 +46,19 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
 
     private final HistogramZoom fZoom;
 
-    private long fRangeStartTime;
+    private long fRangeStartTime = 0L;
     private long fRangeDuration;
 
     // ------------------------------------------------------------------------
     // Construction
     // ------------------------------------------------------------------------
 
+    /**
+     * Full Constructor
+     *
+     * @param view A reference to the parent histogram view
+     * @param parent A reference to the parent composite
+     */
     public FullTraceHistogram(HistogramView view, Composite parent) {
         super(view, parent);
         fZoom = new HistogramZoom(this, fCanvas, getStartTime(), getTimeLimit());
@@ -69,10 +75,33 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
     // Operations
     // ------------------------------------------------------------------------
 
+    @Override
+    public void clear() {
+        fRangeStartTime = 0L;
+        fRangeDuration = 0L;
+        if (fZoom != null) {
+            fZoom.setFullRange(0L, 0L);
+            fZoom.setNewRange(0L, 0L);
+        }
+        super.clear();
+    }
+
+    /**
+     * Sets the time range of the full histogram.
+     *
+     * @param startTime A start time
+     * @param endTime A end time
+     */
     public void setFullRange(long startTime, long endTime) {
         fZoom.setFullRange(startTime, endTime);
     }
 
+    /**
+     * Sets the selected time range.
+     *
+     * @param startTime The histogram start time
+     * @param duration The histogram duration
+     */
     public void setTimeRange(long startTime, long duration) {
         fRangeStartTime = startTime;
         fRangeDuration = duration;
@@ -94,15 +123,6 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
 
     @Override
     public void mouseDown(MouseEvent event) {
-        // Check if we are outside the time range; if so, just set the current
-        // event
-        long timestamp = getTimestamp(event.x);
-        if (timestamp < fZoom.getStartTime() || timestamp > fZoom.getEndTime()) {
-            super.mouseDown(event);
-            return;
-        }
-
-        // Otherwise start moving the range window
         fMouseDown = true;
         fStartPosition = event.x;
     }
@@ -111,22 +131,32 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
     public void mouseUp(MouseEvent event) {
         if (fMouseDown) {
             fMouseDown = false;
-            ((HistogramView) fParentView).updateTimeRange(fRangeStartTime, fRangeStartTime + fZoom.getDuration());
+            // Check if mouse click without move; if so, just set the current event time
+            if (event.x == fStartPosition) {
+                super.mouseDown(event);
+                return;
+            }
+
+            ((HistogramView) fParentView).updateTimeRange(fRangeStartTime, fRangeStartTime + fRangeDuration);
+
         }
     }
 
+
     // ------------------------------------------------------------------------
     // MouseMoveListener
     // ------------------------------------------------------------------------
 
     @Override
     public void mouseMove(MouseEvent event) {
+
         if (fMouseDown) {
             int nbBuckets = event.x - fStartPosition;
             long delta = nbBuckets * fScaledData.fBucketDuration;
             long newStart = fZoom.getStartTime() + delta;
-            if (newStart < getStartTime())
+            if (newStart < getStartTime()) {
                 newStart = getStartTime();
+            }
             long newEnd = newStart + fZoom.getDuration();
             if (newEnd > getEndTime()) {
                 newEnd = getEndTime();
@@ -151,8 +181,8 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
         Image rangeRectangleImage = new Image(image.getDevice(), image, SWT.IMAGE_COPY);
         GC rangeWindowGC = new GC(rangeRectangleImage);
 
-        if (fScaledData != null && fRangeStartTime != 0) {
-            drawTimeRangeWindow(rangeWindowGC, rangeRectangleImage);
+        if ((fScaledData != null) && (fRangeStartTime != 0)) {
+            drawTimeRangeWindow(rangeWindowGC);
         }
 
         // Draws the buffer image onto the canvas.
@@ -162,16 +192,16 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
         rangeRectangleImage.dispose();
     }
 
-    private void drawTimeRangeWindow(GC imageGC, Image image) {
+    private void drawTimeRangeWindow(GC imageGC) {
 
         // Map times to histogram coordinates
-        long bucketSpan = fScaledData.fBucketDuration;
+        long bucketSpan = Math.max(fScaledData.fBucketDuration, 1);
         int rangeWidth = (int) (fRangeDuration / bucketSpan);
 
         int left = (int) ((fRangeStartTime - fDataModel.getFirstBucketTime()) / bucketSpan);
         int right = left + rangeWidth;
         int center = (left + right) / 2;
-        int height = fCanvas.getSize().y - 2;
+        int height = fCanvas.getSize().y;
 
         // Draw the selection window
         imageGC.setForeground(fTimeRangeColor);
@@ -190,9 +220,9 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
         imageGC.setLineWidth(1);
         imageGC.setLineStyle(SWT.LINE_SOLID);
 
-        int chHalfWidth = ((rangeWidth < 60) ? rangeWidth * 2 / 3 : 40) / 2;
+        int chHalfWidth = ((rangeWidth < 60) ? (rangeWidth * 2) / 3 : 40) / 2;
         imageGC.drawLine(center - chHalfWidth, height / 2, center + chHalfWidth, height / 2);
-        imageGC.drawLine(center, height / 2 - chHalfWidth, center, height / 2 + chHalfWidth);
+        imageGC.drawLine(center, (height / 2) - chHalfWidth, center, (height / 2) + chHalfWidth);
     }
 
 }
This page took 0.025574 seconds and 5 git commands to generate.