Package uk.ac.starlink.topcat.activate

## Class ConfigState

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

-     public class ConfigState
      extends java.lang.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 Summary

    Constructors
    Constructor | Description
    --- | ---
    `ConfigState()` | Constructs an empty state object.
    `ConfigState​(java.util.Map<java.lang.String,​java.lang.String> map)` | Constructs an object populated by a given map.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `getInt​(java.lang.String key)` | Retrieves an entry of this map as an integer.
    `java.util.Map<java.lang.String,​java.lang.String>` | `getMap()` | Returns the map on which this object is based.
    `void` | `restoreFlag​(java.lang.String key, javax.swing.ButtonModel model)` | Restores the selection state of a toggle button model from this map.
    `void` | `restoreSelection​(java.lang.String key, javax.swing.JComboBox selector)` | Restores the selection of a combo box from this map.
    `void` | `restoreText​(java.lang.String key, javax.swing.text.JTextComponent textComp)` | Restores the text content of a text component from this map.
    `void` | `saveFlag​(java.lang.String key, javax.swing.ButtonModel model)` | Stores the selection state of a button model in this map.
    `void` | `saveSelection​(java.lang.String key, javax.swing.JComboBox selector)` | Stores the selection of a combo box in this map.
    `void` | `saveText​(java.lang.String key, javax.swing.text.JTextComponent textComp)` | Stores the text content of a text component in this map.
    `void` | `setInt​(java.lang.String key, int value)` | Sets an entry of this map as an integer.

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

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

- - ### Constructor Detail

    - #### ConfigState

          public ConfigState()

      Constructs an empty state object.

    - #### ConfigState

          public ConfigState​(java.util.Map<java.lang.String,​java.lang.String> map)

      Constructs an object populated by a given map.
      Parameters:
        `map` - map constituting this object's content

  - ### Method Detail

    - #### getMap

          public java.util.Map<java.lang.String,​java.lang.String> getMap()

      Returns the map on which this object is based. It may, in general, be modified.
      Returns:
        map

    - #### setInt

          public void setInt​(java.lang.String key,
                             int value)

      Sets an entry of this map as an integer.
      Parameters:
        `key` - entry key
        `value` - integer value

    - #### getInt

          public int getInt​(java.lang.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​(java.lang.String key,
                               javax.swing.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​(java.lang.String key,
                                  javax.swing.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​(java.lang.String key,
                               javax.swing.text.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​(java.lang.String key,
                                  javax.swing.text.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​(java.lang.String key,
                                    javax.swing.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​(java.lang.String key,
                                       javax.swing.JComboBox selector)

      Restores the selection of a combo box from this map.
      Parameters:
        `key` - entry key
        `selector` - selection component to be updated with state