Fix minor bugs with histogram time range entry.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 4 Jul 2012 19:45:27 +0000 (15:45 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 12 Jul 2012 20:18:48 +0000 (16:18 -0400)
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramUtils.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java

index bf203842a5516319e843470909273fa1d66414b0..f0516fda754d14d7705ae6a0fddceef2d99d00bd 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2011, 2012 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:
  *   William Bourque - Initial API and implementation
  *   Francois Chouinard - Cleanup and refactoring
@@ -19,10 +19,10 @@ import org.eclipse.swt.widgets.Composite;
 
 /**
  * Bunch of conversion utilities.
- * 
+ *
  * @version 1.0
  * @author Francois Chouinard
- * <p>
+ *         <p>
  */
 public abstract class HistogramUtils {
 
@@ -34,8 +34,9 @@ public abstract class HistogramUtils {
      * Format a long representing nanoseconds into a string of the form
      * "[seconds].[nanoseconds]" with the appropriate zero-padding.
      * <p>
-     * 
-     * @param ns the timestamp in nanoseconds
+     *
+     * @param ns
+     *            the timestamp in nanoseconds
      * @return the formatted string
      */
     public static String nanosecondsToString(long ns) {
@@ -45,7 +46,8 @@ public abstract class HistogramUtils {
         int length = time.length();
         if (time.length() > 9) {
             // Just insert the decimal dot
-            time = time.substring(0, length - 9) + "." + time.substring(length - 9); //$NON-NLS-1$
+            time = time.substring(0, length - 9)
+                    + "." + time.substring(length - 9); //$NON-NLS-1$
             return time;
         }
 
@@ -60,8 +62,9 @@ public abstract class HistogramUtils {
     /**
      * Convert a string representing a time to the corresponding long.
      * <p>
-     * 
-     * @param time the string to convert
+     *
+     * @param time
+     *            the string to convert
      * @return the corresponding nanoseconds value
      */
     public static long stringToNanoseconds(String time) {
@@ -72,27 +75,39 @@ public abstract class HistogramUtils {
         try {
             int dot = buffer.indexOf("."); //$NON-NLS-1$
 
-            // Prepend a "." if none was found (assume ns)
+            // if no . was found, assume ns
             if (dot == -1) {
-                buffer.insert(0, "."); //$NON-NLS-1$
-                dot = 0;
+                // nanoseconds are the base unit.
+                if (time.length() > 9) {
+                    long nanos = Long
+                            .parseLong(time.substring(time.length() - 9));
+                    long secs = Long.parseLong(time.substring(0,
+                            time.length() - 9));
+                    result = (secs * 1000000000) + nanos;
+                } else {
+                    result = Long.parseLong(time);
+                }
+
+            } else {
+                // Zero-pad the string for nanoseconds
+                for (int i = buffer.length() - dot - 1; i < 9; i++) {
+                    buffer.append("0"); //$NON-NLS-1$
+                }
+
+                // Remove the extra decimals if present
+                int nbDecimals = buffer.substring(dot + 1).length();
+                if (nbDecimals > 9) {
+                    buffer.delete(buffer.substring(0, dot + 1 + 9).length(),
+                            buffer.length());
+                }
+
+                // Do the conversion
+                long seconds = (dot > 0) ? Long.parseLong(buffer.substring(0,
+                        dot)) : 0;
+                seconds = Math.abs(seconds);
+                long nanosecs = Long.parseLong(buffer.substring(dot + 1));
+                result = (seconds * 1000000000) + nanosecs;
             }
-
-            // Zero-pad the string for nanoseconds
-            for (int i = buffer.length() - dot - 1; i < 9; i++)
-                buffer.append("0"); //$NON-NLS-1$
-
-            // Remove the extra decimals if present
-            int nbDecimals = buffer.substring(dot + 1).length();
-            if (nbDecimals > 9)
-                buffer.delete(buffer.substring(0, dot + 1 + 9).length(), buffer.length());
-
-            // Do the conversion
-            long seconds = (dot > 0) ? Long.parseLong(buffer.substring(0, dot)) : 0;
-            seconds = Math.abs(seconds);
-            long nanosecs = Long.parseLong(buffer.substring(dot + 1));
-            result = seconds * 1000000000 + nanosecs;
-
         } catch (NumberFormatException e) {
             // TODO: Find something interesting to say
         }
@@ -103,10 +118,12 @@ public abstract class HistogramUtils {
     /**
      * Calculate the width of a String.
      * <p>
-     * 
-     * @param parent The control used as reference
-     * @param text The Text to measure
-     * 
+     *
+     * @param parent
+     *            The control used as reference
+     * @param text
+     *            The Text to measure
+     *
      * @return The result size
      */
     public static int getTextSizeInControl(Composite parent, String text) {
index 6ad857d434eb2c9aa58f9dcb85d4261ae67cf14d..0601b5eb0011cce75d38fbdd03d5c15b85787cd3 100644 (file)
@@ -1,15 +1,15 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2010, 2011, 2012 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:
  *   William Bourque - Initial API and implementation
  *   Yuriy Vashchuk - GUI reorganisation, simplification and some related code improvements.
- *   Yuriy Vashchuk - Histograms optimisation.   
+ *   Yuriy Vashchuk - Histograms optimisation.
  *   Yuriy Vashchuk - Histogram Canvas Heritage correction
  *   Francois Chouinard - Cleanup and refactoring
  *   Francois Chouinard - Moved from LTTng to TMF
@@ -114,10 +114,10 @@ public class HistogramView extends TmfView {
 
     @Override
     public void dispose() {
-        if (fTimeRangeRequest != null && !fTimeRangeRequest.isCompleted()) {
+        if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
             fTimeRangeRequest.cancel();
         }
-        if (fFullTraceRequest != null && !fFullTraceRequest.isCompleted()) {
+        if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
             fFullTraceRequest.cancel();
         }
         fFullTraceHistogram.dispose();
@@ -246,8 +246,9 @@ public class HistogramView extends TmfView {
 
         // Load the experiment if present
         fCurrentExperiment = (TmfExperiment<ITmfEvent>) TmfExperiment.getCurrentExperiment();
-        if (fCurrentExperiment != null)
+        if (fCurrentExperiment != null) {
             loadExperiment();
+        }
     }
 
     @Override
@@ -326,21 +327,26 @@ public class HistogramView extends TmfView {
     public synchronized void updateTimeRange(long newDuration) {
         if (fCurrentExperiment != null) {
             long delta = newDuration - fWindowSpan;
-            long newStartTime = fWindowStartTime + delta / 2;
+            long newStartTime = fWindowStartTime + (delta / 2);
             setNewRange(newStartTime, newDuration);
         }
     }
 
     private void setNewRange(long startTime, long duration) {
-        if (startTime < fExperimentStartTime)
+        if (startTime < fExperimentStartTime) {
             startTime = fExperimentStartTime;
+        }
 
         long endTime = startTime + duration;
+        if( endTime < startTime ) {
+            endTime = fExperimentEndTime;
+            startTime = fExperimentStartTime;
+        }
         if (endTime > fExperimentEndTime) {
             endTime = fExperimentEndTime;
-            if (endTime - duration > fExperimentStartTime)
+            if ((endTime - duration) > fExperimentStartTime) {
                 startTime = endTime - duration;
-            else {
+            else {
                 startTime = fExperimentStartTime;
             }
         }
@@ -508,7 +514,7 @@ public class HistogramView extends TmfView {
     }
 
     private void sendTimeRangeRequest(long startTime, long endTime) {
-        if (fTimeRangeRequest != null && !fTimeRangeRequest.isCompleted()) {
+        if ((fTimeRangeRequest != null) && !fTimeRangeRequest.isCompleted()) {
             fTimeRangeRequest.cancel();
         }
         TmfTimestamp startTS = new TmfTimestamp(startTime, TIME_SCALE);
@@ -524,7 +530,7 @@ public class HistogramView extends TmfView {
     }
 
     private void sendFullRangeRequest(TmfTimeRange fullRange) {
-        if (fFullTraceRequest != null && !fFullTraceRequest.isCompleted()) {
+        if ((fFullTraceRequest != null) && !fFullTraceRequest.isCompleted()) {
             fFullTraceRequest.cancel();
         }
         int cacheSize = fCurrentExperiment.getCacheSize();
This page took 0.028324 seconds and 5 git commands to generate.