org.jfree.chart.axis
Class Axis

java.lang.Object
  |
  +--org.jfree.chart.axis.Axis
All Implemented Interfaces:
AxisConstants, java.io.Serializable
Direct Known Subclasses:
CategoryAxis, ValueAxis

public abstract class Axis
extends java.lang.Object
implements AxisConstants, java.io.Serializable

The base class for all axes in JFreeChart. Subclasses are divided into those that display values (ValueAxis) and those that display categories (CategoryAxis).

Author:
David Gilbert
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.jfree.chart.axis.AxisConstants
BOTTOM, DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_VISIBLE, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_LABELS_VISIBLE, DEFAULT_TICK_MARK_INSIDE_LENGTH, DEFAULT_TICK_MARK_OUTSIDE_LENGTH, DEFAULT_TICK_MARK_PAINT, DEFAULT_TICK_MARK_STROKE, DEFAULT_TICK_MARKS_VISIBLE, LEFT, RIGHT, TOP
 
Constructor Summary
protected Axis(java.lang.String label)
          Constructs an axis, using default values where necessary.
 
Method Summary
 void addChangeListener(AxisChangeListener listener)
          Registers an object for notification of changes to the axis.
abstract  void configure()
          Configures the axis to work with the current plot.
abstract  void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, int location)
          Draws the axis on a Java 2D graphics device (such as the screen or a printer).
protected  double drawHorizontalLabel(java.lang.String label, java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, int location, double cursorY)
          A utility method intended for use by subclasses that are 'horizontal' axes (for example, HorizontalCategoryAxis, HorizontalCategoryAxis3D, HorizontalNumberAxis, HorizontalNumberAxis3D and HorizontalDateAxis).
protected  void drawVerticalLabel(java.lang.String label, boolean vertical, java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, int location)
          A utility method intended for use by subclasses that are 'vertical' axes (for example, VerticalCategoryAxis, VerticalNumberAxis and VerticalDateAxis.
 boolean equals(java.lang.Object obj)
          Tests this axis for equality with another object.
 double getFixedDimension()
          Returns the fixed dimension for the axis.
 java.lang.String getLabel()
          Returns the label for the axis.
 java.awt.Font getLabelFont()
          Returns the font for the axis label.
 java.awt.Insets getLabelInsets()
          Returns the insets for the label (that is, the amount of blank space that should be left around the label).
 java.awt.Paint getLabelPaint()
          Returns the color/shade used to draw the axis label.
protected  double getMaxTickLabelWidth(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea)
          Returns the maximum width of the ticks in the working list (that is set up by refreshTicks()).
 Plot getPlot()
          Returns the plot that the axis is assigned to.
 java.awt.Font getTickLabelFont()
          Returns the font used for the tick labels (if showing).
 java.awt.Insets getTickLabelInsets()
          Returns the insets for the tick labels.
 java.awt.Paint getTickLabelPaint()
          Returns the color/shade used for the tick labels.
 float getTickMarkInsideLength()
          Returns the inside length of the tick marks.
 float getTickMarkOutsideLength()
          Returns the outside length of the tick marks.
 java.awt.Paint getTickMarkPaint()
          Returns the paint used to draw tick marks (if they are showing).
 java.awt.Stroke getTickMarkStroke()
          Returns the pen/brush used to draw tick marks (if they are showing).
 java.util.List getTicks()
          Returns the current list of ticks.
protected abstract  boolean isCompatiblePlot(Plot plot)
          Returns true if the plot is compatible with the axis.
 boolean isTickLabelsVisible()
          Returns a flag indicating whether or not the tick labels are visible.
 boolean isTickMarksVisible()
          Returns the flag that indicates whether or not the tick marks are showing.
 boolean isVisible()
          Returns true if the axis is visible, and false otherwise.
protected  void notifyListeners(AxisChangeEvent event)
          Notifies all registered listeners that the axis has changed.
abstract  void refreshTicks(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, int location)
          Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).
 void removeChangeListener(AxisChangeListener listener)
          Deregisters an object for notification of changes to the axis.
 void setFixedDimension(double dimension)
          Sets the fixed dimension for the axis.
 void setLabel(java.lang.String label)
          Sets the label for the axis (null permitted).
 void setLabelFont(java.awt.Font font)
          Sets the font for the axis label.
 void setLabelInsets(java.awt.Insets insets)
          Sets the insets for the axis label, and notifies registered listeners that the axis has been modified.
 void setLabelPaint(java.awt.Paint paint)
          Sets the color/shade used to draw the axis label.
 void setPlot(Plot plot)
          Sets a reference to the plot that the axis is assigned to.
 void setTickLabelFont(java.awt.Font font)
          Sets the font for the tick labels.
 void setTickLabelInsets(java.awt.Insets insets)
          Sets the insets for the tick labels, and notifies registered listeners that the axis has been modified.
 void setTickLabelPaint(java.awt.Paint paint)
          Sets the color/shade used to draw tick labels (if they are showing).
 void setTickLabelsVisible(boolean flag)
          Sets the flag that determines whether or not the tick labels are visible.
 void setTickMarkInsideLength(float length)
          Sets the inside length of the tick marks.
 void setTickMarkOutsideLength(float length)
          Sets the outside length of the tick marks.
 void setTickMarkPaint(java.awt.Paint paint)
          Sets the paint used to draw tick marks (if they are showing).
 void setTickMarkStroke(java.awt.Stroke stroke)
          Sets the pen/brush used to draw tick marks (if they are showing).
 void setTickMarksVisible(boolean flag)
          Sets the flag that indicates whether or not the tick marks are showing.
 void setVisible(boolean flag)
          Sets a flag that controls whether or not the axis is drawn on the chart.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Axis

protected Axis(java.lang.String label)
Constructs an axis, using default values where necessary.

Parameters:
label - the axis label (null permitted).
Method Detail

isVisible

public boolean isVisible()
Returns true if the axis is visible, and false otherwise.

Returns:
a flag indicating whether or not the axis is visible.

setVisible

public void setVisible(boolean flag)
Sets a flag that controls whether or not the axis is drawn on the chart.

Parameters:
flag - the flag.

getLabel

public java.lang.String getLabel()
Returns the label for the axis.

Returns:
the label for the axis (null possible).

setLabel

public void setLabel(java.lang.String label)
Sets the label for the axis (null permitted).

Registered listeners are notified of a general change to the axis.

Parameters:
label - the new label.

getLabelFont

public java.awt.Font getLabelFont()
Returns the font for the axis label.

Returns:
the font.

setLabelFont

public void setLabelFont(java.awt.Font font)
Sets the font for the axis label.

Registered listeners are notified of a general change to the axis.

Parameters:
font - the new label font.

getLabelPaint

public java.awt.Paint getLabelPaint()
Returns the color/shade used to draw the axis label.

Returns:
the color/shade used to draw the axis label.

setLabelPaint

public void setLabelPaint(java.awt.Paint paint)
Sets the color/shade used to draw the axis label.

Registered listeners are notified of a general change to the axis.

Parameters:
paint - the new color/shade for the axis label.

getLabelInsets

public java.awt.Insets getLabelInsets()
Returns the insets for the label (that is, the amount of blank space that should be left around the label).

Returns:
the label insets.

setLabelInsets

public void setLabelInsets(java.awt.Insets insets)
Sets the insets for the axis label, and notifies registered listeners that the axis has been modified.

Parameters:
insets - the new label insets.

isTickLabelsVisible

public boolean isTickLabelsVisible()
Returns a flag indicating whether or not the tick labels are visible.

Returns:
the flag.

setTickLabelsVisible

public void setTickLabelsVisible(boolean flag)
Sets the flag that determines whether or not the tick labels are visible.

Registered listeners are notified of a general change to the axis.

Parameters:
flag - the flag.

getTickLabelFont

public java.awt.Font getTickLabelFont()
Returns the font used for the tick labels (if showing).

Returns:
the font used for the tick labels.

setTickLabelFont

public void setTickLabelFont(java.awt.Font font)
Sets the font for the tick labels.

Registered listeners are notified of a general change to the axis.

Parameters:
font - the new tick label font.

getTickLabelPaint

public java.awt.Paint getTickLabelPaint()
Returns the color/shade used for the tick labels.

Returns:
the color/shade used for the tick labels.

setTickLabelPaint

public void setTickLabelPaint(java.awt.Paint paint)
Sets the color/shade used to draw tick labels (if they are showing).

Registered listeners are notified of a general change to the axis.

Parameters:
paint - the new color/shade.

getTickLabelInsets

public java.awt.Insets getTickLabelInsets()
Returns the insets for the tick labels.

Returns:
the insets for the tick labels.

setTickLabelInsets

public void setTickLabelInsets(java.awt.Insets insets)
Sets the insets for the tick labels, and notifies registered listeners that the axis has been modified.

Parameters:
insets - the new tick label insets.

isTickMarksVisible

public boolean isTickMarksVisible()
Returns the flag that indicates whether or not the tick marks are showing.

Returns:
the flag that indicates whether or not the tick marks are showing.

setTickMarksVisible

public void setTickMarksVisible(boolean flag)
Sets the flag that indicates whether or not the tick marks are showing.

Registered listeners are notified of a general change to the axis.

Parameters:
flag - the flag.

getTickMarkInsideLength

public float getTickMarkInsideLength()
Returns the inside length of the tick marks.

Returns:
the length.

setTickMarkInsideLength

public void setTickMarkInsideLength(float length)
Sets the inside length of the tick marks.

Parameters:
length - the new length.

getTickMarkOutsideLength

public float getTickMarkOutsideLength()
Returns the outside length of the tick marks.

Returns:
the length.

setTickMarkOutsideLength

public void setTickMarkOutsideLength(float length)
Sets the outside length of the tick marks.

Parameters:
length - the new length.

getTickMarkStroke

public java.awt.Stroke getTickMarkStroke()
Returns the pen/brush used to draw tick marks (if they are showing).

Returns:
the pen/brush used to draw tick marks.

setTickMarkStroke

public void setTickMarkStroke(java.awt.Stroke stroke)
Sets the pen/brush used to draw tick marks (if they are showing).

Registered listeners are notified of a general change to the axis.

Parameters:
stroke - the new pen/brush (null not permitted).

getTickMarkPaint

public java.awt.Paint getTickMarkPaint()
Returns the paint used to draw tick marks (if they are showing).

Returns:
the paint.

setTickMarkPaint

public void setTickMarkPaint(java.awt.Paint paint)
Sets the paint used to draw tick marks (if they are showing).

Registered listeners are notified of a general change to the axis.

Parameters:
paint - the new paint (null not permitted).

getTicks

public java.util.List getTicks()
Returns the current list of ticks.

Returns:
the ticks.

getPlot

public Plot getPlot()
Returns the plot that the axis is assigned to.

This method will return null if the axis is not currently assigned to a plot.

Returns:
The plot that the axis is assigned to.

setPlot

public void setPlot(Plot plot)
             throws PlotNotCompatibleException
Sets a reference to the plot that the axis is assigned to.

This method is used internally, you shouldn't need to call it yourself.

Parameters:
plot - the plot.
Throws:
PlotNotCompatibleException - if plot is not compatible.

getFixedDimension

public double getFixedDimension()
Returns the fixed dimension for the axis.

Returns:
the fixed dimension.

setFixedDimension

public void setFixedDimension(double dimension)
Sets the fixed dimension for the axis.

This is used when combining more than one plot on a chart. In this case, there may be several axes that need to have the same height or width so that they are aligned. This method is used to fix a dimension for the axis (the context determines whether the dimension is horizontal or vertical).

Parameters:
dimension - the fixed dimension.

draw

public abstract void draw(java.awt.Graphics2D g2,
                          java.awt.geom.Rectangle2D plotArea,
                          java.awt.geom.Rectangle2D dataArea,
                          int location)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).

Parameters:
g2 - the graphics device.
plotArea - the area within which the axes and plot should be drawn.
dataArea - the area within which the data should be drawn.
location - the axis location (TOP, BOTTOM, RIGHT or LEFT).

refreshTicks

public abstract void refreshTicks(java.awt.Graphics2D g2,
                                  java.awt.geom.Rectangle2D plotArea,
                                  java.awt.geom.Rectangle2D dataArea,
                                  int location)
Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).

Parameters:
g2 - the graphics device.
plotArea - the area within which the axes and plot should be drawn.
dataArea - the area inside the axes.
location - the axis location.

configure

public abstract void configure()
Configures the axis to work with the current plot. Override this method to perform any special processing (such as auto-rescaling).


getMaxTickLabelWidth

protected double getMaxTickLabelWidth(java.awt.Graphics2D g2,
                                      java.awt.geom.Rectangle2D plotArea)
Returns the maximum width of the ticks in the working list (that is set up by refreshTicks()).

Parameters:
g2 - the graphics device.
plotArea - the area within which the plot is to be drawn.
Returns:
the maximum width of the ticks in the working list.

isCompatiblePlot

protected abstract boolean isCompatiblePlot(Plot plot)
Returns true if the plot is compatible with the axis.

Parameters:
plot - the plot.
Returns:
true if the plot is compatible with the axis.

addChangeListener

public void addChangeListener(AxisChangeListener listener)
Registers an object for notification of changes to the axis.

Parameters:
listener - the object that is being registered.

removeChangeListener

public void removeChangeListener(AxisChangeListener listener)
Deregisters an object for notification of changes to the axis.

Parameters:
listener - the object to deregister.

notifyListeners

protected void notifyListeners(AxisChangeEvent event)
Notifies all registered listeners that the axis has changed. The AxisChangeEvent provides information about the change.

Parameters:
event - information about the change to the axis.

drawHorizontalLabel

protected double drawHorizontalLabel(java.lang.String label,
                                     java.awt.Graphics2D g2,
                                     java.awt.geom.Rectangle2D plotArea,
                                     java.awt.geom.Rectangle2D dataArea,
                                     int location,
                                     double cursorY)
A utility method intended for use by subclasses that are 'horizontal' axes (for example, HorizontalCategoryAxis, HorizontalCategoryAxis3D, HorizontalNumberAxis, HorizontalNumberAxis3D and HorizontalDateAxis).

Parameters:
label - the label.
g2 - the graphics device.
plotArea - the plot area.
dataArea - the data area.
location - the axis location (TOP or BOTTOM).
cursorY - the Y cursor.
Returns:
the updated value of the Y cursor.

drawVerticalLabel

protected void drawVerticalLabel(java.lang.String label,
                                 boolean vertical,
                                 java.awt.Graphics2D g2,
                                 java.awt.geom.Rectangle2D plotArea,
                                 java.awt.geom.Rectangle2D dataArea,
                                 int location)
A utility method intended for use by subclasses that are 'vertical' axes (for example, VerticalCategoryAxis, VerticalNumberAxis and VerticalDateAxis.

Parameters:
label - the label.
vertical - rotate the label to vertical?
g2 - the graphics device.
plotArea - the plot area.
dataArea - the data area.
location - the axis location (TOP or BOTTOM).

equals

public boolean equals(java.lang.Object obj)
Tests this axis for equality with another object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object.
Returns:
true or false.