vmm.planecurve
Class PlaneCurve

java.lang.Object
  extended by vmm.core.Exhibit
      extended by vmm.planecurve.PlaneCurve
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.ChangeListener, Decorateable, Parameterizable
Direct Known Subclasses:
PlaneCurveParametric

public abstract class PlaneCurve
extends Exhibit

A PlaneCurve represents a curve in the xy-plane that is defined by an array of points. Since a null value in that array is interpreted as a break in the curve, the curve can in fact consist of multiple segments.


Field Summary
protected  java.awt.geom.Point2D[] movingSquare
           
protected  java.awt.geom.Point2D[] points
          The array of xy-points that define the curve.
protected  java.awt.geom.Point2D[] randomSquare
           
 
Fields inherited from class vmm.core.Exhibit
decorations, exhibitNeedsRedraw, isMorphing, morphingView, parameters, previousTransform
 
Constructor Summary
PlaneCurve()
           
 
Method Summary
protected  void computeDrawData(View view, boolean exhibitNeedsRedraw, Transform previousTransform, Transform newTransform)
          Recompute any cached data in the Exhibit that might have changed since it was computed.
protected  void doDraw(java.awt.Graphics2D g, View view, Transform transform)
          Do the actual drawing of the exhibit.
 java.awt.geom.Point2D[] fillRandomSquare(int numPoints)
          public Point2D[] fillRandomSquare() puts numPoints random points into a square of edge length 2.
 java.awt.geom.Point2D getPoint(int index)
          Get one of the points in the point array that defines this curve.
 int getPointCount()
          Returns the number of points in the Point array for this curve (including any null values).
 java.awt.geom.Point2D[] initializeMovingSquare(int numPoints)
          initializeMovingSquare(numPoints) Initializes the array MovingSquare[] and its elements only once for each new call of a curve exhibit.
protected abstract  void makePoints()
          This method should compute the array of points that define the curve.
protected  java.awt.geom.Point2D[] moveSquare(int numPoints, double xm, double ym, double ex, double ey, double ll)
          Point2D[] moveSquare(...) moves the scaled standard random square along the curve.
 
Methods inherited from class vmm.core.Exhibit
addChangeListener, addDecoration, addExtraXML, addParameter, addView, clearDecorations, computeDrawDataHook, doDrawHook, fireExhibitChangeEvent, forceRedraw, getActionsForView, getAdditionalAnimationsForView, getAlternativeViews, getBuildAnimation, getCreateAnimation, getDecorations, getDefaultBackground, getDefaultForeground, getDefaultTransform, getDefaultView, getDefaultWindow, getFramesForMorphing, getMorphingAnimation, getName, getParameterByName, getParameters, getSettingsCommandsForView, getTitle, getUseFilmstripForMorphing, getViews, parameterChanged, readExtraXML, removeChangeListener, removeDecoration, removeParameter, removeView, render, setDefaultBackground, setDefaultForeground, setDefaultWindow, setDefaultWindow, setFramesForMorphing, setName, setUseFilmstripForMorphing, stateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

points

protected java.awt.geom.Point2D[] points
The array of xy-points that define the curve. A null value in this array is interpreted as a break in the curve. This array is initially null; if it is null at the time the curve is drawn, nothing is done.


randomSquare

protected java.awt.geom.Point2D[] randomSquare

movingSquare

protected java.awt.geom.Point2D[] movingSquare
Constructor Detail

PlaneCurve

public PlaneCurve()
Method Detail

makePoints

protected abstract void makePoints()
This method should compute the array of points that define the curve. The array must be assigned to the protected variable points. This method is called by the computeDrawData(View, boolean, Transform, Transform) method.


getPointCount

public int getPointCount()
Returns the number of points in the Point array for this curve (including any null values). If the point array has not yet been created, because the curve has not yet been drawn, then the return value is zero.


getPoint

public java.awt.geom.Point2D getPoint(int index)
Get one of the points in the point array that defines this curve.

Parameters:
index - the index of the point in the point array. The value must be in the range from 0 to one less than the value returned by getPointCount(), or an error of type NullPointerException or ArrayIndexOutOfBoundsError will occur.
Returns:
the point at the specified index in the point array. This can be null if the specified position in the array holds a null value.

computeDrawData

protected void computeDrawData(View view,
                               boolean exhibitNeedsRedraw,
                               Transform previousTransform,
                               Transform newTransform)
Description copied from class: Exhibit
Recompute any cached data in the Exhibit that might have changed since it was computed. This method is called (indirectly through computeDrawDataHook) by the render method before it calls doDraw. Its purpose is to give the Exhibit a chance to recalculate any data that it needs in order to draw itself. Not all Exhibits will need to "cache" computed data in this way. The method in this top-level exhibit class does nothing.

Overrides:
computeDrawData in class Exhibit
Parameters:
view - The View that is drawing the Exhibit.
exhibitNeedsRedraw - This parameter is set to "true" if the Exhibit's forceRedraw() method has been called since the last redraw. If it is true, then presumably the appearance of the Exhibit has changed, so any cached data should be recomputed.
previousTransform - The Transform object that was used the last time the Exhibit was drawn. This can be null if the Exhibit is being drawn for the first time.
newTransform - The Transform object that is being used for this drawing of the Exhibit. Transform objects contain data about the window in the xy-plane where the Exhibit is being drawn and about the pixel coordinates on the drawing area. The two Transform objects are provided in case any cached data depends on the xy-window or on the pixel coordinates. Note that the Transform might have changed even if exhibitNeedsRedraw is false.
See Also:
Exhibit.render(Graphics2D, View, Transform, ArrayList), Exhibit.forceRedraw(), Exhibit.doDraw(Graphics2D, View, Transform)

doDraw

protected void doDraw(java.awt.Graphics2D g,
                      View view,
                      Transform transform)
Description copied from class: Exhibit
Do the actual drawing of the exhibit. This method is called (indirectly through doDrawHook) by render to draw the Exhibit. The computeDrawData method is called by render before it calls this method, so any cached data should be valid by the time this method is called. The method in this class does nothing. Subclasses should override this method, unless they provide some other technique for drawing the Exhibit.

Overrides:
doDraw in class Exhibit
Parameters:
g - The graphics context where the Exhibit is being drawn. It has already been cleared to the background color (assuming that drawing is being done in the usual way, as defined in the top-level View class).
view - The View that is drawing the Exhibit; this object contains other information that might be of use, such as the Display, if any, associated with the View.
transform - Contains information about the rectangular area in the xy-plane that is being drawn and about the rectangle of pixels in the graphics context where it is drawn. Note that at least for the top-level View class, transform.getX() and transform.getY() can be assumed to be zero.
See Also:
Exhibit.render(Graphics2D, View, Transform, ArrayList), Exhibit.computeDrawData(View, boolean, Transform, Transform)

fillRandomSquare

public java.awt.geom.Point2D[] fillRandomSquare(int numPoints)
public Point2D[] fillRandomSquare() puts numPoints random points into a square of edge length 2.


initializeMovingSquare

public java.awt.geom.Point2D[] initializeMovingSquare(int numPoints)
initializeMovingSquare(numPoints) Initializes the array MovingSquare[] and its elements only once for each new call of a curve exhibit. Avoids garbage collection while the dotted square moves along a curve.


moveSquare

protected java.awt.geom.Point2D[] moveSquare(int numPoints,
                                             double xm,
                                             double ym,
                                             double ex,
                                             double ey,
                                             double ll)
Point2D[] moveSquare(...) moves the scaled standard random square along the curve. The random points are put with .setLocation into movingSquare[] without creating new points.