Package PamController

Class PamSettingManager

java.lang.Object
PamController.PamSettingManager

public class PamSettingManager extends Object
Author:
Doug Gillespie Singleton class for managing Pam settings - where and how they are stored in a persistent way between runs. Any class that wants is settings saved should register with the PamSettingsManager.

When the GUI closes, SaveSettings is called, SaveSettings goes through the list of registered objects and asks each one to give it a reference to an Object containing the settings (this MUST implement serialisable). This can be the object itself, but will more likely be a reference to another object just containing settings parameters. The class implementing PamSettings must also provide functions getUnitType, getUnitName and getSettingsVersion. These four pieces of information are then bundled into a PamControlledUnitSettings which is added to an array list which is then stored in a serialised file.

When PAMGUARD starts, after all detectors have been created, the serialised file is reopened. Each PamControlledUnitSettings is taken in turn and compared with the list of registered objects to find one with the same name, type and settings version. Once one is found, it is given the reference to the settings data which t is responsible for casting into whatever class it requires.

  • Field Details

    • LOAD_SETTINGS_OK

      public static final int LOAD_SETTINGS_OK
      See Also:
    • LOAD_SETTINGS_CANCEL

      public static final int LOAD_SETTINGS_CANCEL
      See Also:
    • LOAD_SETTINGS_NEW

      public static final int LOAD_SETTINGS_NEW
      See Also:
    • fileEnd

      public static final String fileEnd
      See Also:
    • fileEndx

      public static final String fileEndx
      See Also:
    • fileEndXML

      public static final String fileEndXML
      See Also:
    • LIST_UNITS

      public static final int LIST_UNITS
      Identifier for modules that go in the 'normal' list (everything apart from database modules)
      See Also:
    • LIST_DATABASESTUFF

      public static final int LIST_DATABASESTUFF
      Identifier for modules which are part of the database system.
      See Also:
    • LIST_SYSTEMGLOBAL

      public static final int LIST_SYSTEMGLOBAL
      Stuff which is global to the computer system (at the user level). Invented for colour settings, might extend to other things too.
      See Also:
    • SAVE_PSF

      public static final int SAVE_PSF
      Save settings to a psf file
      See Also:
    • SAVE_DATABASE

      public static final int SAVE_DATABASE
      Save settings to database tables (if available).
      See Also:
    • RUN_REMOTE

      public static boolean RUN_REMOTE
      running in remote mode, default normal
    • remote_psf

      public static String remote_psf
    • external_wav

      public static String external_wav
  • Method Details

    • getCurrentSettingsFileEnd

      public static String getCurrentSettingsFileEnd()
    • getInstance

      public static PamSettingManager getInstance()
    • reset

      public void reset()
      Clear all settings from the manager
    • notifyModelChanged

      public void notifyModelChanged(int changeType)
      Called everytime anything in the model changes.
      Parameters:
      changeType - type of change
    • registerSettings

      public boolean registerSettings(PamSettings pamUnit)
      Register a PAMGAURD module that wants to store settings in a serialised file (.psf file) and / or have those settings stored in the database settings table.

      Normally, all modules will call this for at least one set of settings. Often the PamSettings is implemented by the class that extends PamControlledunit, but it's also possible to have multiple sub modules, processes or displays implement PamSettings so that different settings for different bits of a PamControlledUnit are stored separately.

      Parameters:
      pamUnit - Reference to a PamSettings module
      Returns:
      True if settings correctly restored. This is either the return of the restoreSettings() function in the calling pamUnit, or will be false if there was a ClassCastException in the call to restoreSettings()
      See Also:
    • registerSettings

      public boolean registerSettings(PamSettings pamUnit, int whichLists)
      Register modules that have settings information that should be stored in serialised form in psf files and database Pamguard_Settings tables.
      Parameters:
      pamUnit - Unit containing the settings
      whichLists - which lists to store the settings in.

      N.B. These are internal lists and not the external storage. Basically any database modules connected with settings should to in LIST_DATABASESTUFF everything else (including the normal database) should go to LISTS_UNITS

      Returns:
      true if settings registered sucessfully.
    • findGeneralSettings

      public PamControlledUnitSettings findGeneralSettings(String unitType)
      Searches a list of settings for settings with a specific type.
      Parameters:
      unitType -
      Returns:
      PamControlledUnitSettings or null if none found
      See Also:
    • findSettings

      public PamControlledUnitSettings findSettings(ArrayList<PamControlledUnitSettings> settingsList, String unitType, String unitName)
      Find settings in a list of settings by name and by type.
      Parameters:
      settingsList - settings list to search
      unitType - unit name
      unitName - unit type
      Returns:
      settings object
    • findSettingsOwner

      public PamSettings findSettingsOwner(String unitType, String unitName, String unitClassName)
      Find a settings owner for a type, name and class.
      Parameters:
      unitType - unit Type
      unitName - unit Name
      unitClass - unit Class
      Returns:
      Settings owner or null.
    • saveFinalSettings

      public boolean saveFinalSettings()
      Call just before PAMGUARD exits to save the settings either to psf and / or database tables.
      Returns:
      true if settings saved successfully.
    • saveSettings

      public boolean saveSettings(int saveWhere)
      Save settings to a psf file and / or the database tables.
      Parameters:
      saveWhere -
      Returns:
      true if sucessful
    • saveSettingsToFile

      public boolean saveSettingsToFile()
    • saveSettingsToFile

      public boolean saveSettingsToFile(String fileName)
      Save configuration settings to the default (most recently used) psf file.
      Returns:
      true if successful.
    • saveSettingsToPSFFile

      public boolean saveSettingsToPSFFile(String fileName)
      Save configuration settings to the default (most recently used) psf file.
      Returns:
      true if successful.
    • thisIsADuplicate

      public boolean thisIsADuplicate(ArrayList<PamControlledUnitSettings> pamSettingsList, PamControlledUnitSettings settingToCheck)
      Checks if the PamControlledSettings object is already in the settings ArrayList. Comparison is done by checking the unit type and unit name.
      Parameters:
      pamSettingsList - the ArrayList containing the PamControlledUnitSettings
      settingToCheck - the PamControlledUnitSettings to check
      Returns:
      true if it is in the list, false if not
    • saveSettingsToXMLFile

      public boolean saveSettingsToXMLFile(File file)
      Save configuration settings to a PSFX file (XML).
      Returns:
      true if successful.
    • objectToXMLFile

      public void objectToXMLFile(Object serialisableObject, File file)
      An object is serializable iff .... TBC
    • loadPAMSettings

      public int loadPAMSettings(int runMode)
      Load the PAMGAURD settings either from psf file or from a database, depending on the run mode and type of settings required.
      Parameters:
      runMode -
      Returns:
      OK if load was successful.
    • loadLocalSettings

      public boolean loadLocalSettings()
      Load data from settings files.

      This is just the general data - the list of recently used psf files and recent database files.

    • loadDBSettings

      public int loadDBSettings()
      Try to get settings information from a valid database. If none are loaded, then return null and Pamguard will try to get them from a psf file.
    • loadDBSettings

      public int loadDBSettings(int showDatabaseDialog)
      Try to get settings information from a valid database. If none are loaded, then return null and Pamguard will try to get them from a psf file.
      Parameters:
      showDatabaseDialog - Show a dialog to ask for a database. 0 = never, 1 = if no database open 2 = always.
    • isSettingsUnit

      public boolean isSettingsUnit(PamSettings settingsUser, PamControlledUnitSettings settings)
      See if a particular PamControlledUnitSettings object is the right one for a particular module that wants some settings.
      Parameters:
      settingsUser - User of settings
      settings - Settings object.
      Returns:
      true if matched.
    • openOutputFile

      public ObjectOutputStream openOutputFile(String outputFile)
      Open psf file for settings serialised output.
      Returns:
      stream handle.
    • loadSettingsFileData

      public boolean loadSettingsFileData()
      Now that the database is becoming much more fundamental to settings storage and retrieval, the latest database settings should go into the main settings file. This contains a list of recent databases. The trouble is, the settings are spread amongst several different settings object (e.g. one that tells us what type of database, another that tells us a list of recent databases for a specific database type, etc.

      We therefore need some modules (i.e. database ones) to also store their settings in a general settings list so that they can be read in before any other settings are read in. So each unit when it registers, says whether it should be included in the general list as well as the specific data file.

    • getSettingsFileName

      public String getSettingsFileName()
      Get the most recently used settings file name. We have added a switch in here to allow for the direct setting of the psf used from the command line. This can be used in remote on non remote deployments.
      Returns:
      File name string.
    • getDefaultFile

      public String getDefaultFile()
    • saveSettings

      public void saveSettings(JFrame frame)
      saves settings in the current file
      Parameters:
      frame - GUI frame (needed for dialog, can be null)
    • saveSettingsAs

      public void saveSettingsAs(JFrame frame)
      Save settings to a new psf file.
      Parameters:
      frame - parent frame for dialog.
    • setDefaultFile

      public void setDefaultFile(String defaultFile)
      Set the default (first) file in the settings file data.
      Parameters:
      defaultFile - File name string.
    • loadSettingsFrom

      public void loadSettingsFrom(JFrame frame)
      Pop up the dialog that's shown at start up to show a list of recent settings file and give the opportunity for browsing for more. IF the new settings file is different from the current one, then send a command off to the Controller to re-do the entire Pamguard system model
      Parameters:
      frame - parent frame for dialog (can be null)
    • importSettings

      public void importSettings(JFrame frame)
      Import a configuration during viewer mode operation.
      Parameters:
      frame -
    • loadSettings

      public PamSettingsGroup loadSettings(File psfFile)
      Load a settings file and return the contents in a settings group object. Give the time of the settings group as the time the file was modified. the settings load code is a bit of a mess - this function has been written mainly so that it can be called from Matlab and r so that those languages can load PAMGuard settings.
      Parameters:
      psfFile - psf file object.
      Returns:
      loaded settings from the file.
    • exportSettings

      public void exportSettings(JFrame frame)
    • getOwners

      public ArrayList<PamSettings> getOwners()
    • getCurrentSettingsGroup

      public PamSettingsGroup getCurrentSettingsGroup()
      Returns:
      everything about every set of settings currently loaded.
    • loadSettingsGroup

      public void loadSettingsGroup(PamSettingsGroup settingsGroup, boolean notifyExisting)
      Load some old settings into all modules.

      Currently used in viewer mode to load reloaded settings from binary files and the database.

      Parameters:
      settingsGroup - settings group to load.
      send - these new settings round to all existing modules.
    • findSettingsForType

      public PamControlledUnitSettings findSettingsForType(String unitType)
      Find the settings for a given unit type and any name
      Returns:
      the initialSettingsList
    • findPamSettings

      public ArrayList<PamSettings> findPamSettings(String unitType, String unitName)
      Find a list of unit settings by type and name. If both are specified, then it's going to (hopefully only return one setting. Otherwise, with null or wildcard names we may get many.
      Parameters:
      unitType - unit type, can be wildcard * or null
      unitName - unit name, can be wildcard * or null
      Returns:
      Array list of settings.
    • getInitialSettingsList

      public ArrayList<PamControlledUnitSettings> getInitialSettingsList()
      Returns:
      the initialSettingsList
    • getCurrentDisplayScaling

      public double getCurrentDisplayScaling()
      Get the current scaling factor
      Returns:
    • scalingFactorDialog

      public void scalingFactorDialog(JFrame frame)
      Parameters:
      frame -