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 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
- See Also:
- Serialized Form
Field Summary |
static java.awt.Font |
DEFAULT_FONT
Default font, 12 point "SansSerif" . |
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 |
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()
Return the Swing component that this Swing node wraps. |
double |
getGreekThreshold()
Return the greek threshold in scale. |
(package private) void |
init(java.awt.Component c)
We need to turn off double buffering of Swing components within Piccolo
since all components contained within a native container use the same
buffer for double buffering. |
protected void |
paint(PPaintContext paintContext)
|
protected void |
paintComponent(PPaintContext paintContext)
Paint the Swing component with the specified paint context. |
protected void |
paintGreek(PPaintContext paintContext)
Paint the Swing component as greek with the specified paint context. |
void |
propertyChange(java.beans.PropertyChangeEvent evt)
|
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. |
(package private) void |
reshape()
Ensures the bounds of the underlying component are accurate, and sets the
bounds of this PNode. |
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. |
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
DEFAULT_FONT
public static final java.awt.Font DEFAULT_FONT
- Default font, 12 point
"SansSerif"
. Will be made final in
version 2.0.
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)
reshape
void reshape()
- Ensures the bounds of the underlying component are accurate, and sets the
bounds of this PNode.
paint
protected void paint(PPaintContext paintContext)
-
- Overrides:
paint
in class PNode
getGreekThreshold
public double getGreekThreshold()
- Return the greek threshold in 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 in scale
- See Also:
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:
paintGreek(PPaintContext)
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
paintGreek
protected void paintGreek(PPaintContext paintContext)
- Paint the Swing component as greek with the specified paint context. The
implementation in this class paints a rectangle with the Swing
component's background color and paints a stroke with the Swing
component's foreground color.
- Parameters:
paintContext
- paint context
removeFromSwingWrapper
public void removeFromSwingWrapper()
- Remove from the SwingWrapper; throws an exception if no canvas is
associated with this PSwing.
paintComponent
protected void paintComponent(PPaintContext paintContext)
- Paint the Swing component with the specified paint context.
- Parameters:
paintContext
- paint context
setVisible
public void setVisible(boolean visible)
-
- Overrides:
setVisible
in class PNode
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()
- Return the Swing component that this Swing node wraps.
- Returns:
- the Swing component that this Swing node wraps
init
void init(java.awt.Component c)
- We need to turn off double buffering of Swing components within Piccolo
since all components contained within a native container use the same
buffer for double buffering. With normal Swing widgets this is fine, but
for Swing components within Piccolo this causes problems. This function
recurses the component tree rooted at c, and turns off any double
buffering in use. It also updates the minimum font size based on the font
size of c and adds a property change listener to listen for changes to
the font.
- Parameters:
c
- The Component to be recursively unDoubleBuffered
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
-
- Specified by:
propertyChange
in interface java.beans.PropertyChangeListener
Copyright © 1995-2009 Piccolo2D. All Rights Reserved.