Package uk.ac.starlink.topcat.activate
Class ConfigState
java.lang.Object
uk.ac.starlink.topcat.activate.ConfigState
Object that can preserve the state of a collection of GUI components
in a way that is easy to de/serialize.
This object provides convenience methods on top of a String->String map,
which constitutes its only state, so that serialization to a
string context presents no problems.
The intention is that restoring from state encoded in this object
should be lenient, for instance ignoring unrecognised keys,
so that it can be used in contexts in which the format has changed
somewhat between serialization and deserialization, for instance
as a consequence of sofware updates.
The various restore(key,component)
methods will not affect the
supplied GUI components in the case that the map contains no entry
for the given key.
- Since:
- 30 Apr 2018
- Author:
- Mark Taylor
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty state object.ConfigState
(Map<String, String> map) Constructs an object populated by a given map. -
Method Summary
Modifier and TypeMethodDescriptionint
Retrieves an entry of this map as an integer.getMap()
Returns the map on which this object is based.void
restoreFlag
(String key, ButtonModel model) Restores the selection state of a toggle button model from this map.void
restoreSelection
(String key, JComboBox<?> selector) Restores the selection of a combo box from this map.void
restoreText
(String key, JTextComponent textComp) Restores the text content of a text component from this map.void
saveFlag
(String key, ButtonModel model) Stores the selection state of a button model in this map.void
saveSelection
(String key, JComboBox<?> selector) Stores the selection of a combo box in this map.void
saveText
(String key, JTextComponent textComp) Stores the text content of a text component in this map.void
Sets an entry of this map as an integer.
-
Constructor Details
-
ConfigState
public ConfigState()Constructs an empty state object. -
ConfigState
Constructs an object populated by a given map.- Parameters:
map
- map constituting this object's content
-
-
Method Details
-
getMap
Returns the map on which this object is based. It may, in general, be modified.- Returns:
- map
-
setInt
Sets an entry of this map as an integer.- Parameters:
key
- entry keyvalue
- integer value
-
getInt
Retrieves an entry of this map as an integer.- Parameters:
key
- entry key- Returns:
- integer value, or 0 if not present
-
saveFlag
Stores the selection state of a button model in this map.- Parameters:
key
- entry keymodel
- toggle model containing state
-
restoreFlag
Restores the selection state of a toggle button model from this map.- Parameters:
key
- entry keymodel
- toggle model to be updated with state
-
saveText
Stores the text content of a text component in this map.- Parameters:
key
- entry keytextComp
- component containing state
-
restoreText
Restores the text content of a text component from this map.- Parameters:
key
- entry keytextComp
- text component to be updated with state
-
saveSelection
Stores the selection of a combo box in this map. The text representation is stored. The selector does not need to contain entries that are strings, but the save/restore will only work if at least the cell renderer is a JLabel whose text property is manipulated to represent (uniquely) the value.- Parameters:
key
- entry keyselector
- selection component containing state
-
restoreSelection
Restores the selection of a combo box from this map.- Parameters:
key
- entry keyselector
- selection component to be updated with state
-