public class PropertyDesc extends java.lang.Object implements PropertyInfo
Modifier and Type | Class and Description |
---|---|
static class |
PropertyDesc.TypeCode |
PropertyInfo.Edit, PropertyInfo.ExpandState
Modifier and Type | Field and Description |
---|---|
static boolean |
debug |
static int |
INHERITABLE |
static int |
READ_ONLY |
static int |
REGULAR |
Constructor and Description |
---|
PropertyDesc()
Creates an empty PropertyDesc.
|
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.
|
Modifier and Type | Method and Description |
---|---|
Property |
createHandle(HasProperties host)
Creates a handle to the property for a specified host object.
|
java.lang.Object |
createInstance(HasProperties host) |
java.util.List<java.lang.Class<?>> |
getAllowedTypes()
Returns a list of allowed classes that should be used for creating
instances of this property.
|
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.
|
java.lang.Object |
getKey()
Returns the key for the property associated with this descriptor,
or
null if there is no key. |
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.
|
static boolean |
initialize(PropertyDesc desc,
java.lang.String nameAndMethods,
java.lang.Object key,
java.lang.Class<?> hostClass,
java.lang.String descriptor,
java.lang.Object defaultValue,
java.lang.String options,
int propType) |
static boolean |
initialize(PropertyDesc desc,
java.lang.String name,
java.lang.String methods,
java.lang.Object key,
java.lang.Class<?> hostClass,
java.lang.String descriptor,
java.lang.Object defaultValue,
java.lang.String options,
int propType) |
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.
|
boolean |
isSliderAllowed()
Returns
true if a slider is allowed to be used in
the interactive editing widget created for this property. |
java.lang.Object |
scanInstance(ReaderTokenizer rtok)
For a property whose class type implements
Scannable , attempts to
create and return a class instance based on input from a tokenizer. |
java.lang.Object |
scanValue(ReaderTokenizer rtok)
Scans a value of the type associated with the property from a
ReaderTokenizer.
|
static java.lang.Object |
scanValue(ReaderTokenizer rtok,
PropertyDesc.TypeCode valueType,
java.lang.Class<?> valueClass)
Static version of
scanValue(maspack.util.ReaderTokenizer, maspack.properties.PropertyDesc.TypeCode, java.lang.Class<?>) , with the value type and
class explicitly specified. |
void |
set(PropertyDesc desc,
java.lang.Class<?> hostClass)
Sets this PropertyDesc from an existing one and a
a specified host class.
|
void |
setAllowedTypes(java.util.List<java.lang.Class<?>> types) |
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 |
setKey(java.lang.Object key)
Sets a key for the property associated with this descriptor.
|
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 |
setSliderAllowed(boolean allowed) |
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.
|
boolean |
writeIfNonDefault(HasProperties host,
java.io.PrintWriter pw,
NumberFormat fmt,
java.lang.Object ref) |
void |
writeValue(java.lang.Object value,
java.io.PrintWriter pw,
NumberFormat fmt,
java.lang.Object ref)
Writes a value of the type associated with the property out to a
PrintWriter.
|
static boolean |
writeValue(java.lang.Object value,
java.io.PrintWriter pw,
PropertyDesc.TypeCode valueType,
java.lang.Class<?> valueClass,
NumberFormat floatFmt,
NumberFormat fmt,
java.lang.Object ref) |
public static boolean debug
public static final int REGULAR
public static final int READ_ONLY
public static final int INHERITABLE
public PropertyDesc()
public PropertyDesc(java.lang.String name, java.lang.Class<?> hostClass)
name
- name of the property.hostClass
- host class for the property.public PropertyDesc(java.lang.String name, java.lang.Class<?> hostClass, java.lang.Class<?> valueClass)
name
- property namehostClass
- class object for the host class.valueClass
- class object for the value.public void set(PropertyDesc desc, java.lang.Class<?> hostClass)
public static PropertyDesc.TypeCode getTypeCode(java.lang.Class<?> cls)
public java.lang.Class<?> getValueClass()
getValueClass
in interface PropertyInfo
public java.lang.String getName()
getName
in interface PropertyInfo
public void setName(java.lang.String name)
name
- new name of the propertypublic java.lang.Object getKey()
null
if there is no key.public void setKey(java.lang.Object key)
key
- new key for the propertypublic java.lang.String getDescription()
getDescription
in interface PropertyInfo
setDescription(java.lang.String)
public void setDescription(java.lang.String text)
text
- new text descriptiongetDescription()
public java.lang.Class<?> getHostClass()
getHostClass
in interface PropertyInfo
public void setPrintFormat(java.lang.String fmtStr)
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).fmtStr
- numeric format string for the propertyjava.lang.IllegalArgumentException
- if the format string syntax is invalidgetFormat()
public void setFormat(NumberFormat fmt)
fmt
- numeric formatter for the propertygetFormat()
,
setPrintFormat(String)
public NumberFormat getFormat()
setFormat(NumberFormat)
,
setPrintFormat(String)
public java.lang.String getPrintFormat()
getPrintFormat
in interface PropertyInfo
setFormat(NumberFormat)
,
setPrintFormat(String)
public boolean getAutoWrite()
PropertyList.writeProps
.getAutoWrite
in interface PropertyInfo
public void setAutoWrite(boolean enable)
public boolean getNullValueOK()
getNullValueOK
in interface PropertyInfo
public void setNullValueOK(boolean allowed)
public PropertyInfo.Edit getEditing()
getEditing
in interface PropertyInfo
public void setEditing(PropertyInfo.Edit edit)
public PropertyInfo.ExpandState getWidgetExpandState()
getWidgetExpandState
in interface PropertyInfo
public void setWidgetExpandState(PropertyInfo.ExpandState state)
public boolean isSliderAllowed()
true
if a slider is allowed to be used in
the interactive editing widget created for this property. In addition
to this, creation of sliders also require that the property have
a numeric value and a valid range.isSliderAllowed
in interface PropertyInfo
true
if a slider is allowed in the widgetpublic void setSliderAllowed(boolean allowed)
public boolean isReadOnly()
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.isReadOnly
in interface PropertyInfo
public boolean hasRestrictedRange()
Property.getRange()
method can be used to obtain a Range
object to
determine whether or not a particular value is legal.hasRestrictedRange
in interface PropertyInfo
public int getDimension()
getDimension
in interface PropertyInfo
public void setDimension(int dim)
public boolean isSharable()
PropertyInfo
isSharable
in interface PropertyInfo
public void setGetMethod(java.lang.String methodName)
public void setSetMethod(java.lang.String methodName)
public void setGetModeMethod(java.lang.String methodName)
public void setSetModeMethod(java.lang.String methodName)
public void setDefaultValue(java.lang.Object value)
public java.lang.Object getDefaultValue()
PropertyInfo
Property.VoidValue
if there is not default value.getDefaultValue
in interface PropertyInfo
public Property createHandle(HasProperties host)
getHostClass
).createHandle
in interface PropertyInfo
public java.lang.Object createInstance(HasProperties host) throws java.lang.InstantiationException, java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.IllegalAccessException
public java.lang.Object getValue(HasProperties host)
public Range getRange(HasProperties host)
public void setValue(HasProperties host, java.lang.Object value)
public PropertyMode getMode(HasProperties host)
public void setMode(HasProperties host, PropertyMode mode)
public static boolean initialize(PropertyDesc desc, java.lang.String nameAndMethods, java.lang.Object key, java.lang.Class<?> hostClass, java.lang.String descriptor, java.lang.Object defaultValue, java.lang.String options, int propType)
public static boolean initialize(PropertyDesc desc, java.lang.String name, java.lang.String methods, java.lang.Object key, java.lang.Class<?> hostClass, java.lang.String descriptor, java.lang.Object defaultValue, java.lang.String options, int propType)
public boolean valueEqualsDefault(java.lang.Object value)
PropertyInfo
valueEqualsDefault
in interface PropertyInfo
value
- value to check against the defaultpublic NumericInterval getDefaultNumericRange()
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.
getDefaultNumericRange
in interface PropertyInfo
setNumericRange(maspack.util.NumericInterval)
public void setNumericRange(NumericInterval rng)
rng
- new numeric range for this property (value is copied).public boolean writeIfNonDefault(HasProperties host, java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref) throws java.io.IOException
writeIfNonDefault
in interface PropertyInfo
java.io.IOException
public static boolean writeValue(java.lang.Object value, java.io.PrintWriter pw, PropertyDesc.TypeCode valueType, java.lang.Class<?> valueClass, NumberFormat floatFmt, NumberFormat fmt, java.lang.Object ref) throws java.io.IOException
java.io.IOException
public void writeValue(java.lang.Object value, java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref) throws java.io.IOException
writeValue
in interface PropertyInfo
value
- value to be writtenpw
- PrintWriter to which value is writtenfmt
- Numeric formatting information. This is only used when the value to be
written is itself Scannable
, in which case
it is passed to that value's write
method.ref
- Reference object. This is only used when the value to be
written is itself Scannable
, in which case
it is passed to that value's write
method.java.io.IOException
- if an I/O error occurred, or the value has a type which PropertyInfo does
not know aboutpublic static java.lang.Object scanValue(ReaderTokenizer rtok, PropertyDesc.TypeCode valueType, java.lang.Class<?> valueClass) throws java.io.IOException
scanValue(maspack.util.ReaderTokenizer, maspack.properties.PropertyDesc.TypeCode, java.lang.Class<?>)
, with the value type and
class explicitly specified.rtok
- ReaderTokenizer supplying input tokens used to specify the property valuevalueType
- Code specifying the class type of the value. It is possible to
obtain this from valueClass
by calling getTypeCode(java.lang.Class<?>)
.valueClass
- Class type for the valuejava.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 aboutpublic java.lang.Object scanInstance(ReaderTokenizer rtok) throws java.io.IOException
Scannable
, attempts to
create and return a class instance based on input from a tokenizer.
"null"
, then no instance is created and null
is
returned. Otherwise, the word is assumed to be the name of a class for
which an instance is created and returned. The class must equal or be a
subclass of the property's value class.
Any returned value instance will need to subsequently scan itself from
the input stream using its scan
method. As
mentioned above, it is assumed the initial token required for this scan
is a '['
.
Since this method temporarily changes the accepted word characters
in order to read a class name, it should not be called if the next
available token might have been pushed back on the token stream using
pushBack()
.
scanInstance
in interface PropertyInfo
rtok
- ReaderTokenizer supplying input tokensnull
if "null"
appears as the next token.java.io.IOException
- if no class is found for the class name specified in
the input stream, or the class is not equal to, or a subclass of,
the property's value class, or the class cannot be instantiated.public java.lang.Object scanValue(ReaderTokenizer rtok) throws java.io.IOException
Since this method temporarily changes the accepted word characters
in order to read a class name, it should not be called if the next
available token might have been pushed back on the token stream using
pushBack()
.
scanValue
in interface PropertyInfo
rtok
- ReaderTokenizer supplying input tokens used to specify the property valuejava.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 aboutpublic boolean isInheritable()
inheritable
property.isInheritable
in interface PropertyInfo
public PropertyMode getDefaultMode()
getDefaultMode
in interface PropertyInfo
public void setAllowedTypes(java.util.List<java.lang.Class<?>> types)
public java.util.List<java.lang.Class<?>> getAllowedTypes()
PropertyInfo.getValueClass()
. If there are no restrictions, this
method should return null
. At present, this method is intended as
a hint for use in widgets that manipulate the property value.getAllowedTypes
in interface PropertyInfo