Spirograph Problem Set Javadocs

spirograph
Class DotPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended byspirograph.DotPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class DotPanel
extends java.awt.Canvas
implements java.lang.Runnable

This class keeps track of the coordinates of the Dot. It has a seperate Thread to update the "state" of the two coordinates and to repaint itself. It also handles the dot bouncing off either the walls of the square or the circle. It also keeps track of all of the gravity points and all of the places where the dot has been before and draws the trail.

Copyright © 1998 Massachusetts Institute of Technology.
Copyright © 2002-2003 Franklin W. Olin College of Engineering.

Version:
$Id: DotPanel.java,v 1.5 2004/02/09 20:55:03 gus Exp $
Author:
Luis Sarmenta, lfgs@cag.lcs.mit.edu, Henry Wong, henryw@mit.edu, Patrick G. Heck, gus.heck@olin.edu
See Also:
Coord, Spirograph, AccelHandler, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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
DotPanel(Coord x, Coord y)
          Create a new dot panel that displays a dot by poling two Coord objects.
 
Method Summary
 void addGrav(int x, int y)
          Place a gravity source at the coordinates specified.
 int curHeight()
          Deprecated. This method and the associated shadow variable violate the DRY (Do not Repeat Yourself) principle. The only visible benefit is a slightly reduced typing. With modern compilers this won't even yield a performance increase because the getWidth or getHeight methods will be inlined. The Sun code for these methods in Component is: public int getWidth() { return width; } For this reason, this method and the associated variables will be removed.
 int curWidth()
          Deprecated. This method and the associated shadow variable violate the DRY (Do not Repeat Yourself) principle. The only visible benefit is a slightly reduced typing. With modern compilers this won't even yield a performance increase because the getWidth or getHeight methods will be inlined. The Sun code for these methods in Component is: public int getWidth() { return width; } For this reason, this method and the associated variable will be removed.
 void flushGrav()
          Delete all gravity sources, and repaint.
 void flushLines()
          Delete the trail of the dot.
 boolean getBounce()
          Query the state of bounce mode.
 boolean getCirc()
          Query the state of circular mode.
 double getMaxX()
          The maximum distance from the center of the drawing area that the ball can be placed in the X direction.
 double getMaxY()
          The maximum distance from the center of the drawing area that the ball can be placed in the X direction.
 java.awt.Dimension getMinimumSize()
          Overide the parent class to return the prefered size as the minimum size.
 java.awt.Dimension getPreferredSize()
          Overides the superclass to return our constants.
 boolean getWrap()
          Query the state of wrap mode.
 boolean inEllipse()
          Convenience wrapper for SpiroUtils.inEllipse(double, double, double, double).
 void paint(java.awt.Graphics out)
          Overide the superclass paint method, to do our own drawing.
 void paintBuf()
          This method paints an off-screen image to be used for the double buffering.
 void run()
          Conducts the drawing of all objects in the DotPanel.
 void setBounce(boolean bounceOn)
          Turn bounce mode on or off.
 void setCirc(boolean circMode)
          Turn circular mode on or off.
 void setMode(int mode)
          Set the operational mode for both coordinate axis.
 void setSize(int width, int height)
          Recalculate the foci and repaint of the elipse before calling the super.setSize().
 void setWrap(boolean wrapOn)
          Turn wrap mode on or off.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, 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, getAlignmentX, getAlignmentY, getBackground, 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, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, 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, 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, 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, setName, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DotPanel

public DotPanel(Coord x,
                Coord y)
Create a new dot panel that displays a dot by poling two Coord objects.

Parameters:
x - Defines the position and movement atributes along the x axis
y - Defines the position and movement atributes along the y axis
Method Detail

setMode

public void setMode(int mode)
Set the operational mode for both coordinate axis.

Parameters:
mode - AccelHandler.POSMODE, AccelHandler.VELMODE, or AccelHandler.ACCELMODE

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overides the superclass to return our constants.

Returns:
new Dimension(Spirograph.WIDTH,Spirograph.HEIGHT)

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overide the parent class to return the prefered size as the minimum size.

Returns:
getPreferredSize()

getMaxX

public double getMaxX()
The maximum distance from the center of the drawing area that the ball can be placed in the X direction.

Returns:
half the width minus the size of the ball

getMaxY

public double getMaxY()
The maximum distance from the center of the drawing area that the ball can be placed in the X direction.

Returns:
half the height minus the size of the ball

run

public void run()
Conducts the drawing of all objects in the DotPanel.

Specified by:
run in interface java.lang.Runnable

inEllipse

public boolean inEllipse()
Convenience wrapper for SpiroUtils.inEllipse(double, double, double, double). This is called by the AdvArg to see whether or not the ball is in the circle. If the ball isn't inside the circle, AdvArg won't turn on circle mode.

Returns:
True if the ball is currently inside the elipse used by circular mode, false otherwise

paintBuf

public void paintBuf()
This method paints an off-screen image to be used for the double buffering.

It adds the balls current position to the vector of Points, then reconstructs the balls path from the Points.


paint

public void paint(java.awt.Graphics out)
Overide the superclass paint method, to do our own drawing.

Parameters:
out - The Graphics object for this component.

setSize

public void setSize(int width,
                    int height)
Recalculate the foci and repaint of the elipse before calling the super.setSize(). Called by the DotFrame whenever the DotFrame is resized

Parameters:
width - The new width
height - The new height

flushLines

public void flushLines()
Delete the trail of the dot. The points defining the trail of the dot are removed from the containing Vector. The position of the dot is uneffected, and the panel is repainted.


flushGrav

public void flushGrav()
Delete all gravity sources, and repaint.


addGrav

public void addGrav(int x,
                    int y)
Place a gravity source at the coordinates specified. Usually this is called by a MouseListener that has been added to the DotPanel.

Parameters:
x - The horizontal coordinate for the gravity source.
y - The vertical coordinate for the gravity source.

setCirc

public void setCirc(boolean circMode)
Turn circular mode on or off.

Parameters:
circMode - true to turn circular mode on, false to turn it off

getCirc

public boolean getCirc()
Query the state of circular mode.

Returns:
True if circular mode is on, false otherwise

curHeight

public int curHeight()
Deprecated. This method and the associated shadow variable violate the DRY (Do not Repeat Yourself) principle. The only visible benefit is a slightly reduced typing. With modern compilers this won't even yield a performance increase because the getWidth or getHeight methods will be inlined. The Sun code for these methods in Component is: public int getWidth() { return width; } For this reason, this method and the associated variables will be removed.

Get the current height of the DotPanel. This method reports the value of the height variable, which in turn shadows the same value as getHeight() in the component class.

Returns:
The current height of the panel

curWidth

public int curWidth()
Deprecated. This method and the associated shadow variable violate the DRY (Do not Repeat Yourself) principle. The only visible benefit is a slightly reduced typing. With modern compilers this won't even yield a performance increase because the getWidth or getHeight methods will be inlined. The Sun code for these methods in Component is: public int getWidth() { return width; } For this reason, this method and the associated variable will be removed.

Get the current width of the DotPanel. This method reports the value of the height variable, which in turn shadows the same value as getHeight() in the component class.

Returns:
The current width of the panel

getBounce

public boolean getBounce()
Query the state of bounce mode.

Returns:
True if bounce mode is on, false otherwise

setBounce

public void setBounce(boolean bounceOn)
Turn bounce mode on or off.

Parameters:
bounceOn - true to turn bounce mode on, false to turn it off

getWrap

public boolean getWrap()
Query the state of wrap mode.

Returns:
True if wrap mode is on, false otherwise

setWrap

public void setWrap(boolean wrapOn)
Turn wrap mode on or off.

Parameters:
wrapOn - true to turn wrap mode on, false to turn it off

Spirograph Problem Set Javadocs