Class GValuesMap

java.lang.Object
docking.widgets.values.GValuesMap
Direct Known Subclasses:
GhidraValuesMap

public class GValuesMap extends Object
Class for defining, storing, and retrieving groups of values of various types. The intended use is to create a ValuesMap, define some named values, and then invoke the ValuesMapDialog to allow the user to fill in values for the defined values. It also has a rich set of convenience methods for adding predefined value types to the map. Users can also directly add custom value types by using the addValue(AbstractValue) method.
  • Field Details

  • Constructor Details

    • GValuesMap

      public GValuesMap()
  • Method Details

    • getValues

      public Collection<AbstractValue<?>> getValues()
      Returns a collection of the AbstractValues defined in this ValuesMap.
      Returns:
      a collection of the AbstractValues defined in this ValuesMap.
    • addValue

      public AbstractValue<?> addValue(AbstractValue<?> value)
      Adds an AbstractValue to this ValuesMap. This is a way to add a custom AbstractValue that doesn't have a convenience method for a predefine value type.
      Parameters:
      value - the AbstractValue to add to this ValuesMap
      Returns:
      returns the added value
    • setValidator

      public void setValidator(ValuesMapValidator validator)
      Sets a ValuesMapValidator. If set, this will be called when the user presses the "Ok" button on the ValuesMapDialog. If the validator passes (returns true), then the dialog will close and return the user values. Otherwise, the dialog will display the error message (via the StatusListener in the ValuesMapValidator.validate(GValuesMap, StatusListener) call) and remain open.
      Parameters:
      validator - the validator to be called before returning from the dialog
    • isValid

      public boolean isValid(StatusListener listener)
      The call to validate the data using the ValuesMapValidator set in the setValidator(ValuesMapValidator) method. If no validator has been set, this method will return true.
      Parameters:
      listener - The StatusListener for reporting an error message.
      Returns:
      true if the validator passes or no validator has been set.
    • updateFromComponents

      public void updateFromComponents() throws ValuesMapParseException
      Updates each value in this ValuesMap from its corresponding JComponent.
      Throws:
      ValuesMapParseException - if any value encountered an error trying to update its value from the editor component.
    • getAbstractValue

      public AbstractValue<?> getAbstractValue(String name)
      Returns the AbstractValue for the given value name.
      Parameters:
      name - the name for which to get the AbstractValue
      Returns:
      the AbstractValue for the given value name.
    • isDefined

      public boolean isDefined(String name)
      Returns true if there is a defined value for the given name.
      Parameters:
      name - the name of the value to check for
      Returns:
      true if there is a defined value for the given name.
    • hasValue

      public boolean hasValue(String name)
      Returns true if the value defined for the given name has a non-null value.
      Parameters:
      name - the name of the value
      Returns:
      true if the value defined for the given name has a non-null value.
    • copyValues

      public void copyValues(GValuesMap otherMap)
      Copies the values (not the AbstractValues objects, but the T values of each AbstractValue) from the given map into this map. The given map must have exactly the same name and AbstractValue types as this map.
      Parameters:
      otherMap - The GValuesMap to copy values from
      Throws:
      IllegalArgumentException - if the given map does not have exactly the same set of names and types as this this map
    • defineBoolean

      public BooleanValue defineBoolean(String name, boolean defaultValue)
      Defines a value of type Boolean.
      Parameters:
      name - the name for this value
      defaultValue - the default value for this boolean value.
      Returns:
      the new BooleanValue that was defined.
    • defineChoice

      public ChoiceValue defineChoice(String name, String defaultValue, String... choices)
      Defines a value of type String, but with a restricted set of valid string values.
      Parameters:
      name - the name for this value.
      defaultValue - an optional (can be null) initial value
      choices - varargs list of valid string choices
      Returns:
      the new ChoiceValue that was defined
    • defineDirectory

      public FileValue defineDirectory(String name, File defaultValue)
      Defines a value of type File, but is restricted to directories.
      Parameters:
      name - the name for this value
      defaultValue - an optional initial value
      Returns:
      the new FileValue that was defined
    • defineDouble

      public DoubleValue defineDouble(String name)
      Defines a value of type Double with no initial default value.
      Parameters:
      name - the name for this value
      Returns:
      the new DoubleValue that was defined
    • defineDouble

      public DoubleValue defineDouble(String name, double defaultValue)
      Defines a value of type Double with an initial value
      Parameters:
      name - the name for this value
      defaultValue - the initial value
      Returns:
      the new DoubleValue that was defined
    • defineFile

      public FileValue defineFile(String name, File defaultValue)
      Defines a value of type File
      Parameters:
      name - the name for this value
      defaultValue - an optional initial value
      Returns:
      the new FileValue that was defined
    • defineFile

      public FileValue defineFile(String name, File defaultValue, File startingDir)
      Defines a value of type File
      Parameters:
      name - the name for this value
      defaultValue - an optional initial value
      startingDir - specifies the starting directory when the FileChooser is invoked
      Returns:
      the new FileValue that was defined
    • defineHexInt

      public IntValue defineHexInt(String name)
      Defines a value of type Integer that displays as a hex value.
      Parameters:
      name - the name for this value
      Returns:
      the new IntValue that was defined
    • defineHexInt

      public IntValue defineHexInt(String name, int defaultValue)
      Defines a value of type Integer with an initial value and displays as a hex value.
      Parameters:
      name - the name for this value
      defaultValue - the initial value
      Returns:
      the new IntValue that was defined
    • defineHexLong

      public LongValue defineHexLong(String name)
      Defines a value of type Long that displays as a hex value.
      Parameters:
      name - the name for this value
      Returns:
      the new LongValue that was defined
    • defineHexLong

      public LongValue defineHexLong(String name, long defaultValue)
      Defines a value of type Long with an initial value and displays as a hex value.
      Parameters:
      name - the name for this value
      defaultValue - the initial value
      Returns:
      the new LongValue that was defined
    • defineInt

      public IntValue defineInt(String name)
      Defines a value of type Integer with no initial value.
      Parameters:
      name - the name for this value
      Returns:
      the new IntValue that was defined
    • defineInt

      public IntValue defineInt(String name, int defaultValue)
      Defines a value of type Integer with an initial value.
      Parameters:
      name - the name for this value
      defaultValue - the initial value
      Returns:
      the new IntValue that was defined
    • defineLong

      public LongValue defineLong(String name)
      Defines a value of type Long with an initial value.
      Parameters:
      name - the name for this value
      Returns:
      the new LongValue that was defined
    • defineLong

      public LongValue defineLong(String name, long defaultValue)
      Defines a value of type Long with an initial value.
      Parameters:
      name - the name for this value
      defaultValue - the initial value
      Returns:
      the new LongValue that was defined
    • defineString

      public StringValue defineString(String name)
      Defines a value of type String.
      Parameters:
      name - the name for this value
      Returns:
      the new StringValue that was defined
    • defineString

      public StringValue defineString(String name, String defaultValue)
      Defines a value of type String with an optional initial value
      Parameters:
      name - the name for this value
      defaultValue - the initial value (can be null)
      Returns:
      the new StringValue that was defined
    • getBoolean

      public boolean getBoolean(String name)
      Gets the boolean value for the given name.
      Parameters:
      name - the name of a previously defined boolean value
      Returns:
      the boolean value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a boolean type
    • getChoice

      public String getChoice(String name)
      Gets the Choice (String) value for the given name. The value will be either null or one of the strings that were defined as valid choices.
      Parameters:
      name - the name of a previously defined Choice value
      Returns:
      the Choice value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a Choice type
    • getDouble

      public double getDouble(String name)
      Gets the double value for the given name.
      Parameters:
      name - the name of a previously defined double value
      Returns:
      the double value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a double type
    • getFile

      public File getFile(String name)
      Gets the File value for the given name.
      Parameters:
      name - the name of a previously defined File value
      Returns:
      the File value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a File type
    • getInt

      public int getInt(String name)
      Gets the int value for the given name.
      Parameters:
      name - the name of a previously defined int value
      Returns:
      the int value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a int type
    • getLong

      public long getLong(String name)
      Gets the long value for the given name.
      Parameters:
      name - the name of a previously defined long value
      Returns:
      the long value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a long type
    • getString

      public String getString(String name)
      Gets the String value for the given name.
      Parameters:
      name - the name of a previously defined String value
      Returns:
      the String value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a String type
    • setBoolean

      public void setBoolean(String name, boolean value)
      Sets the boolean value for the given name.
      Parameters:
      name - the name of the boolean value that was previously defined
      value - the boolean to set as the value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a boolean type
    • setChoice

      public void setChoice(String name, String choice)
      Sets the Choice (String) value for the given name.
      Parameters:
      name - the name of the Choice value that was previously defined
      choice - the string to set as the value. This String must be one of the defined choices
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a choice type
    • setDouble

      public void setDouble(String name, double value)
      Sets the double value for the given name.
      Parameters:
      name - the name of the double value that was previously defined
      value - the double to set as the value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a double type
    • setFile

      public void setFile(String name, File value)
      Sets the File value for the given name.
      Parameters:
      name - the name of the File value that was previously defined
      value - the File to set as the value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a File type
    • setInt

      public void setInt(String name, int value)
      Sets the int value for the given name.
      Parameters:
      name - the name of the int value that was previously defined
      value - the int to set as the value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a int type
    • setLong

      public void setLong(String name, long value)
      Sets the long value for the given name.
      Parameters:
      name - the name of the long value that was previously defined
      value - the long to set as the value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a long type
    • setString

      public void setString(String name, String value)
      Sets the String value for the given name.
      Parameters:
      name - the name of the String value that was previously defined
      value - the String to set as the value
      Throws:
      IllegalArgumentException - if the name hasn't been defined as a String type
    • getValue

      protected <T> T getValue(String name, Class<T> c, String typeName)
    • checkDup

      protected void checkDup(String name)
    • reset

      protected void reset()
      Resets the values back to their original values when constructed. Used by the dialog when the user cancels.