Gephi Toolkit Javadoc

org.gephi.preview.api
Class PreviewProperties

java.lang.Object
  extended by org.gephi.preview.api.PreviewProperties

public class PreviewProperties
extends java.lang.Object

Container for PreviewProperty attached to a PreviewModel.

This class holds all preview properties defined in the model. Each property has a unique name, a type and a value and can be configured by users.

Properties should be added using the addProperty() method before calling putValue() to properly register properties.

Besides holding well-defined properties this class acts also as a map and can store arbitrary (key,value) pairs. All (key,value) pairs are stored when calling the putValue() method but only properties added with the addProperty() method are returned when calling the getProperties() methods. Therefore this class can both be used for fixed properties and temporary variables.

To batch put a set of property values the best way is to create a PreviewPreset and call the applyPreset() method.

Author:
Mathieu Bastian
See Also:
PreviewPreset

Constructor Summary
PreviewProperties()
           
 
Method Summary
 void addProperty(PreviewProperty property)
          Add property to the properties.
 void applyPreset(PreviewPreset previewPreset)
          Sets all preset's property values to this properties.
 boolean getBooleanValue(java.lang.String property)
          Returns the property value as a boolean.
 PreviewProperty[] getChildProperties(PreviewProperty property)
          Returns all properties which defined property as a dependency.
 java.awt.Color getColorValue(java.lang.String property)
          Returns an the property value as a Color.
 double getDoubleValue(java.lang.String property)
          Returns the property value as a double.
 float getFloatValue(java.lang.String property)
          Returns the property value as a float.
 java.awt.Font getFontValue(java.lang.String property)
          Returns an the property value as a Font.
 int getIntValue(java.lang.String property)
          Returns the property value as an int.
 java.lang.Number getNumberValue(java.lang.String property, java.lang.Number defaultValue)
          Returns the property value as a Number.
 PreviewProperty[] getParentProperties(PreviewProperty property)
          Returns all properties property defined as dependencies.
 PreviewProperty[] getProperties()
          Returns all properties.
 PreviewProperty[] getProperties(java.lang.Object source)
          Returns all properties with source as source.
 PreviewProperty[] getProperties(java.lang.String category)
          Returns all properties with category as category.
 PreviewProperty getProperty(java.lang.String name)
          Returns the property defined as name.
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> getSimpleValues()
          Return all simple values.
 java.lang.String getStringValue(java.lang.String property)
          Returns the property value as an string.
<T> T
getValue(java.lang.String property)
          Returns the property value and cast it to the T type.
<T> T
getValue(java.lang.String property, T defaultValue)
          Returns the property value and cast it to the T type.
 boolean hasProperty(java.lang.String name)
          Returns true if a property name exists.
 void putValue(java.lang.String name, java.lang.Object value)
          Puts the property's value.
 void removeProperty(PreviewProperty property)
           
 void removeSimpleValue(java.lang.String name)
          Removes a simple value if existing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreviewProperties

public PreviewProperties()
Method Detail

addProperty

public void addProperty(PreviewProperty property)
Add property to the properties.

The property should have a unique name and the method will throw an exception if not.

Parameters:
property - the property to add to the properties
Throws:
java.lang.IllegalArgumentException - if property already exists

removeProperty

public void removeProperty(PreviewProperty property)

hasProperty

public boolean hasProperty(java.lang.String name)
Returns true if a property name exists.

Parameters:
name - the name of the property to lookup
Returns:
true if the property exists, false otherwise

putValue

public void putValue(java.lang.String name,
                     java.lang.Object value)
Puts the property's value.

Parameters:
name - the name of the property
value - the value

removeSimpleValue

public void removeSimpleValue(java.lang.String name)
Removes a simple value if existing

Parameters:
name - Simple value name

getIntValue

public int getIntValue(java.lang.String property)
Returns the property value as an int.

Parameters:
property - the property's name
Returns:
the property's value or 0 if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to Number

getFloatValue

public float getFloatValue(java.lang.String property)
Returns the property value as a float.

Parameters:
property - the property's name
Returns:
the property's value or 0 if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to Number

getDoubleValue

public double getDoubleValue(java.lang.String property)
Returns the property value as a double.

Parameters:
property - the property's name
Returns:
the property's value or 0.0 if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to Number

getStringValue

public java.lang.String getStringValue(java.lang.String property)
Returns the property value as an string. If the value is not a String it calls the toString() method.

Parameters:
property - the property's name
Returns:
the property's value or "" if not found

getColorValue

public java.awt.Color getColorValue(java.lang.String property)
Returns an the property value as a Color.

Parameters:
property - the property's name
Returns:
the property's value or null if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to Color

getFontValue

public java.awt.Font getFontValue(java.lang.String property)
Returns an the property value as a Font.

Parameters:
property - the property's name
Returns:
the property's value or null if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to Font

getBooleanValue

public boolean getBooleanValue(java.lang.String property)
Returns the property value as a boolean.

Parameters:
property - the property's name
Returns:
the property's value or false if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to Boolean

getValue

public <T> T getValue(java.lang.String property)
Returns the property value and cast it to the T type.

Type Parameters:
T - the type to cast the property value to
Parameters:
property - the property's name
Returns:
the property's value or null if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to T

getValue

public <T> T getValue(java.lang.String property,
                      T defaultValue)
Returns the property value and cast it to the T type.

Type Parameters:
T - the type to cast the property value to
Parameters:
property - the property's name
defaultValue - the default value if not found
Returns:
the property's value or defaultValue if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to T

getNumberValue

public java.lang.Number getNumberValue(java.lang.String property,
                                       java.lang.Number defaultValue)
Returns the property value as a Number.

Parameters:
property - the property's name
defaultValue - the default value if not found
Returns:
the property's value or defaultValue if not found
Throws:
java.lang.ClassCastException - if the property can't be cast to Number

getSimpleValues

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> getSimpleValues()
Return all simple values.

Returns:
all simple values

getProperties

public PreviewProperty[] getProperties()
Returns all properties.

Returns:
all properties

getProperties

public PreviewProperty[] getProperties(java.lang.String category)
Returns all properties with category as category. A property can belong to only one category. Default categories names are defined in PreviewProperty.

Parameters:
category - the category properties belong to
Returns:
all properties in category

getProperty

public PreviewProperty getProperty(java.lang.String name)
Returns the property defined as name.

Parameters:
name - the property's name
Returns:
the property with this name or null if not found

getProperties

public PreviewProperty[] getProperties(java.lang.Object source)
Returns all properties with source as source. A property can belong to only one source.

Parameters:
source - the source properties belong to
Returns:
all properties in source

getChildProperties

public PreviewProperty[] getChildProperties(PreviewProperty property)
Returns all properties which defined property as a dependency.

Parameters:
property - the parent property
Returns:
all properties with property as a parent property

getParentProperties

public PreviewProperty[] getParentProperties(PreviewProperty property)
Returns all properties property defined as dependencies.

Parameters:
property - the property to find parent properties from
Returns:
all properties property depends on

applyPreset

public void applyPreset(PreviewPreset previewPreset)
Sets all preset's property values to this properties.

Parameters:
previewPreset - the preset to get values from

Gephi Toolkit Javadoc