JHotDraw 7.1

org.jhotdraw.draw
Interface Drawing

All Superinterfaces:
java.lang.Cloneable, CompositeFigure, DOMStorable, Figure, java.io.Serializable
All Known Implementing Classes:
AbstractDrawing, DefaultDrawing, ODGDrawing, QuadTreeDrawing

public interface Drawing
extends CompositeFigure, java.io.Serializable, DOMStorable

A drawing holds figures. It can draw its figures, and it can find them on its drawing area.
A drawing notifies listeners when a figure is added or removed, and when its drawing area needs to be repainted.

The drawing object is used by figure handles and editing tools to fire undoable edit events. This way, undoable edit listeners only need to register on a drawing in order to receive all undoable edit events related to a drawing.

A drawing can have a number of input formats and output formats, allowing to load and save the drawing, and to copy and paste figures into the clipboard.

Version:
3.0 2007-07-17 Refactored Drawing from an independent interface into an interface that extends from CompositeFigure.
2.4 2007-05-21 Added add-methods with index to the interface.
2.3 2007-05-16 Added method findFigureBehind.
2.2 2007-04-09 Methods setCanvasSize, getCanvasSize added.
2.1 2006-12-31 Changed to return lists instead of collections.
2.0 2006-01-14 Changed to support double precision coordinates.
1.0 2003-12-01 Derived from JHotDraw 5.4b1.
Author:
Werner Randelshofer

Field Summary
 
Fields inherited from interface org.jhotdraw.draw.CompositeFigure
LAYOUT_INSETS
 
Method Summary
 boolean add(Figure figure)
          Adds a figure to the drawing.
 void add(int index, Figure figure)
          Adds a figure to the drawing.
 void addAll(java.util.Collection<Figure> figures)
          Adds a collection of figures to the drawing.
 void addAll(int index, java.util.Collection<Figure> figures)
          Adds a collection of figures to the drawing.
 void addInputFormat(InputFormat format)
          Adds an input format to the drawing.
 void addOutputFormat(OutputFormat format)
          Adds an output format to the drawing.
 void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
          Adds a listener for undooable edit events.
 void basicAdd(Figure figure)
          Reinserts a figure which was temporarily removed using basicRemove.
 void basicAdd(int index, Figure figure)
          Reinserts a figure which was temporarily removed using basicRemove.
 void basicAddAll(int index, java.util.Collection<Figure> figures)
          Reinserts the specified figures which were temporarily removed from the drawing.
 int basicRemove(Figure figure)
          Removes a figure temporarily from the drawing.
 void basicRemoveAll(java.util.Collection<Figure> figures)
          Removes the specified figures temporarily from the drawing.
 void bringToFront(Figure figure)
          Brings a figure to the front.
 void draw(java.awt.Graphics2D g)
          Draws all the figures from back to front.
 Figure findFigure(java.awt.geom.Point2D.Double p)
          Finds a top level Figure.
 Figure findFigureBehind(java.awt.geom.Point2D.Double p, java.util.Collection<Figure> figures)
          Finds a top level Figure which is behind the specified Figures.
 Figure findFigureBehind(java.awt.geom.Point2D.Double p, Figure figure)
          Finds a top level Figure which is behind the specified Figure.
 Figure findFigureExcept(java.awt.geom.Point2D.Double p, java.util.Collection<Figure> ignore)
          Finds a top level Figure.
 Figure findFigureExcept(java.awt.geom.Point2D.Double p, Figure ignore)
          Finds a top level Figure.
 Figure findFigureInside(java.awt.geom.Point2D.Double p)
          Finds a figure but descends into a figure's children.
 java.util.List<Figure> findFigures(java.awt.geom.Rectangle2D.Double bounds)
          Returns all figures that lie within or intersect the specified bounds.
 java.util.List<Figure> findFiguresWithin(java.awt.geom.Rectangle2D.Double bounds)
          Returns all figures that lie within the specified bounds.
 void fireUndoableEditHappened(javax.swing.undo.UndoableEdit edit)
          Notify all listenerList that have registered interest for notification on this event type.
 Dimension2DDouble getCanvasSize()
          Gets the canvas size of this drawing.
 int getChildCount()
          Returns the number of figures in this drawing.
 java.util.List<Figure> getChildren()
          Returns the figures of the drawing.
 java.util.List<Figure> getFiguresFrontToBack()
          Returns a list of the figures in Z-Order from front to back.
 java.awt.font.FontRenderContext getFontRenderContext()
          Returns the font render context used to do text leyout and text drawing.
 java.util.List<InputFormat> getInputFormats()
          Gets input formats for the Drawing in order of preferred formats.
 java.lang.Object getLock()
          Returns the lock object on which all threads acting in Figures in this drawing synchronize to prevent race conditions.
 java.util.List<OutputFormat> getOutputFormats()
          Gets output formats for the Drawing in order of preferred formats.
 int indexOf(Figure figure)
          Returns the index of the specified figure.
 boolean remove(Figure figure)
          Removes a figure from the drawing.
 void removeAll(java.util.Collection<Figure> figures)
          Removes the specified figures from the drawing.
 void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)
          Removes a listener for undoable edit events.
 void sendToBack(Figure figure)
          Sends a figure to the back of the drawing.
 void setCanvasSize(Dimension2DDouble canvasSize)
          Sets the canvas size for this drawing.
 void setFontRenderContext(java.awt.font.FontRenderContext frc)
          Sets the font render context used to do text leyout and text drawing.
 void setInputFormats(java.util.List<InputFormat> formats)
          Sets input formats for the Drawing in order of preferred formats.
 void setOutputFormats(java.util.List<OutputFormat> formats)
          Sets output formats for the Drawing in order of preferred formats.
 java.util.List<Figure> sort(java.util.Collection<Figure> figures)
          Returns a copy of the provided collection which is sorted in z order from back to front.
 
Methods inherited from interface org.jhotdraw.draw.CompositeFigure
addCompositeFigureListener, basicRemoveAllChildren, basicRemoveChild, contains, getChild, getLayouter, layout, removeAllChildren, removeChild, removeCompositeFigureListener, setLayouter
 
Methods inherited from interface org.jhotdraw.draw.Figure
addFigureListener, addNotify, canConnect, changed, clone, contains, createHandles, findCompatibleConnector, findConnector, getActions, getAttribute, getAttributes, getAttributesRestoreData, getBounds, getConnectors, getCursor, getDecomposition, getDrawingArea, getEndPoint, getLayer, getPreferredSize, getStartPoint, getTool, getToolTipText, getTransformRestoreData, handleDrop, handleMouseClick, includes, isRemovable, isSelectable, isTransformable, isVisible, remap, removeFigureListener, removeNotify, requestRemove, restoreAttributesTo, restoreTransformTo, setAttribute, setBounds, transform, willChange
 
Methods inherited from interface org.jhotdraw.xml.DOMStorable
read, write
 

Method Detail

add

boolean add(Figure figure)
Adds a figure to the drawing. The drawing sends an addNotify message to the figure after it has been added.

Specified by:
add in interface CompositeFigure
Parameters:
figure - to be added to the drawing
Returns:
true if this CompositeFigure changed as a result of the call
See Also:
Figure.addNotify(org.jhotdraw.draw.Drawing)

add

void add(int index,
         Figure figure)
Adds a figure to the drawing. The drawing sends an addNotify message to the figure after it has been added.

Specified by:
add in interface CompositeFigure
Parameters:
index - The z-index of the figure.
figure - to be added to the drawing
See Also:
Figure.addNotify(org.jhotdraw.draw.Drawing)

addAll

void addAll(java.util.Collection<Figure> figures)
Adds a collection of figures to the drawing. The drawing sends an addNotify message to each figure after it has been added.

Parameters:
figures - to be added to the drawing
See Also:
Figure.addNotify(org.jhotdraw.draw.Drawing)

addAll

void addAll(int index,
            java.util.Collection<Figure> figures)
Adds a collection of figures to the drawing. The drawing sends an addNotify message to each figure after it has been added.

Parameters:
index - The z-index of the figure.
figures - to be added to the drawing
See Also:
Figure.addNotify(org.jhotdraw.draw.Drawing)

remove

boolean remove(Figure figure)
Removes a figure from the drawing. The drawing sends a removeNotify message to the figure before it is removed.

Specified by:
remove in interface CompositeFigure
Parameters:
figure - that is part of the drawing and should be removed
See Also:
Figure.removeNotify(org.jhotdraw.draw.Drawing)

removeAll

void removeAll(java.util.Collection<Figure> figures)
Removes the specified figures from the drawing. The drawing sends a removeNotify message to each figure before it is removed.

Parameters:
figures - A collection of figures which are part of the drawing and should be removed
See Also:
Figure.removeNotify(org.jhotdraw.draw.Drawing)

basicRemove

int basicRemove(Figure figure)
Removes a figure temporarily from the drawing.

Specified by:
basicRemove in interface CompositeFigure
Parameters:
figure - that is part of the drawing and should be removed
See Also:
basicAdd(Figure)

basicRemoveAll

void basicRemoveAll(java.util.Collection<Figure> figures)
Removes the specified figures temporarily from the drawing.

Parameters:
figures - A collection of figures which are part of the drawing and should be removed
See Also:
basicAddAll(int, Collection)

basicAdd

void basicAdd(Figure figure)
Reinserts a figure which was temporarily removed using basicRemove.

This is a convenience method for calling basicAdd(size(), figure).

Specified by:
basicAdd in interface CompositeFigure
Parameters:
figure - that is part of the drawing and should be removed
See Also:
basicRemove(Figure)

basicAdd

void basicAdd(int index,
              Figure figure)
Reinserts a figure which was temporarily removed using basicRemove.

Specified by:
basicAdd in interface CompositeFigure
Parameters:
figure - that is part of the drawing and should be removed
See Also:
basicRemove(Figure)

indexOf

int indexOf(Figure figure)
Returns the index of the specified figure. Returns -1 if the Figure is not directly contained in this Drawing, for example if the Figure is a child of a CompositeFigure.

Specified by:
indexOf in interface CompositeFigure
Returns:
The index of the child, or -1 if the specified figure is not a child of this CompositeFigure.

basicAddAll

void basicAddAll(int index,
                 java.util.Collection<Figure> figures)
Reinserts the specified figures which were temporarily removed from the drawing.

Parameters:
index - The insertion index.
figures - A collection of figures which are part of the drawing and should be reinserted.
See Also:
basicRemoveAll(Collection)

draw

void draw(java.awt.Graphics2D g)
Draws all the figures from back to front.

Specified by:
draw in interface Figure
Parameters:
g - The Graphics2D to draw to.

findFigures

java.util.List<Figure> findFigures(java.awt.geom.Rectangle2D.Double bounds)
Returns all figures that lie within or intersect the specified bounds. The figures are returned in Z-order from back to front.


findFiguresWithin

java.util.List<Figure> findFiguresWithin(java.awt.geom.Rectangle2D.Double bounds)
Returns all figures that lie within the specified bounds. The figures are returned in Z-order from back to front.


getChildren

java.util.List<Figure> getChildren()
Returns the figures of the drawing.

Specified by:
getChildren in interface CompositeFigure
Returns:
A Collection of Figure's.

getChildCount

int getChildCount()
Returns the number of figures in this drawing.

Specified by:
getChildCount in interface CompositeFigure

findFigure

Figure findFigure(java.awt.geom.Point2D.Double p)
Finds a top level Figure. Use this call for hit detection that should not descend into the figure's children.


findFigureExcept

Figure findFigureExcept(java.awt.geom.Point2D.Double p,
                        Figure ignore)
Finds a top level Figure. Use this call for hit detection that should not descend into the figure's children.


findFigureExcept

Figure findFigureExcept(java.awt.geom.Point2D.Double p,
                        java.util.Collection<Figure> ignore)
Finds a top level Figure. Use this call for hit detection that should not descend into the figure's children.


findFigureBehind

Figure findFigureBehind(java.awt.geom.Point2D.Double p,
                        Figure figure)
Finds a top level Figure which is behind the specified Figure.


findFigureBehind

Figure findFigureBehind(java.awt.geom.Point2D.Double p,
                        java.util.Collection<Figure> figures)
Finds a top level Figure which is behind the specified Figures.


getFiguresFrontToBack

java.util.List<Figure> getFiguresFrontToBack()
Returns a list of the figures in Z-Order from front to back.


findFigureInside

Figure findFigureInside(java.awt.geom.Point2D.Double p)
Finds a figure but descends into a figure's children. Use this method to implement click-through hit detection, that is, you want to detect the inner most figure containing the given point.

Specified by:
findFigureInside in interface Figure

sendToBack

void sendToBack(Figure figure)
Sends a figure to the back of the drawing.

Parameters:
figure - that is part of the drawing

bringToFront

void bringToFront(Figure figure)
Brings a figure to the front.

Parameters:
figure - that is part of the drawing

sort

java.util.List<Figure> sort(java.util.Collection<Figure> figures)
Returns a copy of the provided collection which is sorted in z order from back to front.


addUndoableEditListener

void addUndoableEditListener(javax.swing.event.UndoableEditListener l)
Adds a listener for undooable edit events.


removeUndoableEditListener

void removeUndoableEditListener(javax.swing.event.UndoableEditListener l)
Removes a listener for undoable edit events.


fireUndoableEditHappened

void fireUndoableEditHappened(javax.swing.undo.UndoableEdit edit)
Notify all listenerList that have registered interest for notification on this event type.


getFontRenderContext

java.awt.font.FontRenderContext getFontRenderContext()
Returns the font render context used to do text leyout and text drawing.


setFontRenderContext

void setFontRenderContext(java.awt.font.FontRenderContext frc)
Sets the font render context used to do text leyout and text drawing.


getLock

java.lang.Object getLock()
Returns the lock object on which all threads acting in Figures in this drawing synchronize to prevent race conditions.


addInputFormat

void addInputFormat(InputFormat format)
Adds an input format to the drawing.


addOutputFormat

void addOutputFormat(OutputFormat format)
Adds an output format to the drawing.


setInputFormats

void setInputFormats(java.util.List<InputFormat> formats)
Sets input formats for the Drawing in order of preferred formats.

The input formats are used for loading the Drawing from a file and for pasting Figures from the clipboard into the Drawing.


getInputFormats

java.util.List<InputFormat> getInputFormats()
Gets input formats for the Drawing in order of preferred formats.


setOutputFormats

void setOutputFormats(java.util.List<OutputFormat> formats)
Sets output formats for the Drawing in order of preferred formats.

The output formats are used for saving the Drawing into a file and for cutting and copying Figures from the Drawing into the clipboard.


getOutputFormats

java.util.List<OutputFormat> getOutputFormats()
Gets output formats for the Drawing in order of preferred formats.


setCanvasSize

void setCanvasSize(Dimension2DDouble canvasSize)
Sets the canvas size for this drawing.

If canvasSize is null, the size of the canvas is expected to be adjusted dynamically to fit the drawing areas of all figures contained in the drawing.

This is a bound property.

Parameters:
canvasSize - The canvas size, or null.

getCanvasSize

Dimension2DDouble getCanvasSize()
Gets the canvas size of this drawing. If null is returned, the canvas size needs to be adjusted dynamically to fit the drawing areas of all figures contained in the drawing.

Returns:
The canvas size, or null.

Copyright 1996-2007 (c) JHotDraw.org.
Some rights reserved.