Class LinearScale
- java.lang.Object
-
- org.eclipse.draw2d.Figure
-
- org.eclipse.nebula.visualization.xygraph.linearscale.AbstractScale
-
- org.eclipse.nebula.visualization.xygraph.linearscale.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|
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLinearScale.Orientationscale direction-
Nested classes/interfaces inherited from class org.eclipse.nebula.visualization.xygraph.linearscale.AbstractScale
AbstractScale.LabelSide
-
-
Field Summary
Fields Modifier and Type Field Description private intlengththe length of the whole scaleprivate RangelocalRangeprivate intmarginprivate LinearScale.Orientationorientationscale direction, no meaning for round scaleprotected static intSPACE_BTW_MARK_LABELprivate LinearScaleTickLabelstickLabelsthe scale tick labelsprivate LinearScaleTickMarkstickMarksthe scale tick marks-
Fields inherited from class org.eclipse.nebula.visualization.xygraph.linearscale.AbstractScale
DEFAULT_DATE_FORMAT, default_decimal_format, DEFAULT_ENGINEERING_FORMAT, DEFAULT_LOG_SCALE_MAX, DEFAULT_MAX, DEFAULT_MIN, dirty, ENGINEERING_LIMIT, max, min
-
-
Constructor Summary
Constructors Constructor Description LinearScale()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcalcMargin()protected LinearScaleTickLabelscreateLinearScaleTickLabels()Creates the linearScaleTickLabel.protected LinearScaleTickMarkscreateLinearScaleTickMarks()Creates the LinearScaleTickMarks.voidfigureLayout()Simple call oforg.eclipse.draw2d.Figure.layout()org.eclipse.draw2d.geometry.DimensiongetDimension(java.lang.Object obj)Calculate dimension of a textual form of objectdoublegetLabel(double value)Override to provide custom axis labels.intgetLength()RangegetLocalRange()intgetMargin()Margin is half of the label's length(Horizontal Scale) or height(Vertical scale), so that the label can be displayed correctly.intgetMargin(boolean updateTick)If updateTick is True,getMargin()is used where the tick are updated, if not, the method returnsmargin.LinearScale.OrientationgetOrientation()doublegetPositionValue(double position, boolean relative)Get the corresponding value on the position of the scale.doublegetPositionValue(int position, boolean relative)Get the corresponding value on the position of the scale.org.eclipse.draw2d.geometry.DimensiongetPreferredSize(int wHint, int hHint)RangegetScaleRange()LinearScaleTickLabelsgetScaleTickLabels()Gets the scale tick labels.LinearScaleTickMarksgetScaleTickMarks()Gets the scale tick marks.intgetTickLength()ITicksProvidergetTicksProvider()Gets the ticks providerintgetValuePosition(double value, boolean relative)Get the position of the value based on scale.doublegetValuePrecisePosition(double value, boolean relative)Get the position of the value based on scale.booleanhasTicksAtEnds()booleanisHorizontal()booleanisLabelCustomised()booleanisPrimary()booleanisShowMaxLabel()shows the maximum value of the range as a labelbooleanisShowMinLabel()shows the minimum value of the range as a labelprotected voidlayout()voidsetBounds(org.eclipse.draw2d.geometry.Rectangle rect)voidsetFont(org.eclipse.swt.graphics.Font font)voidsetForegroundColor(org.eclipse.swt.graphics.Color color)voidsetLength(int length)voidsetLocalRange(Range localRange)voidsetMargin(int margin)voidsetOrientation(LinearScale.Orientation orientation)sets the orientationvoidsetShowMaxLabel(boolean b)sets the visibility of the maximum labelvoidsetShowMinLabel(boolean b)sets the visibility of the minimum labelvoidupdateTick()Updates the tick, recalculate all parameters, such as margin, length...protected booleanuseLocalCoordinates()-
Methods inherited from class org.eclipse.nebula.visualization.xygraph.linearscale.AbstractScale
format, format, getFormatPattern, getMajorGridStep, getMajorTickMarkStepHint, getMinorTickMarkStepHint, getRange, getTickLabelSide, getTickLablesSide, getTimeUnit, internalSetAutoFormat, internalSetFormatPattern, internalSetLogScaleEnabled, internalSetRange, isAutoFormat, isDateEnabled, isDirty, isLogScaleEnabled, isMinorTicksVisible, isScaleLineVisible, setAutoFormat, setDateEnabled, setDirty, setFormatPattern, setLogScale, setMajorGridStep, setMajorTickMarkStepHint, setMinorTickMarkStepHint, setMinorTicksVisible, setRange, setRange, setRange, setScaleLineVisible, setTickLabelSide, setTickLableSide, setTimeUnit
-
Methods inherited from class org.eclipse.draw2d.Figure
add, add, add, add, addAncestorListener, addCoordinateListener, addFigureListener, addFocusListener, addKeyListener, addLayoutListener, addListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, containsPoint, containsPoint, erase, findDescendantAtExcluding, findFigureAt, findFigureAt, findFigureAt, findFigureAtExcluding, findMouseEventTargetAt, findMouseEventTargetInDescendantsAt, fireCoordinateSystemChanged, fireFigureMoved, fireMoved, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundColor, getBorder, getBounds, getChildren, getClientArea, getClientArea, getClippingStrategy, getCursor, getFlag, getFont, getForegroundColor, getInsets, getLayoutManager, getListeners, getLocalBackgroundColor, getLocalFont, getLocalForegroundColor, getLocation, getMaximumSize, getMinimumSize, getMinimumSize, getParent, getPreferredSize, getSize, getToolTip, getUpdateManager, handleFocusGained, handleFocusLost, handleKeyPressed, handleKeyReleased, handleMouseDoubleClicked, handleMouseDragged, handleMouseEntered, handleMouseExited, handleMouseHover, handleMouseMoved, handleMousePressed, handleMouseReleased, hasFocus, internalGetEventDispatcher, intersects, invalidate, invalidateTree, isCoordinateSystem, isEnabled, isFocusTraversable, isMirrored, isMouseEventTarget, isOpaque, isRequestFocusEnabled, isShowing, isValid, isValidationRoot, isVisible, paint, paintBorder, paintChildren, paintClientArea, paintFigure, primTranslate, remove, removeAll, removeAncestorListener, removeCoordinateListener, removeFigureListener, removeFocusListener, removeKeyListener, removeLayoutListener, removeListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, revalidate, setBackgroundColor, setBorder, setChildrenDirection, setChildrenEnabled, setChildrenOrientation, setClippingStrategy, setConstraint, setCursor, setEnabled, setFlag, setFocusTraversable, setLayoutManager, setLocation, setMaximumSize, setMinimumSize, setOpaque, setParent, setPreferredSize, setPreferredSize, setRequestFocusEnabled, setSize, setSize, setToolTip, setValid, setVisible, translate, translateFromParent, translateToAbsolute, translateToParent, translateToRelative, validate
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.nebula.visualization.xygraph.linearscale.IScaleProvider
format, format, getFont, getForegroundColor, getFormatPattern, getMajorGridStep, getMajorTickMarkStepHint, getMinorTickMarkStepHint, getTimeUnit, isAutoFormat, isDateEnabled, isLogScaleEnabled, setAutoFormat
-
-
-
-
Field Detail
-
SPACE_BTW_MARK_LABEL
protected static final int SPACE_BTW_MARK_LABEL
- See Also:
- Constant Field Values
-
orientation
private LinearScale.Orientation orientation
scale direction, no meaning for round scale
-
tickLabels
private LinearScaleTickLabels tickLabels
the scale tick labels
-
tickMarks
private LinearScaleTickMarks tickMarks
the scale tick marks
-
length
private int length
the length of the whole scale
-
margin
private int margin
-
localRange
private Range localRange
-
-
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:
getLengthin interfaceIScaleProvider- 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 returnsmargin.- 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:
getMarginin interfaceIScaleProvider- Returns:
- the margin
-
setMargin
public void setMargin(int margin)
- Parameters:
margin-
-
getOrientation
public LinearScale.Orientation getOrientation()
- Returns:
- the orientation
-
getPreferredSize
public org.eclipse.draw2d.geometry.Dimension getPreferredSize(int wHint, int hHint)- Specified by:
getPreferredSizein interfaceorg.eclipse.draw2d.IFigure- Overrides:
getPreferredSizein classorg.eclipse.draw2d.Figure
-
getTicksProvider
public ITicksProvider getTicksProvider()
Description copied from interface:IScaleProviderGets the ticks provider- Specified by:
getTicksProviderin interfaceIScaleProvider- Returns:
- tick provider
-
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:
isHorizontalin interfaceIScaleProvider- 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:
layoutin classorg.eclipse.draw2d.Figure
-
figureLayout
public void figureLayout()
Simple call oforg.eclipse.draw2d.Figure.layout()
-
setBounds
public void setBounds(org.eclipse.draw2d.geometry.Rectangle rect)
- Specified by:
setBoundsin interfaceorg.eclipse.draw2d.IFigure- Overrides:
setBoundsin classorg.eclipse.draw2d.Figure
-
setFont
public void setFont(org.eclipse.swt.graphics.Font font)
- Specified by:
setFontin interfaceorg.eclipse.draw2d.IFigure- Overrides:
setFontin classAbstractScale
-
setForegroundColor
public void setForegroundColor(org.eclipse.swt.graphics.Color color)
- Specified by:
setForegroundColorin interfaceorg.eclipse.draw2d.IFigure- Overrides:
setForegroundColorin classorg.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:
updateTickin classAbstractScale
-
useLocalCoordinates
protected boolean useLocalCoordinates()
- Overrides:
useLocalCoordinatesin classorg.eclipse.draw2d.Figure
-
getScaleRange
public Range getScaleRange()
- Specified by:
getScaleRangein interfaceIScaleProvider- Returns:
- scale range
-
getDimension
public org.eclipse.draw2d.geometry.Dimension getDimension(java.lang.Object obj)
Calculate dimension of a textual form of object- Specified by:
getDimensionin interfaceIScaleProvider- Parameters:
obj- object- Returns:
- dimension
-
isPrimary
public boolean isPrimary()
- Specified by:
isPrimaryin interfaceIScaleProvider- 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:
getLabelin interfaceIScaleProvider- Returns:
- double value of label
-
isLabelCustomised
public boolean isLabelCustomised()
- Specified by:
isLabelCustomisedin interfaceIScaleProvider- Returns:
- true if axis labels are customised
-
hasTicksAtEnds
public boolean hasTicksAtEnds()
- Specified by:
hasTicksAtEndsin interfaceIScaleProvider- Returns:
- true if ticks at end of axis are shown
-
-