This commit is contained in:
Douglas Gillespie 2022-07-26 08:22:16 +01:00
commit 1a2625dee6
10 changed files with 119 additions and 23 deletions

View File

@ -61,6 +61,7 @@ import PamView.dialog.PamLabel;
import PamView.dialog.warn.WarnOnce;
import PamView.panel.PamPanel;
import PamView.panel.PamProgressBar;
import pamguard.GlobalArguments;
import warnings.PamWarning;
/**
@ -1075,8 +1076,17 @@ public class FileInputSystem extends DaqSystem implements ActionListener, PamSe
@Override
public void daqHasEnded() {
// TODO Auto-generated method stub
fileListComplete();
}
/**
* Called when all files to be processed have been processed.
*/
protected void fileListComplete() {
if (GlobalArguments.getParam(PamController.AUTOEXIT) != null) {
System.out.println("All sound files processed, PAMGuard can close on " + PamController.AUTOEXIT);
PamController.getInstance().batchProcessingComplete();
}
}
JPanel statusPanel;

View File

@ -79,7 +79,7 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings{
private FolderInputParameters folderInputParameters;
public static final String GlobalWavFolderArg = "wavfilefolder";
public static final String GlobalWavFolderArg = "-wavfilefolder";
/**
@ -652,6 +652,10 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings{
}
calculateETA();
setFolderProgress();
if (currentFile > 0 && currentFile >= allFiles.size()) {
fileListComplete();
}
// System.out.println("FolderinputSytem: daqHasEnded");
}

View File

@ -43,6 +43,7 @@ import Acquisition.AcquisitionProcess;
import pamScrollSystem.AbstractScrollManager;
import pamViewFX.PamGuiManagerFX;
import pamViewFX.pamTask.PamTaskUpdate;
import pamguard.GlobalArguments;
import pamguard.Pamguard;
import soundPlayback.PlaybackControl;
import warnings.PamWarning;
@ -51,6 +52,7 @@ import zipUnpacker.ZipUnpacker;
import fftManager.FFTDataBlock;
import fftManager.FFTDataUnit;
import generalDatabase.DBControlUnit;
import javafx.application.Platform;
import javafx.stage.Stage;
import Array.ArrayManager;
import PamController.command.NetworkController;
@ -128,6 +130,11 @@ public class PamController implements PamControllerInterface, PamSettings {
public static final int RUN_NETWORKRECEIVER = 5;
private int runMode = RUN_NORMAL;
// flag used in main() to indicate that processing should start immediately.
public static final String AUTOSTART = "-autostart";
// flag used in main() to indicate that pamguard should exit as soon as processing ends.
public static final String AUTOEXIT = "-autoexit";
/**
* The pam model.
@ -300,10 +307,33 @@ public class PamController implements PamControllerInterface, PamSettings {
public static void create(int runMode) {
if (uniqueController == null) {
PamController pamcontroller = new PamController(runMode, null);
// I don't see any reason not have have this running with the GUI.
/*
* I don't see any reason not have have this running with the GUI.
* It launches in a new thread, so it should be fine to have
* additional commands afterwards.
*/
TerminalController tc = new TerminalController(pamcontroller);
tc.getTerminalCommands();
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
uniqueController.creationComplete();
}
});
}
/**
* Not to sound God like, but this will be called on the AWT dispatch thread shortly
* after all modules are created, PAMGuard should be fully setup and all modules will
* have recieved INITIALISATION_COMPLETE and should be good to run
*/
private void creationComplete() {
if (GlobalArguments.getParam(PamController.AUTOSTART) != null) {
startLater(); // may as well give AWT time to loop it's queue once more
}
}
/**
@ -526,6 +556,7 @@ public class PamController implements PamControllerInterface, PamSettings {
clearSelectorsAndSymbols();
/**
* Debug code for starting PG as soon as it's initialised.
*/
@ -660,11 +691,24 @@ public class PamController implements PamControllerInterface, PamSettings {
@Override
public void pamClose() {
getUidManager().runShutDownOps();
for (int i = 0; i < pamControlledUnits.size(); i++) {
pamControlledUnits.get(i).pamClose();
}
}
/**
* Shut down Pamguard
*/
public void shutDownPamguard() {
// force close the javaFX thread (because it won't close by itself - see Platform.setImplicitExit(false) in constructor
Platform.exit();
// terminate the JVM
System.exit(0);
}
/**
* Go through all data blocks in all modules and tell them to save.
* This has been built into PamProcess and PamDataBlock since we want
@ -1297,6 +1341,25 @@ public class PamController implements PamControllerInterface, PamSettings {
pamControlledUnits.get(iU).pamHasStopped();
}
guiFrameManager.pamEnded();
// no good having this here since it get's called at the end of every file.
// if (GlobalArguments.getParam(PamController.AUTOEXIT) != null) {
//// can exit here, since we've auto started, can auto exit.
// if (canClose()) {
// pamClose();
// shutDownPamguard();
// }
// }
}
public void batchProcessingComplete( ) {
if (GlobalArguments.getParam(PamController.AUTOEXIT) != null) {
// can exit here, since we've auto started, can auto exit.
if (canClose()) {
pamClose();
shutDownPamguard();
}
}
}

View File

@ -307,7 +307,10 @@ public interface PamControllerInterface {
public static final int REORDER_CONTROLLEDUNITS = 8;
/**
* Automatically sent when PAMGAURD has finished loading it's
* initial settings file and created the GUI
* initial settings file and created the GUI. It's a good time for modules
* to subscribe to their data sources, but they shouldn't do much else since
* these go around in order, so when this arrives in the first module, other
* modules may not yet be setup.
*/
public static final int INITIALIZATION_COMPLETE = 9;
/**
@ -404,6 +407,13 @@ public interface PamControllerInterface {
* The medium has been updated.
*/
public static final int GLOBAL_MEDIUM_UPDATE = 24;
/**
* Sent shortly after the main PAMGUard setup has been completed, but this point
* all modules will have received INITIALIZATION_COMPLETE and should be ready to
* go.
*/
public static final int READY_TO_RUN = 25;

View File

@ -32,6 +32,7 @@ public class NullGuiController implements PAMControllerGUI {
@Override
public void pamEnded() {
// TODO Auto-generated method stub
}

View File

@ -1659,7 +1659,8 @@ public class PamGui extends PamView implements WindowListener, PamSettings {
}
// deal with anything that needs sorting out in the realm of UID's.
pamController.getUidManager().runShutDownOps();
// move this to pamController.pamClose()
// pamController.getUidManager().runShutDownOps();
// if the user doesn't want to save the config file, make sure they know
// that they'll lose any changes to the settings
@ -1685,7 +1686,7 @@ public class PamGui extends PamView implements WindowListener, PamSettings {
pamControllerInterface.pamClose();
// shut down the JavaFX thread and the JVM
this.shutDownPamguard();
pamController.shutDownPamguard();
return true;
}

View File

@ -86,15 +86,5 @@ abstract public class PamView implements PamViewInterface {
this.frameNumber = frameNumber;
}
/**
* Shut down Pamguard
*/
public void shutDownPamguard() {
// force close the javaFX thread (because it won't close by itself - see Platform.setImplicitExit(false) in constructor
Platform.exit();
// terminate the JVM
System.exit(0);
}
}

View File

@ -122,7 +122,8 @@ public class SqliteSystem extends DBSystem implements PamSettings {
File newFile = new File(databaseName);
// if the file doesn't exit, consider creating it.
if (newFile.exists() == false) {
newFile = createNewDatabase(databaseName, null, true);
boolean ask = GlobalArguments.getParam(DBControl.GlobalDatabaseNameArg) == null;
newFile = createNewDatabase(databaseName, null, ask);
if (newFile == null) {
System.out.println("Unable to create "+newFile);
return;

View File

@ -880,8 +880,9 @@ public class PamGuiManagerFX implements PAMControllerGUI, PamSettings {
pamController.saveViewerData();
}
// deal with anything that needs sorting out in the realm of UID's.
pamController.getUidManager().runShutDownOps();
// // deal with anything that needs sorting out in the realm of UID's.
// move this to pamController.pamClose()
// pamController.getUidManager().runShutDownOps();
// if the user doesn't want to save the config file, make sure they know
// that they'll lose any changes to the settings

View File

@ -23,6 +23,7 @@ package pamguard;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import Acquisition.AcquisitionControl;
import Acquisition.FolderInputSystem;
import PamController.PamController;
import PamController.PamGUIManager;
@ -229,6 +230,14 @@ public class Pamguard {
// source folder for wav files (or other supported sound files)
GlobalArguments.setParam(FolderInputSystem.GlobalWavFolderArg, args[iArg++]);
}
else if (anArg.equalsIgnoreCase(PamController.AUTOSTART)) {
// auto start processing.
GlobalArguments.setParam(PamController.AUTOSTART, PamController.AUTOSTART);
}
else if (anArg.equalsIgnoreCase(PamController.AUTOEXIT)) {
// auto exit at end of processing.
GlobalArguments.setParam(PamController.AUTOEXIT, PamController.AUTOEXIT);
}
else if (anArg.equalsIgnoreCase("-help")) {
System.out.println("--PamGuard Help");
System.out.println("\n--For standard GUI deployment run without any options.\n");
@ -329,10 +338,16 @@ public class Pamguard {
Thread.setDefaultUncaughtExceptionHandler(new PamExceptionHandler());
System.setProperty("sun.awt.exception.handler", PamExceptionHandler.class.getName());
//Amongst other stuff the call to PamController.create()
//will build and show the GUI and the user can't
//do much else until that's done so let's have all
//that kicked off from with the EDT CJB 2009-06-16
/*
* Amongst other stuff the call to PamController.create()
* will build and show the GUI and the user can't
* do much else until that's done so let's have all
* that kicked off from with the EDT CJB 2009-06-16
* Either of these will call .create, just one is in a different
* thread, so it's at the end of the create function that other automatic
* processes should be started.
*
*/
if (PamGUIManager.isSwing()) {
SwingUtilities.invokeLater(createPamguard);