jsky.image.graphics
Class DivaImageGraphics

java.lang.Object
  extended by jsky.image.graphics.DivaImageGraphics
All Implemented Interfaces:
CanvasGraphics

public class DivaImageGraphics
extends java.lang.Object
implements CanvasGraphics

Implements drawing for image overlays. It is based on the Diva package. See The Diva package

Version:
$Revision: 1.1 $
Author:
Allan Brighton

Field Summary
 
Fields inherited from interface jsky.graphics.CanvasGraphics
MOVE, RESIZE, ROTATE, SELECT
 
Constructor Summary
DivaImageGraphics(DivaGraphicsImageDisplay imageDisplay)
          Construct an object for drawing on the given image display.
 
Method Summary
 void add(CanvasFigure fig)
          Add the given figure to the canvas.
 void clearSelection()
          Clear the selection.
 void deselect(CanvasFigure fig)
          Deselect the given figure.
 diva.canvas.interactor.DragInteractor getDragInteractor()
          Return an interactor that allows dragging figures
 int getFigureCount()
          Return the number of figures.
 diva.canvas.interactor.SelectionInteractor getFixedSelectionInteractor()
          Return an interactor that allows selecting figures, but not dragging or resizing
 diva.canvas.GraphicsPane getGraphicsPane()
          Return the Diva graphics pane.
 ImageLayer getImageLayer()
          Return the Diva layer containing the image
 diva.canvas.interactor.SelectionInteractor getLineInteractor()
          Return an interactor for lines
 SelectionDragger getSelectionDragger()
          Used for selecting all objects in a rectangular region
 diva.canvas.interactor.SelectionInteractor getSelectionInteractor()
          Return an interactor that allows selection, dragging and resizing figures
static void main(java.lang.String[] args)
          test main: usage: java GraphicsImageDisplay .
 CanvasFigure makeEllipse(java.awt.geom.Ellipse2D.Double ellipse, int coordType, java.awt.Paint fill, java.awt.Paint outline, float lineWidth, diva.canvas.interactor.Interactor interactor)
          This is a convenience method for drawing ellipses that allows you to specify the type of the coordinates given by the ellipse argument.
 CanvasFigure makeFigure(java.awt.Shape shape, java.awt.Paint fill, java.awt.Paint outline, float lineWidth)
          Make and return a figure with the given shape, fill, outline and line width.
 CanvasFigure makeFigure(java.awt.Shape shape, java.awt.Paint fill, java.awt.Paint outline, float lineWidth, diva.canvas.interactor.Interactor interactor)
          Make and return a figure with the given shape, fill, outline and line width.
 CanvasFigureGroup makeFigureGroup()
          Make and return a new CanvasFigureGroup object that can be used as a figure container to hold other figures.
 CanvasFigureGroup makeFigureGroup(diva.canvas.interactor.Interactor interactor)
          Make and return a new CanvasFigureGroup object that can be used as a figure container to hold other figures.
 CanvasFigure makeLabel(java.awt.geom.Point2D.Double pos, java.lang.String text, java.awt.Paint color, java.awt.Font font)
          Make and return a canvas label.
 CanvasFigure makeLabel(java.awt.geom.Point2D.Double pos, java.lang.String text, java.awt.Paint color, java.awt.Font font, diva.canvas.interactor.Interactor interactor)
          Make and return a canvas label.
 CanvasFigure makeLabeledEllipse(java.awt.geom.Ellipse2D.Double ellipse, int coordType, java.awt.Paint fill, java.awt.Paint outline, float lineWidth, java.lang.String label, int anchor, java.awt.Paint labelColor, java.awt.Font font, diva.canvas.interactor.Interactor interactor)
          This is a convenience method for drawing a labeled ellipse that allows you to specify the type of the coordinates given by the ellipse argument.
 CanvasFigure makeLabeledFigure(java.awt.Shape shape, java.awt.Paint fill, java.awt.Paint outline, float lineWidth, java.lang.String label, int anchor, java.awt.Paint labelColor, java.awt.Font font)
          Make and return a labeled figure with the given shape, fill, outline and line width.
 CanvasFigure makeLabeledFigure(java.awt.Shape shape, java.awt.Paint fill, java.awt.Paint outline, float lineWidth, java.lang.String label, int anchor, java.awt.Paint labelColor, java.awt.Font font, diva.canvas.interactor.Interactor interactor)
          Make and return a labeled figure with the given shape, fill, outline and line width.
 CanvasFigure makeLabeledRectangle(java.awt.geom.Rectangle2D.Double rect, int coordType, java.awt.Paint fill, java.awt.Paint outline, float lineWidth, java.lang.String label, int anchor, java.awt.Paint labelColor, java.awt.Font font, diva.canvas.interactor.Interactor interactor)
          This is a convenience method for making a labeled rectangle that allows you to specify the type of the coordinates given by the rect argument.
 CanvasFigure makeRectangle(java.awt.geom.Rectangle2D.Double rect, int coordType, java.awt.Paint fill, java.awt.Paint outline, float lineWidth, diva.canvas.interactor.Interactor interactor)
          This is a convenience method for making rectangles that allows you to specify the type of the coordinates given by the rect argument.
 void remove(CanvasFigure fig)
          Remove the given figure from the display.
 void repaint()
          Schedule a repaint of the window containing the graphics.
 void repaint(java.awt.geom.Rectangle2D region)
          Schedule a repaint of the given area of the window containing the graphics.
 void scheduleRemoval(CanvasFigure fig)
          Schedule the removal of the given figure from the display at a later time.
 void select(CanvasFigure fig)
          Select the given figure.
 void selectArea(SelectedAreaListener l)
          Wait for the user to drag out an area on the image canvas and then notify the listener with the coordinates of the box.
 void setInteractionMode(CanvasFigure fig, int mode)
          Set the interaction mode for the given figure to an OR'ed combination of the following constants: SELECT, MOVE, RESIZE, ROTATE.
 void transform(java.awt.geom.AffineTransform trans)
          Transform all graphics according to the given AffineTransform object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DivaImageGraphics

public DivaImageGraphics(DivaGraphicsImageDisplay imageDisplay)
Construct an object for drawing on the given image display.

Method Detail

getGraphicsPane

public diva.canvas.GraphicsPane getGraphicsPane()
Return the Diva graphics pane.


getImageLayer

public ImageLayer getImageLayer()
Return the Diva layer containing the image


getSelectionDragger

public SelectionDragger getSelectionDragger()
Used for selecting all objects in a rectangular region


getDragInteractor

public diva.canvas.interactor.DragInteractor getDragInteractor()
Return an interactor that allows dragging figures


getSelectionInteractor

public diva.canvas.interactor.SelectionInteractor getSelectionInteractor()
Return an interactor that allows selection, dragging and resizing figures


getLineInteractor

public diva.canvas.interactor.SelectionInteractor getLineInteractor()
Return an interactor for lines


getFixedSelectionInteractor

public diva.canvas.interactor.SelectionInteractor getFixedSelectionInteractor()
Return an interactor that allows selecting figures, but not dragging or resizing


makeLabeledFigure

public CanvasFigure makeLabeledFigure(java.awt.Shape shape,
                                      java.awt.Paint fill,
                                      java.awt.Paint outline,
                                      float lineWidth,
                                      java.lang.String label,
                                      int anchor,
                                      java.awt.Paint labelColor,
                                      java.awt.Font font,
                                      diva.canvas.interactor.Interactor interactor)
Make and return a labeled figure with the given shape, fill, outline and line width. The shape is expected to be in screen coordinates. If a label is specified, it will be attached to the figure using the given anchor argument for the relative position.

The CoordinateConverter object in the image display class may be used while constructing the shape to convert to screen coordinates.

Event handling for figures is done through Diva Interactors. A number of common interactors are defined in this class for dragging and selecting figures. When selecting figures, the Diva SelectionModel class can also be used to get notification whenever the selection changes. When dragging figures, the DragIterator class has listener methods that can notify you whenever a figure is dragged.

Parameters:
shape - the shape to draw
fill - the paint to use to fill the shape
outline - the paint to use for the outline
lineWidth - the width of the shape lines in pixels
label - an optional label text to be displayed with the figure (may be null)
anchor - SwingConstants value for label position
labelColor - color of the label
font - the label's font
interactor - determines the behavior of the figure (may be null)
Returns:
the handle for the figure
See Also:
CoordinateConverter, GraphicsImageDisplay

makeFigure

public CanvasFigure makeFigure(java.awt.Shape shape,
                               java.awt.Paint fill,
                               java.awt.Paint outline,
                               float lineWidth,
                               diva.canvas.interactor.Interactor interactor)
Make and return a figure with the given shape, fill, outline and line width. The shape is expected to be in screen coordinates. If a label is specified, it will be attached to the figure using the given anchor argument for the relative position.

Parameters:
shape - the shape to draw
fill - the paint to use to fill the shape
outline - the paint to use for the outline
lineWidth - the width of the shape lines in pixels
interactor - determines the behavior of the figure (may be null)
Returns:
the handle for the figure

makeLabeledFigure

public CanvasFigure makeLabeledFigure(java.awt.Shape shape,
                                      java.awt.Paint fill,
                                      java.awt.Paint outline,
                                      float lineWidth,
                                      java.lang.String label,
                                      int anchor,
                                      java.awt.Paint labelColor,
                                      java.awt.Font font)
Make and return a labeled figure with the given shape, fill, outline and line width. The shape is expected to be in screen coordinates.

Specified by:
makeLabeledFigure in interface CanvasGraphics
Parameters:
shape - the shape to draw
fill - the paint to use to fill the shape
outline - the paint to use for the outline
lineWidth - the width of the shape lines in pixels
label - an optional label text to be displayed with the figure (may be null)
anchor - SwingConstants value for label position
labelColor - color of the label
font - the label's font
Returns:
an object representing the figure

makeFigure

public CanvasFigure makeFigure(java.awt.Shape shape,
                               java.awt.Paint fill,
                               java.awt.Paint outline,
                               float lineWidth)
Make and return a figure with the given shape, fill, outline and line width. The shape is expected to be in screen coordinates.

Specified by:
makeFigure in interface CanvasGraphics
Parameters:
shape - the shape to draw
fill - the paint to use to fill the shape
outline - the paint to use for the outline
lineWidth - the width of the shape lines in pixels
Returns:
an object representing the figure
See Also:
CoordinateConverter, GraphicsImageDisplay

makeLabeledRectangle

public CanvasFigure makeLabeledRectangle(java.awt.geom.Rectangle2D.Double rect,
                                         int coordType,
                                         java.awt.Paint fill,
                                         java.awt.Paint outline,
                                         float lineWidth,
                                         java.lang.String label,
                                         int anchor,
                                         java.awt.Paint labelColor,
                                         java.awt.Font font,
                                         diva.canvas.interactor.Interactor interactor)
This is a convenience method for making a labeled rectangle that allows you to specify the type of the coordinates given by the rect argument. The rect argument is converted to screen coordinates before creating the figure as in add(Shape shape, Paint fill, Paint outline, float lineWidth, Interactor interactor).


makeRectangle

public CanvasFigure makeRectangle(java.awt.geom.Rectangle2D.Double rect,
                                  int coordType,
                                  java.awt.Paint fill,
                                  java.awt.Paint outline,
                                  float lineWidth,
                                  diva.canvas.interactor.Interactor interactor)
This is a convenience method for making rectangles that allows you to specify the type of the coordinates given by the rect argument. The rect argument is converted to screen coordinates before creating the figure as in add(Shape shape, Paint fill, Paint outline, float lineWidth, Interactor interactor).


makeLabeledEllipse

public CanvasFigure makeLabeledEllipse(java.awt.geom.Ellipse2D.Double ellipse,
                                       int coordType,
                                       java.awt.Paint fill,
                                       java.awt.Paint outline,
                                       float lineWidth,
                                       java.lang.String label,
                                       int anchor,
                                       java.awt.Paint labelColor,
                                       java.awt.Font font,
                                       diva.canvas.interactor.Interactor interactor)
This is a convenience method for drawing a labeled ellipse that allows you to specify the type of the coordinates given by the ellipse argument. The ellipse argument is converted to screen coordinates before creating the figure as in makeFigure(Shape shape, Paint fill, Paint outline, float lineWidth, Interactor interactor).


makeEllipse

public CanvasFigure makeEllipse(java.awt.geom.Ellipse2D.Double ellipse,
                                int coordType,
                                java.awt.Paint fill,
                                java.awt.Paint outline,
                                float lineWidth,
                                diva.canvas.interactor.Interactor interactor)
This is a convenience method for drawing ellipses that allows you to specify the type of the coordinates given by the ellipse argument. The ellipse argument is converted to screen coordinates before creating the figure as in makeFigure(Shape shape, Paint fill, Paint outline, float lineWidth, Interactor interactor).


makeLabel

public CanvasFigure makeLabel(java.awt.geom.Point2D.Double pos,
                              java.lang.String text,
                              java.awt.Paint color,
                              java.awt.Font font,
                              diva.canvas.interactor.Interactor interactor)
Make and return a canvas label.

Parameters:
pos - the label position
text - the text of the label to draw
color - the paint to use to draw the text
font - the font to use for the label
interactor - determines the behavior of the figure (may be null)

makeLabel

public CanvasFigure makeLabel(java.awt.geom.Point2D.Double pos,
                              java.lang.String text,
                              java.awt.Paint color,
                              java.awt.Font font)
Make and return a canvas label.

Specified by:
makeLabel in interface CanvasGraphics
Parameters:
text - the text of the label to draw
pos - the label position
color - the paint to use to draw the text
font - the font to use for the label

makeFigureGroup

public CanvasFigureGroup makeFigureGroup(diva.canvas.interactor.Interactor interactor)
Make and return a new CanvasFigureGroup object that can be used as a figure container to hold other figures.

Parameters:
interactor - determines the selection behavior of the figure group (may be null)

makeFigureGroup

public CanvasFigureGroup makeFigureGroup()
Make and return a new CanvasFigureGroup object that can be used as a figure container to hold other figures.

Specified by:
makeFigureGroup in interface CanvasGraphics

add

public void add(CanvasFigure fig)
Add the given figure to the canvas.

Specified by:
add in interface CanvasGraphics

remove

public void remove(CanvasFigure fig)
Remove the given figure from the display.

Specified by:
remove in interface CanvasGraphics

select

public void select(CanvasFigure fig)
Select the given figure.

Specified by:
select in interface CanvasGraphics

deselect

public void deselect(CanvasFigure fig)
Deselect the given figure.

Specified by:
deselect in interface CanvasGraphics

clearSelection

public void clearSelection()
Clear the selection.


scheduleRemoval

public void scheduleRemoval(CanvasFigure fig)
Schedule the removal of the given figure from the display at a later time. This version may be used to avoid problems with iterators working on a a list of figures that should not be modified inside the loop.

Specified by:
scheduleRemoval in interface CanvasGraphics

getFigureCount

public int getFigureCount()
Return the number of figures.

Specified by:
getFigureCount in interface CanvasGraphics

transform

public void transform(java.awt.geom.AffineTransform trans)
Transform all graphics according to the given AffineTransform object.

Specified by:
transform in interface CanvasGraphics

setInteractionMode

public void setInteractionMode(CanvasFigure fig,
                               int mode)
Set the interaction mode for the given figure to an OR'ed combination of the following constants: SELECT, MOVE, RESIZE, ROTATE. For example, if mode is (SELECT | MOVE | RESIZE), the figure can be selected, moved, and resized. (Note that MOVE, RESIZE and ROTATE automatically assume SELECT).

Specified by:
setInteractionMode in interface CanvasGraphics

selectArea

public void selectArea(SelectedAreaListener l)
Wait for the user to drag out an area on the image canvas and then notify the listener with the coordinates of the box.

Specified by:
selectArea in interface CanvasGraphics

repaint

public void repaint()
Schedule a repaint of the window containing the graphics.

Specified by:
repaint in interface CanvasGraphics

repaint

public void repaint(java.awt.geom.Rectangle2D region)
Schedule a repaint of the given area of the window containing the graphics.


main

public static void main(java.lang.String[] args)
test main: usage: java GraphicsImageDisplay .