Package diva.canvas.toolbox
Class SwingWrapper
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- diva.canvas.toolbox.SwingWrapper
-
- All Implemented Interfaces:
CanvasComponent
,Figure
,VisibleComponent
,UserObjectContainer
public class SwingWrapper extends AbstractFigure
A figure that embeds swing components in canvas drawings.- Version:
- $Id$
- Author:
- Michael Shilman, John Reekie
-
-
Constructor Summary
Constructors Constructor Description SwingWrapper(javax.swing.JComponent c)
Construct a new swing wrapper instance to wrap the given component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.geom.Rectangle2D
getBounds()
Get the bounding box of this figure.javax.swing.JComponent
getComponent()
Return the component that this is wrapping.java.awt.Shape
getShape()
Get the shape of this figure.void
paint(java.awt.Graphics2D g)
Ask the wrapped component to paint itself.void
setComponent(javax.swing.JComponent c)
Replace the currently wrapped component with the given component and reshape/repaint the figure.void
setParent(CanvasComponent fc)
Set the parent of this figure.void
transform(java.awt.geom.AffineTransform at)
Transform the figure with the supplied transform.void
translate(double x, double y)
Translate the figure by the given distance.-
Methods inherited from class diva.canvas.AbstractFigure
contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getTransformContext, getUserObject, hit, intersects, isVisible, paint, repaint, repaint, setInteractor, setToolTipText, setUserObject, setVisible
-
-
-
-
Method Detail
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Get the bounding box of this figure. This method overrides the inherited method to take account of the thickness of the stroke, if there is one.- Specified by:
getBounds
in interfaceFigure
- Overrides:
getBounds
in classAbstractFigure
- Returns:
- the bounding box of this figure.
-
getComponent
public javax.swing.JComponent getComponent()
Return the component that this is wrapping.
-
getShape
public java.awt.Shape getShape()
Get the shape of this figure.- Specified by:
getShape
in interfaceFigure
- Specified by:
getShape
in classAbstractFigure
- Returns:
- the outline shape of this figure
-
paint
public void paint(java.awt.Graphics2D g)
Ask the wrapped component to paint itself.- Specified by:
paint
in interfaceVisibleComponent
- Specified by:
paint
in classAbstractFigure
- Parameters:
g
- The 2D graphics object that this object it to be painted upon.
-
setComponent
public void setComponent(javax.swing.JComponent c)
Replace the currently wrapped component with the given component and reshape/repaint the figure.
-
setParent
public void setParent(CanvasComponent fc)
Set the parent of this figure. This method overrides the inherited method to deal with the Swing component hierarchy.- Specified by:
setParent
in interfaceFigure
- Overrides:
setParent
in classAbstractFigure
- Parameters:
fc
- The parent of the figure.- See Also:
Figure.getParent()
-
transform
public void transform(java.awt.geom.AffineTransform at)
Transform the figure with the supplied transform. For now this throws an UnsupportedOperationException because it is unclear how we want to deal with transformations that are not shape-preserving, such as shears and rotations.- Specified by:
transform
in interfaceFigure
- Specified by:
transform
in classAbstractFigure
- Parameters:
at
- The transform to be used.
-
translate
public void translate(double x, double y)
Translate the figure by the given distance.- Specified by:
translate
in interfaceFigure
- Overrides:
translate
in classAbstractFigure
- Parameters:
x
- The x value to be moved.y
- The y value to be moved.
-
-