edu.umd.cs.piccolox.pswing
Class PSwing
java.lang.Object
edu.umd.cs.piccolo.PNode
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 Piccolo2D 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
- See Also:
- Serialized Form
Field Summary |
static java.lang.String |
PSWING_PROPERTY
Key for this object in the Swing component's client properties. |
Fields inherited from class edu.umd.cs.piccolo.PNode |
FILL_STRATEGY_ASPECT_COVER, FILL_STRATEGY_ASPECT_FIT, FILL_STRATEGY_EXACT_FIT, 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)
Create a new visual component wrapper for the specified Swing component. |
PSwing(PSwingCanvas swingCanvas,
javax.swing.JComponent component)
Deprecated. by PSwing(JComponent) |
Method Summary |
javax.swing.JComponent |
getComponent()
Returns the Swing component that this visual component wraps. |
double |
getGreekThreshold()
Return the Greek threshold scale. |
void |
paint(java.awt.Graphics2D g2)
Renders the wrapped component to the graphics context provided. |
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. |
void |
setGreekThreshold(double greekThreshold)
Set the Greek threshold in scale to greekThreshold . |
void |
setVisible(boolean visible)
|
protected boolean |
shouldRenderGreek(PPaintContext paintContext)
Return true if this Swing node should render as greek given the specified
paint context. |
void |
updateBounds()
Ensures the bounds of the underlying component are accurate, and sets the
bounds of this PNode. |
Methods inherited from class edu.umd.cs.piccolo.PNode |
addActivity, addAttribute, addChild, addChild, addChildren, addClientProperty, addInputEventListener, addPropertyChangeListener, addPropertyChangeListener, animateToBounds, animateToColor, animateToPositionScaleRotation, animateToRelativePosition, 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, getInputEventListeners, getIntegerAttribute, getInverseTransform, getListenerList, getLocalToGlobalTransform, getName, 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, setName, setOccluded, setOffset, setOffset, setPaint, setPaintInvalid, setParent, setPickable, setPropertyChangeParentMask, setRotation, setScale, setTransform, setTransparency, setWidth, setX, setY, signalBoundsChanged, startResizeBounds, toImage, toImage, toImage, toImage, transformBy, translate, validateFullBounds, validateFullPaint |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PSWING_PROPERTY
public static final java.lang.String PSWING_PROPERTY
- Key for this object in the Swing component's client properties.
- See Also:
- Constant Field Values
PSwing
public PSwing(javax.swing.JComponent component)
- Create a new visual component wrapper for the specified Swing component.
- Parameters:
component
- Swing component to be wrapped
PSwing
public PSwing(PSwingCanvas swingCanvas,
javax.swing.JComponent component)
- Deprecated. by
PSwing(JComponent)
- Parameters:
swingCanvas
- canvas on which the PSwing node will be embeddedcomponent
- not used
updateBounds
public void updateBounds()
- Ensures the bounds of the underlying component are accurate, and sets the
bounds of this PNode.
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 paintContext)
- Return true if this Swing node should render as greek given the specified
paint context.
- Parameters:
paintContext
- paint context
- Returns:
- true if this Swing node should render as greek given the
specified paint context
paintAsGreek
public void paintAsGreek(java.awt.Graphics2D g2)
- Paints the Swing component as greek.
- Parameters:
g2
- The graphics used to render the filled rectangle
setVisible
public void setVisible(boolean visible)
-
- Overrides:
setVisible
in class PNode
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 the wrapped component to the graphics context provided.
- 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
- bounds that need repainting
getComponent
public javax.swing.JComponent getComponent()
- Returns the Swing component that this visual component wraps.
- Returns:
- The Swing component wrapped by this PSwing node
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
- Parameters:
evt
- property change event representing the change in font
getGreekThreshold
public double getGreekThreshold()
- Return the Greek threshold scale. When the scale will be below this
threshold the Swing component is rendered as 'Greek' instead of painting
the Swing component. Defaults to
DEFAULT_GREEK_THRESHOLD
.
- Returns:
- the current Greek threshold scale
- See Also:
PSwing#paintGreek(PPaintContext)
setGreekThreshold
public void setGreekThreshold(double greekThreshold)
- Set the Greek threshold in scale to
greekThreshold
. When the
scale will be below this threshold the Swing component is rendered as
'Greek' instead of painting the Swing component..
- Parameters:
greekThreshold
- Greek threshold in scale- See Also:
PSwing#paintGreek(PPaintContext)
Copyright © 1995-2010 Piccolo2D. All Rights Reserved.