edu.umd.cs.piccolo
Class PCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by edu.umd.cs.piccolo.PCanvas
All Implemented Interfaces:
PComponent, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
PCacheCanvas, PSwingCanvas

public class PCanvas
extends javax.swing.JComponent
implements PComponent

PCanvas is a simple Swing component that can be used to embed Piccolo into a Java Swing application. Canvases view the Piccolo scene graph through a camera. The canvas manages screen updates coming from this camera, and forwards swing mouse and keyboard events to the camera.

Version:
1.0
Author:
Jesse Grosjean
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static PCanvas CURRENT_ZCANVAS
           
static java.lang.String INTERATING_CHANGED_NOTIFICATION
           
 
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
PCanvas()
          Construct a canvas with the basic scene graph consisting of a root, camera, and layer.
 
Method Summary
 void addInputEventListener(PInputEventListener listener)
          Add an input listener to the camera associated with this canvas.
protected  PCamera createDefaultCamera()
           
 javax.swing.Timer createTimer(int delay, java.awt.event.ActionListener listener)
           
 boolean getAnimating()
          Return true if any activities that respond with true to the method isAnimating were run in the last PRoot.processInputs() loop.
 PCamera getCamera()
          Return the camera associated with this canvas.
 boolean getInteracting()
          Return true if this canvas has been marked as interacting.
 PLayer getLayer()
          Return layer for this canvas.
 PPanEventHandler getPanEventHandler()
          Get the pan event handler associated with this canvas.
 PRoot getRoot()
          Return root for this canvas.
 PZoomEventHandler getZoomEventHandler()
          Get the zoom event handler associated with this canvas.
protected  void installInputSources()
          This method installs mouse and key listeners on the canvas that forward those events to piccolo.
 void paintComponent(java.awt.Graphics g)
           
 void paintImmediately()
           
 void popCursor()
          Pop the cursor on top of the cursorStack and set it as the canvas cursor.
 void pushCursor(java.awt.Cursor cursor)
          Set the canvas cursor, and remember the previous cursor on the cursor stack.
 void removeInputEventListener(PInputEventListener listener)
          Remove an input listener to the camera associated with this canvas.
protected  void removeInputSources()
          This method removes mouse and key listeners on the canvas that forward those events to piccolo.
 void repaint(PBounds bounds)
           
protected  void sendInputEventToInputManager(java.awt.event.InputEvent e, int type)
           
 void setAnimatingRenderQuality(int requestedQuality)
          Set the render quality that should be used when rendering this canvas when it is animating.
 void setBounds(int x, int y, int w, int h)
           
 void setCamera(PCamera newCamera)
          Set the camera associated with this canvas.
 void setDefaultRenderQuality(int requestedQuality)
          Set the render quality that should be used when rendering this canvas when it is not interacting or animating.
 void setEnabled(boolean enabled)
          Overrride setEnabled to install/remove canvas input sources as needed.
 void setInteracting(boolean isInteracting)
          Set if this canvas is interacting.
 void setInteractingRenderQuality(int requestedQuality)
          Set the render quality that should be used when rendering this canvas when it is interacting.
 void setPanEventHandler(PPanEventHandler handler)
          Set the pan event handler associated with this canvas.
 void setZoomEventHandler(PZoomEventHandler handler)
          Set the zoom event handler associated with this canvas.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, 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, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INTERATING_CHANGED_NOTIFICATION

public static final java.lang.String INTERATING_CHANGED_NOTIFICATION
See Also:
Constant Field Values

CURRENT_ZCANVAS

public static PCanvas CURRENT_ZCANVAS
Constructor Detail

PCanvas

public PCanvas()
Construct a canvas with the basic scene graph consisting of a root, camera, and layer. Event handlers for zooming and panning are automatically installed.

Method Detail

createDefaultCamera

protected PCamera createDefaultCamera()

getPanEventHandler

public PPanEventHandler getPanEventHandler()
Get the pan event handler associated with this canvas. This event handler is set up to get events from the camera associated with this canvas by default.


setPanEventHandler

public void setPanEventHandler(PPanEventHandler handler)
Set the pan event handler associated with this canvas.

Parameters:
handler - the new zoom event handler

getZoomEventHandler

public PZoomEventHandler getZoomEventHandler()
Get the zoom event handler associated with this canvas. This event handler is set up to get events from the camera associated with this canvas by default.


setZoomEventHandler

public void setZoomEventHandler(PZoomEventHandler handler)
Set the zoom event handler associated with this canvas.

Parameters:
handler - the new zoom event handler

getCamera

public PCamera getCamera()
Return the camera associated with this canvas. All input events from this canvas go through this camera. And this is the camera that paints this canvas.


setCamera

public void setCamera(PCamera newCamera)
Set the camera associated with this canvas. All input events from this canvas go through this camera. And this is the camera that paints this canvas.


getRoot

public PRoot getRoot()
Return root for this canvas.


getLayer

public PLayer getLayer()
Return layer for this canvas.


addInputEventListener

public void addInputEventListener(PInputEventListener listener)
Add an input listener to the camera associated with this canvas.


removeInputEventListener

public void removeInputEventListener(PInputEventListener listener)
Remove an input listener to the camera associated with this canvas.


getInteracting

public boolean getInteracting()
Return true if this canvas has been marked as interacting. If so the canvas will normally render at a lower quality that is faster.


getAnimating

public boolean getAnimating()
Return true if any activities that respond with true to the method isAnimating were run in the last PRoot.processInputs() loop. This values is used by this canvas to determine the render quality to use for the next paint.


setInteracting

public void setInteracting(boolean isInteracting)
Set if this canvas is interacting. If so the canvas will normally render at a lower quality that is faster. Also repaints the canvas if the render quality should change.

Specified by:
setInteracting in interface PComponent

setDefaultRenderQuality

public void setDefaultRenderQuality(int requestedQuality)
Set the render quality that should be used when rendering this canvas when it is not interacting or animating. The default value is PPaintContext. HIGH_QUALITY_RENDERING.

Parameters:
requestedQuality - supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING

setAnimatingRenderQuality

public void setAnimatingRenderQuality(int requestedQuality)
Set the render quality that should be used when rendering this canvas when it is animating. The default value is PPaintContext.LOW_QUALITY_RENDERING.

Parameters:
requestedQuality - supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING

setInteractingRenderQuality

public void setInteractingRenderQuality(int requestedQuality)
Set the render quality that should be used when rendering this canvas when it is interacting. The default value is PPaintContext.LOW_QUALITY_RENDERING.

Parameters:
requestedQuality - supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING

pushCursor

public void pushCursor(java.awt.Cursor cursor)
Set the canvas cursor, and remember the previous cursor on the cursor stack.

Specified by:
pushCursor in interface PComponent

popCursor

public void popCursor()
Pop the cursor on top of the cursorStack and set it as the canvas cursor.

Specified by:
popCursor in interface PComponent

setEnabled

public void setEnabled(boolean enabled)
Overrride setEnabled to install/remove canvas input sources as needed.

Overrides:
setEnabled in class javax.swing.JComponent

installInputSources

protected void installInputSources()
This method installs mouse and key listeners on the canvas that forward those events to piccolo.


removeInputSources

protected void removeInputSources()
This method removes mouse and key listeners on the canvas that forward those events to piccolo.


sendInputEventToInputManager

protected void sendInputEventToInputManager(java.awt.event.InputEvent e,
                                            int type)

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Overrides:
setBounds in class java.awt.Component

repaint

public void repaint(PBounds bounds)
Specified by:
repaint in interface PComponent

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

paintImmediately

public void paintImmediately()
Specified by:
paintImmediately in interface PComponent

createTimer

public javax.swing.Timer createTimer(int delay,
                                     java.awt.event.ActionListener listener)


Copyright © 2008 by University of Maryland, College Park, MD 20742, USA All rights reserved.