Class PreviewProperties
- java.lang.Object
-
- org.gephi.preview.api.PreviewProperties
-
public class PreviewProperties extends Object
Container forPreviewPropertyattached 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
PreviewPresetand 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 voidaddProperty(PreviewProperty property)Addpropertyto the properties.voidapplyPreset(PreviewPreset previewPreset)Sets all preset's property values to this properties.booleangetBooleanValue(String property)Returns the property value as a boolean.PreviewProperty[]getChildProperties(PreviewProperty property)Returns all properties which definedpropertyas a dependency.ColorgetColorValue(String property)Returns an the property value as aColor.doublegetDoubleValue(String property)Returns the property value as a double.floatgetFloatValue(String property)Returns the property value as a float.FontgetFontValue(String property)Returns an the property value as aFont.intgetIntValue(String property)Returns the property value as an int.NumbergetNumberValue(String property, Number defaultValue)Returns the property value as aNumber.PreviewProperty[]getParentProperties(PreviewProperty property)Returns all propertiespropertydefined as dependencies.PreviewProperty[]getProperties()Returns all properties.PreviewProperty[]getProperties(Object source)Returns all properties withsourceas source.PreviewProperty[]getProperties(String category)Returns all properties withcategoryas category.PreviewPropertygetProperty(String name)Returns the property defined asname.Set<Map.Entry<String,Object>>getSimpleValues()Return all simple values.StringgetStringValue(String property)Returns the property value as an string.<T> TgetValue(String property)Returns the property value and cast it to theTtype.<T> TgetValue(String property, T defaultValue)Returns the property value and cast it to theTtype.static StringgetValueAsText(Object value)Converts any value to a serialized String.booleanhasProperty(String name)Returnstrueif a propertynameexists.voidputValue(String name, Object value)Puts the property's value.static ObjectreadValueFromText(String valueStr, Class valueClass)Deserializes a serialized String of the given class.voidremoveProperty(PreviewProperty property)voidremoveSimpleValue(String name)Removes a simple value if existing
-
-
-
Method Detail
-
getValueAsText
public static String getValueAsText(Object value)
Converts any value to a serialized String. UsesPropertyEditorfor serialization except for values ofFontclass.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. UsesPropertyEditorfor serialization except for values ofFontclass.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)
Addpropertyto 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- ifpropertyalready exists
-
removeProperty
public void removeProperty(PreviewProperty property)
-
hasProperty
public boolean hasProperty(String name)
Returnstrueif a propertynameexists.- Parameters:
name- the name of the property to lookup- Returns:
trueif the property exists,falseotherwise
-
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
0if 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
0if 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.0if 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 aStringit 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
nullif 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
nullif 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
falseif 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 theTtype.- Type Parameters:
T- the type to cast the property value to- Parameters:
property- the property's name- Returns:
- the property's value or
nullif 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 theTtype.- 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
defaultValueif 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
defaultValueif 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 withcategoryas 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
nullif not found
-
getProperties
public PreviewProperty[] getProperties(Object source)
Returns all properties withsourceas 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 definedpropertyas a dependency.- Parameters:
property- the parent property- Returns:
- all properties with
propertyas a parent property
-
getParentProperties
public PreviewProperty[] getParentProperties(PreviewProperty property)
Returns all propertiespropertydefined as dependencies.- Parameters:
property- the property to find parent properties from- Returns:
- all properties
propertydepends on
-
applyPreset
public void applyPreset(PreviewPreset previewPreset)
Sets all preset's property values to this properties.- Parameters:
previewPreset- the preset to get values from
-
-