org.jdrawing
Class AbstractDrawingModelCache

java.lang.Object
  extended byorg.jdrawing.AbstractDrawingModelCache
All Implemented Interfaces:
DrawingModelCache
Direct Known Subclasses:
DefaultDrawingModelCache, GridDrawingModelCache, QuadTreeDrawingModelCache

public abstract class AbstractDrawingModelCache
extends java.lang.Object
implements DrawingModelCache

This abstract class provides default implementations for most of the methods in the DrawingModelCache interface. It takes care of the management of listeners and provides some conveniences for generating DrawingModelCacheEvents and dispatching them to the listeners. Also it provides some default handling of drawing model events.


Constructor Summary
AbstractDrawingModelCache()
           
 
Method Summary
 void addDrawingModelCacheListener(DrawingModelCacheListener listener)
          Adds a listener which will be notified about changes in this model cache.
protected  void elementsAdded(DrawingModelEvent event)
          Invoked after elements have been inserted into the model.
protected  void elementsChanged(DrawingModelEvent event)
          Invoked after elements have been changed in some way.
protected  void elementsRemoved(DrawingModelEvent event)
          Invoked after elements have been removed from the model.
protected  void fireAreaChanged(java.awt.Rectangle area)
          Notifies all listeners that the area has changed in some way.
protected  void fireDrawingChanged()
          Notifies all listeners that the drawing has changed in some way.
 DrawingModelCacheListener[] getDrawingModelCacheListeners()
          Returns an array of all the drawing model cache listeners registered on this model cache.
 DrawingModel getModel()
          Returns the DrawingModel that is cached by this cache.
 java.awt.Rectangle getModelBounds()
          Returns the bounding box of all elements of the model.
 DrawingRenderer getRenderer()
          Returns the DrawingRenderer that is used by this cache.
protected  void modelChanged(DrawingModelEvent event)
          Invoked after the model has drastically changed in some way.
 void removeDrawingModelCacheListener(DrawingModelCacheListener listener)
          Removes a listener from the list that is notified about changes in this model cache.
 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jdrawing.DrawingModelCache
getElementsForPoint, getElementsForRectangle, getModelBounds2D
 

Constructor Detail

AbstractDrawingModelCache

public AbstractDrawingModelCache()
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
Parameters:
model - the DrawingModel that is to be cached or null

getModel

public DrawingModel getModel()
Returns the DrawingModel that is cached by this cache. If no DrawingModel is cached by this cache, return null

Returns:
the DrawingModel that is cached by this cache, or null if no model is cached

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
Parameters:
renderer - the DrawingRenderer that is to be used

getRenderer

public DrawingRenderer getRenderer()
Returns the DrawingRenderer that is used by this cache. If no DrawingRenderer is used by this cache, return null

Returns:
the DrawingRenderer that is used by this cache, or null if not renderer is used

getModelBounds

public java.awt.Rectangle getModelBounds()
Description copied from interface: DrawingModelCache
Returns the bounding box of all elements of the model.

Specified by:
getModelBounds in interface DrawingModelCache
Returns:
the bounding box of all elements of the model

addDrawingModelCacheListener

public void addDrawingModelCacheListener(DrawingModelCacheListener listener)
Description copied from interface: DrawingModelCache
Adds a listener which will be notified about changes in this model cache.

Specified by:
addDrawingModelCacheListener in interface DrawingModelCache
Parameters:
listener - the DrawingModelCacheListener

removeDrawingModelCacheListener

public void removeDrawingModelCacheListener(DrawingModelCacheListener listener)
Description copied from interface: DrawingModelCache
Removes a listener from the list that is notified about changes in this model cache. If the listener is not in the list of is null then this method does nothing.

Specified by:
removeDrawingModelCacheListener in interface DrawingModelCache
Parameters:
listener - the DrawingModelCacheListener

getDrawingModelCacheListeners

public DrawingModelCacheListener[] getDrawingModelCacheListeners()
Returns an array of all the drawing model cache listeners registered on this model cache.

Returns:
all of this model's DrawingModelCacheListeners or an empty array if no drawing model cache listeners are currently registered

fireAreaChanged

protected void fireAreaChanged(java.awt.Rectangle area)
Notifies all listeners that the area has changed in some way.

Parameters:
area - rectangular bounds of the changed area
Throws:
java.lang.IllegalArgumentException - if area is null

fireDrawingChanged

protected void fireDrawingChanged()
Notifies all listeners that the drawing has changed in some way.


elementsAdded

protected void elementsAdded(DrawingModelEvent event)
Invoked after elements have been inserted into the model. Notifies all listeners that the area occupied by the inserted element have been changed. Do not call this method directly.

Parameters:
event - DrawingModelEvent object encapsulating event information

elementsRemoved

protected void elementsRemoved(DrawingModelEvent event)
Invoked after elements have been removed from the model. Notifies all listeners that the area occupied by the removed element have been changed. Do not call this method directly.

Parameters:
event - DrawingModelEvent object encapsulating event information

elementsChanged

protected void elementsChanged(DrawingModelEvent event)
Invoked after elements have been changed in some way. Notifies all listeners that drawing has changed. Do not call this method directly.

Parameters:
event - DrawingModelEvent object encapsulating event information

modelChanged

protected void modelChanged(DrawingModelEvent event)
Invoked after the model has drastically changed in some way. Notifies all listeners that drawing has changed. Do not call this method directly.

Parameters:
event - DrawingModelEvent object encapsulating event information