edu.umd.cs.piccolox.swt
Class PSWTCanvas

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by edu.umd.cs.piccolox.swt.PSWTCanvas
All Implemented Interfaces:
PComponent, org.eclipse.swt.graphics.Drawable

public class PSWTCanvas
extends org.eclipse.swt.widgets.Composite
implements PComponent

PSWTCanvas is an SWT Composite that can be used to embed Piccolo into a SWT 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

Field Summary
static PSWTCanvas CURRENT_CANVAS
          Terrible Singleton instance of the PSWTCanvas.
 
Fields inherited from class org.eclipse.swt.widgets.Composite
embeddedHandle
 
Fields inherited from class org.eclipse.swt.widgets.Widget
handle
 
Constructor Summary
PSWTCanvas(org.eclipse.swt.widgets.Composite parent, int style)
          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.
 PCamera createBasicSceneGraph()
          Builds the basic scene graph associated with this canvas.
 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 getDoubleBuffered()
          Get whether this canvas should use double buffering - the default is to double buffer.
 boolean getInteracting()
          Return true if this canvas has been marked as interacting.
 PLayer getLayer()
          Helper method to return the first layer attached to the camera of 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 Piccolo2D.
 void paintComponent(org.eclipse.swt.graphics.GC gc, int x, int y, int w, int h)
          Paints the region specified of the canvas onto the given Graphics Context.
 void paintImmediately()
          Performs an immediate repaint if no other client is currently performing one.
 void popCursor()
          Pop the cursor on top of the cursorStack and set it as the canvas cursor.
 void pushCursor(java.awt.Cursor newCursor)
          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.
 void repaint()
          Exists to dispatch from the Swing's repaint method to SWT's redraw method.
 void repaint(PBounds bounds)
          Flags the bounds provided as needing to be redrawn.
protected  void sendInputEventToInputManager(java.awt.event.InputEvent awtEvent, int type)
          Dispatches the given event to the default input manager for the root of this canvas.
 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 newWidth, int newHeight)
          Changes the bounds of this PSWTCanvas.
 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.
 void setDoubleBuffered(boolean doubleBuffered)
          Set whether this canvas should use double buffering - the default is yes.
 void setInteracting(boolean isInteracting)
          Changes the number of callers that are interacting with the canvas.
 void setInteractingRenderQuality(int requestedQuality)
          Set the render quality that should be used when rendering this canvas when it is interacting.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, computeSize, drawBackground, getBackgroundMode, getChildren, getClientArea, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getBorderWidth, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getRegion, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setRegion, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CURRENT_CANVAS

public static PSWTCanvas CURRENT_CANVAS
Terrible Singleton instance of the PSWTCanvas. Falsely assumes you will only have one of these per application.

Constructor Detail

PSWTCanvas

public PSWTCanvas(org.eclipse.swt.widgets.Composite parent,
                  int style)
Construct a canvas with the basic scene graph consisting of a root, camera, and layer. Event handlers for zooming and panning are automatically installed.

Parameters:
parent - component onto which the canvas is installed
style - component style for the PSWTCanvas
Method Detail

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.

Returns:
the current pan event handler, which may be null

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.

Returns:
the event handler installed to handle zooming

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.

Returns:
the camera associated with 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.

Parameters:
newCamera - camera to attach to this canvas

getRoot

public PRoot getRoot()
Return root for this canvas.

Returns:
root of the scene this canvas is viewing through its camera

getLayer

public PLayer getLayer()
Helper method to return the first layer attached to the camera of this canvas. Short form of canvas.getCamera.getLayer(0)

Returns:
the first layer attached to the camera of this canvas

addInputEventListener

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

Parameters:
listener - listener to add to to the camera

removeInputEventListener

public void removeInputEventListener(PInputEventListener listener)
Remove an input listener to the camera associated with this canvas. Does nothign is the listener is not found.

Parameters:
listener - listener to remove from the set of event listeners attached to this canvas.

createBasicSceneGraph

public PCamera createBasicSceneGraph()
Builds the basic scene graph associated with this canvas. Developers may override this method to install their own layers, and cameras.

Returns:
PCamera viewing the freshly created scene

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.

Returns:
true if canvas is flagged as interacting

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:
true if there is an animating activity that is currently active

setInteracting

public void setInteracting(boolean isInteracting)
Changes the number of callers that are interacting with the canvas. Will allow the scene to be rendered in a lower quality if the number is not 0.

Specified by:
setInteracting in interface PComponent
Parameters:
isInteracting - state the client considers the PSWTCanvas to be in with regard to interacting

getDoubleBuffered

public boolean getDoubleBuffered()
Get whether this canvas should use double buffering - the default is to double buffer.

Returns:
true if double buffering is enabled

setDoubleBuffered

public void setDoubleBuffered(boolean doubleBuffered)
Set whether this canvas should use double buffering - the default is yes.

Parameters:
doubleBuffered - value of double buffering flas

setDefaultRenderQuality

public void setDefaultRenderQuality(int requestedQuality)
Set the render quality that should be used when rendering this canvas. 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 newCursor)
Set the canvas cursor, and remember the previous cursor on the cursor stack. Under the hood it is mapping the java.awt.Cursor to org.eclipse.swt.graphics.Cursor objects.

Specified by:
pushCursor in interface PComponent
Parameters:
newCursor - new 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:
popCursor in interface PComponent

installInputSources

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


sendInputEventToInputManager

protected void sendInputEventToInputManager(java.awt.event.InputEvent awtEvent,
                                            int type)
Dispatches the given event to the default input manager for the root of this canvas.

Parameters:
awtEvent - awt event needing dispatching
type - type of the event

setBounds

public void setBounds(int x,
                      int y,
                      int newWidth,
                      int newHeight)
Changes the bounds of this PSWTCanvas. Updating the camera and the double buffered image appropriately.

Overrides:
setBounds in class org.eclipse.swt.widgets.Control
Parameters:
x - left of the new bounds
y - top of the new bounds
newWidth - new width of the bounds
newHeight - new height of the bounds

repaint

public void repaint()
Exists to dispatch from the Swing's repaint method to SWT's redraw method.


repaint

public void repaint(PBounds bounds)
Flags the bounds provided as needing to be redrawn.

Specified by:
repaint in interface PComponent
Parameters:
bounds - the bounds that should be repainted

paintComponent

public void paintComponent(org.eclipse.swt.graphics.GC gc,
                           int x,
                           int y,
                           int w,
                           int h)
Paints the region specified of the canvas onto the given Graphics Context.

Parameters:
gc - graphics onto within painting should occur
x - left of the dirty region
y - top of the dirty region
w - width of the dirty region
h - height of the dirty region

paintImmediately

public void paintImmediately()
Performs an immediate repaint if no other client is currently performing one.

Specified by:
paintImmediately in interface PComponent


Copyright © 1995-2010 Piccolo2D. All Rights Reserved.