diva.canvas.toolbox
Class PathFigure

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

public class PathFigure
extends AbstractFigure
implements ShapedFigure

A PathFigure 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 open shapes (without fill). For filled shapes, use the BasicFigure class, and for more complex figures, use VectorFigure or create a custom Figure class.

Version:
$Revision: 1.9 $
Author:
John Reekie, Peter Draper (p.w.draper@durham.ac.uk)

Constructor Summary
PathFigure(Shape shape)
          Create a new figure with the given shape.
PathFigure(Shape shape, float lineWidth)
          Create a new figure with the given shape and width.
PathFigure(Shape shape, Paint paint, float lineWidth)
          Create a new figure with the given paint and width.
 
Method Summary
 Rectangle2D getBounds()
          Get the bounding box of this figure.
 Composite getComposite()
          Get the compositing operator
 float[] getDashArray()
          Get the dash array.
 float getLineWidth()
          Get the line width of this figure.
 Shape getShape()
          Get the shape of this figure.
 Stroke getStroke()
          Get the stroke of this figure.
 Paint getStrokePaint()
          Get the stroke paint of this figure.
 boolean hit(Rectangle2D r)
          Test if this figure intersects the given rectangle.
 void paint(Graphics2D g)
          Paint the figure.
 void setComposite(AlphaComposite c)
          Set the compositing operation for this figure.
 void setDashArray(float[] dashArray)
          Set the dash array of the stroke.
 void setLineWidth(float lineWidth)
          Set the line width.
 void setShape(Shape s)
          Set the shape of this figure.
 void setStroke(BasicStroke s)
          Set the stroke of this figure.
 void setStrokePaint(Paint p)
          Set the stroke paint of this figure.
 void transform(AffineTransform at)
          Transform the figure with the supplied transform.
 void translate(double x, double y)
          Translate the figure with by the given distance.
 
Methods inherited from class diva.canvas.AbstractFigure
contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getTransformContext, getUserObject, intersects, isVisible, paint, repaint, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible
 
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, getOrigin, getParent, getToolTipText, intersects, setInteractor, setParent, setToolTipText
 
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
 

Constructor Detail

PathFigure

public PathFigure(Shape shape)
Create a new figure with the given shape. The figure, by default, is stroked with a unit-width continuous black stroke.


PathFigure

public PathFigure(Shape shape,
                  float lineWidth)
Create a new figure with the given shape and width. The default paint is black.


PathFigure

public PathFigure(Shape shape,
                  Paint paint,
                  float lineWidth)
Create a new figure with the given paint and width.

Method Detail

getBounds

public Rectangle2D getBounds()
Get the bounding box of this figure. This method overrides the inherited method to take account of the thickness of the stroke.

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

getDashArray

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


getLineWidth

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


getShape

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

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

getStroke

public Stroke getStroke()
Get the stroke of this figure.


getStrokePaint

public Paint getStrokePaint()
Get the stroke paint of this figure.


getComposite

public Composite getComposite()
Get the compositing operator


hit

public boolean hit(Rectangle2D r)
Test if this figure intersects the given rectangle. If the figure is not visible, always return false.

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

paint

public void paint(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

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.


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.


setShape

public void setShape(Shape s)
Set the shape of this figure.

Specified by:
setShape in interface ShapedFigure

setStroke

public void setStroke(BasicStroke s)
Set the stroke of this figure.


setStrokePaint

public void setStrokePaint(Paint p)
Set the stroke paint of this figure.


setComposite

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


transform

public void transform(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

translate

public void translate(double x,
                      double y)
Translate the figure with by the given distance. 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:
translate in interface Figure
Overrides:
translate in class AbstractFigure


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.