Package ghidra.framework.options

# Class SaveState

java.lang.Object
ghidra.framework.options.GProperties
ghidra.framework.options.XmlProperties
ghidra.framework.options.SaveState

Direct Known Subclasses:
  `PreferenceState`

public class SaveState extends XmlProperties
Class for saving name/value pairs as XML or Json. Classes that want to be able to save their state can do so using the SaveState object. The idea is that each state variable in the class is first saved into a SaveState object via a String key. Then the SaveState object is written out as XML or Json. When the save state object is restored, the SaveState object is constructed with an XML Element or JsonObject that contains all of the name/value pairs. Since the "get" methods require a default value, the object that is recovering its state variables will be successfully initialized even if the given key,value pair is not found in the SaveState object.

Note: Names for options are assumed to be unique. When a putXXX() method is called, if a value already exists for a name, it will be overwritten.

The SaveState supports the following types:

          java primitives
          arrays of java primitives
          String
          Color
          Font
          KeyStroke
          File
          Date
          Enum
          SaveState (values can be nested SaveStates)

- ## Field Summary

  ### Fields inherited from class ghidra.framework.options.GProperties

  `DATE_FORMAT, map, NAME, TYPE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SaveState()`
  Default Constructor for SaveState; uses "SAVE_STATE" as the name of the state.
  `SaveState(File file)`
  Construct a SaveState from a file containing XML from a previously saved SaveState.
  `SaveState(String name)`
  Creates a new SaveState object with a non-default name.
  `SaveState(org.jdom.Element element)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected org.jdom.Element`
  `createElement(String key, Object value)`
  `SaveState`
  `getSaveState(String name)`
  Returns the sub SaveState associated with the given name.
  `protected void`
  `processElement(org.jdom.Element element)`
  `void`
  `putSaveState(String name, SaveState value)`
  Associates a sub SaveState value with the given name.
  `void`
  `saveToFile(File file)`
  Write the saveState to a file as XML

  ### Methods inherited from class ghidra.framework.options.GProperties

  `clear, createElementFromElement, getAsType, getBoolean, getBooleans, getByte, getBytes, getColor, getDate, getDouble, getDoubles, getEnum, getFile, getFloat, getFloats, getFont, getGProperties, getInt, getInts, getKeyStroke, getLong, getLongs, getNames, getShort, getShorts, getString, getStrings, getXmlElement, hasValue, isEmpty, putBoolean, putBooleans, putByte, putBytes, putColor, putDate, putDouble, putDoubles, putEnum, putFile, putFloat, putFloats, putFont, putGProperties, putInt, putInts, putKeyStroke, putLong, putLongs, putShort, putShorts, putString, putStrings, putXmlElement, remove, saveToJson, saveToJsonFile, saveToXml, saveToXmlFile, size, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### SaveState

    public SaveState(String name)
    Creates a new SaveState object with a non-default name. The name serves no real purpose other than as a hint as to what the SaveState represents
    Parameters:
      `name` - of the state

  - ### SaveState

    public SaveState()
    Default Constructor for SaveState; uses "SAVE_STATE" as the name of the state.
    See Also:
      - `Object()`

  - ### SaveState

    public SaveState(File file) throws IOException
    Construct a SaveState from a file containing XML from a previously saved SaveState.
    Parameters:
      `file` - the file containing the XML to read.
    Throws:
      `IOException` - if the file can't be read or is not formatted properly for a SaveState

  - ### SaveState

    public SaveState(org.jdom.Element element)

- ## Method Details

  - ### saveToFile

    public void saveToFile(File file) throws IOException
    Write the saveState to a file as XML
    Parameters:
      `file` - the file to write to.
    Throws:
      `IOException` - if the file could not be written

  - ### putSaveState

    public void putSaveState(String name, SaveState value)
    Associates a sub SaveState value with the given name.
    Parameters:
      `name` - The name in the name,value pair.
      `value` - The value in the name,value pair.

  - ### getSaveState

    public SaveState getSaveState(String name)
    Returns the sub SaveState associated with the given name.
    Parameters:
      `name` - The name associated with the desired Element.
    Returns:
      The SaveState object associated with the given name.

  - ### processElement

    protected void processElement(org.jdom.Element element)
    Overrides:
      `processElement` in class `GProperties`

  - ### createElement

    protected org.jdom.Element createElement(String key, Object value)
    Overrides:
      `createElement` in class `GProperties`