Class DialogSettings

  • All Implemented Interfaces:
    IDialogSettings

    public class DialogSettings
    extends java.lang.Object
    implements IDialogSettings
    Concrete implementation of a dialog settings (IDialogSettings) using a hash table and XML. The dialog store can be read from and saved to a stream. All keys and values must be strings or array of strings. Primitive types are converted to strings.

    This class was not designed to be subclassed. Here is an example of using a DialogSettings:

     
     DialogSettings settings = new DialogSettings("root");
     settings.put("Boolean1",true);
     settings.put("Long1",100);
     settings.put("Array1",new String[]{"aaaa1","bbbb1","cccc1"});
     DialogSettings section = new DialogSettings("sectionName");
     settings.addSection(section);
     section.put("Int2",200);
     section.put("Float2",1.1);
     section.put("Array2",new String[]{"aaaa2","bbbb2","cccc2"});
     settings.save("c:\\temp\\test\\dialog.xml");
     
     
    Restriction:
    This class is not intended to be subclassed by clients.
    • Constructor Summary

      Constructors 
      Constructor Description
      DialogSettings​(java.lang.String sectionName)
      Create an empty dialog settings which loads and saves its content to a file.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      IDialogSettings addNewSection​(java.lang.String sectionName)
      Create a new section in the receiver and return it.
      void addSection​(IDialogSettings section)
      Add a section in the receiver.
      java.lang.String get​(java.lang.String key)
      Returns the value of the given key in this dialog settings.
      java.lang.String[] getArray​(java.lang.String key)
      Returns the value, an array of strings, of the given key in this dialog settings.
      boolean getBoolean​(java.lang.String key)
      Convenience API.
      double getDouble​(java.lang.String key)
      Convenience API.
      float getFloat​(java.lang.String key)
      Convenience API.
      int getInt​(java.lang.String key)
      Convenience API.
      long getLong​(java.lang.String key)
      Convenience API.
      java.lang.String getName()
      Returns the IDialogSettings name.
      static IDialogSettings getOrCreateSection​(IDialogSettings settings, java.lang.String sectionName)
      Returns a section with the given name in the given dialog settings.
      IDialogSettings getSection​(java.lang.String sectionName)
      Returns the section with the given name in this dialog settings.
      IDialogSettings[] getSections()
      Returns all the sections in this dialog settings.
      void load​(java.io.Reader r)
      Load a dialog settings from a stream and fill the receiver with its content.
      void load​(java.lang.String fileName)
      Load a dialog settings from a file and fill the receiver with its content.
      void put​(java.lang.String key, boolean value)
      Convenience API.
      void put​(java.lang.String key, double value)
      Convenience API.
      void put​(java.lang.String key, float value)
      Convenience API.
      void put​(java.lang.String key, int value)
      Convenience API.
      void put​(java.lang.String key, long value)
      Convenience API.
      void put​(java.lang.String key, java.lang.String value)
      Adds the pair key/value to this dialog settings.
      void put​(java.lang.String key, java.lang.String[] value)
      Adds the pair key/value to this dialog settings.
      IDialogSettings removeSection​(java.lang.String sectionName)
      Remove a section by name in the receiver.
      void removeSection​(IDialogSettings section)
      Remove a section in the receiver.
      void save​(java.io.Writer writer)
      Save a dialog settings to a stream
      void save​(java.lang.String fileName)
      Save a dialog settings to a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DialogSettings

        public DialogSettings​(java.lang.String sectionName)
        Create an empty dialog settings which loads and saves its content to a file. Use the methods load(String) and store(String) to load and store this dialog settings.
        Parameters:
        sectionName - the name of the section in the settings.
    • Method Detail

      • removeSection

        public void removeSection​(IDialogSettings section)
        Remove a section in the receiver. If the given section does not exist, nothing is done.
        Parameters:
        section - the section to be removed. Must not be null.
        Since:
        3.9
      • removeSection

        public IDialogSettings removeSection​(java.lang.String sectionName)
        Remove a section by name in the receiver. If the given section does not exist, nothing is done.
        Parameters:
        sectionName - the name of the section to be removed. Must not be null.
        Returns:
        The dialog section removed, or null if it wasn't there.
        Since:
        3.9
      • get

        public java.lang.String get​(java.lang.String key)
        Description copied from interface: IDialogSettings
        Returns the value of the given key in this dialog settings.
        Specified by:
        get in interface IDialogSettings
        Parameters:
        key - the key
        Returns:
        the value, or null if none
      • getArray

        public java.lang.String[] getArray​(java.lang.String key)
        Description copied from interface: IDialogSettings
        Returns the value, an array of strings, of the given key in this dialog settings.
        Specified by:
        getArray in interface IDialogSettings
        Parameters:
        key - the key
        Returns:
        the array of string, or null if none
      • getBoolean

        public boolean getBoolean​(java.lang.String key)
        Description copied from interface: IDialogSettings
        Convenience API. Convert the value of the given key in this dialog settings to a boolean and return it.
        Specified by:
        getBoolean in interface IDialogSettings
        Parameters:
        key - the key
        Returns:
        the boolean value, or false if none
      • getDouble

        public double getDouble​(java.lang.String key)
                         throws java.lang.NumberFormatException
        Description copied from interface: IDialogSettings
        Convenience API. Convert the value of the given key in this dialog settings to a double and return it.
        Specified by:
        getDouble in interface IDialogSettings
        Parameters:
        key - the key
        Returns:
        the value coverted to double, or throws NumberFormatException if none
        Throws:
        java.lang.NumberFormatException - if the string value does not contain a parsable number.
        See Also:
        Double.valueOf(java.lang.String)
      • getFloat

        public float getFloat​(java.lang.String key)
                       throws java.lang.NumberFormatException
        Description copied from interface: IDialogSettings
        Convenience API. Convert the value of the given key in this dialog settings to a float and return it.
        Specified by:
        getFloat in interface IDialogSettings
        Parameters:
        key - the key
        Returns:
        the value coverted to float, or throws NumberFormatException if none
        Throws:
        java.lang.NumberFormatException - if the string value does not contain a parsable number.
        See Also:
        Float.valueOf(java.lang.String)
      • getInt

        public int getInt​(java.lang.String key)
                   throws java.lang.NumberFormatException
        Description copied from interface: IDialogSettings
        Convenience API. Convert the value of the given key in this dialog settings to a int and return it.
        Specified by:
        getInt in interface IDialogSettings
        Parameters:
        key - the key
        Returns:
        the value coverted to int, or throws NumberFormatException if none
        Throws:
        java.lang.NumberFormatException - if the string value does not contain a parsable number.
        See Also:
        Integer.valueOf(java.lang.String)
      • getLong

        public long getLong​(java.lang.String key)
                     throws java.lang.NumberFormatException
        Description copied from interface: IDialogSettings
        Convenience API. Convert the value of the given key in this dialog settings to a long and return it.
        Specified by:
        getLong in interface IDialogSettings
        Parameters:
        key - the key
        Returns:
        the value coverted to long, or throws NumberFormatException if none
        Throws:
        java.lang.NumberFormatException - if the string value does not contain a parsable number.
        See Also:
        Long.valueOf(java.lang.String)
      • getName

        public java.lang.String getName()
        Description copied from interface: IDialogSettings
        Returns the IDialogSettings name.
        Specified by:
        getName in interface IDialogSettings
        Returns:
        the name
      • getOrCreateSection

        public static IDialogSettings getOrCreateSection​(IDialogSettings settings,
                                                         java.lang.String sectionName)
        Returns a section with the given name in the given dialog settings. If the section doesn't exist yet, then it is first created.
        Parameters:
        settings - the parent settings
        sectionName - the name of the section
        Returns:
        the section
        Since:
        3.7
      • load

        public void load​(java.io.Reader r)
        Description copied from interface: IDialogSettings
        Load a dialog settings from a stream and fill the receiver with its content.
        Specified by:
        load in interface IDialogSettings
        Parameters:
        r - a Reader specifying the stream where the settings are read from.
      • load

        public void load​(java.lang.String fileName)
                  throws java.io.IOException
        Description copied from interface: IDialogSettings
        Load a dialog settings from a file and fill the receiver with its content.
        Specified by:
        load in interface IDialogSettings
        Parameters:
        fileName - the name of the file the settings are read from.
        Throws:
        java.io.IOException - on IO problem while loading
      • put

        public void put​(java.lang.String key,
                        java.lang.String[] value)
        Description copied from interface: IDialogSettings
        Adds the pair key/value to this dialog settings.
        Specified by:
        put in interface IDialogSettings
        Parameters:
        key - the key.
        value - the value to be associated with the key
      • put

        public void put​(java.lang.String key,
                        double value)
        Description copied from interface: IDialogSettings
        Convenience API. Converts the double value to a string and adds the pair key/value to this dialog settings.
        Specified by:
        put in interface IDialogSettings
        Parameters:
        key - the key.
        value - the value to be associated with the key
      • put

        public void put​(java.lang.String key,
                        float value)
        Description copied from interface: IDialogSettings
        Convenience API. Converts the float value to a string and adds the pair key/value to this dialog settings.
        Specified by:
        put in interface IDialogSettings
        Parameters:
        key - the key.
        value - the value to be associated with the key
      • put

        public void put​(java.lang.String key,
                        int value)
        Description copied from interface: IDialogSettings
        Convenience API. Converts the int value to a string and adds the pair key/value to this dialog settings.
        Specified by:
        put in interface IDialogSettings
        Parameters:
        key - the key.
        value - the value to be associated with the key
      • put

        public void put​(java.lang.String key,
                        long value)
        Description copied from interface: IDialogSettings
        Convenience API. Converts the long value to a string and adds the pair key/value to this dialog settings.
        Specified by:
        put in interface IDialogSettings
        Parameters:
        key - the key.
        value - the value to be associated with the key
      • put

        public void put​(java.lang.String key,
                        java.lang.String value)
        Description copied from interface: IDialogSettings
        Adds the pair key/value to this dialog settings.
        Specified by:
        put in interface IDialogSettings
        Parameters:
        key - the key.
        value - the value to be associated with the key
      • put

        public void put​(java.lang.String key,
                        boolean value)
        Description copied from interface: IDialogSettings
        Convenience API. Converts the boolean value to a string and adds the pair key/value to this dialog settings.
        Specified by:
        put in interface IDialogSettings
        Parameters:
        key - the key.
        value - the value to be associated with the key
      • save

        public void save​(java.io.Writer writer)
                  throws java.io.IOException
        Description copied from interface: IDialogSettings
        Save a dialog settings to a stream
        Specified by:
        save in interface IDialogSettings
        Parameters:
        writer - a Writer specifying the stream the settings are written in.
        Throws:
        java.io.IOException - on IO problem while saving
      • save

        public void save​(java.lang.String fileName)
                  throws java.io.IOException
        Description copied from interface: IDialogSettings
        Save a dialog settings to a file.
        Specified by:
        save in interface IDialogSettings
        Parameters:
        fileName - the name of the file the settings are written in.
        Throws:
        java.io.IOException - on IO problem while saving