Class ModeSettings<A,B>

java.lang.Object
bibliothek.gui.dock.support.mode.ModeSettings<A,B>
Type Parameters:
A - the objects used by ModeManager to store information
B - the independent objects used by this ModeSettings to store information
Direct Known Subclasses:
CLocationModeSettings

public class ModeSettings<A,B> extends Object
A set of properties extracted from a ModeManager and its Modes. The properties can be stored persistently and do not depend on any existing object (like for example the Modes).
Author:
Benjamin Sigg
  • Constructor Details

    • ModeSettings

      public ModeSettings(ModeSettingsConverter<A,B> converter)
      Creates a new setting
      Parameters:
      converter - the converter to read and write properties
  • Method Details

    • getConverter

      public ModeSettingsConverter<A,B> getConverter()
      Gets the converter that is used to transform internal and external properties.
      Returns:
      the converter, never null
    • addFactory

      public void addFactory(ModeSettingFactory<A> factory)
      Adds a factory to this setting. The factory will be used to create new ModeSettings.
      Parameters:
      factory - the new factory, not null
    • add

      public void add(String id, Path current, Map<Path,A> properties, Collection<Path> history)
      Adds a new set of properties to this setting.
      Parameters:
      id - the unique identifier of this set of properties
      current - the current mode of the set, can be null
      properties - the properties, will be copied by this method
      history - older modes of the setting, will be copied by this method
    • add

      public void add(Mode<A> mode)
      Adds the settings of mode to this.
      Parameters:
      mode - the mode whose settings are to be stored
    • add

      public void add(ModeSetting<A> mode)
      Adds the settings mode to this.
      Parameters:
      mode - the properties to store
    • size

      public int size()
      Gets the number of sets this setting stores.
      Returns:
      the number of sets
    • indexOf

      public int indexOf(String id)
      Gets the index of the entry with identifier id.
      Parameters:
      id - the identifier of a dockable
      Returns:
      the entry that represents that dockable, can be -1
    • getId

      public String getId(int index)
      Gets the unique id of the index'th set.
      Parameters:
      index - the index of the set
      Returns:
      the unique id
    • getCurrent

      public Path getCurrent(int index)
      Gets the current mode of the index'th set.
      Parameters:
      index - the index of the set
      Returns:
      the current mode
    • getHistory

      public Path[] getHistory(int index)
      Gets the history of the index'th set.
      Parameters:
      index - the index of the set
      Returns:
      the history
    • getProperties

      public Map<Path,A> getProperties(int index)
      Gets the converted properties of the index'th set.
      Parameters:
      index - the index of the set
      Returns:
      a new map of freshly converted properties
    • getSettings

      public ModeSetting<A> getSettings(Path modeId)
      Gets the settings which belong to a Mode with unique identifier modeId.
      Parameters:
      modeId - the unique identifier of some mode
      Returns:
      the settings or null if not found
    • write

      public void write(DataOutputStream out) throws IOException
      Writes all properties of this setting into out.
      Parameters:
      out - the stream to write into
      Throws:
      IOException - if an I/O-error occurs
    • rescueSettings

      protected void rescueSettings(DataInputStream in, Version version) throws IOException
      Called if some setting with version < 1.0.8 is found. Subclasses may override this method to read and interpret the old settings. The default implementation does nothing.
      Parameters:
      in - the stream to read from
      version - the version that was found
      Throws:
      IOException - in case of an error
    • rescueSettings

      protected void rescueSettings(XElement element)
      Called if some setting does not have the "modes" entry, the assumption is that only old settings are missing this entry.
      Parameters:
      element - the entry that has to be rescued
      Throws:
      XException - in case of an error related to a wrongly read attribute
    • resuceMode

      protected Path resuceMode(String identifier)
      Called if a single identifier of a mode is found as was used in version 1.0.7 and below.
      Parameters:
      identifier - the single identifier
      Returns:
      the identifier of the matching mode, can be null
    • read

      public void read(DataInputStream in) throws IOException
      Clears all properties of this setting and then reads new properties from in.
      Parameters:
      in - the stream to read from
      Throws:
      IOException - if an I/O-error occurs
    • writeXML

      public void writeXML(XElement element)
      Writes the contents of this setting in xml format.
      Parameters:
      element - the element to write into, the attributes of element will not be changed.
      See Also:
    • readXML

      public void readXML(XElement element)
      Clears all properties of this setting and then reads new properties from element.
      Parameters:
      element - the element from which the properties should be read
      See Also: