canvas
Class ShapeComponent

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--canvas.ShapeComponent
All Implemented Interfaces:
CanvasComponent, ImageObserver, MenuContainer, RotatingCanvasComponent, Serializable
Direct Known Subclasses:
DropDragShapeComponent

public class ShapeComponent
extends JComponent
implements RotatingCanvasComponent

Provides the infrastructure for drawing and using Arc, Ellipse, Line, and Rect objects.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static boolean debug
           
 String name
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
ShapeComponent(Shape shape)
          Creates a ShapeComponent for the given Shape.
ShapeComponent(Shape shape, boolean filled)
          Creates a ShapeComponent for the given Shape.
ShapeComponent(Shape shape, boolean filled, Color c)
          Creates a ShapeComponent for the given Shape.
ShapeComponent(Shape shape, Color c)
          Creates a ShapeComponent for the given Shape.
 
Method Summary
 void displace(double dx, double dy)
          Displaces this ShapeComponent by the given amount.
 void displace(double dx, double dy, canvas.DrawingGrid dg)
          Displaces the ShapeComponent by the given DrawingGrid amount.
 canvas.DrawingPane getDrawingPane()
          Returns the DrawingPane that this ShapeComponent has been added to.
 boolean getFilled()
          Returns true if the shape is filled, and false if it is not
 Dimension getPreferredSize()
          For discovering the "best" width and height of the component.
 Shape getShape()
          Gets the shape out of this ShapeComponent.
 double getShapeHeight()
          Returns the height of the shape
 double getShapeWidth()
          Returns the widith of the shape
 double getShapeX()
          Returns the X coodinate of the the shape
 double getShapeY()
          Returns the Y coordinate of the shape
 void moveTo(double x, double y)
          Moves the Shape
 void moveTo(double x, double y, canvas.DrawingGrid dg)
          Moves the ShapeComponent to be centered on DrawingGrid (x, y).
 void paint(Graphics g)
          Paints the component.
 void redraw()
          Use this method whenever you want to immediately update the display of this ShapeComponent.
 void resizeTo(double width, double height)
          Resizes the Shape
 void resizeTo(double width, double height, canvas.DrawingGrid dg)
          Resizes the Shape to the specified DrawingGrid width and height.
 void rotate(double degrees)
          Rotates the shape
 void rotateAbout(double degrees, double x, double y)
          Rotates the shape About a Specific Point
 void rotateAbout(double degrees, double x, double y, canvas.DrawingGrid dg)
          Rotates the shape about a specific DrawingGrid point.
static void setDebug(boolean debug)
          Sets whether or not to print error messages
 void setFeedbackText(String text)
          If this ShapeComponent is contained in a ViewFrame, then this will set the ViewFrame's Feedback Label to the given text
 void setFilled(boolean filled)
          Sets whether or not to fill the shape when drawing.
 void smoothDisplace(double dx, double dy, int milliseconds)
           
 void smoothDisplace(double dx, double dy, int milliseconds, canvas.DrawingGrid dg)
           
 void smoothMove(double x, double y, int milliseconds)
          Moves the Shape over a Specific Amount of Time
 void smoothMove(double x, double y, int milliseconds, canvas.DrawingGrid dg)
          Moves the Shape over a specific amount of time to the DrawingGrid (x, y).
 void smoothResize(double width, double height, int milliseconds)
          Resizes the Shape over a Specific Amount of Time
 void smoothResize(double width, double height, int milliseconds, canvas.DrawingGrid dg)
          Resizes the Shape to the specified DrawingGrid width and height over a specific amount of time.
 void smoothRotate(double degree, int milliseconds)
          Rotates the shape over a Specific Amount of Time
 void smoothRotateAbout(double degrees, double x, double y, int milliseconds)
          Rotates the shape About a Specific Point over a Specific Time
 void smoothRotateAbout(double degrees, double x, double y, int milliseconds, canvas.DrawingGrid dg)
           
 String toString()
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface canvas.CanvasComponent
getHeight, getWidth
 

Field Detail

debug

public static boolean debug

name

public String name
Constructor Detail

ShapeComponent

public ShapeComponent(Shape shape)
Creates a ShapeComponent for the given Shape. The shape will be drawn in black and will not be filled.

Parameters:
shape - any 'Shape'

ShapeComponent

public ShapeComponent(Shape shape,
                      boolean filled)
Creates a ShapeComponent for the given Shape. The shape will be drawn in black.

Parameters:
shape - any 'Shape'
filled - whether or not to fill in the shape

ShapeComponent

public ShapeComponent(Shape shape,
                      Color c)
Creates a ShapeComponent for the given Shape. The shape will not be filled in.

Parameters:
shape - any 'Shape'
c - the color to be used to draw the shape

ShapeComponent

public ShapeComponent(Shape shape,
                      boolean filled,
                      Color c)
Creates a ShapeComponent for the given Shape.

Parameters:
shape - any 'Shape'
filled - whether or not to fill the shape with color
c - the color with which to draw the shape
Method Detail

setDebug

public static void setDebug(boolean debug)
Sets whether or not to print error messages


redraw

public void redraw()
Use this method whenever you want to immediately update the display of this ShapeComponent. Such a situation is quite unlikely.

Specified by:
redraw in interface CanvasComponent

getShapeX

public double getShapeX()
Returns the X coodinate of the the shape


getShapeY

public double getShapeY()
Returns the Y coordinate of the shape


getShapeWidth

public double getShapeWidth()
Returns the widith of the shape


getShapeHeight

public double getShapeHeight()
Returns the height of the shape


setFilled

public void setFilled(boolean filled)
Sets whether or not to fill the shape when drawing.

Parameters:
filled - whether or not to fill the shape when drawing.

getFilled

public boolean getFilled()
Returns true if the shape is filled, and false if it is not


displace

public void displace(double dx,
                     double dy)
Displaces this ShapeComponent by the given amount.


displace

public void displace(double dx,
                     double dy,
                     canvas.DrawingGrid dg)
Displaces the ShapeComponent by the given DrawingGrid amount.


smoothDisplace

public void smoothDisplace(double dx,
                           double dy,
                           int milliseconds)

smoothDisplace

public void smoothDisplace(double dx,
                           double dy,
                           int milliseconds,
                           canvas.DrawingGrid dg)

getDrawingPane

public canvas.DrawingPane getDrawingPane()
Returns the DrawingPane that this ShapeComponent has been added to.


getShape

public Shape getShape()
Gets the shape out of this ShapeComponent.


getPreferredSize

public Dimension getPreferredSize()
For discovering the "best" width and height of the component.

Overrides:
getPreferredSize in class JComponent
Returns:
a 'Dimension' object encapsulating the preferred width and height

paint

public void paint(Graphics g)
Paints the component.

Overrides:
paint in class JComponent
Parameters:
g - the graphics context in which to draw

rotate

public void rotate(double degrees)
Rotates the shape

Specified by:
rotate in interface RotatingCanvasComponent
Parameters:
degrees - the number of degrees the shape is rotated counter clockwise

smoothRotate

public void smoothRotate(double degree,
                         int milliseconds)
Rotates the shape over a Specific Amount of Time

Specified by:
smoothRotate in interface RotatingCanvasComponent
Parameters:
milliseconds - the amount of time the rotation will take

rotateAbout

public void rotateAbout(double degrees,
                        double x,
                        double y)
Rotates the shape About a Specific Point

Specified by:
rotateAbout in interface RotatingCanvasComponent
Parameters:
degrees - the number of degrees the shape is rotated counter clockwise
x - the x coord of the rotation point
y - the y coord of the rotation point

rotateAbout

public void rotateAbout(double degrees,
                        double x,
                        double y,
                        canvas.DrawingGrid dg)
Rotates the shape about a specific DrawingGrid point.

Parameters:
degrees - the number of degrees the shape is rotated counter clockwise
x - the x DrawingGrid coord of the rotation point
y - the y DrawingGrid coord of the rotation point

smoothRotateAbout

public void smoothRotateAbout(double degrees,
                              double x,
                              double y,
                              int milliseconds)
Rotates the shape About a Specific Point over a Specific Time

Specified by:
smoothRotateAbout in interface RotatingCanvasComponent
Parameters:
degrees - the number of degrees the shape is rotated counter clockwise
x - the x coord of the rotation point
y - the y coord of the rotation point
milliseconds - the amount of time rotation will take

smoothRotateAbout

public void smoothRotateAbout(double degrees,
                              double x,
                              double y,
                              int milliseconds,
                              canvas.DrawingGrid dg)

resizeTo

public void resizeTo(double width,
                     double height)
Resizes the Shape

Specified by:
resizeTo in interface CanvasComponent
Parameters:
width - the desired width
height - the desired height

resizeTo

public void resizeTo(double width,
                     double height,
                     canvas.DrawingGrid dg)
Resizes the Shape to the specified DrawingGrid width and height.


smoothResize

public void smoothResize(double width,
                         double height,
                         int milliseconds)
Resizes the Shape over a Specific Amount of Time

Specified by:
smoothResize in interface CanvasComponent
Parameters:
width - the desired width
height - the desired height
milliseconds - time resizing will take

smoothResize

public void smoothResize(double width,
                         double height,
                         int milliseconds,
                         canvas.DrawingGrid dg)
Resizes the Shape to the specified DrawingGrid width and height over a specific amount of time.


moveTo

public void moveTo(double x,
                   double y)
Moves the Shape

Specified by:
moveTo in interface CanvasComponent
Parameters:
x - the desired x location
y - the desired y location

moveTo

public void moveTo(double x,
                   double y,
                   canvas.DrawingGrid dg)
Moves the ShapeComponent to be centered on DrawingGrid (x, y).


smoothMove

public void smoothMove(double x,
                       double y,
                       int milliseconds)
Moves the Shape over a Specific Amount of Time

Specified by:
smoothMove in interface CanvasComponent
Parameters:
x - the desired x location
y - the desired y location
milliseconds - time move will take

smoothMove

public void smoothMove(double x,
                       double y,
                       int milliseconds,
                       canvas.DrawingGrid dg)
Moves the Shape over a specific amount of time to the DrawingGrid (x, y).


setFeedbackText

public void setFeedbackText(String text)
If this ShapeComponent is contained in a ViewFrame, then this will set the ViewFrame's Feedback Label to the given text

Specified by:
setFeedbackText in interface CanvasComponent

toString

public String toString()
Overrides:
toString in class Component