org.jdrawing
Class LayeredDrawingModel

java.lang.Object
  extended byorg.jdrawing.AbstractDrawingModel
      extended byorg.jdrawing.LayeredDrawingModel
All Implemented Interfaces:
DrawingModel

public class LayeredDrawingModel
extends AbstractDrawingModel

This implementation of DrawingModel interface allows user to specify layer for each element. Elements will be sorted by layer before painting


Constructor Summary
LayeredDrawingModel()
           
 
Method Summary
 void addElement(java.lang.Object element)
          Adds new element to the model at layer zero.
 void addElement(java.lang.Object element, int layer)
          Adds new element to the model at given layer.
 java.util.Enumeration elements()
          Returns an enumeration of the elements of this model.
 int getElementLayer(java.lang.Object element)
          Returns current layer of the element.
 void removeElement(java.lang.Object element)
          Remove element from the model.
 void setElementLayer(java.lang.Object element, int layer)
          Sets layer for element.
 void sortElements(java.lang.Object[] elements)
          Reorder elements to be in order suitable for painting. This implementation sorts elements by layer.
 void updateElement(java.lang.Object element)
          Notify all listeners that element has changed.
 
Methods inherited from class org.jdrawing.AbstractDrawingModel
addDrawingModelListener, fireElementsAdded, fireElementsChanged, fireElementsRemoved, fireModelChanged, getDrawingModelListeners, removeDrawingModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LayeredDrawingModel

public LayeredDrawingModel()
Method Detail

addElement

public void addElement(java.lang.Object element)
Adds new element to the model at layer zero.

Parameters:
element - element to be added to the model

addElement

public void addElement(java.lang.Object element,
                       int layer)
Adds new element to the model at given layer.

Parameters:
element - element to be added to the model

removeElement

public void removeElement(java.lang.Object element)
Remove element from the model.

Parameters:
element - element to be removed from the model

updateElement

public void updateElement(java.lang.Object element)
Notify all listeners that element has changed.

Parameters:
element - changed element

elements

public java.util.Enumeration elements()
Description copied from interface: DrawingModel
Returns an enumeration of the elements of this model. The returned Enumeration object will generate all elements in this model. The elements will be generated by this enumeration in order suitable for painting.

Returns:
an enumeration of the elements of this model

sortElements

public void sortElements(java.lang.Object[] elements)
Reorder elements to be in order suitable for painting. This implementation sorts elements by layer.

Parameters:
elements - the elements to reorder

setElementLayer

public void setElementLayer(java.lang.Object element,
                            int layer)
Sets layer for element.

Parameters:
element - element to be moved to another layer
layer - new layer for the element

getElementLayer

public int getElementLayer(java.lang.Object element)
Returns current layer of the element.

Returns:
current layer of the element