Clear text controls and labels when histogram is empty
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 17 Dec 2012 20:29:20 +0000 (15:29 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 19 Dec 2012 15:26:35 +0000 (10:26 -0500)
- Do not display default time (epoch) for text controls and
start/end labels when histogram is initialized or when last trace is
closed
- Prevent user update of text controls when histogram is empty
- Fix layout problem on time format update

Change-Id: I9285853b127e0dca0fa0c2035fea1c414390a759
Reviewed-on: https://git.eclipse.org/r/9273
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Bernd Hufmann <bhufmann@gmail.com>
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
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/HistogramCurrentTimeControl.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramTimeRangeControl.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java

index d80b90aac127c5bbc2e5fa7b92290f2ee44557cf..7b2ff4c8cd1969a41ff92b147e72064ab0d12550 100644 (file)
@@ -36,8 +36,6 @@ import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -104,7 +102,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
      */
     protected TmfView fParentView;
 
-    private Composite fParent;
+    private Composite fComposite;
     private Font fFont;
 
     // Histogram text fields
@@ -145,9 +143,8 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
      */
     public Histogram(final TmfView view, final Composite parent) {
         fParentView = view;
-        fParent = parent;
 
-        createWidget(parent);
+        fComposite = createWidget(parent);
         fDataModel = new HistogramDataModel();
         fDataModel.addHistogramListener(this);
         clear();
@@ -171,7 +168,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
         fDataModel.removeHistogramListener(this);
     }
 
-    private void createWidget(final Composite parent) {
+    private Composite createWidget(final Composite parent) {
 
         final Color labelColor = parent.getBackground();
         fFont = adjustFont(parent);
@@ -253,7 +250,6 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
         fTimeRangeStartText = new Text(composite, SWT.READ_ONLY);
         fTimeRangeStartText.setFont(fFont);
         fTimeRangeStartText.setBackground(labelColor);
-        fTimeRangeStartText.setText(TmfTimestamp.ZERO.toString());
         fTimeRangeStartText.setLayoutData(gridData);
 
         // Window range end time
@@ -263,8 +259,9 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
         fTimeRangeEndText = new Text(composite, SWT.READ_ONLY);
         fTimeRangeEndText.setFont(fFont);
         fTimeRangeEndText.setBackground(labelColor);
-        fTimeRangeEndText.setText(TmfTimestamp.ZERO.toString());
         fTimeRangeEndText.setLayoutData(gridData);
+
+        return composite;
     }
 
     private static Font adjustFont(final Composite composite) {
@@ -464,9 +461,14 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
                         synchronized(fDataModel) {
                             if (fScaledData != null) {
                                 fCanvas.redraw();
-                                // Display histogram and update X-,Y-axis labels
-                                fTimeRangeStartText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime()));
-                                fTimeRangeEndText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()));
+                                if (fDataModel.getNbEvents() != 0) {
+                                    // Display histogram and update X-,Y-axis labels
+                                    fTimeRangeStartText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime()));
+                                    fTimeRangeEndText.setText(TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime()));
+                                } else {
+                                    fTimeRangeStartText.setText(""); //$NON-NLS-1$
+                                    fTimeRangeEndText.setText(""); //$NON-NLS-1$
+                                }
                                 fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue));
                                 // The Y-axis area might need to be re-sized
                                 fMaxNbEventsText.getParent().layout();
@@ -675,42 +677,17 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
      */
     @TmfSignalHandler
     public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) {
-        Point size = fTimeRangeStartText.getSize();
+        if (fDataModel.getNbEvents() == 0) {
+            return;
+        }
+
         String newTS = TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getFirstBucketTime());
-        size.x = getTextSize(newTS);
-        fTimeRangeStartText.setSize(size);
         fTimeRangeStartText.setText(newTS);
 
         newTS = TmfTimestampFormat.getDefaulTimeFormat().format(fDataModel.getEndTime());
-        Rectangle rect = fTimeRangeEndText.getBounds();
-        int newWidth = getTextSize(newTS);
-        rect.x += rect.width - newWidth;
-        rect.width = newWidth;
-        fTimeRangeEndText.setBounds(rect);
         fTimeRangeEndText.setText(newTS);
-    }
-
-    /**
-     * Compute the width of a String.
-     *
-     * @param text the Text to measure
-     * @return The result size
-     * @since 2.0
-     */
-    private int getTextSize(final String text) {
-        GC controlGC = new GC(fParent);
-        controlGC.setFont(fFont);
-
-        int textSize = 0;
-        for (int pos = 0; pos < text.length(); pos++) {
-            textSize += controlGC.getAdvanceWidth(text.charAt(pos));
-        }
-        // Add an extra space
-        textSize += controlGC.getAdvanceWidth(' ');
-
-        controlGC.dispose();
 
-        return textSize;
+        fComposite.layout();
     }
 
 }
index 91b7d35cf9491043586364ce6f11391b719df483..b9043e99f1a7dfa8eee447f74eab266a63378427 100644 (file)
@@ -23,7 +23,6 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimestampFormat;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
-import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.swt.widgets.Composite;
 
@@ -35,12 +34,6 @@ import org.eclipse.swt.widgets.Composite;
  */
 public class HistogramCurrentTimeControl extends HistogramTextControl {
 
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
-
-    private long fTraceStartTime;
-
     // ------------------------------------------------------------------------
     // Construction
     // ------------------------------------------------------------------------
@@ -75,6 +68,10 @@ public class HistogramCurrentTimeControl extends HistogramTextControl {
 
     @Override
     protected void updateValue() {
+        if (getValue() == Long.MIN_VALUE) {
+            fTextValue.setText(""); //$NON-NLS-1$
+            return;
+        }
         String string = fTextValue.getText();
         long value = 0;
         try {
@@ -103,22 +100,11 @@ public class HistogramCurrentTimeControl extends HistogramTextControl {
 
     @Override
     public void setValue(long time) {
-        super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString());
-    }
-
-    // ------------------------------------------------------------------------
-    // Signal Handlers
-    // ------------------------------------------------------------------------
-
-    /**
-     * Update the initial time value
-     *
-     * @param signal the time range signal
-     * @since 2.0
-     */
-    @TmfSignalHandler
-    public void traceUpdated(final TmfTraceUpdatedSignal signal) {
-        fTraceStartTime = signal.getTrace().getTimeRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
+        if (time != Long.MIN_VALUE) {
+            super.setValue(time, new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE).toString());
+        } else {
+            super.setValue(time, ""); //$NON-NLS-1$
+        }
     }
 
     // ------------------------------------------------------------------------
index 5a8c5cedfe6138ca58eae99c3996e241adb326f3..fb7b4546ebc6716e7010cbca6a08b9dc8465f4c2 100644 (file)
@@ -70,6 +70,10 @@ public class HistogramTimeRangeControl extends HistogramTextControl {
      */
     @Override
     protected void updateValue() {
+        if (getValue() == Long.MIN_VALUE) {
+            fTextValue.setText(""); //$NON-NLS-1$
+            return;
+        }
         String string = fTextValue.getText();
         long value = getValue();
         try {
@@ -81,8 +85,12 @@ public class HistogramTimeRangeControl extends HistogramTextControl {
 
     @Override
     public void setValue(long time) {
-        ITmfTimestamp ts = new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE);
-        super.setValue(time, ts.toString(TmfTimestampFormat.getDefaulIntervalFormat()));
+        if (time != Long.MIN_VALUE) {
+            ITmfTimestamp ts = new TmfTimestamp(time, ITmfTimestamp.NANOSECOND_SCALE);
+            super.setValue(time, ts.toString(TmfTimestampFormat.getDefaulIntervalFormat()));
+        } else {
+            super.setValue(time, ""); //$NON-NLS-1$
+        }
     }
 
     // ------------------------------------------------------------------------
index 617d2d0434fa64a5b55d99b5d74a0f36d230a95c..e1f144773383b3da210062e89a99ffba0dd26a8a 100644 (file)
@@ -178,7 +178,7 @@ public class HistogramView extends TmfView {
         gridData.verticalAlignment = SWT.CENTER;
         fCurrentEventTimeControl = new HistogramCurrentTimeControl(this, controlsComposite, currentEventLabel, 0L);
         fCurrentEventTimeControl.setLayoutData(gridData);
-        fCurrentEventTimeControl.setValue(0L);
+        fCurrentEventTimeControl.setValue(Long.MIN_VALUE);
 
         // Window span time control
         gridData = new GridData();
@@ -186,7 +186,7 @@ public class HistogramView extends TmfView {
         gridData.verticalAlignment = SWT.CENTER;
         fTimeSpanControl = new HistogramTimeRangeControl(this, controlsComposite, windowSpanLabel, 0L);
         fTimeSpanControl.setLayoutData(gridData);
-        fTimeSpanControl.setValue(0L);
+        fTimeSpanControl.setValue(Long.MIN_VALUE);
 
         // --------------------------------------------------------------------
         // Time range histogram
@@ -426,9 +426,9 @@ public class HistogramView extends TmfView {
         // Clear the UI widgets
         fFullTraceHistogram.clear();
         fTimeRangeHistogram.clear();
-        fCurrentEventTimeControl.setValue(0L);
+        fCurrentEventTimeControl.setValue(Long.MIN_VALUE);
 
-        fTimeSpanControl.setValue(0);
+        fTimeSpanControl.setValue(Long.MIN_VALUE);
     }
 
     /**
This page took 0.031064 seconds and 5 git commands to generate.