org.PingOO.DLAI.lib.graph
Class Axis

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.graph.Axis

public class Axis
extends java.lang.Object

This class controls the look and feel of axes.
It is designed to be used in conjunction with the Graph2D class and DataSet class for plotting 2D graphs.

To work with the other classes a system of registration is used.
The axes have to be attached to the controlling Graph2D class and the DataSet's have to be attached to both the Graph2D class and the Axis class.

This way the 3 main classes Graph2D, Axis and DataSet know of each others existence.

This does not mean the classes cannot be used independently, they can but in this mode nothing is automated, the user must code everything manually.

Version:
1.12 1996/09/12 03:27:07
Author:
Leigh Brookshaw (http://www.sci.usq.edu.au/staff/leighb/graph/) (leighb@usq.edu.au)

Field Summary
protected  java.awt.Point amax
          The position in pixels of the maximum point of the axis line
protected  java.awt.Point amin
          The position in pixels of the minimum point of the axis line
 java.awt.Color axiscolor
          Color of the Axis.
static int BOTTOM
          Constant flagging Axis position on the graph.
 java.awt.Dimension data_window
          Before the Axis can be positioned correctly and drawn the data window needs to be calculated and passed to the Axis.
protected  java.util.Vector dataset
          Vector containing a list of attached DataSets.
 boolean drawgrid
          If true draw a grid positioned on major ticks over the graph.
 boolean drawzero
          If true draw a line positioned on the Zero label tick mark.
protected  RTextLine exponent
          Textline class to hold the label's exponent (if it has one).
 boolean force_end_labels
          Rescale the axis so that labels fall at the end of the Axis.
 Graph2D g2d
          The graph canvas this axis is attached to (if it is attached to any)
 java.awt.Color gridcolor
          Color of the grid.
protected  int guess_label_number
          Initial guess for the number of labels required
static int HORIZONTAL
          Constant flagging Horizontal Axis
protected  RTextLine label
          Textline class to hold the labels before printing.
protected  int label_count
          The number of labels required
protected  int label_exponent
          The label exponent
protected  double label_start
          The starting value of the labels
protected  double label_step
          The increment between labels
protected  java.lang.String[] label_string
          String to contain the labels.
protected  float[] label_value
          The actual values of the axis labels.
static int LEFT
          Constant flagging Axis position on the graph.
 int major_tic_size
          Size in pixels of the major tick marks
protected  boolean manualRange
          If true the axis range must be manually set by setting the Axis.minimum and Axis.maximum variables.
protected  int max_label_width
          The width of the maximum label.
 double maximum
          Maximum data value of the axis.
 double minimum
          Minimum data value of the axis.
 int minor_tic_count
          Number of minor tick marks between major tick marks
 int minor_tic_size
          Size in pixels of the minor tick marks
static int NUMBER_OF_TICS
          The first guess on the number of Labeled Major tick marks.
protected  int orientation
          The orientation of the axis.
protected  int position
          The position of the axis.
 boolean redraw
          Default value true.
static int RIGHT
          Constant flagging Axis position on the graph.
protected  RTextLine title
          Textline class to contain the title of the axis.
static int TOP
          Constant flagging Axis position on the graph.
static int VERTICAL
          Constant flagging Vertical Axis
protected  int width
          The width of the Axis.
 java.awt.Color zerocolor
          Color of the line at the Zero label.
 
Constructor Summary
Axis()
          Instantiate the class.
Axis(int p)
          Instantiates the class.
 
Method Summary
 void attachDataSet(DataSet d)
          Attaches a DataSet for the Axis to manage.
protected  void attachXdata(DataSet d)
          Attaches a DataSet to a Horizontal Axis
protected  void attachYdata(DataSet d)
          Attaches a DataSet to a Vertical Axis
protected  void calculateGridLabels()
          Calculate the labels
 void detachAll()
          Detaches all attached dataSets.
 void detachDataSet(DataSet d)
          Detaches an attached DataSet.
 void drawAxis(java.awt.Graphics g)
          Draws the axis using the passed Graphics context.
protected  void drawHAxis(java.awt.Graphics g)
          Drawq a Horizontal Axis.
protected  void drawVAxis(java.awt.Graphics g)
          Draws a Vertical Axis.
 int getAxisPos()
          Returns the position of the Axis.
 int getAxisWidth(java.awt.Graphics g)
          Return the width of the axis.
 double getDataMax()
          Returns the maximum value of All datasets attached to the axis.
 double getDataMin()
          Returns the minimum value of All datasets attached to the axis.
 double getDouble(int i)
          Returns the data value equivalent of the passed pixel position.
 int getInteger(double v)
          Returns the pixel equivalent of the passed data value.
 boolean isVertical()
          If the Axis is Vertical return true.
 boolean positionAxis(int xmin, int xmax, int ymin, int ymax)
          Positions the axis at the passed coordinates.
 void resetRange()
          Resets the range of the axis (the minimum and maximum values) to the default data values.
private  double RoundUp(double val)
          Rounds up the passed value to a NICE value.
 void setExponentColor(java.awt.Color c)
          Sets the color of the exponent
 void setExponentFont(java.awt.Font f)
          Sets the font of the exponent
 void setLabelColor(java.awt.Color c)
          Sets the color of the labels
 void setLabelFont(java.awt.Font f)
          Sets the font of the labels.
 void setManualRange(boolean b)
          Is the range of the axis to be set automatically (based on the data) or manually by setting the values Axis.minimum and Axis.maximum?
 void setPosition(int p)
          Sets the axis position.
 void setTitleColor(java.awt.Color c)
          Sets the color of the title
 void setTitleFont(java.awt.Font f)
          Sets the font of the title
 void setTitleRotation(int a)
          Sets the title rotation angle.
 void setTitleText(java.lang.String s)
          Sets the title of the axis
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

HORIZONTAL

public static final int HORIZONTAL
Constant flagging Horizontal Axis

VERTICAL

public static final int VERTICAL
Constant flagging Vertical Axis

LEFT

public static final int LEFT
Constant flagging Axis position on the graph.
Left side => Vertical

RIGHT

public static final int RIGHT
Constant flagging Axis position on the graph.
Right side => Vertical

TOP

public static final int TOP
Constant flagging Axis position on the graph.
Top side => Horizontal

BOTTOM

public static final int BOTTOM
Constant flagging Axis position on the graph.
Bottom side => Horizontal

NUMBER_OF_TICS

public static final int NUMBER_OF_TICS
The first guess on the number of Labeled Major tick marks.

drawgrid

public boolean drawgrid
If true draw a grid positioned on major ticks over the graph.

drawzero

public boolean drawzero
If true draw a line positioned on the Zero label tick mark.

gridcolor

public java.awt.Color gridcolor
Color of the grid.

zerocolor

public java.awt.Color zerocolor
Color of the line at the Zero label.

redraw

public boolean redraw
Default value true. Normally never changed.
If set false the Axis draw method exits without drawing the axis.
See Also:
org.PingOO.DLAI.lib.grap.Axis#drawAxis

force_end_labels

public boolean force_end_labels
Rescale the axis so that labels fall at the end of the Axis. false.

major_tic_size

public int major_tic_size
Size in pixels of the major tick marks

minor_tic_size

public int minor_tic_size
Size in pixels of the minor tick marks

minor_tic_count

public int minor_tic_count
Number of minor tick marks between major tick marks

axiscolor

public java.awt.Color axiscolor
Color of the Axis.

minimum

public double minimum
Minimum data value of the axis.
This is the value used to scale data into the data window.
This is the value to alter to force a rescaling of the data window.

maximum

public double maximum
Maximum data value of the axis.
This is the value used to scale data into the data window.
This is the value to alter to force a rescaling of the data window.

data_window

public java.awt.Dimension data_window
Before the Axis can be positioned correctly and drawn the data window needs to be calculated and passed to the Axis.

g2d

public Graph2D g2d
The graph canvas this axis is attached to (if it is attached to any)
See Also:
Graph2D

amin

protected java.awt.Point amin
The position in pixels of the minimum point of the axis line

amax

protected java.awt.Point amax
The position in pixels of the maximum point of the axis line

orientation

protected int orientation
The orientation of the axis.
Either Axis.HORIZONTAL or Axis.VERTICAL.

position

protected int position
The position of the axis.
Either Axis.LEFT, Axis.RIGHT, Axis.TOP, or Axis.BOTTOM.

width

protected int width
The width of the Axis.
Where width for a horizontal axis is really the height.

title

protected RTextLine title
Textline class to contain the title of the axis.

label

protected RTextLine label
Textline class to hold the labels before printing.

exponent

protected RTextLine exponent
Textline class to hold the label's exponent (if it has one).

max_label_width

protected int max_label_width
The width of the maximum label.
Used to position a Vertical Axis.

dataset

protected java.util.Vector dataset
Vector containing a list of attached DataSets.

label_string

protected java.lang.String[] label_string
String to contain the labels.

label_value

protected float[] label_value
The actual values of the axis labels.

label_start

protected double label_start
The starting value of the labels

label_step

protected double label_step
The increment between labels

label_exponent

protected int label_exponent
The label exponent

label_count

protected int label_count
The number of labels required

guess_label_number

protected int guess_label_number
Initial guess for the number of labels required

manualRange

protected boolean manualRange
If true the axis range must be manually set by setting the Axis.minimum and Axis.maximum variables.
The default is false. The default action is for the axis range to be calculated everytime a dataset is attached.
Constructor Detail

Axis

public Axis()
Instantiate the class.
The defalt type is a Horizontal axis positioned at the bottom of the graph.

Axis

public Axis(int p)
Instantiates the class.
Setting the position.
Parameters:
p - Set the axis position. Must be one of Axis.BOTTOM, Axis.TOP, Axis.LEFT, Axis.RIGHT, Axis.HORIZONTAL or Axis.VERTICAL. If one of the latter two are used then Axis.BOTTOM or Axis.LEFT is assumed.
Method Detail

setPosition

public void setPosition(int p)
Sets the axis position.
Parameters:
p - Must be one of Axis.BOTTOM, Axis.TOP, Axis.LEFT, Axis.RIGHT, Axis.HORIZONTAL or Axis.VERTICAL. If one of the latter two are used then Axis.BOTTOM or Axis.LEFT is assumed.

attachDataSet

public void attachDataSet(DataSet d)
Attaches a DataSet for the Axis to manage.
Parameters:
d - dataSet to attach
See Also:
DataSet

detachDataSet

public void detachDataSet(DataSet d)
Detaches an attached DataSet.
Parameters:
d - The DataSet to detach.
See Also:
DataSet

detachAll

public void detachAll()
Detaches all attached dataSets.

getDataMin

public double getDataMin()
Returns the minimum value of All datasets attached to the axis.
Returns:
The minimum value of All datasets attached to the axis.

getDataMax

public double getDataMax()
Returns the maximum value of All datasets attached to the axis.
Returns:
The maximum value of All datasets attached to the axis.

getInteger

public int getInteger(double v)
Returns the pixel equivalent of the passed data value.
Using the position of the axis and the maximum and minimum values convert the data value into a pixel value.
Parameters:
v - The data value to convert.
Returns:
The equivalent pixel value.
See Also:
org.PingOO.DLAI.lib.graph.graph.Axis#getDouble

getDouble

public double getDouble(int i)
Returns the data value equivalent of the passed pixel position.
Using the position of the axis and the maximum and minimum values convert the pixel position into a data value.
Parameters:
i - The pixel value.
Returns:
equivalent data value
See Also:
org.PingOO.DLAI.lib.graph.graph.Axis#getInteger

resetRange

public void resetRange()
Resets the range of the axis (the minimum and maximum values) to the default data values.

getAxisPos

public int getAxisPos()
Returns the position of the Axis.
Returns:
One of Axis.LEFT, Axis.RIGHT, Axis.TOP, or Axis.BOTTOM.

isVertical

public boolean isVertical()
If the Axis is Vertical return true.
Returns:
If the Axis is Vertical return true, false otherwise.

getAxisWidth

public int getAxisWidth(java.awt.Graphics g)
Return the width of the axis.
Parameters:
g - graphics context.

positionAxis

public boolean positionAxis(int xmin,
                            int xmax,
                            int ymin,
                            int ymax)
Positions the axis at the passed coordinates.
The coordinates should match the type of axis.
Parameters:
xmin - The minimum X pixel.
xmax - The maximum X pixel. These should be equal if the axis is vertical.
ymin - The minimum Y pixel
ymax - The maximum Y pixel. These should be equal if the axis is horizontal.
Returns:
true if there are no inconsistencies, false otherwise.

drawAxis

public void drawAxis(java.awt.Graphics g)
Draws the axis using the passed Graphics context.
Parameters:
g - Graphics context for drawing

setTitleText

public void setTitleText(java.lang.String s)
Sets the title of the axis
Parameters:
s - A string containing text.

setTitleColor

public void setTitleColor(java.awt.Color c)
Sets the color of the title
Parameters:
c - The color of the title.

setTitleFont

public void setTitleFont(java.awt.Font f)
Sets the font of the title
Parameters:
c - The title font.

setTitleRotation

public void setTitleRotation(int a)
Sets the title rotation angle.
Only multiples of 90 degrees allowed.
Parameters:
a - The title rotation angle in degrees.

setLabelColor

public void setLabelColor(java.awt.Color c)
Sets the color of the labels
Parameters:
c - The color of the labels.

setLabelFont

public void setLabelFont(java.awt.Font f)
Sets the font of the labels.
Parameters:
f - The font of the labels.

setExponentColor

public void setExponentColor(java.awt.Color c)
Sets the color of the exponent
Parameters:
c - The color of the exponent.

setExponentFont

public void setExponentFont(java.awt.Font f)
Sets the font of the exponent
Parameters:
f - The font of the exponent.

setManualRange

public void setManualRange(boolean b)
Is the range of the axis to be set automatically (based on the data) or manually by setting the values Axis.minimum and Axis.maximum?
Parameters:
b - A boolean value.

drawHAxis

protected void drawHAxis(java.awt.Graphics g)
Drawq a Horizontal Axis.
Parameters:
g - Graphics context.

drawVAxis

protected void drawVAxis(java.awt.Graphics g)
Draws a Vertical Axis.
Parameters:
g - Graphics context.

attachXdata

protected void attachXdata(DataSet d)
Attaches a DataSet to a Horizontal Axis
Parameters:
d - The dataset to attach.

attachYdata

protected void attachYdata(DataSet d)
Attaches a DataSet to a Vertical Axis
Parameters:
d - The dataset to attach.

calculateGridLabels

protected void calculateGridLabels()
Calculate the labels

RoundUp

private double RoundUp(double val)
Rounds up the passed value to a NICE value.
Returns:
The pased values rounded up.