JHotDraw 7.1

org.jhotdraw.draw
Class QuadTreeDrawing

java.lang.Object
  extended by org.jhotdraw.beans.AbstractBean
      extended by org.jhotdraw.draw.AbstractFigure
          extended by org.jhotdraw.draw.AbstractCompositeFigure
              extended by org.jhotdraw.draw.AbstractAttributedCompositeFigure
                  extended by org.jhotdraw.draw.AbstractDrawing
                      extended by org.jhotdraw.draw.QuadTreeDrawing
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, CompositeFigure, Drawing, Figure, DOMStorable
Direct Known Subclasses:
ODGDrawing

public class QuadTreeDrawing
extends AbstractDrawing

QuadTreeDrawing uses a QuadTree2DDouble to improve responsiveness of drawings which contain many children.

Version:
2.2 2007-04-09 Added methods setCanvasSize, getCanvasSize.
2.1 2007-02-09 Moved FigureListener and UndoableEditListener into inner class.
2.0 2006-01-14 Changed to support double precision coordinates.
1.0 2003-12-01 Derived from JHotDraw 5.4b1.
Author:
Werner Randelshofer
See Also:
Serialized Form

Nested Class Summary
protected  class QuadTreeDrawing.QuadTreeEventHandler
          Handles all figure events fired by Figures contained in the Drawing.
 
Nested classes/interfaces inherited from class org.jhotdraw.draw.AbstractCompositeFigure
AbstractCompositeFigure.EventHandler
 
Field Summary
 
Fields inherited from class org.jhotdraw.draw.AbstractCompositeFigure
cachedBounds, cachedDrawingArea, children, eventHandler, layouter
 
Fields inherited from class org.jhotdraw.draw.AbstractFigure
changingDepth, listenerList
 
Fields inherited from class org.jhotdraw.beans.AbstractBean
propertySupport
 
Fields inherited from interface org.jhotdraw.draw.CompositeFigure
LAYOUT_INSETS
 
Constructor Summary
QuadTreeDrawing()
           
 
Method Summary
 void basicAdd(int index, Figure figure)
          Adds a child to the figure at the specified index without firing events.
 Figure basicRemoveChild(int index)
          Removes the child at the specified index without firing events.
 void bringToFront(Figure figure)
          Brings a figure to the front.
 QuadTreeDrawing clone()
          Returns a clone of the figure, with clones of all aggregated figures, such as chilrend and decorators.
 boolean contains(Figure f)
          Returns true if this composite figure contains the specified figure.
protected  AbstractCompositeFigure.EventHandler createEventHandler()
           
 void draw(java.awt.Graphics2D g)
          Draws the figure.
 void draw(java.awt.Graphics2D g, java.util.Collection<Figure> c)
           
protected  void drawFill(java.awt.Graphics2D g)
          This method is called by method draw() to draw the fill area of the figure.
protected  void drawStroke(java.awt.Graphics2D g)
          This method is called by method draw() to draw the text of the figure .
 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> children)
          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 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)
          Returns the figure that contains the given point.
 java.util.List<Figure> findFigures(java.awt.geom.Rectangle2D.Double r)
          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.
 Dimension2DDouble getCanvasSize()
          Gets the canvas size of this drawing.
 java.util.List<Figure> getChildren()
          Returns an unchangeable list view on the children.
 java.util.List<Figure> getChildren(java.awt.geom.Rectangle2D.Double bounds)
           
 java.util.List<Figure> getFiguresFrontToBack()
          Returns an iterator to iterate in Z-order front to back over the children.
 int indexOf(Figure figure)
          Returns the index of the specified child.
 void sendToBack(Figure figure)
          Sends a figure to the back of the composite figure.
protected  void setAttributeOnChildren(AttributeKey key, java.lang.Object newValue)
           
 void setCanvasSize(Dimension2DDouble newValue)
          Sets the canvas size for this drawing.
 java.util.List<Figure> sort(java.util.Collection<Figure> c)
          Implementation note: Sorting can not be done for orphaned children.
 
Methods inherited from class org.jhotdraw.draw.AbstractDrawing
addInputFormat, addOutputFormat, addUndoableEditListener, fireUndoableEditHappened, getDrawing, getFontRenderContext, getInputFormats, getLock, getOutputFormats, read, removeUndoableEditListener, setFontRenderContext, setInputFormats, setOutputFormats, write
 
Methods inherited from class org.jhotdraw.draw.AbstractAttributedCompositeFigure
applyAttributesTo, drawChildren, drawFigure, drawText, getAttribute, getAttributeKey, getAttributes, getAttributesRestoreData, getFigureDrawBounds, getStroke, getStrokeMiterLimitFactor, hasAttribute, isAttributeEnabled, readAttributes, removeAttribute, restoreAttributesTo, setAttribute, setAttributeEnabled, setAttributes, writeAttributes
 
Methods inherited from class org.jhotdraw.draw.AbstractCompositeFigure
add, add, addAll, addAll, addCompositeFigureListener, addNotify, basicAdd, basicAddAll, basicRemove, basicRemoveAll, basicRemoveAllChildren, contains, createHandles, findChild, findChildIndex, fireFigureAdded, fireFigureRemoved, getBounds, getChild, getChildCount, getChildrenFrontToBack, getDecomposition, getDrawingArea, getLayouter, getPreferredSize, getTransformRestoreData, invalidate, layout, remove, removeAll, removeAllChildren, removeChild, removeCompositeFigureListener, removeNotify, restoreTransformTo, sendToFront, setBounds, setLayouter, transform, validate
 
Methods inherited from class org.jhotdraw.draw.AbstractFigure
addFigureListener, basicClone, canConnect, changed, findCompatibleConnector, findConnector, fireAreaInvalidated, fireAreaInvalidated, fireAreaInvalidated, fireAttributeChanged, fireFigureAdded, fireFigureChanged, fireFigureChanged, fireFigureChanged, fireFigureHandlesChanged, fireFigureRemoved, fireFigureRequestRemove, getActions, getChangingDepth, getConnectors, getCursor, getEndPoint, getLayer, getStartPoint, getTool, getToolTipText, handleDrop, handleMouseClick, includes, isChanging, isRemovable, isSelectable, isTransformable, isVisible, remap, remap, removeFigureListener, requestRemove, setBounds, setRemovable, setSelectable, setTransformable, setVisible, toString, willChange
 
Methods inherited from class org.jhotdraw.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.draw.Drawing
add, add, addAll, addAll, basicAdd, basicAddAll, basicRemove, basicRemoveAll, getChildCount, remove, removeAll
 
Methods inherited from interface org.jhotdraw.draw.CompositeFigure
addCompositeFigureListener, basicRemoveAllChildren, getChild, getLayouter, layout, removeAllChildren, removeChild, removeCompositeFigureListener, setLayouter
 
Methods inherited from interface org.jhotdraw.draw.Figure
addFigureListener, addNotify, canConnect, changed, 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
 

Constructor Detail

QuadTreeDrawing

public QuadTreeDrawing()
Method Detail

indexOf

public int indexOf(Figure figure)
Description copied from interface: CompositeFigure
Returns the index of the specified child.

This is a convenience method for calling getChildren().indexOf(index);.

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

basicAdd

public void basicAdd(int index,
                     Figure figure)
Description copied from interface: CompositeFigure
Adds a child to the figure at the specified index without firing events.

This method can be used to reinsert a child figure which has been temporarily removed from this CompositeFigure (for example to reorder the sequence of the children) and to efficiently build a drawing from an InputFormat.

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

basicRemoveChild

public Figure basicRemoveChild(int index)
Description copied from interface: CompositeFigure
Removes the child at the specified index without firing events.

This method can be used to temporarily remove a child from this CompositeFigure (for example to reorder the sequence of the children).

Returns the removed child figure.

Specified by:
basicRemoveChild in interface CompositeFigure
Overrides:
basicRemoveChild in class AbstractCompositeFigure

draw

public void draw(java.awt.Graphics2D g)
Description copied from interface: Figure
Draws the figure.

Specified by:
draw in interface Drawing
Specified by:
draw in interface Figure
Overrides:
draw in class AbstractCompositeFigure
Parameters:
g - The Graphics2D to draw to.

sort

public java.util.List<Figure> sort(java.util.Collection<Figure> c)
Implementation note: Sorting can not be done for orphaned children.


draw

public void draw(java.awt.Graphics2D g,
                 java.util.Collection<Figure> c)

getChildren

public java.util.List<Figure> getChildren(java.awt.geom.Rectangle2D.Double bounds)

getChildren

public java.util.List<Figure> getChildren()
Description copied from interface: CompositeFigure
Returns an unchangeable list view on the children.

Specified by:
getChildren in interface CompositeFigure
Specified by:
getChildren in interface Drawing
Overrides:
getChildren in class AbstractCompositeFigure
Returns:
A Collection of Figure's.

findFigureInside

public Figure findFigureInside(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Returns the figure that contains the given point.

Specified by:
findFigureInside in interface Drawing
Specified by:
findFigureInside in interface Figure
Overrides:
findFigureInside in class AbstractCompositeFigure

getFiguresFrontToBack

public java.util.List<Figure> getFiguresFrontToBack()
Returns an iterator to iterate in Z-order front to back over the children.


findFigure

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


findFigureExcept

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


findFigureExcept

public Figure findFigureExcept(java.awt.geom.Point2D.Double p,
                               java.util.Collection ignore)
Description copied from interface: Drawing
Finds a top level Figure. Use this call for hit detection that should not descend into the figure's children.


findFigureBehind

public Figure findFigureBehind(java.awt.geom.Point2D.Double p,
                               Figure figure)
Description copied from interface: Drawing
Finds a top level Figure which is behind the specified Figure.


findFigureBehind

public Figure findFigureBehind(java.awt.geom.Point2D.Double p,
                               java.util.Collection<Figure> children)
Description copied from interface: Drawing
Finds a top level Figure which is behind the specified Figures.


findFigures

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


findFiguresWithin

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


bringToFront

public void bringToFront(Figure figure)
Description copied from interface: Drawing
Brings a figure to the front.

Parameters:
figure - that is part of the drawing

sendToBack

public void sendToBack(Figure figure)
Description copied from class: AbstractCompositeFigure
Sends a figure to the back of the composite figure.

Specified by:
sendToBack in interface Drawing
Overrides:
sendToBack in class AbstractCompositeFigure
Parameters:
figure - that is part of this composite figure

contains

public boolean contains(Figure f)
Description copied from interface: CompositeFigure
Returns true if this composite figure contains the specified figure.

This is a convenience method for calling getChildren().contains(f);.

Specified by:
contains in interface CompositeFigure
Overrides:
contains in class AbstractCompositeFigure

setAttributeOnChildren

protected void setAttributeOnChildren(AttributeKey key,
                                      java.lang.Object newValue)
Overrides:
setAttributeOnChildren in class AbstractAttributedCompositeFigure

setCanvasSize

public void setCanvasSize(Dimension2DDouble newValue)
Description copied from interface: Drawing
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:
newValue - The canvas size, or null.

getCanvasSize

public Dimension2DDouble getCanvasSize()
Description copied from interface: Drawing
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.

clone

public QuadTreeDrawing clone()
Description copied from interface: Figure
Returns a clone of the figure, with clones of all aggregated figures, such as chilrend and decorators. The cloned figure does not clone the list of FigureListeners from its original.

Specified by:
clone in interface Figure
Overrides:
clone in class AbstractAttributedCompositeFigure

createEventHandler

protected AbstractCompositeFigure.EventHandler createEventHandler()
Overrides:
createEventHandler in class AbstractCompositeFigure

drawFill

protected void drawFill(java.awt.Graphics2D g)
Description copied from class: AbstractAttributedCompositeFigure
This method is called by method draw() to draw the fill area of the figure. AttributedFigure configures the Graphics2D object with the FILL_COLOR attribute before calling this method. If the FILL_COLOR attribute is null, this method is not called.

Specified by:
drawFill in class AbstractAttributedCompositeFigure

drawStroke

protected void drawStroke(java.awt.Graphics2D g)
Description copied from class: AbstractAttributedCompositeFigure
This method is called by method draw() to draw the text of the figure . AttributedFigure configures the Graphics2D object with the TEXT_COLOR attribute before calling this method. If the TEXT_COLOR attribute is null, this method is not called.

Specified by:
drawStroke in class AbstractAttributedCompositeFigure

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