Package diva.canvas.tutorial
Class TransformedFigureTutorial.CloudFigure
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- diva.canvas.tutorial.TransformedFigureTutorial.CloudFigure
-
- All Implemented Interfaces:
CanvasComponent
,Figure
,VisibleComponent
,UserObjectContainer
- Enclosing class:
- TransformedFigureTutorial
public static class TransformedFigureTutorial.CloudFigure extends AbstractFigure
CloudFigure is a class that paints itself as a translucent "cloud." This example figure class illustrates the use of different paints and strokes to create the required image, and the use of TransformContext to position that image.
-
-
Constructor Summary
Constructors Constructor Description CloudFigure(double x, double y, double width, double height)
Create a new instance of this figure.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.geom.Rectangle2D
getBounds()
Get the bounds of this figure.java.awt.Shape
getShape()
Get the shape of this figure.TransformContext
getTransformContext()
Get the transform context.void
paint(java.awt.Graphics2D g)
Paint this figure onto the given graphics context.void
transform(java.awt.geom.AffineTransform at)
Transform the object.-
Methods inherited from class diva.canvas.AbstractFigure
contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getUserObject, hit, intersects, isVisible, paint, repaint, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible, translate
-
-
-
-
Constructor Detail
-
CloudFigure
public CloudFigure(double x, double y, double width, double height)
Create a new instance of this figure. The cloud is initially created at coordinates (0,0) and then transformed to the requested coordinates. To create the cloud shape, use the Area class in Java2D, which implements constructive area geometry, and join a bunch of circles into a single shape.
-
-
Method Detail
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Get the bounds of this figure. Because this figure has its own transform, we need to transform the internal bounds into the enclosing context. To make this more efficient, we use a previously-cached copy of the transformed bounds if there is one.- Specified by:
getBounds
in interfaceFigure
- Overrides:
getBounds
in classAbstractFigure
- Returns:
- the bounding box of this figure.
-
getShape
public java.awt.Shape getShape()
Get the shape of this figure. Because this figure has its own transform, we need to transform the internal shape into the enclosing context. To make this more efficient, we use a previously-cached copy of the transformed shape if there is one.- Specified by:
getShape
in interfaceFigure
- Specified by:
getShape
in classAbstractFigure
- Returns:
- the outline shape of this figure
-
getTransformContext
public TransformContext getTransformContext()
Get the transform context. This method must be overridden since this figure defined its own context.- Specified by:
getTransformContext
in interfaceCanvasComponent
- Overrides:
getTransformContext
in classAbstractFigure
- Returns:
- The transform context of this component.
-
paint
public void paint(java.awt.Graphics2D g)
Paint this figure onto the given graphics context. First we "push" the transform context onto the transform stack, so that the graphics port has the correct transform. Then we paint the cloud a translucent magenta (yum!), and then we make a couple of little clouds and paint them opaque. (The way this is done in this example is horrendously inefficient.) Finally, we "pop" the transform context off the stack.- Specified by:
paint
in interfaceVisibleComponent
- Specified by:
paint
in classAbstractFigure
- Parameters:
g
- The 2D graphics object that this object it to be painted upon.
-
transform
public void transform(java.awt.geom.AffineTransform at)
Transform the object. In this example, we pre-concatenate the given transform with the transform in the transform context. When the figure is repainted, it will be redrawn in the right place. We also must be sure to invalidate the cached geometry objects that depend on the transform.- Specified by:
transform
in interfaceFigure
- Specified by:
transform
in classAbstractFigure
- Parameters:
at
- The transform to be used.
-
-