maspack.properties
Class PropertyDesc

java.lang.Object
  extended by maspack.properties.PropertyDesc
All Implemented Interfaces:
PropertyInfo

public class PropertyDesc
extends java.lang.Object
implements PropertyInfo

Provides information and implementation code for specific properties exported by a class.


Nested Class Summary
static class PropertyDesc.TypeCode
           
 
Nested classes/interfaces inherited from interface maspack.properties.PropertyInfo
PropertyInfo.Edit, PropertyInfo.ExpandState
 
Field Summary
static boolean debug
           
static int INHERITABLE
           
static int READ_ONLY
           
static int REGULAR
           
 
Constructor Summary
PropertyDesc(PropertyDesc prop, java.lang.Class<?> hostClass)
          Creates a new PropertyDesc by copying an existing one and updating it for a specified host class.
PropertyDesc(java.lang.String name, java.lang.Class<?> hostClass)
          Creates a new PropertyDesc object with a specific property name and host class.
PropertyDesc(java.lang.String name, java.lang.Class<?> hostClass, java.lang.Class<?> valueClass)
          Creates a new PropertyDesc for a property with a specified name, host class, and value class.
 
Method Summary
static PropertyDesc create(java.lang.String nameAndMethods, java.lang.Class<?> hostClass, java.lang.String descriptor, java.lang.Object defaultValue, java.lang.String options, int propType)
           
 Property createHandle(HasProperties host)
          Creates a handle to the property for a specified host object.
 java.lang.Object createInstance(HasProperties host)
           
 boolean getAutoWrite()
          Returns true if auto-writing is enabled for this property.
 PropertyMode getDefaultMode()
          Returns the default inheritance mode for the property.
 NumericInterval getDefaultNumericRange()
          Returns a default numeric range for this property, if any.
 java.lang.Object getDefaultValue()
          Returns the default value for the property, or Property.VoidValue if there is not default value.
 java.lang.String getDescription()
          Returns a text description of the property.
 int getDimension()
          Returns the numeric dimension of this property, or -1 if the property is not numeric or does not have a fixed dimension.
 PropertyInfo.Edit getEditing()
          Returns information describing the conditions under which this property should be interactively edited.
 NumberFormat getFormat()
          Returns the formatter used to convert numeric components of the property's value into text.
 java.lang.Class<?> getHostClass()
          Returns the host class of the property.
 PropertyMode getMode(HasProperties host)
           
 java.lang.String getName()
          Returns the name of the property associated with this descriptor.
 boolean getNullValueOK()
          Returns true if the property value may be null.
 java.lang.String getPrintFormat()
          Returns a format string used to convert numeric components of the property's value into text.
 Range getRange(HasProperties host)
           
static PropertyDesc.TypeCode getTypeCode(java.lang.Class<?> cls)
           
 java.lang.Object getValue(HasProperties host)
           
 java.lang.Class<?> getValueClass()
          Returns the class type for the property's value.
 PropertyInfo.ExpandState getWidgetExpandState()
          
 boolean hasRestrictedRange()
          Returns true if the property has a restricted value range.
 boolean isInheritable()
          Returns true if the property is a inheritable property.
 boolean isReadOnly()
          Returns true if the property is read-only.
 boolean isSharable()
          Returns true if the value of this property is sharable among several hosts.
 java.lang.Object scanValue(ReaderTokenizer rtok)
          Scans a value of the type associated with the property from a ReaderTokenizer.
 void setAutoWrite(boolean enable)
           
 void setDefaultValue(java.lang.Object value)
           
 void setDescription(java.lang.String text)
          Sets a text description for the property.
 void setDimension(int dim)
           
 void setEditing(PropertyInfo.Edit edit)
           
 void setFormat(NumberFormat fmt)
          Directly sets the formatter used to convert numeric components of the property's value into text.
 void setGetMethod(java.lang.String methodName)
           
 void setGetModeMethod(java.lang.String methodName)
           
 void setGetRangeMethod(java.lang.String methodName)
           
 void setMode(HasProperties host, PropertyMode mode)
           
 void setName(java.lang.String name)
          Sets the name of the property associated with this descriptor.
 void setNullValueOK(boolean allowed)
           
 void setNumericRange(NumericInterval rng)
          Sets a NumericRange for this property.
 void setPrintFormat(java.lang.String fmtStr)
          Sets the formatter used to convert numeric components of the property's value into text.
 void setSetMethod(java.lang.String methodName)
           
 void setSetModeMethod(java.lang.String methodName)
           
 void setValue(HasProperties host, java.lang.Object value)
           
 void setWidgetExpandState(PropertyInfo.ExpandState state)
           
 boolean valueEqualsDefault(java.lang.Object value)
          Returns true if a specified value equals the default value of the property.
 void writeValue(java.lang.Object value, java.io.PrintWriter pw, NumberFormat fmt)
          Writes a value of the type associated with the property out to a PrintWriter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug

REGULAR

public static final int REGULAR
See Also:
Constant Field Values

READ_ONLY

public static final int READ_ONLY
See Also:
Constant Field Values

INHERITABLE

public static final int INHERITABLE
See Also:
Constant Field Values
Constructor Detail

PropertyDesc

public PropertyDesc(java.lang.String name,
                    java.lang.Class<?> hostClass)
Creates a new PropertyDesc object with a specific property name and host class.

Parameters:
name - name of the property.
hostClass - host class for the property.

PropertyDesc

public PropertyDesc(java.lang.String name,
                    java.lang.Class<?> hostClass,
                    java.lang.Class<?> valueClass)
Creates a new PropertyDesc for a property with a specified name, host class, and value class.

Parameters:
name - property name
hostClass - class object for the host class.
valueClass - class object for the value.

PropertyDesc

public PropertyDesc(PropertyDesc prop,
                    java.lang.Class<?> hostClass)
Creates a new PropertyDesc by copying an existing one and updating it for a specified host class.

Method Detail

getTypeCode

public static PropertyDesc.TypeCode getTypeCode(java.lang.Class<?> cls)

getValueClass

public java.lang.Class<?> getValueClass()
Returns the class type for the property's value.

Specified by:
getValueClass in interface PropertyInfo
Returns:
property value class type

getName

public java.lang.String getName()
Returns the name of the property associated with this descriptor.

Specified by:
getName in interface PropertyInfo
Returns:
name of the property

setName

public void setName(java.lang.String name)
Sets the name of the property associated with this descriptor.

Parameters:
name - new name of the property

getDescription

public java.lang.String getDescription()
Returns a text description of the property. This can be used for generating documentation, GUI tool tips, etc.

Specified by:
getDescription in interface PropertyInfo
Returns:
text description of the property
See Also:
setDescription(java.lang.String)

setDescription

public void setDescription(java.lang.String text)
Sets a text description for the property.

Parameters:
text - new text description
See Also:
getDescription()

getHostClass

public java.lang.Class<?> getHostClass()
Returns the host class of the property.

Specified by:
getHostClass in interface PropertyInfo
Returns:
host class of the property

setPrintFormat

public void setPrintFormat(java.lang.String fmtStr)
Sets the formatter used to convert numeric components of the property's value into text. The formatter is specified using a C printf-style format string. For a description of the format string syntax, see NumberFormat. The format should be consistent with the numeric type (e.g., %d or %x for integers, %g, $f or %e for floats).

Parameters:
fmtStr - numeric format string for the property
Throws:
java.lang.IllegalArgumentException - if the format string syntax is invalid
See Also:
getFormat()

setFormat

public void setFormat(NumberFormat fmt)
Directly sets the formatter used to convert numeric components of the property's value into text.

Parameters:
fmt - numeric formatter for the property
See Also:
getFormat(), setPrintFormat(String)

getFormat

public NumberFormat getFormat()
Returns the formatter used to convert numeric components of the property's value into text. The formatter may be null if there is no numeric data associated with the property.

Returns:
numeric formatter
See Also:
setFormat(NumberFormat), setPrintFormat(String)

getPrintFormat

public java.lang.String getPrintFormat()
Returns a format string used to convert numeric components of the property's value into text. This string may be null if there is no numeric data associated with the property.

Specified by:
getPrintFormat in interface PropertyInfo
Returns:
numeric format string
See Also:
setFormat(NumberFormat), setPrintFormat(String)

getAutoWrite

public boolean getAutoWrite()
Returns true if auto-writing is enabled for this property. Auto-writing means that the property and it's value should be written out by the method PropertyList.writeProps.

Specified by:
getAutoWrite in interface PropertyInfo
Returns:
true if auto-writing is enabled for this property

setAutoWrite

public void setAutoWrite(boolean enable)

getNullValueOK

public boolean getNullValueOK()
Returns true if the property value may be null.

Specified by:
getNullValueOK in interface PropertyInfo
Returns:
true if the property value may be null

setNullValueOK

public void setNullValueOK(boolean allowed)

getEditing

public PropertyInfo.Edit getEditing()
Returns information describing the conditions under which this property should be interactively edited.

Specified by:
getEditing in interface PropertyInfo
Returns:
conditions for interactive editing.

setEditing

public void setEditing(PropertyInfo.Edit edit)

getWidgetExpandState

public PropertyInfo.ExpandState getWidgetExpandState()

Specified by:
getWidgetExpandState in interface PropertyInfo

setWidgetExpandState

public void setWidgetExpandState(PropertyInfo.ExpandState state)

isReadOnly

public boolean isReadOnly()
Returns true if the property is read-only. A property is read-only if it's value cannot be set using the the Property.set method. getAutoWrite should return false for read-only properties, since it makes no sense to try to save such properties in persistent storage.

Specified by:
isReadOnly in interface PropertyInfo
Returns:
true if the property is read-only

hasRestrictedRange

public boolean hasRestrictedRange()
Returns true if the property has a restricted value range. If the property has a restricted range, the Property.getRange() method can be used to obtain a Range object to determine whether or not a particular value is legal.

Specified by:
hasRestrictedRange in interface PropertyInfo
Returns:
true if the property has a restricted value range

getDimension

public int getDimension()
Returns the numeric dimension of this property, or -1 if the property is not numeric or does not have a fixed dimension.

Specified by:
getDimension in interface PropertyInfo

setDimension

public void setDimension(int dim)

isSharable

public boolean isSharable()
Description copied from interface: PropertyInfo
Returns true if the value of this property is sharable among several hosts. This implies that the host does not maintain an internal copy of the value. Changes to the value itself may therefore effect several hosts.

Specified by:
isSharable in interface PropertyInfo
Returns:
true if the property value can be shared by several hosts

setGetMethod

public void setGetMethod(java.lang.String methodName)

setSetMethod

public void setSetMethod(java.lang.String methodName)

setGetRangeMethod

public void setGetRangeMethod(java.lang.String methodName)

setGetModeMethod

public void setGetModeMethod(java.lang.String methodName)

setSetModeMethod

public void setSetModeMethod(java.lang.String methodName)

setDefaultValue

public void setDefaultValue(java.lang.Object value)

getDefaultValue

public java.lang.Object getDefaultValue()
Description copied from interface: PropertyInfo
Returns the default value for the property, or Property.VoidValue if there is not default value.

Specified by:
getDefaultValue in interface PropertyInfo
Returns:
property's default value

createHandle

public Property createHandle(HasProperties host)
Creates a handle to the property for a specified host object. The host must export the property (i.e., it must be an instance of the class returned by getHostClass).

Specified by:
createHandle in interface PropertyInfo
Returns:
property handle

createInstance

public java.lang.Object createInstance(HasProperties host)
                                throws java.lang.InstantiationException,
                                       java.lang.IllegalAccessException
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

getValue

public java.lang.Object getValue(HasProperties host)

getRange

public Range getRange(HasProperties host)

setValue

public void setValue(HasProperties host,
                     java.lang.Object value)

getMode

public PropertyMode getMode(HasProperties host)

setMode

public void setMode(HasProperties host,
                    PropertyMode mode)

create

public static PropertyDesc create(java.lang.String nameAndMethods,
                                  java.lang.Class<?> hostClass,
                                  java.lang.String descriptor,
                                  java.lang.Object defaultValue,
                                  java.lang.String options,
                                  int propType)

valueEqualsDefault

public boolean valueEqualsDefault(java.lang.Object value)
Description copied from interface: PropertyInfo
Returns true if a specified value equals the default value of the property.

Specified by:
valueEqualsDefault in interface PropertyInfo
Parameters:
value - value to check against the default
Returns:
true if the value equals the default value

getDefaultNumericRange

public NumericInterval getDefaultNumericRange()
Returns a default numeric range for this property, if any. If there is no default numeric range, null is returned.

If a getRangeMethod is not defined for the property, and the property has a numeric type, then the default numeric range is returned by the property's getRange method. The default numeric range is also used to determine bounds on slider widgets for manipulating the property's value, in case the upper or lower limits returned by the getRange method are unbounded.

Specified by:
getDefaultNumericRange in interface PropertyInfo
Returns:
default numeric range for this property
See Also:
setNumericRange(maspack.util.NumericInterval)

setNumericRange

public void setNumericRange(NumericInterval rng)
Sets a NumericRange for this property. A null argument will cause any existing NumericRange to be removed. At present, numeric ranges are mainly used when automatically creating GUI sliders to manipulate property values.

Parameters:
rng - new numeric range for this property (value is copied).

writeValue

public void writeValue(java.lang.Object value,
                       java.io.PrintWriter pw,
                       NumberFormat fmt)
                throws java.io.IOException
Writes a value of the type associated with the property out to a PrintWriter.

Specified by:
writeValue in interface PropertyInfo
Parameters:
value - value to be written
pw - PrintWriter to which value is written
fmt - Numeric formatting information. This is only used when the value to be writtem is itself Scannable, in which case it is passed to that value's write method.
Throws:
java.io.IOException - if an I/O error occurred, or the value has a type which PropertyInfo does not know about

scanValue

public java.lang.Object scanValue(ReaderTokenizer rtok)
                           throws java.io.IOException
Scans a value of the type associated with the property from a ReaderTokenizer.

Specified by:
scanValue in interface PropertyInfo
Parameters:
rtok - ReaderTokenizer supplying input tokens used to specify the property value
Throws:
java.io.IOException - if the input is not in the correct format, an I/O error occurred, or the value has a type which PropertyInfo does not know about

isInheritable

public boolean isInheritable()
Returns true if the property is a inheritable property.

Specified by:
isInheritable in interface PropertyInfo

getDefaultMode

public PropertyMode getDefaultMode()
Returns the default inheritance mode for the property. If the property is not inheritable, then this method should return PropertyMode.Explicit.

Specified by:
getDefaultMode in interface PropertyInfo
Returns:
default inheritance mode