edu.davidson.display
Class SGraph

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--edu.davidson.graph.Graph2D
                    |
                    +--edu.davidson.display.SGraph
All Implemented Interfaces:
javax.accessibility.Accessible, java.lang.Cloneable, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, SDataListener, java.io.Serializable
Direct Known Subclasses:
SContour

public class SGraph
extends edu.davidson.graph.Graph2D
implements java.lang.Cloneable, SDataListener, java.lang.Runnable

A plotting bean based on the graph package by Leigh Brookshaw. SDataListener added 1/1/99

See Also:
Serialized Form

Fields inherited from class edu.davidson.graph.Graph2D
borderBottom, borderLeft, borderRight, borderTop, clearAll, datarect, drawgrid, drawzero, frame, framecolor, gridcolor, lastText, loadingData, paintAll, square, zerocolor
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
SGraph()
           
SGraph(SApplet applet)
           
 
Method Summary
 int addCursor(int diameter, double x, double y)
          Add a dragable cursor
 void addData(int sid, double[] x, double[] y)
          Add data to the graph using arrays.
 void addData(int sid, double[] x, double[] y, int num)
           
 void addData(SDataSource ds, int sid, double[] x, double[] y)
           
 edu.davidson.graph.DataSet addDataSet(double[] points, int np)
          Add a data set to the graph.
 void addDatum(int sid, double x, double y)
          Add a datum to the graph.
 void addDatum(SDataSource ds, int id, double x, double y)
           
 int addFunction(java.lang.String str)
           
 int addFunction(java.lang.String indVar, java.lang.String str)
          Add an analytic function to the graph.
 int addThing(Thing t)
          Add a drawable thing.
 void adjustScale()
          Use this method to make some last minute scale adjustments.
 void clearAllData()
          Clear the data from all series.
 void clearAllThings()
          Remove all dragable objects for the graph.
 void clearSeries(int s)
          Clear the data from a series.
 void clearSeriesData(int sid)
          Delete the data from a series.
 java.lang.Object clone()
           
 edu.davidson.display.SGraph.Series createSeries(int sid)
          Create an empty series so that styles, color, and other properites can be set.
 void deleteAllFunctions()
          Delete all functions.
 void deleteAllNonSeriesData()
          Remove any Data that is not part of a series.
 void deleteAllSeries()
          Delete all series from the graph.
 void deleteFunction(int id)
          Delete a function from the plot.
 void deleteSeries(int id)
          Delete one series from the graph.
 void deleteSeries(int id, boolean willRepaint)
           
 void drawCoords(java.awt.Graphics g, int xPix, int yPix)
           
 void drawCoords(int xPix, int yPix)
           
 java.lang.String getBorders()
          Get the margins.
 edu.davidson.display.SGraph.MathFunction getFunction(int id)
          Get the function object from the id.
 java.lang.String getFunctionString(int id)
          Get the function that is being graphed.
 int getID()
          Get the ID for this object.
 int getIDFromSID(int val)
           
 java.lang.String getLabelX()
           
 java.lang.String getLabelY()
           
 double getMaxX()
          Get the x axis maximum .
 double getMaxY()
          Get the y axis maximum .
 double getMinX()
          Get the x axis minimum .
 double getMinY()
          Get the y axis minimum .
 SApplet getOwner()
           
 Thing getThing(int id)
          Get the ID for a Thing object from the hashcode.
 java.lang.String getTitle()
           
 boolean isAutoRefresh()
           
 boolean isAutoscaleX()
           
 boolean isAutoscaleY()
           
 boolean isDrawGrid()
          Will the graph have a grid?
 boolean isDrawZero()
           
 boolean isEnableMouse()
           
 boolean isSampleData()
          Will the graph show sample data when it is initialized?
 void paintFunctions(java.awt.Graphics g, java.awt.Rectangle r)
          A hook into the Graph2D.paint method.
 void paintLast(java.awt.Graphics g, java.awt.Rectangle r)
          A hook into the Graph2D.paint method.
 void paintOffScreen()
           
 void paintOffScreen(java.awt.Graphics g)
          Paint the graph offscreen into an image and then blast the image onto the screen
 int pixFromX(double x)
          Get the pixel value corresponding to an x value.
 int pixFromY(double y)
           
 int plotRegression(int sid)
           
 void repaint()
           
 void run()
           
 void setAddRepeatedDatum(int sid, boolean add)
          Set the addRepeatedDataum property.
 void setAutoRefresh(boolean auto)
          Set the autoRefresh property.
 void setAutoReplaceData(int sid, boolean auto)
           
 void setAutoscaleX(boolean as)
          Set the autoscaleX property.
 void setAutoscaleY(boolean as)
          Set the autoscaleY property.
 void setBorders(java.lang.String s)
          Set the margins.
 void setDrawGrid(boolean dg)
          Set the draw grid property.
 void setDrawZero(boolean dz)
          Have the graph draw x=0 and y=0 lines.
 void setEnableMouse(boolean em)
          Enable the graph to respond to mouse actionions.
 void setFormat(java.lang.String str)
          Change the display format for mouse actions.
 void setFunctionRange(int id, double xmin, double xmax, int n)
           
 boolean setFunctionString(int id, java.lang.String str)
          Change the function that is being graphed without adding a new function.
 boolean setFunctionVariable(int id, java.lang.String str)
          Change the function's independent variable.
 void setGutters(int g1, int g2, int g3, int g4)
          Set the gutters.
 void setLabelX(java.lang.String s)
          Set the x axis label.
 void setLabelX(java.lang.String s, java.awt.Color c)
           
 void setLabelY(java.lang.String s)
          Set the y axis label.
 void setLabelY(java.lang.String s, java.awt.Color c)
           
 void setLastPointMarker(int sid, boolean lpm)
           
 void setMarkerSize(double scale)
          Set the default marker size.
 void setMarkerSize(int sid, double scale)
          Set the marker size.
 void setMinMaxX(double min, double max)
          Set the x axis minimum and maximum values.
 void setMinMaxY(double min, double max)
          Set the y axis minimum and maximum values.
 void setObjectColor(int id, java.awt.Color c)
          set the color of the object from the id.
 void setOwner(SApplet owner)
           
 void setParentSApplet(SApplet p)
           
 void setSampleData(boolean sd)
          Create sample data when it is initialized.
 void setSeriesColor(int sid, java.awt.Color c)
           
 void setSeriesLegend(int sid, java.awt.Color c, int xpix, int ypix, java.lang.String legend)
          Set the series legend.
 void setSeriesLegend(int sid, int xpix, int ypix, java.lang.String legend)
           
 void setSeriesLegendColor(int sid, java.awt.Color c)
           
 void setSeriesStyle(int sid, boolean conPts, int m)
           
 void setSeriesStyle(int sid, java.awt.Color c, boolean conPts, int m)
          Set the series style.
 void setShowAxes(boolean sa)
          Show or hide the the X and Y axes on the graph.
 void setSquare(boolean isSquare)
          Set the aspect ratio=1 so that both axes have the same pixels per unit.
 void setTitle(java.lang.String str)
           
 void sGraph_mouseEntered(java.awt.event.MouseEvent e)
           
 void sGraph_mouseExited(java.awt.event.MouseEvent e)
           
 void sGraph_mouseMoved(java.awt.event.MouseEvent e)
           
 double xFromPix(int x)
          Get the value on the x axis from the pixel value.
 double yFromPix(int y)
           
 
Methods inherited from class edu.davidson.graph.Graph2D
attachAxis, attachDataSet, createAxis, detachAxes, detachAxis, detachDataSet, detachDataSets, finishedloading, getDataBackground, getMarkers, getXmax, getXmin, getYmax, getYmin, isShowAxis, loadDataSet, loadFile, loadmessage, paint, paint, paintBeforeData, paintFirst, setDataBackground, setGraphBackground, setMarkers, setShowAxis, startedloading, update
 
Methods inherited from class java.awt.Canvas
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SGraph

public SGraph()

SGraph

public SGraph(SApplet applet)
Method Detail

setSampleData

public void setSampleData(boolean sd)
Create sample data when it is initialized.
Parameters:
sd - Create the sample data?.

isSampleData

public boolean isSampleData()
Will the graph show sample data when it is initialized?
Returns:
True if graph contains sample data?.

setDrawGrid

public void setDrawGrid(boolean dg)
Set the draw grid property.
Parameters:
dg - Draw the grid?.

isDrawGrid

public boolean isDrawGrid()
Will the graph have a grid?
Returns:
True if grid is shown.

setAutoRefresh

public void setAutoRefresh(boolean auto)
Set the autoRefresh property. Repaint the graph whenever data changes. Slows down the system.
Parameters:
auto - AutoRefresh the graph?.

isAutoRefresh

public boolean isAutoRefresh()

setAutoscaleX

public void setAutoscaleX(boolean as)
Set the autoscaleX property.
Parameters:
as - Autoscale the x axis?.

isAutoscaleX

public boolean isAutoscaleX()

setAutoscaleY

public void setAutoscaleY(boolean as)
Set the autoscaleY property.
Parameters:
as - Autoscale the y axis?.

isAutoscaleY

public boolean isAutoscaleY()

setDrawZero

public void setDrawZero(boolean dz)
Have the graph draw x=0 and y=0 lines.
Parameters:
dz - Draw the lines?

isDrawZero

public boolean isDrawZero()

setSeriesLegend

public void setSeriesLegend(int sid,
                            java.awt.Color c,
                            int xpix,
                            int ypix,
                            java.lang.String legend)
Set the series legend.
Parameters:
sid - The series id.
c - The legend color.
xpix - The x postion in pixels.
ypix - The y postion in pixels.
legend - The legend.

setSeriesLegend

public void setSeriesLegend(int sid,
                            int xpix,
                            int ypix,
                            java.lang.String legend)

setSeriesLegendColor

public void setSeriesLegendColor(int sid,
                                 java.awt.Color c)

setSeriesStyle

public void setSeriesStyle(int sid,
                           java.awt.Color c,
                           boolean conPts,
                           int m)
Set the series style.
Parameters:
sid - The series id.
c - The series color.
conPts - Connect the points?
m - Marker style. (m=1 is cross; m=2 is square, m=3 is circle)

setSeriesStyle

public void setSeriesStyle(int sid,
                           boolean conPts,
                           int m)

setSeriesColor

public void setSeriesColor(int sid,
                           java.awt.Color c)

setShowAxes

public void setShowAxes(boolean sa)
Show or hide the the X and Y axes on the graph. May need to set the gutters to zero seliminate white space.
Parameters:
sa - Show the axis?

setSquare

public void setSquare(boolean isSquare)
Set the aspect ratio=1 so that both axes have the same pixels per unit.
Parameters:
isSquare? -  

getBorders

public java.lang.String getBorders()
Get the margins. Use strings for the beans inspector.
Returns:
A string containg the gutter sizes: left, top, right, bottom.

getID

public int getID()
Get the ID for this object.
Specified by:
getID in interface SDataListener

getThing

public Thing getThing(int id)
Get the ID for a Thing object from the hashcode.

setBorders

public void setBorders(java.lang.String s)
Set the margins. Need to use strings for the beans inspector.
Parameters:
s - The gutter sizes: left, top, right, bottom.

setGutters

public void setGutters(int g1,
                       int g2,
                       int g3,
                       int g4)
Set the gutters.
Parameters:
g1 - The gutter sizes: left, top, right, bottom.

setLabelX

public void setLabelX(java.lang.String s)
Set the x axis label.
Parameters:
The - label value.

setLabelX

public void setLabelX(java.lang.String s,
                      java.awt.Color c)

getLabelX

public java.lang.String getLabelX()

setLabelY

public void setLabelY(java.lang.String s)
Set the y axis label.
Parameters:
The - label value.

setLastPointMarker

public void setLastPointMarker(int sid,
                               boolean lpm)

setAutoReplaceData

public void setAutoReplaceData(int sid,
                               boolean auto)

setAddRepeatedDatum

public void setAddRepeatedDatum(int sid,
                                boolean add)
Set the addRepeatedDataum property. A new datum will not be added to a series if this is false. Default is true.
Parameters:
add - Added repeated data values to the graph?

setLabelY

public void setLabelY(java.lang.String s,
                      java.awt.Color c)

getLabelY

public java.lang.String getLabelY()

setMarkerSize

public void setMarkerSize(double scale)
Set the default marker size.
Parameters:
size - Marker size.

setMarkerSize

public void setMarkerSize(int sid,
                          double scale)
Set the marker size.
Parameters:
id - Series id.
size - Marker size.

setMinMaxX

public void setMinMaxX(double min,
                       double max)
Set the x axis minimum and maximum values.
Parameters:
min - Minumum value.
max - Maximum value.

getMinX

public double getMinX()
Get the x axis minimum .

getMaxX

public double getMaxX()
Get the x axis maximum .

setMinMaxY

public void setMinMaxY(double min,
                       double max)
Set the y axis minimum and maximum values.
Parameters:
min - Minumum value.
max - Maximum value.

getMinY

public double getMinY()
Get the y axis minimum .

getMaxY

public double getMaxY()
Get the y axis maximum .

getFunction

public edu.davidson.display.SGraph.MathFunction getFunction(int id)
Get the function object from the id.
Parameters:
id - The id of the function.

getTitle

public java.lang.String getTitle()

setTitle

public void setTitle(java.lang.String str)

getIDFromSID

public int getIDFromSID(int val)

setObjectColor

public void setObjectColor(int id,
                           java.awt.Color c)
set the color of the object from the id.
Parameters:
id - The id of the function.
c - The color

setOwner

public void setOwner(SApplet owner)
Specified by:
setOwner in interface SDataListener

getOwner

public SApplet getOwner()
Specified by:
getOwner in interface SDataListener

deleteAllFunctions

public void deleteAllFunctions()
Delete all functions.

deleteFunction

public void deleteFunction(int id)
Delete a function from the plot.
Parameters:
id - The id of the function;

deleteAllSeries

public void deleteAllSeries()
Delete all series from the graph.

deleteAllNonSeriesData

public void deleteAllNonSeriesData()
Remove any Data that is not part of a series. Used to get grid of field lines, contour lines, etc

deleteSeries

public void deleteSeries(int id)
Delete one series from the graph.
Specified by:
deleteSeries in interface SDataListener
Parameters:
id - The id of the series to remove.

deleteSeries

public void deleteSeries(int id,
                         boolean willRepaint)

setFunctionRange

public void setFunctionRange(int id,
                             double xmin,
                             double xmax,
                             int n)

setFunctionString

public boolean setFunctionString(int id,
                                 java.lang.String str)
Change the function that is being graphed without adding a new function.
Parameters:
str - The function f(x).

getFunctionString

public java.lang.String getFunctionString(int id)
Get the function that is being graphed.
Parameters:
id - The id of the function.
Returns:
String The function string.

setFunctionVariable

public boolean setFunctionVariable(int id,
                                   java.lang.String str)
Change the function's independent variable.
Parameters:
str - The new variable

clone

public java.lang.Object clone()

createSeries

public edu.davidson.display.SGraph.Series createSeries(int sid)
Create an empty series so that styles, color, and other properites can be set. Return the current series if it exists

clearAllData

public void clearAllData()
Clear the data from all series. Series continues to exist so that data can be added without resetting the style

clearSeries

public void clearSeries(int s)
Clear the data from a series. Series properties such as color and style remain unchanged.
Specified by:
clearSeries in interface SDataListener
Parameters:
s - Series ID

clearSeriesData

public void clearSeriesData(int sid)
Delete the data from a series. Series continues to exist so that data can be added without resetting the style
Parameters:
id - The id of the series.

adjustScale

public void adjustScale()
Use this method to make some last minute scale adjustments. For example, it is uses to rescale the graph if analytic functions are present in SGraph.
Overrides:
adjustScale in class edu.davidson.graph.Graph2D

paintFunctions

public void paintFunctions(java.awt.Graphics g,
                           java.awt.Rectangle r)
A hook into the Graph2D.paint method. This is called before the data is drawn but after the axis in Graph2D. It is used to paint analytic functions in SGraph. The rectangle passed is the dimension of the data window.
Overrides:
paintFunctions in class edu.davidson.graph.Graph2D

repaint

public void repaint()
Overrides:
repaint in class java.awt.Component

run

public void run()
Specified by:
run in interface java.lang.Runnable

paintOffScreen

public void paintOffScreen(java.awt.Graphics g)
Paint the graph offscreen into an image and then blast the image onto the screen

paintOffScreen

public void paintOffScreen()

paintLast

public void paintLast(java.awt.Graphics g,
                      java.awt.Rectangle r)
A hook into the Graph2D.paint method. This is called before the data is drawn but after the axis in Graph2D. It is used to paint analytic functions in SGraph. The rectangle passed is the dimension of the data window.
Overrides:
paintLast in class edu.davidson.graph.Graph2D

pixFromX

public int pixFromX(double x)
Get the pixel value corresponding to an x value.
Parameters:
x - The value along the x axis.
Returns:
The pixel value inside the canvas.

pixFromY

public int pixFromY(double y)

xFromPix

public double xFromPix(int x)
Get the value on the x axis from the pixel value.
Parameters:
x - The pixel inside the canvas.
Returns:
The corresponding value along the x axis.

yFromPix

public double yFromPix(int y)

addDataSet

public edu.davidson.graph.DataSet addDataSet(double[] points,
                                             int np)
Add a data set to the graph. The data does not have an ID and cannot be accessed as a series.
Parameters:
points - The data.
np - The number of points.

addDatum

public void addDatum(int sid,
                     double x,
                     double y)
Add a datum to the graph. The data is attached to series.
Parameters:
id - The series id.
x - The x value of the datum.
y - The y value of the datum.

addDatum

public void addDatum(SDataSource ds,
                     int id,
                     double x,
                     double y)
Specified by:
addDatum in interface SDataListener

clearAllThings

public void clearAllThings()
Remove all dragable objects for the graph.

addCursor

public int addCursor(int diameter,
                     double x,
                     double y)
Add a dragable cursor
Parameters:
int - diameter The diameter.
double - x The initial x position.
double - y The initial y position.

addThing

public int addThing(Thing t)
Add a drawable thing.
Parameters:
t - the ting to be added.

addData

public void addData(int sid,
                    double[] x,
                    double[] y)
Add data to the graph using arrays. The data is attached to series.
Parameters:
id - The series id.
x - The x array of the data.
y - The y array of the data.

addData

public void addData(SDataSource ds,
                    int sid,
                    double[] x,
                    double[] y)
Specified by:
addData in interface SDataListener

addData

public void addData(int sid,
                    double[] x,
                    double[] y,
                    int num)

addFunction

public int addFunction(java.lang.String indVar,
                       java.lang.String str)
Add an analytic function to the graph.
Parameters:
str - The function f(x).

addFunction

public int addFunction(java.lang.String str)

plotRegression

public int plotRegression(int sid)

drawCoords

public void drawCoords(java.awt.Graphics g,
                       int xPix,
                       int yPix)

drawCoords

public void drawCoords(int xPix,
                       int yPix)

isEnableMouse

public boolean isEnableMouse()

setEnableMouse

public void setEnableMouse(boolean em)
Enable the graph to respond to mouse actionions.
Parameters:
em - Enable the coordinate display when the mouse is pressed.

setParentSApplet

public void setParentSApplet(SApplet p)

setFormat

public void setFormat(java.lang.String str)
Change the display format for mouse actions.
Parameters:
str - The format for cooridinate display.

sGraph_mouseEntered

public void sGraph_mouseEntered(java.awt.event.MouseEvent e)

sGraph_mouseExited

public void sGraph_mouseExited(java.awt.event.MouseEvent e)

sGraph_mouseMoved

public void sGraph_mouseMoved(java.awt.event.MouseEvent e)

Copyright Wolfgang Christian

Visit the Davidson CollegeSTools Documentation Page