com.approximatrix.charting.coordsystem
Class AbstractCoordSystem

java.lang.Object
  extended by com.approximatrix.charting.render.AbstractRenderer
      extended by com.approximatrix.charting.coordsystem.AbstractCoordSystem
All Implemented Interfaces:
CoordSystem, Renderer
Direct Known Subclasses:
BoxCoordSystem, ClassicCoordSystem

public abstract class AbstractCoordSystem
extends AbstractRenderer
implements CoordSystem

Implements some common components of a Coordinate System object. Provides the render listener functionality, unit storage, decimal formats for tick marks, fonts, bounds, and margin information.

Author:
jarmstrong

Field Summary
protected  int bottommargin
          The bottom margin.
(package private)  java.awt.Rectangle bounds
          The bounds within which this object should be rendered.
protected  boolean centerObjectLabelsBetweenTicks
          Flag to center labels for object x-axis between tick marks
protected  java.text.DecimalFormat dfX
          DecimalFormat used throught on the Xaxis of the ClassicCoordSystem
protected  java.text.DecimalFormat dfY
          DecimalFormat used throught on the Yaxis of the ClassicCoordSystem
protected  int leftmargin
          The left margin
protected  javax.swing.event.EventListenerList listener
          The listener list.
protected  int rightmargin
          The right margin.
protected  boolean shouldPaintAxes
          If true, axes will be drawn, but nothing is drawn if false
protected  boolean shouldPaintGrid
          If true, a grid is painted along with the tick marks.
protected  boolean shouldPaintLabels
          If true, the labels will be painted.
protected  boolean shouldPaintOnlyTick
          if true only the tick will be painted on the yaxis.
protected  java.awt.Font tickFont
          The font used for labeling tick marks
protected  int topmargin
          The top margin.
protected  java.awt.Font unitFont
          The font used for axis units
protected  Axis xaxis
          The xaxis.
protected  java.lang.String xaxis_unit
          The x-axis caption string.
protected  java.awt.geom.AffineTransform y1transform
          The multiplication matrix for the first y-axis and the x-axis.
protected  java.awt.geom.AffineTransform y2transform
          The multiplication matrix for the second y-axis and the x-axis.
protected  Axis yaxis
          The first y-axis.
protected  java.lang.String yaxis_unit
          The y-axis caption string.
protected  Axis yaxis2
          The second y-axis.
 
Fields inherited from interface com.approximatrix.charting.coordsystem.CoordSystem
FIRST_YAXIS, SECOND_YAXIS
 
Constructor Summary
AbstractCoordSystem()
           
 
Method Summary
 void addRenderChangeListener(RenderChangeListener l)
          Adds a RenderChangeListener.
 void clearRenderChangeListeners()
          Clears all RenderChangeListeners from the object
protected abstract  int computeBottomMargin()
          Computes the bottom margin.
protected abstract  int computeLeftMargin()
          Computes the left margin.
protected abstract  int computeRightMargin()
          Computes the right margin.
protected abstract  int computeTopMargin()
          Computes the top margin.
 void fireRenderChangeEvent()
          Protected function that fires a render change event, notifying any listeners that this renderable component needs to be redrawn.
protected  int getBottomMargin()
          Returns the bottom margin.
 java.awt.Rectangle getBounds()
          Gets the bounds for this renderer.
 java.awt.geom.AffineTransform getDefaultTransform(int axis)
          This method computes the default transform which transforms the user space coordinates of this coordinate system to the pixel space coordinates used in the Graphics object.
 Axis getFirstYAxis()
          Returns the first y-axis.
 java.awt.Font getFont()
          Deprecated. Deprecated in version 1.4 - use getTickFont()
 java.awt.Rectangle getInnerBounds()
          Returns the inner margin, ie the bounds minus the margins.
protected  int getLeftMargin()
          Returns the left margin.
 boolean getPaintGrid()
          Returns whether a grid is painted.
 java.awt.Dimension getPreferredSize()
          Returns the preferred size needed for the renderer.
protected  int getRightMargin()
          Returns the right margin.
 Axis getSecondYAxis()
          Returns the second y-axis.
 java.awt.Font getTickFont()
          Returns the font used for the axis tick labels.
protected  int getTopMargin()
          Returns the top margin.
 java.awt.geom.AffineTransform getTransform(int axis)
          Returns the currently defined AffineTransform for any y-axis.
 java.awt.Font getUnitFont()
          Returns the font used for the axis unit labels.
 Axis getXAxis()
          Returns the x axis.
 java.lang.String getXAxisUnit()
          Gets the x-axis unit string.
 java.text.DecimalFormat getXDecimalFormat()
          Returns the DecimalFormat used on the Xaxis
 java.lang.String getYAxisUnit()
          Gets the y-axis label.
 java.text.DecimalFormat getYDecimalFormat()
          Returns the DecimalFormat used on the Yaxis
 boolean isCenterLabelsBetweenTicks()
          Returns true if labels are centered between ticks.
 boolean isPaintAxes()
          Returns whether axes will be painted.
 boolean isPaintGrid()
          if true, a grid will be painted on the chart
 boolean isPaintLabels()
          if true, labels will be painted for each axis
 boolean isPaintOnlyTick()
          if true only the tick will be painted on the yaxis.
abstract  void paintDefault(java.awt.Graphics2D g)
          This method is called by the paint method to do the actual painting.
 void removeRenderChangeListener(RenderChangeListener l)
          Removes a RenderChangeListener.
 void render(java.awt.Graphics2D g)
          Renders the Object in the Graphics object.
protected  void setBottomMargin(int margin)
           
 void setBounds(java.awt.Rectangle bounds)
          Sets the bounds the layout manager has assigned to this renderer.
 void setCenterLabelsBetweenTicks(boolean value)
          Forces the coordinate system to place the label centered between tick marks (for bar charts for example).
 void setFirstYAxis(Axis a)
          Sets the left y-axis and computes the matrix transformation.
 void setFont(java.awt.Font f)
          Sets the font for the axis tick labels.
protected  void setLeftMargin(int margin)
          Sets the left margin.
 void setPaintAxes(boolean axes)
          Sets whether the axes will be painted.
 void setPaintGrid(boolean value)
          Sets whether a grid is painted.
 void setPaintLabels(boolean label)
          Sets whether labels should be painted for the axes
protected  void setRightMargin(int margin)
          Sets the right margin.
 void setSecondYAxis(Axis a)
          Sets the second y-axis and computes the matrix transformation.
 void setTickFont(java.awt.Font f)
          Sets the font for the axis tick labels.
protected  void setTopMargin(int margin)
          Sets the top margin.
 void setTransform(java.awt.geom.AffineTransform at, int axis)
          Sets the coordinate transformation for any y-coordinate.
protected  void setTransforms()
          Sets axes transforms for this coordinate system
 void setUnitFont(java.awt.Font f)
          Sets the font for the axis unit labels.
 void setXAxis(Axis a)
          Sets the x-axis.
 void setXAxisUnit(java.lang.String xunit)
          Sets the X axis unit to be displayed along the x axis
 void setXDecimalFormat(java.text.DecimalFormat df)
          Returns the DecimalFormat used on the Xaxis
 void setYAxisUnit(java.lang.String yunit)
          Sets the Y axis unit to be displayed along the y axis
 void setYDecimalFormat(java.text.DecimalFormat df)
          Returns the DecimalFormat used on the Yaxis
 
Methods inherited from class com.approximatrix.charting.render.AbstractRenderer
getDirectRender, isDifferentBounds, setDirectRender
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.approximatrix.charting.coordsystem.CoordSystem
chartDataChanged, getChartDataModelConstraints, getMaximumXTicks, getMaximumYTicks, resetMaximumXTicks, resetMaximumYTicks, setMaximumXTicks, setMaximumYTicks
 

Field Detail

listener

protected javax.swing.event.EventListenerList listener
The listener list.


xaxis_unit

protected java.lang.String xaxis_unit
The x-axis caption string.


yaxis_unit

protected java.lang.String yaxis_unit
The y-axis caption string.


dfY

protected java.text.DecimalFormat dfY
DecimalFormat used throught on the Yaxis of the ClassicCoordSystem


dfX

protected java.text.DecimalFormat dfX
DecimalFormat used throught on the Xaxis of the ClassicCoordSystem


tickFont

protected java.awt.Font tickFont
The font used for labeling tick marks


unitFont

protected java.awt.Font unitFont
The font used for axis units


xaxis

protected Axis xaxis
The xaxis.


yaxis

protected Axis yaxis
The first y-axis.


yaxis2

protected Axis yaxis2
The second y-axis.


leftmargin

protected int leftmargin
The left margin


topmargin

protected int topmargin
The top margin.


rightmargin

protected int rightmargin
The right margin.


bottommargin

protected int bottommargin
The bottom margin.


shouldPaintOnlyTick

protected boolean shouldPaintOnlyTick
if true only the tick will be painted on the yaxis. Alternately, if false, a light grey line will paint across the background of the chart.


shouldPaintLabels

protected boolean shouldPaintLabels
If true, the labels will be painted. If false, only the ticks will display.


shouldPaintGrid

protected boolean shouldPaintGrid
If true, a grid is painted along with the tick marks.


shouldPaintAxes

protected boolean shouldPaintAxes
If true, axes will be drawn, but nothing is drawn if false


bounds

java.awt.Rectangle bounds
The bounds within which this object should be rendered.


y1transform

protected java.awt.geom.AffineTransform y1transform
The multiplication matrix for the first y-axis and the x-axis.


y2transform

protected java.awt.geom.AffineTransform y2transform
The multiplication matrix for the second y-axis and the x-axis.


centerObjectLabelsBetweenTicks

protected boolean centerObjectLabelsBetweenTicks
Flag to center labels for object x-axis between tick marks

Constructor Detail

AbstractCoordSystem

public AbstractCoordSystem()
Method Detail

getFont

public java.awt.Font getFont()
Deprecated. Deprecated in version 1.4 - use getTickFont()

Description copied from interface: CoordSystem
Returns the font used for the axis tick labels.

Specified by:
getFont in interface CoordSystem
Returns:
the Font object

getTickFont

public java.awt.Font getTickFont()
Description copied from interface: CoordSystem
Returns the font used for the axis tick labels.

Specified by:
getTickFont in interface CoordSystem
Returns:
the Font object

getUnitFont

public java.awt.Font getUnitFont()
Description copied from interface: CoordSystem
Returns the font used for the axis unit labels.

Specified by:
getUnitFont in interface CoordSystem
Returns:
the Font object

getXAxis

public Axis getXAxis()
Description copied from interface: CoordSystem
Returns the x axis.

Specified by:
getXAxis in interface CoordSystem
Returns:
the x-axis

getXAxisUnit

public java.lang.String getXAxisUnit()
Description copied from interface: CoordSystem
Gets the x-axis unit string.

Specified by:
getXAxisUnit in interface CoordSystem
Returns:
the label String

getXDecimalFormat

public java.text.DecimalFormat getXDecimalFormat()
Description copied from interface: CoordSystem
Returns the DecimalFormat used on the Xaxis

Specified by:
getXDecimalFormat in interface CoordSystem

getYAxisUnit

public java.lang.String getYAxisUnit()
Description copied from interface: CoordSystem
Gets the y-axis label.

Specified by:
getYAxisUnit in interface CoordSystem
Returns:
the label String

getYDecimalFormat

public java.text.DecimalFormat getYDecimalFormat()
Description copied from interface: CoordSystem
Returns the DecimalFormat used on the Yaxis

Specified by:
getYDecimalFormat in interface CoordSystem

paintDefault

public abstract void paintDefault(java.awt.Graphics2D g)
Description copied from class: AbstractRenderer
This method is called by the paint method to do the actual painting. The painting is supposed to start at point (0,0) and the size is always the same as the preferred size. The paint method performs the possible scaling.

Specified by:
paintDefault in interface CoordSystem
Specified by:
paintDefault in class AbstractRenderer
Parameters:
g - the Graphics2D object to paint in.

render

public void render(java.awt.Graphics2D g)
Description copied from class: AbstractRenderer
Renders the Object in the Graphics object. Creates a BufferedImage and the corresponding Graphics2D object to paint in. The Image is created using the preferred size. Afterwards paintDefault is called to perform a standard painting in the Graphics object. If the bounds and the preferred size don't match the image is scaled afterwards.

Specified by:
render in interface CoordSystem
Specified by:
render in interface Renderer
Overrides:
render in class AbstractRenderer
Parameters:
g - the Graphics2D object in which to render

setFont

public void setFont(java.awt.Font f)
Description copied from interface: CoordSystem
Sets the font for the axis tick labels.

Specified by:
setFont in interface CoordSystem
Parameters:
f - the Font to be used

setTickFont

public void setTickFont(java.awt.Font f)
Description copied from interface: CoordSystem
Sets the font for the axis tick labels.

Specified by:
setTickFont in interface CoordSystem
Parameters:
f - the Font to be used

setUnitFont

public void setUnitFont(java.awt.Font f)
Description copied from interface: CoordSystem
Sets the font for the axis unit labels.

Specified by:
setUnitFont in interface CoordSystem
Parameters:
f - the Font to be used
See Also:
CoordSystem.setUnitFont(java.awt.Font)

getBounds

public java.awt.Rectangle getBounds()
Description copied from class: AbstractRenderer
Gets the bounds for this renderer.

Specified by:
getBounds in interface Renderer
Overrides:
getBounds in class AbstractRenderer
Returns:
the bounds of this renderer. If setBounds has not been called before, the bounds computed from getPreferredSize is returned.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Description copied from interface: CoordSystem
Returns the preferred size needed for the renderer.

Specified by:
getPreferredSize in interface CoordSystem
Specified by:
getPreferredSize in interface Renderer
Returns:
a Dimension with the minimum Integer values.

setBounds

public void setBounds(java.awt.Rectangle bounds)
Description copied from class: AbstractRenderer
Sets the bounds the layout manager has assigned to this renderer. Those, of course, have to be considered in the rendering process.

Specified by:
setBounds in interface CoordSystem
Specified by:
setBounds in interface Renderer
Overrides:
setBounds in class AbstractRenderer
Parameters:
bounds - the new bounds for the renderer.

setTransforms

protected void setTransforms()
Sets axes transforms for this coordinate system


isPaintOnlyTick

public boolean isPaintOnlyTick()
Description copied from interface: CoordSystem
if true only the tick will be painted on the yaxis. Alternately a light grey line will paint across the background of the chart.

Specified by:
isPaintOnlyTick in interface CoordSystem

isPaintLabels

public boolean isPaintLabels()
Description copied from interface: CoordSystem
if true, labels will be painted for each axis

Specified by:
isPaintLabels in interface CoordSystem
Returns:
true if labels will be painted, false otherwise

isPaintGrid

public boolean isPaintGrid()
Description copied from interface: CoordSystem
if true, a grid will be painted on the chart

Specified by:
isPaintGrid in interface CoordSystem
Returns:
true if grid will be painted, false otherwise

setPaintGrid

public void setPaintGrid(boolean value)
Description copied from interface: CoordSystem
Sets whether a grid is painted.

Specified by:
setPaintGrid in interface CoordSystem
Parameters:
value - whether the grid should be painted

getPaintGrid

public boolean getPaintGrid()
Description copied from interface: CoordSystem
Returns whether a grid is painted.

Specified by:
getPaintGrid in interface CoordSystem

setPaintLabels

public void setPaintLabels(boolean label)
Description copied from interface: CoordSystem
Sets whether labels should be painted for the axes

Specified by:
setPaintLabels in interface CoordSystem
Parameters:
label - true to paint labels, false otherwise

isPaintAxes

public boolean isPaintAxes()
Description copied from interface: CoordSystem
Returns whether axes will be painted. If true, the axes, at minimum, will be painted. If false, all ClassicCoordSystem painting is skipped regardless of other settings.

Specified by:
isPaintAxes in interface CoordSystem
Returns:
true if axes are to be painted, false otherwise

setPaintAxes

public void setPaintAxes(boolean axes)
Description copied from interface: CoordSystem
Sets whether the axes will be painted. If set to false, the ClassicCoordSystem object will perform no painting whatsoever, regardless of other settings.

Specified by:
setPaintAxes in interface CoordSystem
Parameters:
axes - true to paint axes, false otherwise

setXAxis

public void setXAxis(Axis a)
Description copied from interface: CoordSystem
Sets the x-axis.

Specified by:
setXAxis in interface CoordSystem
Parameters:
a - the x-axis

setFirstYAxis

public void setFirstYAxis(Axis a)
Description copied from interface: CoordSystem
Sets the left y-axis and computes the matrix transformation.

Specified by:
setFirstYAxis in interface CoordSystem
Parameters:
a - the left y-axis

getFirstYAxis

public Axis getFirstYAxis()
Description copied from interface: CoordSystem
Returns the first y-axis.

Specified by:
getFirstYAxis in interface CoordSystem
Returns:
the left y-axis

setSecondYAxis

public void setSecondYAxis(Axis a)
Description copied from interface: CoordSystem
Sets the second y-axis and computes the matrix transformation.

Specified by:
setSecondYAxis in interface CoordSystem
Parameters:
a - the right y-axis

getSecondYAxis

public Axis getSecondYAxis()
Description copied from interface: CoordSystem
Returns the second y-axis.

Specified by:
getSecondYAxis in interface CoordSystem
Returns:
the right y-axis

setXAxisUnit

public void setXAxisUnit(java.lang.String xunit)
Sets the X axis unit to be displayed along the x axis

Specified by:
setXAxisUnit in interface CoordSystem
Parameters:
xunit - the text to display

setYAxisUnit

public void setYAxisUnit(java.lang.String yunit)
Sets the Y axis unit to be displayed along the y axis

Specified by:
setYAxisUnit in interface CoordSystem
Parameters:
yunit - the text to display

setXDecimalFormat

public void setXDecimalFormat(java.text.DecimalFormat df)
Description copied from interface: CoordSystem
Returns the DecimalFormat used on the Xaxis

Specified by:
setXDecimalFormat in interface CoordSystem
See Also:
CoordSystem.setXDecimalFormat(java.text.DecimalFormat)

setYDecimalFormat

public void setYDecimalFormat(java.text.DecimalFormat df)
Description copied from interface: CoordSystem
Returns the DecimalFormat used on the Yaxis

Specified by:
setYDecimalFormat in interface CoordSystem
See Also:
CoordSystem.setYDecimalFormat(java.text.DecimalFormat)

fireRenderChangeEvent

public void fireRenderChangeEvent()
Protected function that fires a render change event, notifying any listeners that this renderable component needs to be redrawn.

Specified by:
fireRenderChangeEvent in interface Renderer
Overrides:
fireRenderChangeEvent in class AbstractRenderer

removeRenderChangeListener

public void removeRenderChangeListener(RenderChangeListener l)
Removes a RenderChangeListener.

Specified by:
removeRenderChangeListener in interface Renderer
Overrides:
removeRenderChangeListener in class AbstractRenderer
Parameters:
l - the RenderChangeListener

addRenderChangeListener

public void addRenderChangeListener(RenderChangeListener l)
Adds a RenderChangeListener.

Specified by:
addRenderChangeListener in interface Renderer
Overrides:
addRenderChangeListener in class AbstractRenderer
Parameters:
l - the RenderChangeListener

clearRenderChangeListeners

public void clearRenderChangeListeners()
Clears all RenderChangeListeners from the object

Specified by:
clearRenderChangeListeners in interface Renderer
Overrides:
clearRenderChangeListeners in class AbstractRenderer

getLeftMargin

protected int getLeftMargin()
Returns the left margin.


getRightMargin

protected int getRightMargin()
Returns the right margin.


getTopMargin

protected int getTopMargin()
Returns the top margin.


getBottomMargin

protected int getBottomMargin()
Returns the bottom margin.


setLeftMargin

protected void setLeftMargin(int margin)
Sets the left margin.

Parameters:
margin - the new margin value

setRightMargin

protected void setRightMargin(int margin)
Sets the right margin.

Parameters:
margin - the new margin value

setTopMargin

protected void setTopMargin(int margin)
Sets the top margin.

Parameters:
margin - the new margin value

setBottomMargin

protected void setBottomMargin(int margin)

computeLeftMargin

protected abstract int computeLeftMargin()
Computes the left margin.

Parameters:
margin - the new margin value

computeRightMargin

protected abstract int computeRightMargin()
Computes the right margin.

Parameters:
margin - the new margin value

computeTopMargin

protected abstract int computeTopMargin()
Computes the top margin.

Parameters:
margin - the new margin value

computeBottomMargin

protected abstract int computeBottomMargin()
Computes the bottom margin.

Parameters:
margin - the new margin value

getInnerBounds

public java.awt.Rectangle getInnerBounds()
Description copied from interface: CoordSystem
Returns the inner margin, ie the bounds minus the margins.

Specified by:
getInnerBounds in interface CoordSystem
Returns:
a Rectangle object defining the inner bounds.

getDefaultTransform

public java.awt.geom.AffineTransform getDefaultTransform(int axis)
Description copied from interface: CoordSystem
This method computes the default transform which transforms the user space coordinates of this coordinate system to the pixel space coordinates used in the Graphics object. All rendering in the CoordinateSystem and the ChartRenderers will rely on this transform.

Specified by:
getDefaultTransform in interface CoordSystem
Parameters:
axis - defines which y-axis to use.

getTransform

public java.awt.geom.AffineTransform getTransform(int axis)
Description copied from interface: CoordSystem
Returns the currently defined AffineTransform for any y-axis.

Specified by:
getTransform in interface CoordSystem
Parameters:
axis - the y-axis to be used.

setTransform

public void setTransform(java.awt.geom.AffineTransform at,
                         int axis)
Description copied from interface: CoordSystem
Sets the coordinate transformation for any y-coordinate.

Specified by:
setTransform in interface CoordSystem
Parameters:
at - the AffineTransform that transforms the coordinates into pixel space

isCenterLabelsBetweenTicks

public boolean isCenterLabelsBetweenTicks()
Description copied from interface: CoordSystem
Returns true if labels are centered between ticks.

Specified by:
isCenterLabelsBetweenTicks in interface CoordSystem
Returns:
true if centered between ticks, false if centered on ticks

setCenterLabelsBetweenTicks

public void setCenterLabelsBetweenTicks(boolean value)
Description copied from interface: CoordSystem
Forces the coordinate system to place the label centered between tick marks (for bar charts for example).

Specified by:
setCenterLabelsBetweenTicks in interface CoordSystem
Parameters:
value - true to center, false otherwise