Class TableFunctionGraph

java.lang.Object
edu.hws.jcm.draw.Drawable
edu.hws.jcm.functions.TableFunctionGraph
All Implemented Interfaces:
MouseListener, MouseMotionListener, Serializable, EventListener

public class TableFunctionGraph extends Drawable implements MouseListener, 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:
  • Field Summary

    Fields inherited from class edu.hws.jcm.draw.Drawable

    canvas, coords
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a TableFunctionGraph that initially draws no function.
    Create a TableFunctionGraph to draw the specified TableFunction.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    draw(Graphics g, boolean coordsChanged)
    Override the draw() method from class Drawable to draw the function.
    Get the non-null color that is used for drawing the graph.
    Get the TableFunction whose graph is drawn by this TableFunctionGraph.
    boolean
    Get the value of the interactive property, which is true if the user can modify the function by dragging the points from the table.
    Get the Computable that is notified as the user drags a point.
    Get the Computable that is notified when the user finishes dragging a point.
    boolean
    Get the showPoints property, which determines whether the points from the table that defines the function are visible as little disks.
    void
    Empty method, required by the MouseListener interface.
    void
    Method required by the MouseListener interface.
    void
    Empty method, required by the MouseMotionListener interface.
    void
    Empty method, required by the MouseMotionListener interface.
    void
    Empty method, required by the MouseMotionListener interface.
    void
    Method required by the MouseListener interface.
    void
    Method required by the MouseListener interface.
    void
    Set the color that is used for drawing the graph.
    void
    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
    Specify a controller whose compute() method will be called repeatedly as the user drags one of the points from the table function.
    void
    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
    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 edu.hws.jcm.draw.Drawable

    getVisible, needsRedraw, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • 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.
  • Method Details

    • setFunction

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

      public TableFunction getFunction()
      Get the TableFunction whose graph is drawn by this TableFunctionGraph. If the value is null, then no graph is drawn.
    • 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.
    • getOnDrag

      public Computable getOnDrag()
      Get the Computable that is notified as the user drags a point.
    • 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.
    • getOnFinishDrag

      public Computable getOnFinishDrag()
      Get the Computable that is notified when the user finishes dragging a point.
    • 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.
    • 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.
    • 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;
    • 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.
    • setColor

      public void setColor(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.
    • getColor

      public Color getColor()
      Get the non-null color that is used for drawing the graph.
    • 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
    • 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.
    • draw

      public void draw(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 - The graphics context in which the Drawble is to be drawn. (The drawing can change the color in g, but should not permanently change font, painting mode, etc. Thus, every drawable is responsible for setting the color it wants to use.)
      coordsChanged - Indicates whether the CoordinateRect has changed.
    • mousePressed

      public void mousePressed(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 MouseListener
    • mouseReleased

      public void mouseReleased(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 MouseListener
    • mouseDragged

      public void mouseDragged(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 MouseMotionListener
    • mouseClicked

      public void mouseClicked(MouseEvent evt)
      Empty method, required by the MouseListener interface.
      Specified by:
      mouseClicked in interface MouseListener
    • mouseEntered

      public void mouseEntered(MouseEvent evt)
      Empty method, required by the MouseMotionListener interface.
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent evt)
      Empty method, required by the MouseMotionListener interface.
      Specified by:
      mouseExited in interface MouseListener
    • mouseMoved

      public void mouseMoved(MouseEvent evt)
      Empty method, required by the MouseMotionListener interface.
      Specified by:
      mouseMoved in interface MouseMotionListener