Class MultiProp<VALUE>

java.lang.Object
com.iizix.prop.GProp<Object[]>
com.iizix.prop.MultiProp<VALUE>
All Implemented Interfaces:
EventListener, IGProp<Object[]>, Cloneable
Direct Known Subclasses:
Color4Prop, Int4Prop, String4Prop, Unit4Prop

public abstract class MultiProp<VALUE> extends GProp<Object[]>
The multiple property class holds the property name, a common value or an array of different properties (typically 4 for e.g. GColor's for the "Border Color" property).
Author:
Christopher Mindus
  • Constructor Details

    • MultiProp

      protected MultiProp()
      Creates a color property with no name and with a null value.
    • MultiProp

      public MultiProp(Atom propertyAtom)
      Creates a color property with the specified name with a null value.
      Parameters:
      propertyAtom - the property atom.
  • Method Details

    • getValueClasses

      public Class<?>[] getValueClasses()
      Gets the list of possible native Java classes that can be used to set a value using setPropertyValue, in order of importance. Note that loss of precision in data if e.g. an Float property accepts a Double. However, the setPropertyValue throws IllegalArgumentException if the range in invalid, e.g. conversion of a Integer to a Byte, and the value is not -127 to 128.
      Specified by:
      getValueClasses in interface IGProp<VALUE>
      Specified by:
      getValueClasses in class GProp<Object[]>
      Returns:
      The array of Java classes that can be accepted in the setPropertyValue method. The first type is the "native" or most preferred type. The array is at least one item in length and never null.
    • setup

      protected final void setup(int count, Class<?> valueClass)
      Sets up the property.
      Parameters:
      count - The count of values.
      valueClass - The class for the values.
    • modifyPropValue

      protected int modifyPropValue(Object oldValue, Object newValue, PropMgr propMgr) throws PropException
      Called when setting a new value for this property. This method is normally not overridden by subclasses, but e.g. for properties containing arrays, this may be handled here, in order not modify the "oldValue" (such as an array, but rather to change it with the data from the "newValue").
      Overrides:
      modifyPropValue in class GProp<Object[]>
      Parameters:
      oldValue - The old value.
      newValue - The new value.
      propMgr - The property manager for remote change, null for local.
      Returns:
      1 for value has changed, 0 for same value as current value, -1 for not processed. 2 can also be returned to indicate the current value has been modified with new contents. This is e.g. the case for the StringMapProp.
      Throws:
      PropException - when the new value doesn't validate correctly.
    • equalValues

      protected Object equalValues(GProp<?> compareTo, Object[] thisValue, Object[] compareValue, int how)
      Checks for property value equality. The object is of the correct type for the respective property type. The Atoms and other properties such as Private/Extends has already been checked for equality or correctness.
      Overrides:
      equalValues in class GProp<Object[]>
      Parameters:
      compareTo - The comparing-to property that contains the value.
      thisValue - This property value (for synchronization reasons).
      compareValue - Another property value.
      how - Flags EQC_* values for equal checking.
      Returns:
      The property not being equal, null for equal (both values null).
    • getValueCount

      public int getValueCount()
      Gets the value count.
    • validatePropType

      public void validatePropType(Object newValue) throws PropTypeException
      Validates that the value to set is of GColor instance.

      Note: When this method is called, synchronization is done at the property itself, so no synchronization on the tree should be done.

      Specified by:
      validatePropType in interface IGProp<VALUE>
      Specified by:
      validatePropType in class GProp<Object[]>
      Parameters:
      newValue - The new value to set.
      Throws:
      PropTypeException - when the new value isn't of the correct class.
    • getPropValueDefault

      public VALUE getPropValueDefault()
      Gets the default value.
      Returns:
      The default value set at last call to setDefaultValue.
    • getPropValue

      public VALUE getPropValue(int index)
      Gets an indexed property value. If the value is not set for this index, the default is returned.
      Parameters:
      index - The index.
      Returns:
      The property value, null if none has been set anywhere.
    • getRealPropValue

      public VALUE getRealPropValue(int realIndex)
      Gets the "real" indexed property value (default index=0, other indexes+1).
      Parameters:
      realIndex - The "real" index.
      Returns:
      The property value or null for none.
    • setPropValueDefault

      public boolean setPropValueDefault(VALUE value) throws PropException
      Sets the default value.
      Parameters:
      value - The new default value.
      Returns:
      change-flag.
      Throws:
      PropException - If value is not of correct type.
    • setPropValue

      public boolean setPropValue(VALUE value, int index) throws PropException
      Sets an indexed property value. If set to null, the default value is set (if defined).
      Parameters:
      value - The value.
      index - The index.
      Returns:
      The change-flag.
      Throws:
      PropException - If value is not of correct type.
    • setRealPropValue

      public boolean setRealPropValue(VALUE value, int realIndex) throws PropException
      Sets the value at "real" index.
      Parameters:
      value - The new default value.
      realIndex - The "real" index.
      Returns:
      change-flag.
      Throws:
      PropException - If value is not of correct type.
    • setPropValues

      public boolean setPropValues(VALUE singleValue) throws PropException
      Sets all property values at once to a single value. The default value is also set with this call.
      Parameters:
      singleValue - The single value to set for all values, including the default value.
      Returns:
      The change-flag.
      Throws:
      PropException - If value is not of correct type.
    • setPropValues

      public boolean setPropValues(Object[] values) throws PropException
      Sets all property values at once along with a default value.
      Parameters:
      values - The new values.
      Returns:
      The change-flag.
      Throws:
      PropException - If value is not of correct type.
    • setPropValues

      public boolean setPropValues(VALUE defaultValue, Object[] values) throws PropException
      Sets all property values at once along with a default value.
      Parameters:
      defaultValue - The new default value.
      values - The new values.
      Returns:
      The change-flag.
      Throws:
      PropException - If value is not of correct type.
    • appendPropValue

      protected void appendPropValue(PropMgr propertyManager, SendTransaction trans, Object value)
      Appends the bounds property value.
      Specified by:
      appendPropValue in class GProp<Object[]>
      Parameters:
      propertyManager - the property manager instance.
      trans - transaction to append the properties to.
      value - the value to append to the transaction, a reference to the current property value.
    • appendPropValueItem

      protected abstract void appendPropValueItem(SendTransaction trans, VALUE value)
      Appends the property value item to a transaction.
      Parameters:
      trans - The transaction.
      value - The value to append.
    • initializeValue

      public boolean initializeValue(PropMgr propertyManager, ReadTransaction trans) throws PropException
      Initializes the property value from a transaction.
      Specified by:
      initializeValue in class GProp<Object[]>
      Parameters:
      propertyManager - the property manager.
      trans - the transaction to initialize the property with.
      Returns:
      true if the value has changed, false otherwise.
      Throws:
      PropException
    • createValue

      public abstract VALUE createValue(ReadTransaction trans)
      Creates a property value from a transaction.
    • initializeProp

      public void initializeProp(Element element) throws PropException
      Called to initialize the property from an Element. The property should initialize itself from attributes and nodes with appropriate information.
      Overrides:
      initializeProp in class GProp<Object[]>
      Parameters:
      element - The Element.
      Throws:
      PropException - when the initialization fails.
    • initializeElement

      public void initializeElement(Element element)
      Called when the XML file for the property tree is serialized from properties. The property should fill attributes and nodes with appropriate information.

      The attribute "sort" may be set to "client", "server" or not present, i.e. no sorting. The setting "server" indicates that the Server provides the sorting rule to use, settable for each client session programmatically.

      After the element, elements "string" builds up all text entries containing the strings.

      Overrides:
      initializeElement in class GProp<Object[]>
      Parameters:
      element - The Element.
    • initializeValueElement

      protected abstract void initializeValueElement(VALUE value, Element element)
      Method to override for the implementor.

      Initializes an XML Element from a value in the array.

      Parameters:
      value - The value to "stream" to the XML element.
      element - The XML value element, attributes "index" "null" are "taken".
    • createValue

      protected abstract VALUE createValue(Element element) throws Exception
      Method to override for the implementor.

      Creates an value in the property array from an Element.

      Parameters:
      element - The XML value element, attributes "index" and "null" are "taken".
      Throws:
      Exception - For errors.
    • getPropValue0

      protected Object getPropValue0(Object value, int index) throws Exception
      Gets the property value in another class form than the "native" one. This method tries conversion of a "native" property value into another class type. This method is used when filling in a POJO variable (Plain Old Java Object Field) from a "native" property value.
      Specified by:
      getPropValue0 in class GProp<Object[]>
      Parameters:
      value - The property value.
      index - The index in the Class array returned by getValueClasses().
      Returns:
      The property value in the requested class, after conversion.
      Throws:
      Exception - Other exceptions that could occur.
    • toNativeValue0

      protected Object toNativeValue0(Object value, int index) throws Exception
      Tries conversion of possibly accepted properties values using the setPropertyValue method into the most preferred property value type. If the input value already is of the preferred type, the same object is returned.
      Specified by:
      toNativeValue0 in class GProp<Object[]>
      Parameters:
      value - The input value to convert to native value.
      index - The index in the array returned by getValueClasses(), or -1 if not found.
      Returns:
      The converted input value in the preferred property value object type.
      Throws:
      Exception - For conversion exceptions.
    • paramValue

      protected String paramValue(Object value)
      Formats the value as a string to add to paramString. The default is to do "value.toString()" if value is not null, otherwise "[null]" is returned.
      Overrides:
      paramValue in class GProp<Object[]>
      Parameters:
      value - The property value.
      Returns:
      The String representation of the value.