All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class graph.Graph2D

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----graph.Graph2D

public class Graph2D
extends Canvas
This is the main plotting class. It partitions the canvas to contain the specified axes with the remaining space taken with the plotting region. Axes are packed against the walls of the canvas. The paint and update methods of this class handle all the drawing operations of the graph. This means that independent components like Axis and DataSets must be registered with this class to be incorporated into the plot.

Version:
LB1.12 MCC 3/19/97
Author:
Leigh Brookshaw modified by Michael Cross

Variable Index

 o axis
A vector list of All the axes attached
 o borderBottom
The width of the border at the bottom of the canvas.
 o borderLeft
The width of the border at the left of the canvas.
 o borderRight
The width of the border at the right of the canvas.
 o borderTop
The width of the border at the top of the canvas.
 o clearAll
If set true (the default) the canvas will be set to the background color (erasing the plot) when the update method is called.
 o DataBackground
The background color for the data window
 o datarect
The rectangle that the data will be plotted within.
 o dataset
A vector list of All the DataSets attached
 o drawgrid
If set true (the default) a grid will be drawn over the data window.
 o drawzero
If set true (the default) a grid line will be drawn across the data window at the zeros of the innermost axes.
 o frame
If set true a frame will be drawn around the data window.
 o framecolor
The color of the frame to be drawn
 o gridcolor
The color of the grid to be drawn
 o lastText
Text to be painted Last onto the Graph Canvas.
 o lg
Protected Variables added by MCC
 o load_thread
The blinking "data loading" thread
 o loadingData
If this is greater than zero it means that data loading threads are active so the message "loading data" is flashed on the plot canvas.
 o markers
The markers that may have been loaded
 o newRectangle
 o offScreenGraphics
 o offScreenImage
 o paintAll
If set true (the default) everything associated with the plot will be drawn when the update method or paint method are called.
 o r_g
 o r_save
 o square
Modify the position of the axis and the range of the axis so that the aspect ratio of the major tick marks are 1 and the plot is square on the screen
 o zerocolor
The color of the zero grid lines.

Constructor Index

 o Graph2D()

Method Index

 o attachAxis(Axis)
Attach a previously created Axis.
 o attachDataSet(DataSet)
Attach a DataSet to the graph.
 o axesChanged()
Check to see if any of axes range has changed.
 o createAxis(int)
Create and attach an Axis to the graph.
 o detachAxes()
Detach All attached Axes.
 o detachAxis(Axis)
Detach a previously attached Axis.
 o detachDataSet(DataSet)
Detach the DataSet from the class.
 o detachDataSets()
Detach All the DataSets from the class.
 o drawAxis(Graphics, Rectangle)
Draw the Axis.
 o drawFrame(Graphics, int, int, int, int)
 o finishedloading()
Decrement the loading Data counter by one.
 o ForceSquare(Graphics, Rectangle)
Force the plot to have an aspect ratio of 1 by forcing the axes to have the same range.
 o getDataRectangle(Graphics, Rectangle)
Calculate the rectangle occupied by the data
 o getMarkers()
Get the markers
 o getXmax()
Get the Maximum X value of all attached DataSets.
 o getXmin()
Get the Minimum X value of all attached DataSets.
 o getYmax()
Get the Maximum Y value of all attached DataSets.
 o getYmin()
Get the Minimum Y value of all attached DataSets.
 o keyDown(Event, int)
Handle keyDown events.
 o loadDataSet(double[], int)
Load and Attach a DataSet from an array.
 o loadFile(URL)
Load and Attach a DataSet from a File.
 o loadmessage(String)
Change the message to be flashed on the canvas
 o paint(Graphics)
This paints the entire plot.
 o paintBeforeData(Graphics, Rectangle)
A hook into the Graph2D.paint method.
 o paintFirst(Graphics, Rectangle)
A hook into the Graph2D.paint method.
 o paintLast(Graphics, Rectangle)
A hook into the Graph2D.paint method.
 o resetAxes()
Call to indicate axes have been changed.
 o setDataBackground(Color)
Set the background color for the data window.
 o setGraphBackground(Color)
Set the background color for the entire canvas.
 o setMarkers(Markers)
Set the markers for the plot.
 o startedloading()
Calling this method pauses the plot and displays a flashing message on the screen.
 o update(Graphics)
This method is called through the repaint() method.

Variables

 o axis
 protected Vector axis
A vector list of All the axes attached

See Also:
attachAxis
 o dataset
 protected Vector dataset
A vector list of All the DataSets attached

See Also:
attachDataSet, DataSet
 o markers
 protected Markers markers
The markers that may have been loaded

See Also:
setMarkers
 o load_thread
 protected LoadMessage load_thread
The blinking "data loading" thread

See Also:
startedloading
 o DataBackground
 protected Color DataBackground
The background color for the data window

 o lg
 protected Graphics lg
Protected Variables added by MCC

 o offScreenImage
 protected Image offScreenImage
 o offScreenGraphics
 protected Graphics offScreenGraphics
 o r_save
 protected Rectangle r_save
 o r_g
 protected Rectangle r_g
 o newRectangle
 protected boolean newRectangle
 o loadingData
 public int loadingData
If this is greater than zero it means that data loading threads are active so the message "loading data" is flashed on the plot canvas. When it is back to zero the plot progresses normally

 o borderTop
 public int borderTop
The width of the border at the top of the canvas. This allows slopover from axis labels, legends etc.

 o borderBottom
 public int borderBottom
The width of the border at the bottom of the canvas. This allows slopover from axis labels, legends etc.

 o borderLeft
 public int borderLeft
The width of the border at the left of the canvas. This allows slopover from axis labels, legends etc.

 o borderRight
 public int borderRight
The width of the border at the right of the canvas. This allows slopover from axis labels, legends etc.

 o frame
 public boolean frame
If set true a frame will be drawn around the data window. Any axes will overlay this frame.

 o framecolor
 public Color framecolor
The color of the frame to be drawn

 o drawgrid
 public boolean drawgrid
If set true (the default) a grid will be drawn over the data window. The grid will align with the major tic marks of the Innermost axes.

 o gridcolor
 public Color gridcolor
The color of the grid to be drawn

 o drawzero
 public boolean drawzero
If set true (the default) a grid line will be drawn across the data window at the zeros of the innermost axes.

 o zerocolor
 public Color zerocolor
The color of the zero grid lines.

 o datarect
 public Rectangle datarect
The rectangle that the data will be plotted within. This is an output variable only.

 o clearAll
 public boolean clearAll
If set true (the default) the canvas will be set to the background color (erasing the plot) when the update method is called. This would only be changed for special effects.

 o paintAll
 public boolean paintAll
If set true (the default) everything associated with the plot will be drawn when the update method or paint method are called. Normally only modified for special effects

 o square
 public boolean square
Modify the position of the axis and the range of the axis so that the aspect ratio of the major tick marks are 1 and the plot is square on the screen

 o lastText
 public TextLine lastText
Text to be painted Last onto the Graph Canvas.

Constructors

 o Graph2D
 public Graph2D()

Methods

 o loadFile
 public DataSet loadFile(URL file)
Load and Attach a DataSet from a File. The method loads the data into a DataSet class and attaches the class to the graph for plotting. The data is assumed to consist (at this stage) 2 ASCII columns of numbers x, y. As always blank lines are ignored and everything following # is ignored as a comment.

Parameters:
file - The URL of the data file to read.
Returns:
The DataSet constructed containing the data read.
 o loadDataSet
 public DataSet loadDataSet(double data[],
                            int n)
Load and Attach a DataSet from an array. The method loads the data into a DataSet class and attaches the class to the graph for plotting. The data is assumed to be stored in the form x,y,x,y,x,y.... A local copy of the data is made.

Parameters:
data - The data to be loaded in the form x,y,x,y,...
n - The number of (x,y) data points. This means that the minimum length of the data array is 2*n.
Returns:
The DataSet constructed containing the data read.
 o attachDataSet
 public void attachDataSet(DataSet d)
Attach a DataSet to the graph. By attaching the data set the class can draw the data through its paint method.

 o detachDataSet
 public void detachDataSet(DataSet d)
Detach the DataSet from the class. Data associated with the DataSet will nolonger be plotted.

Parameters:
d - The DataSet to detach.
 o detachDataSets
 public void detachDataSets()
Detach All the DataSets from the class.

 o createAxis
 public Axis createAxis(int position)
Create and attach an Axis to the graph. The position of the axis is one of Axis.TOP, Axis.BOTTOM, Axis.LEFT or Axis.RIGHT.

Parameters:
position - Position of the axis in the drawing window.
 o attachAxis
 public void attachAxis(Axis a)
Attach a previously created Axis. Only Axes that have been attached will be drawn

Parameters:
the - Axis to attach.
 o detachAxis
 public void detachAxis(Axis a)
Detach a previously attached Axis.

Parameters:
the - Axis to dettach.
 o detachAxes
 public void detachAxes()
Detach All attached Axes.

 o getXmax
 public double getXmax()
Get the Maximum X value of all attached DataSets.

Returns:
The maximum value
 o getYmax
 public double getYmax()
Get the Maximum Y value of all attached DataSets.

Returns:
The maximum value
 o getXmin
 public double getXmin()
Get the Minimum X value of all attached DataSets.

Returns:
The minimum value
 o getYmin
 public double getYmin()
Get the Minimum Y value of all attached DataSets.

Returns:
The minimum value
 o setMarkers
 public void setMarkers(Markers m)
Set the markers for the plot.

Parameters:
m - Marker class containing the defined markers
See Also:
Markers
 o getMarkers
 public Markers getMarkers()
Get the markers

Returns:
defined Marker class
See Also:
Markers
 o setGraphBackground
 public void setGraphBackground(Color c)
Set the background color for the entire canvas.

Parameters:
s - c The color to set the canvas
 o setDataBackground
 public void setDataBackground(Color c)
Set the background color for the data window.

Parameters:
s - c The color to set the data window.
 o paint
 public void paint(Graphics g)
This paints the entire plot. It calls the draw methods of all the attached axis and data sets. The order of drawing is - Axis first, data legends next, data last. MCC : method changed to use double buffering for smoothe updates.

Parameters:
s - g Graphics state.
Overrides:
paint in class Canvas
 o paintFirst
 public void paintFirst(Graphics g,
                        Rectangle r)
A hook into the Graph2D.paint method. This is called before anything is plotted. The rectangle passed is the dimension of the canvas minus the border dimensions.

Parameters:
s - g Graphics state
s - r Rectangle containing the graph
 o paintBeforeData
 public void paintBeforeData(Graphics g,
                             Rectangle r)
A hook into the Graph2D.paint method. This is called before the data is drawn but after the axis. The rectangle passed is the dimension of the data window.

Parameters:
s - g Graphics state
s - r Rectangle containing the data
 o paintLast
 public void paintLast(Graphics g,
                       Rectangle r)
A hook into the Graph2D.paint method. This is called after everything has been drawn. The rectangle passed is the dimension of the data window.

Parameters:
s - g Graphics state
s - r Rectangle containing the data
 o update
 public void update(Graphics g)
This method is called through the repaint() method. For double buffered graphics we just call paint.

Overrides:
update in class Component
 o keyDown
 public boolean keyDown(Event e,
                        int key)
Handle keyDown events. Only one event is handled the pressing of the key 'r' - this will repaint the canvas.

Overrides:
keyDown in class Component
 o startedloading
 public void startedloading()
Calling this method pauses the plot and displays a flashing message on the screen. Mainly used when data is being loaded across the net. Everytime this routine is called a counter is incremented the method Graph2D.finishedloading() decrements the counter. When the counter is back to zero the plotting resumes.

See Also:
finishedloading, loadmessage, LoadMessage
 o finishedloading
 public void finishedloading()
Decrement the loading Data counter by one. When it is zero resume plotting.

See Also:
startedloading, loadmessage, LoadMessage
 o loadmessage
 public void loadmessage(String s)
Change the message to be flashed on the canvas

Parameters:
s - String contining the new message.
See Also:
startedloading, finishedloading, LoadMessage
 o axesChanged
 protected boolean axesChanged()
Check to see if any of axes range has changed. (MCC 3/19/97)

 o resetAxes
 protected void resetAxes()
Call to indicate axes have been changed. (MCC 3/19/97)

 o ForceSquare
 protected Rectangle ForceSquare(Graphics g,
                                 Rectangle r)
Force the plot to have an aspect ratio of 1 by forcing the axes to have the same range. If the range of the axes are very different some extremely odd things can occur. All axes are forced to have the same range, so more than 2 axis is pointless.

 o getDataRectangle
 protected Rectangle getDataRectangle(Graphics g,
                                      Rectangle r)
Calculate the rectangle occupied by the data

 o drawAxis
 protected Rectangle drawAxis(Graphics g,
                              Rectangle r)
Draw the Axis. As each axis is drawn and aligned less of the canvas is avaliable to plot the data. The returned Rectangle is the canvas area that the data is plotted in.

 o drawFrame
 protected void drawFrame(Graphics g,
                          int x,
                          int y,
                          int width,
                          int height)

All Packages  Class Hierarchy  This Package  Previous  Next  Index