Class ProfileManager


  • public class ProfileManager
    extends java.lang.Object
    Handles multiple profiles for settings.
    Author:
    stm
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ProfileManager.ProfileException
      Informs about problems during profile handling.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String ASK_ALWAYS  
      protected static java.lang.String CURRENT_PROFILE  
      protected static java.lang.String DIRECTORY  
      static java.lang.String INIFILE
      The name of the profile configuration file.
      protected static java.lang.String NAME  
      protected static java.lang.String PROFILE_PREFIX  
      protected static java.lang.String XCMD_FILENAME  
    • Constructor Summary

      Constructors 
      Constructor Description
      ProfileManager()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void add​(java.lang.String name, java.lang.String copyFrom)
      Adds a new profile and creates its directory.
      static java.lang.String getCurrentProfile()
      Returns the currently active profile.
      static java.io.File getProfileDirectory()
      Returns the directory of the current profile.
      static java.io.File getProfileDirectory​(java.lang.String name)
      Returns the directory of the specified profile.
      static java.util.Collection<java.lang.String> getProfiles()
      Returns a list of known profiles.
      static java.io.File getSettingsDirectory()
      Returns the settings directory where INIFILE is stored.
      static java.lang.String init​(Client.Parameters parameters)
      Reads the profile information from the INIFILE.
      static boolean isAlwaysAsk()
      Returns true if the "always ask at startup" property is set.
      static boolean remove​(java.lang.String name, boolean removeFiles)
      Removes a profile.
      static void saveSettings()
      Writes the settings to the INIFILE in the settings directory.
      static void setAlwaysAsk​(boolean newValue)
      Sets the "always ask at startup" property.
      static boolean setProfile​(java.lang.String name)
      Changes the active profile.
      static boolean showProfileChooser​(java.awt.Frame parent)
      Shows a dialog to manage profiles.
      • Methods inherited from class java.lang.Object

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

      • ProfileManager

        public ProfileManager()
    • Method Detail

      • init

        public static java.lang.String init​(Client.Parameters parameters)
        Reads the profile information from the INIFILE. If there is no inifile in parameters.settingsDir, new settings are created with a default profile.
        Parameters:
        parameters -
        Returns:
        The name of the current profile. null if there was an I/O error while reading the inifile
      • getProfileDirectory

        public static java.io.File getProfileDirectory()
        Returns the directory of the current profile.
        Returns:
        The directory of the current profile.
      • getProfileDirectory

        public static java.io.File getProfileDirectory​(java.lang.String name)
        Returns the directory of the specified profile.
        Parameters:
        name - A profile name
        Returns:
        The directory of the specified profile.
      • getCurrentProfile

        public static java.lang.String getCurrentProfile()
        Returns the currently active profile.
        Returns:
        The currently active profile.
      • isAlwaysAsk

        public static boolean isAlwaysAsk()
        Returns true if the "always ask at startup" property is set.
        Returns:
        true if the "always ask at startup" property is set.
      • setAlwaysAsk

        public static void setAlwaysAsk​(boolean newValue)
        Sets the "always ask at startup" property.
        Parameters:
        newValue -
      • showProfileChooser

        public static boolean showProfileChooser​(java.awt.Frame parent)
        Shows a dialog to manage profiles.
        Parameters:
        parent - The parent frame for the JDialog.
        Returns:
        true if the dialog was confirmed
      • getProfiles

        public static java.util.Collection<java.lang.String> getProfiles()
        Returns a list of known profiles.
        Returns:
        a list of known profiles.
      • remove

        public static boolean remove​(java.lang.String name,
                                     boolean removeFiles)
        Removes a profile. Tries to delete the profile directory if removFiles is true.
        Parameters:
        name -
        removeFiles -
        Returns:
        true if there was such a profile and it has been removed.
      • add

        public static void add​(java.lang.String name,
                               java.lang.String copyFrom)
                        throws ProfileManager.ProfileException
        Adds a new profile and creates its directory. If copyFrom is not null , all files from the corresponding directory are copied to the new profile directory.
        Parameters:
        name -
        copyFrom -
        Throws:
        ProfileManager.ProfileException - if the profile directory could not be created, or the files could not be copied
      • setProfile

        public static boolean setProfile​(java.lang.String name)
        Changes the active profile.
        Parameters:
        name -
        Returns:
        true if the specified profile exists.
      • getSettingsDirectory

        public static java.io.File getSettingsDirectory()
        Returns the settings directory where INIFILE is stored.
        Returns:
        the settings directory
      • saveSettings

        public static void saveSettings()
                                 throws java.io.IOException
        Writes the settings to the INIFILE in the settings directory.
        Throws:
        java.io.IOException - if an I/O error occurs