Class Axis

  • All Implemented Interfaces:
    org.eclipse.draw2d.IFigure, IScaleProvider
    Direct Known Subclasses:
    DAxis

    public class Axis
    extends LinearScale
    The axis figure.
    • Field Detail

      • ZOOM_RATIO

        static final double ZOOM_RATIO
        The ratio of the shrink/expand area for one zoom.
        See Also:
        Constant Field Values
      • title

        private java.lang.String title
      • traceList

        private final java.util.List<Trace> traceList
      • grid

        private Grid grid
      • titleFont

        private org.eclipse.swt.graphics.Font titleFont
      • titleFontData

        private org.eclipse.swt.graphics.FontData titleFontData
      • scaleFontData

        private org.eclipse.swt.graphics.FontData scaleFontData
      • autoScale

        private boolean autoScale
      • showMajorGrid

        private boolean showMajorGrid
      • showMinorGrid

        private boolean showMinorGrid
      • isInverted

        private boolean isInverted
      • majorGridColor

        private org.eclipse.swt.graphics.Color majorGridColor
      • minorGridColor

        private org.eclipse.swt.graphics.Color minorGridColor
      • dashGridLine

        private boolean dashGridLine
      • autoScaleThreshold

        private double autoScaleThreshold
      • listeners

        protected final java.util.List<IAxisListener> listeners
      • start

        private org.eclipse.draw2d.geometry.Point start
      • end

        private org.eclipse.draw2d.geometry.Point end
      • armed

        private boolean armed
      • startRange

        private Range startRange
      • grabbing

        private final org.eclipse.swt.graphics.Cursor grabbing
      • revertBackColor

        private org.eclipse.swt.graphics.Color revertBackColor
      • colorRGB

        private org.eclipse.swt.graphics.RGB colorRGB
      • majorGridColorRGB

        private org.eclipse.swt.graphics.RGB majorGridColorRGB
      • previousZoomType

        private ZoomType previousZoomType
        Field used to remember the previous zoom type used
    • Constructor Detail

      • Axis

        public Axis​(java.lang.String title,
                    boolean yAxis)
        Constructor
        Parameters:
        title - title of the axis
        yAxis - true if this is the Y-Axis, false if this is the X-Axis.
    • Method Detail

      • setFont

        public void setFont​(org.eclipse.swt.graphics.Font font)
        Specified by:
        setFont in interface org.eclipse.draw2d.IFigure
        Overrides:
        setFont in class LinearScale
      • getTitleFontData

        public org.eclipse.swt.graphics.FontData getTitleFontData()
      • getScaleFontData

        public org.eclipse.swt.graphics.FontData getScaleFontData()
      • addListener

        public void addListener​(IAxisListener listener)
      • removeListener

        public boolean removeListener​(IAxisListener listener)
      • fireRevalidated

        protected void fireRevalidated()
      • fireAxisRangeChanged

        protected void fireAxisRangeChanged​(Range old_range,
                                            Range new_range)
      • setRange

        public void setRange​(double lower,
                             double upper)
        Description copied from class: AbstractScale
        set the scale range
        Overrides:
        setRange in class AbstractScale
        Parameters:
        lower - the lower limit
        upper - the upper limit
      • setInverted

        public void setInverted​(boolean isInverted)
        Inverts the axis if set to True
        Parameters:
        isInverted -
      • isInverted

        public boolean isInverted()
        Returns True if axis is inverted, False otherwise
        Returns:
      • setVisible

        public void setVisible​(boolean visible)
        Specified by:
        setVisible in interface org.eclipse.draw2d.IFigure
        Overrides:
        setVisible in class org.eclipse.draw2d.Figure
      • setForegroundColor

        public void setForegroundColor​(org.eclipse.swt.graphics.Color color)
        Specified by:
        setForegroundColor in interface org.eclipse.draw2d.IFigure
        Overrides:
        setForegroundColor in class LinearScale
      • setMinorTicksVisible

        public void setMinorTicksVisible​(boolean minorTicksVisible)
        Overrides:
        setMinorTicksVisible in class AbstractScale
        Parameters:
        minorTicksVisible - the minorTicksVisible to set
      • getForegroundColorRGB

        public org.eclipse.swt.graphics.RGB getForegroundColorRGB()
      • fireAxisForegroundColorChanged

        private void fireAxisForegroundColorChanged​(org.eclipse.swt.graphics.Color oldColor,
                                                    org.eclipse.swt.graphics.Color newColor)
      • setBackgroundColor

        public void setBackgroundColor​(org.eclipse.swt.graphics.Color bg)
        Specified by:
        setBackgroundColor in interface org.eclipse.draw2d.IFigure
        Overrides:
        setBackgroundColor in class org.eclipse.draw2d.Figure
      • getPreferredSize

        public org.eclipse.draw2d.geometry.Dimension getPreferredSize​(int wHint,
                                                                      int hHint)
        Specified by:
        getPreferredSize in interface org.eclipse.draw2d.IFigure
        Overrides:
        getPreferredSize in class LinearScale
      • paintClientArea

        protected void paintClientArea​(org.eclipse.draw2d.Graphics graphics)
        Overrides:
        paintClientArea in class org.eclipse.draw2d.Figure
      • getTraceDataRange

        public Range getTraceDataRange()
        Returns:
        Range that reflects the minimum and maximum value of all traces on this axis. Returns null if there is no trace data.
      • performAutoScale

        public boolean performAutoScale​(boolean force)
        Perform an auto-scale: Axis limits are set to the value range of the traces on this axis. Includes some optimization: Axis range is set a little wider than exact trace data range. When auto-scale would only perform a minor axis adjustment, axis is left unchanged.
        Parameters:
        force - If true, the axis will be auto-scaled by force regardless the autoScale field. Otherwise, it will use the autoScale field to judge whether an auto-scale will be performed.
        Returns:
        true if the axis is repainted due to range change.
        See Also:
        autoScaleThreshold
      • addTrace

        public void addTrace​(Trace trace)
        Add a trace to the axis.
        Parameters:
        trace - the trace to be added.
      • removeTrace

        public boolean removeTrace​(Trace trace)
        Remove a trace from the axis.
        Parameters:
        trace -
        Returns:
        true if this axis contained the specified trace
      • setTitle

        public void setTitle​(java.lang.String title)
        Parameters:
        title - the title to set
      • fireAxisTitleChanged

        private void fireAxisTitleChanged​(java.lang.String oldTitle,
                                          java.lang.String newTitle)
      • getTitle

        public java.lang.String getTitle()
        Returns:
        the title
      • isAutoScale

        public boolean isAutoScale()
        Returns:
        the autoScale
      • setAutoScale

        public void setAutoScale​(boolean autoScale)
        Parameters:
        autoScale - the autoScale to set
      • fireAxisAutoScaleChanged

        private void fireAxisAutoScaleChanged​(boolean oldAutoScale,
                                              boolean newAutoScale)
      • isShowMajorGrid

        public boolean isShowMajorGrid()
        Returns:
        the showMajorGrid
      • setShowMajorGrid

        public void setShowMajorGrid​(boolean showMajorGrid)
        Parameters:
        showMajorGrid - the showMajorGrid to set
      • isShowMinorGrid

        public boolean isShowMinorGrid()
        Returns:
        the showMinorGrid
      • setShowMinorGrid

        public void setShowMinorGrid​(boolean showMinorGrid)
        Parameters:
        showMinorGrid - the showMinorGrid to set
      • getMajorGridColor

        public org.eclipse.swt.graphics.Color getMajorGridColor()
        Returns:
        the majorGridColor
      • setMajorGridColor

        public void setMajorGridColor​(org.eclipse.swt.graphics.Color majorGridColor)
        Parameters:
        majorGridColor - the majorGridColor to set
      • getMajorGridColorRGB

        public org.eclipse.swt.graphics.RGB getMajorGridColorRGB()
      • getMinorGridColor

        public org.eclipse.swt.graphics.Color getMinorGridColor()
        Returns:
        the minorGridColor
      • setMinorGridColor

        public void setMinorGridColor​(org.eclipse.swt.graphics.Color minorGridColor)
        Parameters:
        minorGridColor - the minorGridColor to set
      • setTitleFont

        public void setTitleFont​(org.eclipse.swt.graphics.Font titleFont)
        Parameters:
        titleFont - the titleFont to set
      • isDashGridLine

        public boolean isDashGridLine()
        Returns:
        the dashGridLine
      • setDashGridLine

        public void setDashGridLine​(boolean dashGridLine)
        Parameters:
        dashGridLine - the dashGridLine to set
      • setXYGraph

        public void setXYGraph​(IXYGraph xyGraph)
        Parameters:
        xyGraph - the xyGraph to set
      • getXYGraph

        public IXYGraph getXYGraph()
        Returns:
        the graph
      • getTraceList

        protected java.util.List<Trace> getTraceList()
        Returns:
        traceList
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • dataChanged

        public void dataChanged​(IDataProvider dataProvider)
      • setAutoScaleThreshold

        public void setAutoScaleThreshold​(double autoScaleThreshold)
        The autoScaleThreshold must be a value in range [0,1], which represents a percentage of the plot area for the threshold when autoScale is performed.The autoScale will performed only if the spare space exceeds this threshold. So it can reduce the CPU usage by increasing the threshold.
        Parameters:
        autoScaleThreshold - the autoScaleThreshold to set
      • isValidZoomType

        private boolean isValidZoomType​(ZoomType zoom)
        Parameters:
        zoom - Zoom Type
        Returns:
        true if the zoom type is applicable to this axis
      • setZoomType

        public void setZoomType​(ZoomType zoomType)
        Parameters:
        zoomType - the zoomType to set
      • getTitleFont

        public org.eclipse.swt.graphics.Font getTitleFont()
        Returns:
        the titleFont
      • getAutoScaleThreshold

        public double getAutoScaleThreshold()
        Returns:
        the autoScaleThreshold
      • getAutoScale

        public boolean getAutoScale()
        Returns:
        autoScale
      • setYAxis

        public void setYAxis​(boolean isYAxis)
        Set this axis as Y-Axis or X-Axis.
        Parameters:
        isYAxis - set true if the axis is Y-Axis; false if it is X-Axis.
      • setPrimarySide

        public void setPrimarySide​(boolean onPrimarySide)
        Set the axis on primary side (Bottom/Left) or secondary side (Top/Right).
        Parameters:
        onPrimarySide - set true if the axis on primary side(Bottom/Left); false if it is not on the primary side of xy graph(Top/Right).
      • isYAxis

        public boolean isYAxis()
        Returns:
        true if the axis is Y-Axis; false if it is X-Axis;
      • isOnPrimarySide

        public boolean isOnPrimarySide()
        Returns:
        true if the axis is on the primary side of xy graph(Bottom/Left); false if it is on the secondary side(Top/Right).
      • pan

        private void pan()
        Pan axis according to start/end from mouse listener
      • pan

        protected void pan​(Range temp,
                           double t1,
                           double t2)
        Pan the axis
        Parameters:
        temp - Original axis range before the panning started
        t1 - Start of the panning move
        t2 - End of the panning move
      • panChecked

        protected boolean panChecked​(Range temp,
                                     double t1,
                                     double t2)
        Pan the axis and check if new range is okay
        Parameters:
        temp - Original axis range before the panning started
        t1 - Start of the panning move
        t2 - End of the panning move
        Returns:
        true if pan ends up out-of-bounds
      • zoomInOut

        public void zoomInOut​(double center,
                              double factor)
        Zoom axis
        Parameters:
        center - Axis position at the 'center' of the zoom
        factor - Zoom factor. Positive to zoom 'in', negative 'out'.
      • setGrid

        public void setGrid​(Grid grid)
        Parameters:
        grid - the grid to set
      • getGrid

        public Grid getGrid()
        Returns:
        the grid
      • setLogScale

        public void setLogScale​(boolean enabled)
                         throws java.lang.IllegalStateException
        Overrides:
        setLogScale in class AbstractScale
        Parameters:
        enabled - true if enabling log scales
        Throws:
        java.lang.IllegalStateException
      • fireAxisLogScaleChanged

        private void fireAxisLogScaleChanged​(boolean old,
                                             boolean logScale)