Class PreviewProperties
- java.lang.Object
-
- org.gephi.preview.api.PreviewProperties
-
public class PreviewProperties extends Object
Container forPreviewProperty
attached to aPreviewModel
.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 callingputValue()
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 theaddProperty()
method are returned when calling thegetProperties()
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 theapplyPreset()
method.- Author:
- Mathieu Bastian
- See Also:
PreviewPreset
-
-
Constructor Summary
Constructors Constructor Description PreviewProperties()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProperty(PreviewProperty property)
Addproperty
to the properties.void
applyPreset(PreviewPreset previewPreset)
Sets all preset's property values to this properties.boolean
getBooleanValue(String property)
Returns the property value as a boolean.PreviewProperty[]
getChildProperties(PreviewProperty property)
Returns all properties which definedproperty
as a dependency.Color
getColorValue(String property)
Returns an the property value as aColor
.double
getDoubleValue(String property)
Returns the property value as a double.float
getFloatValue(String property)
Returns the property value as a float.Font
getFontValue(String property)
Returns an the property value as aFont
.int
getIntValue(String property)
Returns the property value as an int.Number
getNumberValue(String property, Number defaultValue)
Returns the property value as aNumber
.PreviewProperty[]
getParentProperties(PreviewProperty property)
Returns all propertiesproperty
defined as dependencies.PreviewProperty[]
getProperties()
Returns all properties.PreviewProperty[]
getProperties(Object source)
Returns all properties withsource
as source.PreviewProperty[]
getProperties(String category)
Returns all properties withcategory
as category.PreviewProperty
getProperty(String name)
Returns the property defined asname
.Set<Map.Entry<String,Object>>
getSimpleValues()
Return all simple values.String
getStringValue(String property)
Returns the property value as an string.<T> T
getValue(String property)
Returns the property value and cast it to theT
type.<T> T
getValue(String property, T defaultValue)
Returns the property value and cast it to theT
type.static String
getValueAsText(Object value)
Converts any value to a serialized String.boolean
hasProperty(String name)
Returnstrue
if a propertyname
exists.void
putValue(String name, Object value)
Puts the property's value.static Object
readValueFromText(String valueStr, Class valueClass)
Deserializes a serialized String of the given class.void
removeProperty(PreviewProperty property)
void
removeSimpleValue(String name)
Removes a simple value if existing
-
-
-
Method Detail
-
getValueAsText
public static String getValueAsText(Object value)
Converts any value to a serialized String. UsesPropertyEditor
for serialization except for values ofFont
class.Note: Method moved to Utils module (org.gephi.utils.Serialization).
- Parameters:
value
- Value to serialize as String- Returns:
- Result String or null if the value can't be serialized with a
PropertyEditor
-
readValueFromText
public static Object readValueFromText(String valueStr, Class valueClass)
Deserializes a serialized String of the given class. UsesPropertyEditor
for serialization except for values ofFont
class.Note: Method moved to Utils module (org.gephi.utils.Serialization).
- Parameters:
valueStr
- String to deserializevalueClass
- Class of the serialized value- Returns:
- Deserialized value or null if it can't be deserialized with a
PropertyEditor
-
addProperty
public void addProperty(PreviewProperty property)
Addproperty
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:
IllegalArgumentException
- ifproperty
already exists
-
removeProperty
public void removeProperty(PreviewProperty property)
-
hasProperty
public boolean hasProperty(String name)
Returnstrue
if a propertyname
exists.- Parameters:
name
- the name of the property to lookup- Returns:
true
if the property exists,false
otherwise
-
putValue
public void putValue(String name, Object value)
Puts the property's value.- Parameters:
name
- the name of the propertyvalue
- the value
-
removeSimpleValue
public void removeSimpleValue(String name)
Removes a simple value if existing- Parameters:
name
- Simple value name
-
getIntValue
public int getIntValue(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:
ClassCastException
- if the property can't be cast toNumber
-
getFloatValue
public float getFloatValue(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:
ClassCastException
- if the property can't be cast toNumber
-
getDoubleValue
public double getDoubleValue(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:
ClassCastException
- if the property can't be cast toNumber
-
getStringValue
public String getStringValue(String property)
Returns the property value as an string. If the value is not aString
it calls thetoString()
method.- Parameters:
property
- the property's name- Returns:
- the property's value or
""
if not found
-
getColorValue
public Color getColorValue(String property)
Returns an the property value as aColor
.- Parameters:
property
- the property's name- Returns:
- the property's value or
null
if not found - Throws:
ClassCastException
- if the property can't be cast toColor
-
getFontValue
public Font getFontValue(String property)
Returns an the property value as aFont
.- Parameters:
property
- the property's name- Returns:
- the property's value or
null
if not found - Throws:
ClassCastException
- if the property can't be cast toFont
-
getBooleanValue
public boolean getBooleanValue(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:
ClassCastException
- if the property can't be cast toBoolean
-
getValue
public <T> T getValue(String property)
Returns the property value and cast it to theT
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:
ClassCastException
- if the property can't be cast toT
-
getValue
public <T> T getValue(String property, T defaultValue)
Returns the property value and cast it to theT
type.- Type Parameters:
T
- the type to cast the property value to- Parameters:
property
- the property's namedefaultValue
- the default value if not found- Returns:
- the property's value or
defaultValue
if not found - Throws:
ClassCastException
- if the property can't be cast toT
-
getNumberValue
public Number getNumberValue(String property, Number defaultValue)
Returns the property value as aNumber
.- Parameters:
property
- the property's namedefaultValue
- the default value if not found- Returns:
- the property's value or
defaultValue
if not found - Throws:
ClassCastException
- if the property can't be cast toNumber
-
getSimpleValues
public Set<Map.Entry<String,Object>> getSimpleValues()
Return all simple values.- Returns:
- all simple values
-
getProperties
public PreviewProperty[] getProperties()
Returns all properties.- Returns:
- all properties
-
getProperties
public PreviewProperty[] getProperties(String category)
Returns all properties withcategory
as category. A property can belong to only one category. Default categories names are defined inPreviewProperty
.- Parameters:
category
- the category properties belong to- Returns:
- all properties in
category
-
getProperty
public PreviewProperty getProperty(String name)
Returns the property defined asname
.- Parameters:
name
- the property's name- Returns:
- the property with this name or
null
if not found
-
getProperties
public PreviewProperty[] getProperties(Object source)
Returns all properties withsource
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 definedproperty
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 propertiesproperty
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
-
-