Package Layout
Class PamAxis
java.lang.Object
Layout.PamAxis
- Direct Known Subclasses:
 ClassifierHistoryTimeAxis,RepeatedAxis
Draws an axis on a Java Component.
PamAxis contains all the information needed to draw an axis, the actual drawing is generally called from the paintComponent function in the containing window.
for a good example, see PamAxisPanel which will automaticall draw four axis around a central plot.
- Author:
 - Doug Gillespie
 - See Also:
 
- 
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionvoidDraw the axis in the Graphics Context gvoidDraw the axis in the graphics context g at the given positionvoidDraw a grid to go with the axis.voidprotected voiddrawLinearAxis(Graphics2D g2d) Draw a linear axis on the graphics contextprotected voiddrawLogAxis(Graphics2D g2d) Draw a logarithmic axis on the graphics contextprotected voiddrawTickAndLabel(Graphics2D g2d, Point xy, double value) Draw a tick and a label at the given point.protected StringformatValue(double val) Format the text for the label.getAutoFormat(boolean isInteger) static StringgetAutoFormat(double minVal, double maxVal, boolean isInteger) Work out the optimal format for the axis labels based on analysis of previously used axis labels.getAxisPoints(boolean extraOne) Work out the coordinates of all tick marks.doublegetDataValue(double position) Converts a position on the plot into a data value based on the axis max, min and scale.static doublegetDefaultScaleEnd(double val, double otherVal) intGets the dimension of the axis parallel to the direction of the tickmark - i.e.intGets the dimension of the axis parallel to the direction of the tickmark - i.e.intGets the dimension of the axis perpendicular to the direction of the tickmark - i.e.intgetExtent2(Graphics g, String typicalString) Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e.getLabel()intgetLogPoints(boolean extraOne) Get the coordinates of tick points for a logarithmic axisdoubledoublestatic intgetNumDecPlaces(double value) doublegetOuterPosition(double dataValue) To get a position in the context that the axis is drawn in, not the inner window relative to the axis.doublegetPosition(double dataValue) Get a distance along the axis within the bounds of the axis, i.e.intintgetX1()intgetX2()intgetY1()intgetY2()booleanbooleanCramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.booleanbooleanbooleanbooleanbooleanvoidoverrideAxisColour(Color color) Overrides the standard axis color;voidsetAllowScaleMultiples(boolean allowScaleMultiples) voidsetAngleScales(boolean angleScales) Easy way to make scales end at 45, 90, 180, etc and step in sensible 45, 90, etc.voidsetAutoFormat(boolean isInteger) Automatically set the format of axis labels based on the types of numbers in there.voidsetCrampLabels(boolean crampLabels) Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.voidsetDrawLine(boolean drawLine) voidsetExtraAxisEndLabel(String extraAxisEndLabel) voidsetExtraAxisStartLabel(String extraAxStartLabel) voidsetForceFirstVal(boolean forceFirstVal, double forcedFirstVal) voidSet the format string for writing out numbers on the axis.voidsetFractionalScale(boolean fractionalScale) voidsetInterval(double interval) Set the interval between ticks.voidvoidsetLabelPos(int labelPos) voidsetLogScale(boolean logScale) voidsetLogTenthsScale(boolean logTenthsScale) voidsetMaxVal(double maxVal) voidsetMinVal(double minVal) voidsetPosition(int x1, int y1, int x2, int y2) Set the axis default coordinatesvoidsetRange(double minVal, double maxVal) Set the minimum and maximum values for the axis.voidsetTickPosition(int tickPosition) voidsetX1(int x1) voidsetX2(int x2) voidsetY1(int y1) voidsetY2(int y2)  
- 
Field Details
- 
INTERVAL_AUTO
public static final int INTERVAL_AUTO- See Also:
 
 - 
ABOVE_LEFT
public static final int ABOVE_LEFT- See Also:
 
 - 
BELOW_RIGHT
public static final int BELOW_RIGHT- See Also:
 
 - 
BOTH_SIDES
public static final int BOTH_SIDES- See Also:
 
 - 
LABEL_NEAR_MAX
public static final int LABEL_NEAR_MAX- See Also:
 
 - 
LABEL_NEAR_MIN
public static final int LABEL_NEAR_MIN- See Also:
 
 - 
LABEL_NEAR_CENTRE
public static final int LABEL_NEAR_CENTRE- See Also:
 
 
 - 
 - 
Constructor Details
- 
PamAxis
public PamAxis(int x1, int y1, int x2, int y2, double minVal, double maxVal, int tickPosition, String label, int labelPos, String format) - Parameters:
 x1- first x coordinate of axisy1- first y coordinate of axisx2- second x coordinate of axisy2- second coordinate of axisminVal- minimum axis valuemaxVal- maximum axis valuetickPosition- tick position (ABOVE_LEFT or BELOW_RIGHT)label- text for label (or null if no label)labelPos- Position of axis label (LABEL_NEAR_MAX, LABEL_NEAR_MIN or LABEL_NEAR_CENTRE)format- format for numbers printed on the display. This must be a standard format String such as "%d", "%f", "%3.1f", "%.2 seconds", etc.
 - 
PamAxis
public PamAxis(int x1, int y1, int x2, int y2, double minVal, double maxVal, boolean aboveLeft, String label, String format) - Parameters:
 x1- x1y1- y1x2- x2y2- y2minVal- min axis valuemaxVal- max axis valueaboveLeft- above and / or to the leftlabel- axis labelformat- format of numbers
 
 - 
 - 
Method Details
- 
setPosition
public void setPosition(int x1, int y1, int x2, int y2) Set the axis default coordinates- Parameters:
 x1-y1-x2-y2-
 - 
setInterval
public void setInterval(double interval) Set the interval between ticks. This is by default set to INTERVAL_AUTO whereby an interval is chosen so that there is a tick mark approximately every 100 pixels.- Parameters:
 interval- the interval or INTERVAL_AUTO
 - 
setRange
public void setRange(double minVal, double maxVal) Set the minimum and maximum values for the axis.- Parameters:
 minVal-maxVal-
 - 
drawAxis
Draw the axis in the graphics context g at the given position- Parameters:
 g-x1-y1-x2-y2-
 - 
drawAxis
Draw the axis in the Graphics Context g- Parameters:
 g- graphics context to draw on
 - 
getAxisPoints
Work out the coordinates of all tick marks.- Parameters:
 extraOne-- Returns:
 - list of axis points.
 
 - 
drawLinearAxis
Draw a linear axis on the graphics context- Parameters:
 g2d- graphics context to draw on
 - 
drawLogAxis
Draw a logarithmic axis on the graphics context- Parameters:
 g2d- graphics context to draw on
 - 
getLogPoints
Get the coordinates of tick points for a logarithmic axis- Parameters:
 extraOne-- Returns:
 - Array of points
 
 - 
drawTickAndLabel
Draw a tick and a label at the given point.- Parameters:
 g2d-xy-value-
 - 
formatValue
Format the text for the label.- Parameters:
 val- value- Returns:
 - formatted String
 
 - 
drawGrid
Draw a grid to go with the axis. Generally, the graphics handle for grid drawing will be some inner window sitting inside the window containing the axis.- Parameters:
 g- Graphics context to draw onplotSize- size of the graphicminorGrid- draw a minor grid as well as lines at the main tick marks.
 - 
drawGrid
 - 
getExtent2
Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e. for a vertical axis, it's half the text height, for a horizontal axis it's half the typical string width.- Parameters:
 g- graphics handle for component the axis is to be draw on- Returns:
 - axis extent in pixels
 
 - 
getExtent2
Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e. for a vertical axis, it's half the text height, for a horizontal axis it's half the typical string width.- Parameters:
 g- graphics handle for component the axis is to be draw ontypicalString- typical text string.- Returns:
 - Axis extent
 
 - 
getExtent
Gets the dimension of the axis parallel to the direction of the tickmark - i.e. the ticklength + the text height + the label height.- Parameters:
 g- graphics handle for component the axis is to be draw on- Returns:
 - axis extent in pixels
 
 - 
getExtent
Gets the dimension of the axis parallel to the direction of the tickmark - i.e. the ticklength + the text height + the label height.- Parameters:
 g- graphics handle the axis is being draw ontypicalString- typical label string for a tick- Returns:
 - axisextent in pixels
 
 - 
isLogScale
public boolean isLogScale() - 
setLogScale
public void setLogScale(boolean logScale)  - 
isDrawLine
public boolean isDrawLine() - 
setDrawLine
public void setDrawLine(boolean drawLine)  - 
getFormat
 - 
setFormat
Set the format string for writing out numbers on the axis.- Parameters:
 format- format string
 - 
setAutoFormat
public void setAutoFormat(boolean isInteger) Automatically set the format of axis labels based on the types of numbers in there. - 
getAutoFormat
 - 
getAutoFormat
 - 
getNumDecPlaces
public static int getNumDecPlaces(double value)  - 
isIntegerFormat
public boolean isIntegerFormat() - 
getLabel
 - 
setLabel
 - 
getLabelPos
public int getLabelPos() - 
setLabelPos
public void setLabelPos(int labelPos)  - 
getTickPosition
public int getTickPosition() - 
setTickPosition
public void setTickPosition(int tickPosition)  - 
getMaxVal
public double getMaxVal() - 
setMaxVal
public void setMaxVal(double maxVal)  - 
getMinVal
public double getMinVal() - 
setMinVal
public void setMinVal(double minVal)  - 
getAutoLabelFormat
Work out the optimal format for the axis labels based on analysis of previously used axis labels.- Returns:
 - some kind of sensible format string !
 
 - 
getDefaultScaleEnd
public static double getDefaultScaleEnd(double val, double otherVal)  - 
setForceFirstVal
public void setForceFirstVal(boolean forceFirstVal, double forcedFirstVal)  - 
isLogTenthsScale
public boolean isLogTenthsScale() - 
setLogTenthsScale
public void setLogTenthsScale(boolean logTenthsScale)  - 
getAxisValues
 - 
getX1
public int getX1() - 
setX1
public void setX1(int x1)  - 
getX2
public int getX2() - 
setX2
public void setX2(int x2)  - 
getY1
public int getY1() - 
setY1
public void setY1(int y1)  - 
getY2
public int getY2() - 
setY2
public void setY2(int y2)  - 
getPosition
public double getPosition(double dataValue) Get a distance along the axis within the bounds of the axis, i.e. generally within an inner panel drawn to the same bounds as the axis.The axis knows all about scale and can tell us the pixel value for any given data value.
- Parameters:
 dataValue-- Returns:
 - position in pixels along the axis for a given data value.
 
 - 
getOuterPosition
public double getOuterPosition(double dataValue) To get a position in the context that the axis is drawn in, not the inner window relative to the axis. The axis knows all about scale and can tell us the pixel value for any given data value.- Parameters:
 dataValue-- Returns:
 - position in pixels along the axis for a given data value.
 
 - 
getDataValue
public double getDataValue(double position) Converts a position on the plot into a data value based on the axis max, min and scale.This is the exact compliment of getPosition()
- Parameters:
 position- position along the axis in pixels.- Returns:
 - data value.
 
 - 
isAllowScaleMultiples
public boolean isAllowScaleMultiples() - 
setAllowScaleMultiples
public void setAllowScaleMultiples(boolean allowScaleMultiples)  - 
setAngleScales
public void setAngleScales(boolean angleScales) Easy way to make scales end at 45, 90, 180, etc and step in sensible 45, 90, etc. steps.- Parameters:
 angleScales-
 - 
isFractionalScale
public boolean isFractionalScale() - 
setFractionalScale
public void setFractionalScale(boolean fractionalScale)  - 
getExtraAxisStartLabel
- Returns:
 - the extraAxStartLabel
 
 - 
setExtraAxisStartLabel
- Parameters:
 extraAxStartLabel- the extraAxStartLabel to set
 - 
getExtraAxisEndLabel
- Returns:
 - the extraAxisEndLabel
 
 - 
setExtraAxisEndLabel
- Parameters:
 extraAxisEndLabel- the extraAxisEndLabel to set
 - 
isCrampLabels
public boolean isCrampLabels()Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.- Returns:
 - the crampLables
 
 - 
setCrampLabels
public void setCrampLabels(boolean crampLabels) Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.- Parameters:
 crampLabels- the crampLables to set
 - 
overrideAxisColour
Overrides the standard axis color;- Parameters:
 color- - null if default colour.
 
 -