Package docking.widgets.values
Class AbstractValue<T>
java.lang.Object
docking.widgets.values.AbstractValue<T>
- Type Parameters:
T
- The type of the value stored and edited by this class
- Direct Known Subclasses:
AddressValue
,BooleanValue
,ChoiceValue
,DoubleValue
,FileValue
,IntValue
,LanguageValue
,LongValue
,ProjectFileValue
,ProjectFolderValue
,StringValue
Abstract base class for defined name/values in a
GValuesMap
and whose values can be
edited in the ValuesMapDialog
. Its main purpose is to provide a JComponent for
editing the value. Generally, objects of this type can be in one of two states: having a value
or not. This can be useful for validating the dialog input values to ensure the user enters
a value.
There are two situations where parse/conversion exceptions can occur in subclass implementations.
One is the setAsText(String)
method. The subclass should catch any specific expected
exception when parsing the string and convert it to an IllegalArgumentException. The other method
is the updateValueFromComponent()
method which may also need to parse string data. In
this case any expected exception should be converted to ValuesMapParseException
. This
is the only exception type the dialog will be trapping and displaying error messages for in the
ValuesMapDialog
. Any other type of exception will be considered unexpected and a
programing error and will be eventally be handled by the default application error handler.
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractValue
(String name, T defaultValue) Constructor that assigned a name and optional initial value for this object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
copyValue
(AbstractValue<T> other) Copies the T value from the given AbstractValue to this AbstractValue.protected abstract T
fromString
(String valueString) Parses the given string into a value of type TReturns a string representation for the value.abstract JComponent
Returns a JComponent for entering or editing a value of this type.getName()
Returns the name of this value object.getValue()
Returns the value currently assigned to this object.boolean
hasValue()
Returns true if the value is non-null.protected void
reset()
Resets the value to its original value when constructedSets the value for this object from the given string.void
Sets the value for this object.protected String
protected abstract void
Updates the JComponent returned fromgetComponent()
to represent the current value of this object.protected abstract void
Causes the stored value for this object to be updated based on the state of the JComponent returned fromgetComponent()
-
Constructor Details
-
AbstractValue
Constructor that assigned a name and optional initial value for this object.- Parameters:
name
- the name associated with this value.defaultValue
- an optional initial value for this object
-
-
Method Details
-
getName
Returns the name of this value object.- Returns:
- the name of this value object
-
getValue
Returns the value currently assigned to this object.- Returns:
- the value currently assigned to this object (may be null)
-
setValue
Sets the value for this object.- Parameters:
value
- the value to set for this object (may be null)
-
copyValue
Copies the T value from the given AbstractValue to this AbstractValue.- Parameters:
other
- the AbstractValue to copy from
-
hasValue
public boolean hasValue()Returns true if the value is non-null.- Returns:
- true if the value is non-null
-
setAsText
Sets the value for this object from the given string. If this object can not succesfully parse the string, an exception will be thrown.- Parameters:
valueString
- the string to be parsed into the type for this object- Returns:
- The value resulting from parsing the string value
- Throws:
IllegalArgumentException
- if the string can not be parsed into a value of type T
-
getAsText
Returns a string representation for the value. It is expected that the string returned from this method can be parsed by the correspondingsetAsText(String)
method. If the value of this object is null, null will be returned.- Returns:
- a string representation for the value or null if the value is null
-
reset
protected void reset()Resets the value to its original value when constructed -
toString
-
getComponent
Returns a JComponent for entering or editing a value of this type.- Returns:
- a JComponent for entering or editing a value of this type.
-
updateValueFromComponent
Causes the stored value for this object to be updated based on the state of the JComponent returned fromgetComponent()
- Throws:
ValuesMapParseException
- if an error occurs trying update the value from a component. This usually is a result of trying to parse a string value.
-
updateComponentFromValue
protected abstract void updateComponentFromValue()Updates the JComponent returned fromgetComponent()
to represent the current value of this object. -
fromString
Parses the given string into a value of type T- Parameters:
valueString
- the string to parse- Returns:
- a value of type T
-