de.esprit.common.gui.util

## Class EnvStore

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.common.gui.util.EnvStore

- All Implemented Interfaces:
    Dumpable
  Direct Known Subclasses:
    ClientEnvStore

      public class EnvStore
      extends DumpableObject

  This class stores environment properties in a file. On instantiation it reads the properties from the given filename and makes them accessible through it's accessor methods. Any class which implements the `EnvStorable` interface may register for being asked for it's properties to be saved. When the save() method is called a new property map is created and passed to all registered classes to give them the opportunity to fill in the properties they want to have saved.
  Author:
    Rainer Buesch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `EnvStore(LogChannel logCh)` Creates an env-file in the current dir named as the application name of the context.
    `EnvStore(LogChannel logCh, java.io.File workingDir, java.lang.String fileName)` Creates an env-file in the given dir using the given fileName.
    `EnvStore(LogChannel logCh, java.lang.String fileName)` Creates an env-file in the current dir using the given fileName.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `containsKey(java.lang.String envKey)` Checks whether the given key exists in the environment store.
    `boolean` | `getAsBoolean(java.lang.String envKey)`
    `boolean` | `getAsBoolean(java.lang.String envKey, boolean defaultValue)`
    `java.awt.Color` | `getAsColor(java.lang.String envKey)`
    `java.awt.Dimension` | `getAsDimension(java.lang.String envKey)`
    `int` | `getAsInt(java.lang.String envKey)`
    `int` | `getAsInt(java.lang.String envKey, int defaultValue)`
    `java.awt.Point` | `getAsLocation(java.lang.String envKey)`
    `long` | `getAsLong(java.lang.String envKey)`
    `long` | `getAsLong(java.lang.String envKey, int defaultValue)`
    `java.lang.String` | `getAsString(java.lang.String envKey)`
    `java.lang.String` | `getAsString(java.lang.String envKey, java.lang.String defaultValue)`
    `void` | `initWindow(java.lang.String envKey, java.awt.Window window)` Convenience method for setting the frames size and location based on the window property found for the given key.
    `boolean` | `load()` Loads the properties form the underlying file.
    `void` | `registerForSave(EnvStorable candidate)` Registers the given class for being asked for it's properties when save() is called.
    `boolean` | `save()` Asks all registered components for their properties and saves them in the underlying file.
    `void` | `setStoreOnExit(boolean isStoreOnExit)` Sets the store-on-exit flag (true by default).
    `DumpString` | `toDumpString(DumpString s)` This method allows subclasses to add values to the existing DumpString of the superclass.
    `ToString` | `toString(ToString s)` This method allows subclasses to add values to the existing ToString of the superclass.

    - ### Methods inherited from class de.esprit.common.util.DumpableObject

      `configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toString`

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

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

- - ### Constructor Detail

    - #### EnvStore

          public EnvStore(LogChannel logCh)

      Creates an env-file in the current dir named as the application name of the context.

    - #### EnvStore

          public EnvStore(LogChannel logCh,
                  java.lang.String fileName)

      Creates an env-file in the current dir using the given fileName.

    - #### EnvStore

          public EnvStore(LogChannel logCh,
                  java.io.File workingDir,
                  java.lang.String fileName)

      Creates an env-file in the given dir using the given fileName.

  - ### Method Detail

    - #### initWindow

          public void initWindow(java.lang.String envKey,
                        java.awt.Window window)

      Convenience method for setting the frames size and location based on the window property found for the given key. If no matching property is found the frame won't be changed. The given frame is automatically registered to be saved with the next save() call.

    - #### registerForSave

          public void registerForSave(EnvStorable candidate)

      Registers the given class for being asked for it's properties when save() is called. The class must implement the `EnvStorable` interface to be able to tell it's environment properties.
      Note that if the candidate is of type EnvStoreAndSettable it is automatically initialized from the `EnvStore` (calling initFromEnvStore() delayed);

    - #### setStoreOnExit

          public void setStoreOnExit(boolean isStoreOnExit)

      Sets the store-on-exit flag (true by default). If this is set to false, nothing will happen when save() is called.

    - #### containsKey

          public final boolean containsKey(java.lang.String envKey)

      Checks whether the given key exists in the environment store.

    - #### getAsString

          public final java.lang.String getAsString(java.lang.String envKey)

      Returns:
        the value for the given key as a String - null if no value was found

    - #### getAsString

          public final java.lang.String getAsString(java.lang.String envKey,
                                     java.lang.String defaultValue)

      Returns:
        the value for the given key as a String - defaultValue if no value was found

    - #### getAsBoolean

          public boolean getAsBoolean(java.lang.String envKey)

      Returns:
        the value for the given key as a boolean - false if no value was found

    - #### getAsBoolean

          public boolean getAsBoolean(java.lang.String envKey,
                             boolean defaultValue)

      Returns:
        the value for the given key as a boolean - defaultValue if no value was found

    - #### getAsInt

          public int getAsInt(java.lang.String envKey)

      Returns:
        the value for the given key as a int - 0 if no value was found

    - #### getAsLong

          public long getAsLong(java.lang.String envKey)

      Returns:
        the value for the given key as a long - 0 if no value was found

    - #### getAsLong

          public long getAsLong(java.lang.String envKey,
                       int defaultValue)

      Returns:
        the value for the given key as a long - defaultValue if no value was found

    - #### getAsInt

          public int getAsInt(java.lang.String envKey,
                     int defaultValue)

      Returns:
        the value for the given key as an int - defaultValue if no value was found

    - #### getAsColor

          public java.awt.Color getAsColor(java.lang.String envKey)

      Returns:
        the value for the given key as a Color object - null if no value was found

    - #### getAsDimension

          public java.awt.Dimension getAsDimension(java.lang.String envKey)

      Returns:
        the value for the given key as a Dimension object - null if no value was found

    - #### getAsLocation

          public java.awt.Point getAsLocation(java.lang.String envKey)

      Returns:
        the value for the given key as a Point object - null if no value was found

    - #### load

          public boolean load()

      Loads the properties form the underlying file.

    - #### save

          public boolean save()

      Asks all registered components for their properties and saves them in the underlying file.

    - #### toString

          public ToString toString(ToString s)

      Description copied from interface: `Dumpable`
      This method allows subclasses to add values to the existing ToString of the superclass. Usually subclasses only need to override this method.
      Specified by:
        `toString` in interface `Dumpable`
      Overrides:
        `toString` in class `DumpableObject`

    - #### toDumpString

          public DumpString toDumpString(DumpString s)

      Description copied from interface: `Dumpable`
      This method allows subclasses to add values to the existing DumpString of the superclass. Usually subclasses only need to override this method.
      Specified by:
        `toDumpString` in interface `Dumpable`
      Overrides:
        `toDumpString` in class `DumpableObject`

Copyright © 2014 EsprIT-Systems. All Rights Reserved.