Class ConfigState

java.lang.Object
uk.ac.starlink.topcat.activate.ConfigState

public class ConfigState extends Object
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 Details

    • ConfigState

      public ConfigState()
      Constructs an empty state object.
    • ConfigState

      public ConfigState(Map<String,String> map)
      Constructs an object populated by a given map.
      Parameters:
      map - map constituting this object's content
  • Method Details

    • getMap

      public Map<String,String> getMap()
      Returns the map on which this object is based. It may, in general, be modified.
      Returns:
      map
    • setInt

      public void setInt(String key, int value)
      Sets an entry of this map as an integer.
      Parameters:
      key - entry key
      value - integer value
    • getInt

      public int getInt(String key)
      Retrieves an entry of this map as an integer.
      Parameters:
      key - entry key
      Returns:
      integer value, or 0 if not present
    • saveFlag

      public void saveFlag(String key, ButtonModel model)
      Stores the selection state of a button model in this map.
      Parameters:
      key - entry key
      model - toggle model containing state
    • restoreFlag

      public void restoreFlag(String key, ButtonModel model)
      Restores the selection state of a toggle button model from this map.
      Parameters:
      key - entry key
      model - toggle model to be updated with state
    • saveText

      public void saveText(String key, JTextComponent textComp)
      Stores the text content of a text component in this map.
      Parameters:
      key - entry key
      textComp - component containing state
    • restoreText

      public void restoreText(String key, JTextComponent textComp)
      Restores the text content of a text component from this map.
      Parameters:
      key - entry key
      textComp - text component to be updated with state
    • saveSelection

      public void saveSelection(String key, JComboBox<?> selector)
      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 key
      selector - selection component containing state
    • restoreSelection

      public void restoreSelection(String key, JComboBox<?> selector)
      Restores the selection of a combo box from this map.
      Parameters:
      key - entry key
      selector - selection component to be updated with state