PamController
Class PamSettingManager

java.lang.Object
  extended by PamController.PamSettingManager

public class PamSettingManager
extends java.lang.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 Summary
 java.lang.String databaseListFile
          Name of a list of recent database informations (probably just the last one)
private  java.util.ArrayList<PamSettings> databaseOwners
          List of modules that specifically use settings from the database storage.
(package private)  java.util.ArrayList<PamControlledUnitSettings> databaseSettingsList
          List of settings used specifically by databases.
static java.lang.String external_wav
           
static java.lang.String fileEnd
           
private  boolean initializationComplete
           
(package private)  java.util.ArrayList<PamControlledUnitSettings> initialSettingsList
          List of settings used by 'normal' modules.
static int LIST_DATABASESTUFF
          Identifier for modules which are part of the database system.
static int LIST_UNITS
          Identifier for modules that go in the 'normal' list (everything apart from database modules)
private  boolean loadingLocalSettings
           
private  java.util.ArrayList<PamSettings> owners
          List of modules that have / want PAMGUARD Settings which get stored in the psf file and / or the database store.
private static PamSettingManager pamSettingManager
           
private  boolean programStart
           
private  java.util.ArrayList<java.io.File> recentFiles
           
static java.lang.String remote_psf
           
static boolean RUN_REMOTE
          running in remote mode, default normal
private static int SAVE_DATABASE
          Save settings to database tables (if available).
private static int SAVE_PSF
          Save settings to a psf file
(package private)  SettingsFileData settingsFileData
           
 java.lang.String settingsListFile
          Name of the file that contains a list of recent psf files.
private  boolean[] settingsUsed
           
private  boolean userNotifiedAbsentDefaultSettingsFile
           
private  boolean userNotifiedAbsentSettingsFile
           
 
Constructor Summary
private PamSettingManager()
           
 
Method Summary
 void exportSettings(javax.swing.JFrame frame)
           
 PamControlledUnitSettings findGeneralSettings(java.lang.String unitType)
          Searches a list of settings for settings with a specific type.
private  PamSettings findOwner(java.util.ArrayList<PamSettings> ownersList, java.lang.String unitType, java.lang.String unitName)
          Find the owner of some PAMGUARD settings.
private  PamControlledUnitSettings findSettings(java.util.ArrayList<PamControlledUnitSettings> settingsList, boolean[] usedSettings, PamSettings user)
          Find settings in a list of settings, ignoring settings which have already been used by a module.
 PamControlledUnitSettings findSettings(java.util.ArrayList<PamControlledUnitSettings> settingsList, java.lang.String unitType, java.lang.String unitName)
          Find settings in a list of settings by name and by type.
private  PamControlledUnitSettings findSettings(PamSettings user, int whichLists)
          Find settings for a particular user in one or more lists.
 PamSettingsGroup getCurrentSettingsGroup()
           
 java.lang.String getDefaultFile()
           
static PamSettingManager getInstance()
           
 java.util.ArrayList<PamSettings> getOwners()
           
 java.lang.String getSettingsFileName()
          Get the most recently used settings file name.
 void importSettings(javax.swing.JFrame frame)
           
private  void initialiseRegisteredModules()
          Some modules may have already registered before the settings were loaded, so this function is called as soon as they are loaded which sends settings to all modules in the list.
 boolean isSettingsUnit(PamSettings settingsUser, PamControlledUnitSettings settings)
          See if a particular PamControlledUnitSettings object is the right one for a particular module that wants some settings.
private  boolean loadDatabaseFileData()
          Loads the details of the last database to be opened.
 boolean loadDBSettings()
          Try to get settings information from a valid databse.
 boolean loadLocalSettings()
          Load data from settings files.
private  boolean loadMixedModeSettings()
          Load settings for mixed mode.
private  boolean loadNormalSettings()
          Load settings perfectly 'normally' from a psf file.
 boolean 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.
private  boolean loadPSFSettings()
          Open the file that contains a list of files and optionally open a dialog giving the list of recent files.
 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.
 void loadSettingsFrom(javax.swing.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.
private  java.util.ArrayList<PamControlledUnitSettings> loadSettingsFromFile()
          Load PAMGUARD settings from a psf file.
 void loadSettingsGroup(PamSettingsGroup settingsGroup, boolean notifyExisting)
          Load some old settings into all modules.
private  boolean loadViewerSettings()
          Load settings for viewer mode.
 void notifyModelChanged(int changeType)
          Called everytime anything in the model changes.
private  java.io.ObjectInputStream openInputFile()
          Open psf file for settings input.
private  java.io.ObjectInputStream openInputFileResource()
          Returns total gobbledygook - need to improve the way PAMGAURD creates new psf files.
 java.io.ObjectOutputStream openOutputFile()
          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 manager
private  boolean saveDatabaseFileData()
          Save the details of the most recently used database.
 boolean saveFinalSettings()
          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(javax.swing.JFrame frame)
          saves settings in the current file
 void saveSettingsAs(javax.swing.JFrame frame)
          Save settings to a new psf file.
private  boolean saveSettingsFileData()
          Save the list of recently used settings files.
private  boolean saveSettingsToDatabase()
          See if there is a database module in PAMGUARD and if so, save the settings in serialised from in the Pamguard_Settings and Pamguard_Settings_Last tables.
 boolean saveSettingsToFile()
          Save settings to the default (most recently used) psf file.
 void setDefaultFile(java.lang.String defaultFile)
          Set the default (first) file in the settings file data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pamSettingManager

private static PamSettingManager pamSettingManager

owners

private java.util.ArrayList<PamSettings> owners
List of modules that have / want PAMGUARD Settings which get stored in the psf file and / or the database store.


databaseOwners

private java.util.ArrayList<PamSettings> databaseOwners
List of modules that specifically use settings from the database storage.


initialSettingsList

java.util.ArrayList<PamControlledUnitSettings> initialSettingsList
List of settings used by 'normal' modules.


databaseSettingsList

java.util.ArrayList<PamControlledUnitSettings> databaseSettingsList
List of settings used specifically by databases. This list never get's stored anywhere, but is just held in memory so that the database identified at startup in viewer and mixed modes gets reloaded later on .


fileEnd

public static final java.lang.String fileEnd
See Also:
Constant Field Values

settingsListFile

public transient java.lang.String settingsListFile
Name of the file that contains a list of recent psf files.


databaseListFile

public transient java.lang.String databaseListFile
Name of a list of recent database informations (probably just the last one)


LIST_UNITS

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

See Also:
Constant Field Values

LIST_DATABASESTUFF

public static final int LIST_DATABASESTUFF
Identifier for modules which are part of the database system.

See Also:
Constant Field Values

SAVE_PSF

private static final int SAVE_PSF
Save settings to a psf file

See Also:
Constant Field Values

SAVE_DATABASE

private static final int SAVE_DATABASE
Save settings to database tables (if available).

See Also:
Constant Field Values

RUN_REMOTE

public static boolean RUN_REMOTE
running in remote mode, default normal


remote_psf

public static java.lang.String remote_psf

external_wav

public static java.lang.String external_wav

loadingLocalSettings

private boolean loadingLocalSettings

recentFiles

private java.util.ArrayList<java.io.File> recentFiles

settingsUsed

private boolean[] settingsUsed

userNotifiedAbsentSettingsFile

private boolean userNotifiedAbsentSettingsFile

userNotifiedAbsentDefaultSettingsFile

private boolean userNotifiedAbsentDefaultSettingsFile

programStart

private boolean programStart

settingsFileData

SettingsFileData settingsFileData

initializationComplete

private boolean initializationComplete
Constructor Detail

PamSettingManager

private PamSettingManager()
Method Detail

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 implemnt PamSettings so that different settings for different bits of a PamControlledUnit are stored separately.

Parameters:
pamUnit - Reference to a PamSettings module
See Also:
PamSettings, PamControlledUnit

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.

findSettings

private PamControlledUnitSettings findSettings(PamSettings user,
                                               int whichLists)
Find settings for a particular user in one or more lists.

Parameters:
user - PamSettings user.
whichLists - lists to search
Returns:
settings object.

findSettings

private PamControlledUnitSettings findSettings(java.util.ArrayList<PamControlledUnitSettings> settingsList,
                                               boolean[] usedSettings,
                                               PamSettings user)
Find settings in a list of settings, ignoring settings which have already been used by a module.

Parameters:
settingsList - settings list
usedSettings - list of settings that have already been used.
user - module that uses the settings.
Returns:
Settings object.

findGeneralSettings

public PamControlledUnitSettings findGeneralSettings(java.lang.String unitType)
Searches a list of settings for settings with a specific type.

Parameters:
unitType -
Returns:
PamControlledUnitSettings or null if none found
See Also:
PamControlledUnitSettings

findSettings

public PamControlledUnitSettings findSettings(java.util.ArrayList<PamControlledUnitSettings> settingsList,
                                              java.lang.String unitType,
                                              java.lang.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

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 sucessfully.

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()
Save settings to the default (most recently used) psf file.

Returns:
true if successful.

loadPAMSettings

public boolean 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.

loadNormalSettings

private boolean loadNormalSettings()
Load settings perfectly 'normally' from a psf file.

Returns:
OK whether or not any settings were loaded.

loadViewerSettings

private boolean loadViewerSettings()
Load settings for viewer mode. These must come from an old PAMGUARD database containing settings information.

Returns:
true if settings loaded sucessfully.

loadMixedModeSettings

private boolean loadMixedModeSettings()
Load settings for mixed mode. These must come from an old PAMGUARD database containing settings information.

Returns:
true if settings loaded sucessfully.

initialiseRegisteredModules

private void initialiseRegisteredModules()
Some modules may have already registered before the settings were loaded, so this function is called as soon as they are loaded which sends settings to all modules in the list.


loadPSFSettings

private boolean loadPSFSettings()
Open the file that contains a list of files and optionally open a dialog giving the list of recent files.

Unfortunately, as soon as this gets called th efirst time, it tries to open a database to get more settings information and different database plug ins all start trying to get more settings and it goes round and round and round. Need to ensure that these loop around only get given the general settings information.

Returns:

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 boolean loadDBSettings()
Try to get settings information from a valid databse. If none are loaded, then return null and Pamguard will try to get them from a psf file.


saveSettingsToDatabase

private boolean saveSettingsToDatabase()
See if there is a database module in PAMGUARD and if so, save the settings in serialised from in the Pamguard_Settings and Pamguard_Settings_Last tables.

Returns:
true if successful.

findOwner

private PamSettings findOwner(java.util.ArrayList<PamSettings> ownersList,
                              java.lang.String unitType,
                              java.lang.String unitName)
Find the owner of some PAMGUARD settings.

Parameters:
ownersList - which list to search
unitType - unit type
unitName - unit name
Returns:
owner of the settings.

loadSettingsFromFile

private java.util.ArrayList<PamControlledUnitSettings> loadSettingsFromFile()
Load PAMGUARD settings from a psf file.

Returns:
Array list of settings.

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 java.io.ObjectOutputStream openOutputFile()
Open psf file for settings serialised output.

Returns:
stream handle.

openInputFile

private java.io.ObjectInputStream openInputFile()
Open psf file for settings input.

Returns:
stream handle.

openInputFileResource

private java.io.ObjectInputStream openInputFileResource()
Returns total gobbledygook - need to improve the way PAMGAURD creates new psf files.

Returns:
lies.

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.


saveSettingsFileData

private boolean saveSettingsFileData()
Save the list of recently used settings files.

Returns:
true if write OK.

loadDatabaseFileData

private boolean loadDatabaseFileData()
Loads the details of the last database to be opened. This will probably be in the form of multiple serialised objects since the database information is spread amongst several plug in sub-modules.

Returns:
true if settings data loaded ok

saveDatabaseFileData

private boolean saveDatabaseFileData()
Save the details of the most recently used database.

Returns:
true if successful.

getSettingsFileName

public java.lang.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 java.lang.String getDefaultFile()

saveSettings

public void saveSettings(javax.swing.JFrame frame)
saves settings in the current file

Parameters:
frame - GUI frame (needed for dialog, can be null)

saveSettingsAs

public void saveSettingsAs(javax.swing.JFrame frame)
Save settings to a new psf file.

Parameters:
frame - parent frame for dialog.

setDefaultFile

public void setDefaultFile(java.lang.String defaultFile)
Set the default (first) file in the settings file data.

Parameters:
defaultFile - File name string.

loadSettingsFrom

public void loadSettingsFrom(javax.swing.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(javax.swing.JFrame frame)

exportSettings

public void exportSettings(javax.swing.JFrame frame)

getOwners

public java.util.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.