ctf: fix windows regression
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / xycharts / TmfXYChartViewer.java
index 680b93e822ef7364c8acf64553e4d2acc666735f..ceb24ab4a834043fc5108a1c5bd8546030e3db76 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2013, 2014 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2013, 2015 Ericsson, École Polytechnique de Montréal
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -16,10 +16,10 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.tracecompass.tmf.core.signal.TmfRangeSynchSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.ui.viewers.TmfTimeViewer;
 import org.swtchart.Chart;
@@ -39,11 +39,6 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
-    /**
-     * The offset to apply to any x position. This offset ensures better
-     * precision when converting long to double and back.
-     */
-    private long fTimeOffset;
     /** The SWT Chart reference */
     private Chart fSwtChart;
     /** The mouse selection provider */
@@ -56,6 +51,12 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
     private TmfBaseProvider fToolTipProvider;
     /** The middle mouse drag provider */
     private TmfBaseProvider fMouseDragProvider;
+    /**
+     * Whether or not to send time alignment signals. This should be set to true
+     * for viewers that are part of an aligned view.
+     */
+    private boolean fSendTimeAlignSignals = false;
+
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -107,16 +108,6 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
     // ------------------------------------------------------------------------
     // Getter/Setters
     // ------------------------------------------------------------------------
-    /**
-     * Sets the time offset to apply.
-     * @see ITmfChartTimeProvider#getTimeOffset()
-     *
-     * @param timeOffset
-     *            The time offset to apply
-     */
-    protected void setTimeOffset(long timeOffset) {
-        fTimeOffset = timeOffset;
-    }
 
     /**
      * Sets the SWT Chart reference
@@ -214,7 +205,7 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
 
     @Override
     public long getTimeOffset() {
-        return fTimeOffset;
+        return getWindowStartTime() - 1;
     }
 
     // ------------------------------------------------------------------------
@@ -297,11 +288,11 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
      * Signal handler for handling of the time synch signal.
      *
      * @param signal
-     *            The time synch signal {@link TmfTimeSynchSignal}
+     *            The time synch signal {@link TmfSelectionRangeUpdatedSignal}
      */
     @Override
     @TmfSignalHandler
-    public void selectionRangeUpdated(TmfTimeSynchSignal signal) {
+    public void selectionRangeUpdated(TmfSelectionRangeUpdatedSignal signal) {
         super.selectionRangeUpdated(signal);
         if ((signal.getSource() != this) && (getTrace() != null)) {
             if (fMouseSelectionProvider != null) {
@@ -311,15 +302,15 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
     }
 
     /**
-     * Signal handler for handling of the time range synch signal.
+     * Signal handler for handling of the window range signal.
      *
      * @param signal
-     *            The time range synch signal {@link TmfRangeSynchSignal}
+     *            The {@link TmfWindowRangeUpdatedSignal}
      */
     @Override
     @TmfSignalHandler
-    public void timeRangeUpdated(TmfRangeSynchSignal signal) {
-        super.timeRangeUpdated(signal);
+    public void windowRangeUpdated(TmfWindowRangeUpdatedSignal signal) {
+        super.windowRangeUpdated(signal);
         updateContent();
     }
 
@@ -369,4 +360,78 @@ public abstract class TmfXYChartViewer extends TmfTimeViewer implements ITmfChar
         return display;
     }
 
+    /**
+     * Get the offset of the point area, relative to the XY chart viewer
+     * control. We consider the point area to be from where the first point
+     * could be drawn to where the last point could be drawn.
+     *
+     * @return the offset in pixels
+     *
+     * @since 1.0
+     */
+    public int getPointAreaOffset() {
+
+        int pixelCoordinate = 0;
+        IAxis[] xAxes = getSwtChart().getAxisSet().getXAxes();
+        ISeries[] series = fSwtChart.getSeriesSet().getSeries();
+        if ((xAxes.length > 0) && (series.length > 0) &&
+                (series[0].getXSeries() != null) && (series[0].getXSeries().length > 0)) {
+            IAxis axis = xAxes[0];
+            // All series have the same X series
+            double[] xSeries = series[0].getXSeries();
+            pixelCoordinate = axis.getPixelCoordinate(xSeries[0]);
+        }
+        return getSwtChart().toControl(getSwtChart().getPlotArea().toDisplay(pixelCoordinate, 0)).x;
+    }
+
+    /**
+     * Get the width of the point area. We consider the point area to be from
+     * where the first point could be drawn to where the last point could be
+     * drawn. The point area differs from the plot area because there might be a
+     * gap between where the plot area start and where the fist point is drawn.
+     * This also matches the width that the use can select.
+     *
+     * @return the width in pixels
+     *
+     * @since 1.0
+     */
+    public int getPointAreaWidth() {
+        IAxis[] xAxes = getSwtChart().getAxisSet().getXAxes();
+        ISeries[] series = fSwtChart.getSeriesSet().getSeries();
+        if ((xAxes.length > 0) && (series.length > 0) &&
+                (series[0].getXSeries() != null) && (series[0].getXSeries().length > 0)) {
+            IAxis axis = xAxes[0];
+            // All series have the same X series
+            double[] xSeries = series[0].getXSeries();
+            int x1 = getPointAreaOffset();
+            int x2 = axis.getPixelCoordinate(xSeries[xSeries.length - 1]);
+            x2 = getSwtChart().toControl(getSwtChart().getPlotArea().toDisplay(x2, 0)).x;
+            int width = x2 - x1;
+            return width;
+        }
+
+        return getSwtChart().getPlotArea().getSize().x;
+    }
+
+    /**
+     * Sets whether or not to send time alignment signals. This should be set to
+     * true for viewers that are part of an aligned view.
+     *
+     * @param sendTimeAlignSignals
+     *            whether or not to send time alignment signals
+     * @since 1.0
+     */
+    public void setSendTimeAlignSignals(boolean sendTimeAlignSignals) {
+        fSendTimeAlignSignals = sendTimeAlignSignals;
+    }
+
+    /**
+     * Returns whether or not to send time alignment signals.
+     *
+     * @return whether or not to send time alignment signals.
+     * @since 1.0
+     */
+    public boolean isSendTimeAlignSignals() {
+        return fSendTimeAlignSignals;
+    }
 }
This page took 0.040235 seconds and 5 git commands to generate.