Commit in hps-java/src/main/java/org/lcsim/hps/monitoring on MAIN
DefaultEtEventProcessor.java+11-51.1 -> 1.2
MonitoringApplication.java+873-5021.27 -> 1.28
MonitoringCommands.java+4-21.7 -> 1.8
+888-509
3 modified files

hps-java/src/main/java/org/lcsim/hps/monitoring
DefaultEtEventProcessor.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- DefaultEtEventProcessor.java	29 Apr 2012 18:11:26 -0000	1.1
+++ DefaultEtEventProcessor.java	29 Apr 2012 23:17:49 -0000	1.2
@@ -18,7 +18,7 @@
 /**
  * This class executes the default event processing chain for HPS Test Run monitoring: ET -> EVIO -> LCIO.
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: DefaultEtEventProcessor.java,v 1.1 2012/04/29 18:11:26 jeremy Exp $
+ * @version $Id: DefaultEtEventProcessor.java,v 1.2 2012/04/29 23:17:49 jeremy Exp $
  */
 public class DefaultEtEventProcessor implements EtEventProcessor
 {
@@ -33,7 +33,12 @@
     boolean stopProcessing;
     boolean stopOnError;
 
-    DefaultEtEventProcessor(EtConnection et, LCSimEventBuilder eventBuilder, JobControlManager jobManager, int maxEvents, boolean stopOnError) {
+    DefaultEtEventProcessor(
+            EtConnection et, 
+            LCSimEventBuilder eventBuilder, 
+            JobControlManager jobManager, 
+            int maxEvents, 
+            boolean stopOnError) {
         this.et = et;
         this.eventBuilder = eventBuilder;
         this.jobManager = jobManager;
@@ -125,7 +130,8 @@
         
         // Check if max events was reached or exceeded.
         if (maxEvents != -1 && eventsProcessed >= maxEvents) {
-            System.out.println("Reached max events " + eventsProcessed + " of " + maxEvents);
+            // TODO: log mesg that max events was reached
+            //System.out.println("Reached max events " + eventsProcessed + " of " + maxEvents);
             throw new MaxEventsException();
         }
 
@@ -201,7 +207,7 @@
         // Notify listeners of job start.
         begin();
         
-        // Loop until Exception is thrown that stops event processing.
+        // Loop until Exception is thrown that stops event processing or stop is requested.
         while (true) { 
 
             // Got a request to stop processing.
@@ -239,4 +245,4 @@
         // Notify listeners of job end.
         finish();
     }
-}
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringApplication.java 1.27 -> 1.28
diff -u -r1.27 -r1.28
--- MonitoringApplication.java	29 Apr 2012 18:11:26 -0000	1.27
+++ MonitoringApplication.java	29 Apr 2012 23:17:49 -0000	1.28
@@ -10,12 +10,18 @@
 import static org.lcsim.hps.monitoring.MonitoringCommands.resetDriversCmd;
 import static org.lcsim.hps.monitoring.MonitoringCommands.resetEventsCmd;
 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.terminalCmd;
-import static org.lcsim.hps.monitoring.MonitoringCommands.udpateTimeCmd;
+import static org.lcsim.hps.monitoring.MonitoringCommands.updateTimeCmd;
+import static org.lcsim.hps.monitoring.MonitoringCommands.clearLogCmd;
+import hep.aida.dev.IDevTree;
+import hep.aida.ref.remote.RemoteServer;
+import hep.aida.ref.remote.rmi.client.RmiStoreFactory;
+import hep.aida.ref.remote.rmi.server.RmiServerImpl;
 
 import java.awt.AWTException;
 import java.awt.Dimension;
@@ -28,12 +34,21 @@
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
 import java.awt.image.BufferedImage;
+import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.net.InetAddress;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Vector;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
 
 import javax.imageio.ImageIO;
 import javax.swing.JFileChooser;
@@ -43,9 +58,12 @@
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
+import javax.swing.JTable;
 import javax.swing.SwingUtilities;
 import javax.swing.Timer;
+import javax.swing.table.DefaultTableModel;
 
 import org.lcsim.hps.evio.LCSimEventBuilder;
 import org.lcsim.hps.evio.LCSimTestRunEventBuilder;
@@ -61,194 +79,314 @@
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class MonitoringApplication {
-    
+
+    // Top-level Swing components.
     private JPanel mainPanel;
     private JTabbedPane tabs;	
-	private ConnectionPanel connectionPanel;
-	private ConnectionStatusPanel connectionStatusPanel;
-	private EventPanel eventPanel;
-	private JobPanel jobPanel;			
-	private JMenuBar menuBar;	
-	private JMenuItem connectItem;
-	private JMenuItem disconnectItem;
-	private JMenuItem resetConnectionItem;
-	private JMenuItem connectionLoadItem;
-	private JMenuItem connectionSaveItem;
-	private JMenuItem exitItem;
-	private JMenuItem resetEventsItem;
-	private JMenuItem eventRefreshItem;
-	private JMenuItem savePlotsItem;
-	private JMenuItem resetDriversItem;
-	private JMenuItem logItem;
-	private JMenuItem terminalItem;
-	private JMenuItem screenshotItem;
-	private JMenuItem steeringItem;
-	private JMenuItem maxEventsItem;		
-	private final PrintStream sysOut = System.out;
-	private final PrintStream sysErr = System.err;
-	private ConnectionParameters connectionParameters;
-	private EtConnection connection;
-	private int connectionStatus = ConnectionStatus.DISCONNECTED;	
-	private JobControlManager jobManager;
-	private LCSimEventBuilder eventBuilder;
-	private MonitoringApplicationActionListener actionListener;
-	private Timer timer;
-	private long jobStartTime;
-    private static final String screenshotFormat = "png";
-    EtEventProcessor eventProcessor;
+    private ConnectionPanel connectionPanel;
+    private ConnectionStatusPanel connectionStatusPanel;
+    private EventPanel eventPanel;
+    private JobPanel jobPanel;			
+    private JMenuBar menuBar;	
     
-    MonitoringApplication() {
-        
-        // Create ActionEvent listener.
+    // References to menu items that will be enabled/disabled depending on application state.
+    private JMenuItem connectItem;
+    private JMenuItem disconnectItem;
+    private JMenuItem resetConnectionItem;
+    private JMenuItem connectionLoadItem;
+    private JMenuItem connectionSaveItem;
+    private JMenuItem savePlotsItem;
+    private JMenuItem resetDriversItem;
+    private JMenuItem logItem;
+    private JMenuItem terminalItem;
+    private JMenuItem steeringItem;
+
+    // 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;
+
+    // Job timing.
+    private Timer timer;
+    private long jobStartTime;
+
+    // ActionListener for GUI event dispatching.
+    private MonitoringApplicationActionListener actionListener;
+
+    // Logging objects.
+    private Logger logger;
+    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 static final String screenshotFormat = "png";
+
+    private MonitoringApplication() {
+
+        // Create the ActionEventListener for event dispatching.
         actionListener = new MonitoringApplicationActionListener(this);
-        
+
+        // Setup the application menus.
+        createMenu();
+
+        // Create the GUI panels.
+        createPanels();
+
+        // Create the log table GUI component.
+        createLogTable();
+
+        // Create and configure the logger.
+        setupLogger();
+
+        // Log that the application started successfully.
+        logger.log(Level.INFO, "Application initialized successfully.");
+    }
+
+    /**
+     * Creates all the JPanels for the application.
+     */
+    private void createPanels()
+    {
         // Main panel for the application.
         mainPanel = new JPanel();
+        //mainPanel.setPreferredSize(new Dimension(800, 750));
         mainPanel.setLayout(new GridBagLayout());
         
-        // Setup the menus.
-        createMenu();
-        
-        // Main panel.
+        // Connection status panel.
         GridBagConstraints c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 0;
         c.anchor = GridBagConstraints.NORTHWEST;
+        c.fill = GridBagConstraints.BOTH;
+        c.weightx = c.weighty = 1.0;
         connectionStatusPanel = new ConnectionStatusPanel();
         mainPanel.add(connectionStatusPanel, c);
-    
+
         // Sub-panels.
         connectionPanel = new ConnectionPanel();
         eventPanel = new EventPanel();
         jobPanel = new JobPanel();
-    
+
         // Tabs.
+        c = new GridBagConstraints();
+        c.fill = GridBagConstraints.BOTH;
+        c.weightx = c.weighty = 1.0;
         JPanel tabsPanel = new JPanel();
         tabs = new JTabbedPane();
         tabs.addTab("Connection", connectionPanel);
         tabs.addTab("Event Monitor", eventPanel);
         tabs.addTab("Job Settings", jobPanel);
-        tabsPanel.add(tabs);
-        
+        tabsPanel.add(tabs, c);
+
         // Add tabs to main panel.
         c = new GridBagConstraints();
         c.gridx = 0;
         c.gridy = 1;        
+        c.fill = GridBagConstraints.BOTH;
+        c.weightx = c.weighty = 1.0;
         mainPanel.add(tabsPanel, c);
     }
-    
+
     private void createMenu() {
-        
+
         menuBar = new JMenuBar();
-        
+
         JMenu connectionMenu = new JMenu("Connection");
         connectionMenu.setMnemonic(KeyEvent.VK_C);
         menuBar.add(connectionMenu);        
-        
+
         connectItem = new JMenuItem("Connect");
         connectItem.setMnemonic(KeyEvent.VK_C);
         connectItem.setActionCommand(connectCmd);
         connectItem.addActionListener(actionListener);
         connectionMenu.add(connectItem);
-        
+
         disconnectItem = new JMenuItem("Disconnect");
         disconnectItem.setMnemonic(KeyEvent.VK_D);
         disconnectItem.setActionCommand(disconnectCmd);
         disconnectItem.addActionListener(actionListener);
         disconnectItem.setEnabled(false);
         connectionMenu.add(disconnectItem);
-        
+
         resetConnectionItem = new JMenuItem("Reset Connection Settings");
         resetConnectionItem.setMnemonic(KeyEvent.VK_R);
         resetConnectionItem.setActionCommand(resetConnectionSettingsCmd);
         resetConnectionItem.addActionListener(actionListener);
         connectionMenu.add(resetConnectionItem);
-                
+
         connectionLoadItem = new JMenuItem("Load Connection...");
         connectionLoadItem.setMnemonic(KeyEvent.VK_L);
         connectionLoadItem.setActionCommand(loadConnectionCmd);
         connectionLoadItem.addActionListener(actionListener);
         connectionMenu.add(connectionLoadItem);
-        
+
         connectionSaveItem = new JMenuItem("Save Connection...");
         connectionSaveItem.setMnemonic(KeyEvent.VK_S);
         connectionSaveItem.setActionCommand(saveConnectionCmd);
         connectionSaveItem.addActionListener(actionListener);
         connectionMenu.add(connectionSaveItem);
-        
-        exitItem = new JMenuItem("Exit");
+
+        JMenuItem exitItem = new JMenuItem("Exit");
         exitItem.setMnemonic(KeyEvent.VK_X);
         exitItem.setActionCommand(exitCmd);
         exitItem.addActionListener(actionListener);
         connectionMenu.add(exitItem);
-        
+
         JMenu eventMenu = new JMenu("Event");
         eventMenu.setMnemonic(KeyEvent.VK_E);
         menuBar.add(eventMenu);
-        
-        resetEventsItem = new JMenuItem("Reset Event Monitor");
+
+        JMenuItem resetEventsItem = new JMenuItem("Reset Event Monitor");
         resetEventsItem.setMnemonic(KeyEvent.VK_E);
         resetEventsItem.setActionCommand(resetEventsCmd);
         resetEventsItem.addActionListener(actionListener);
         eventMenu.add(resetEventsItem);     
-        
-        eventRefreshItem = new JMenuItem("Set Event Refresh...");
+
+        JMenuItem eventRefreshItem = new JMenuItem("Set Event Refresh...");
         eventRefreshItem.setMnemonic(KeyEvent.VK_V);
         eventRefreshItem.setActionCommand(eventRefreshCmd);
         eventRefreshItem.addActionListener(actionListener);
         eventMenu.add(eventRefreshItem);        
-        
-        maxEventsItem = new JMenuItem("Set Max Events...");
+
+        JMenuItem maxEventsItem = new JMenuItem("Set Max Events...");
         maxEventsItem.setMnemonic(KeyEvent.VK_M);
         maxEventsItem.setActionCommand(setMaxEventsCmd);
         maxEventsItem.addActionListener(actionListener);
         eventMenu.add(maxEventsItem);
-        
+
         JMenu jobMenu = new JMenu("Job");
         jobMenu.setMnemonic(KeyEvent.VK_J);
         menuBar.add(jobMenu);
-        
+
         steeringItem = new JMenuItem("Set Steering File...");
-          steeringItem.setMnemonic(KeyEvent.VK_S);
+        steeringItem.setMnemonic(KeyEvent.VK_S);
         steeringItem.setActionCommand(setSteeringFileCmd);
         steeringItem.addActionListener(actionListener);
         jobMenu.add(steeringItem);
-        
+
         savePlotsItem = new JMenuItem("Save Plots to AIDA File...");
         savePlotsItem.setMnemonic(KeyEvent.VK_P);
         savePlotsItem.setActionCommand(savePlotsCmd);
         savePlotsItem.addActionListener(actionListener);
         savePlotsItem.setEnabled(false);
         jobMenu.add(savePlotsItem);     
-        
+
         resetDriversItem = new JMenuItem("Reset LCSim Drivers");
         resetDriversItem.setMnemonic(KeyEvent.VK_D);
         resetDriversItem.setActionCommand(resetDriversCmd);
         resetDriversItem.addActionListener(actionListener);
         resetDriversItem.setEnabled(false);
         jobMenu.add(resetDriversItem);
-        
-        logItem = new JMenuItem("Log to File...");
+
+        logItem = new JMenuItem("Redirect to File...");
         logItem.setMnemonic(KeyEvent.VK_F);
         logItem.setActionCommand(logCmd);
         logItem.addActionListener(actionListener);
         logItem.setEnabled(true);
         jobMenu.add(logItem);
-        
-        terminalItem = new JMenuItem("Log to Terminal");
+
+        terminalItem = new JMenuItem("Redirect to Terminal");
         terminalItem.setMnemonic(KeyEvent.VK_T);
         terminalItem.setActionCommand(terminalCmd);
         terminalItem.addActionListener(actionListener);
         terminalItem.setEnabled(false);
         jobMenu.add(terminalItem);
-        
-        screenshotItem = new JMenuItem("Take a screenshot...");
+
+        JMenuItem screenshotItem = new JMenuItem("Take a screenshot...");
         screenshotItem.setMnemonic(KeyEvent.VK_N);
         screenshotItem.setActionCommand(screenshotCmd);
         screenshotItem.addActionListener(actionListener);
         jobMenu.add(screenshotItem);
+
+        JMenu logMenu = new JMenu("Log");
+        jobMenu.setMnemonic(KeyEvent.VK_L);
+        menuBar.add(logMenu);
+
+        JMenuItem saveLogItem = new JMenuItem("Save log to file...");
+        saveLogItem.setMnemonic(KeyEvent.VK_S);
+        saveLogItem.setActionCommand(saveLogCmd);
+        saveLogItem.addActionListener(actionListener);
+        logMenu.add(saveLogItem);
+        
+        JMenuItem clearLogItem = new JMenuItem("Clear log");
+        clearLogItem.setMnemonic(KeyEvent.VK_C);
+        clearLogItem.setActionCommand(clearLogCmd);
+        clearLogItem.addActionListener(actionListener);
+        logMenu.add(clearLogItem);
     }
-    
+
+    /**
+     * Log handler for inserting messages into the log table.
+     */
+    private class MonitoringApplicationLogHandler extends Handler {
+
+        final SimpleDateFormat dateFormat = new SimpleDateFormat("MMM 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
+            logTableModel.insertRow(logTable.getRowCount(), row);
+        }
+
+        public void close() throws SecurityException
+        {}
+
+        public void flush()
+        {}        
+    }
+
+    /**
+     * 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"};
+
+        String data[][] = new String[0][0];
+        logTableModel = new DefaultTableModel(data, logTableColumns);
+        logTable = new JTable(logTableModel);
+        logTable.setEnabled(false);
+
+        GridBagConstraints c = new GridBagConstraints();
+        c.gridx = 0;
+        c.gridy = 2;
+        c.fill = GridBagConstraints.BOTH;
+        c.weightx = c.weighty = 1.0;
+        JScrollPane logPane = new JScrollPane(logTable);
+        logPane.setPreferredSize(new Dimension(maxWidth, logHeight));
+        mainPanel.add(logPane, c);
+    }
+
+    private void setupLogger() {
+        this.logger = Logger.getLogger(this.getClass().getSimpleName());
+        logger.setUseParentHandlers(false);
+        logger.addHandler(new MonitoringApplicationLogHandler());
+        logger.setLevel(Level.FINEST);
+    }
+
+    /**
+     * 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() {
@@ -258,9 +396,9 @@
         });
         return app;
     }
-    
+
     /**
-     * Run the monitoring application.
+     * Run the monitoring application from the command line.
      * @param args The command line arguments.
      */
     public static void main(String[] args)
@@ -268,7 +406,7 @@
         final String defaultDetectorName;
         final String defaultSteering;
         final String defaultEventBuilder;
-        
+
         if (args.length == 0) {
             defaultDetectorName = "HPS-Test-JLAB-v4pt0";
             defaultSteering = "/org/lcsim/hps/steering/TestRunMonitoring.lcsim";
@@ -283,23 +421,26 @@
             defaultSteering = args[1];
             defaultEventBuilder = args[2];
         }
-               
+
         // Create the main app class.
         MonitoringApplication app = MonitoringApplication.createMonitoringApplication();
-               
+
         // Set job parameters.
         app.setJobParameters(new JobParameters(new String[] {defaultDetectorName, defaultSteering, defaultEventBuilder}));
-        
+
         // Run the app.
         app.run();
     }
-    
+
+    /**
+     * Runs the application loop.
+     */
     private void run() {
         // GUI outer loop.  
         while (true) {  
             try {                
-                // Start job with current parameters.
-                runJob();
+                // Execute a monitoring session.
+                startSession();
             }
             // Top-level exception catcher.
             catch (Exception e) {
@@ -309,95 +450,109 @@
             }
         }      
     }
-    
-	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.");
-    	    }
-    	    this.detectorName = params[0];
-    	    this.steeringResource = params[1];
-    	    this.eventBuilderClassName = params[2];
-    	}
-	}
-	
-	/**
-	 * The ActionListener implementation for the MonitoringApplication class.
-	 * @author Jeremy McCormick <[log in to unmask]>
-	 */
-	private static final class MonitoringApplicationActionListener implements ActionListener {
-	    
-	    MonitoringApplication app;
-	    
-	    MonitoringApplicationActionListener(MonitoringApplication app) {
-	        this.app = app;
-	    }
-	    
-	    public void actionPerformed(ActionEvent e) {
-	        String cmd = e.getActionCommand();
-	        if (connectCmd.equals(cmd)) {
-	            app.requestConnection();
-	        } 
-	        else if (disconnectCmd.equals(cmd)) {
-	            app.eventProcessor.stop();
-	            app.disconnect(ConnectionStatus.DISCONNECTING);
-	        } 
-	        else if (eventRefreshCmd.equals(cmd)) {
-	            app.setEventRefresh();
-	        }
-	        else if (savePlotsCmd.equals(cmd)) {
-	            app.savePlots();
-	        } 
-	        else if (resetDriversCmd.equals(cmd)) {
-	            app.resetDrivers();
-	        } 
-	        else if (logCmd.equals(cmd)) {
-	            app.logToFile();
-	        } 
-	        else if (terminalCmd.equals(cmd)) {
-	            app.logToTerminal();
-	        }
-	        else if (screenshotCmd.equals(cmd)) {
-	            app.screenshot();
-	        }
-	        else if (exitCmd.equals(cmd)) {
-	            app.exit();
-	        }
-	        else if (udpateTimeCmd.equals(cmd)) {
-	            app.updateTime();
-	        }
-	        else if (resetEventsCmd.equals(cmd)) {
-	            app.resetJob();
-	        } 
-	        else if (saveConnectionCmd.equals(e.getActionCommand())) {
-	            app.connectionPanel.save();
-	        } 
-	        else if (loadConnectionCmd.equals(e.getActionCommand())) {
-	            app.connectionPanel.load();
-	        } 
-	        else if (resetConnectionSettingsCmd.equals(e.getActionCommand())) {
-	            app.connectionPanel.reset();
-	        }
-	        else if (setSteeringFileCmd.equals(e.getActionCommand())) {
-	            app.selectSteeringFile();
-	        } 
-	        else if (setMaxEventsCmd.equals(e.getActionCommand())) {
-	            app.setMaxEvents();
-	        }
-	    } 
-	}
-	
+
+    /**
+     * 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.");
+            }
+            this.detectorName = params[0];
+            this.steeringResource = params[1];
+            this.eventBuilderClassName = params[2];
+        }
+    }
+
+    /**
+     * The ActionListener implementation for handling all GUI events.
+     */
+    private static final class MonitoringApplicationActionListener implements ActionListener {
+
+        MonitoringApplication app;
+
+        MonitoringApplicationActionListener(MonitoringApplication app) {
+            this.app = app;
+        }
+
+        public void actionPerformed(ActionEvent e) {
+            String cmd = e.getActionCommand();
+            if (connectCmd.equals(cmd)) {
+                app.requestConnection();
+            } 
+            else if (disconnectCmd.equals(cmd)) {
+                app.eventProcessor.stop();
+                app.disconnect(ConnectionStatus.DISCONNECTING);
+            } 
+            else if (eventRefreshCmd.equals(cmd)) {
+                app.setEventRefresh();
+            }
+            else if (savePlotsCmd.equals(cmd)) {
+                app.savePlots();
+            } 
+            else if (resetDriversCmd.equals(cmd)) {
+                app.resetDrivers();
+            } 
+            else if (logCmd.equals(cmd)) {
+                app.logToFile();
+            } 
+            else if (terminalCmd.equals(cmd)) {
+                app.logToTerminal();
+            }
+            else if (screenshotCmd.equals(cmd)) {
+                app.screenshot();
+            }
+            else if (exitCmd.equals(cmd)) {
+                app.exit();
+            }
+            else if (updateTimeCmd.equals(cmd)) {
+                app.updateTime();
+            }
+            else if (resetEventsCmd.equals(cmd)) {
+                app.resetJob();
+            } 
+            else if (saveConnectionCmd.equals(cmd)) {
+                app.connectionPanel.save();
+            } 
+            else if (loadConnectionCmd.equals(cmd)) {
+                app.connectionPanel.load();
+            } 
+            else if (resetConnectionSettingsCmd.equals(cmd)) {
+                app.connectionPanel.reset();
+            }
+            else if (setSteeringFileCmd.equals(cmd)) {
+                app.selectSteeringFile();
+            } 
+            else if (setMaxEventsCmd.equals(cmd)) {
+                app.setMaxEvents();
+            }
+            else if (saveLogCmd.equals(cmd)) {
+                app.saveLogToFile();
+            }
+            else if (clearLogCmd.equals(cmd)) {
+                app.clearLog();
+            }
+        } 
+    }
+
+    /**
+     * The listener for hooking into the event processor.
+     */
     private static final class MonitoringApplicationEtListener implements EtEventProcessor.EtEventListener {
 
         MonitoringApplication app;
-        
+
         MonitoringApplicationEtListener(MonitoringApplication app) {
             this.app = app;
         }
-        
+
         public void begin() {
             // Reset event GUI.
             app.eventPanel.reset();
@@ -408,7 +563,7 @@
             // Start the job timer.
             app.startTimer();
         }
-        
+
         public void startOfEvent() {
             app.eventPanel.updateEventCount();
         }
@@ -426,11 +581,11 @@
                 // Call cleanup methods of Drivers.
                 if (app.jobManager != null)
                     app.jobManager.finish();
-                
+
                 // Stop the job timer.
                 app.timer.stop();
                 app.timer = null;
-                
+
                 // Push final event counts to GUI.
                 app.eventPanel.endJob();
             }
@@ -439,53 +594,79 @@
             }
         }
     }
-    
 
-	
-	private void setJobParameters(JobParameters p) {		
-    	jobPanel.setDetectorName(p.detectorName);
-    	jobPanel.setSteeringResource(p.steeringResource);
-    	jobPanel.setDefaultEventBuilder(p.eventBuilderClassName);
-	}
-	
-	private void requestConnection() {
+    /**
+     * 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);
+    }
+
+    /**
+     * Request a connection to the ET system.
+     */
+    private void requestConnection() {
         setConnectionStatus(ConnectionStatus.CONNECTION_REQUESTED);
-	}
-	
-	private void setConnectionStatus(int status) {
-	    connectionStatus = status;
-	    connectionStatusPanel.setStatus(status);
-	}
-
-	private int getConnectionStatus() {
-	    return connectionStatus;
-	}
-	    
-	private boolean connectionRequested() {
-	    return connectionStatus == ConnectionStatus.CONNECTION_REQUESTED;
-	}            
-		
-	private void showDialog(String m) {
-		JOptionPane.showMessageDialog(mainPanel, m);
-	}
-	
-	/**
-	 * Sets up the frame to run the application.  
-	 * This should be called using Runnable.run() (see MonitoringExample).
-	 */
-	private void createApplicationFrame() {
-	    mainPanel.setOpaque(true);
-	    
+    }
+
+    /**
+     * Set the connection status.
+     * @param status The connection status.
+     */
+    private void setConnectionStatus(int status) {
+        connectionStatus = status;
+        connectionStatusPanel.setStatus(status);
+        logger.log(Level.FINE, "Connection status changed to " + ConnectionStatus.toString(status) + ".");
+    }
+
+    /**
+     * Get the current connection status.
+     * @return The connection status.
+     */
+    private int getConnectionStatus() {
+        return connectionStatus;
+    }
+
+    /**
+     * 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.
+     */
+    private void showDialog(String m) {
+        JOptionPane.showMessageDialog(mainPanel, m);
+    }
+
+    /**
+     * Sets up the frame to run the application.  
+     * This should be called using Runnable.run() (see MonitoringExample).
+     */
+    private void createApplicationFrame() {
+        mainPanel.setOpaque(true);
+
         JFrame frame = new JFrame(getApplicationTitle());
         frame.setContentPane(mainPanel);
         frame.setJMenuBar(menuBar);
         frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+        frame.setMinimumSize(new Dimension(800,400));
         frame.setResizable(false);
         frame.pack();
         frame.setVisible(true);
     }
-						
-	private void savePlots() {
+
+    /**
+     * Save plots to a selected output file.
+     */
+    private void savePlots() {
         JFileChooser fc = new JFileChooser();
         int r = fc.showSaveDialog(mainPanel);
         if (r == JFileChooser.APPROVE_OPTION) {
@@ -497,95 +678,126 @@
             }
         }
     }
-	
-	private void selectSteeringFile() {
-	    JFileChooser fc = new JFileChooser();
-	    int r = fc.showOpenDialog(mainPanel);
-	    if (r == JFileChooser.APPROVE_OPTION) {
-	        File fileName = fc.getSelectedFile();
-	        try {
-	            (new JobControlManager()).setup(fileName);
-	            jobPanel.setSteeringFile(fileName.getPath());
-	        }
-	        catch (Exception e) {
-	            e.printStackTrace();
-	            showDialog("Failed to read the LCSim XML file.");
-	        }	       
-	    }
-	}
-	
-	private static String getApplicationTitle() {
-	    return "HPS Monitoring - " + getUserName() + "@"+ getHostname();
-	}
-	
-	private static String getHostname() {
-	    try {
-	        return InetAddress.getLocalHost().getHostName();
-	    }
-	    catch (Exception e) {
-	        return "UNKNOWN_HOST";
-	    }
-	}
-	
-	private static String getUserName() {
-	    if (System.getProperty("user.name") == null) {
-	        return "UNKNOWN_USER";
-	    } 
-	    else {
-	        return System.getProperty("user.name");
-	    }
-	}
-
-	private synchronized void resetDrivers() {
-		if (jobManager != null) {
-			for (Driver driver : jobManager.getDriverExecList()) {
-				if (driver instanceof Resettable) {
-					try {
-						((Resettable) driver).reset();
-					} catch (Exception e) {
-						e.printStackTrace();
-					}
-				} 
-			}
-		}
-	 }
-	
-	private void logToFile() {
-		JFileChooser fc = new JFileChooser();
-		fc.setDialogTitle("Log File");
-		int fcs = fc.showSaveDialog(this.mainPanel);
-		if (fcs == JFileChooser.APPROVE_OPTION) {
-			final File logFile = fc.getSelectedFile();
-			if (logFile.exists()) {
-				JOptionPane.showMessageDialog(this.mainPanel, "Log file already exists.");
-			} else {			
-				try {
-					if (!logFile.createNewFile()) throw new IOException();
-					PrintStream ps = new PrintStream(new FileOutputStream(logFile.getPath()));
-					System.setOut(ps);
-					System.setErr(ps);				
-					
-					jobPanel.logFileField.setText(logFile.getPath());
+
+    /**
+     * Select an LCSim steering file from disk.
+     */
+    private void selectSteeringFile() {
+        JFileChooser fc = new JFileChooser();
+        int r = fc.showOpenDialog(mainPanel);
+        if (r == JFileChooser.APPROVE_OPTION) {
+            File fileName = fc.getSelectedFile();
+            try {
+                (new JobControlManager()).setup(fileName);
+                jobPanel.setSteeringFile(fileName.getPath());
+            }
+            catch (Exception e) {
+                e.printStackTrace();
+                showDialog("Failed to read the LCSim XML file.");
+            }	       
+        }
+    }
+
+    /**
+     * Get the full title of the application.
+     * @return The application title.
+     */
+    private static String getApplicationTitle() {
+        return "HPS Monitoring - " + getUserName() + "@"+ getHostname();
+    }
+
+    /**
+     * Get the hostname.
+     * @return The hostname.
+     */
+    private static String getHostname() {
+        try {
+            return InetAddress.getLocalHost().getHostName();
+        }
+        catch (Exception e) {
+            return "UNKNOWN_HOST";
+        }
+    }
+
+    /**
+     * Get the user name.
+     * @return The user name.
+     */
+    private static String getUserName() {
+        if (System.getProperty("user.name") == null) {
+            return "UNKNOWN_USER";
+        } 
+        else {
+            return System.getProperty("user.name");
+        }
+    }
+
+    /**
+     * Call the reset() method on Drivers which support this.
+     * They must implement the {@link Resettable} interface for this to work.
+     */
+    private synchronized void resetDrivers() {
+        if (jobManager != null) {
+            for (Driver driver : jobManager.getDriverExecList()) {
+                if (driver instanceof Resettable) {
+                    try {
+                        ((Resettable) driver).reset();
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                } 
+            }
+        }
+    }
+
+    /**
+     * 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();
+        fc.setDialogTitle("Log File");
+        int fcs = fc.showSaveDialog(this.mainPanel);
+        if (fcs == JFileChooser.APPROVE_OPTION) {
+            final File logFile = fc.getSelectedFile();
+            if (logFile.exists()) {
+                JOptionPane.showMessageDialog(this.mainPanel, "Log file already exists.");
+            } else {			
+                try {
+                    if (!logFile.createNewFile()) throw new IOException();
+                    PrintStream ps = new PrintStream(new FileOutputStream(logFile.getPath()));
+                    System.setOut(ps);
+                    System.setErr(ps);				
+
+                    jobPanel.logFileField.setText(logFile.getPath());
[truncated at 1000 lines; 707 more skipped]

hps-java/src/main/java/org/lcsim/hps/monitoring
MonitoringCommands.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- MonitoringCommands.java	19 Apr 2012 23:01:28 -0000	1.7
+++ MonitoringCommands.java	29 Apr 2012 23:17:49 -0000	1.8
@@ -23,7 +23,9 @@
 	static final String terminalCmd = "logTerminal";
 	static final String screenshotCmd = "screenshot";
 	static final String eventRefreshCmd = "eventRefreshEdit";
-	static final String udpateTimeCmd = "updateTime";
+	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";
+}
\ 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