gishur.gui2
Class PropertyStatusReader

java.lang.Object
  |
  +--gishur.gui2.PropertyStatusReader

public class PropertyStatusReader
extends java.lang.Object

Help class for easily reading properties from a given DrawAtom with different prefixes depending on a given state. The properties to read with this class should have the following structure:

<prefix>[.<subtype>][.<style>][.<layout>].<key>

An property key (used by getProperty(java.lang.String, java.lang.Object)) will be expanded like this using the set prefix strings and the set layout state. The actual layout state must be set actively by the code using this PropertyStatusReader. Only DisplayInteractiveObjects manage setting the layout state automatically. In this case, the layout state will be composed by the state of the DisplayInteractiveObject and the state of the Painter that uses the PropertyStatusReader.

The set layout state determines not only the according part of the property key, but also determines, how this part should be switched through the layouts, if the property was not found. If a property was not found, first the given style will be ignored (so if the property "xsegment.point.round.active.color" was not found, the PropertyStatusReader tries "xsegment.point.active.color" instead). If still no value was found, the layout will be lowered, meaning the elemination of the highest bit in the layout mask. Assume, the layout state is set to LAYOUT_1 | LAYOUT_2. The highest layout (bit) defines the prefix according to the global prefix table; the highest layout is LAYOUT_2, the according entry is "active". If no property with this layout prefix is found, the highest bit in the layout state mask will be eleminated; thus LAYOUT_1 is remaining. The according prefix of the highest layout (bit) is "selected", so e.g. "xsegment.point.round.selected.color" will be read. This continues until all layout state bits are cleared and the normal prefix ("") was read (e.g. "xsegment.point.round.color"/"xsegment.point.color").

If a value is found, the PropertyStatusReader can cache the found value, to accelerate the retrieval of this property next time. The caching can be disabled by calling disableCaching(). This will cost performance but save memory. Per default, caching is enabled. Caching assumes static properties. If properties do change dynamically, clearCache() must be called to ensure reading of correct properties.

Version:
1.3
Author:
Thomas Wolf

Field Summary
static byte LAYOUT_0
          Layout constant: normal layout (no prefix).
static byte LAYOUT_1
          Layout constant: layout 1 (prefix according prefix table).
static byte LAYOUT_2
          Layout constant: layout 2 (prefix according prefix table).
static byte LAYOUT_3
          Layout constant: layout 3 (prefix according prefix table).
static byte LAYOUT_4
          Layout constant: layout 4 (prefix according prefix table).
static byte LAYOUT_5
          Layout constant: layout 5 (prefix according prefix table).
static byte LAYOUT_6
          Layout constant: layout 6 (prefix according prefix table).
static byte LAYOUT_7
          Layout constant: layout 7 (prefix according prefix table).
static byte LAYOUT_8
          Layout constant: layout 8 (prefix according prefix table).
static java.lang.String STYLE_PROPERTY_NAME
          The property name for a style property.
 
Constructor Summary
PropertyStatusReader(java.lang.String prefix, DrawAtom dob)
          Constructs a new PropertyStatusReader object with the specified properties prefix and source DrawAtom.
PropertyStatusReader(java.lang.String prefix, DrawAtom drw, byte state)
          Constructs a new PropertyStatusReader object with the specified properties prefix, source DrawAtom and state.
 
Method Summary
 void addPrefix(java.lang.String prefix)
          Adds a prefix for reading properties.
 void clearCache()
          Clears the Cache of this PropertyStatusReader.
 void clearPropertyAdapterSource()
          Clears the source object for SourcePropertyAdapter entries.
 void disableCaching()
          Disables the caching of properties.
 void enableCaching()
          Enables the caching of properties.
 boolean getBoolProperty(java.lang.String key, boolean default_value)
          Returns a property value which must be an boolean value.
 java.awt.Color getColorProperty(java.lang.String key, java.awt.Color default_color)
          Returns a property value which must be a color.
 double getDoubleProperty(java.lang.String key, double default_value)
          Returns a property value which must be an double number.
 java.awt.Font getFontProperty(java.lang.String key, java.awt.Font default_font)
          Returns a property value which must be a java.awt.Font object.
 int getIntProperty(java.lang.String key, int default_value)
          Returns a property value which must be an integer number.
 Painter getPainterFromStyle(java.lang.String name, java.lang.String subtype)
          Returns a Painter created by a Style stored at the style property of the given subtype.
 java.awt.Point getPointProperty(java.lang.String key, java.awt.Point default_point)
          Returns a property value which must be a java.awt.Point object.
 java.lang.Object getProperty(java.lang.String key)
          Returns property with the given key of the connected DrawAtom.
 java.lang.Object getProperty(java.lang.String key, java.lang.Object default_value)
          Returns property with the given key of the connected DrawAtom. with a given default value if the property is not set.
 java.lang.Object getSpecialProperty(java.lang.String key, java.lang.Object default_value, java.lang.Object source, DrawAtom atom)
          Reads the property with this PropertyStatusReader from another DrawAtom in the drawing hierachy.
 java.lang.String getStringProperty(java.lang.String key, java.lang.String default_string)
          Returns a property value which must be a string.
 Style getStyleProperty(java.lang.String subtype)
          Reads a Style property value for a given subtype.
 java.lang.Object getSubTypeProperty(java.lang.String subtype, java.lang.String key)
          Returns property with the given key of the connected DrawAtom using the specified subtype string instead of the one already set on this PropertyStatusReader.
 java.lang.Object getSubTypeProperty(java.lang.String subtype, java.lang.String key, java.lang.Object default_value)
          Returns property with the given key of the connected DrawAtom. (with a given default value if the property is not set) using the specified subtype string instead of the one already set on this PropertyStatusReader.
 boolean hasProperty(java.lang.String key)
          Returns true, if the specified property is set.
 java.lang.String prefix()
          Returns the properties prefix of the PropertyStatusReader.
 java.lang.Object propertyAdapterSource()
          Returns the source object for SourcePropertyAdapter entries.
 java.lang.String removeLastPrefix()
          Removes the last added prefix (to the last point).
 void setPrefixTo(java.lang.String prefix)
          Sets the properties prefix for reading properties.
 void setPropertyAdapterSource(java.lang.Object source)
          Sets a source object for SourcePropertyAdapter entries.
 void setState(byte state)
          Sets the layout state.
 void setStyle(java.lang.String style)
          Sets the style prefix to the given String (may be empty).
 void setSubType(java.lang.String subtype)
          Sets the subtype prefix to the given String (may be empty).
 byte state()
          Returns the layout state of the PropertyReader.
 java.lang.String style()
          Returns the style prefix for properties (may be empty).
 java.lang.String subtype()
          Returns the subtype prefix for properties (may be empty).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STYLE_PROPERTY_NAME

public static final java.lang.String STYLE_PROPERTY_NAME
The property name for a style property.

LAYOUT_0

public static final byte LAYOUT_0
Layout constant: normal layout (no prefix).

LAYOUT_1

public static final byte LAYOUT_1
Layout constant: layout 1 (prefix according prefix table).

LAYOUT_2

public static final byte LAYOUT_2
Layout constant: layout 2 (prefix according prefix table).

LAYOUT_3

public static final byte LAYOUT_3
Layout constant: layout 3 (prefix according prefix table).

LAYOUT_4

public static final byte LAYOUT_4
Layout constant: layout 4 (prefix according prefix table).

LAYOUT_5

public static final byte LAYOUT_5
Layout constant: layout 5 (prefix according prefix table).

LAYOUT_6

public static final byte LAYOUT_6
Layout constant: layout 6 (prefix according prefix table).

LAYOUT_7

public static final byte LAYOUT_7
Layout constant: layout 7 (prefix according prefix table).

LAYOUT_8

public static final byte LAYOUT_8
Layout constant: layout 8 (prefix according prefix table).
Constructor Detail

PropertyStatusReader

public PropertyStatusReader(java.lang.String prefix,
                            DrawAtom drw,
                            byte state)
Constructs a new PropertyStatusReader object with the specified properties prefix, source DrawAtom and state.
Parameters:
prefix - the prefix for all properties
drw - the DrawAtom to read properties from
state - the state of the element

PropertyStatusReader

public PropertyStatusReader(java.lang.String prefix,
                            DrawAtom dob)
Constructs a new PropertyStatusReader object with the specified properties prefix and source DrawAtom. The state will be determined through the state of the DrawAtom (if it is an instance of DisplayInteractiveObject).
Parameters:
prefix - the prefix for all properties
drw - the DrawAtom to read properties from
state - the state of the element
Method Detail

state

public byte state()
Returns the layout state of the PropertyReader.
Returns:
state of the PropertyReader.

setState

public void setState(byte state)
Sets the layout state.
Parameters:
state - the new state

enableCaching

public void enableCaching()
Enables the caching of properties.

disableCaching

public void disableCaching()
Disables the caching of properties.

clearCache

public void clearCache()
Clears the Cache of this PropertyStatusReader.

prefix

public java.lang.String prefix()
Returns the properties prefix of the PropertyStatusReader.
Returns:
the properties prefix of the PropertyStatusReader.

setPrefixTo

public void setPrefixTo(java.lang.String prefix)
Sets the properties prefix for reading properties. The prefix will end with a dot (this dot will be added to the prefix). This method clears all set prefixes at this time.
Parameters:
prefix - new prefix string
See Also:
addPrefix(java.lang.String)

addPrefix

public void addPrefix(java.lang.String prefix)
Adds a prefix for reading properties. Various prefixes are separated by dots (".").
Parameters:
prefix - new prefix to add

removeLastPrefix

public java.lang.String removeLastPrefix()
Removes the last added prefix (to the last point).
Returns:
the removed prefix
See Also:
addPrefix(java.lang.String)

subtype

public java.lang.String subtype()
Returns the subtype prefix for properties (may be empty).
Returns:
the subtype prefix.

setSubType

public void setSubType(java.lang.String subtype)
Sets the subtype prefix to the given String (may be empty).
Parameters:
subtype - the subtype string

style

public java.lang.String style()
Returns the style prefix for properties (may be empty).
Returns:
style the style prefix

setStyle

public void setStyle(java.lang.String style)
Sets the style prefix to the given String (may be empty). The String should not contain dots (".") - if it does, only the first part of the string (to the first dot) will be taken.
Parameters:
style - the style string

setPropertyAdapterSource

public void setPropertyAdapterSource(java.lang.Object source)
Sets a source object for SourcePropertyAdapter entries.
Parameters:
source - the source object to use

propertyAdapterSource

public java.lang.Object propertyAdapterSource()
Returns the source object for SourcePropertyAdapter entries.
Returns:
the source object for SourcePropertyAdapter entries.

clearPropertyAdapterSource

public void clearPropertyAdapterSource()
Clears the source object for SourcePropertyAdapter entries.

getSpecialProperty

public final java.lang.Object getSpecialProperty(java.lang.String key,
                                                 java.lang.Object default_value,
                                                 java.lang.Object source,
                                                 DrawAtom atom)
Reads the property with this PropertyStatusReader from another DrawAtom in the drawing hierachy. Use this method with caution!
Parameters:
key - property key
default_value - the default value
source - the source object to use
atom - the DrawAtom to use
Returns:
the read property

getProperty

public final java.lang.Object getProperty(java.lang.String key,
                                          java.lang.Object default_value)
Returns property with the given key of the connected DrawAtom. with a given default value if the property is not set. The read property depends on the actual state. The key will be expanded by the given prefix, the subtype and style and the prefixes "selected", "active", "active1", "active2",... dependend on the current state.
Parameters:
key - a key in the properties list
default_value - the default value of that property
Returns:
the value to which the key is mapped in a properties list; null if the key is not mapped to any value in the properties lists of the connected DrawAtom and parent object(s).

getProperty

public java.lang.Object getProperty(java.lang.String key)
Returns property with the given key of the connected DrawAtom. The read property depends on the actual state. The key will be expanded by the given prefix, the subtype and style and the prefixes "selected", "active", "active1", "active2",... dependend on the current state.
Parameters:
key - a key in the properties list
Returns:
the value to which the key is mapped in a properties list; null if the key is not mapped to any value in the properties lists of the connected DrawAtom and parent object(s).

hasProperty

public final boolean hasProperty(java.lang.String key)
Returns true, if the specified property is set.
Parameters:
key - the key for the property
Returns:
true, if the specified property is set.

getSubTypeProperty

public java.lang.Object getSubTypeProperty(java.lang.String subtype,
                                           java.lang.String key)
Returns property with the given key of the connected DrawAtom using the specified subtype string instead of the one already set on this PropertyStatusReader. The read property depends on the actual state. The key will be expanded by the given prefix and subtype and the style and the prefixes "selected", "active", "active1", "active2",... dependend on the current state.
Parameters:
subtype - the subtype string to use
key - a key in the properties list
Returns:
the value to which the key is mapped in a properties list; null if the key is not mapped to any value in the properties lists of the connected DrawAtom and parent object(s).

getSubTypeProperty

public java.lang.Object getSubTypeProperty(java.lang.String subtype,
                                           java.lang.String key,
                                           java.lang.Object default_value)
Returns property with the given key of the connected DrawAtom. (with a given default value if the property is not set) using the specified subtype string instead of the one already set on this PropertyStatusReader. The read property depends on the actual state. The key will be expanded by the given prefix, the subtype and style and the prefixes "selected", "active", "active1", "active2",... dependend on the current state.
Parameters:
subtype - the subtype string to use
key - a key in the properties list
Returns:
the value to which the key is mapped in a properties list; null if the key is not mapped to any value in the properties lists of the connected DrawAtom and parent object(s).

getIntProperty

public int getIntProperty(java.lang.String key,
                          int default_value)
Returns a property value which must be an integer number. The property value must be of the type Number. If the property is not set or is not of the type Number, the specified default value will be returned.
Parameters:
key - a key in the properties list
default_value - the default value if the property is not set or invalid.
Returns:
the read integer value

getDoubleProperty

public double getDoubleProperty(java.lang.String key,
                                double default_value)
Returns a property value which must be an double number. The property value must be of the type Number. If the property is not set or is not of the type Number, the specified default value will be returned.
Parameters:
key - a key in the properties list
default_value - the default value if the property is not set or invalid.
Returns:
the read integer value

getStringProperty

public java.lang.String getStringProperty(java.lang.String key,
                                          java.lang.String default_string)
Returns a property value which must be a string. The property value must be of the type String. If the property is not set or is not of the type String, the specified default string will be returned.
Parameters:
key - a key in the properties list
default_string - the default string if the property is not set or invalid.
Returns:
the read string.

getColorProperty

public java.awt.Color getColorProperty(java.lang.String key,
                                       java.awt.Color default_color)
Returns a property value which must be a color. The property value must be of the type Color. If the property is not set or is not of the type Color, the specified default color will be returned.
Parameters:
key - a key in the properties list
default_color - the default color if the property is not set or invalid.
Returns:
the read color.

getBoolProperty

public boolean getBoolProperty(java.lang.String key,
                               boolean default_value)
Returns a property value which must be an boolean value. The property value must be of the type Boolean. If the property is not set or is not of the type Boolean, the specified default value will be returned.
Parameters:
key - a key in the properties list
default_value - the default value if the property is not set or invalid.
Returns:
the read boolean value

getPointProperty

public java.awt.Point getPointProperty(java.lang.String key,
                                       java.awt.Point default_point)
Returns a property value which must be a java.awt.Point object. If the property is not set or is not of the type java.awt.Point, the specified default point will be returned.
Parameters:
key - a key in the properties list
default_point - the default java.awt.Point if the property is not set or invalid.
Returns:
the read java.awt.Point property.

getFontProperty

public java.awt.Font getFontProperty(java.lang.String key,
                                     java.awt.Font default_font)
Returns a property value which must be a java.awt.Font object. If the property is not set or is not of the type java.awt.Font, the specified default font will be returned.
Parameters:
key - a key in the properties list
default_font - the default java.awt.Font if the property is not set or invalid.
Returns:
the read java.awt.Font property.

getStyleProperty

public Style getStyleProperty(java.lang.String subtype)
Reads a Style property value for a given subtype. The Style property is a required property. The property name that is used is defined via STYLE_PROPERTY_NAME.
Parameters:
subtype - the subtype string to use
Returns:
the read Style property.

getPainterFromStyle

public Painter getPainterFromStyle(java.lang.String name,
                                   java.lang.String subtype)
Returns a Painter created by a Style stored at the style property of the given subtype. The created Painter will have the same subtype string.
Parameters:
name - the name of the created Painter
subtype - where to create a Painter from
Returns:
a Painter created by the Style that is stored at the style property of the given subtype