Print

Print


Commit in hps-java/src/main/java/org/lcsim/hps/monitoring on MAIN
JobSettings.java+79added 1.1
SteeringFileUtil.java+53added 1.1
ConnectionPanel.java+3-21.22 -> 1.23
ConnectionStatusPanel.java+42-61.6 -> 1.7
DefaultEtEventProcessor.java+9-91.6 -> 1.7
EventPanel.java+2-21.14 -> 1.15
JobPanel.java+279-891.11 -> 1.12
MonitoringApplication.java+361-3101.41 -> 1.42
MonitoringCommands.java+8-51.9 -> 1.10
+836-423
2 added + 7 modified, total 9 files
updates to monitoring; many feature additions; command line interface was changed; can now save and load job settings; also reworked the layout a bit so resizing the frame works okay (usually)

hps-java/src/main/java/org/lcsim/hps/monitoring
JobSettings.java added at 1.1
diff -N JobSettings.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ JobSettings.java	10 May 2012 21:14:53 -0000	1.1
@@ -0,0 +1,79 @@
+package org.lcsim.hps.monitoring;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.logging.Level;
+
+/**
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: JobSettings.java,v 1.1 2012/05/10 21:14:53 jeremy Exp $
+ */
+final class JobSettings {
+    
+    // Default job settings.
+    boolean pauseMode = false;
+    boolean disconnectOnError = false;
+    boolean warnBeforeDisconnect = true;
+    Level logLevel = Level.ALL;
+    int steeringType = 0; // resource = 0; file = 1
+    String steeringResource = "org/lcsim/hps/steering/TestRunMonitoring.lcsim";
+    String steeringFile = "";
+    String detectorName = "HPS-Test-JLAB-v4pt1";
+    String eventBuilderClassName = "org.lcsim.hps.evio.LCSimTestRunEventBuilder";
+    boolean logToFile = false;
+    String logFileName = "";
+    boolean autoSaveAida = false;
+    String autoSaveAidaFileName = "";
+    boolean enableRemoteAida = false;
+    String remoteAidaName = "hps";
+    
+    JobSettings() {
+    }
+    
+    JobSettings(File f) throws IOException {
+        load(f);
+    }
+        
+    void save(File file) throws IOException {
+        Properties prop = new Properties();
+        prop.setProperty("pauseMode", Boolean.toString(pauseMode));
+        prop.setProperty("disconnectOnError", Boolean.toString(disconnectOnError));
+        prop.setProperty("warnBeforeDisconnect", Boolean.toString(warnBeforeDisconnect));
+        prop.setProperty("logLevel", logLevel.toString());
+        prop.setProperty("steeringType", Integer.toString(steeringType));
+        prop.setProperty("steeringFile", steeringFile);
+        prop.setProperty("steeringResource", steeringResource);
+        prop.setProperty("detectorName", detectorName);
+        prop.setProperty("eventBuilderClassName", eventBuilderClassName);
+        prop.setProperty("logToFile", Boolean.toString(logToFile));
+        prop.setProperty("logFileName", logFileName);
+        prop.setProperty("autoSaveAida", Boolean.toString(autoSaveAida));
+        prop.setProperty("autoSaveAidaFileName", autoSaveAidaFileName);
+        prop.setProperty("enableRemoteAida", Boolean.toString(enableRemoteAida));
+        prop.setProperty("remoteAidaName", remoteAidaName);
+        prop.store(new FileOutputStream(file), null);
+    }
+    
+    void load(File file) throws IOException {
+        Properties prop = new Properties();
+        prop.load(new FileInputStream(file));
+        pauseMode = Boolean.parseBoolean(prop.getProperty("pauseMode"));
+        disconnectOnError = Boolean.parseBoolean(prop.getProperty("disconnectOnError"));
+        warnBeforeDisconnect = Boolean.parseBoolean(prop.getProperty("warnBeforeDisconnect"));
+        logLevel = Level.parse(prop.getProperty("logLevel"));
+        steeringType = Integer.parseInt(prop.getProperty("steeringType"));
+        steeringFile = prop.getProperty("steeringFile");
+        steeringResource = prop.getProperty("steeringResource");
+        detectorName = prop.getProperty("detectorName");
+        eventBuilderClassName = prop.getProperty("eventBuilderClassName");
+        logToFile = Boolean.parseBoolean(prop.getProperty("logToFile"));
+        logFileName = prop.getProperty("logFileName");
+        autoSaveAida = Boolean.parseBoolean(prop.getProperty("autoSaveAida"));
+        autoSaveAidaFileName = prop.getProperty("autoSaveAidaFileName");
+        enableRemoteAida = Boolean.parseBoolean(prop.getProperty("enableRemoteAida"));
+        remoteAidaName = prop.getProperty("remoteAidaName");
+    }
+} 
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
SteeringFileUtil.java added at 1.1
diff -N SteeringFileUtil.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SteeringFileUtil.java	10 May 2012 21:14:53 -0000	1.1
@@ -0,0 +1,53 @@
+package org.lcsim.hps.monitoring;
+
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * This class provides a static utility method to get a list of steering file resources from the package in hps-java that contains these files.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: SteeringFileUtil.java,v 1.1 2012/05/10 21:14:53 jeremy Exp $
+ */
+public class SteeringFileUtil {
+
+    private static final String path = "org/lcsim/hps/steering/";
+
+    public static String[] getAvailableSteeringFileResources() {
+        List<String> resources = new ArrayList<String>();
+        URL url = SteeringFileUtil.class.getResource("SteeringFileUtil.class");
+        String scheme = url.getProtocol();
+        if (!"jar".equals(scheme)) {
+            throw new IllegalArgumentException("Unsupported scheme: " + scheme);
+        }
+        try {
+            JarURLConnection con = (JarURLConnection) url.openConnection();
+            JarFile archive = con.getJarFile();
+            Enumeration<JarEntry> entries = archive.entries();
+            while (entries.hasMoreElements()) {
+                JarEntry entry = entries.nextElement();
+                if (entry.getName().startsWith(path)) {
+                    if (entry.getName().endsWith(".lcsim")) {
+                        resources.add(entry.getName());
+                    }
+                }
+            }
+            archive.close();
+        }
+        catch (IOException e) {
+            throw new RuntimeException(e);
+        }        
+        java.util.Collections.sort(resources);
+        String[] arr = new String[resources.size()];
+        for (int i=0; i<arr.length; i++) {
+            arr[i] = resources.get(i);
+        }
+        return arr;
+    }
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
ConnectionPanel.java 1.22 -> 1.23
diff -u -r1.22 -r1.23
--- ConnectionPanel.java	8 May 2012 15:52:52 -0000	1.22
+++ ConnectionPanel.java	10 May 2012 21:14:53 -0000	1.23
@@ -19,7 +19,7 @@
 
 /**
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: ConnectionPanel.java,v 1.22 2012/05/08 15:52:52 meeg Exp $
+ * @version $Id: ConnectionPanel.java,v 1.23 2012/05/10 21:14:53 jeremy Exp $
  */
 class ConnectionPanel extends FieldsPanel {
 
@@ -45,7 +45,8 @@
 
     ConnectionPanel() {
 
-        super(new Insets(1, 1, 1, 1), true);
+        //super(new Insets(1, 1, 1, 1), true);
+        super(new Insets(5, 5, 5, 5), true);
 
         setLayout(new GridBagLayout());
 

hps-java/src/main/java/org/lcsim/hps/monitoring
ConnectionStatusPanel.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- ConnectionStatusPanel.java	3 May 2012 16:59:28 -0000	1.6
+++ ConnectionStatusPanel.java	10 May 2012 21:14:53 -0000	1.7
@@ -1,30 +1,41 @@
 package org.lcsim.hps.monitoring;
 
 import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Font;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
+import javax.swing.BorderFactory;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.SwingUtilities;
+import javax.swing.border.EtchedBorder;
 
 class ConnectionStatusPanel extends JPanel {
 
     JTextField statusField;
+    JTextField dateField;
+    
+    private final SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM-dd-yyyy HH:mm:ss");
 
     ConnectionStatusPanel() {
-
+        
         setLayout(new GridBagLayout());
-
-        Insets insets = new Insets(5,2,1,2);
+        Insets insets = new Insets(10, 5, 5, 10);
+        setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));        
+        Font font = new Font("Arial", Font.PLAIN, 14);
 
         GridBagConstraints c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 0;
         c.insets = insets;
         c.anchor = GridBagConstraints.WEST;
+        c.weightx = c.weighty = 1.0;
         JLabel statusLabel = new JLabel("Connection Status:");
         statusLabel.setHorizontalAlignment(JLabel.LEFT);
         add(statusLabel, c);
@@ -34,22 +45,47 @@
         c.gridy = 0;
         c.insets = insets;
         c.anchor = GridBagConstraints.EAST;
-        statusField = new JTextField("", 20);
+        c.weightx = c.weighty = 1.0;
+        statusField = new JTextField("", 15);
         statusField.setHorizontalAlignment(JTextField.CENTER);
         statusField.setEditable(false);
         statusField.setBackground(Color.WHITE);
+        statusField.setFont(font);
         add(statusField, c);
-
+        
+        c = new GridBagConstraints();
+        c.gridx = 2;
+        c.gridy = 0;
+        c.insets = insets;
+        c.anchor = GridBagConstraints.CENTER;
+        c.weightx = c.weighty = 1.0;
+        JLabel atLabel = new JLabel("@");
+        add(atLabel, c);
+        
+        c = new GridBagConstraints();
+        c.gridx = 3;
+        c.gridy = 0;
+        c.insets = insets;
+        c.anchor = GridBagConstraints.WEST;
+        c.weightx = c.weighty = 1.0;
+        dateField = new JTextField("", 15);
+        dateField.setEditable(false);
+        dateField.setBackground(Color.WHITE);
+        dateField.setHorizontalAlignment(JTextField.RIGHT);
+        dateField.setFont(font);
+        add(dateField, c);
+        
         setStatus(ConnectionStatus.DISCONNECTED);
     }
 
     void setStatus(final int status) {
         if (status < 0 || status > (ConnectionStatus.NUMBER_STATUSES - 1)) {
-            throw new IllegalArgumentException("Invalid index value.  Must be between 0 and " + (ConnectionStatus.NUMBER_STATUSES - 1) + ".");
+            throw new IllegalArgumentException("Invalid status argument: " + status);
         }
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
                 statusField.setText(ConnectionStatus.toString(status));
+                dateField.setText(dateFormat.format(new Date()));
             }
         });
     }

hps-java/src/main/java/org/lcsim/hps/monitoring
DefaultEtEventProcessor.java 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- DefaultEtEventProcessor.java	3 May 2012 16:59:28 -0000	1.6
+++ DefaultEtEventProcessor.java	10 May 2012 21:14:53 -0000	1.7
@@ -27,7 +27,7 @@
  * having a direct reference to the actual application.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: DefaultEtEventProcessor.java,v 1.6 2012/05/03 16:59:28 jeremy Exp $
+ * @version $Id: DefaultEtEventProcessor.java,v 1.7 2012/05/10 21:14:53 jeremy Exp $
  */
 public class DefaultEtEventProcessor implements EtEventProcessor
 {
@@ -38,14 +38,13 @@
     JobControlManager jobManager;
     EtConnection et;
     List<EtEventListener> listeners = new ArrayList<EtEventListener>();
-    int status;
-    // FIXME: The volatile keyword might not be needed.  Debugging.
-    volatile boolean stopProcessing;
-    volatile boolean stopOnError;
-    volatile boolean nextEvents;
-    volatile boolean pauseMode = false;
-    volatile boolean done = false;
-    volatile boolean blocked = false; 
+    int status;    
+    boolean stopProcessing;
+    boolean stopOnError;
+    boolean nextEvents;
+    boolean pauseMode = false;
+    boolean done = false;
+    boolean blocked = false; 
     static Logger logger;
 
     /**
@@ -189,6 +188,7 @@
             catch (EventProcessingException e) {               
                 e.getCause().printStackTrace(); // This message shows up in detailed job log.
                 logger.log(Level.WARNING, "Error processing event <" + this.eventsProcessed + ">.");
+                errorOnEvent();
                 if (stopOnError) {
                     this.status = ConnectionStatus.ERROR;
                     logger.log(Level.INFO, "Exiting on first error.");

hps-java/src/main/java/org/lcsim/hps/monitoring
EventPanel.java 1.14 -> 1.15
diff -u -r1.14 -r1.15
--- EventPanel.java	3 May 2012 16:59:28 -0000	1.14
+++ EventPanel.java	10 May 2012 21:14:53 -0000	1.15
@@ -37,7 +37,7 @@
  
     EventPanel() {
         
-        super(new Insets(0, 0, 0, 0), false);
+        super(new Insets(5, 5, 5, 5), false);
 
         setLayout(new GridBagLayout());
 
@@ -110,7 +110,7 @@
     }
     
     /**
-     * At end of job, all 
+     * At end of job, final event totals are pushed to the GUI. 
      */
     void endJob() {
         incrementEventCounts();

hps-java/src/main/java/org/lcsim/hps/monitoring
JobPanel.java 1.11 -> 1.12
diff -u -r1.11 -r1.12
--- JobPanel.java	3 May 2012 16:59:28 -0000	1.11
+++ JobPanel.java	10 May 2012 21:14:53 -0000	1.12
@@ -9,31 +9,34 @@
 
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
+import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
 import javax.swing.JTextField;
 import javax.swing.SwingUtilities;
 
 class JobPanel extends FieldsPanel {
 
-    private JComboBox steeringComboBox;
-    private JTextField steeringField;
     private JTextField detectorNameField;
+    private JCheckBox disconnectWarningCheckBox;    
+    private JCheckBox disconnectOnErrorCheckBox;
     private JTextField eventBuilderField;
-    JCheckBox disconnectWarningCheckBox;	
-    JCheckBox disconnectOnErrorCheckBox;
-    JCheckBox logCheckBox;
-    JTextField logFileField;
-    JCheckBox remoteAidaCheckBox;
-    JTextField aidaNameField;
-    JCheckBox pauseModeCheckBox;
-    JComboBox logLevelComboBox;
+    private JComboBox steeringTypeComboBox;
+    private JTextField steeringFileField;
+    private JComboBox steeringResourcesComboBox;
+    private JCheckBox logCheckBox;
+    private JTextField logFileField;
+    private JCheckBox remoteAidaCheckBox;
+    private JTextField remoteAidaNameField;
+    private JCheckBox pauseModeCheckBox;
+    private JComboBox logLevelComboBox;
+    private JTextField aidaSaveField;
+    private JCheckBox aidaSaveCheckBox;
 
     private String defaultEventBuilderClassName = "";
 
-    private final static String[] steeringTypes = {"RESOURCE", "FILE", "NONE"};	
+    private final static String[] steeringTypes = {"RESOURCE", "FILE"};
     final static int RESOURCE = 0;
     final static int FILE = 1;
-    final static int NONE = 2;
     
     String[] logLevels = new String[] {
         Level.ALL.toString(),
@@ -48,69 +51,93 @@
 
     JobPanel() {
 
-        super(new Insets(1, 1, 1, 1), true);
-
+        super(new Insets(4, 0, 0, 4), true);
         setLayout(new GridBagLayout());
 
         pauseModeCheckBox = addCheckBox("Pause mode", false, true);
-        disconnectOnErrorCheckBox = addCheckBox("Disconnect on error", true, true);
-        disconnectWarningCheckBox = addCheckBox("Warn before disconnect", false, true);
+        disconnectOnErrorCheckBox = addCheckBox("Disconnect on error", false, true);
+        disconnectWarningCheckBox = addCheckBox("Warn before disconnect", true, true);
         logLevelComboBox = addComboBox("Log Level", this.logLevels);
         logLevelComboBox.setActionCommand(MonitoringCommands.logLevelCmd);
-        steeringComboBox = addComboBox("Steering Type", steeringTypes);  
-        steeringField = addField("Steering File", 30);
-        steeringField.setActionCommand(MonitoringCommands.steeringCmd);
+        steeringTypeComboBox = addComboBox("Steering Type", steeringTypes);  
+        steeringFileField = addField("Steering File", 30);        
+        steeringResourcesComboBox = addComboBox("Steering File Resource", SteeringFileUtil.getAvailableSteeringFileResources());
         detectorNameField = addField("Detector Name", 20);
         eventBuilderField = addField("Event Builder Class", 30);
         eventBuilderField.setActionCommand(MonitoringCommands.eventBuilderCmd);
         logCheckBox = addCheckBox("Log to File", false, false);
         logFileField = addField("Log File", "", "Full path to log file.", 30, false);
-        remoteAidaCheckBox = addCheckBox("Enabled remote AIDA", false, true);
-        aidaNameField = addField("Remote AIDA name", "", 15, true);
-
+        aidaSaveCheckBox = addCheckBox("Save AIDA at End of Job", false, false);
+        aidaSaveField = addField("AIDA Auto Save File Name", "", 30, false);
+        remoteAidaCheckBox = addCheckBox("Enable remote AIDA", false, true);
+        remoteAidaNameField = addField("Remote AIDA name", "", 15, true);
+        
+        // Set default job settings.
+        setJobSettings(new JobSettings());
     }
     
-    boolean isAIDAServerEnabled() {
-        return remoteAidaCheckBox.isSelected();
-    }
+    void enableJobPanel(boolean enable) {
+        detectorNameField.setEnabled(enable);
+        eventBuilderField.setEnabled(enable);
+        pauseModeCheckBox.setEnabled(enable);
+        remoteAidaCheckBox.setEnabled(enable);
+        remoteAidaNameField.setEnabled(enable);
+        steeringTypeComboBox.setEnabled(enable);
+        steeringFileField.setEnabled(enable);   
+        steeringResourcesComboBox.setEnabled(enable);
+    }   
     
-    String getRemoteAIDAName() {
-        return aidaNameField.getText();
+    void addActionListener(ActionListener listener) {
+        steeringFileField.addActionListener(listener);
+        eventBuilderField.addActionListener(listener);
+        logLevelComboBox.addActionListener(listener);
+    }
+        
+    void chooseAidaAutoSaveFile() {
+        JFileChooser fc = new JFileChooser();
+        fc.setDialogTitle("Choose AIDA Auto Save File");
+        int r = fc.showSaveDialog(this);
+        if (r == JFileChooser.APPROVE_OPTION) {
+            File file = fc.getSelectedFile();
+            String fileName = file.getPath();
+            int extIndex = fileName.lastIndexOf(".");
+            if ((extIndex == -1) || !(fileName.substring(extIndex + 1, fileName.length())).toLowerCase().equals("aida")) {
+                fileName = fileName + ".aida";
+            }
+            final String fileName2 = fileName;
+            SwingUtilities.invokeLater(new Runnable() {
+                public void run() {
+                    aidaSaveCheckBox.setSelected(true);
+                    aidaSaveField.setText(fileName2);
+                }
+            });
+        }
     }
 
-    void editSteering() {
-        String steering = steeringField.getText();
-        int steeringType = steeringComboBox.getSelectedIndex();		
+    boolean checkSteering() {
+        String steering = steeringFileField.getText();
+        int steeringType = steeringTypeComboBox.getSelectedIndex();		
         if (RESOURCE == steeringType) {
             // Check that steering resource exists.
             InputStream is = getClass().getResourceAsStream(steering);
             if (is == null) {
-                JOptionPane.showMessageDialog(this, "The LCSim steering resource does not exist.");
-                //disableSteering();
+                return false;
+            } else {
+                return true;
             }
-        } 
-        else if (FILE == steeringType) {
+        } else if (FILE == steeringType) {
             // Check that steering file exists.
             File f = new File(steering);
             if (!f.exists()) {
-                JOptionPane.showMessageDialog(this, "The LCSim steering file does not exist.");
-                //disableSteering();
+                return false;
+            } else {
+                return true;
             }
-        } 
-        else if (NONE == steeringType) {
-            if (!("".equals(steeringField.getText().trim()))) {
-                JOptionPane.showMessageDialog(this, "Select resource or file type in above combo box to enable LCSim.");
-            }
-        }
-    }
-
-    /*
-    private void disableSteering() {
-        JOptionPane.showMessageDialog(this, "No valid steering file was selected, so job will run without LCSim.");
-        steeringComboBox.setSelectedIndex(NONE);
+        } else {
+            throw new IllegalArgumentException("The steeringType is invalid: " + steeringType);
+        }               
     }
-    */
-
+ 
     void editEventBuilder() {
         String eventBuilderClassName = eventBuilderField.getText();
         try {
@@ -141,27 +168,21 @@
     }
 
     String getEventBuilderClassName() {
-        if (!"".equals(eventBuilderField.getText().trim())) {
-            return eventBuilderField.getText();
-        } else {
-            return null;
-        }
+        return eventBuilderField.getText();
     }
 
     void setSteeringFile(final String steeringFile) {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
-                steeringField.setText(steeringFile);
-                steeringComboBox.setSelectedIndex(FILE);
+                steeringFileField.setText(steeringFile);
             }
         });
     }
-
-    void setSteeringResource(final String steeringResource) {
+    
+    void setSteeringResource(final String s) {
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
-                steeringField.setText(steeringResource);
-                steeringComboBox.setSelectedIndex(RESOURCE);
+                steeringResourcesComboBox.setSelectedItem(s);
             }
         });
     }
@@ -175,24 +196,25 @@
     }
 
     String getSteering() {
-        if (steeringComboBox.getSelectedIndex() != NONE)
-            return steeringField.getText();
-        else
+        if (getSteeringType() == FILE) {
+            return steeringFileField.getText();
+        }
+        else if (getSteeringType() == RESOURCE) {
+            return (String) steeringResourcesComboBox.getSelectedItem();
+        }
+        else {
             return null;
+        }
     }
 
     int getSteeringType() {
-        return steeringComboBox.getSelectedIndex();
+        return steeringTypeComboBox.getSelectedIndex();
     }
 
     String getDetectorName() {
         return detectorNameField.getText();
     }
 
-    boolean validSteering() {
-        return !("".equals(steeringField.getText().trim())) && (this.steeringComboBox.getSelectedIndex() != NONE);
-    }
-
     void setDefaultEventBuilder(final String defaultEventBuilderClassName) {
         this.defaultEventBuilderClassName = defaultEventBuilderClassName;
         SwingUtilities.invokeLater(new Runnable() {
@@ -202,32 +224,200 @@
         });
     }
 
-    void enableJobPanel(boolean enable) {
-        steeringComboBox.setEnabled(enable);
-        steeringField.setEnabled(enable);
-        detectorNameField.setEnabled(enable);
-        eventBuilderField.setEnabled(enable);
-        remoteAidaCheckBox.setEnabled(enable);
-        aidaNameField.setEnabled(enable);
-        pauseModeCheckBox.setEnabled(enable);
-    }	
+    boolean pauseMode() {
+        return this.pauseModeCheckBox.isSelected();
+    }
     
-    void addActionListener(ActionListener listener) {
-        steeringField.addActionListener(listener);
-        eventBuilderField.addActionListener(listener);
-        //pauseModeCheckBox.addActionListener(listener);
-        logLevelComboBox.addActionListener(listener);
+    void enablePauseMode(final boolean p) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                pauseModeCheckBox.setSelected(p);
+            }
+        });
     }
 
-    boolean pauseMode() {
-        return this.pauseModeCheckBox.isSelected();
+    Level getLogLevel() {
+        return Level.parse((String) logLevelComboBox.getSelectedItem());
     }
     
-    void setPauseMode(boolean p) {
-        this.pauseModeCheckBox.setSelected(p);
+    boolean disconnectOnError() {
+        return disconnectOnErrorCheckBox.isSelected();
     }
     
-    Level getLogLevel() {
-        return Level.parse((String)this.logLevelComboBox.getSelectedItem());
+    boolean warnBeforeDisconnect() {
+        return disconnectWarningCheckBox.isSelected();
+    }
+    
+    boolean logToFile() {
+        return logCheckBox.isSelected();
+    }
+    
+    String getLogFileName() {
+        return logFileField.getText();
+    }    
+    
+    boolean isAidaServerEnabled() {
+        return remoteAidaCheckBox.isSelected();
+    }
+    
+    boolean isAidaAutoSaveEnabled() {
+        return aidaSaveCheckBox.isSelected();
+    }
+    
+    String getAidaAutoSaveFileName() {
+        return aidaSaveField.getText();
+    }
+    
+    String getRemoteAidaName() {
+        return remoteAidaNameField.getText();
     }
+                    
+    private void setDisconnectOnError(final boolean b) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                disconnectOnErrorCheckBox.setSelected(b);
+            }
+        });        
+    }
+    
+    private void setWarnBeforeDisconnect(final boolean b) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                disconnectWarningCheckBox.setSelected(b);
+            }
+        });            
+    }
+    
+    private void setSteeringType(final int t) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                steeringTypeComboBox.setSelectedIndex(t);
+            }
+        });        
+    }
+    
+    private void setLogLevel(final Level level) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                logLevelComboBox.setSelectedItem(level.toString());
+            }
+        });               
+    }
+    
+    private void setEventBuilder(final String c) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                eventBuilderField.setText(c);
+            }
+        });        
+    }
+    
+    void setLogToFile(final boolean b) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                logCheckBox.setSelected(b);
+            }
+        });        
+    }
+    
+    void setLogFile(final String s) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                logFileField.setText(s);
+            }
+        });
+    }
+    
+    private void enableAidaAutoSave(final boolean b) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                aidaSaveCheckBox.setSelected(b);
+            }
+        });
+    }
+    
+    private void setAidaAutoSaveFileName(final String s) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                aidaSaveField.setText(s);
+            }
+        });
+    }
+    
+    private void enableRemoteAida(final boolean b) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                remoteAidaCheckBox.setSelected(b);
+            }
+        });
+    }
+    
+    private void setRemoteAidaName(final String s) {
+        SwingUtilities.invokeLater(new Runnable() {
+            public void run() {
+                remoteAidaNameField.setText(s);
+            }
+        });
+    }
+    
+    private String getSelectedSteeringResource() {
+        return (String) steeringResourcesComboBox.getSelectedItem();
+    }
+    
+    private String getSteeringFile() {
+        return steeringFileField.getText();
+    }
+            
+    /**
+     * Gather JobSettings parameters from GUI and return a JobSettings object.
+     * @return The JobSettings from the JobPanel.
+     */
+    JobSettings getJobSettings() {
+        JobSettings settings = new JobSettings();
+        settings.pauseMode = pauseMode();
+        settings.disconnectOnError = disconnectOnError();
+        settings.warnBeforeDisconnect = warnBeforeDisconnect();
+        settings.logLevel = getLogLevel();
+        settings.steeringType = getSteeringType();
+        settings.steeringFile = getSteeringFile();
+        settings.steeringResource = getSelectedSteeringResource();
+        settings.detectorName = getDetectorName();
+        settings.eventBuilderClassName = getEventBuilderClassName();
+        settings.logToFile = logToFile();
+        settings.logFileName = getLogFileName();
+        settings.autoSaveAida = isAidaAutoSaveEnabled();
+        settings.autoSaveAidaFileName = getAidaAutoSaveFileName();
+        settings.remoteAidaName = getRemoteAidaName();
+        settings.enableRemoteAida = remoteAidaCheckBox.isSelected();
+        return settings;
+    }
+               
+    /**
+     * Set the JobPanel parameters from a JobSettings object.
+     * @param settings The JobSettings to load.
+     */
+    void setJobSettings(JobSettings settings) {
+        enablePauseMode(settings.pauseMode);
+        setDisconnectOnError(settings.disconnectOnError);
+        setWarnBeforeDisconnect(settings.warnBeforeDisconnect);
+        setLogLevel(settings.logLevel);
+        setSteeringType(settings.steeringType);
+        setSteeringFile(settings.steeringFile);
+        setSteeringResource(settings.steeringResource);
+        setDetectorName(settings.detectorName);
+        setEventBuilder(settings.eventBuilderClassName);
+        setLogToFile(settings.logToFile);        
+        setLogFile(settings.logFileName);
+        enableAidaAutoSave(settings.autoSaveAida);
+        setAidaAutoSaveFileName(settings.autoSaveAidaFileName);
+        enableRemoteAida(settings.enableRemoteAida);
+        setRemoteAidaName(settings.remoteAidaName);
+    }
+    
+    /**
+     * Reset the JobPanel to its defaults.
+     */
+    void resetJobSettings() {
+        setJobSettings(new JobSettings());
+    }    
 }
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringApplication.java 1.41 -> 1.42
diff -u -r1.41 -r1.42
--- MonitoringApplication.java	8 May 2012 15:52:52 -0000	1.41
+++ MonitoringApplication.java	10 May 2012 21:14:53 -0000	1.42
@@ -1,34 +1,12 @@
 package org.lcsim.hps.monitoring;
 
-import static org.lcsim.hps.monitoring.MonitoringCommands.clearLogCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.connectCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.disconnectCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.eventBuilderCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.eventRefreshCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.exitCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.loadConnectionCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.logCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.logLevelCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.nextCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.pauseCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.resetConnectionSettingsCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.resetDriversCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.resetEventsCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.resumeCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.saveConnectionCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.saveLogCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.savePlotsCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.screenshotCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.setMaxEventsCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.setSteeringFileCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.steeringCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.terminalCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.updateTimeCmd;
+import static org.lcsim.hps.monitoring.MonitoringCommands.*;
 
 import java.awt.AWTException;
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
+import java.awt.Insets;
 import java.awt.Rectangle;
 import java.awt.Robot;
 import java.awt.Toolkit;
@@ -38,6 +16,7 @@
 import java.awt.image.BufferedImage;
 import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -67,22 +46,24 @@
 import javax.swing.Timer;
 import javax.swing.table.DefaultTableModel;
 
-import org.apache.commons.cli.*;
-
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
 import org.lcsim.hps.evio.LCSimEventBuilder;
-import org.lcsim.hps.evio.LCSimTestRunEventBuilder;
 import org.lcsim.job.JobControlManager;
 import org.lcsim.util.Driver;
 import org.lcsim.util.aida.AIDA;
 
 /**
- * Monitoring application for HPS Test Run, which can run LCSim steering files
- * on data converted from the ET ring. This class is accessible to users by
- * calling its main() method.
- *
+ * Monitoring application for HPS Test Run, which can run LCSim steering files on data converted from the ET
+ * ring. This class is accessible to users by calling its main() method.
+ * 
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: MonitoringApplication.java,v 1.36 2012/05/03 16:59:28 jeremy
- * Exp $
+ * @version $Id: MonitoringApplication.java,v 1.42 2012/05/10 21:14:53 jeremy Exp $
  */
 public class MonitoringApplication {
 
@@ -95,6 +76,7 @@
     private JobPanel jobPanel;
     private JMenuBar menuBar;
     private EventButtonsPanel buttonsPanel;
+
     // References to menu items that will be enabled/disabled depending on application state.
     private JMenuItem connectItem;
     private JMenuItem disconnectItem;
@@ -106,44 +88,63 @@
     private JMenuItem logItem;
     private JMenuItem terminalItem;
     private JMenuItem steeringItem;
+    private JMenuItem aidaAutoSaveItem;
+    private JMenuItem saveJobSettingsItem;
+    private JMenuItem loadJobSettingsItem;
+    private JMenuItem resetJobSettingsItem;
+
     // Saved references to System.out and System.err in case need to reset.
     private final PrintStream sysOut = System.out;
     private final PrintStream sysErr = System.err;
+
     // ET connection parameters and state.
     private ConnectionParameters connectionParameters;
     private EtConnection connection;
     private int connectionStatus = ConnectionStatus.DISCONNECTED;
+
     // Event processing objects.
     private JobControlManager jobManager;
     private LCSimEventBuilder eventBuilder;
     private EtEventProcessor eventProcessor;
     private Thread eventProcessingThread;
+
     // Job timing.
     private Timer timer;
     private long jobStartTime;
+
     // ActionListener for GUI event dispatching.
     private ActionListener actionListener;
+
     // Logging objects.
     private static Logger logger;
     private Handler logHandler;
     private DefaultTableModel logTableModel;
     private JTable logTable;
+
     // Some default GUI size parameters.
-    private final int maxWidth = 800;
-    private final int logHeight = 300;
-    // Format for screenshots.  Hard-coded to PNG.
+    private final int logTableWidth = 700;
+    private final int logTableHeight = 320;
+
+    // Format for screenshots. Hard-coded to PNG.
     private static final String screenshotFormat = "png";
+
     // The AIDA remote server.
     private AIDAServer server;
+
     // Listener for processing EtEvents.
     private EtEventListener etListener = new MonitoringApplicationEtListener();
-    // Maximum time to wait for ET system to disconnect before zombifying the station, in milliseconds.
-    // TODO: Make this an option in JobPanel.
+
+    // Maximum time in millis to wait for the ET system to disconnect.
+    // TODO: Make this an option in the JobPanel.
     private int maxCleanupTime = 5000;
 
+    // Format of date field for log.
+    private final SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM-dd-yyyy HH:mm:ss.SSS");
+
+    private static final String LCSIM_FAIL_MESSAGE = "Failed to setup LCSim.";
+
     /**
-     * Constructor for monitoring application. Users should not need to use
-     * this; call main() method instead.
+     * Constructor for monitoring application. Users should not need to use this; call main() method instead.
      */
     private MonitoringApplication() {
 
@@ -167,9 +168,10 @@
     }
 
     /**
-     * Creates all the JPanels for the application.
+     * Creates all the JPanels for the monitoring GUI.
      */
     private void createPanels() {
+
         // Main panel for the application.
         mainPanel = new JPanel();
         mainPanel.setLayout(new GridBagLayout());
@@ -178,9 +180,9 @@
         GridBagConstraints c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 0;
-        c.anchor = GridBagConstraints.NORTHWEST;
-        c.fill = GridBagConstraints.BOTH;
+        c.anchor = GridBagConstraints.NORTH;
         c.weightx = c.weighty = 1.0;
+        c.insets = new Insets(15, 0, 0, 15);
         connectionStatusPanel = new ConnectionStatusPanel();
         mainPanel.add(connectionStatusPanel, c);
 
@@ -189,20 +191,20 @@
         c.gridx = 0;
         c.gridy = 1;
         c.anchor = GridBagConstraints.CENTER;
+        c.insets = new Insets(0, 0, 0, 20);
         buttonsPanel = new EventButtonsPanel();
         buttonsPanel.addActionListener(actionListener);
         mainPanel.add(buttonsPanel, c);
 
-        // Sub-panels.
+        // Contents of the tabs panel.
         connectionPanel = new ConnectionPanel();
         eventPanel = new EventPanel();
         jobPanel = new JobPanel();
-        jobPanel.addActionListener(actionListener);
 
         // Tab panels.
         c = new GridBagConstraints();
         c.fill = GridBagConstraints.BOTH;
-        c.weightx = c.weighty = 1.0;
+        c.weightx = c.weighty = 0.8;
         JPanel tabsPanel = new JPanel();
         tabs = new JTabbedPane();
         tabs.addTab("Connection Settings", connectionPanel);
@@ -216,6 +218,7 @@
         c.gridy = 2;
         c.fill = GridBagConstraints.BOTH;
         c.weightx = c.weighty = 1.0;
+        c.insets = new Insets(0, 0, 0, 10);
         mainPanel.add(tabsPanel, c);
     }
 
@@ -299,6 +302,27 @@
         jobMenu.setMnemonic(KeyEvent.VK_J);
         menuBar.add(jobMenu);
 
+        saveJobSettingsItem = new JMenuItem("Save Job Settings...");
+        saveJobSettingsItem.setMnemonic(KeyEvent.VK_J);
+        saveJobSettingsItem.setActionCommand(saveJobSettingsCmd);
+        saveJobSettingsItem.addActionListener(actionListener);
+        saveJobSettingsItem.setToolTipText("Save Job Settings configuration to a properties file.");
+        jobMenu.add(saveJobSettingsItem);
+
+        loadJobSettingsItem = new JMenuItem("Load Job Settings...");
+        loadJobSettingsItem.setMnemonic(KeyEvent.VK_L);
+        loadJobSettingsItem.setActionCommand(loadJobSettingsCmd);
+        loadJobSettingsItem.addActionListener(actionListener);
+        loadJobSettingsItem.setToolTipText("Load Job Settings from a properties file.");
+        jobMenu.add(loadJobSettingsItem);
+
+        resetJobSettingsItem = new JMenuItem("Reset Job Settings");
+        resetJobSettingsItem.setMnemonic(KeyEvent.VK_R);
+        resetJobSettingsItem.setActionCommand(resetJobSettingsCmd);
+        resetJobSettingsItem.addActionListener(actionListener);
+        resetJobSettingsItem.setToolTipText("Reset Job Settings to the defaults.");
+        jobMenu.add(resetJobSettingsItem);
+
         steeringItem = new JMenuItem("Set Steering File...");
         steeringItem.setMnemonic(KeyEvent.VK_S);
         steeringItem.setActionCommand(setSteeringFileCmd);
@@ -306,6 +330,13 @@
         steeringItem.setToolTipText("Set the job's LCSim steering file.");
         jobMenu.add(steeringItem);
 
+        aidaAutoSaveItem = new JMenuItem("AIDA Auto Save File...");
+        aidaAutoSaveItem.setMnemonic(KeyEvent.VK_A);
+        aidaAutoSaveItem.setActionCommand(aidaAutoSaveCmd);
+        aidaAutoSaveItem.addActionListener(actionListener);
+        aidaAutoSaveItem.setToolTipText("Select name of file to auto save AIDA plots at end of job.");
+        jobMenu.add(aidaAutoSaveItem);
+
         savePlotsItem = new JMenuItem("Save Plots to AIDA File...");
         savePlotsItem.setMnemonic(KeyEvent.VK_P);
         savePlotsItem.setActionCommand(savePlotsCmd);
@@ -324,7 +355,7 @@
 
         logItem = new JMenuItem("Redirect to File...");
         logItem.setMnemonic(KeyEvent.VK_F);
-        logItem.setActionCommand(logCmd);
+        logItem.setActionCommand(logToFileCmd);
         logItem.addActionListener(actionListener);
         logItem.setEnabled(true);
         logItem.setToolTipText("Redirect job's standard out and err to a file.");
@@ -332,7 +363,7 @@
 
         terminalItem = new JMenuItem("Redirect to Terminal");
         terminalItem.setMnemonic(KeyEvent.VK_T);
-        terminalItem.setActionCommand(terminalCmd);
+        terminalItem.setActionCommand(logToTerminalCmd);
         terminalItem.addActionListener(actionListener);
         terminalItem.setEnabled(false);
         terminalItem.setToolTipText("Redirect job's standard out and err back to the terminal.");
@@ -351,16 +382,16 @@
 
         JMenuItem saveLogItem = new JMenuItem("Save log to file...");
         saveLogItem.setMnemonic(KeyEvent.VK_S);
-        saveLogItem.setActionCommand(saveLogCmd);
+        saveLogItem.setActionCommand(saveLogTableCmd);
         saveLogItem.addActionListener(actionListener);
         saveLogItem.setToolTipText("Save the log records to a tab delimited text file.");
         logMenu.add(saveLogItem);
 
         JMenuItem clearLogItem = new JMenuItem("Clear log");
         clearLogItem.setMnemonic(KeyEvent.VK_C);
-        clearLogItem.setActionCommand(clearLogCmd);
+        clearLogItem.setActionCommand(clearLogTableCmd);
         clearLogItem.addActionListener(actionListener);
-        clearLogItem.setToolTipText("Clear the log of all messages.");
+        clearLogItem.setToolTipText("Clear the log table of all messages.");
         logMenu.add(clearLogItem);
     }
 
@@ -369,18 +400,14 @@
      */
     private class MonitoringApplicationLogHandler extends Handler {
 
-        // Format of date field.
-        private final SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM-dd-yyyy HH:mm:ss.SSS");
-
         /**
          * Puts log messages into the application's log table GUI component.
          */
         public void publish(LogRecord record) {
-            Object[] row = new Object[]{
-                record.getLoggerName(), // source
-                record.getMessage(), // message
-                dateFormat.format(new Date(record.getMillis())), // date
-                record.getLevel()}; // level
+            Object[] row = new Object[] { record.getLoggerName(), // source
+                    record.getMessage(), // message
+                    dateFormat.format(new Date(record.getMillis())), // date
+                    record.getLevel() }; // level
             logTableModel.insertRow(logTable.getRowCount(), row);
         }
 
@@ -392,11 +419,11 @@
     }
 
     /**
-     * Creates the application's log table GUI component, which is a JTable
-     * containing messages from the logger.
+     * Creates the application's log table GUI component, which is a JTable containing messages from the
+     * logger.
      */
     private void createLogTable() {
-        final String[] logTableColumns = {"Source", "Message", "Date", "Level"};
+        final String[] logTableColumns = { "Source", "Message", "Date", "Level" };
         String data[][] = new String[0][0];
         logTableModel = new DefaultTableModel(data, logTableColumns);
         logTable = new JTable(logTableModel);
@@ -407,14 +434,15 @@
         c.gridy = 3;
         c.fill = GridBagConstraints.BOTH;
         c.weightx = c.weighty = 1.0;
+        c.insets = new Insets(0, 3, 0, 10);
         JScrollPane logPane = new JScrollPane(logTable);
-        logPane.setPreferredSize(new Dimension(maxWidth, logHeight));
+        logPane.setPreferredSize(new Dimension(logTableWidth, logTableHeight));
+        logPane.setMinimumSize(new Dimension(0, 300));
         mainPanel.add(logPane, c);
     }
 
     /**
-     * Setup the application's Logger object for writing messages to the log
-     * table.
+     * Setup the application's Logger object for writing messages to the log table.
      */
     private void setupLogger() {
         logger = Logger.getLogger(this.getClass().getSimpleName());
@@ -426,13 +454,12 @@
 
     /**
      * Create the monitoring application frame and run it on a separate thread.
-     *
+     * 
      * @return Reference to the created application.
      */
     private static final MonitoringApplication createMonitoringApplication() {
         final MonitoringApplication app = new MonitoringApplication();
         SwingUtilities.invokeLater(new Runnable() {
-
             public void run() {
                 app.createApplicationFrame();
             }
@@ -442,36 +469,28 @@
 
     /**
      * Run the monitoring application from the command line.
-     *
+     * 
      * @param args The command line arguments.
      */
-    // TODO: Command line arguments should be: [etFile] [steeringFile] (according to Matthew Graham!)
     public static void main(String[] args) {
-        final String defaultDetectorName;
-        final String defaultSteering = "/org/lcsim/hps/steering/TestRunMonitoring.lcsim";
-        final String defaultEventBuilder;
 
         // Set up command line parsing.
         Options options = new Options();
-
-        options.addOption(new Option("h", false, "Print this help."));
-        options.addOption(new Option("p", true, "Load properties file."));
-        options.addOption(new Option("r", true, "Load specified steering file resource."));
-        options.addOption(new Option("x", true, "Load specified steering file path."));
-        options.addOption(new Option("d", true, "Detector to use."));
-        options.addOption(new Option("b", true, "Event builder to use."));
-        options.addOption(new Option("s", false, "Set misc. shifter-friendly defaults."));
-
+        options.addOption(new Option("h", false, "Print help."));
+        options.addOption(new Option("c", true, "Load properties file with connection settings."));
+        options.addOption(new Option("j", true, "Load properties file with job settings."));
         CommandLineParser parser = new PosixParser();
 
         // Parse command line arguments.
         CommandLine cl = null;
         try {
             cl = parser.parse(options, args);
-        } catch (ParseException e) {
+        }
+        catch (ParseException e) {
             throw new RuntimeException("Problem parsing command line options.", e);
         }
 
+        // Print help and exit.
         if (cl.hasOption("h")) {
             System.out.println("MonitoringApplication [options]");
             HelpFormatter help = new HelpFormatter();
@@ -479,73 +498,34 @@
             System.exit(1);
         }
 
-        if (cl.hasOption("d")) {
-            defaultDetectorName = cl.getOptionValue("d");
-        } else {
-            defaultDetectorName = "HPS-Test-JLAB-v4pt0";
-        }
-
-        if (cl.hasOption("b")) {
-            defaultEventBuilder = cl.getOptionValue("b");
-        } else {
-            defaultEventBuilder = LCSimTestRunEventBuilder.class.getCanonicalName();
-        }
-
-        // Create the main app class.
+        // Create the application class.
         MonitoringApplication app = MonitoringApplication.createMonitoringApplication();
 
-        if (cl.hasOption("p")) {
-            File propertiesFile = new File(cl.getOptionValue("p"));
-            app.connectionPanel.loadPropertiesFile(propertiesFile);
+        // Load the connection settings.
+        if (cl.hasOption("c")) {
+            app.loadConnectionSettings(new File(cl.getOptionValue("p")));
         }
 
-        if (cl.hasOption("s")) {
-            app.jobPanel.disconnectOnErrorCheckBox.setSelected(false);
-            app.jobPanel.disconnectWarningCheckBox.setSelected(true);
-        }
-
-        // Set job parameters.
-        app.setJobParameters(new JobParameters(new String[]{defaultDetectorName, defaultSteering, defaultEventBuilder}));
-
-        if (cl.hasOption("r")) {
-            app.jobPanel.setSteeringResource(cl.getOptionValue("r"));
+        // Load the job settings.
+        if (cl.hasOption("j")) {
+            app.loadJobSettings(new File(cl.getOptionValue("j")));
         }
-
-        if (cl.hasOption("x")) {
-            app.jobPanel.setSteeringFile(cl.getOptionValue("x"));
-        }
-
-
-        // Run the app.
-        app.run();
     }
 
-    /**
-     * Runs the application loop.
-     */
-    private void run() {
-        // GUI loop.
-        while (true) {
-        }
+    private void loadConnectionSettings(File file) {
+        connectionPanel.loadPropertiesFile(file);
     }
 
-    /**
-     * Application parameters: params[0] = detectorName params[1] =
-     * steeringResourceString params[2] = eventBuilderClassName
-     */
-    private static final class JobParameters {
-
-        private String detectorName;
-        private String steeringResource;
-        private String eventBuilderClassName;
-
-        JobParameters(String[] params) {
-            if (params.length != 3) {
-                new IllegalArgumentException("Parameter array is wrong length.");
+    private void loadJobSettings(File file) {
+        try {
+            jobPanel.setJobSettings(new JobSettings(file));
+            // Need to check here if System.out and err have been redirected.
+            if (jobPanel.logToFile()) {
+                redirectStdOutAndErrToFile(new File(jobPanel.getLogFileName()));
             }
-            this.detectorName = params[0];
-            this.steeringResource = params[1];
-            this.eventBuilderClassName = params[2];
+        }
+        catch (IOException e) {
+            throw new RuntimeException(e);
         }
     }
 
@@ -569,12 +549,12 @@
                 savePlots();
             } else if (resetDriversCmd.equals(cmd)) {
                 resetDrivers();
-            } else if (logCmd.equals(cmd)) {
+            } else if (logToFileCmd.equals(cmd)) {
                 logToFile();
-            } else if (terminalCmd.equals(cmd)) {
+            } else if (logToTerminalCmd.equals(cmd)) {
                 logToTerminal();
             } else if (screenshotCmd.equals(cmd)) {
-                screenshot();
+                chooseScreenshot();
             } else if (exitCmd.equals(cmd)) {
                 exit();
             } else if (updateTimeCmd.equals(cmd)) {
@@ -588,15 +568,13 @@
             } else if (resetConnectionSettingsCmd.equals(cmd)) {
                 connectionPanel.reset();
             } else if (setSteeringFileCmd.equals(cmd)) {
-                selectSteeringFile();
+                chooseSteeringFile();
             } else if (setMaxEventsCmd.equals(cmd)) {
                 setMaxEvents();
-            } else if (saveLogCmd.equals(cmd)) {
+            } else if (saveLogTableCmd.equals(cmd)) {
                 saveLogToFile();
-            } else if (clearLogCmd.equals(cmd)) {
+            } else if (clearLogTableCmd.equals(cmd)) {
                 clearLog();
-            } else if (steeringCmd.equals(cmd)) {
-                jobPanel.editSteering();
             } else if (eventBuilderCmd.equals(cmd)) {
                 jobPanel.editEventBuilder();
             } else if (pauseCmd.equals(cmd)) {
@@ -607,12 +585,19 @@
                 resume();
             } else if (logLevelCmd.equals(cmd)) {
                 setLogLevel();
+            } else if (aidaAutoSaveCmd.equals(cmd)) {
+                jobPanel.chooseAidaAutoSaveFile();
+            } else if (saveJobSettingsCmd.equals(cmd)) {
+                saveJobSettings();
+            } else if (loadJobSettingsCmd.equals(cmd)) {
+                loadJobSettings();
+            } else if (resetJobSettingsCmd.equals(cmd)) {
+                resetJobSettings();
             }
         }
 
         private void startDisconnectThread() {
             Runnable r = new Runnable() {
-
                 public void run() {
                     disconnect();
                 }
@@ -622,14 +607,56 @@
         }
     }
 
+    private void saveJobSettings() {
+        JFileChooser fc = new JFileChooser();
+        fc.setDialogTitle("Save Job Settings");
+        int r = fc.showSaveDialog(mainPanel);
+        if (r == JFileChooser.APPROVE_OPTION) {
+            File f = fc.getSelectedFile();
+            JobSettings settings = jobPanel.getJobSettings();
+            try {
+                settings.save(f);
+                logger.log(Level.INFO, "Saved Job Settings to properties file <" + f.getPath() + ">.");
+            }
+            catch (IOException e) {
+                e.printStackTrace();
+                logger.log(Level.SEVERE, "Error saving Job Settings to properties file <" + f.getPath() + ">.");
+                showDialog("Error saving Job Settings to properties file.");
+            }
+        }
+    }
+
+    private void loadJobSettings() {
+        JFileChooser fc = new JFileChooser();
+        fc.setDialogTitle("Load Job Settings");
+        int r = fc.showOpenDialog(mainPanel);
+        if (r == JFileChooser.APPROVE_OPTION) {
+            File f = fc.getSelectedFile();
+            try {
+                jobPanel.setJobSettings(new JobSettings(f));
+                logger.log(Level.INFO, "Loaded Job Settings from properties file <" + f.getPath() + ">.");
+            }
+            catch (IOException e) {
+                e.printStackTrace();
+                logger.log(Level.SEVERE, "Error loading Job Settings from properties file <" + f.getPath() + ">.");
+                showDialog("Error loading Job Settings from properties file.");
+            }
+        }
+    }
+
+    private void resetJobSettings() {
+        jobPanel.resetJobSettings();
+        // Redirect System.out and err back to the terminal.
+        logToTerminal();
+    }
+
     /**
-     * This is the primary entry point for starting a monitoring session. The
-     * session is started on a new thread so it doesn't block.
+     * This is the primary entry point for starting a monitoring session. The session is started on a new
+     * thread so it doesn't block.
      */
     private void startSessionThread() {
         if (getConnectionStatus() != ConnectionStatus.CONNECTED) {
             Runnable r = new Runnable() {
-
                 public void run() {
                     session();
                 }
@@ -642,8 +669,7 @@
     }
 
     /**
-     * Set a new log level for the application and also forward to the event
-     * processor.
+     * Set a new log level for the application and also forward to the event processor.
      */
     private void setLogLevel() {
         Level newLevel = jobPanel.getLogLevel();
@@ -658,6 +684,9 @@
      */
     private final class MonitoringApplicationEtListener implements EtEventListener {
 
+        /**
+         * Beginning of job.
+         */
         public void begin() {
 
             // Reset event GUI.
@@ -670,29 +699,55 @@
             startTimer();
         }
 
+        /**
+         * Start of next event.
+         */
         public void startOfEvent() {
             eventPanel.updateEventCount();
         }
 
+        /**
+         * End of single event.
+         */
         public void endOfEvent() {
             eventPanel.updateAverageEventRate(jobStartTime);
         }
 
+        /**
+         * Error on this event.
+         */
         public void errorOnEvent() {
             eventPanel.updateBadEventCount();
         }
 
+        /**
+         * End of job.
+         */
         public void finish() {
-            logger.log(Level.FINEST, "In finish() method to cleanup job.");
+
+            // Show a warning dialog box before disconnecting, if this option is selected.
+            // This needs to go here rather than in disconnect() so that the LCSim plots stay up.
+            if (warnOnDisconnect()) {
+                logger.log(Level.FINEST, "Waiting for user to verify disconnect request.");
+                showDialog("You are about to be disconnected.");
+            }
+
             try {
+
+                // Save final AIDA file if option is selected.
+                if (jobPanel.isAidaAutoSaveEnabled()) {
+                    AIDA.defaultInstance().saveAs(jobPanel.getAidaAutoSaveFileName());
+                }
+
                 // Call cleanup methods of Drivers.
                 try {
                     if (jobManager != null) {
                         jobManager.finish();
                     }
-                } catch (Exception e) {
+                }
+                catch (Exception e) {
                     e.printStackTrace();
-                    logger.log(Level.WARNING, "Error calling jobManager.finish() in job cleanup.");
+                    logger.log(Level.WARNING, "Error cleaning up LCSim job.");
                 }
 
                 // Stop the job timer.
@@ -709,12 +764,16 @@
                     server = null;
                     logger.log(Level.CONFIG, "Remote AIDA server was closed.");
                 }
-            } catch (Exception e) {
+            }
+            catch (Exception e) {
                 e.printStackTrace();
                 logger.log(Level.WARNING, "Error in finish() method <" + e.getMessage() + ">.");
             }
         }
 
+        /**
+         * Prestart event received.
+         */
         public void prestart(int seconds, int runNumber) {
             final long millis = ((long) seconds) * 1000;
             eventPanel.setRunNumber(runNumber);
@@ -723,6 +782,9 @@
             logger.log(Level.INFO, "Pre Start time <" + EventPanel.dateFormat.format(new Date(millis)) + ">.");
         }
 
+        /**
+         * End run event received.
+         */
         public void endRun(int seconds, int events) {
             final long millis = ((long) seconds) * 1000;
             eventPanel.setRunEndTime(millis);
@@ -733,19 +795,8 @@
     }
 
     /**
-     * Set the job parameters.
-     *
-     * @param p The job parameters.
-     */
-    private void setJobParameters(JobParameters p) {
-        jobPanel.setDetectorName(p.detectorName);
-        jobPanel.setSteeringResource(p.steeringResource);
-        jobPanel.setDefaultEventBuilder(p.eventBuilderClassName);
-    }
-
-    /**
      * Set the connection status.
-     *
+     * 
      * @param status The connection status.
      */
     private void setConnectionStatus(int status) {
@@ -757,7 +808,7 @@
 
     /**
      * Get the current connection status.
-     *
+     * 
      * @return The connection status.
      */
     private int getConnectionStatus() {
@@ -765,17 +816,8 @@
     }
 
     /**
-     * Get whether there is currently a connection request.
-     *
-     * @return True if connection is currently requested; false if no.
-     */
-    private boolean connectionRequested() {
-        return connectionStatus == ConnectionStatus.CONNECTION_REQUESTED;
-    }
-
-    /**
      * Pop-up a modal dialog.
-     *
+     * 
      * @param m The message to display in the dialog box.
      */
     private void showDialog(String m) {
@@ -783,8 +825,8 @@
     }
 
     /**
-     * Setup the frame to run the application. This should be called using
-     * Runnable.run() (see MonitoringExample).
+     * Setup the frame to run the application. This should be called using Runnable.run() (see
+     * MonitoringExample).
      */
     private void createApplicationFrame() {
         mainPanel.setOpaque(true);
@@ -792,8 +834,8 @@
         frame.setContentPane(mainPanel);
         frame.setJMenuBar(menuBar);
         frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
-        frame.setMinimumSize(new Dimension(800, 400));
-        frame.setResizable(false);
+        frame.setMinimumSize(new Dimension(600, 850));
+        frame.setResizable(true);
         frame.pack();
         frame.setVisible(true);
     }
@@ -809,7 +851,8 @@
             try {
                 AIDA.defaultInstance().saveAs(fileName);
                 logger.log(Level.INFO, "Plots saved to <" + fileName + ">.");
-            } catch (IOException e) {
+            }
+            catch (IOException e) {
                 e.printStackTrace();
             }
         }
@@ -818,7 +861,7 @@
     /**
      * Select an LCSim steering file from disk.
      */
-    private void selectSteeringFile() {
+    private void chooseSteeringFile() {
         JFileChooser fc = new JFileChooser();
         int r = fc.showOpenDialog(mainPanel);
         if (r == JFileChooser.APPROVE_OPTION) {
@@ -827,7 +870,8 @@
                 (new JobControlManager()).setup(fileName);
                 jobPanel.setSteeringFile(fileName.getPath());
                 logger.log(Level.INFO, "Steering file set to <" + fileName.getPath() + ">.");
-            } catch (Exception e) {
+            }
+            catch (Exception e) {
                 e.printStackTrace();
                 logger.log(Level.SEVERE, "Failed to read steering file <" + fileName.getPath() + ">.");
                 showDialog("Failed to read the LCSim XML file.");
@@ -837,7 +881,7 @@
 
     /**
      * Get the full title of the application.
-     *
+     * 
      * @return The application title.
      */
     private static String getApplicationTitle() {
@@ -846,20 +890,21 @@
 
     /**
      * Get the hostname, which is used in the application title.
-     *
+     * 
      * @return The hostname.
      */
     private static String getHostname() {
         try {
             return InetAddress.getLocalHost().getHostName();
-        } catch (Exception e) {
+        }
+        catch (Exception e) {
             return "UNKNOWN_HOST";
         }
     }
 
     /**
      * Get the user name, which is used in the application title.
-     *
+     * 
      * @return The user name.
      */
     private static String getUserName() {
@@ -871,8 +916,8 @@
     }
 
     /**
-     * Call the reset() method on Drivers which implement {@link Resettable}.
-     * They must implement the {@link Resettable} interface for this to work.
+     * Call the reset() method on Drivers which implement {@link Resettable}. They must implement the
+     * {@link Resettable} interface for this to work.
      */
     private synchronized void resetDrivers() {
         if (jobManager != null) {
@@ -880,7 +925,8 @@
                 if (driver instanceof Resettable) {
                     try {
                         ((Resettable) driver).reset();
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e) {
                         e.printStackTrace();
                     }
                 }
@@ -890,9 +936,8 @@
     }
 
     /**
-     * Redirect System.out and System.err to a file. This is independent of
-     * messages that are sent to the application's log table and is primarily
-     * used to capture lengthy debug output from event processing.
+     * Redirect System.out and System.err to a file. This is independent of messages that are sent to the
+     * application's log table and is primarily used to capture lengthy debug output from event processing.
      */
     private void logToFile() {
         JFileChooser fc = new JFileChooser();
@@ -914,35 +959,41 @@
                     SwingUtilities.invokeLater(new Runnable() {
 
                         public void run() {
-                            jobPanel.logFileField.setText(logFile.getPath());
-                            jobPanel.logCheckBox.setSelected(true);
+                            jobPanel.setLogToFile(true);
+                            jobPanel.setLogFile(logFile.getPath());
+
                             terminalItem.setEnabled(true);
                             logItem.setEnabled(false);
                         }
                     });
 
                     logger.log(Level.INFO, "Redirected print output to file <" + logFile.getPath() + ">.");
-                } catch (IOException e) {
+                }
+                catch (IOException e) {
                     logger.log(Level.SEVERE, "Error redirecting print output to file <" + logFile.getPath() + ">.");
                     showDialog("Error creating log file.");
                 }
             }
         }
     }
+    
+    private void redirectStdOutAndErrToFile(File file) throws FileNotFoundException {
+        PrintStream ps = new PrintStream(new FileOutputStream(file.getPath()));
+        System.setOut(ps);
+        System.setErr(ps);
+    }
 
     /**
-     * Redirect System.out and System.err back to the terminal, e.g. if they
-     * were previously sent to a file. This is independent of messages that are
-     * sent to the application's log table.
+     * Redirect System.out and System.err back to the terminal, e.g. if they were previously sent to a file.
+     * This is independent of messages that are sent to the application's log table.
      */
     private void logToTerminal() {
         System.setOut(sysOut);
         System.setErr(sysErr);
         SwingUtilities.invokeLater(new Runnable() {
-
             public void run() {
-                jobPanel.logFileField.setText("");
-                jobPanel.logCheckBox.setSelected(false);
+                jobPanel.setLogFile("");
+                jobPanel.setLogToFile(false);
                 terminalItem.setEnabled(false);
                 logItem.setEnabled(true);
             }
@@ -962,15 +1013,16 @@
             }
             eventPanel.setEventRefresh(newEventRefresh);
             logger.log(Level.INFO, "Event refresh set to <" + newEventRefresh + ">.");
-        } catch (Exception e) {
+        }
+        catch (Exception e) {
             logger.log(Level.WARNING, "Ignored invalid event refresh setting.");
             showDialog("The value " + inputValue + " is not valid for Event Refresh Rate.");
         }
     }
 
     /**
-     * Using a modal input dialog, set the maximum number of events to process
-     * before automatic disconnect.
+     * Using a modal dialog, set the maximum number of events to process before an automatic disconnect
+     * occurs.
      */
     private void setMaxEvents() {
         String inputValue = JOptionPane.showInputDialog("Max Events:", eventPanel.getMaxEvents());
@@ -983,17 +1035,18 @@
             // Set max events in panel.
             eventPanel.setMaxEvents(newMaxEvents);
             // Set max events in event processor.
-            eventProcessor.setMaxEvents(newMaxEvents);
+            if (eventProcessor != null)
+                eventProcessor.setMaxEvents(newMaxEvents);
             logger.log(Level.INFO, "Max events set to <" + newMaxEvents + ">.");
-        } catch (Exception e) {
+        }
+        catch (Exception e) {
             logger.log(Level.WARNING, "Ignored invalid max events setting <" + inputValue + ">.");
             showDialog("The value " + inputValue + " is not valid for Max Events.");
         }
     }
 
     /**
-     * Set the GUI state to disconnected, which will enable/disable applicable
-     * GUI components and menu items.
+     * Set the GUI state to disconnected, which will enable/disable applicable GUI components and menu items.
      */
     private void setDisconnectedGuiState() {
 
@@ -1023,8 +1076,7 @@
     }
 
     /**
-     * Set the GUI to connected state, which will enable/disable appropriate
-     * components and menu items.
+     * Set the GUI to connected state, which will enable/disable appropriate components and menu items.
      */
     private void setConnectedGuiState() {
 
@@ -1064,9 +1116,9 @@
[truncated at 1000 lines; 449 more skipped]

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringCommands.java 1.9 -> 1.10
diff -u -r1.9 -r1.10
--- MonitoringCommands.java	3 May 2012 16:59:28 -0000	1.9
+++ MonitoringCommands.java	10 May 2012 21:14:53 -0000	1.10
@@ -17,21 +17,24 @@
     static final String resetEventsCmd = "resetEvents";
     static final String savePlotsCmd = "savePlots";
     static final String resetDriversCmd = "resetDrivers";
-    static final String steeringCmd = "steering";
     static final String eventBuilderCmd = "eventBuilder";
     static final String refreshCmd = "eventRefresh";
     static final String exitCmd = "exit";
-    static final String logCmd = "logFile";
-    static final String terminalCmd = "logTerminal";
+    static final String logToFileCmd = "logToFile";
+    static final String logToTerminalCmd = "logToTerminal";
     static final String screenshotCmd = "screenshot";
     static final String eventRefreshCmd = "eventRefreshEdit";
     static final String updateTimeCmd = "updateTime";
     static final String setSteeringFileCmd = "setSteeringFile";
     static final String setMaxEventsCmd = "setMaxEvents";
-    static final String saveLogCmd = "saveLogRecords";
-    static final String clearLogCmd = "clearLogRecords";
+    static final String saveLogTableCmd = "saveLogTable";
+    static final String clearLogTableCmd = "clearLogTable";    
     static final String pauseCmd = "pause";
     static final String resumeCmd = "resume";
     static final String nextCmd = "next";
     static final String logLevelCmd = "logLevel";
+    static final String aidaAutoSaveCmd = "aidaAutoSave";
+    static final String saveJobSettingsCmd = "saveJobSettings";
+    static final String loadJobSettingsCmd = "loadJobSettings";
+    static final String resetJobSettingsCmd = "resetJobSettings";
 }
\ No newline at end of file
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1