org.jdrawing
Class GridDrawingModelCache

java.lang.Object
  extended byorg.jdrawing.AbstractDrawingModelCache
      extended byorg.jdrawing.GridDrawingModelCache
All Implemented Interfaces:
DrawingModelCache, DrawingModelListener, java.util.EventListener

public class GridDrawingModelCache
extends AbstractDrawingModelCache
implements DrawingModelListener

This implementation of DrawingModelCache optimizes drawing operations by splitting all the drawing area into rectangular cells and caching elements intersecting each cell.


Constructor Summary
GridDrawingModelCache()
           
 
Method Summary
 void elementsAdded(DrawingModelEvent event)
          Invoked after elements have been inserted into the model.
 void elementsChanged(DrawingModelEvent event)
          Invoked after elements have been changed in some way.
 void elementsRemoved(DrawingModelEvent event)
          Invoked after elements have been removed from the model.
 java.awt.Dimension getCellSize()
          Return size of cells used by this cache.
 java.lang.Object[] getElementsForPoint(java.awt.geom.Point2D point)
          Returns elements which contain a given point.
 java.lang.Object[] getElementsForRectangle(java.awt.geom.Rectangle2D rectangle)
          Returns elements neccessary for repainting given area. Elements are returned in order suitable for painting.
 java.awt.geom.Rectangle2D getModelBounds2D()
          Returns the high precision bounding box of all elements of the model.
 void modelChanged(DrawingModelEvent event)
          Invoked after the model has drastically changed in some way.
 void setCellSize(java.awt.Dimension cellSize)
          Set size for rectangular cells.
 void setModel(DrawingModel model)
          Sets the DrawingModel that will be cached by this cache.
 void setRenderer(DrawingRenderer renderer)
          Sets the DrawingRenderer that will be used in this cache.
 
Methods inherited from class org.jdrawing.AbstractDrawingModelCache
addDrawingModelCacheListener, fireAreaChanged, fireDrawingChanged, getDrawingModelCacheListeners, getModel, getModelBounds, getRenderer, removeDrawingModelCacheListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridDrawingModelCache

public GridDrawingModelCache()
Method Detail

setModel

public void setModel(DrawingModel model)
Description copied from interface: DrawingModelCache
Sets the DrawingModel that will be cached by this cache. If model is null, then set this DrawingModelCache to do not cache any DrawingModel.

Specified by:
setModel in interface DrawingModelCache
Overrides:
setModel in class AbstractDrawingModelCache

setRenderer

public void setRenderer(DrawingRenderer renderer)
Description copied from interface: DrawingModelCache
Sets the DrawingRenderer that will be used in this cache. If renderer is null, then set this DrawingModelCache to do not use any DrawingRenderer. Renderer is used to obtain the bounds of an element of the model.

Specified by:
setRenderer in interface DrawingModelCache
Overrides:
setRenderer in class AbstractDrawingModelCache

setCellSize

public void setCellSize(java.awt.Dimension cellSize)
Set size for rectangular cells. By default size of the cells is 256x256 pixels

Parameters:
cellSize - new size for cells
Throws:
java.lang.IllegalArgumentException - if cellSize is null

getCellSize

public java.awt.Dimension getCellSize()
Return size of cells used by this cache.

Returns:
current size of cells

getModelBounds2D

public java.awt.geom.Rectangle2D getModelBounds2D()
Description copied from interface: DrawingModelCache
Returns the high precision bounding box of all elements of the model.

Specified by:
getModelBounds2D in interface DrawingModelCache
Returns:
the high precision bounding box of all elements of the model

getElementsForRectangle

public java.lang.Object[] getElementsForRectangle(java.awt.geom.Rectangle2D rectangle)
Returns elements neccessary for repainting given area. Elements are returned in order suitable for painting.

Specified by:
getElementsForRectangle in interface DrawingModelCache
Parameters:
rectangle - area that will be repainted
Returns:
elements neccessary for repainting
Throws:
java.lang.IllegalArgumentException - if rectangle is null

getElementsForPoint

public java.lang.Object[] getElementsForPoint(java.awt.geom.Point2D point)
Description copied from interface: DrawingModelCache
Returns elements which contain a given point. Elements are returned in order, suitable for painting.

Specified by:
getElementsForPoint in interface DrawingModelCache
Parameters:
point - the Point2D return elements containing given point

elementsAdded

public void elementsAdded(DrawingModelEvent event)
Description copied from interface: DrawingModelListener
Invoked after elements have been inserted into the model.

Specified by:
elementsAdded in interface DrawingModelListener
Overrides:
elementsAdded in class AbstractDrawingModelCache
Parameters:
event - DrawingModelEvent object encapsulating event information

elementsRemoved

public void elementsRemoved(DrawingModelEvent event)
Description copied from interface: DrawingModelListener
Invoked after elements have been removed from the model.

Specified by:
elementsRemoved in interface DrawingModelListener
Overrides:
elementsRemoved in class AbstractDrawingModelCache
Parameters:
event - DrawingModelEvent object encapsulating event information

elementsChanged

public void elementsChanged(DrawingModelEvent event)
Description copied from interface: DrawingModelListener
Invoked after elements have been changed in some way.

Specified by:
elementsChanged in interface DrawingModelListener
Overrides:
elementsChanged in class AbstractDrawingModelCache
Parameters:
event - DrawingModelEvent object encapsulating event information

modelChanged

public void modelChanged(DrawingModelEvent event)
Description copied from interface: DrawingModelListener
Invoked after the model has drastically changed in some way.

Specified by:
modelChanged in interface DrawingModelListener
Overrides:
modelChanged in class AbstractDrawingModelCache
Parameters:
event - DrawingModelEvent object encapsulating event information