Class PamSettingManager
- 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 Summary
Modifier and TypeFieldDescriptionstatic String
static final String
static final String
static final String
static final int
Identifier for modules which are part of the database system.static final int
Stuff which is global to the computer system (at the user level).static final int
Identifier for modules that go in the 'normal' list (everything apart from database modules)static final int
static final int
static final int
static String
static boolean
running in remote mode, default normalstatic final int
Save settings to database tables (if available).static final int
Save settings to a psf file -
Method Summary
Modifier and TypeMethodDescriptionvoid
exportSettings
(JFrame frame) findGeneralSettings
(String unitType) Searches a list of settings for settings with a specific type.findPamSettings
(String unitType, String unitName) Find a list of unit settings by type and name.findSettings
(ArrayList<PamControlledUnitSettings> settingsList, String unitType, String unitName) Find settings in a list of settings by name and by type.findSettingsForType
(String unitType) Find the settings for a given unit type and any namefindSettingsOwner
(String unitType, String unitName, String unitClassName) Find a settings owner for a type, name and class.double
Get the current scaling factorstatic String
static PamSettingManager
Get the most recently used settings file name.void
importSettings
(JFrame frame) Import a configuration during viewer mode operation.boolean
isSettingsUnit
(PamSettings settingsUser, PamControlledUnitSettings settings) See if a particular PamControlledUnitSettings object is the right one for a particular module that wants some settings.int
Try to get settings information from a valid database.int
loadDBSettings
(int showDatabaseDialog) Try to get settings information from a valid database.boolean
Load data from settings files.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.loadSettings
(File psfFile) Load a settings file and return the contents in a settings group object.boolean
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.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.void
loadSettingsGroup
(PamSettingsGroup settingsGroup, boolean notifyExisting) Load some old settings into all modules.void
notifyModelChanged
(int changeType) Called everytime anything in the model changes.void
objectToXMLFile
(Object serialisableObject, File file) An object is serializable iff ....openOutputFile
(String outputFile) Open psf file for settings serialised output.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.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.void
reset()
Clear all settings from the managerboolean
Call just before PAMGUARD exits to save the settings either to psf and / or database tables.boolean
saveSettings
(int saveWhere) Save settings to a psf file and / or the database tables.void
saveSettings
(JFrame frame) saves settings in the current filevoid
saveSettingsAs
(JFrame frame) Save settings to a new psf file.boolean
boolean
saveSettingsToFile
(String fileName) Save configuration settings to the default (most recently used) psf file.boolean
saveSettingsToPSFFile
(String fileName) Save configuration settings to the default (most recently used) psf file.boolean
saveSettingsToXMLFile
(File file) Save configuration settings to a PSFX file (XML).void
scalingFactorDialog
(JFrame frame) void
setDefaultFile
(String defaultFile) Set the default (first) file in the settings file data.boolean
thisIsADuplicate
(ArrayList<PamControlledUnitSettings> pamSettingsList, PamControlledUnitSettings settingToCheck) Checks if the PamControlledSettings object is already in the settings ArrayList.
-
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
- See Also:
-
fileEndx
- See Also:
-
fileEndXML
- See Also:
-
LIST_UNITS
public static final int LIST_UNITSIdentifier for modules that go in the 'normal' list (everything apart from database modules)- See Also:
-
LIST_DATABASESTUFF
public static final int LIST_DATABASESTUFFIdentifier for modules which are part of the database system.- See Also:
-
LIST_SYSTEMGLOBAL
public static final int LIST_SYSTEMGLOBALStuff 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_PSFSave settings to a psf file- See Also:
-
SAVE_DATABASE
public static final int SAVE_DATABASESave settings to database tables (if available).- See Also:
-
RUN_REMOTE
public static boolean RUN_REMOTErunning in remote mode, default normal -
remote_psf
-
external_wav
-
-
Method Details
-
getCurrentSettingsFileEnd
-
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
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
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 settingswhichLists
- 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
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 searchunitType
- unit nameunitName
- unit type- Returns:
- settings object
-
findSettingsOwner
Find a settings owner for a type, name and class.- Parameters:
unitType
- unit TypeunitName
- unit NameunitClass
- 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
Save configuration settings to the default (most recently used) psf file.- Returns:
- true if successful.
-
saveSettingsToPSFFile
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 PamControlledUnitSettingssettingToCheck
- the PamControlledUnitSettings to check- Returns:
- true if it is in the list, false if not
-
saveSettingsToXMLFile
Save configuration settings to a PSFX file (XML).- Returns:
- true if successful.
-
objectToXMLFile
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
See if a particular PamControlledUnitSettings object is the right one for a particular module that wants some settings.- Parameters:
settingsUser
- User of settingssettings
- Settings object.- Returns:
- true if matched.
-
openOutputFile
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
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
-
saveSettings
saves settings in the current file- Parameters:
frame
- GUI frame (needed for dialog, can be null)
-
saveSettingsAs
Save settings to a new psf file.- Parameters:
frame
- parent frame for dialog.
-
setDefaultFile
Set the default (first) file in the settings file data.- Parameters:
defaultFile
- File name string.
-
loadSettingsFrom
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
Import a configuration during viewer mode operation.- Parameters:
frame
-
-
loadSettings
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
-
getOwners
-
getCurrentSettingsGroup
- Returns:
- everything about every set of settings currently loaded.
-
loadSettingsGroup
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
Find the settings for a given unit type and any name- Returns:
- the initialSettingsList
-
findPamSettings
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 nullunitName
- unit name, can be wildcard * or null- Returns:
- Array list of settings.
-
getInitialSettingsList
- Returns:
- the initialSettingsList
-
getCurrentDisplayScaling
public double getCurrentDisplayScaling()Get the current scaling factor- Returns:
-
scalingFactorDialog
- Parameters:
frame
-
-