lt.monarch.chart.style
Class Stylesheet

java.lang.Object
  extended by lt.monarch.chart.style.Stylesheet
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Style

public class Stylesheet
extends java.lang.Object
implements java.io.Serializable

Stylesheet is a simple in-memory database, designed to store rendering entityStyle, such as color, font, etc.
Warning: When running under Java 1.1 stylesheet listeners do not chain together parent-child style sheets. Java 1.1 lacks weak references, and stylesheet listener usage would result in huge memory leaks.
Please see user guide for complete description of style sheets.

Internal chart objects make use of these stylesheet keys in various combinations:

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
static Stylesheet defaultStylesheet
          the default Stylesheet
static java.lang.Object inheritedValue
          A value place holder to be used in the setXXX methods.
protected static java.lang.Object nullValue
          specifies null value
protected  DefaultListenerList<StylesheetListener> stylesheetListeners
           
protected  ListenerList<StylesheetListener> weakStylesheetListeners
           
 
Constructor Summary
Constructor and Description
Stylesheet()
          Constructs empty Stylesheet.
 
Method Summary
Modifier and Type Method and Description
 void addListener(StylesheetListener listener)
          Registers a stylesheet listener
 void addWeakListener(StylesheetListener listener)
          Registers a weak stylesheet listener.
protected  java.util.Hashtable<Key,java.lang.Object> defaultRead(java.io.ObjectInputStream in, java.util.Hashtable<Key,java.lang.Object> styleSettings)
          Default read of serialization
protected  void defaultWrite(java.io.ObjectOutputStream out, java.util.Hashtable<Key,java.lang.Object> styleSettings)
          Default serialization write
 void dispose()
          Cleans this stylesheet object.
protected  void finalize()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
protected  java.lang.Object findValue(java.lang.String tag, java.lang.String attribute)
          Finds and returns a property.
protected  void fireStylesheetChanged()
          Notifies all listeners that stylesheet changed.
protected  void fireStylesheetKeyChanged(Key key)
          Notifies all listeners that value correspondent to specified key in the stylesheet changed.
 java.awt.Color getBackground(java.lang.String tag)
          Finds and returns a background property.
 java.awt.Color getColor(java.lang.String tag, java.lang.String attribute)
          Finds and returns a color property.
 java.lang.Object getComposite(java.lang.String tag)
          Finds and returns a composite property.
 java.lang.String getContext()
          Returns a textual stylesheet context.
 java.lang.StringBuilder getContext(java.lang.StringBuilder stringBuilder)
          Returns a textual stylesheet context appended to a StringBuilder.
 int getFlag(java.lang.String tag, java.lang.String attribute)
          Finds and returns a integer flag property.
 java.awt.Font getFont(java.lang.String tag)
          Finds and returns a font property.
 java.awt.Color getForeground(java.lang.String tag)
          Finds and returns a foreground property.
 java.lang.Object getObject(java.lang.String tag, java.lang.String attribute)
          Finds and returns a property.
 java.lang.Object getPaint()
          Finds and returns a Paint property.
 java.lang.Object getPaint(java.lang.String tag)
          Finds and returns a Paint property.
 Stylesheet getParentStylesheet()
          Returns the parent stylesheet in the stylesheet hierarchy
 StyleObject getProperty(java.lang.String tag, java.lang.String attribute)
          Gets property enumeration value
 java.lang.Object getRenderingHints(java.lang.String tag)
          Finds and returns a rendering hints property.
 java.lang.Object getStroke(java.lang.String tag)
          Finds and returns a stroke property.
 void removeListener(StylesheetListener listener)
          Unregisters a stylesheet listener
 void removeWeakListener(StylesheetListener listener)
          Unregisters a weak stylesheet listener.
 void resumeListeners()
          Resumes all listeners
 void setBackground(java.lang.String tag, java.awt.Color color)
          Sets the background property in the stylesheet.
 void setColor(java.lang.String tag, java.lang.String attribute, java.awt.Color color)
          Sets the color property in the stylesheet.
 void setComposite(java.lang.String tag, java.awt.Composite c)
          Sets the composite property in the stylesheet.
 void setFlag(java.lang.String tag, java.lang.String attribute, int value)
          Sets the integer flag property in the stylesheet.
 void setFont(java.lang.String tag, java.awt.Font font)
          Sets the font property in the stylesheet.
 void setForeground(java.lang.String tag, java.awt.Color color)
          Sets the foreground property in the stylesheet.
 void setObject(java.lang.String tag, java.lang.String attribute, java.lang.Object value)
          Sets any property in the stylesheet.
 void setPaint(java.awt.Paint paint)
          Sets paint property in the stylesheet.
 void setPaint(java.awt.Paint paint, java.lang.String tag)
          Sets paint property in the stylesheet.
 void setProperty(java.lang.String tag, java.lang.String attribute, StyleObject property)
          Sets enumeration property to the stylesheet
 void setRenderingHints(java.lang.String tag, java.awt.RenderingHints c)
          Sets the rendering hints property in the stylesheet.
 void setStroke(java.lang.String tag, java.awt.Stroke c)
          Sets the stroke property in the stylesheet.
protected  void setValue(java.lang.String tag, java.lang.String attribute, java.lang.Object value)
          Sets any property in the stylesheet.
 void suspendListeners()
          Suspends all listeners, which later can be resumed
 java.lang.String toString()
          Returns the String representation of this Stylesheet object.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nullValue

protected static final java.lang.Object nullValue
specifies null value


inheritedValue

public static final java.lang.Object inheritedValue
A value place holder to be used in the setXXX methods. It states that a corresponding attribute has to be taken from the parent stylesheet.


defaultStylesheet

public static final Stylesheet defaultStylesheet
the default Stylesheet


stylesheetListeners

protected transient DefaultListenerList<StylesheetListener> stylesheetListeners

weakStylesheetListeners

protected transient ListenerList<StylesheetListener> weakStylesheetListeners
Constructor Detail

Stylesheet

public Stylesheet()
Constructs empty Stylesheet.

Method Detail

getParentStylesheet

public Stylesheet getParentStylesheet()
Returns the parent stylesheet in the stylesheet hierarchy

Returns:
parent stylesheet

addListener

public void addListener(StylesheetListener listener)
Registers a stylesheet listener

Parameters:
listener - stylesheet listener

removeListener

public void removeListener(StylesheetListener listener)
Unregisters a stylesheet listener

Parameters:
listener - stylesheet listener

addWeakListener

public void addWeakListener(StylesheetListener listener)
Registers a weak stylesheet listener.

Parameters:
listener - a weak stylesheet listener

removeWeakListener

public void removeWeakListener(StylesheetListener listener)
Unregisters a weak stylesheet listener.

Parameters:
listener - a weak stylesheet listener

fireStylesheetChanged

protected void fireStylesheetChanged()
Notifies all listeners that stylesheet changed.


fireStylesheetKeyChanged

protected void fireStylesheetKeyChanged(Key key)
Notifies all listeners that value correspondent to specified key in the stylesheet changed.

Parameters:
key - the key

setComposite

public void setComposite(java.lang.String tag,
                         java.awt.Composite c)
Sets the composite property in the stylesheet. It is stored under the "composite" attribute name.

Parameters:
tag - property tag
c - composite object

setStroke

public void setStroke(java.lang.String tag,
                      java.awt.Stroke c)
Sets the stroke property in the stylesheet. It is stored under the "stroke" attribute name.

Parameters:
tag - property tag
c - stroke object

setRenderingHints

public void setRenderingHints(java.lang.String tag,
                              java.awt.RenderingHints c)
Sets the rendering hints property in the stylesheet. It is stored under the "renderingHints" attribute name.

Parameters:
tag - property tag
c - rendering hints

setFlag

public void setFlag(java.lang.String tag,
                    java.lang.String attribute,
                    int value)
Sets the integer flag property in the stylesheet.

Parameters:
tag - property tag
attribute - property attribute
value - integer flag value

setProperty

public void setProperty(java.lang.String tag,
                        java.lang.String attribute,
                        StyleObject property)
Sets enumeration property to the stylesheet

Parameters:
tag - property tag
attribute - property attribute
property - property value

getProperty

public StyleObject getProperty(java.lang.String tag,
                               java.lang.String attribute)
Gets property enumeration value

Parameters:
tag - property tag
attribute - property attribute
Returns:
returns property as enumeration value

setFont

public void setFont(java.lang.String tag,
                    java.awt.Font font)
Sets the font property in the stylesheet. It is stored under the "font" attribute name.

Parameters:
tag - property tag
font - font

setForeground

public void setForeground(java.lang.String tag,
                          java.awt.Color color)
Sets the foreground property in the stylesheet. It is stored under the "foreground" attribute name.

Parameters:
tag - property tag
color - foreground color

setBackground

public void setBackground(java.lang.String tag,
                          java.awt.Color color)
Sets the background property in the stylesheet. It is stored under the "background" attribute name.

Parameters:
tag - property tag
color - background color

setColor

public void setColor(java.lang.String tag,
                     java.lang.String attribute,
                     java.awt.Color color)
Sets the color property in the stylesheet.

Parameters:
tag - property tag
attribute - property attribute
color - foreground color

setPaint

public void setPaint(java.awt.Paint paint)
Sets paint property in the stylesheet. It is stored under the "paint" attribute name.

Parameters:
paint - paint object

getPaint

public java.lang.Object getPaint()
Finds and returns a Paint property. It is searched by the "paint" attribute name.

Returns:
property value

setPaint

public void setPaint(java.awt.Paint paint,
                     java.lang.String tag)
Sets paint property in the stylesheet. It is stored under the "paint" attribute name and given tag value.

Parameters:
paint - paint object
tag - object tag identifier value

getPaint

public java.lang.Object getPaint(java.lang.String tag)
Finds and returns a Paint property. It is searched by the "paint" attribute name and given tag value.

Parameters:
tag - object tag identifier value
Returns:
property value

setObject

public void setObject(java.lang.String tag,
                      java.lang.String attribute,
                      java.lang.Object value)
Sets any property in the stylesheet.

Parameters:
tag - property tag
attribute - property attribute
value - property value

getObject

public java.lang.Object getObject(java.lang.String tag,
                                  java.lang.String attribute)
Finds and returns a property.

Parameters:
tag - property tag
attribute - property attribute
Returns:
property value

getComposite

public java.lang.Object getComposite(java.lang.String tag)
Finds and returns a composite property. It is looked under the "composite" attribute name.

Parameters:
tag - property tag
Returns:
property value

getStroke

public java.lang.Object getStroke(java.lang.String tag)
Finds and returns a stroke property. It is searched by the "stroke" attribute name.

Parameters:
tag - property tag
Returns:
property value

getRenderingHints

public java.lang.Object getRenderingHints(java.lang.String tag)
Finds and returns a rendering hints property. It is looked under the "renderingHints" attribute name.

Parameters:
tag - property tag
Returns:
property value

getFlag

public int getFlag(java.lang.String tag,
                   java.lang.String attribute)
Finds and returns a integer flag property. If the flag value is not found in the stylesheet, value 0 is returned.

Parameters:
tag - property tag
attribute - property attribute
Returns:
property value

getFont

public java.awt.Font getFont(java.lang.String tag)
Finds and returns a font property. It is looked under the "font" attribute name.

Parameters:
tag - property tag
Returns:
property value

getForeground

public java.awt.Color getForeground(java.lang.String tag)
Finds and returns a foreground property. It is searched by the "foreground" attribute name.

Parameters:
tag - property tag
Returns:
property value

getBackground

public java.awt.Color getBackground(java.lang.String tag)
Finds and returns a background property. It is looked under the "background" attribute name.

Parameters:
tag - property tag
Returns:
property value

getColor

public java.awt.Color getColor(java.lang.String tag,
                               java.lang.String attribute)
Finds and returns a color property. Color entityStyle are handles in a special way. If a Color[] object is stored in the stylesheet instead of a plain Color object, this method assumes that there is a number as the last component of the tag value or the style context value. That number is parsed and a corresponding entry from an Color array is returned.

Parameters:
tag - property tag
attribute - property attribute
Returns:
property value

findValue

protected java.lang.Object findValue(java.lang.String tag,
                                     java.lang.String attribute)
Finds and returns a property.

Parameters:
tag - property tag
attribute - property attribute
Returns:
property value

setValue

protected void setValue(java.lang.String tag,
                        java.lang.String attribute,
                        java.lang.Object value)
Sets any property in the stylesheet.

Parameters:
tag - property tag
attribute - property attribute
value - property value

getContext

public java.lang.String getContext()
Returns a textual stylesheet context. It specifies how deeply is this stylesheet nested in the stylesheet hierarchy.

Returns:
context tag

getContext

public java.lang.StringBuilder getContext(java.lang.StringBuilder stringBuilder)
Returns a textual stylesheet context appended to a StringBuilder. It specifies how deeply is this stylesheet nested in the stylesheet hierarchy.

Parameters:
stringBuilder - StringBuilder to use for context assembly.
Returns:
context tag in a StringBuilder

toString

public java.lang.String toString()
Returns the String representation of this Stylesheet object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the stylesheet.

dispose

public void dispose()
Cleans this stylesheet object. After this style object is unusable and can be garbage collected.


finalize

protected void finalize()
                 throws java.lang.Throwable
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. Calls cleanup method if it isn't called yet.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - the Exception raised by this method

defaultWrite

protected void defaultWrite(java.io.ObjectOutputStream out,
                            java.util.Hashtable<Key,java.lang.Object> styleSettings)
                     throws java.io.IOException
Default serialization write

Parameters:
out - serialization output stream
styleSettings - stylesheet settings
Throws:
java.io.IOException - throws error if occurs during serialization

defaultRead

protected java.util.Hashtable<Key,java.lang.Object> defaultRead(java.io.ObjectInputStream in,
                                                                java.util.Hashtable<Key,java.lang.Object> styleSettings)
                                                         throws java.io.IOException,
                                                                java.lang.ClassNotFoundException
Default read of serialization

Parameters:
in - input stream of serialization
styleSettings - stylesheet settings
Throws:
java.io.IOException - throws error if something goes wrong during serialization
java.lang.ClassNotFoundException

resumeListeners

public void resumeListeners()
Resumes all listeners


suspendListeners

public void suspendListeners()
Suspends all listeners, which later can be resumed