public class PamAxis
extends java.lang.Object
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.
PamLabel
,
PamAxisPanel
Modifier and Type | Field and Description |
---|---|
static int |
ABOVE_LEFT |
static int |
BELOW_RIGHT |
static int |
BOTH_SIDES |
static int |
INTERVAL_AUTO |
static int |
LABEL_NEAR_CENTRE |
static int |
LABEL_NEAR_MAX |
static int |
LABEL_NEAR_MIN |
Constructor and Description |
---|
PamAxis(int x1,
int y1,
int x2,
int y2,
double minVal,
double maxVal,
boolean aboveLeft,
java.lang.String label,
java.lang.String format) |
PamAxis(int x1,
int y1,
int x2,
int y2,
double minVal,
double maxVal,
int tickPosition,
java.lang.String label,
int labelPos,
java.lang.String format) |
Modifier and Type | Method and Description |
---|---|
void |
drawAxis(java.awt.Graphics g)
Draw the axis in the Graphics Context g
|
void |
drawAxis(java.awt.Graphics g,
int x1,
int y1,
int x2,
int y2)
Draw the axis in the graphics context g at the given position
|
void |
drawGrid(java.awt.Graphics g,
java.awt.Dimension plotSize,
java.awt.Insets insets,
int minorGrid) |
void |
drawGrid(java.awt.Graphics g,
java.awt.Dimension plotSize,
int minorGrid)
Draw a grid to go with the axis.
|
java.lang.String |
getAutoFormat(boolean isInteger) |
static java.lang.String |
getAutoFormat(double minVal,
double maxVal,
boolean isInteger) |
java.lang.String |
getAutoLabelFormat()
Work out the optimal format for the axis labels based on
analysis of previously used axis labels.
|
java.util.ArrayList<java.awt.Point> |
getAxisPoints(boolean extraOne)
Work out the coordinates of all tick marks.
|
java.util.ArrayList<java.lang.Double> |
getAxisValues() |
double |
getDataValue(double position)
Converts a position on the plot into a data value
based on the axis max, min and scale.
|
static double |
getDefaultScaleEnd(double val,
double otherVal) |
int |
getExtent(java.awt.Graphics g)
Gets the dimension of the axis parallel to the direction of the
tickmark - i.e.
|
int |
getExtent(java.awt.Graphics g,
java.lang.String typicalString)
Gets the dimension of the axis parallel to the direction of the
tickmark - i.e.
|
int |
getExtent2(java.awt.Graphics g)
Gets the dimension of the axis perpendicular to the direction of the
tickmark - i.e.
|
int |
getExtent2(java.awt.Graphics g,
java.lang.String typicalString)
Gets the dimension of the axis perpendicular to the direction of the
tickmark - i.e.
|
java.lang.String |
getExtraAxisEndLabel() |
java.lang.String |
getExtraAxisStartLabel() |
java.lang.String |
getFormat() |
java.lang.String |
getLabel() |
int |
getLabelPos() |
double |
getMaxVal() |
double |
getMinVal() |
static int |
getNumDecPlaces(double value) |
double |
getPosition(double dataValue)
The axis knows all about scale and can tell us the
pixel value for any given data value.
|
int |
getTickPosition() |
int |
getX1() |
int |
getX2() |
int |
getY1() |
int |
getY2() |
boolean |
isAllowScaleMultiples() |
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.
|
boolean |
isDrawLine() |
boolean |
isFractionalScale() |
boolean |
isIntegerFormat() |
boolean |
isLogScale() |
boolean |
isLogTenthsScale() |
void |
overrideAxisColour(java.awt.Color color)
Overrides the standard axis color;
|
void |
setAllowScaleMultiples(boolean allowScaleMultiples) |
void |
setAngleScales(boolean angleScales)
Easy way to make scales end at 45, 90, 180, etc and
step in sensible 45, 90, etc.
|
void |
setAutoFormat(boolean isInteger)
Automatically set the format of axis labels based on the types of
numbers in there.
|
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.
|
void |
setDrawLine(boolean drawLine) |
void |
setExtraAxisEndLabel(java.lang.String extraAxisEndLabel) |
void |
setExtraAxisStartLabel(java.lang.String extraAxStartLabel) |
void |
setForceFirstVal(boolean forceFirstVal,
double forcedFirstVal) |
void |
setFormat(java.lang.String format)
Set the format string for writing out numbers on the axis.
|
void |
setFractionalScale(boolean fractionalScale) |
void |
setInterval(double interval)
Set the interval between ticks.
|
void |
setLabel(java.lang.String label) |
void |
setLabelPos(int labelPos) |
void |
setLogScale(boolean logScale) |
void |
setLogTenthsScale(boolean logTenthsScale) |
void |
setMaxVal(double maxVal) |
void |
setMinVal(double minVal) |
void |
setPosition(int x1,
int y1,
int x2,
int y2)
Set the axis default coordinates
|
void |
setRange(double minVal,
double maxVal)
Set the minimum and maximum values for the axis.
|
void |
setTickPosition(int tickPosition) |
void |
setX1(int x1) |
void |
setX2(int x2) |
void |
setY1(int y1) |
void |
setY2(int y2) |
public static final int INTERVAL_AUTO
public static final int ABOVE_LEFT
public static final int BELOW_RIGHT
public static final int BOTH_SIDES
public static final int LABEL_NEAR_MAX
public static final int LABEL_NEAR_MIN
public static final int LABEL_NEAR_CENTRE
public PamAxis(int x1, int y1, int x2, int y2, double minVal, double maxVal, int tickPosition, java.lang.String label, int labelPos, java.lang.String format)
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.public PamAxis(int x1, int y1, int x2, int y2, double minVal, double maxVal, boolean aboveLeft, java.lang.String label, java.lang.String format)
x1
- x1y1
- y1x2
- x2y2
- y2minVal
- min axis valuemaxVal
- max axis valueaboveLeft
- above and / or to the leftlabel
- axis labelformat
- format of numberspublic void setPosition(int x1, int y1, int x2, int y2)
x1
- y1
- x2
- y2
- public void setInterval(double interval)
interval
- the interval or INTERVAL_AUTOpublic void setRange(double minVal, double maxVal)
minVal
- maxVal
- public void drawAxis(java.awt.Graphics g, int x1, int y1, int x2, int y2)
g
- x1
- y1
- x2
- y2
- public void drawAxis(java.awt.Graphics g)
g
- graphics context to draw onpublic java.util.ArrayList<java.awt.Point> getAxisPoints(boolean extraOne)
extraOne
- public void drawGrid(java.awt.Graphics g, java.awt.Dimension plotSize, int minorGrid)
g
- Graphics context to draw onplotSize
- size of the graphicminorGrid
- draw a minor grid as well as lines at the main tick marks.public void drawGrid(java.awt.Graphics g, java.awt.Dimension plotSize, java.awt.Insets insets, int minorGrid)
public int getExtent2(java.awt.Graphics g)
g
- graphics handle for component the axis is to be draw onpublic int getExtent2(java.awt.Graphics g, java.lang.String typicalString)
g
- graphics handle for component the axis is to be draw ontypicalString
- typical text string.public int getExtent(java.awt.Graphics g)
g
- graphics handle for component the axis is to be draw onpublic int getExtent(java.awt.Graphics g, java.lang.String typicalString)
g
- graphics handle the axis is being draw ontypicalString
- typical label string for a tickpublic boolean isLogScale()
public void setLogScale(boolean logScale)
public boolean isDrawLine()
public void setDrawLine(boolean drawLine)
public java.lang.String getFormat()
public void setFormat(java.lang.String format)
format
- format stringpublic void setAutoFormat(boolean isInteger)
public java.lang.String getAutoFormat(boolean isInteger)
public static java.lang.String getAutoFormat(double minVal, double maxVal, boolean isInteger)
public static int getNumDecPlaces(double value)
public boolean isIntegerFormat()
public java.lang.String getLabel()
public void setLabel(java.lang.String label)
public int getLabelPos()
public void setLabelPos(int labelPos)
public int getTickPosition()
public void setTickPosition(int tickPosition)
public double getMaxVal()
public void setMaxVal(double maxVal)
public double getMinVal()
public void setMinVal(double minVal)
public java.lang.String getAutoLabelFormat()
public static double getDefaultScaleEnd(double val, double otherVal)
public void setForceFirstVal(boolean forceFirstVal, double forcedFirstVal)
public boolean isLogTenthsScale()
public void setLogTenthsScale(boolean logTenthsScale)
public java.util.ArrayList<java.lang.Double> getAxisValues()
public int getX1()
public void setX1(int x1)
public int getX2()
public void setX2(int x2)
public int getY1()
public void setY1(int y1)
public int getY2()
public void setY2(int y2)
public double getPosition(double dataValue)
dataValue
- public double getDataValue(double position)
This is the exact compliment of getPosition()
position
- position along the axis in pixels.public boolean isAllowScaleMultiples()
public void setAllowScaleMultiples(boolean allowScaleMultiples)
public void setAngleScales(boolean angleScales)
angleScales
- public boolean isFractionalScale()
public void setFractionalScale(boolean fractionalScale)
public java.lang.String getExtraAxisStartLabel()
public void setExtraAxisStartLabel(java.lang.String extraAxStartLabel)
extraAxStartLabel
- the extraAxStartLabel to setpublic java.lang.String getExtraAxisEndLabel()
public void setExtraAxisEndLabel(java.lang.String extraAxisEndLabel)
extraAxisEndLabel
- the extraAxisEndLabel to setpublic boolean isCrampLabels()
public void setCrampLabels(boolean crampLabels)
crampLabels
- the crampLables to setpublic void overrideAxisColour(java.awt.Color color)
color-
- null if default colour.