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
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
ConstructorDescriptionDefault Constructor for SaveState; uses "SAVE_STATE" as the name of the state.Construct a SaveState from a file containing XML from a previously saved SaveState.Creates a new SaveState object with a non-default name.SaveState
(org.jdom.Element element) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.jdom.Element
createElement
(String key, Object value) 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 XMLMethods 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
-
Constructor Details
-
SaveState
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:
-
SaveState
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
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
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
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 classGProperties
-
createElement
- Overrides:
createElement
in classGProperties
-