Package edu.hws.jcm.draw
Class Axes
- java.lang.Object
-
- edu.hws.jcm.draw.Drawable
-
- edu.hws.jcm.draw.Axes
-
- All Implemented Interfaces:
java.io.Serializable
public class Axes extends Drawable
A set of horizontal and vertical axes that look OK and have reasonable, labeled tick marks. The number and spacing of tick marks changes depending on the scale on the axes. (The heuristics for computing this could use some improvement.)- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
BOTTOM
A constant that can be used in the setYAxisPosition() method to indicate the placement of the y-axs.static int
CENTER
A constant that can be used in the setXAxisPosition() and setYAxisPosition() methods to indicate the placement of the axes.static int
LEFT
A constant that can be used in the setXAxisPosition() method to indicate the placement of the x-axis.static int
RIGHT
A constant that can be used in the setXAxisPosition() method to indicate the placement of the x-axis.static int
SMART
A constant that can be used in the setXAxisPosition() and setYAxisPosition() methods to indicate the placement of the axes.static int
TOP
A constant that can be used in the setYAxisPosition() method to indicate the placement of the y-axis.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
draw(java.awt.Graphics g, boolean coordsChanged)
Draw the axes.java.awt.Color
getAxesColor()
Get the color that is used for drawing the axes, when they are drawn in their true position.java.awt.Color
getLabelColor()
Get the color that is used for drawing the labels on the x- and y-axes.java.awt.Color
getLightAxesColor()
Get the color that is used for drawing an axis, when it is drawn along an edge of the CoordinateRect instead of in its proper x- or y-position.int
getXAxisPosition()
Get the positioning constant that tells where the x-axis is drawn.java.lang.String
getXLabel()
Get the label that appears on the x-axis.int
getYAxisPosition()
Get the positioning constant that tells where the y-axis is drawn.java.lang.String
getYLabel()
Get the label that appears on the y-axis.void
setAxesColor(java.awt.Color c)
Set the color that is used for drawing the axes, when they are drawn in their true position.void
setLabelColor(java.awt.Color c)
Set the color that is used for drawing the labels (usually the names of the variables) on the x- and y-axes.void
setLightAxesColor(java.awt.Color c)
Get the color that is used for drawing an axis, when it is drawn along an edge of the CoordinateRect instead of in its proper x- or y-position.void
setXAxisPosition(int pos)
Set the positioning constant that tells where the x-axis is drawn.void
setXLabel(java.lang.String s)
Set the label that appears on the x-axis.void
setYAxisPosition(int pos)
Set the positioning constant that tells where the y-axis is drawn.void
setYLabel(java.lang.String s)
Set the label that appears on the y-axis.-
Methods inherited from class edu.hws.jcm.draw.Drawable
getVisible, needsRedraw, setOwnerData, setVisible
-
-
-
-
Field Detail
-
TOP
public static final int TOP
A constant that can be used in the setYAxisPosition() method to indicate the placement of the y-axis. The axis is placed at the top of the CoordinateRect.- See Also:
- Constant Field Values
-
BOTTOM
public static final int BOTTOM
A constant that can be used in the setYAxisPosition() method to indicate the placement of the y-axs. The axis is placed at the bottom of the CoordinateRect.- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
A constant that can be used in the setXAxisPosition() method to indicate the placement of the x-axis. The axis is placed at the left edge of the CoordinateRect.- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
A constant that can be used in the setXAxisPosition() method to indicate the placement of the x-axis. The axis is placed at the right edge of the CoordinateRect.- See Also:
- Constant Field Values
-
CENTER
public static final int CENTER
A constant that can be used in the setXAxisPosition() and setYAxisPosition() methods to indicate the placement of the axes. The axis is placed in the center of the CoordinateRect.- See Also:
- Constant Field Values
-
SMART
public static final int SMART
A constant that can be used in the setXAxisPosition() and setYAxisPosition() methods to indicate the placement of the axes. The axis is placed at its true x- or y-position, if that lies within the range of values shown on the CoordinateRect. Otherwise, it is placed along an edge of the CoordinateRect. This is the default value for axis placement.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Axes
public Axes()
Creates axes with no names on the axes.
-
Axes
public Axes(java.lang.String xLabel, java.lang.String yLabel)
Creates axes with given names on the axes.- Parameters:
xlabel
- Label for x axis. If the value is null, no label is drawn.ylabel
- Label for y axis. If the value is null, no label is drawn.
-
-
Method Detail
-
getAxesColor
public java.awt.Color getAxesColor()
Get the color that is used for drawing the axes, when they are drawn in their true position.
-
setAxesColor
public void setAxesColor(java.awt.Color c)
Set the color that is used for drawing the axes, when they are drawn in their true position. The default is blue.
-
getLightAxesColor
public java.awt.Color getLightAxesColor()
Get the color that is used for drawing an axis, when it is drawn along an edge of the CoordinateRect instead of in its proper x- or y-position.
-
setLightAxesColor
public void setLightAxesColor(java.awt.Color c)
Get the color that is used for drawing an axis, when it is drawn along an edge of the CoordinateRect instead of in its proper x- or y-position. The default is a light blue.
-
getLabelColor
public java.awt.Color getLabelColor()
Get the color that is used for drawing the labels on the x- and y-axes.
-
setLabelColor
public void setLabelColor(java.awt.Color c)
Set the color that is used for drawing the labels (usually the names of the variables) on the x- and y-axes. The default is black.
-
getXAxisPosition
public int getXAxisPosition()
Get the positioning constant that tells where the x-axis is drawn. This can be LEFT, RIGHT, CENTER, or SMART.
-
setXAxisPosition
public void setXAxisPosition(int pos)
Set the positioning constant that tells where the x-axis is drawn. This can be LEFT, RIGHT, CENTER, or SMART. The default is SMART.
-
getYAxisPosition
public int getYAxisPosition()
Get the positioning constant that tells where the y-axis is drawn. This can be TOP, BOTTOM, CENTER, or SMART.
-
setYAxisPosition
public void setYAxisPosition(int pos)
Set the positioning constant that tells where the y-axis is drawn. This can be TOP, BOTTOM, CENTER, or SMART. The default is SMART.
-
getXLabel
public java.lang.String getXLabel()
Get the label that appears on the x-axis. If the value is null, no label appears.
-
setXLabel
public void setXLabel(java.lang.String s)
Set the label that appears on the x-axis. If the value is null, no label appears. This is the default.
-
getYLabel
public java.lang.String getYLabel()
Get the label that appears on the y-axis. If the value is null, no label appears.
-
setYLabel
public void setYLabel(java.lang.String s)
Set the label that appears on the y-axis. If the value is null, no label appears. This is the default.
-
draw
public void draw(java.awt.Graphics g, boolean coordsChanged)
Draw the axes. This is not meant to be called directly.- Specified by:
draw
in classDrawable
- Parameters:
g
- The graphics context in which the Drawble is to be drawn. (The drawing can change the color in g, but should not permanently change font, painting mode, etc. Thus, every drawable is responsible for setting the color it wants to use.)coordsChanged
- Indicates whether the CoordinateRect has changed.
-
-