jsky.image.graphics.gui
Class CanvasDraw

java.lang.Object
  extended by jsky.image.graphics.gui.CanvasDraw
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener

public class CanvasDraw
extends java.lang.Object
implements javax.swing.event.MouseInputListener

This class defines a set of AbstractAction objects for drawing on the image. These can be used for menu items or buttons in the user interface.

Version:
$Revision: 1.2 $
Author:
Allan Brighton

Field Summary
protected  javax.swing.event.ChangeEvent changeEvent
          Event fired for changes
protected  javax.swing.AbstractAction clearAction
          Action to use to remove all figures.
static java.lang.String[] COLOR_NAMES
          Colors names corresponding to the above array
static java.awt.Color[] COLORS
          Colors for color change actions
protected  java.awt.Composite composite
          Current composite
static java.lang.String[] COMPOSITE_NAMES
          Display names for Composites
protected  javax.swing.AbstractAction[] compositeActions
          Actions to use to set the composite
static java.awt.Composite[] COMPOSITES
          Composites
protected  javax.swing.AbstractAction deleteSelectedAction
          Action to use to delete the selected figure.
static java.lang.String[] DRAWING_MODES
          Drawing mode action names
protected  int drawingMode
          Current drawing mode
protected  javax.swing.AbstractAction[] drawingModeActions
          Drawing mode actions
static int ELLIPSE
          Mode to draw an ellipse
protected  diva.canvas.AbstractFigure figure
          Current figure (during figure creation)
protected  java.util.LinkedList figureList
          List of figures created by this instance
protected  java.awt.Paint fill
          Current fill paint
protected  javax.swing.AbstractAction[] fillActions
          Actions to use to set the fill color
protected  java.awt.Font font
          Default font for text items (labels can be resized afterwards)
protected  javax.swing.AbstractAction[] fontActions
          Actions to use to set the font
static java.awt.Font[] FONTS
          Fonts for font change actions
protected  diva.util.java2d.Polyline2D.Double freehand
          Used while drawing freehand
static int FREEHAND
          Mode to draw a free-hand figure
protected  DivaImageGraphics graphics
          Object managing image graphics
protected  javax.swing.AbstractAction hideGraphicsAction
          Action to use to toggle the visibility of all figures.
protected  DivaMainImageDisplay imageDisplay
          The target image display.
static int LINE
          Mode to draw a line
static int[] LINE_WIDTHS
          Supported line widths
protected  int lineWidth
          Current line width
protected  javax.swing.AbstractAction[] lineWidthActions
          Actions to use to set the line width
protected  javax.swing.event.EventListenerList listenerList
          list of listeners for change events
protected  boolean mouseClicked
          True if mouse was clicked
static int NUM_COLORS
          The number of colors for which fill and outline actions are defined.
static int NUM_COMPOSITES
          The number of composites defined above
static int NUM_DRAWING_MODES
          The number of drawing modes.
static int NUM_FONTS
          The number of fonts for which actions are defined.
static int NUM_LINE_WIDTHS
          Number of Supported line widths
protected  java.awt.Paint outline
          Current outline paint
protected  javax.swing.AbstractAction[] outlineActions
          Actions to use to set the outline color
protected  diva.util.java2d.Polygon2D.Double polygon
          Used while drawing a polygon
static int POLYGON
          Mode to draw a polygon
protected  diva.util.java2d.Polyline2D.Double polyline
          Used while drawing a polyline
static int POLYLINE
          Mode to draw a polyline
static int RECTANGLE
          Mode to draw a rectangle
static int REGION
          Mode to select objects in a rectangular region
static int SELECT
          Mode to select an object
protected  int startX
          Starting point of drag
protected  int startY
          Starting point of drag
static int TEXT
          Mode to insert a text label
protected  boolean visible
          Used to toggle the visibility of all figures
 
Constructor Summary
CanvasDraw(DivaMainImageDisplay imageDisplay)
          Create a menu with graphics related items.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
          register to receive change events from this object whenever the drawing settings are changed.
 void addFigure(CanvasFigure fig)
          Add the given figure to the list of managed figures.
 void clear()
          Remove all figures created by this instance.
 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 in the image or cut levels.
 java.awt.Composite getComposite()
          Return the current composite composite for drawing.
 javax.swing.AbstractAction getCompositeAction(int i)
          Return the action for the given composite composite
 int getDrawingMode()
          Return the current drawing mode
 javax.swing.AbstractAction getDrawingModeAction(int drawingMode)
          Return the action for the given mode
 java.util.LinkedList getFigureList()
          Return a list of figures managed by this instance.
 java.awt.Paint getFill()
          Return the current fill color for drawing.
 javax.swing.AbstractAction getFillAction(int i)
          Return the action for the given fill color
 java.awt.Font getFont()
          Return the current font color for drawing.
 javax.swing.AbstractAction getFontAction(int i)
          Return the action for the given font color
 DivaMainImageDisplay getImageDisplay()
          Return the target image display.
 int getLineWidth()
          Return the current line width for drawing.
 javax.swing.AbstractAction getLineWidthAction(int i)
          Return the action for the given line width
 java.awt.Paint getOutline()
          Return the current outline color for drawing.
 javax.swing.AbstractAction getOutlineAction(int i)
          Return the action for the given outline color
 void hideGraphics()
          Toggle the visibility all figures created by this instance.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void removeChangeListener(javax.swing.event.ChangeListener l)
          Stop receiving change events from this object.
 void setComposite(java.awt.Composite composite)
          Set the composite (transparency).
 void setDrawingMode(int drawingMode)
          Set the drawing mode.
 void setFill(java.awt.Paint fill)
          Set the fill color.
 void setFont(java.awt.Font font)
          Set the font to use for labels.
 void setLineWidth(int lineWidth)
          Set the line width.
 void setOutline(java.awt.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

imageDisplay

protected DivaMainImageDisplay imageDisplay
The target image display.


graphics

protected DivaImageGraphics graphics
Object managing image graphics


listenerList

protected javax.swing.event.EventListenerList listenerList
list of listeners for change events


changeEvent

protected javax.swing.event.ChangeEvent changeEvent
Event fired for changes


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 diva.util.java2d.Polyline2D.Double polyline
Used while drawing a polyline


polygon

protected diva.util.java2d.Polygon2D.Double polygon
Used while drawing a polygon


freehand

protected diva.util.java2d.Polyline2D.Double freehand
Used while drawing freehand


figure

protected diva.canvas.AbstractFigure figure
Current figure (during figure creation)


figureList

protected java.util.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

REGION

public static final int REGION
Mode to select objects in a rectangular region

See Also:
Constant Field Values

LINE

public static final int LINE
Mode to draw a line

See Also:
Constant Field Values

RECTANGLE

public static final int RECTANGLE
Mode to draw a rectangle

See Also:
Constant Field Values

ELLIPSE

public static final int ELLIPSE
Mode to draw an ellipse

See Also:
Constant Field Values

POLYLINE

public static final int POLYLINE
Mode to draw a polyline

See Also:
Constant Field Values

POLYGON

public static final int POLYGON
Mode to draw a polygon

See Also:
Constant Field Values

FREEHAND

public static final int FREEHAND
Mode to draw a free-hand figure

See Also:
Constant Field Values

TEXT

public static final int TEXT
Mode to insert a text label

See Also:
Constant Field Values

DRAWING_MODES

public static final java.lang.String[] DRAWING_MODES
Drawing mode action names


NUM_DRAWING_MODES

public static final int NUM_DRAWING_MODES
The number of drawing modes.


drawingModeActions

protected javax.swing.AbstractAction[] 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 final java.awt.Color[] COLORS
Colors for color change actions


COLOR_NAMES

public static final java.lang.String[] COLOR_NAMES
Colors names corresponding to the above array


NUM_COLORS

public static final int NUM_COLORS
The number of colors for which fill and outline actions are defined.


fill

protected java.awt.Paint fill
Current fill paint


outline

protected java.awt.Paint outline
Current outline paint


outlineActions

protected javax.swing.AbstractAction[] outlineActions
Actions to use to set the outline color


fillActions

protected javax.swing.AbstractAction[] fillActions
Actions to use to set the fill color


COMPOSITES

public static final java.awt.Composite[] COMPOSITES
Composites


COMPOSITE_NAMES

public static final java.lang.String[] COMPOSITE_NAMES
Display names for Composites


NUM_COMPOSITES

public static final int NUM_COMPOSITES
The number of composites defined above


compositeActions

protected javax.swing.AbstractAction[] compositeActions
Actions to use to set the composite


composite

protected java.awt.Composite composite
Current composite


FONTS

public static final java.awt.Font[] FONTS
Fonts for font change actions


NUM_FONTS

public static final int NUM_FONTS
The number of fonts for which actions are defined.


fontActions

protected javax.swing.AbstractAction[] fontActions
Actions to use to set the font


font

protected java.awt.Font font
Default font for text items (labels can be resized afterwards)


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 javax.swing.AbstractAction[] lineWidthActions
Actions to use to set the line width


deleteSelectedAction

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


clearAction

protected javax.swing.AbstractAction clearAction
Action to use to remove all figures.


hideGraphicsAction

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

Constructor Detail

CanvasDraw

public CanvasDraw(DivaMainImageDisplay imageDisplay)
Create a menu with graphics related items.

Parameters:
imageDisplay - used to access the JCanvas and DivaImageGraphics objects
Method Detail

getImageDisplay

public DivaMainImageDisplay getImageDisplay()
Return the target image display.


setDrawingMode

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

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

getDrawingMode

public int getDrawingMode()
Return the current drawing mode


getDrawingModeAction

public javax.swing.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 javax.swing.AbstractAction getLineWidthAction(int i)
Return the action for the given line width


setOutline

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


getOutline

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


getOutlineAction

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


setFill

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


getFill

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


getFillAction

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


setComposite

public void setComposite(java.awt.Composite composite)
Set the composite (transparency).


getComposite

public java.awt.Composite getComposite()
Return the current composite composite for drawing.


getCompositeAction

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


setFont

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


getFont

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


getFontAction

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


addChangeListener

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


removeChangeListener

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


fireChange

protected void fireChange()
Notify any listeners of a change in the image or cut levels.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.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.


hideGraphics

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


getFigureList

public java.util.LinkedList getFigureList()
Return a list of figures managed by this instance.


addFigure

public void addFigure(CanvasFigure fig)
Add the given figure to the list of managed figures.