org.jfree.report.style
Class StyleSheetCollection

java.lang.Object
  extended byorg.jfree.report.style.StyleSheetCollection
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class StyleSheetCollection
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

The StyleSheet collection is assigned to all Elements, all StyleSheets and to the JFreeReport and the ReportDefinition objects. This collection is used to coordinate the deep cloning of the stylesheets of an report. As bonus functionality it allows simplified access to the stylesheets.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
StyleSheetCollection()
          DefaultConstructor.
 
Method Summary
protected  void addParents(ElementStyleSheet es)
          Adds all parents of the given stylesheet recursivly to this collection.
 void addStyleSheet(ElementStyleSheet es)
          Adds the given stylesheet to this collection.
protected  void addStyleSheet(ElementStyleSheet es, boolean updateRefs)
          Adds the given stylesheet to this collection.
 java.lang.Object clone()
          Clones this stylesheet collection and all stylesheets contained in that collection.
 ElementStyleSheet[] getAll(java.lang.String name)
          Returns all stylesheets for a given name or null, if there is no such stylesheet registered.
 ElementStyleSheet getFirst(java.lang.String name)
          Returns the first element stylesheet with that name.
 java.util.Iterator keys()
          Returns the names of all registered stylesheets as iterator.
 boolean remove(ElementStyleSheet es)
          Returns true, if removing the stylesheet was successfull, false if the stylesheet is still referenced and will not be removed.
protected  boolean remove(ElementStyleSheet es, boolean update)
          Returns true, if the stylesheet if removing was successfull, false if the stylesheet is still referenced and won't be removed.
protected  void updateReferences()
          Updates the reference count of all stylesheets.
 void updateStyleSheet(ElementStyleSheet es)
          Updates a stylesheet reference from this collection.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StyleSheetCollection

public StyleSheetCollection()
DefaultConstructor.

Method Detail

addStyleSheet

public void addStyleSheet(ElementStyleSheet es)
Adds the given stylesheet to this collection. This throw an IllegalArgumentException if the stylesheet is already added to another stylesheet collection.

Parameters:
es - the element stylesheet
Throws:
java.lang.NullPointerException - if the given stylesheet is null.

addStyleSheet

protected void addStyleSheet(ElementStyleSheet es,
                             boolean updateRefs)
Adds the given stylesheet to this collection. This throw an IllegalArgumentException if the stylesheet is already added to another stylesheet collection.

Parameters:
es - the element stylesheet that should be added.
updateRefs - true, if the reference counts should be recomputed, false otherwise.
Throws:
java.lang.IllegalStateException - if the stylesheet is already added, but has a different stylesheet collection assigned.
java.lang.NullPointerException - if the given element stylesheet is null.

getAll

public ElementStyleSheet[] getAll(java.lang.String name)
Returns all stylesheets for a given name or null, if there is no such stylesheet registered.

Parameters:
name - the name of the stylesheet.
Returns:
the found stylesheets as object array or null.

getFirst

public ElementStyleSheet getFirst(java.lang.String name)
Returns the first element stylesheet with that name.

Parameters:
name - the name of the searched stylesheet.
Returns:
the stylesheet or null, if there is no such stylesheet.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones this stylesheet collection and all stylesheets contained in that collection. The stylesheets of this collection get cloned and reassigned after the cloning.

Returns:
the cloned collection.
Throws:
java.lang.CloneNotSupportedException - if cloning failed.

updateStyleSheet

public void updateStyleSheet(ElementStyleSheet es)
Updates a stylesheet reference from this collection. This is usually done after a clone() operation to update the parents of the given element stylesheet.

This operation will remove all parents of the stylesheet and repace them with stylesheets from this collection with the same name and Id.

Parameters:
es - the elements stylesheet that should be replaced.

addParents

protected void addParents(ElementStyleSheet es)
Adds all parents of the given stylesheet recursivly to this collection.

Parameters:
es - the element style sheet whose parents should be added.

updateReferences

protected void updateReferences()
Updates the reference count of all stylesheets. This method is expensive and is (like the whole class) a candidate for an performance redesign ...


remove

public boolean remove(ElementStyleSheet es)
Returns true, if removing the stylesheet was successfull, false if the stylesheet is still referenced and will not be removed.

Parameters:
es - the element stylesheet that should be removed.
Returns:
true, if the stylesheet was removed, false otherwise.

remove

protected boolean remove(ElementStyleSheet es,
                         boolean update)
Returns true, if the stylesheet if removing was successfull, false if the stylesheet is still referenced and won't be removed.

Parameters:
update - true, if the reference counts should be updated, false otherwise.
es - the element stylesheet that should be removed.
Returns:
true, if the stylesheet was removed, false otherwise.

keys

public java.util.Iterator keys()
Returns the names of all registered stylesheets as iterator. There can be more than one stylesheet be registered with a certain name.

Returns:
the names of all stylesheets.