diva.canvas.toolbox
Class BasicFigure

java.lang.Object
  extended by diva.canvas.AbstractFigure
      extended by diva.canvas.toolbox.BasicFigure
All Implemented Interfaces:
CanvasComponent, Figure, ShapedFigure, VisibleComponent, UserObjectContainer
Direct Known Subclasses:
BasicEllipse, BasicRectangle, PathFigure, RoundedRectangle

public class BasicFigure
extends AbstractFigure
implements ShapedFigure

A BasicFigure is one that contains a single instance of Shape. The figure can have a fill with optional compositing (for translucency), and a stroke with a different fill. With this class, simple objects can be created on-the-fly simply by passing an instance of java.awt.Shape to the constructor. This class is mainly intended for use for simple open and closed shapes. For more complex Figures, use the VectorFigure class.

Version:
$Id: BasicFigure.java 41477 2006-03-29 00:03:58Z cxh $
Author:
John Reekie, Nick Zamora

Field Summary
private  boolean _centered
          Indicator of whether this figure should be centered on its origin.
private  java.awt.Composite _composite
          The color compositing operator.
private  float[] _dashArray
          The dash array if setDashArray is called.
private  java.awt.Paint _fillPaint
          The paint for the fill.
private  float _lineWidth
          The width of the line.
private  java.awt.Shape _shape
          The shape of this figure.
private  java.awt.Stroke _stroke
          The stroke.
private  java.awt.Paint _strokePaint
          The stroke paint.
private  java.awt.geom.AffineTransform _transform
          The transform.
 
Constructor Summary
BasicFigure(java.awt.Shape shape)
          Create a new figure with the given shape.
BasicFigure(java.awt.Shape shape, float lineWidth)
          Create a new figure with the given shape and outline width.
BasicFigure(java.awt.Shape shape, int lineWidth)
          Deprecated. Use the float constructor instead.
BasicFigure(java.awt.Shape shape, java.awt.Paint fill)
          Create a new figure with the given paint pattern.
BasicFigure(java.awt.Shape shape, java.awt.Paint fill, float lineWidth)
          Create a new figure with the given paint pattern and line width.
 
Method Summary
 java.awt.geom.Rectangle2D getBounds()
          Get the bounding box of this figure.
 java.awt.Composite getComposite()
          Get the compositing operator
 float[] getDashArray()
          Get the dash array.
 java.awt.Paint getFillPaint()
          Get the fill paint
 float getLineWidth()
          Get the line width.
 java.awt.geom.Point2D getOrigin()
          Return the origin of the figure in the enclosing transform context.
 java.awt.Shape getShape()
          Get the shape of this figure.
 java.awt.Paint getStrokePaint()
          Get the paint used to stroke this figure
 boolean hit(java.awt.geom.Rectangle2D r)
          Test if this figure intersects the given rectangle.
 boolean isCentered()
          Return whether the figure should be centered on its origin.
 void paint(java.awt.Graphics2D g)
          Paint the figure.
 void setCentered(boolean centered)
          Specify whether the figure should be centered on its origin.
 void setComposite(java.awt.AlphaComposite c)
          Set the compositing operation for this figure.
 void setDashArray(float[] dashArray)
          Set the dash array of the stroke.
 void setFillPaint(java.awt.Paint p)
          Set the fill paint.
 void setLineWidth(float lineWidth)
          Set the line width.
 void setPrototypeShape(java.awt.Shape s)
          Change the shape of the figure without modifying its other properties, such as its position.
 void setShape(java.awt.Shape s)
          Set the shape of this figure.
 void setStroke(java.awt.Stroke s)
          Set the stroke
 void setStrokePaint(java.awt.Paint p)
          Set the stroke paint
 void transform(java.awt.geom.AffineTransform at)
          Transform the figure with the supplied transform.
 
Methods inherited from class diva.canvas.AbstractFigure
contains, getInteractor, getLayer, getParent, getToolTipText, getTransformContext, getUserObject, intersects, isVisible, paint, repaint, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible, translate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface diva.canvas.Figure
contains, getInteractor, getLayer, getParent, getToolTipText, intersects, setInteractor, setParent, setToolTipText, translate
 
Methods inherited from interface diva.canvas.VisibleComponent
isVisible, paint, setVisible
 
Methods inherited from interface diva.canvas.CanvasComponent
getTransformContext, repaint, repaint
 
Methods inherited from interface diva.util.UserObjectContainer
getUserObject, setUserObject
 

Field Detail

_centered

private boolean _centered
Indicator of whether this figure should be centered on its origin. By default, this class is centered, like the superclass.


_dashArray

private float[] _dashArray
The dash array if setDashArray is called.


_composite

private java.awt.Composite _composite
The color compositing operator.


_lineWidth

private float _lineWidth
The width of the line.


_shape

private java.awt.Shape _shape
The shape of this figure.


_fillPaint

private java.awt.Paint _fillPaint
The paint for the fill.


_stroke

private java.awt.Stroke _stroke
The stroke.


_strokePaint

private java.awt.Paint _strokePaint
The stroke paint.


_transform

private java.awt.geom.AffineTransform _transform
The transform.

Constructor Detail

BasicFigure

public BasicFigure(java.awt.Shape shape)
Create a new figure with the given shape. The figure, by default, has a unit-width continuous black outline and no fill. The given shape will be cloned to prevent the original from being modified.


BasicFigure

public BasicFigure(java.awt.Shape shape,
                   int lineWidth)
Deprecated. Use the float constructor instead.

Create a new figure with the given shape and outline width. It has no fill. The default outline paint is black. The given shape will be cloned to prevent the original from being modified.


BasicFigure

public BasicFigure(java.awt.Shape shape,
                   float lineWidth)
Create a new figure with the given shape and outline width. It has no fill. The default outline paint is black. The given shape will be cloned to prevent the original from being modified.


BasicFigure

public BasicFigure(java.awt.Shape shape,
                   java.awt.Paint fill)
Create a new figure with the given paint pattern. The figure, by default, has no stroke. The given shape will be cloned to prevent the original from being modified.


BasicFigure

public BasicFigure(java.awt.Shape shape,
                   java.awt.Paint fill,
                   float lineWidth)
Create a new figure with the given paint pattern and line width. The given shape will be cloned to prevent the original from being modified.

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 interface Figure
Overrides:
getBounds in class AbstractFigure

getComposite

public java.awt.Composite getComposite()
Get the compositing operator


getDashArray

public float[] getDashArray()
Get the dash array. If the stroke is not a BasicStroke then null will always be returned.


getFillPaint

public java.awt.Paint getFillPaint()
Get the fill paint


getLineWidth

public float getLineWidth()
Get the line width. If the stroke is not a BasicStroke then 1.0 will always be returned.


getOrigin

public java.awt.geom.Point2D getOrigin()
Return the origin of the figure in the enclosing transform context. This overrides the base class to return the center of the shape, if the figure is centered, or the origin of the shape if the figure is not centered.

Specified by:
getOrigin in interface Figure
Overrides:
getOrigin in class AbstractFigure
Returns:
The origin of the figure.
See Also:
AbstractFigure.getBounds()

getShape

public java.awt.Shape getShape()
Get the shape of this figure.

Specified by:
getShape in interface Figure
Specified by:
getShape in class AbstractFigure

getStrokePaint

public java.awt.Paint getStrokePaint()
Get the paint used to stroke this figure


hit

public boolean hit(java.awt.geom.Rectangle2D r)
Test if this figure intersects the given rectangle. If there is a fill but no outline, then there is a hit if the shape is intersected. If there is an outline but no fill, then the area covered by the outline stroke is tested. If there is both a fill and a stroke, the region bounded by the outside edge of the stroke is tested. If there is neither a fill nor a stroke, then return false. If the figure is not visible, always return false.

Specified by:
hit in interface Figure
Overrides:
hit in class AbstractFigure

isCentered

public boolean isCentered()
Return whether the figure should be centered on its origin.

Returns:
False If the origin of the figure, as returned by getOrigin(), is the upper left corner.
See Also:
getOrigin(), setCentered(boolean)

paint

public void paint(java.awt.Graphics2D g)
Paint the figure. The figure is redrawn with the current shape, fill, and outline.

Specified by:
paint in interface VisibleComponent
Specified by:
paint in class AbstractFigure

setCentered

public void setCentered(boolean centered)
Specify whether the figure should be centered on its origin. By default, it is.

Parameters:
centered - False to make the origin of the figure, as returned by getOrigin(), be the upper left corner.
See Also:
getOrigin()

setComposite

public void setComposite(java.awt.AlphaComposite c)
Set the compositing operation for this figure.


setDashArray

public void setDashArray(float[] dashArray)
Set the dash array of the stroke. The existing stroke will be removed, but the line width will be preserved if possible.


setFillPaint

public void setFillPaint(java.awt.Paint p)
Set the fill paint. If p is null then the figure will not be filled.


setLineWidth

public void setLineWidth(float lineWidth)
Set the line width. The existing stroke will be removed, but the dash array will be preserved if possible.


setPrototypeShape

public void setPrototypeShape(java.awt.Shape s)
Change the shape of the figure without modifying its other properties, such as its position. If you are writing client code that is modifying the appearance of the Figure after it is created, this is most likely the method you want to call, as opposed to setShape().


setShape

public void setShape(java.awt.Shape s)
Set the shape of this figure. Note that this method is primarily intended to be used by interactors that modify the figures shape (such as PathManipulator). In particular, the position of the figure is likely to move. In order to change the shape of the figure without moving the figure, use the setPrototypeShape() method instead.

Specified by:
setShape in interface ShapedFigure

setStrokePaint

public void setStrokePaint(java.awt.Paint p)
Set the stroke paint


setStroke

public void setStroke(java.awt.Stroke s)
Set the stroke


transform

public void transform(java.awt.geom.AffineTransform at)
Transform the figure with the supplied transform. This can be used to perform arbitrary translation, scaling, shearing, and rotation operations. As much as possible, this method attempts to preserve the type of the shape: if the shape of this figure is an of RectangularShape or Polyline, then the shape may be modified directly. Otherwise, a general transformation is used that loses the type of the shape, converting it into a GeneralPath.

Specified by:
transform in interface Figure
Specified by:
transform in class AbstractFigure