uk.ac.starlink.diva
Class DrawBasicFigure

java.lang.Object
  extended by diva.canvas.AbstractFigure
      extended by diva.canvas.toolbox.BasicFigure
          extended by uk.ac.starlink.diva.DrawBasicFigure
All Implemented Interfaces:
CanvasComponent, Figure, ShapedFigure, VisibleComponent, UserObjectContainer, DrawFigure
Direct Known Subclasses:
DrawEllipseFigure, DrawPolygonFigure, DrawRectangleFigure, XRangeFigure

public class DrawBasicFigure
extends BasicFigure
implements DrawFigure

DrawBasicFigure extends the diva BasicFigure class to add support for events that allow users of any derived figures to be made aware of any changes -- figure creation, removal and transformations.

All figures used on a Draw that is using DrawActions should be derived classes of this class, or implement the necessary code to support the DrawFigure interface. They should also invoke fireChanged in their translate and transform methods (but not if calling super) and respect the transformFreely state.

Version:
$Id$
Author:
Peter W. Draper
See Also:
Draw, DrawFigure

Field Summary
protected  EventListenerList listeners
           
protected static boolean transformFreely
          Hint that figures should ignore any transformation constraints.
 
Constructor Summary
DrawBasicFigure()
          Default constructor.
DrawBasicFigure(Shape shape)
          Create a new figure with the given shape.
DrawBasicFigure(Shape shape, float lineWidth)
          Create a new figure with the given shape and outline width.
DrawBasicFigure(Shape shape, Paint fill)
          Create a new figure with the given paint pattern.
DrawBasicFigure(Shape shape, Paint fill, float lineWidth)
          Create a new figure with the given paint pattern and outline width.
DrawBasicFigure(Shape shape, Paint fill, Paint outline, float lineWidth)
          Create a new figure with the given fill and outline paints and outline width.
 
Method Summary
 void addListener(FigureListener l)
          Registers a listener for to be informed when figure changes occur.
protected  void fireChanged()
          Send a FigureChangedEvent object specifying that this figure has changed.
protected  void fireCreated()
          Send a FigureChangedEvent object specifying that this figure has created to all listeners.
protected  void fireRemoved()
          Send a FigureChangedEvent object specifying that this figure has been removed.
static boolean isTransformFreely()
          Find out if this is an occasion when a figure should give up any constraints and traneform freely.
 void removeListener(FigureListener l)
          Remove a listener.
 void setTransformFreely(boolean state)
          Enable the hint that a figure should allow itself to transform freely, rather than obey any constraints (this is meant for figures that could not otherwise redraw themselves to fit a resized Draw, given their normal constraints, e.g.
 void setVisible(boolean flag)
          Set the visibility flag of this figure.
 void transform(AffineTransform at)
          Transform the figure.
 void translate(double x, double y)
          Translate the figure.
 
Methods inherited from class diva.canvas.toolbox.BasicFigure
getBounds, getComposite, getDashArray, getFillPaint, getLineWidth, getShape, getStrokePaint, hit, paint, setComposite, setDashArray, setFillPaint, setLineWidth, setShape, setStroke, setStrokePaint
 
Methods inherited from class diva.canvas.AbstractFigure
contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getTransformContext, getUserObject, intersects, isVisible, paint, repaint, repaint, setInteractor, setParent, setToolTipText, setUserObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface uk.ac.starlink.diva.DrawFigure
getComposite, getFillPaint, getLineWidth, getStrokePaint, setComposite, setFillPaint, setLineWidth, setShape, setStrokePaint
 
Methods inherited from interface diva.canvas.Figure
contains, getBounds, getInteractor, getLayer, getOrigin, getParent, getShape, getToolTipText, hit, intersects, setInteractor, setParent, setToolTipText
 
Methods inherited from interface diva.canvas.VisibleComponent
isVisible, paint, paint
 
Methods inherited from interface diva.canvas.CanvasComponent
getTransformContext, repaint, repaint
 
Methods inherited from interface diva.util.UserObjectContainer
getUserObject, setUserObject
 

Field Detail

transformFreely

protected static boolean transformFreely
Hint that figures should ignore any transformation constraints.


listeners

protected EventListenerList listeners
Constructor Detail

DrawBasicFigure

public DrawBasicFigure()
Default constructor.


DrawBasicFigure

public DrawBasicFigure(Shape shape)
Create a new figure with the given shape. The figure, by default, has a unit-width continuous black outline and no fill.


DrawBasicFigure

public DrawBasicFigure(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.


DrawBasicFigure

public DrawBasicFigure(Shape shape,
                       Paint fill)
Create a new figure with the given paint pattern. The figure, by default, has no stroke.


DrawBasicFigure

public DrawBasicFigure(Shape shape,
                       Paint fill,
                       Paint outline,
                       float lineWidth)
Create a new figure with the given fill and outline paints and outline width.


DrawBasicFigure

public DrawBasicFigure(Shape shape,
                       Paint fill,
                       float lineWidth)
Create a new figure with the given paint pattern and outline width. The default outline paint is black.

Method Detail

translate

public void translate(double x,
                      double y)
Translate the figure.

Specified by:
translate in interface Figure
Overrides:
translate in class BasicFigure

transform

public void transform(AffineTransform at)
Transform the figure.

Specified by:
transform in interface Figure
Overrides:
transform in class BasicFigure

setVisible

public void setVisible(boolean flag)
Description copied from class: AbstractFigure
Set the visibility flag of this figure. If the flag is false, then the figure will not be drawn on the screen and it will not respond to user input events.

Specified by:
setVisible in interface VisibleComponent
Specified by:
setVisible in interface DrawFigure
Overrides:
setVisible in class AbstractFigure

setTransformFreely

public void setTransformFreely(boolean state)
Enable the hint that a figure should allow itself to transform freely, rather than obey any constraints (this is meant for figures that could not otherwise redraw themselves to fit a resized Draw, given their normal constraints, e.g. XRangeFigure).

Specified by:
setTransformFreely in interface DrawFigure

isTransformFreely

public static boolean isTransformFreely()
Find out if this is an occasion when a figure should give up any constraints and traneform freely.


addListener

public void addListener(FigureListener l)
Registers a listener for to be informed when figure changes occur.

Specified by:
addListener in interface DrawFigure
Parameters:
l - the FigureListener

removeListener

public void removeListener(FigureListener l)
Remove a listener.

Specified by:
removeListener in interface DrawFigure
Parameters:
l - the FigureListener

fireCreated

protected void fireCreated()
Send a FigureChangedEvent object specifying that this figure has created to all listeners.


fireRemoved

protected void fireRemoved()
Send a FigureChangedEvent object specifying that this figure has been removed.


fireChanged

protected void fireChanged()
Send a FigureChangedEvent object specifying that this figure has changed.



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