Class LinearScale

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

    public class LinearScale
    extends AbstractScale
    implements IScaleProvider
    Linear(straight) scale has the tick labels and tick marks on a straight line. It can be used for any scale based widget, such as 2D plot, chart, graph, thermometer or tank etc.
    A scale is comprised of Margins, Scale line, tick labels and tick marks which include minor ticks and major ticks.
    Margin is half of the label's length(Horizontal Scale) or height(Vertical scale), so that the label can be displayed correctly. So the range must be set before you can get the correct margin.

    |Margin|______|______|______|______|______|______|Margin|
    • Constructor Detail

      • LinearScale

        public LinearScale()
        Constructor.
    • Method Detail

      • createLinearScaleTickLabels

        protected LinearScaleTickLabels createLinearScaleTickLabels()
        Creates the linearScaleTickLabel. To be overridden if necessary if another Axis implementation is used.
      • createLinearScaleTickMarks

        protected LinearScaleTickMarks createLinearScaleTickMarks()
        Creates the LinearScaleTickMarks. To be overridden if necessary if another Axis implementation is used.
      • calcMargin

        private void calcMargin()
      • getLength

        public int getLength()
        Specified by:
        getLength in interface IScaleProvider
        Returns:
        the length of the whole scale (include margin)
      • setLength

        public void setLength​(int length)
        Parameters:
        length -
      • getMargin

        public int getMargin​(boolean updateTick)
        If updateTick is True, getMargin() is used where the tick are updated, if not, the method returns margin.
        Parameters:
        updateTick -
        Returns:
      • getMargin

        public int getMargin()
        Margin is half of the label's length(Horizontal Scale) or height(Vertical scale), so that the label can be displayed correctly. So the range and format pattern must be set correctly before you can get the correct margin.
        Specified by:
        getMargin in interface IScaleProvider
        Returns:
        the margin
      • setMargin

        public void setMargin​(int margin)
        Parameters:
        margin -
      • 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 org.eclipse.draw2d.Figure
      • getScaleTickLabels

        public LinearScaleTickLabels getScaleTickLabels()
        Gets the scale tick labels.
        Returns:
        the scale tick labels
      • getScaleTickMarks

        public LinearScaleTickMarks getScaleTickMarks()
        Gets the scale tick marks.
        Returns:
        the scale tick marks
      • getTickLength

        public int getTickLength()
        Returns:
        the length of the tick part (without margin)
      • getValuePosition

        public int getValuePosition​(double value,
                                    boolean relative)
        Get the position of the value based on scale.
        Parameters:
        value - the value to find its position. Support value out of range.
        relative - return the position relative to the left/bottom bound of the scale if true. If false, return the absolute position which has the scale bounds counted.
        Returns:
        position in pixels
      • getValuePrecisePosition

        public double getValuePrecisePosition​(double value,
                                              boolean relative)
        Get the position of the value based on scale.
        Parameters:
        value - the value to find its position. Support value out of range.
        relative - return the position relative to the left/bottom bound of the scale if true. If false, return the absolute position which has the scale bounds counted.
        Returns:
        position in pixels
      • getPositionValue

        public double getPositionValue​(int position,
                                       boolean relative)
        Get the corresponding value on the position of the scale.
        Parameters:
        position -
        relative - if true the position is relative to the left/bottom bound of the scale; if false it is the absolute position.
        Returns:
        the value corresponding to the position.
      • getPositionValue

        public double getPositionValue​(double position,
                                       boolean relative)
        Get the corresponding value on the position of the scale.
        Parameters:
        position -
        relative - if true the position is relative to the left/bottom bound of the scale; if false it is the absolute position.
        Returns:
        the value corresponding to the position.
      • isHorizontal

        public boolean isHorizontal()
        Specified by:
        isHorizontal in interface IScaleProvider
        Returns:
        True if scale is horizontal
      • isShowMaxLabel

        public boolean isShowMaxLabel()
        shows the maximum value of the range as a label
        Returns:
        true (default) if shown
      • isShowMinLabel

        public boolean isShowMinLabel()
        shows the minimum value of the range as a label
        Returns:
        true (default) if shown
      • layout

        protected void layout()
        Overrides:
        layout in class org.eclipse.draw2d.Figure
      • figureLayout

        public void figureLayout()
        Simple call of org.eclipse.draw2d.Figure.layout()
      • setBounds

        public void setBounds​(org.eclipse.draw2d.geometry.Rectangle rect)
        Specified by:
        setBounds in interface org.eclipse.draw2d.IFigure
        Overrides:
        setBounds in class org.eclipse.draw2d.Figure
      • setFont

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

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

        public void setOrientation​(LinearScale.Orientation orientation)
        sets the orientation
        Parameters:
        orientation - the orientation to set
      • setShowMaxLabel

        public void setShowMaxLabel​(boolean b)
        sets the visibility of the maximum label
        Parameters:
        b - show maximal value as a label
      • setShowMinLabel

        public void setShowMinLabel​(boolean b)
        sets the visibility of the minimum label
        Parameters:
        b - show minimum value as a label
      • getLocalRange

        public Range getLocalRange()
        Returns:
        range used for axis (not range given by data)
      • setLocalRange

        public void setLocalRange​(Range localRange)
        Parameters:
        localRange -
      • updateTick

        public void updateTick()
        Updates the tick, recalculate all parameters, such as margin, length...
        Specified by:
        updateTick in class AbstractScale
      • useLocalCoordinates

        protected boolean useLocalCoordinates()
        Overrides:
        useLocalCoordinates in class org.eclipse.draw2d.Figure
      • getDimension

        public org.eclipse.draw2d.geometry.Dimension getDimension​(java.lang.Object obj)
        Calculate dimension of a textual form of object
        Specified by:
        getDimension in interface IScaleProvider
        Parameters:
        obj - object
        Returns:
        dimension
      • isPrimary

        public boolean isPrimary()
        Specified by:
        isPrimary in interface IScaleProvider
        Returns:
        true if axis is a primary one (i.e. left for y and bottom for x)
      • getLabel

        public double getLabel​(double value)
        Override to provide custom axis labels.
        Specified by:
        getLabel in interface IScaleProvider
        Returns:
        double value of label
      • isLabelCustomised

        public boolean isLabelCustomised()
        Specified by:
        isLabelCustomised in interface IScaleProvider
        Returns:
        true if axis labels are customised
      • hasTicksAtEnds

        public boolean hasTicksAtEnds()
        Specified by:
        hasTicksAtEnds in interface IScaleProvider
        Returns:
        true if ticks at end of axis are shown