net.sourceforge.webcompmath.functions
Class TableFunctionGraph

java.lang.Object
  extended by java.awt.Component
      extended by net.sourceforge.webcompmath.draw.Drawable
          extended by net.sourceforge.webcompmath.functions.TableFunctionGraph
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener
Direct Known Subclasses:
WCMTableFunctionGraphBean

public class TableFunctionGraph
extends Drawable
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

A TableFunctionGraph is a Drawable object that can be added to a CoordinateRect (or DisplayCanvas). It draws the graph of a specified TableFunction. A TableFunction is a function and can also be graphed by an object of the class edu.hws.jcm.draw.Graph1D. However, a TableFunctionGraph offers the option of showing the points from the table that defines the function as small disks (true by default) and the option of making the graph "interactive" so that the user can drag the points (false by default).

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int DASHED_STYLE
          Specifies that the shape should be drawn with dashed line(s).
protected  int lineStyle
          The line style, SOLID_STYLE or DASHED_STYLE
protected  int lineWidth
          The width, in pixels, of lines.
static int SOLID_STYLE
          Specifies that the shape should be drawn with solid line(s).
 
Fields inherited from class net.sourceforge.webcompmath.draw.Drawable
canvas, coords
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TableFunctionGraph()
          Create a TableFunctionGraph that initially draws no function.
TableFunctionGraph(TableFunction function)
          Create a TableFunctionGraph to draw the specified TableFunction.
 
Method Summary
 void draw(java.awt.Graphics g, boolean coordsChanged)
          Override the draw() method from class Drawable to draw the function.
 java.awt.Color getColor()
          Get the non-null color that is used for drawing the graph.
 TableFunction getFunction()
          Get the TableFunction whose graph is drawn by this TableFunctionGraph.
 boolean getInteractive()
          Get the value of the interactive property, which is true if the user can modify the function by dragging the points from the table.
 int getLineStyle()
          Get the line style, SOLID_STYLE or DASHED_STYLE
 int getLineWidth()
          Get the width, in pixels, of lines that are drawn.
 Computable getOnDrag()
          Get the Computable that is notified as the user drags a point.
 Computable getOnFinishDrag()
          Get the Computable that is notified when the user finishes dragging a point.
 boolean getShowPoints()
          Get the showPoints property, which determines whether the points from the table that defines the function are visible as little disks.
 void mouseClicked(java.awt.event.MouseEvent evt)
          Empty method, required by the MouseListener interface.
 void mouseDragged(java.awt.event.MouseEvent evt)
          Method required by the MouseListener interface.
 void mouseEntered(java.awt.event.MouseEvent evt)
          Empty method, required by the MouseMotionListener interface.
 void mouseExited(java.awt.event.MouseEvent evt)
          Empty method, required by the MouseMotionListener interface.
 void mouseMoved(java.awt.event.MouseEvent evt)
          Empty method, required by the MouseMotionListener interface.
 void mousePressed(java.awt.event.MouseEvent evt)
          Method required by the MouseListener interface.
 void mouseReleased(java.awt.event.MouseEvent evt)
          Method required by the MouseListener interface.
 void setColor(java.awt.Color c)
          Set the color that is used for drawing the graph.
 void setFunction(TableFunction function)
          Set the function whose graph is drawn by this TableFunctionGraph.
 void setFunctionStyle(int style)
          Provided as a convenience.
 void setInteractive(boolean interactive)
          Set the value of the interactive property, which is true if the user can modify the function by dragging the points from the table.
 void setLineStyle(int lineStyle)
          Set the line style, SOLID_STYLE or DASHED_STYLE
 void setLineWidth(int width)
          Set the width, in pixels, of lines that are drawn.
 void setOnDrag(Computable c)
          Specify a controller whose compute() method will be called repeatedly as the user drags one of the points from the table function.
 void setOnFinishDrag(Computable c)
          Specify a controller whose compute() method will be called once when the user finishes dragging one of the points from the table function.
protected  void setOwnerData(DisplayCanvas canvas, CoordinateRect coords)
          Sets the values of member variables canvas and coords.
 void setShowPoints(boolean show)
          Set the showPoints property, which determines whether the points from the table that defines the function are visible as little disks.
 
Methods inherited from class net.sourceforge.webcompmath.draw.Drawable
getVisible, needsRedraw, setVisible
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lineWidth

protected int lineWidth
The width, in pixels, of lines. It is restricted to being an integer in the range from 1 to 10.


SOLID_STYLE

public static final int SOLID_STYLE
Specifies that the shape should be drawn with solid line(s). This is the default.

See Also:
Constant Field Values

DASHED_STYLE

public static final int DASHED_STYLE
Specifies that the shape should be drawn with dashed line(s).

See Also:
Constant Field Values

lineStyle

protected int lineStyle
The line style, SOLID_STYLE or DASHED_STYLE

Constructor Detail

TableFunctionGraph

public TableFunctionGraph()
Create a TableFunctionGraph that initially draws no function. A function can be set later with setFunction.


TableFunctionGraph

public TableFunctionGraph(TableFunction function)
Create a TableFunctionGraph to draw the specified TableFunction.

Parameters:
function - table function to graph
Method Detail

setFunction

public void setFunction(TableFunction function)
Set the function whose graph is drawn by this TableFunctionGraph. If the value is null, nothing is drawn

Parameters:
function - table function to graph

getFunction

public TableFunction getFunction()
Get the TableFunction whose graph is drawn by this TableFunctionGraph. If the value is null, then no graph is drawn.

Returns:
table function being graphed

setOnDrag

public void setOnDrag(Computable c)
Specify a controller whose compute() method will be called repeatedly as the user drags one of the points from the table function. This only applies if the "interactive" property is true.

Parameters:
c - computable to use (usually a controller)

getOnDrag

public Computable getOnDrag()
Get the Computable that is notified as the user drags a point.

Returns:
computable notified (usually a controller)

setOnFinishDrag

public void setOnFinishDrag(Computable c)
Specify a controller whose compute() method will be called once when the user finishes dragging one of the points from the table function. This only applies if the "interactive" property is true.

Parameters:
c - controller to use

getOnFinishDrag

public Computable getOnFinishDrag()
Get the Computable that is notified when the user finishes dragging a point.

Returns:
controller notified

setInteractive

public void setInteractive(boolean interactive)
Set the value of the interactive property, which is true if the user can modify the function by dragging the points from the table. The default is false.

Parameters:
interactive - true or false

getInteractive

public boolean getInteractive()
Get the value of the interactive property, which is true if the user can modify the function by dragging the points from the table.

Returns:
true or false

setShowPoints

public void setShowPoints(boolean show)
Set the showPoints property, which determines whether the points from the table that defines the function are visible as little disks. The default is true;

Parameters:
show - true or false

getShowPoints

public boolean getShowPoints()
Get the showPoints property, which determines whether the points from the table that defines the function are visible as little disks.

Returns:
true or false

setColor

public void setColor(java.awt.Color c)
Set the color that is used for drawing the graph. The defalt is magenta. If the specified Color value is null, the call to setColor is ignored.

Parameters:
c - color for drawing

getColor

public java.awt.Color getColor()
Get the non-null color that is used for drawing the graph.

Returns:
color for drawing

setLineWidth

public void setLineWidth(int width)
Set the width, in pixels, of lines that are drawn. If set to 0, the thinnest possible line is drawn.

Parameters:
width - line width

getLineWidth

public int getLineWidth()
Get the width, in pixels, of lines that are drawn.

Returns:
line width

getLineStyle

public int getLineStyle()
Get the line style, SOLID_STYLE or DASHED_STYLE

Returns:
Returns the lineStyle.

setLineStyle

public void setLineStyle(int lineStyle)
Set the line style, SOLID_STYLE or DASHED_STYLE

Parameters:
lineStyle - The lineStyle to set.

setOwnerData

protected void setOwnerData(DisplayCanvas canvas,
                            CoordinateRect coords)
Sets the values of member variables canvas and coords. This is designed to be called only by the CoordinateRect class. This overrides Drawable.setOwnerData();

Overrides:
setOwnerData in class Drawable
Parameters:
canvas - the DisplayCanvas to use
coords - the CoordinateRect to use

setFunctionStyle

public void setFunctionStyle(int style)
Provided as a convenience. If the function for this TableFunctionGraph is non-null, its style is set to the specified style, and the graph is redrawn. The parameter should be one of the constants TableFunction.SMOOTH, TableFunction.PIECEWISE_LINEAR, TableFunction.STEP, TableFunction.STEP_LEFT, or TableFunction.STEP_RIGHT.

Parameters:
style - function style

draw

public void draw(java.awt.Graphics g,
                 boolean coordsChanged)
Override the draw() method from class Drawable to draw the function. This is not meant to be called directly.

Specified by:
draw in class Drawable
Parameters:
g - graphics context to use
coordsChanged - true or false

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Method required by the MouseListener interface. Defined here to support dragging of points on the function's graph. Not meant to be called directly.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
evt - event created when user clicks mouse

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Method required by the MouseListener interface. Defined here to support dragging of points on the function's graph. Not meant to be called directly.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
evt - event created when user releases mouse button

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)
Method required by the MouseListener interface. Defined here to support dragging of points on the function's graph. Not meant to be called directly.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
evt - event created while mouse being dragged

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent evt)
Empty method, required by the MouseListener interface.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
evt - the event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent evt)
Empty method, required by the MouseMotionListener interface.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
evt - the event

mouseExited

public void mouseExited(java.awt.event.MouseEvent evt)
Empty method, required by the MouseMotionListener interface.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
evt - the event

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Empty method, required by the MouseMotionListener interface.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
evt - the event