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
-
axis
- A vector list of All the axes attached
-
borderBottom
- The width of the border at the bottom of the canvas.
-
borderLeft
- The width of the border at the left of the canvas.
-
borderRight
- The width of the border at the right of the canvas.
-
borderTop
- The width of the border at the top of the canvas.
-
clearAll
- If set true (the default) the canvas will be set to the background
color (erasing the plot) when the update method is called.
-
DataBackground
- The background color for the data window
-
datarect
- The rectangle that the data will be plotted within.
-
dataset
- A vector list of All the DataSets attached
-
drawgrid
- If set true (the default) a grid will be drawn over the data window.
-
drawzero
- If set true (the default) a grid line will be drawn
across the data window
at the zeros of the innermost axes.
-
frame
- If set true a frame will be drawn around the data window.
-
framecolor
- The color of the frame to be drawn
-
gridcolor
- The color of the grid to be drawn
-
lastText
- Text to be painted Last onto the Graph Canvas.
-
lg
-
Protected Variables added by MCC
-
load_thread
- The blinking "data loading" thread
-
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.
-
markers
- The markers that may have been loaded
-
newRectangle
-
-
offScreenGraphics
-
-
offScreenImage
-
-
paintAll
- If set true (the default) everything associated with the plot
will be drawn when the update method or paint method are called.
-
r_g
-
-
r_save
-
-
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
-
zerocolor
- The color of the zero grid lines.
-
Graph2D()
-
-
attachAxis(Axis)
- Attach a previously created Axis.
-
attachDataSet(DataSet)
- Attach a DataSet to the graph.
-
axesChanged()
- Check to see if any of axes range has changed.
-
createAxis(int)
- Create and attach an Axis to the graph.
-
detachAxes()
- Detach All attached Axes.
-
detachAxis(Axis)
- Detach a previously attached Axis.
-
detachDataSet(DataSet)
- Detach the DataSet from the class.
-
detachDataSets()
- Detach All the DataSets from the class.
-
drawAxis(Graphics, Rectangle)
-
Draw the Axis.
-
drawFrame(Graphics, int, int, int, int)
-
-
finishedloading()
- Decrement the loading Data counter by one.
-
ForceSquare(Graphics, Rectangle)
- Force the plot to have an aspect ratio of 1 by forcing the
axes to have the same range.
-
getDataRectangle(Graphics, Rectangle)
- Calculate the rectangle occupied by the data
-
getMarkers()
- Get the markers
-
getXmax()
- Get the Maximum X value of all attached DataSets.
-
getXmin()
- Get the Minimum X value of all attached DataSets.
-
getYmax()
- Get the Maximum Y value of all attached DataSets.
-
getYmin()
- Get the Minimum Y value of all attached DataSets.
-
keyDown(Event, int)
- Handle keyDown events.
-
loadDataSet(double[], int)
- Load and Attach a DataSet from an array.
-
loadFile(URL)
- Load and Attach a DataSet from a File.
-
loadmessage(String)
- Change the message to be flashed on the canvas
-
paint(Graphics)
- This paints the entire plot.
-
paintBeforeData(Graphics, Rectangle)
- A hook into the Graph2D.paint method.
-
paintFirst(Graphics, Rectangle)
- A hook into the Graph2D.paint method.
-
paintLast(Graphics, Rectangle)
- A hook into the Graph2D.paint method.
-
resetAxes()
- Call to indicate axes have been changed.
-
setDataBackground(Color)
- Set the background color for the data window.
-
setGraphBackground(Color)
- Set the background color for the entire canvas.
-
setMarkers(Markers)
- Set the markers for the plot.
-
startedloading()
- Calling this method pauses the plot and displays a flashing
message on the screen.
-
update(Graphics)
- This method is called through the repaint() method.
axis
protected Vector axis
- A vector list of All the axes attached
- See Also:
- attachAxis
dataset
protected Vector dataset
- A vector list of All the DataSets attached
- See Also:
- attachDataSet, DataSet
markers
protected Markers markers
- The markers that may have been loaded
- See Also:
- setMarkers
load_thread
protected LoadMessage load_thread
- The blinking "data loading" thread
- See Also:
- startedloading
DataBackground
protected Color DataBackground
- The background color for the data window
lg
protected Graphics lg
- Protected Variables added by MCC
offScreenImage
protected Image offScreenImage
offScreenGraphics
protected Graphics offScreenGraphics
r_save
protected Rectangle r_save
r_g
protected Rectangle r_g
newRectangle
protected boolean newRectangle
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
borderTop
public int borderTop
- The width of the border at the top of the canvas. This allows
slopover from axis labels, legends etc.
borderBottom
public int borderBottom
- The width of the border at the bottom of the canvas. This allows
slopover from axis labels, legends etc.
borderLeft
public int borderLeft
- The width of the border at the left of the canvas. This allows
slopover from axis labels, legends etc.
borderRight
public int borderRight
- The width of the border at the right of the canvas. This allows
slopover from axis labels, legends etc.
frame
public boolean frame
- If set true a frame will be drawn around the data window.
Any axes will overlay this frame.
framecolor
public Color framecolor
- The color of the frame to be drawn
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.
gridcolor
public Color gridcolor
- The color of the grid to be drawn
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.
zerocolor
public Color zerocolor
- The color of the zero grid lines.
datarect
public Rectangle datarect
- The rectangle that the data will be plotted within. This is an output
variable only.
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.
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
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
lastText
public TextLine lastText
- Text to be painted Last onto the Graph Canvas.
Graph2D
public Graph2D()
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.
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.
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.
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.
detachDataSets
public void detachDataSets()
- Detach All the DataSets from the class.
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.
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.
detachAxis
public void detachAxis(Axis a)
- Detach a previously attached Axis.
- Parameters:
- the - Axis to dettach.
detachAxes
public void detachAxes()
- Detach All attached Axes.
getXmax
public double getXmax()
- Get the Maximum X value of all attached DataSets.
- Returns:
- The maximum value
getYmax
public double getYmax()
- Get the Maximum Y value of all attached DataSets.
- Returns:
- The maximum value
getXmin
public double getXmin()
- Get the Minimum X value of all attached DataSets.
- Returns:
- The minimum value
getYmin
public double getYmin()
- Get the Minimum Y value of all attached DataSets.
- Returns:
- The minimum value
setMarkers
public void setMarkers(Markers m)
- Set the markers for the plot.
- Parameters:
- m - Marker class containing the defined markers
- See Also:
- Markers
getMarkers
public Markers getMarkers()
- Get the markers
- Returns:
- defined Marker class
- See Also:
- Markers
setGraphBackground
public void setGraphBackground(Color c)
- Set the background color for the entire canvas.
- Parameters:
- s - c The color to set the canvas
setDataBackground
public void setDataBackground(Color c)
- Set the background color for the data window.
- Parameters:
- s - c The color to set the data window.
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
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
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
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
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
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
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
finishedloading
public void finishedloading()
- Decrement the loading Data counter by one. When it is zero resume
plotting.
- See Also:
- startedloading, loadmessage, LoadMessage
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
axesChanged
protected boolean axesChanged()
- Check to see if any of axes range has changed. (MCC 3/19/97)
resetAxes
protected void resetAxes()
- Call to indicate axes have been changed. (MCC 3/19/97)
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.
getDataRectangle
protected Rectangle getDataRectangle(Graphics g,
Rectangle r)
- Calculate the rectangle occupied by the data
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.
drawFrame
protected void drawFrame(Graphics g,
int x,
int y,
int width,
int height)
All Packages Class Hierarchy This Package Previous Next Index