com.approximatrix.charting
Class CoordSystem

java.lang.Object
  extended by com.approximatrix.charting.render.AbstractRenderer
      extended by com.approximatrix.charting.CoordSystem
All Implemented Interfaces:
Renderer

public class CoordSystem
extends AbstractRenderer

This class defines a coordinate system. The CoordSystem class computes an AffineTransform for each y-axis, which translates the user space coordinates (ie. the data value coordinates) into pixel space coordinates. These AffineTransform classes make the PixelToPointTranslator obsolete, since it provides more flexibility. getDefaultTransform always computes the default transformation, whereas you can set another transformation via setTransform. This will be used to implement zooming and panning in the Swing classes.

All classes incl. this one, which render data will use the transformations to translate the coordinates. The transformations are not set up on instantiation of a CoordSystem, instead they're computed when setBounds is called, because they need this information of course. Afterwards you can set your own transformation or even better you can manipulate the existing ones by pre- or postconcatenating another AffineTransform.


Field Summary
 int ARROWLENGTH
          The arrow length constant.
protected  int bottommargin
          The bottom margin.
protected  CoordSystemUtilities c
          The utilities class, which contains all the rendering methods etc.
protected  ChartDataModelConstraints constraints
          The ChartDataModel constraints of the first y-axis and the x-axis.
protected  ChartDataModelConstraints constraints2
          The ChartDataModel constraints of the second y-axis and the x-axis.
protected  java.text.DecimalFormat dfX
          DecimalFormat used throught on the Xaxis of the CoordSystem
protected  java.text.DecimalFormat dfY
          DecimalFormat used throught on the Yaxis of the CoordSystem
static int FIRST_YAXIS
          the axis binding constant for the first y-axis
protected  java.awt.Font font
          The Font used in the CoordSystem.
protected  java.awt.font.FontRenderContext frc
          FontRenderContext used througout the CoordSystem
protected  int leftmargin
          The left margin
 int MINIMALMARGIN
          The minimal margin constant.
protected  ChartDataModel model
          The DataModel class.
protected  int rightmargin
          The right margin.
static int SECOND_YAXIS
          the axis binding constant for the second y-axis
protected  boolean shouldDrawArrows
          if true, the arrows will be drawn at the end of the axi
protected  boolean shouldPaintAltTick
          if true, the increment will be painted at each tick mark
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  int topmargin
          The top margin.
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 class com.approximatrix.charting.render.AbstractRenderer
listener
 
Constructor Summary
CoordSystem(ChartDataModel cdm)
          Creates a new CoordSystem using the given model constraints.
CoordSystem(ChartDataModel c, java.text.DecimalFormat yAxisFormat, boolean drawArrows, boolean paintAltYTick, boolean paintOnlyYTick)
          Create a new CoordSystem with alternate painting parameters.
CoordSystem(ChartDataModel c, java.lang.String xunit, java.lang.String yunit)
          Creates a new CoordSystem using the given model constraints.
 
Method Summary
protected  int getBottomMargin()
          Returns the bottom margin.
 ChartDataModelConstraints getChartDataModelConstraints(int axis)
          Returns the used ChartDataModelConstraints.
 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()
          Returns the font used for the axis labels.
 java.awt.font.FontRenderContext getFontRenderContext()
          Returns the FontRenderContext used througout the CoordSystem
 java.awt.Rectangle getInnerBounds()
          Returns the inner margin, ie the bounds minus the margins.
protected  int getLeftMargin()
          Returns the left margin.
 int getMaximumXTicks()
          Returns the maximum number of X ticks to draw on the X axis
 int getMaximumYTicks()
          Returns the maximum number of Y ticks to draw on the Y axis
 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.
protected  int getTopMargin()
          Returns the top margin.
 java.awt.geom.AffineTransform getTransform(int axis)
          Returns the currently defined AffineTransform for any y-axis.
 Axis getXAxis()
          Returns the x axis.
 java.lang.String getXAxisUnit()
          Gets the x-axis unit string.
 java.text.DecimalFormat getXDecimalFormat()
          Returns the DecimalFormat used throught on the Xaxis of the CoordSystem
 java.lang.String getYAxisUnit()
          Gets the y-axis label.
 java.text.DecimalFormat getYDecimalFormat()
          Returns the DecimalFormat used throught on the Yaxis of the CoordSystem
 boolean isDrawArrows()
          if true, the arrows will be drawn at the end of the axis
 boolean isPaintAltTick()
          if true, the increment will be painted at each tick mark
 boolean isPaintAxes()
          Returns whether axes will be painted.
 boolean isPaintLabels()
          if true, labels will be painted for each axis
 boolean isPaintOnlyTick()
          if true only the tick will be painted on the yaxis.
 void paintDefault(java.awt.Graphics2D g)
          This method is called by the paint method to do the actual painting.
 void render(java.awt.Graphics2D g)
          Overrides the method to just call paintDefault.
 void resetMaximumXTicks()
          Resets the maximum number of ticks along the X axis to the default value
 void resetMaximumYTicks()
          Resets the maximum number of ticks along the X axis to the default value
 void setBottomMargin(int margin)
          Sets the bottom margin.
 void setBounds(java.awt.Rectangle bounds)
          Computes all margins, initializes the length of the Axis and calls super.setBounds.
 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 labels.
protected  void setLeftMargin(int margin)
          Sets the left margin.
 void setMaximumXTicks(int value)
          Sets the maximum number of ticks along the X axis that will be allowed.
 void setMaximumYTicks(int value)
          Sets the maximum number of ticks along the Y axis that will be allowed.
 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.
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.
 void setXAxis(Axis a)
          Sets the x-axis.
 void setXAxisUnit(java.lang.String xunit)
          Sets the x-axis unit string.
 void setYAxisUnit(java.lang.String yunit)
          Sets the y-axis unit string.
 
Methods inherited from class com.approximatrix.charting.render.AbstractRenderer
addRenderChangeListener, clearRenderChangeListeners, fireRenderChangeEvent, getBounds, getDirectRender, isDifferentBounds, removeRenderChangeListener, setDirectRender
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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.


font

protected java.awt.Font font
The Font used in the CoordSystem.


frc

protected final java.awt.font.FontRenderContext frc
FontRenderContext used througout the CoordSystem


dfY

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


dfX

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


shouldDrawArrows

protected boolean shouldDrawArrows
if true, the arrows will be drawn at the end of the axi


shouldPaintAltTick

protected boolean shouldPaintAltTick
if true, the increment will be painted at each tick mark


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


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.


MINIMALMARGIN

public final int MINIMALMARGIN
The minimal margin constant.

See Also:
Constant Field Values

ARROWLENGTH

public final int ARROWLENGTH
The arrow length constant.

See Also:
Constant Field Values

constraints

protected ChartDataModelConstraints constraints
The ChartDataModel constraints of the first y-axis and the x-axis.


constraints2

protected ChartDataModelConstraints constraints2
The ChartDataModel constraints of the second y-axis and the x-axis.


model

protected ChartDataModel model
The DataModel class.


c

protected CoordSystemUtilities c
The utilities class, which contains all the rendering methods etc.


xaxis

protected Axis xaxis
The xaxis.


yaxis

protected Axis yaxis
The first y-axis.


yaxis2

protected Axis yaxis2
The second y-axis.


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.


FIRST_YAXIS

public static final int FIRST_YAXIS
the axis binding constant for the first y-axis

See Also:
Constant Field Values

SECOND_YAXIS

public static final int SECOND_YAXIS
the axis binding constant for the second y-axis

See Also:
Constant Field Values
Constructor Detail

CoordSystem

public CoordSystem(ChartDataModel cdm)
Creates a new CoordSystem using the given model constraints. Also creates default linear x and y-axis. Note that the length of the axis are set on the first call to setBounds().

Parameters:
c - the ChartDataModel needed to compute the DataConstraints.

CoordSystem

public CoordSystem(ChartDataModel c,
                   java.lang.String xunit,
                   java.lang.String yunit)
Creates a new CoordSystem using the given model constraints. Also creates default linear x and y-axis. Note that the length of the axis are set on the first call to setBounds().

Parameters:
c - the ChartDataModel needed to compute the DataConstraints.
xtext - the x-axis unit
ytext - the y-axis unit

CoordSystem

public CoordSystem(ChartDataModel c,
                   java.text.DecimalFormat yAxisFormat,
                   boolean drawArrows,
                   boolean paintAltYTick,
                   boolean paintOnlyYTick)
Create a new CoordSystem with alternate painting parameters.

Parameters:
c - the ChartDataModel needed to compute the DataConstraints.
drawArrows - if true the arrows will be drawn at the end of the axis
paintAltYTick - if true the caption will paint on alternate ticks of the yaxis instead of on every one.
paintOnlyYTick - if true the horizontal lightgray line will not appear behind the chart at each yaxis tick mark.
Method Detail

setTransform

public void setTransform(java.awt.geom.AffineTransform at,
                         int axis)
Sets the coordinate transformation for any y-coordinate.

Parameters:
at - the AffineTransform that transforms the coordinates into pixel space

getTransform

public java.awt.geom.AffineTransform getTransform(int axis)
Returns the currently defined AffineTransform for any y-axis.

Parameters:
axis - the y-axis to be used.

getDefaultTransform

public 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. All rendering in the CoordinateSystem and the ChartRenderers will rely on this transform.

Parameters:
axis - defines which y-axis to use.

setPaintGrid

public void setPaintGrid(boolean value)
Sets whether a grid is painted.

Parameters:
value - whether the grid should be painted

getPaintGrid

public boolean getPaintGrid()
Returns whether a grid is painted.


setXAxis

public void setXAxis(Axis a)
Sets the x-axis.

Parameters:
a - the x-axis

getXAxis

public Axis getXAxis()
Returns the x axis.

Returns:
the x-axis

setXAxisUnit

public void setXAxisUnit(java.lang.String xunit)
Sets the x-axis unit string.

Parameters:
xtext - the unit string

getXAxisUnit

public java.lang.String getXAxisUnit()
Gets the x-axis unit string.

Returns:
the label String

setYAxisUnit

public void setYAxisUnit(java.lang.String yunit)
Sets the y-axis unit string.

Parameters:
ytext - the unit string

getYAxisUnit

public java.lang.String getYAxisUnit()
Gets the y-axis label.

Returns:
the label String

setFont

public void setFont(java.awt.Font f)
Sets the font for the axis labels.

Parameters:
f - the Font to be used

getFont

public java.awt.Font getFont()
Returns the font used for the axis labels.

Returns:
the Font object

setFirstYAxis

public void setFirstYAxis(Axis a)
Sets the left y-axis and computes the matrix transformation.

Parameters:
a - the left y-axis

getFirstYAxis

public Axis getFirstYAxis()
Returns the first y-axis.

Returns:
the left y-axis

setSecondYAxis

public void setSecondYAxis(Axis a)
Sets the second y-axis and computes the matrix transformation.

Parameters:
a - the right y-axis

getSecondYAxis

public Axis getSecondYAxis()
Returns the second y-axis.

Returns:
the right y-axis

getInnerBounds

public java.awt.Rectangle getInnerBounds()
Returns the inner margin, ie the bounds minus the margins.

Returns:
a Rectangle object defining the inner bounds.

setBounds

public void setBounds(java.awt.Rectangle bounds)
Computes all margins, initializes the length of the Axis and calls super.setBounds. Additionally, it sets the default AffineTransforms for every y-axis.

Specified by:
setBounds in interface Renderer
Overrides:
setBounds in class AbstractRenderer
Parameters:
bounds - Rectangle object defining the bounds

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size needed for the renderer.

Returns:
a Dimension with the minimum Integer values.

render

public void render(java.awt.Graphics2D g)
Overrides the method to just call paintDefault.

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

paintDefault

public void paintDefault(java.awt.Graphics2D g)
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 class AbstractRenderer
Parameters:
g - the Graphics2D object to paint in

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

public void setBottomMargin(int margin)
Sets the bottom margin.

Parameters:
margin - the new margin value

getFontRenderContext

public java.awt.font.FontRenderContext getFontRenderContext()
Returns the FontRenderContext used througout the CoordSystem


getYDecimalFormat

public java.text.DecimalFormat getYDecimalFormat()
Returns the DecimalFormat used throught on the Yaxis of the CoordSystem


getXDecimalFormat

public java.text.DecimalFormat getXDecimalFormat()
Returns the DecimalFormat used throught on the Xaxis of the CoordSystem


isDrawArrows

public boolean isDrawArrows()
if true, the arrows will be drawn at the end of the axis


isPaintAltTick

public boolean isPaintAltTick()
if true, the increment will be painted at each tick mark


isPaintOnlyTick

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


isPaintLabels

public boolean isPaintLabels()
if true, labels will be painted for each axis

Returns:
true if labels will be painted, false otherwise

setPaintLabels

public void setPaintLabels(boolean label)
Sets whether labels should be painted for the axes

Parameters:
label - true to paint labels, false otherwise

isPaintAxes

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

Returns:
true if axes are to be painted, false otherwise

setPaintAxes

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

Parameters:
axes - true to paint axes, false otherwise

getChartDataModelConstraints

public ChartDataModelConstraints getChartDataModelConstraints(int axis)
Returns the used ChartDataModelConstraints.


setMaximumXTicks

public void setMaximumXTicks(int value)
Sets the maximum number of ticks along the X axis that will be allowed.

Parameters:
value - the maximum number of X ticks, or -1 to reset to default

setMaximumYTicks

public void setMaximumYTicks(int value)
Sets the maximum number of ticks along the Y axis that will be allowed.

Parameters:
value - the maximum number of Y ticks, or -1 to reset to default

getMaximumXTicks

public int getMaximumXTicks()
Returns the maximum number of X ticks to draw on the X axis

Returns:
the maximum number of X ticks to draw

getMaximumYTicks

public int getMaximumYTicks()
Returns the maximum number of Y ticks to draw on the Y axis

Returns:
the maximum number of Y ticks to draw

resetMaximumXTicks

public void resetMaximumXTicks()
Resets the maximum number of ticks along the X axis to the default value


resetMaximumYTicks

public void resetMaximumYTicks()
Resets the maximum number of ticks along the X axis to the default value