edu.umd.cs.piccolox.pswing
Class PSwing

java.lang.Object
  extended by edu.umd.cs.piccolo.PNode
      extended by edu.umd.cs.piccolox.pswing.PSwing
All Implemented Interfaces:
java.awt.print.Printable, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener

public class PSwing
extends PNode
implements java.io.Serializable, java.beans.PropertyChangeListener

PSwing is used to add Swing Components to a Piccolo canvas.

Example: adding a swing JButton to a PCanvas:

     PSwingCanvas canvas = new PSwingCanvas();
     JButton button = new JButton("Button");
     swing = new PSwing(canvas, button);
     canvas.getLayer().addChild(swing);
 
 

NOTE: PSwing has the current limitation that it does not listen for Container events. This is only an issue if you create a PSwing and later add Swing components to the PSwing's component hierarchy that do not have double buffering turned off or have a smaller font size than the minimum font size of the original PSwing's component hierarchy.

For instance, the following bit of code will give unexpected results:

            JPanel panel = new JPanel();
            PSwing swing = new PSwing(panel);
            JPanel newChild = new JPanel();
            newChild.setDoubleBuffered(true);
            panel.add(newChild);
       

NOTE: PSwing cannot be correctly interacted with through multiple cameras. There is no support for it yet.

NOTE: PSwing is java.io.Serializable.

Warning: Serialized objects of this class will not be compatible with future Piccolo releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Piccolo. A future release of Piccolo will provide support for long term persistence.

Author:
Sam R. Reid, Benjamin B. Bederson, Lance E. Good 3-23-2007 edited to automatically detect PCamera/PSwingCanvas to allow single-arg constructor usage
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.umd.cs.piccolo.PNode
PNode.PSceneGraphDelegate
 
Field Summary
static java.lang.String PSWING_PROPERTY
          Used as a hashtable key for this object in the Swing component's client properties.
 
Fields inherited from class edu.umd.cs.piccolo.PNode
PROPERTY_BOUNDS, PROPERTY_CHILDREN, PROPERTY_CHILDREN_PICKABLE, PROPERTY_CLIENT_PROPERTIES, PROPERTY_CODE_BOUNDS, PROPERTY_CODE_CHILDREN, PROPERTY_CODE_CHILDREN_PICKABLE, PROPERTY_CODE_CLIENT_PROPERTIES, PROPERTY_CODE_FULL_BOUNDS, PROPERTY_CODE_PAINT, PROPERTY_CODE_PARENT, PROPERTY_CODE_PICKABLE, PROPERTY_CODE_TRANSFORM, PROPERTY_CODE_TRANSPARENCY, PROPERTY_CODE_VISIBLE, PROPERTY_FULL_BOUNDS, PROPERTY_PAINT, PROPERTY_PARENT, PROPERTY_PICKABLE, PROPERTY_TRANSFORM, PROPERTY_TRANSPARENCY, PROPERTY_VISIBLE, SCENE_GRAPH_DELEGATE
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Constructor Summary
PSwing(javax.swing.JComponent component)
          Constructs a new visual component wrapper for the Swing component.
PSwing(PSwingCanvas pSwingCanvas, javax.swing.JComponent component)
          Deprecated.  
 
Method Summary
 void computeBounds()
          Sets the Swing component's bounds to its preferred bounds unless it already is set to its preferred size.
 javax.swing.JComponent getComponent()
          Returns the Swing component that this visual component wraps
 void paint(java.awt.Graphics2D g2)
          Renders to a buffered image, then draws that image to the drawing surface associated with g2 (usually the screen).
 void paint(PPaintContext renderContext)
          Determines if the Swing component should be rendered normally or as a filled rectangle.
 void paintAsGreek(java.awt.Graphics2D g2)
          Paints the Swing component as greek.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Listens for changes in font on components rooted at this PSwing
 void removeFromSwingWrapper()
          Remove from the SwingWrapper; throws an exception if no canvas is associated with this PSwing.
 void repaint(PBounds repaintBounds)
          Repaints the specified portion of this visual component Note that the input parameter may be modified as a result of this call.
protected  boolean shouldRenderGreek(PPaintContext renderContext)
           
 
Methods inherited from class edu.umd.cs.piccolo.PNode
addActivity, addAttribute, addChild, addChild, addChildren, addClientProperty, addInputEventListener, addPropertyChangeListener, addPropertyChangeListener, animateToBounds, animateToColor, animateToPositionScaleRotation, animateToTransform, animateToTransparency, animateTransformToBounds, centerBoundsOnPoint, centerFullBoundsOnPoint, clone, computeFullBounds, endResizeBounds, findIntersectingNodes, fireChildPropertyChange, firePropertyChange, fullIntersects, fullPaint, fullPick, getAllNodes, getAllNodes, getAttribute, getAttribute, getBooleanAttribute, getBounds, getBoundsChanged, getBoundsReference, getBoundsVolatile, getChild, getChildBoundsInvalid, getChildBoundsVolatile, getChildPaintInvalid, getChildrenCount, getChildrenIterator, getChildrenPickable, getChildrenReference, getClientProperties, getClientProperty, getClientPropertyKeysEnumeration, getClientPropertyKeysIterator, getDoubleAttribute, getFullBounds, getFullBoundsInvalid, getFullBoundsReference, getGlobalBounds, getGlobalFullBounds, getGlobalRotation, getGlobalScale, getGlobalToLocalTransform, getGlobalTranslation, getHeight, getIntegerAttribute, getInverseTransform, getListenerList, getLocalToGlobalTransform, getOccluded, getOffset, getPaint, getPaintInvalid, getParent, getPickable, getPropertyChangeParentMask, getRoot, getRotation, getScale, getTransform, getTransformReference, getTransparency, getUnionOfChildrenBounds, getVisible, getWidth, getX, getXOffset, getY, getYOffset, globalToLocal, globalToLocal, globalToLocal, indexOfChild, internalUpdateBounds, intersects, invalidateFullBounds, invalidateLayout, invalidatePaint, isAncestorOf, isDescendentOf, isDescendentOfRoot, isOpaque, layoutChildren, lerp, localToGlobal, localToGlobal, localToGlobal, localToParent, localToParent, localToParent, moveInBackOf, moveInFrontOf, moveToBack, moveToFront, offset, paintAfterChildren, paramString, parentBoundsChanged, parentToLocal, parentToLocal, parentToLocal, pick, pickAfterChildren, position, print, print, removeAllChildren, removeChild, removeChild, removeChildren, removeFromParent, removeInputEventListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaintFrom, reparent, replaceWith, resetBounds, rotate, rotateAboutPoint, rotateAboutPoint, rotateInPlace, scale, scaleAboutPoint, scaleAboutPoint, setBounds, setBounds, setBoundsChanged, setChildBoundsInvalid, setChildBoundsVolatile, setChildPaintInvalid, setChildrenPickable, setFullBoundsInvalid, setGlobalRotation, setGlobalScale, setGlobalTranslation, setHeight, setOccluded, setOffset, setOffset, setPaint, setPaintInvalid, setParent, setPickable, setPropertyChangeParentMask, setRotation, setScale, setTransform, setTransparency, setVisible, setWidth, setX, setY, signalBoundsChanged, startResizeBounds, toImage, toImage, toImage, toString, transformBy, translate, validateFullBounds, validateFullPaint
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PSWING_PROPERTY

public static final java.lang.String PSWING_PROPERTY
Used as a hashtable key for this object in the Swing component's client properties.

See Also:
Constant Field Values
Constructor Detail

PSwing

public PSwing(javax.swing.JComponent component)
Constructs a new visual component wrapper for the Swing component.

Parameters:
component - The swing component to be wrapped

PSwing

public PSwing(PSwingCanvas pSwingCanvas,
              javax.swing.JComponent component)
Deprecated. 

Deprecated constructor for application code still depending on this signature.

Parameters:
pSwingCanvas -
component -
Method Detail

paint

public void paint(PPaintContext renderContext)
Determines if the Swing component should be rendered normally or as a filled rectangle.

The transform, clip, and composite will be set appropriately when this object is rendered. It is up to this object to restore the transform, clip, and composite of the Graphics2D if this node changes any of them. However, the color, font, and stroke are unspecified by Piccolo. This object should set those things if they are used, but they do not need to be restored.

Overrides:
paint in class PNode
Parameters:
renderContext - Contains information about current render.

shouldRenderGreek

protected boolean shouldRenderGreek(PPaintContext renderContext)

paintAsGreek

public void paintAsGreek(java.awt.Graphics2D g2)
Paints the Swing component as greek.

Parameters:
g2 - The graphics used to render the filled rectangle

removeFromSwingWrapper

public void removeFromSwingWrapper()
Remove from the SwingWrapper; throws an exception if no canvas is associated with this PSwing.


paint

public void paint(java.awt.Graphics2D g2)
Renders to a buffered image, then draws that image to the drawing surface associated with g2 (usually the screen).

Parameters:
g2 - graphics context for rendering the JComponent

repaint

public void repaint(PBounds repaintBounds)
Repaints the specified portion of this visual component Note that the input parameter may be modified as a result of this call.

Parameters:
repaintBounds -

computeBounds

public void computeBounds()
Sets the Swing component's bounds to its preferred bounds unless it already is set to its preferred size. Also updates the visual components copy of these bounds


getComponent

public javax.swing.JComponent getComponent()
Returns the Swing component that this visual component wraps

Returns:
The Swing component that this visual component wraps

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Listens for changes in font on components rooted at this PSwing

Specified by:
propertyChange in interface java.beans.PropertyChangeListener


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