com.jrefinery.report.targets.style
Class ElementStyleSheet

java.lang.Object
  |
  +--com.jrefinery.report.targets.style.ElementStyleSheet
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, StyleChangeListener
Direct Known Subclasses:
BandStyleSheet, ElementDefaultStyleSheet

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

An element style-sheet contains zero, one or many attributes that affect the appearance of report elements. For each attribute, there is a predefined key that can be used to access that attribute in the style sheet.

Every report element has an associated style-sheet.

A style-sheet maintains a list of parent style-sheets. If an attribute is not defined in a style-sheet, the code refers to the parent style-sheets to see if the attribute is defined there.

All StyleSheet entries are checked against the StyleKeyDefinition for validity.

Author:
Thomas Morgner
See Also:
Serialized Form

Field Summary
static StyleKey ALIGNMENT
          A key for the horizontal alignment of an element.
static StyleKey BOLD
          A key for an element's 'bold' flag.
static StyleKey BOUNDS
          A key for the 'bounds' of an element.
static StyleKey DYNAMIC_HEIGHT
          A key for the dynamic height flag for an element.
static StyleKey ELEMENT_LAYOUT_CACHEABLE
          The Layout Cacheable stylekey.
static StyleKey EMBEDDED_FONT
          A key for an element's 'embedd' flag.
static StyleKey FONT
          A key for the 'font name' used to draw element text.
static StyleKey FONTENCODING
          A key for an element's 'embedd' flag.
static StyleKey FONTSIZE
          A key for the 'font size' used to draw element text.
static StyleKey ITALIC
          A key for an element's 'italic' flag.
static StyleKey KEEP_ASPECT_RATIO
          A key for an element's 'keep aspect ratio' flag.
static StyleKey LINEHEIGHT
          A key for the 'font size' used to draw element text.
static StyleKey MAXIMUMSIZE
          A key for the 'maximum size' of an element.
static StyleKey MINIMUMSIZE
          A key for the 'minimum size' of an element.
static StyleKey PAINT
          A key for the 'paint' used to color an element.
static StyleKey PREFERREDSIZE
          A key for the 'preferred size' of an element.
static StyleKey SCALE
          A key for an element's 'scale' flag.
static StyleKey STRIKETHROUGH
          A key for an element's 'strikethrough' flag.
static StyleKey STROKE
          A key for the 'stroke' used to draw an element.
static StyleKey UNDERLINED
          A key for an element's 'underlined' flag.
static StyleKey VALIGNMENT
          A key for the vertical alignment of an element.
static StyleKey VISIBLE
          A key for an element's 'visible' flag.
 
Constructor Summary
ElementStyleSheet(java.lang.String name)
          Creates a new element style-sheet with the given name.
 
Method Summary
 void addDefaultParent(ElementStyleSheet parent)
          Adds a parent style-sheet.
 void addDefaultParent(int position, ElementStyleSheet parent)
          Adds a parent style-sheet.
 void addListener(StyleChangeListener l)
          Adds a StyleChangeListener.
 void addParent(ElementStyleSheet parent)
          Adds a parent style-sheet.
 void addParent(int position, ElementStyleSheet parent)
          Adds a parent style-sheet.
 java.lang.Object clone()
          Creates and returns a copy of this object.
 boolean equals(java.lang.Object o)
           
 boolean getBooleanStyleProperty(StyleKey key)
          Returns a boolean style (defaults to false if the style is not found).
 boolean getBooleanStyleProperty(StyleKey key, boolean defaultValue)
          Returns a boolean style.
 ElementStyleSheet getCopy()
          Clones the style-sheet.
 java.util.List getDefaultParents()
          Returns a list of the default style-sheets.
 java.util.Iterator getDefinedPropertyNames()
          Returns an enumeration of all local property keys.
 FontDefinition getFontDefinitionProperty()
          Returns the font for this style-sheet.
 java.awt.Font getFontStyleProperty()
          Deprecated. use getFontDefinition()
 InstanceID getId()
           
 int getIntStyleProperty(StyleKey key, int def)
          Returns an integer style.
 java.lang.String getName()
          Returns the name of the style-sheet.
 java.util.List getParents()
          Returns a list of the parent style-sheets.
 java.lang.Object getStyleProperty(StyleKey key)
          Returns the value of a style.
 java.lang.Object getStyleProperty(StyleKey key, java.lang.Object defaultValue)
          Returns the value of a style.
 StyleSheetCollection getStyleSheetCollection()
          Returns the stylesheet collection of this element stylesheet, or null, if this stylessheet is not assigned with an collection.
 int hashCode()
           
 boolean isAllowCaching()
          Returns true if caching is allowed, and false otherwise.
 boolean isSubStyleSheet(ElementStyleSheet parent)
          Checks, whether the given element stylesheet is already added as child into the stylesheet tree.
 void removeDefaultParent(ElementStyleSheet parent)
          Removes a parent style-sheet.
 void removeListener(StyleChangeListener l)
          Removes a StyleChangeListener.
 void removeParent(ElementStyleSheet parent)
          Removes a parent style-sheet.
 void setAllowCaching(boolean allowCaching)
          Sets the flag that controls whether or not caching is allowed.
 void setBooleanStyleProperty(StyleKey key, boolean value)
          Sets a boolean style property.
 void setFontDefinitionProperty(FontDefinition font)
          Sets the font for this style-sheet.
 void setFontStyleProperty(java.awt.Font font)
          Deprecated. use setFontDefinition()
 void setStyleProperty(StyleKey key, java.lang.Object value)
          Sets a style property (or removes the style if the value is null).
 void setStyleSheetCollection(StyleSheetCollection styleSheetCollection)
          Defines the stylesheet collection for this stylesheet.
 void styleChanged(ElementStyleSheet source, StyleKey key, java.lang.Object value)
          Sends a change event notification to all registered StyleChangeListener objects.
 void styleRemoved(ElementStyleSheet source, StyleKey key)
          Sends a change event notification to all registered StyleChangeListener objects.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MINIMUMSIZE

public static final StyleKey MINIMUMSIZE
A key for the 'minimum size' of an element.


MAXIMUMSIZE

public static final StyleKey MAXIMUMSIZE
A key for the 'maximum size' of an element.


PREFERREDSIZE

public static final StyleKey PREFERREDSIZE
A key for the 'preferred size' of an element.


BOUNDS

public static final StyleKey BOUNDS
A key for the 'bounds' of an element.


VISIBLE

public static final StyleKey VISIBLE
A key for an element's 'visible' flag.


PAINT

public static final StyleKey PAINT
A key for the 'paint' used to color an element.


STROKE

public static final StyleKey STROKE
A key for the 'stroke' used to draw an element.


FONT

public static final StyleKey FONT
A key for the 'font name' used to draw element text.


FONTSIZE

public static final StyleKey FONTSIZE
A key for the 'font size' used to draw element text.


LINEHEIGHT

public static final StyleKey LINEHEIGHT
A key for the 'font size' used to draw element text.


BOLD

public static final StyleKey BOLD
A key for an element's 'bold' flag.


ITALIC

public static final StyleKey ITALIC
A key for an element's 'italic' flag.


UNDERLINED

public static final StyleKey UNDERLINED
A key for an element's 'underlined' flag.


STRIKETHROUGH

public static final StyleKey STRIKETHROUGH
A key for an element's 'strikethrough' flag.


EMBEDDED_FONT

public static final StyleKey EMBEDDED_FONT
A key for an element's 'embedd' flag.


FONTENCODING

public static final StyleKey FONTENCODING
A key for an element's 'embedd' flag.


ALIGNMENT

public static final StyleKey ALIGNMENT
A key for the horizontal alignment of an element.


VALIGNMENT

public static final StyleKey VALIGNMENT
A key for the vertical alignment of an element.


SCALE

public static final StyleKey SCALE
A key for an element's 'scale' flag.


KEEP_ASPECT_RATIO

public static final StyleKey KEEP_ASPECT_RATIO
A key for an element's 'keep aspect ratio' flag.


DYNAMIC_HEIGHT

public static final StyleKey DYNAMIC_HEIGHT
A key for the dynamic height flag for an element.


ELEMENT_LAYOUT_CACHEABLE

public static final StyleKey ELEMENT_LAYOUT_CACHEABLE
The Layout Cacheable stylekey. Set this stylekey to false, to define that the element is not cachable. This key defaults to true.

Constructor Detail

ElementStyleSheet

public ElementStyleSheet(java.lang.String name)
Creates a new element style-sheet with the given name. The style-sheet initially contains no attributes, and has no parent style-sheets.

Parameters:
name - the name (null not permitted).
Method Detail

isAllowCaching

public boolean isAllowCaching()
Returns true if caching is allowed, and false otherwise.

Returns:
A boolean.

setAllowCaching

public void setAllowCaching(boolean allowCaching)
Sets the flag that controls whether or not caching is allowed.

Parameters:
allowCaching - the flag value.

getName

public java.lang.String getName()
Returns the name of the style-sheet.

Returns:
the name (never null).

addParent

public void addParent(ElementStyleSheet parent)
Adds a parent style-sheet. This method adds the parent to the beginning of the list, and guarantees, that this parent is queried first.

Parameters:
parent - the parent (null not permitted).

addDefaultParent

public void addDefaultParent(ElementStyleSheet parent)
Adds a parent style-sheet. This method adds the parent to the beginning of the list, and guarantees, that this parent is queried first.

The default parents operations are reserved for the system internal stylesheet operations. If you want to add own stylesheets, use the addParent methods.

Parameters:
parent - the parent (null not permitted).

addParent

public void addParent(int position,
                      ElementStyleSheet parent)
Adds a parent style-sheet. Parents on a lower position are queried before any parent with an higher position in the list.

Parameters:
position - the position where to insert the parent style sheet
parent - the parent (null not permitted).
Throws:
java.lang.IndexOutOfBoundsException - if the position is invalid (pos < 0 or pos >= numberOfParents)

addDefaultParent

public void addDefaultParent(int position,
                             ElementStyleSheet parent)
Adds a parent style-sheet. Parents on a lower position are queried before any parent with an higher position in the list.

The default parents operations are reserved for the system internal stylesheet operations. If you want to add own stylesheets, use the addParent methods.

Only default style sheets should be added with this method.

Parameters:
position - the position where to insert the parent style sheet
parent - the parent (null not permitted).
Throws:
java.lang.IndexOutOfBoundsException - if the position is invalid (pos < 0 or pos >= numberOfParents)

isSubStyleSheet

public boolean isSubStyleSheet(ElementStyleSheet parent)
Checks, whether the given element stylesheet is already added as child into the stylesheet tree.

Parameters:
parent - the element that should be tested.
Returns:
true, if the element is a child of this element style sheet, false otherwise.

removeParent

public void removeParent(ElementStyleSheet parent)
Removes a parent style-sheet.

Parameters:
parent - the style-sheet to remove (null not permitted).

removeDefaultParent

public void removeDefaultParent(ElementStyleSheet parent)
Removes a parent style-sheet.

Parameters:
parent - the style-sheet to remove (null not permitted).

getParents

public java.util.List getParents()
Returns a list of the parent style-sheets.

The list is unmodifiable.

Returns:
the list.

getDefaultParents

public java.util.List getDefaultParents()
Returns a list of the default style-sheets.

The list is unmodifiable.

Returns:
the list.

getStyleProperty

public java.lang.Object getStyleProperty(StyleKey key)
Returns the value of a style. If the style is not found in this style-sheet, the code looks in the parent style-sheets. If the style is not found in any of the parent style-sheets, then null is returned.

Parameters:
key - the style key.
Returns:
the value.

getStyleProperty

public java.lang.Object getStyleProperty(StyleKey key,
                                         java.lang.Object defaultValue)
Returns the value of a style. If the style is not found in this style-sheet, the code looks in the parent style-sheets. If the style is not found in any of the parent style-sheets, then the default value (possibly null) is returned.

Parameters:
key - the style key.
defaultValue - the default value (null permitted).
Returns:
the value.

setBooleanStyleProperty

public void setBooleanStyleProperty(StyleKey key,
                                    boolean value)
Sets a boolean style property.

Parameters:
key - the style key (null not permitted).
value - the value.
Throws:
java.lang.NullPointerException - if the given key is null.
java.lang.ClassCastException - if the value cannot be assigned with the given key.

setStyleProperty

public void setStyleProperty(StyleKey key,
                             java.lang.Object value)
Sets a style property (or removes the style if the value is null).

Parameters:
key - the style key (null not permitted).
value - the value.
Throws:
java.lang.NullPointerException - if the given key is null.
java.lang.ClassCastException - if the value cannot be assigned with the given key.

getCopy

public ElementStyleSheet getCopy()
Clones the style-sheet. The assigned parent style sheets are not cloned. The stylesheets are not assigned to the contained stylesheet collection, you have to reassign them manually ...

Returns:
the clone.

getBooleanStyleProperty

public boolean getBooleanStyleProperty(StyleKey key)
Returns a boolean style (defaults to false if the style is not found).

Parameters:
key - the style key.
Returns:
true or false.

getBooleanStyleProperty

public boolean getBooleanStyleProperty(StyleKey key,
                                       boolean defaultValue)
Returns a boolean style.

Parameters:
key - the style key.
defaultValue - the default value.
Returns:
true or false.

getIntStyleProperty

public int getIntStyleProperty(StyleKey key,
                               int def)
Returns an integer style.

Parameters:
key - the style key.
def - the default value.
Returns:
the style value.

getFontStyleProperty

public java.awt.Font getFontStyleProperty()
Deprecated. use getFontDefinition()

Returns the font for this style-sheet.

Returns:
the font.

setFontStyleProperty

public void setFontStyleProperty(java.awt.Font font)
Deprecated. use setFontDefinition()

Sets the font for this style-sheet.

Parameters:
font - the font (null not permitted).

getFontDefinitionProperty

public FontDefinition getFontDefinitionProperty()
Returns the font for this style-sheet.

Returns:
the font.

setFontDefinitionProperty

public void setFontDefinitionProperty(FontDefinition font)
Sets the font for this style-sheet.

Parameters:
font - the font (null not permitted).

getDefinedPropertyNames

public java.util.Iterator getDefinedPropertyNames()
Returns an enumeration of all local property keys.

Returns:
an enumeration of all localy defined style property keys.

addListener

public void addListener(StyleChangeListener l)
Adds a StyleChangeListener.

Parameters:
l - the listener.

removeListener

public void removeListener(StyleChangeListener l)
Removes a StyleChangeListener.

Parameters:
l - the listener.

styleChanged

public void styleChanged(ElementStyleSheet source,
                         StyleKey key,
                         java.lang.Object value)
Sends a change event notification to all registered StyleChangeListener objects.

Specified by:
styleChanged in interface StyleChangeListener
Parameters:
source - the source of the change.
key - the style key.
value - the new value.

styleRemoved

public void styleRemoved(ElementStyleSheet source,
                         StyleKey key)
Sends a change event notification to all registered StyleChangeListener objects.

Specified by:
styleRemoved in interface StyleChangeListener
Parameters:
source - the source of the change.
key - the style key.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

clone

public java.lang.Object clone()
Creates and returns a copy of this object. This method calls getCopy().

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
See Also:
Cloneable

getStyleSheetCollection

public StyleSheetCollection getStyleSheetCollection()
Returns the stylesheet collection of this element stylesheet, or null, if this stylessheet is not assigned with an collection.

Returns:
the collection or null.

setStyleSheetCollection

public void setStyleSheetCollection(StyleSheetCollection styleSheetCollection)
Defines the stylesheet collection for this stylesheet.

Parameters:
styleSheetCollection -

getId

public InstanceID getId()
Returns:
the ID of this stylesheet.