uk.ac.starlink.diva
Class DrawActions

java.lang.Object
  extended by uk.ac.starlink.diva.DrawActions
All Implemented Interfaces:
MouseListener, MouseMotionListener, EventListener, MouseInputListener

public class DrawActions
extends Object
implements MouseInputListener

This class defines a set of objects (created as AbstractActions) for drawing on a JCanvas that implements the Draw interface. These can be used for menu items or buttons in the user interface.

Version:
$Id$
Author:
Allan Brighton, Peter W. Draper

Nested Class Summary
protected  class DrawActions.CompositeAction
          Local class used to set the transparency for figures.
protected  class DrawActions.CurveAction
          Local class used to set the interpolated curve type.
protected  class DrawActions.DrawingModeAction
          Local class used to set the drawing mode.
protected  class DrawActions.FillAction
          Local class used to set the fill color for figures.
protected  class DrawActions.FontAction
          Local class used to set the label font.
protected  class DrawActions.GraphicsAction
          Local base class for creating menu/toolbar actions.
protected  class DrawActions.LineWidthAction
          Local class used to set the line width.
protected  class DrawActions.OutlineAction
          Local class used to set the outline color for figures.
 
Field Summary
protected  Draw canvas
          The target drawble canvas
protected  ChangeEvent changeEvent
          Event fired for changes
protected  AbstractAction clearAction
          Action to use to remove all figures.
static ArrayList colors
          Colors for color change actions
protected  AlphaComposite composite
          Current composite
static String[] COMPOSITE_NAMES
          Display names for Composites
protected  AbstractAction[] compositeActions
          Actions to use to set the composite
static AlphaComposite[] COMPOSITES
          Composites
protected  InterpolatedCurve2D curve
          Used while drawing an interpolated curve
static int CURVE
           
protected  AbstractAction[] curveActions
          Actions used to create a curve
protected  AbstractAction deleteSelectedAction
          Action to use to delete the selected figure.
protected  int drawingMode
          Current drawing mode
protected  ArrayList drawingModeActions
          Drawing mode actions
static int EDIT
          Mode to edit an object
protected  DrawLabelFigure editLabelFigure
          Figure to be modified during an edit
static int ELLIPSE
           
protected  Figure figure
          Current figure (during figure creation)
protected  DrawFigureFactory figureFactory
          The DrawFigureFactory
protected  LinkedList figureList
          List of figures created by this instance
protected  EventListenerList figureListenerList
          List of listeners for figure creation events
protected  Paint fill
          Current fill paint
protected  ArrayList fillActions
          Actions to use to set the fill color
protected  Font font
          Default font for text items
protected  ArrayList fontActions
          Actions for choosing a preset font
static ArrayList fonts
          Fixed fonts for font change actions
protected  Polyline2D.Double freehand
          Used while drawing freehand
static int FREEHAND
           
protected  DrawGraphicsPane graphics
          Object managing image graphics
protected  AbstractAction hideGraphicsAction
          Action to use to toggle the visibility of all figures.
protected  int interpolator
          Current curve interpolator.
protected  InterpolatorFactory interpolatorFactory
          The default InterpolatorFactory
protected  Line2D.Double line
          Used while drawing a line
static int LINE
           
static int[] LINE_WIDTHS
          Supported line widths
protected  int lineWidth
          Current line width
protected  AbstractAction[] lineWidthActions
          Actions to use to set the line width
protected  EventListenerList listenerList
          List of listeners for change events
protected  AbstractAction lowerSelectedAction
          Action to lower selected Figures
protected  boolean mouseClicked
          True if mouse was clicked
static int NUM_COMPOSITES
          The number of composites defined above
static int NUM_DRAWING_MODES
          The number of "drawing mode", that's type of Figures plus selection modes.
static int NUM_LINE_WIDTHS
          Number of Supported line widths
protected  Paint outline
          Current outline paint
protected  ArrayList outlineActions
          Actions to use to set the outline color
protected  Polygon2D.Double polygon
          Used while drawing a polygon
static int POLYGON
           
protected  Polyline2D.Double polyline
          Used while drawing a polyline
static int POLYLINE
           
protected  AbstractAction raiseSelectedAction
          Action to raise selected Figures
static int RECTANGLE
           
protected  AbstractAction saveRestoreAction
          Action to save or restore the figures
static int SELECT
          Mode to select an object
protected  int startX
          Starting point of drag
protected  int startY
          Starting point of drag
protected  FigureStore store
          FigureStore instance
static int TEXT
           
protected  boolean visible
          Used to toggle the visibility of all figures
static int XRANGE
           
 
Constructor Summary
DrawActions(Draw canvas, FigureStore store)
          Create an instance for use with a specified Draw
DrawActions(Draw canvas, FigureStore store, InterpolatorFactory factory)
          Create an instance for use with a specified Draw and InterpolatorFactory.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Register to receive change events from this object whenever the drawing settings are changed.
 void addColor(Color color)
          Add a new color.
 void addDrawFigure(DrawFigure figure)
          Add a DrawFigure created to the managed list.
 void addFigureListener(FigureListener l)
          Register to receive figure change events from this object whenever a figure has been created.
 void addFont(Font font)
          Add a new font.
 void clear()
          Remove all figures created by this instance.
 DrawFigure createDrawFigure(int type, FigureProps props)
          Create a DrawFigure using preset properties.
 void deleteFigure(DrawFigure figure)
          Delete a given figure, if displayed.
 void deleteSelected()
          Delete the selected figures.
protected  void finishFigure()
          Finish off the current figure and select it.
protected  void fireChange()
          Notify any listeners of a change.
protected  void fireFigureEvent(DrawFigure figure, int type)
          Notify any figure listeners of a figure created event.
 int fontCount()
          Return the number of fonts
 Action getClearAction()
           
 Color getColor(int i)
          Get a Color by index.
 int getColorCount()
          Return the number of colours.
 AlphaComposite getComposite()
          Return the current composite composite for drawing.
 AbstractAction getCompositeAction(int i)
          Return the action for the given composite composite.
 int getCurve()
          Return the current curve type.
 AbstractAction getCurveAction(int i)
          Return the action for a given curve interpolation type.
 Action getDeleteSelectedAction()
           
 Draw getDraw()
          Return the Draw instance.
 int getDrawingMode()
          Return the current drawing mode.
 AbstractAction getDrawingModeAction(int drawingMode)
          Return the action for the given mode.
 FigureStore getFigureStore()
          Get the FigureStore.
 Paint getFill()
          Return the current fill color for drawing.
 AbstractAction getFillAction(int i)
          Return the action for the given fill color.
 Font getFont()
          Return the current font color for drawing.
 Font getFont(int i)
          Return a given font.
 AbstractAction getFontAction(int i)
          Return the action for the given font.
 Action getHideAction()
           
 InterpolatorFactory getInterpolatorFactory()
          Get the InterpolatorFactory.
 int getLineWidth()
          Return the current line width for drawing.
 AbstractAction getLineWidthAction(int i)
          Return the action for the given line width
 ListIterator getListIterator(boolean forward)
          Return a ListIterator over the figures.
 Action getLowerSelectedAction()
           
 Paint getOutline()
          Return the current outline color for drawing.
 AbstractAction getOutlineAction(int i)
          Return the action for the given outline color
 Action getRaiseSelectedAction()
           
static TypedDecorator getTypedDecorator()
          Create and return a TypedDecorator suitable for manipulating the various types of figures in natural ways.
 void hideGraphics()
          Toggle the visibility all figures created by this instance.
 void lowerFigure(DrawFigure figure)
          Lower the given figure.
 void lowerSelected()
          Lower the selected figures.
 Interpolator makeInterpolator()
          Make an instance of the current interpolator.
 void mouseClicked(MouseEvent e)
           
 void mouseDragged(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mouseMoved(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void raiseFigure(DrawFigure figure)
          Raise the given figure.
 void raiseSelected()
          Raise the selected figures.
 void removeChangeListener(ChangeListener l)
          Stop receiving change events from this object.
 void removeFigureListener(FigureListener l)
          Stop receiving figure change events from this object.
protected  void saveRestore()
          Interact with the object for saving and restoring figures from an XML store of some kind.
 void setComposite(AlphaComposite composite)
          Set the composite (transparency).
 void setCurve(int interpolator)
          Set the interpolated curve type.
 void setDrawingMode(int drawingMode)
          Set the drawing mode.
 void setFigureStore(FigureStore store)
          Set the FigureStore.
 void setFill(Paint fill)
          Set the fill color.
 void setFont(Font font)
          Set the font to use for labels.
 void setInterpolatorFactory(InterpolatorFactory factory)
          Set the InterpolatorFactory.
 void setLineWidth(int lineWidth)
          Set the line width.
 void setOutline(Paint outline)
          Set the outline color.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canvas

protected Draw canvas
The target drawble canvas


graphics

protected DrawGraphicsPane graphics
Object managing image graphics


listenerList

protected EventListenerList listenerList
List of listeners for change events


changeEvent

protected ChangeEvent changeEvent
Event fired for changes


figureListenerList

protected EventListenerList figureListenerList
List of listeners for figure creation events


mouseClicked

protected boolean mouseClicked
True if mouse was clicked


startX

protected int startX
Starting point of drag


startY

protected int startY
Starting point of drag


polyline

protected Polyline2D.Double polyline
Used while drawing a polyline


polygon

protected Polygon2D.Double polygon
Used while drawing a polygon


freehand

protected Polyline2D.Double freehand
Used while drawing freehand


curve

protected InterpolatedCurve2D curve
Used while drawing an interpolated curve


line

protected Line2D.Double line
Used while drawing a line


figure

protected Figure figure
Current figure (during figure creation)


figureList

protected LinkedList figureList
List of figures created by this instance


SELECT

public static final int SELECT
Mode to select an object

See Also:
Constant Field Values

EDIT

public static final int EDIT
Mode to edit an object

See Also:
Constant Field Values

LINE

public static final int LINE
See Also:
Constant Field Values

RECTANGLE

public static final int RECTANGLE
See Also:
Constant Field Values

ELLIPSE

public static final int ELLIPSE
See Also:
Constant Field Values

POLYLINE

public static final int POLYLINE
See Also:
Constant Field Values

POLYGON

public static final int POLYGON
See Also:
Constant Field Values

FREEHAND

public static final int FREEHAND
See Also:
Constant Field Values

TEXT

public static final int TEXT
See Also:
Constant Field Values

CURVE

public static final int CURVE
See Also:
Constant Field Values

XRANGE

public static final int XRANGE
See Also:
Constant Field Values

NUM_DRAWING_MODES

public static final int NUM_DRAWING_MODES
The number of "drawing mode", that's type of Figures plus selection modes.


drawingModeActions

protected ArrayList drawingModeActions
Drawing mode actions


drawingMode

protected int drawingMode
Current drawing mode


visible

protected boolean visible
Used to toggle the visibility of all figures


colors

public static ArrayList colors
Colors for color change actions


fill

protected Paint fill
Current fill paint


outline

protected Paint outline
Current outline paint


outlineActions

protected ArrayList outlineActions
Actions to use to set the outline color


fillActions

protected ArrayList fillActions
Actions to use to set the fill color


COMPOSITES

public static final AlphaComposite[] COMPOSITES
Composites


COMPOSITE_NAMES

public static final String[] COMPOSITE_NAMES
Display names for Composites


NUM_COMPOSITES

public static final int NUM_COMPOSITES
The number of composites defined above


compositeActions

protected AbstractAction[] compositeActions
Actions to use to set the composite


composite

protected AlphaComposite composite
Current composite


fonts

public static ArrayList fonts
Fixed fonts for font change actions


fontActions

protected ArrayList fontActions
Actions for choosing a preset font


font

protected Font font
Default font for text items


editLabelFigure

protected DrawLabelFigure editLabelFigure
Figure to be modified during an edit


LINE_WIDTHS

public static final int[] LINE_WIDTHS
Supported line widths


NUM_LINE_WIDTHS

public static final int NUM_LINE_WIDTHS
Number of Supported line widths


lineWidth

protected int lineWidth
Current line width


lineWidthActions

protected AbstractAction[] lineWidthActions
Actions to use to set the line width


interpolatorFactory

protected InterpolatorFactory interpolatorFactory
The default InterpolatorFactory


curveActions

protected AbstractAction[] curveActions
Actions used to create a curve


interpolator

protected int interpolator
Current curve interpolator.


figureFactory

protected DrawFigureFactory figureFactory
The DrawFigureFactory


store

protected FigureStore store
FigureStore instance


deleteSelectedAction

protected AbstractAction deleteSelectedAction
Action to use to delete the selected figure.


clearAction

protected AbstractAction clearAction
Action to use to remove all figures.


hideGraphicsAction

protected AbstractAction hideGraphicsAction
Action to use to toggle the visibility of all figures.


raiseSelectedAction

protected AbstractAction raiseSelectedAction
Action to raise selected Figures


lowerSelectedAction

protected AbstractAction lowerSelectedAction
Action to lower selected Figures


saveRestoreAction

protected AbstractAction saveRestoreAction
Action to save or restore the figures

Constructor Detail

DrawActions

public DrawActions(Draw canvas,
                   FigureStore store)
Create an instance for use with a specified Draw

Parameters:
canvas - on which graphics will be drawn.
store - used to save and restore graphics, null for none.

DrawActions

public DrawActions(Draw canvas,
                   FigureStore store,
                   InterpolatorFactory factory)
Create an instance for use with a specified Draw and InterpolatorFactory.

Parameters:
canvas - on which graphics will be drawn.
store - used to save and restore graphics, null for none.
factory - an InterpolatorFactory.
Method Detail

getDraw

public Draw getDraw()
Return the Draw instance.


setDrawingMode

public void setDrawingMode(int drawingMode)
Set the drawing mode.

Parameters:
mode - one of the mode constants defined in this class

getDrawingMode

public int getDrawingMode()
Return the current drawing mode.


getDrawingModeAction

public AbstractAction getDrawingModeAction(int drawingMode)
Return the action for the given mode.


setLineWidth

public void setLineWidth(int lineWidth)
Set the line width.


getLineWidth

public int getLineWidth()
Return the current line width for drawing.


getLineWidthAction

public AbstractAction getLineWidthAction(int i)
Return the action for the given line width


setOutline

public void setOutline(Paint outline)
Set the outline color.


getOutline

public Paint getOutline()
Return the current outline color for drawing.


getOutlineAction

public AbstractAction getOutlineAction(int i)
Return the action for the given outline color


setFill

public void setFill(Paint fill)
Set the fill color.


getFill

public Paint getFill()
Return the current fill color for drawing.


getFillAction

public AbstractAction getFillAction(int i)
Return the action for the given fill color.


getColorCount

public int getColorCount()
Return the number of colours.


getColor

public Color getColor(int i)
Get a Color by index.


addColor

public void addColor(Color color)
Add a new color.


setComposite

public void setComposite(AlphaComposite composite)
Set the composite (transparency).


getComposite

public AlphaComposite getComposite()
Return the current composite composite for drawing.


getCompositeAction

public AbstractAction getCompositeAction(int i)
Return the action for the given composite composite.


setFont

public void setFont(Font font)
Set the font to use for labels.


addFont

public void addFont(Font font)
Add a new font.


getFont

public Font getFont()
Return the current font color for drawing.


getFont

public Font getFont(int i)
Return a given font.


getFontAction

public AbstractAction getFontAction(int i)
Return the action for the given font.


fontCount

public int fontCount()
Return the number of fonts


setInterpolatorFactory

public void setInterpolatorFactory(InterpolatorFactory factory)
Set the InterpolatorFactory.


getInterpolatorFactory

public InterpolatorFactory getInterpolatorFactory()
Get the InterpolatorFactory.


setCurve

public void setCurve(int interpolator)
Set the interpolated curve type.


getCurve

public int getCurve()
Return the current curve type.


getCurveAction

public AbstractAction getCurveAction(int i)
Return the action for a given curve interpolation type.


makeInterpolator

public Interpolator makeInterpolator()
Make an instance of the current interpolator.


addChangeListener

public void addChangeListener(ChangeListener l)
Register to receive change events from this object whenever the drawing settings are changed.


removeChangeListener

public void removeChangeListener(ChangeListener l)
Stop receiving change events from this object.


fireChange

protected void fireChange()
Notify any listeners of a change.


addFigureListener

public void addFigureListener(FigureListener l)
Register to receive figure change events from this object whenever a figure has been created.


removeFigureListener

public void removeFigureListener(FigureListener l)
Stop receiving figure change events from this object.


fireFigureEvent

protected void fireFigureEvent(DrawFigure figure,
                               int type)
Notify any figure listeners of a figure created event.


mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
Specified by:
mouseMoved in interface MouseMotionListener

finishFigure

protected void finishFigure()
Finish off the current figure and select it.


clear

public void clear()
Remove all figures created by this instance.


deleteSelected

public void deleteSelected()
Delete the selected figures.


deleteFigure

public void deleteFigure(DrawFigure figure)
Delete a given figure, if displayed.


hideGraphics

public void hideGraphics()
Toggle the visibility all figures created by this instance.


raiseSelected

public void raiseSelected()
Raise the selected figures.


raiseFigure

public void raiseFigure(DrawFigure figure)
Raise the given figure.


lowerSelected

public void lowerSelected()
Lower the selected figures.


lowerFigure

public void lowerFigure(DrawFigure figure)
Lower the given figure.


getListIterator

public ListIterator getListIterator(boolean forward)
Return a ListIterator over the figures. If forward is set false the Iterator will be set to the end of the list so that it is ready to be traversed backwards.


createDrawFigure

public DrawFigure createDrawFigure(int type,
                                   FigureProps props)
Create a DrawFigure using preset properties.


addDrawFigure

public void addDrawFigure(DrawFigure figure)
Add a DrawFigure created to the managed list.


getTypedDecorator

public static TypedDecorator getTypedDecorator()
Create and return a TypedDecorator suitable for manipulating the various types of figures in natural ways.


saveRestore

protected void saveRestore()
Interact with the object for saving and restoring figures from an XML store of some kind. The simple action here communicates that the user wants to interact, we just supply a reference so that this system may interact with various components.


setFigureStore

public void setFigureStore(FigureStore store)
Set the FigureStore.


getFigureStore

public FigureStore getFigureStore()
Get the FigureStore.


getDeleteSelectedAction

public Action getDeleteSelectedAction()

getClearAction

public Action getClearAction()

getHideAction

public Action getHideAction()

getRaiseSelectedAction

public Action getRaiseSelectedAction()

getLowerSelectedAction

public Action getLowerSelectedAction()


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