com.odesys.chart
Class Grid

java.lang.Object
  |
  +--com.odesys.chart.Grid

public class Grid
extends java.lang.Object

Grid is a helper class that draws a coordinate grid. It uses a rectangular coordinate system Oxy. Grid calculates and positions the axes so they use all the available area.


Field Summary
static int BOTTOM
          Constant used to specify the bottom side of the Grid.
static int LEFT
          Constant used to specify the left side of the Grid.
static int RIGHT
          Constant used to specify the right side of the Grid.
static int TOP
          Constant used to specify the top side of the Grid.
 
Constructor Summary
Grid(ChartView parent)
          Creates a new Grid instance for the specified ChartView
 
Method Summary
 void addXConstraint(float pos, int value, float weight, float z)
          Adds an AxisConstraint to the X axis.
 void addYConstraint(float pos, int value, float weight, float z)
          Adds an AxisConstraint to the Y axis.
 Axis getAxisX()
          Gets the X Axis
 int getAxisXPosition()
          Gets the position of Axis X.
 float getAxisXZ()
          Gets the depth of the X axis.
 Axis getAxisY()
          Gets the Y Axis
 int getAxisYPosition()
          Gets the position of Axis Y.
 float getAxisYZ()
          Gets the depth of the Y axis.
 java.awt.Rectangle getGridRect()
          Gets the front rectangle of this Grid
 int getLabelGap()
          Gets the distance from the Axis line to its labels.
 java.awt.Point getLabelStep()
          Gets the increment at which the labels are shown along the axes.
 float getValueFromX(int x)
          Converts component to logical coordinates for Axis X The conversion is performed for Z = 0.
 float getValueFromY(int y)
          Converts component to logical coordinates for Axis Y The conversion is performed for Z = 0.
 int getX(float x)
          Converts logical to component coordinates for Axis X.
 int getY(float y)
          Converts logical to component coordinates for Axis Y The conversion is performed for Z = 0.
 java.awt.Point getZVector()
          Gets the Z vector of this grid.
 boolean isDrawHorzLines()
          Checks whether the horizontal coordinate lines are drawn.
 boolean isDrawVertLines()
          Checks whether the vertical coordinate lines are drawn.
 void paint(java.awt.Graphics g)
          Draws this Grid in the specified Graphics context.
 void resizeToFit(java.awt.FontMetrics fm)
          Resizes this Grid to fit the whole area of its parent ChartView.
 void setAxisXPosition(int pos)
          Sets the position of Axis X.
 void setAxisYPosition(int pos)
          Sets the position of Axis Y.
 void setDrawHorzLines(boolean draw)
          Determines whether the horizontal coordinate lines should be drawn.
 void setDrawVertLines(boolean draw)
          Determines whether the vertical coordinate lines should be drawn.
 void setGridRect(java.awt.Rectangle gridRect)
          Sets the front rectangle of this Grid
 void setLabelGap(int gap)
          Sets the distance from the Axis line to its labels.
 void setLabelStep(java.awt.Point labelStep)
          Sets the increment at which the labels are shown along the axes.
 void setZVector(java.awt.Point zVector)
          Sets the Z vector of this Grid.
static void translate(java.awt.Polygon p, int dx, int dy)
          Translates the points of the Polygon p by dx along the x axis and by dy along the y axis.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
Constant used to specify the left side of the Grid.

RIGHT

public static final int RIGHT
Constant used to specify the right side of the Grid.

TOP

public static final int TOP
Constant used to specify the top side of the Grid.

BOTTOM

public static final int BOTTOM
Constant used to specify the bottom side of the Grid.
Constructor Detail

Grid

public Grid(ChartView parent)
Creates a new Grid instance for the specified ChartView
Method Detail

setGridRect

public void setGridRect(java.awt.Rectangle gridRect)
Sets the front rectangle of this Grid

getGridRect

public java.awt.Rectangle getGridRect()
Gets the front rectangle of this Grid

setZVector

public void setZVector(java.awt.Point zVector)
Sets the Z vector of this Grid. The Z vector determines the depth of the Grid to create a 3D effect.

getZVector

public java.awt.Point getZVector()
Gets the Z vector of this grid.

setLabelStep

public void setLabelStep(java.awt.Point labelStep)
Sets the increment at which the labels are shown along the axes. The labelStep.x determines the step along the X axis and labelStep.y determines the step along the Y axis. If the step is set to 1 all labels are shown, if set to 2 every other label is shown and so on. This property is set automatically by resizeToFit() if used.

getLabelStep

public java.awt.Point getLabelStep()
Gets the increment at which the labels are shown along the axes.

getAxisX

public Axis getAxisX()
Gets the X Axis

getAxisY

public Axis getAxisY()
Gets the Y Axis

getX

public int getX(float x)
Converts logical to component coordinates for Axis X. The conversion is performed for Z = 0.

getValueFromX

public float getValueFromX(int x)
Converts component to logical coordinates for Axis X The conversion is performed for Z = 0.

getY

public int getY(float y)
Converts logical to component coordinates for Axis Y The conversion is performed for Z = 0.

getValueFromY

public float getValueFromY(int y)
Converts component to logical coordinates for Axis Y The conversion is performed for Z = 0.

getAxisXZ

public float getAxisXZ()
Gets the depth of the X axis. The result is between 0.0f and 1.0f.

getAxisYZ

public float getAxisYZ()
Gets the depth of the Y axis. The result is between 0.0f and 1.0f.

addXConstraint

public void addXConstraint(float pos,
                           int value,
                           float weight,
                           float z)
Adds an AxisConstraint to the X axis.

addYConstraint

public void addYConstraint(float pos,
                           int value,
                           float weight,
                           float z)
Adds an AxisConstraint to the Y axis.

resizeToFit

public void resizeToFit(java.awt.FontMetrics fm)
Resizes this Grid to fit the whole area of its parent ChartView.

paint

public void paint(java.awt.Graphics g)
Draws this Grid in the specified Graphics context.

setAxisXPosition

public void setAxisXPosition(int pos)
Sets the position of Axis X.
Parameters:
pos - The position of the Axis X (TOP or BOTTOM)

getAxisXPosition

public int getAxisXPosition()
Gets the position of Axis X.

setAxisYPosition

public void setAxisYPosition(int pos)
Sets the position of Axis Y.
Parameters:
pos - The position of the Axis Y (LEFT or RIGHT)

getAxisYPosition

public int getAxisYPosition()
Gets the position of Axis Y.

setDrawHorzLines

public void setDrawHorzLines(boolean draw)
Determines whether the horizontal coordinate lines should be drawn.

isDrawHorzLines

public boolean isDrawHorzLines()
Checks whether the horizontal coordinate lines are drawn.

setDrawVertLines

public void setDrawVertLines(boolean draw)
Determines whether the vertical coordinate lines should be drawn.

isDrawVertLines

public boolean isDrawVertLines()
Checks whether the vertical coordinate lines are drawn.

setLabelGap

public void setLabelGap(int gap)
Sets the distance from the Axis line to its labels.

getLabelGap

public int getLabelGap()
Gets the distance from the Axis line to its labels.

translate

public static void translate(java.awt.Polygon p,
                             int dx,
                             int dy)
Translates the points of the Polygon p by dx along the x axis and by dy along the y axis.