public class PSwing extends PNode implements Serializable, PropertyChangeListener
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.
PNode.PSceneGraphDelegate
Modifier and Type | Field and Description |
---|---|
static String |
PSWING_PROPERTY
Key for this object in the Swing component's client properties.
|
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
NO_SUCH_PAGE, PAGE_EXISTS
Constructor and Description |
---|
PSwing(JComponent component)
Create a new visual component wrapper for the specified Swing component.
|
PSwing(PSwingCanvas swingCanvas,
JComponent component)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
JComponent |
getComponent()
Returns the Swing component that this visual component wraps.
|
double |
getGreekThreshold()
Return the Greek threshold scale.
|
boolean |
isUseBufferedPainting() |
void |
paint(Graphics2D g2)
Renders the wrapped component to the graphics context provided.
|
void |
paint(PPaintContext renderContext)
Paints the PSwing on the specified renderContext.
|
void |
paintAsGreek(Graphics2D g2)
Paints the Swing component as greek.
|
void |
propertyChange(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 |
setUseBufferedPainting(boolean useBufferedPainting)
If true
PSwing will paint the JComponent to a buffer with no graphics
transformations applied and then paint the buffer to the target transformed
graphics context. |
void |
setVisible(boolean visible)
Set the visibility of this node and its descendants.
|
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.
|
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
public static final String PSWING_PROPERTY
public PSwing(JComponent component)
component
- Swing component to be wrappedpublic PSwing(PSwingCanvas swingCanvas, JComponent component)
PSwing(JComponent)
swingCanvas
- canvas on which the PSwing node will be embeddedcomponent
- not usedpublic void setUseBufferedPainting(boolean useBufferedPainting)
PSwing
will paint the JComponent
to a buffer with no graphics
transformations applied and then paint the buffer to the target transformed
graphics context. On some platforms (such as Mac OS X) rendering JComponent
s to
a transformed context is slow. Enabling buffered painting gives a significant performance
boost on these platforms; however, at the expense of a lower-quality drawing result at larger
scales.useBufferedPainting
- true if this PSwing
should use buffered paintingpublic boolean isUseBufferedPainting()
public void updateBounds()
public void paint(PPaintContext renderContext)
protected boolean shouldRenderGreek(PPaintContext paintContext)
paintContext
- paint contextpublic void paintAsGreek(Graphics2D g2)
g2
- The graphics used to render the filled rectanglepublic void setVisible(boolean visible)
setVisible
in class PNode
visible
- true if this node and its descendants are visiblepublic void removeFromSwingWrapper()
public void paint(Graphics2D g2)
g2
- graphics context for rendering the JComponentpublic void repaint(PBounds repaintBounds)
repaintBounds
- bounds that need repaintingpublic JComponent getComponent()
public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener
evt
- property change event representing the change in fontpublic double getGreekThreshold()
DEFAULT_GREEK_THRESHOLD
.paintAsGreek(Graphics2D)
public void setGreekThreshold(double greekThreshold)
greekThreshold
. When the
scale will be below this threshold the Swing component is rendered as
'Greek' instead of painting the Swing component..greekThreshold
- Greek threshold in scalepaintAsGreek(Graphics2D)
Copyright © 1995-2013 Piccolo2D. All Rights Reserved.