Class PreviewProperties


  • public class PreviewProperties
    extends 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 Detail

      • PreviewProperties

        public PreviewProperties()
    • Method Detail

      • getValueAsText

        public static String getValueAsText​(Object value)
        Converts any value to a serialized String. Uses PropertyEditor for serialization except for values of Font 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. Uses PropertyEditor for serialization except for values of Font class.

        Note: Method moved to Utils module (org.gephi.utils.Serialization).

        Parameters:
        valueStr - String to deserialize
        valueClass - 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)
        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:
        IllegalArgumentException - if property already exists
      • removeProperty

        public void removeProperty​(PreviewProperty property)
      • hasProperty

        public boolean hasProperty​(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​(String name,
                             Object value)
        Puts the property's value.
        Parameters:
        name - the name of the property
        value - 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 to Number
      • 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 to Number
      • 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 to Number
      • getStringValue

        public String getStringValue​(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 Color getColorValue​(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:
        ClassCastException - if the property can't be cast to Color
      • getFontValue

        public Font getFontValue​(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:
        ClassCastException - if the property can't be cast to Font
      • 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 to Boolean
      • getValue

        public <T> T getValue​(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:
        ClassCastException - if the property can't be cast to T
      • getValue

        public <T> T getValue​(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:
        ClassCastException - if the property can't be cast to T
      • getNumberValue

        public Number getNumberValue​(String property,
                                     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:
        ClassCastException - if the property can't be cast to Number
      • 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 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​(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​(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