Package edu.umd.cs.piccolo
Class PCanvas
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
edu.umd.cs.piccolo.PCanvas
- All Implemented Interfaces:
PComponent,ImageObserver,MenuContainer,Serializable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic PCanvasDeprecated.since it falsely assumes that there is only one PCanvas per programstatic final StringDeprecated.in favor of PROPERTY_INTERACTINGstatic final StringDeprecated.this is a typo and clients should change their code to reflect the correct spellingstatic final StringThe property name that identifies a change in the interacting state.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionPCanvas()Construct a canvas with the basic scene graph consisting of a root, camera, and layer. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInputEventListener(PInputEventListener listener) Add an input listener to the camera associated with this canvas.protected PCameraCreates and returns a basic Scene Graph.createTimer(int delay, ActionListener listener) Helper for creating a timer.booleanReturn true if any activities that respond with true to the method isAnimating were run in the last PRoot.processInputs() loop.intReturns the quality to use when animating.Return the camera associated with this canvas.intDeprecated.in favor or getNormalRenderQualityReturns the input event listeners registered to receive input events.booleanReturn true if this canvas has been marked as interacting, or whether it's root is interacting.intReturns the quality to use when interacting.getLayer()Return layer for this canvas.intReturns the quality to use when not animating or interacting.Get the pan event handler associated with this canvas.getRoot()Return root for this canvas.Get the zoom event handler associated with this canvas.protected voidThis method installs mouse and key listeners on the canvas that forward those events to piccolo.voidvoidIf not painting immediately, send paint notification to RepaintManager, otherwise does nothing.voidPop the cursor on top of the cursorStack and set it as the canvas cursor.voidPrints the entire scene regardless of what the viewable area is.voidpushCursor(Cursor cursor) Set the canvas cursor, and remember the previous cursor on the cursor stack.voidremoveInputEventListener(PInputEventListener listener) Remove an input listener to the camera associated with this canvas.protected voidThis method removes mouse and key listeners on the canvas that forward those events to piccolo.voidCalled to notify PComponent that given bounds need repainting.protected voidsendInputEventToInputManager(InputEvent event, int type) Sends the given input event with the given type to the current InputManager.voidsetAnimatingRenderQuality(int animatingRenderQuality) Set the render quality that should be used when rendering this canvas when it is animating.voidsetBounds(int x, int y, int width, int height) Updates the bounds of the component and updates the camera accordingly.voidSet the camera associated with this canvas.voidsetDefaultRenderQuality(int defaultRenderQuality) Set the render quality that should be used when rendering this canvas when it is not interacting or animating.voidsetEnabled(boolean enabled) Override setEnabled to install/remove canvas input sources as needed.voidsetInteracting(boolean isInteracting) Set if this canvas is interacting.voidsetInteractingRenderQuality(int interactingRenderQuality) Set the render quality that should be used when rendering this canvas when it is interacting.voidsetPanEventHandler(PPanEventHandler handler) Set the pan event handler associated with this canvas.voidsetZoomEventHandler(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, 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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, 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, updateUIMethods 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, transferFocusDownCycle, validate, validateTreeMethods 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, getAccessibleContext, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
INTERATING_CHANGED_NOTIFICATION
Deprecated.this is a typo and clients should change their code to reflect the correct spelling- See Also:
-
INTERACTING_CHANGED_NOTIFICATION
Deprecated.in favor of PROPERTY_INTERACTINGThe property name that identifies a change in the interacting state.- Since:
- 1.3
- See Also:
-
PROPERTY_INTERACTING
The property name that identifies a change in the interacting state.- Since:
- 1.3
- See Also:
-
CURRENT_ZCANVAS
Deprecated.since it falsely assumes that there is only one PCanvas per programUsed as a public global to track the current canvas.
-
-
Constructor Details
-
PCanvas
public PCanvas()Construct a canvas with the basic scene graph consisting of a root, camera, and layer. Zooming and panning are automatically installed.
-
-
Method Details
-
createDefaultCamera
Creates and returns a basic Scene Graph.- Returns:
- a built PCamera scene
-
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.- Returns:
- the current pan event handler, may be null
-
setPanEventHandler
Set the pan event handler associated with this canvas.- Parameters:
handler- the new zoom event handler
-
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.- Returns:
- the current zoom event handler, may be null
-
setZoomEventHandler
Set the zoom event handler associated with this canvas.- Parameters:
handler- the new zoom event handler
-
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.- Returns:
- camera through which this PCanvas views the scene
-
setCamera
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.- Parameters:
newCamera- the camera which this PCanvas should view the scene
-
getRoot
Return root for this canvas.- Returns:
- the root PNode at the "bottom" of the scene
-
getLayer
Return layer for this canvas.- Returns:
- the first layer attached to this camera
-
addInputEventListener
Add an input listener to the camera associated with this canvas.- Parameters:
listener- listener to register for event notifications
-
removeInputEventListener
Remove an input listener to the camera associated with this canvas.- Parameters:
listener- listener to unregister from event notifications
-
getInteracting
public boolean getInteracting()Return true if this canvas has been marked as interacting, or whether it's root is interacting. If so the canvas will normally render at a lower quality that is faster.- Returns:
- whether the canvas has been flagged as being interacted with
-
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.- Returns:
- whether the PCanvas is currently being animated
-
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:
setInteractingin interfacePComponent- Parameters:
isInteracting- whether the PCanvas should be considered interacting
-
setDefaultRenderQuality
public void setDefaultRenderQuality(int defaultRenderQuality) 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:
defaultRenderQuality- supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
-
setAnimatingRenderQuality
public void setAnimatingRenderQuality(int animatingRenderQuality) 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:
animatingRenderQuality- supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
-
setInteractingRenderQuality
public void setInteractingRenderQuality(int interactingRenderQuality) 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:
interactingRenderQuality- supports PPaintContext.HIGH_QUALITY_RENDERING or PPaintContext.LOW_QUALITY_RENDERING
-
pushCursor
Set the canvas cursor, and remember the previous cursor on the cursor stack.- Specified by:
pushCursorin interfacePComponent- Parameters:
cursor- the cursor to push onto the cursor stack
-
popCursor
public void popCursor()Pop the cursor on top of the cursorStack and set it as the canvas cursor.- Specified by:
popCursorin interfacePComponent
-
setEnabled
public void setEnabled(boolean enabled) Override setEnabled to install/remove canvas input sources as needed.- Overrides:
setEnabledin classJComponent- Parameters:
enabled- new enable status of the Pcanvas
-
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
Sends the given input event with the given type to the current InputManager.- Parameters:
event- event to dispatchtype- type of event being dispatched
-
setBounds
public void setBounds(int x, int y, int width, int height) Updates the bounds of the component and updates the camera accordingly. -
repaint
Called to notify PComponent that given bounds need repainting.- Specified by:
repaintin interfacePComponent- Parameters:
bounds- bounds needing repaint
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
paintImmediately
public void paintImmediately()If not painting immediately, send paint notification to RepaintManager, otherwise does nothing.- Specified by:
paintImmediatelyin interfacePComponent
-
createTimer
Helper for creating a timer. It's an extension point for subclasses to install their own timers.- Parameters:
delay- the number of milliseconds to wait before invoking the listenerlistener- the listener to invoke after the delay- Returns:
- the created Timer
-
getDefaultRenderQuality
public int getDefaultRenderQuality()Deprecated.in favor or getNormalRenderQualityReturns the quality to use when not animating or interacting.- Returns:
- the render quality to use when not animating or interacting
- Since:
- 1.3
-
getNormalRenderQuality
public int getNormalRenderQuality()Returns the quality to use when not animating or interacting.- Returns:
- the render quality to use when not animating or interacting
- Since:
- 1.3
-
getAnimatingRenderQuality
public int getAnimatingRenderQuality()Returns the quality to use when animating.- Returns:
- Returns the quality to use when animating
- Since:
- 1.3
-
getInteractingRenderQuality
public int getInteractingRenderQuality()Returns the quality to use when interacting.- Returns:
- Returns the quality to use when interacting
- Since:
- 1.3
-
getInputEventListeners
Returns the input event listeners registered to receive input events.- Returns:
- array or input event listeners
- Since:
- 1.3
-
printAll
Prints the entire scene regardless of what the viewable area is.- Overrides:
printAllin classJComponent- Parameters:
graphics- Graphics context onto which to paint the scene for printing
-