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

public abstract class AbstractValue<T> extends Object
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 Details

    • AbstractValue

      protected AbstractValue(String name, T defaultValue)
      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

      public String getName()
      Returns the name of this value object.
      Returns:
      the name of this value object
    • getValue

      public T getValue()
      Returns the value currently assigned to this object.
      Returns:
      the value currently assigned to this object (may be null)
    • setValue

      public void setValue(T value)
      Sets the value for this object.
      Parameters:
      value - the value to set for this object (may be null)
    • copyValue

      public void copyValue(AbstractValue<T> other)
      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

      public T setAsText(String valueString)
      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

      public String getAsText()
      Returns a string representation for the value. It is expected that the string returned from this method can be parsed by the corresponding setAsText(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

      protected String toString(T t)
    • getComponent

      public abstract JComponent 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

      protected abstract void updateValueFromComponent() throws ValuesMapParseException
      Causes the stored value for this object to be updated based on the state of the JComponent returned from getComponent()
      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 from getComponent() to represent the current value of this object.
    • fromString

      protected abstract T fromString(String valueString)
      Parses the given string into a value of type T
      Parameters:
      valueString - the string to parse
      Returns:
      a value of type T