canvas
Class DrawingPane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JLayeredPane
                          |
                          +--canvas.DrawingPane
All Implemented Interfaces:
Accessible, CanvasComponent, DragComponent, DragSourceListener, EventListener, ImageObserver, MenuContainer, Serializable, Transferable

public class DrawingPane
extends JLayeredPane
implements Transferable, DragSourceListener, DragComponent, CanvasComponent

Provides support for drawing shapes in a window. When a Component is added to this DrawingPane, it is displayed in the window that contains this DrawingPane. Since a DrawingPane is a Component, one DrawingPane containing an arrangement of other items can be added to another DrawingPane. This type of modular structure is encouraged. A DrawingPane also provides the smooth movement and resizing of CanvasComponents and smooth rotation of RotatingCanvasComponents.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JLayeredPane
JLayeredPane.AccessibleJLayeredPane
 
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
 Object involvedInDrop
           
 
Fields inherited from class javax.swing.JLayeredPane
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER
 
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
DrawingPane()
          Creates a DrawingPane with a white background that is initially 640 pixels wide and 480 pixels high.
DrawingPane(Color background, int width, int height)
          Creates a DrawingPane with the given title, background color, and size.
DrawingPane(int width, int height)
          Creates a DrawingPane with the given width and height
 
Method Summary
 boolean acceptDrop(Object dropped)
          You should override this method in supclass to get drag/drop to work with your shapes.
 Component add(Component c)
          Puts the given Component on the DrawingPane using the Component's preferred size.
 Component add(Component c, int x, int y)
          Puts the given Component on the DrawingPane using the Component's preferred size at the given x,y location.
 void addDragListener()
          Allows this DrawingPane to listen for Drag & Drop
 void addKeyboardListener()
          Allows this DrawingPane to Listen for Arrow Keys Note: Only one object will listen for key strokes at a time to obtain the focus for this object, you need to call the object's getFocus() method.
 void addMouseListener()
          Allows this DrawingPane to listen for Mouse Events.
 void dragDropEnd(DragSourceDropEvent dsde)
          You should not need to use this method
 void dragEnter(DragSourceDragEvent dsde)
          You should not need to use this method
 void dragExit(DragSourceEvent dse)
          You should not need to use this method
 void dragOver(DragSourceDragEvent dsde)
          You should not need to use this method
 void dropActionChanged(DragSourceDragEvent dsde)
          You should not need to use this method
 int getHeight()
          Returns the Height of the DrawingPane
 Object getTransferData(DataFlavor flavor)
          You should not need to use this method
 DataFlavor[] getTransferDataFlavors()
          You should not need to use this method
 int getWidth()
          Returns the Width of the DrawingPane
 boolean isDataFlavorSupported(DataFlavor flavor)
          You should not need to use this method
 Object manufactureDroppable()
          You should override this method in subclass to get drag/drop to work with your DrawingPane.
 void moveTo(double x, double y)
          Moves the pane to the given coordinates in its container.
 void moveToBack(Component c)
          Moves the given Component behind of all other Components.
 void moveToFront(Component c)
          Moves the given Component on top of all other Components.
 boolean okToDrag()
          Called on DragComponent to see if it can be Dragged.
 void redraw()
          Calls Component.repaint() in a thread-safe way.
 void remove(Component c)
          Takes the given Component off the DrawingPane.
 void removeDragListener()
          Removes this DrawingPane's ability to listen for Drag & Drop
 void removeKeyboardListener()
          Removes this DrawingPane's ability to Listen for Arrow Keys
 void removeMouseListener()
          Removes DrawingPane's ability to listen for Mouse Events.
 void resetBorder()
          You should not need to use this method
 void resizeTo(double width, double height)
          Resizes the pane to the given dimensions.
 void setColor(Color color)
          Sets the Color of the DrawingPane, Note: you need to call setOpaque(true) to make it visible.
 void setFeedbackText(String text)
          If this DrawingPane is contained in a ViewFrame, then this method will set the ViewFrame's Feedback Label to be the given text
 void setLayer(Component c, int layer)
          Changes the layer of a component.
 void setListener(canvas.DefaultListener newListener)
          Will set the listener from the default to your subclass of a DefaultListener so you can obtain function from the listeners
 void setOpaque(boolean opaque)
          Sets whether the DrawingPane is visible or not.
 void sleep(int milliseconds)
          Creates a time delay of approximately the given length.
 void smoothMove(Component c, double newX, double newY, int milliseconds)
          Moves the given component to the given x,y position in a straight-line smooth motion animation lasting approximately the given length of time.
 void smoothMove(double x, double y, int milliseconds)
          Smoothly moves this component to the given coordinates over the time interval given.
 void smoothResize(canvas.CanvasComponent c, double newWidth, double newHeight, int milliseconds)
          Resizes the given component to the given size lasting approximately the the given length of time.
 void smoothResize(double width, double height, int milliseconds)
          Smoothly resizes this component to the given dimensions over the time interval given.
 void smoothRotate(Component c, double degree, int milliseconds)
          Rotates the given component to the given degree in a smooth motion lasting approximately the given length of time.
 void smoothRotateAbout(canvas.RotatingCanvasComponent c, double degree, double x, double y, int milliseconds)
          Rotates the given component to the given degree about the specified point in a smooth motion lasting approximately the given length of time.
 String toString()
          Returns a string of the format "DrawingPane size:(x,y)"
 
Methods inherited from class javax.swing.JLayeredPane
addImpl, getAccessibleContext, getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, paint, paramString, putLayer, remove, setLayer, setPosition
 
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, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, addContainerListener, 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, 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.DragComponent
setBorder
 

Field Detail

involvedInDrop

public Object involvedInDrop
Constructor Detail

DrawingPane

public DrawingPane()
Creates a DrawingPane with a white background that is initially 640 pixels wide and 480 pixels high.


DrawingPane

public DrawingPane(int width,
                   int height)
Creates a DrawingPane with the given width and height

Parameters:
width - the width of the DrawingPane
height - the height of the DrawingPane

DrawingPane

public DrawingPane(Color background,
                   int width,
                   int height)
Creates a DrawingPane with the given title, background color, and size.

Parameters:
background - a value of type 'Color'
width - a value of type 'int'
height - a value of type 'int'
Method Detail

moveTo

public void moveTo(double x,
                   double y)
Moves the pane to the given coordinates in its container. Parameters are rounded to the nearest integer.

Specified by:
moveTo in interface CanvasComponent

resizeTo

public void resizeTo(double width,
                     double height)
Resizes the pane to the given dimensions. Parameters are rounded to the nearest integer.

Specified by:
resizeTo in interface CanvasComponent

redraw

public void redraw()
Description copied from interface: CanvasComponent
Calls Component.repaint() in a thread-safe way. The component is re-drawn on the screen. This is especially useful for PictureComponent objects.

Specified by:
redraw in interface CanvasComponent

smoothResize

public void smoothResize(double width,
                         double height,
                         int milliseconds)
Description copied from interface: CanvasComponent
Smoothly resizes this component to the given dimensions over the time interval given.

Specified by:
smoothResize in interface CanvasComponent

smoothMove

public void smoothMove(double x,
                       double y,
                       int milliseconds)
Description copied from interface: CanvasComponent
Smoothly moves this component to the given coordinates over the time interval given.

Specified by:
smoothMove in interface CanvasComponent

setColor

public void setColor(Color color)
Sets the Color of the DrawingPane, Note: you need to call setOpaque(true) to make it visible.


getWidth

public int getWidth()
Returns the Width of the DrawingPane

Specified by:
getWidth in interface CanvasComponent
Overrides:
getWidth in class JComponent

getHeight

public int getHeight()
Returns the Height of the DrawingPane

Specified by:
getHeight in interface CanvasComponent
Overrides:
getHeight in class JComponent

add

public Component add(Component c)
Puts the given Component on the DrawingPane using the Component's preferred size. The location of the component is not set.

Overrides:
add in class Container
Parameters:
c - the Component to be added
Returns:
the given Component is returned for convenience

add

public Component add(Component c,
                     int x,
                     int y)
Puts the given Component on the DrawingPane using the Component's preferred size at the given x,y location.

Parameters:
c - the Component to be added
x - the x position for the upper left corner of the Component
y - the y position for the upper left corner of the Component

remove

public void remove(Component c)
Takes the given Component off the DrawingPane.

Overrides:
remove in class Container
Parameters:
c - the Component to be removed

moveToFront

public void moveToFront(Component c)
Moves the given Component on top of all other Components.

Overrides:
moveToFront in class JLayeredPane
Parameters:
c - the Component to be moved to the front

setLayer

public void setLayer(Component c,
                     int layer)
Changes the layer of a component.

Overrides:
setLayer in class JLayeredPane
Parameters:
c - the Component
layer - the new layer for the Component

moveToBack

public void moveToBack(Component c)
Moves the given Component behind of all other Components.

Overrides:
moveToBack in class JLayeredPane
Parameters:
c - the Component to be moved to the back

setOpaque

public void setOpaque(boolean opaque)
Sets whether the DrawingPane is visible or not. A visible DrawingPane looks a lot like a solid Rect.

Overrides:
setOpaque in class JComponent
Parameters:
opaque - true will set the DrawingPane to be visible, false will set it invisible

smoothMove

public void smoothMove(Component c,
                       double newX,
                       double newY,
                       int milliseconds)
Moves the given component to the given x,y position in a straight-line smooth motion animation lasting approximately the given length of time. This method can also be called through the shapeComponent.

Parameters:
c - the component to be moved
newX - the destination x coordinate
newY - the destination y coordinate
milliseconds - the desired length of time for the animation

smoothRotate

public void smoothRotate(Component c,
                         double degree,
                         int milliseconds)
Rotates the given component to the given degree in a smooth motion lasting approximately the given length of time. This method can also be called through the shapeComponent.

Parameters:
c - the component to be moved
degree - the number of degrees to rotate
milliseconds - the desired length of time for the animation

smoothRotateAbout

public void smoothRotateAbout(canvas.RotatingCanvasComponent c,
                              double degree,
                              double x,
                              double y,
                              int milliseconds)
Rotates the given component to the given degree about the specified point in a smooth motion lasting approximately the given length of time. This method can also be called through the CanvasComponent.

Parameters:
c - the component to rotate
degree - the number of degrees to rotate
x - The x coordinate of the point to rotate about
y - the y coordinate of the point to rotate about
milliseconds - the desired length of time for the animation

smoothResize

public void smoothResize(canvas.CanvasComponent c,
                         double newWidth,
                         double newHeight,
                         int milliseconds)
Resizes the given component to the given size lasting approximately the the given length of time. This method can also be called through the CanvasComponent

Parameters:
c - the component to be resized
newWidth - the width the component will be resized to
newHeight - the height the component will be resized to
milliseconds - the desired length of time for the animation

setFeedbackText

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

Specified by:
setFeedbackText in interface CanvasComponent

sleep

public void sleep(int milliseconds)
Creates a time delay of approximately the given length.

Parameters:
milliseconds - the desired length of the delay, in milliseconds

toString

public String toString()
Returns a string of the format "DrawingPane size:(x,y)"

Overrides:
toString in class Component

manufactureDroppable

public Object manufactureDroppable()
You should override this method in subclass to get drag/drop to work with your DrawingPane.

Specified by:
manufactureDroppable in interface DragComponent

acceptDrop

public boolean acceptDrop(Object dropped)
You should override this method in supclass to get drag/drop to work with your shapes.

Specified by:
acceptDrop in interface DragComponent

okToDrag

public boolean okToDrag()
Called on DragComponent to see if it can be Dragged.

Specified by:
okToDrag in interface DragComponent

addMouseListener

public void addMouseListener()
Allows this DrawingPane to listen for Mouse Events.


removeMouseListener

public void removeMouseListener()
Removes DrawingPane's ability to listen for Mouse Events.


addDragListener

public void addDragListener()
Allows this DrawingPane to listen for Drag & Drop


removeDragListener

public void removeDragListener()
Removes this DrawingPane's ability to listen for Drag & Drop


addKeyboardListener

public void addKeyboardListener()
Allows this DrawingPane to Listen for Arrow Keys Note: Only one object will listen for key strokes at a time to obtain the focus for this object, you need to call the object's getFocus() method.


removeKeyboardListener

public void removeKeyboardListener()
Removes this DrawingPane's ability to Listen for Arrow Keys


setListener

public void setListener(canvas.DefaultListener newListener)
Will set the listener from the default to your subclass of a DefaultListener so you can obtain function from the listeners


getTransferData

public Object getTransferData(DataFlavor flavor)
You should not need to use this method

Specified by:
getTransferData in interface Transferable

getTransferDataFlavors

public DataFlavor[] getTransferDataFlavors()
You should not need to use this method

Specified by:
getTransferDataFlavors in interface Transferable

isDataFlavorSupported

public boolean isDataFlavorSupported(DataFlavor flavor)
You should not need to use this method

Specified by:
isDataFlavorSupported in interface Transferable

dragDropEnd

public void dragDropEnd(DragSourceDropEvent dsde)
You should not need to use this method

Specified by:
dragDropEnd in interface DragSourceListener

dragEnter

public void dragEnter(DragSourceDragEvent dsde)
You should not need to use this method

Specified by:
dragEnter in interface DragSourceListener

dragExit

public void dragExit(DragSourceEvent dse)
You should not need to use this method

Specified by:
dragExit in interface DragSourceListener

dragOver

public void dragOver(DragSourceDragEvent dsde)
You should not need to use this method

Specified by:
dragOver in interface DragSourceListener

dropActionChanged

public void dropActionChanged(DragSourceDragEvent dsde)
You should not need to use this method

Specified by:
dropActionChanged in interface DragSourceListener

resetBorder

public void resetBorder()
You should not need to use this method

Specified by:
resetBorder in interface DragComponent