All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jdsltools.visualization.GenericShape

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----jdsltools.visualization.GenericShape

public abstract class GenericShape
extends Canvas
implements Timeline, MouseListener, MouseMotionListener
A Timeline that extends a java.awt.Canvas. Maintains the set of base locations and draws the bases (where "base" is the graphical dot that represents an "event" in Timeline parlance). Animates the ball that the user moves with the mouse to change the current event.

Three methods are abstract. They deal with the particular shape that the subclass defines.

Version:
Sat Dec 14 17:58:30 1996
Author:
Lubomir Bourdev, Mark Handy, Ryan Shaun Baker

Variable Index

 o ballPos_
 o baseColors_
 o bases_
 o client_
 o closestIndex_
 o eventSequence_
 o height_
 o margin_
 o size_
 o width_

Constructor Index

 o GenericShape()
Constructor is empty to support instantiation with java.lang.Class.newInstance().

Method Index

 o addEvent(Point, Color, Object)
Ditto above, with hint about color in which to draw the base.
 o addEvent(Point, Object)
Called to add a new event.

 o addEventScroll(Point, Color, Object, boolean)
 o analogousInTree(BinaryTree, BinaryTree, Position)
 o analogousPosition(Container, Container, Position)
 o ballMoveTo(Point)
Moves the ball closest to the given point, but still on the shape.
 o beginOperation()
Called to reset the Timeline and begin a new sequence of events.

 o client()
Gives the current client.

 o clipEnd(String, int)
 o closestBase(Point)
Brute force search, because has no assumptions about the bases' locations.
 o drawBall(Point, Graphics)
Draws the ball at the given location.
 o drawBase(Point, Color, Graphics)
Draws the base at the given point with the given color.
 o drawEmpty(Graphics)
Do something when there is nothing to do -- i.e., when there are no events to be drawn.

 o drawShape(Graphics)
Draw the shape in the Graphics.
 o endOperation()
Called when the current sequence of events is over.

 o init(int, int, int, VisualizationController)
Actual initialization work.

 o isAtBottom()
 o mouseClicked(MouseEvent)
 o mouseDragged(MouseEvent)
 o mouseEntered(MouseEvent)
 o mouseExited(MouseEvent)
 o mouseMoved(MouseEvent)
 o mousePressed(MouseEvent)
 o mouseReleased(MouseEvent)
 o onShape(Point, boolean)
Return a corresponding point on the shape to the parameter point (probably the closest point).

 o paint(Graphics)
 o setClient(TimelineClient)
Sets the link to the client.

 o setInfo(String)
 o setSize(int, int)
Method of Canvas that is called by AWT for layout purposes.

 o setTimelinePos(Point)
 o setTimelineToBottom()
 o spaint(Graphics)
Draws the shape, the bases, and the ball at the last base (if any)

 o squareDistance(Point, Point)
Computes the distance between two points, needed by 'closestBase'.
 o timelinePos()
 o update(Graphics)
Method called by AWT thread at some point after this component requests a repaint().

Variables

 o width_
 protected int width_
 o height_
 protected int height_
 o margin_
 protected int margin_
 o bases_
 protected VectorSequence bases_
 o baseColors_
 protected VectorSequence baseColors_
 o eventSequence_
 protected VectorSequence eventSequence_
 o size_
 protected int size_
 o ballPos_
 protected Point ballPos_
 o closestIndex_
 protected int closestIndex_
 o client_
 protected VisualizationController client_

Constructors

 o GenericShape
 public GenericShape()
Constructor is empty to support instantiation with java.lang.Class.newInstance(). Initialization done in init(.), which should be called immediately after construction.

Methods

 o onShape
 public abstract Point onShape(Point p,
                               boolean constrain)
Return a corresponding point on the shape to the parameter point (probably the closest point).

Parameters:
p - Some point somewhere
constrain - Whether the returned point should be constrained to be on the part of the shape between the first base and the last, as opposed to whether it should be somewhere on the mathematical curve
Returns:
The closest or otherwise corresponding point on the shape
 o drawShape
 public abstract void drawShape(Graphics g)
Draw the shape in the Graphics.

 o drawEmpty
 public abstract void drawEmpty(Graphics g)
Do something when there is nothing to do -- i.e., when there are no events to be drawn.

Parameters:
g - Graphics into which to draw a "no events" message
 o init
 public void init(int width,
                  int height,
                  int margin,
                  VisualizationController client)
Actual initialization work.

Parameters:
width - width of canvas
height - height of canvas
margin - offset of the shape from the boundary of canvas
 o setSize
 public void setSize(int width,
                     int height)
Method of Canvas that is called by AWT for layout purposes.

Parameters:
width - New width of Canvas
height - New height of Canvas
Overrides:
setSize in class Component
 o client
 public TimelineClient client()
Gives the current client.

 o setClient
 public void setClient(TimelineClient client)
Sets the link to the client.

Parameters:
New - client to which this Timeline will report selected events
 o beginOperation
 public void beginOperation()
Called to reset the Timeline and begin a new sequence of events.

 o endOperation
 public void endOperation()
Called when the current sequence of events is over.

 o addEvent
 public void addEvent(Point locatorPosition,
                      Object clientData)
Called to add a new event.

Parameters:
locatorPosition - Hint about where on path to place base
clientData - Object to report to client when corresponding event is selected
 o addEvent
 public void addEvent(Point locatorPosition,
                      Color baseColor,
                      Object clientData)
Ditto above, with hint about color in which to draw the base. Subclass should extend this method to add a new base position to Sequence bases_.

 o addEventScroll
 public void addEventScroll(Point locatorPosition,
                            Color baseColor,
                            Object clientData,
                            boolean scroll)
 o spaint
 public void spaint(Graphics g)
Draws the shape, the bases, and the ball at the last base (if any)

Parameters:
g - java.awt.Graphics into which to draw.
 o paint
 public void paint(Graphics g)
Overrides:
paint in class Canvas
 o update
 public void update(Graphics g)
Method called by AWT thread at some point after this component requests a repaint(). Overridden here to remove the drawing of the background, which causes flickering during mouseDrag() operations.

Overrides:
update in class Component
 o ballMoveTo
 public void ballMoveTo(Point p)
Moves the ball closest to the given point, but still on the shape. Visualizes the container closest to the mouse position.

Parameters:
p - coordinates of the point (will be mapped to the shape)
 o drawBase
 protected void drawBase(Point p,
                         Color c,
                         Graphics g)
Draws the base at the given point with the given color. Optionally override in subclasses.

Parameters:
p - position to draw the base at
c - color of the base
g - java.awt.Graphics into which to draw
 o drawBall
 protected void drawBall(Point p,
                         Graphics g)
Draws the ball at the given location. Assumes XOR mode is set in Graphics g. Optionally override in subclasses.

Parameters:
p - position to draw the ball at
g - java.awt.Graphics into which to draw
 o squareDistance
 protected int squareDistance(Point p1,
                              Point p2)
Computes the distance between two points, needed by 'closestBase'. Note that squared distance is sufficient, since it is needed for relative comparisons.

Returns:
squared distance between p1 and p2
 o closestBase
 protected int closestBase(Point p)
Brute force search, because has no assumptions about the bases' locations. Can be overridden to make it more efficient.

Returns:
Index of base closest to the given point p
 o isAtBottom
 public boolean isAtBottom()
 o timelinePos
 public Point timelinePos()
 o setTimelinePos
 public void setTimelinePos(Point p)
 o setTimelineToBottom
 public void setTimelineToBottom()
 o setInfo
 public void setInfo(String s)
 o mouseClicked
 public void mouseClicked(MouseEvent e)
 o mousePressed
 public void mousePressed(MouseEvent e)
 o mouseReleased
 public void mouseReleased(MouseEvent e)
 o mouseEntered
 public void mouseEntered(MouseEvent e)
 o mouseExited
 public void mouseExited(MouseEvent e)
 o mouseDragged
 public void mouseDragged(MouseEvent e)
 o mouseMoved
 public void mouseMoved(MouseEvent e)
 o analogousPosition
 public Position analogousPosition(Container initial,
                                   Container duplicate,
                                   Position toanalogize)
 o analogousInTree
 public Position analogousInTree(BinaryTree initial,
                                 BinaryTree duplicate,
                                 Position toanalogize)
 o clipEnd
 public String clipEnd(String s,
                       int howmuch)

All Packages  Class Hierarchy  This Package  Previous  Next  Index