com.jrefinery.chart
Class Axis

java.lang.Object
  extended by com.jrefinery.chart.Axis
All Implemented Interfaces:
AxisConstants
Direct Known Subclasses:
CategoryAxis, ValueAxis, WindAxis

public abstract class Axis
extends java.lang.Object
implements AxisConstants

The base class for all axes in JFreeChart.

See Also:
CategoryAxis, ValueAxis

Field Summary
protected  double fixedDimension
          The fixed (horizontal or vertical) dimension for the axis.
protected  java.lang.String label
          The label for the axis.
protected  java.awt.Font labelFont
          The font for displaying the axis label.
protected  java.awt.Insets labelInsets
          The insets for the axis label.
protected  java.awt.Paint labelPaint
          The paint for drawing the axis label.
protected  java.util.List listeners
          Storage for registered listeners (objects interested in receiving change events for the axis).
protected  Plot plot
          A reference back to the plot that the axis is assigned to (can be null).
protected  java.awt.Font tickLabelFont
          The font used to display the tick labels.
protected  java.awt.Insets tickLabelInsets
          The blank space around each tick label.
protected  java.awt.Paint tickLabelPaint
          The color used to display the tick labels.
protected  boolean tickLabelsVisible
          A flag that indicates whether or not tick labels are visible for the axis.
protected  java.awt.Stroke tickMarkStroke
          The line type used to draw tick marks.
protected  boolean tickMarksVisible
          A flag that indicates whether or not tick marks are visible for the axis.
protected  java.util.List ticks
          A working list of ticks - this list is refreshed as required.
protected  boolean visible
          A flag indicating whether or not the axis is visible.
 
Fields inherited from interface com.jrefinery.chart.AxisConstants
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_STROKE
 
Constructor Summary
protected Axis(java.lang.String label)
          Constructs an axis, using default values where necessary.
protected Axis(java.lang.String label, java.awt.Font labelFont, java.awt.Paint labelPaint, java.awt.Insets labelInsets, boolean tickLabelsVisible, java.awt.Font tickLabelFont, java.awt.Paint tickLabelPaint, java.awt.Insets tickLabelInsets, boolean tickMarkVisible, java.awt.Stroke tickMarkStroke)
          Constructs an axis.
 
Method Summary
 void addChangeListener(com.jrefinery.chart.event.AxisChangeListener listener)
          Registers an object for notification of changes to the axis.
abstract  void configure()
          Configures the axis to work with the cuurent plot.
abstract  void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea)
          Draws the axis on a Java 2D graphics device (such as the screen or a printer).
 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.
 java.awt.Stroke getTickMarkStroke()
          Returns the pen/brush used to draw tick marks (if they are showing).
protected abstract  boolean isCompatiblePlot(Plot plot)
          Returns true if the plot is compatible with the axis, and false otherwise.
 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(com.jrefinery.chart.event.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)
          Calculates the positions of the ticks for the axis, storing the results in the tick list (ready for drawing).
 void removeChangeListener(com.jrefinery.chart.event.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 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, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

visible

protected boolean visible
A flag indicating whether or not the axis is visible.


label

protected java.lang.String label
The label for the axis.


labelFont

protected java.awt.Font labelFont
The font for displaying the axis label.


labelPaint

protected java.awt.Paint labelPaint
The paint for drawing the axis label.


labelInsets

protected java.awt.Insets labelInsets
The insets for the axis label.


tickLabelsVisible

protected boolean tickLabelsVisible
A flag that indicates whether or not tick labels are visible for the axis.


tickLabelFont

protected java.awt.Font tickLabelFont
The font used to display the tick labels.


tickLabelPaint

protected java.awt.Paint tickLabelPaint
The color used to display the tick labels.


tickLabelInsets

protected java.awt.Insets tickLabelInsets
The blank space around each tick label.


tickMarksVisible

protected boolean tickMarksVisible
A flag that indicates whether or not tick marks are visible for the axis.


tickMarkStroke

protected java.awt.Stroke tickMarkStroke
The line type used to draw tick marks.


ticks

protected java.util.List ticks
A working list of ticks - this list is refreshed as required.


listeners

protected java.util.List listeners
Storage for registered listeners (objects interested in receiving change events for the axis).


plot

protected Plot plot
A reference back to the plot that the axis is assigned to (can be null).


fixedDimension

protected double fixedDimension
The fixed (horizontal or vertical) dimension for the axis.

Constructor Detail

Axis

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

Parameters:
label - The axis label (null permitted).

Axis

protected Axis(java.lang.String label,
               java.awt.Font labelFont,
               java.awt.Paint labelPaint,
               java.awt.Insets labelInsets,
               boolean tickLabelsVisible,
               java.awt.Font tickLabelFont,
               java.awt.Paint tickLabelPaint,
               java.awt.Insets tickLabelInsets,
               boolean tickMarkVisible,
               java.awt.Stroke tickMarkStroke)
Constructs an axis.

Parameters:
label - The axis label.
labelFont - The font for displaying the axis label.
labelPaint - The paint used to draw the axis label.
labelInsets - Determines the amount of blank space around the label.
tickLabelsVisible - Flag indicating whether or not the tick labels are visible.
tickLabelFont - The font used to display tick labels.
tickLabelPaint - The paint used to draw tick labels.
tickLabelInsets - Determines the amount of blank space around tick labels.
tickMarksVisible - Flag indicating whether or not tick marks are visible.
tickMarkStroke - The stroke used to draw tick marks (if visible).
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 for the axis label.

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:
A flag indicating whether or not the tick labels are visible.

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.

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).

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 called by Plot in the setHorizontalAxis() and setVerticalAxis() methods. You shouldn't need to call the method yourself.

Parameters:
plot - The plot that the axis belongs to.
Throws:
PlotNotCompatibleException

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:
The - fixed dimension.

draw

public abstract void draw(java.awt.Graphics2D g2,
                          java.awt.geom.Rectangle2D plotArea,
                          java.awt.geom.Rectangle2D dataArea)
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.

refreshTicks

public abstract void refreshTicks(java.awt.Graphics2D g2,
                                  java.awt.geom.Rectangle2D plotArea,
                                  java.awt.geom.Rectangle2D dataArea)
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 within which the plot should be drawn.

configure

public abstract void configure()
Configures the axis to work with the cuurent 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.

isCompatiblePlot

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

Parameters:
plot - The plot.
Returns:
True if the plot is compatible with the axis, and false otherwise.

notifyListeners

protected void notifyListeners(com.jrefinery.chart.event.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.

addChangeListener

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

Parameters:
listener - The object that is being registered.

removeChangeListener

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

Parameters:
listener - The object to deregister.


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.