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

PCanvas is a simple Swing component that can be used to embed Piccolo into a Java Swing application. Canvas's 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
           
 
Fields inherited from class org.eclipse.swt.widgets.Control
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()
           
 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 no double buffering
 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(org.eclipse.swt.graphics.GC gc, int x, int y, int w, int h)
           
 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.
 void repaint()
           
 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.
 void setDoubleBuffered(boolean dBuffered)
          Set whether this canvas should use double buffering - the default is no double buffering
 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.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
checkSubclass, computeSize, getChildren, getLayout, getTabList, layout, layout, setFocus, setLayout, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBorderWidth, getBounds, getDisplay, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isDisposed, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBounds, setCapture, setCursor, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getStyle, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, 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
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.

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.


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.


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.


createBasicSceneGraph

public PCamera createBasicSceneGraph()

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.

Specified by:
setInteracting in interface PComponent

getDoubleBuffered

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


setDoubleBuffered

public void setDoubleBuffered(boolean dBuffered)
Set whether this canvas should use double buffering - the default is no double buffering


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 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

installInputSources

protected void installInputSources()
This method installs 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 org.eclipse.swt.widgets.Control

repaint

public void repaint()

repaint

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

paintComponent

public void paintComponent(org.eclipse.swt.graphics.GC gc,
                           int x,
                           int y,
                           int w,
                           int h)

paintImmediately

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


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

Web Accessibility