Print

Print


Author: [log in to unmask]
Date: Mon Mar 30 11:59:38 2015
New Revision: 2627

Log:
Merge in changes from trunk.

Modified:
    java/branches/monitoring-app-dev/   (props changed)
    java/branches/monitoring-app-dev/pom.xml
    java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/EventProcessing.java
    java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/LogTable.java
    java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MenuBar.java
    java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MonitoringApplication.java
    java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MonitoringApplicationFrame.java
    java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/PlotInfoPanel.java

Modified: java/branches/monitoring-app-dev/pom.xml
 =============================================================================
--- java/branches/monitoring-app-dev/pom.xml	(original)
+++ java/branches/monitoring-app-dev/pom.xml	Mon Mar 30 11:59:38 2015
@@ -140,7 +140,7 @@
             <version>3.4.11</version>
             <exclusions>
                 <exclusion>
-                    <groupId>org.jdom</groupId>
+                    <groupId>jdom</groupId>
                     <artifactId>jdom</artifactId>
                 </exclusion>
                 <exclusion>
@@ -150,4 +150,4 @@
             </exclusions>
         </dependency>
     </dependencies>
-</project>
+</project>

Modified: java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/EventProcessing.java
 =============================================================================
--- java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/EventProcessing.java	(original)
+++ java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/EventProcessing.java	Mon Mar 30 11:59:38 2015
@@ -135,12 +135,10 @@
         MonitoringApplication.logger.config("set steering " + steering + " with type " + (steeringType == SteeringType.RESOURCE ? "RESOURCE" : "FILE"));
 
         try {
-            // Create and the job manager. The conditions manager is instantiated from this call but
-            // not configured.
+            // Create the job manager. A new conditions manager is instantiated from this call but not configured.
             sessionState.jobManager = new JobManager();
 
-            // Add conditions listeners after new database conditions manager is initialized from
-            // job manager.
+            // Add conditions listeners after new database conditions manager is initialized from the job manager.
             DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
             for (ConditionsListener conditionsListener : sessionState.conditionsListeners) {
                 logger.config("adding conditions listener " + conditionsListener.getClass().getName());
@@ -206,7 +204,7 @@
 
         try {
             // Create a new instance of the builder class.
-            sessionState.eventBuilder = (LCSimEventBuilder) Class.forName(eventBuilderClassName).newInstance();
+            sessionState.eventBuilder = (LCSimEventBuilder) Class.forName(eventBuilderClassName, true, Thread.currentThread().getContextClassLoader()).newInstance();
         } catch (Exception e) {
             throw new RuntimeException("Failed to create LCSimEventBuilder.", e);
         }
@@ -502,13 +500,13 @@
                 createEtConnection();
 
                 // Add an attachment that listens for DAQ configuration changes via physics SYNC events.
-                createSyncStation();
+                //createSyncStation();
                 
                 // Add an attachment which listens for EPICs events with scalar data.
                 //createEpicsStation();
                 
                 // Add an attachment that listens for PRESTART events.
-                createPreStartStation();
+                //createPreStartStation();
                 
             } catch (Exception e) {
                 throw new IOException(e);

Modified: java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/LogTable.java
 =============================================================================
--- java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/LogTable.java	(original)
+++ java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/LogTable.java	Mon Mar 30 11:59:38 2015
@@ -38,8 +38,12 @@
         setModel(model);
         sorter = new TableRowSorter<LogRecordModel>(model);
         sorter.setRowFilter(new LevelFilter());
-        this.getColumnModel().getColumn(0).setCellRenderer(new DateRenderer());
+        getColumnModel().getColumn(0).setCellRenderer(new DateRenderer());        
         setRowSorter(sorter);
+        getColumnModel().getColumn(0).setPreferredWidth(142);
+        getColumnModel().getColumn(0).setMaxWidth(142);
+        getColumnModel().getColumn(1).setPreferredWidth(60);
+        getColumnModel().getColumn(1).setMaxWidth(60);
         setEnabled(false);
     }
         
@@ -105,7 +109,7 @@
             case 0:
                 return Date.class;
             case 1:
-                return String.class;
+                return Level.class;
             case 2:
                 return String.class;
             default:

Modified: java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MenuBar.java
 =============================================================================
--- java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MenuBar.java	(original)
+++ java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MenuBar.java	Mon Mar 30 11:59:38 2015
@@ -98,12 +98,12 @@
         plotsMenu.setMnemonic(KeyEvent.VK_P);
         add(plotsMenu);
         
-        JMenuItem savePlotsItem = new JMenuItem("Save Plots ...");
+        JMenuItem savePlotsItem = new JMenuItem("Save plots ...");
         savePlotsItem.setMnemonic(KeyEvent.VK_S);
         savePlotsItem.setActionCommand(Commands.SAVE_PLOTS);
         savePlotsItem.addActionListener(listener);
         savePlotsItem.setEnabled(true);
-        savePlotsItem.setToolTipText("Save plots to AIDA file");
+        savePlotsItem.setToolTipText("Save all plots to a file");
         plotsMenu.add(savePlotsItem);
 
         JMenuItem clearPlotsItem = new JMenuItem("Clear plots");

Modified: java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MonitoringApplication.java
 =============================================================================
--- java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MonitoringApplication.java	(original)
+++ java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MonitoringApplication.java	Mon Mar 30 11:59:38 2015
@@ -48,6 +48,7 @@
 import org.hps.monitoring.application.util.TableExporter;
 import org.hps.monitoring.plotting.MonitoringAnalysisFactory;
 import org.hps.monitoring.plotting.MonitoringPlotFactory;
+import org.hps.monitoring.plotting.ExportPdf;
 import org.hps.monitoring.subsys.SystemStatus;
 import org.hps.monitoring.subsys.SystemStatusRegistry;
 import org.hps.record.composite.CompositeRecordProcessor;
@@ -55,6 +56,7 @@
 import org.lcsim.conditions.ConditionsListener;
 import org.lcsim.util.Driver;
 import org.lcsim.util.aida.AIDA;
+import org.lcsim.util.aida.PDFWriter;
 import org.lcsim.util.log.DefaultLogFormatter;
 
 /**
@@ -151,9 +153,9 @@
                  
     /**
      * Instantiate and show the monitoring application with the given configuration.
-     * @param configuration The Configuration object containing application settings.
-     */
-    MonitoringApplication(Configuration configuration) {
+     * @param userConfiguration The Configuration object containing application settings.
+     */
+    MonitoringApplication(Configuration userConfiguration) {
         
         try {
         
@@ -205,14 +207,15 @@
             // Setup AIDA plotting and connect it to the GUI.
             setupAida();
         
+            // TODO: Make sure the configuration loading here is working properly!!!
+            
             // Always load the default configuration first.
             this.configuration = new Configuration(DEFAULT_CONFIGURATION);
             loadConfiguration(this.configuration);
             
             // Overlay the user configuration if one was specified.
-            if (configuration != null) {
-                this.configuration = configuration;
-                loadConfiguration(this.configuration);
+            if (userConfiguration != null) {
+                loadConfiguration(userConfiguration);
             }
         
             // Enable the GUI now that initialization is complete.
@@ -271,7 +274,7 @@
      */
     public void actionPerformed(ActionEvent e) {
 
-        logger.finest("actionPerformed - " + e.getActionCommand());
+        //logger.finest("actionPerformed - " + e.getActionCommand());
         
         String command = e.getActionCommand();
         if (Commands.CONNECT.equals(command)) {
@@ -356,15 +359,17 @@
      */
     void loadConfiguration(Configuration configuration) {
         
+        this.configuration = configuration;
+        
         // HACK: Clear data source combo box for new config.
         frame.dataSourceComboBox.removeAllItems();
         
         // Set the Configuration on the ConfigurationModel which will trigger all the PropertyChangelListeners.
-        configurationModel.setConfiguration(configuration);
-        if (configuration.getFile() != null)
-            logger.config("loaded config from file " + configuration.getFile().getPath());
+        configurationModel.setConfiguration(this.configuration);
+        if (this.configuration.getFile() != null)
+            logger.config("loaded config from file " + this.configuration.getFile().getPath());
         else
-            logger.config("loaded config from resource " + configuration.getResourcePath());
+            logger.config("loaded config from resource " + this.configuration.getResourcePath());
     }
               
     /**
@@ -479,19 +484,41 @@
     }
             
     /**
-     * Save AIDA plots to a file using a file chooser.
+     * Save plots to an AIDA, ROOT or PDF file using a file chooser.
      */
     void savePlots() {
         JFileChooser fc = new JFileChooser();
+        fc.addChoosableFileFilter(new FileNameExtensionFilter("ROOT file", "root"));
+        FileFilter filter = new FileNameExtensionFilter("AIDA file", "aida");
+        fc.addChoosableFileFilter(filter);
+        fc.addChoosableFileFilter(new FileNameExtensionFilter("PDF file", "pdf"));
+        fc.setAcceptAllFileFilterUsed(false);
+        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
+        fc.setFileFilter(filter);
         int r = fc.showSaveDialog(frame);
         if (r == JFileChooser.APPROVE_OPTION) {
-            File fileName = fc.getSelectedFile();
-            try {
-                AIDA.defaultInstance().saveAs(fileName);
-                logger.info("saved plots to " + fileName);
-                DialogUtil.showInfoDialog(frame, "Plots Saved",  "Plots were successfully saved to AIDA file.");
-            } catch (IOException e) {
-                errorHandler.setError(e).setMessage("Error Saving Plots").printStackTrace().log().showErrorDialog();
+            File selectedFile = fc.getSelectedFile();
+            if (!selectedFile.exists()) {
+                String fileName = fc.getSelectedFile().getAbsolutePath();
+                String extension = ((FileNameExtensionFilter) fc.getFileFilter()).getExtensions()[0];
+                if (!fileName.endsWith(".aida") && !fileName.endsWith(".root") && !fileName.endsWith(".pdf")) {
+                    fileName += "." + extension;
+                }
+                try {
+                    if (extension.equals("pdf")) {
+                        // Write to a single PDF file.
+                        ExportPdf.write(MonitoringPlotFactory.getPlotterRegistry().getPlotters(), fileName);
+                    } else {
+                        // Save plot object data to AIDA or ROOT file.
+                        AIDA.defaultInstance().saveAs(fileName);
+                    }
+                    logger.info("saved plots to " + fileName);
+                    DialogUtil.showInfoDialog(frame, "Plots Saved", "Plots were successfully saved to " + '\n' + fileName);
+                } catch (IOException e) {
+                    errorHandler.setError(e).setMessage("Error Saving Plots").printStackTrace().log().showErrorDialog();
+                }
+            } else {
+                DialogUtil.showErrorDialog(frame, "File Exists", "Selected file already exists.");
             }
         }
     }
@@ -586,8 +613,7 @@
         int r = fc.showDialog(frame, "Load ...");
         if (r == JFileChooser.APPROVE_OPTION) {
             File f = fc.getSelectedFile();
-            configuration = new Configuration(f);
-            loadConfiguration(configuration);
+            loadConfiguration(new Configuration(f));
             logger.info("loaded configuration from file: " + f.getPath());
             DialogUtil.showInfoDialog(frame, "Settings Loaded", "Settings were loaded successfully.");
         }
@@ -630,7 +656,6 @@
     /**
      * Save a screenshot to a file using a file chooser.
      */
-    // FIXME: This might need to be on a new thread to allow the GUI to redraw w/o chooser visible.
     void saveScreenshot() {
         JFileChooser fc = new JFileChooser();
         fc.setAcceptAllFileFilterUsed(false);

Modified: java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MonitoringApplicationFrame.java
 =============================================================================
--- java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MonitoringApplicationFrame.java	(original)
+++ java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/MonitoringApplicationFrame.java	Mon Mar 30 11:59:38 2015
@@ -135,12 +135,12 @@
         
         // Create the right panel vertical split pane for displaying plots and their information and statistics.
         rightSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, plotPanel, plotInfoPanel);
-        rightSplitPane.setResizeWeight(0.7);
+        rightSplitPane.setDividerLocation(680);
         rightPanel.add(rightSplitPane, BorderLayout.CENTER);
                        
         // Create the main horizontal split pane for dividing the left and right panels.
         mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
-        mainSplitPane.setDividerLocation((int) (PIXEL_WIDTH_MAX  * 0.4));
+        mainSplitPane.setDividerLocation(600);
         bottomPanel.add(mainSplitPane, BorderLayout.CENTER);
         
         // Create the menu bar.

Modified: java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/PlotInfoPanel.java
 =============================================================================
--- java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/PlotInfoPanel.java	(original)
+++ java/branches/monitoring-app-dev/src/main/java/org/hps/monitoring/application/PlotInfoPanel.java	Mon Mar 30 11:59:38 2015
@@ -15,7 +15,6 @@
 import hep.aida.ref.function.FunctionDispatcher;
 import hep.aida.ref.function.FunctionListener;
 
-import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
@@ -26,7 +25,7 @@
 import java.util.Timer;
 import java.util.TimerTask;
 
-import javax.swing.BorderFactory;
+import javax.swing.Box;
 import javax.swing.BoxLayout;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
@@ -53,11 +52,11 @@
     
     PlotterRegion currentRegion;
     Object currentObject;
-    static final int INSET_SIZE = 5;
-    static final int BORDER_SIZE = 10;
-
+    
+    static final int MAX_ROWS = 13;
+    static final int MIN_WIDTH = 400;
+    static final int MIN_HEIGHT = 300;
     static final String[] COLUMN_NAMES = { "Field", "Value" };
-
     static final String PLOT_SELECTED = "PlotSelected";
 
     Timer timer = new Timer();
@@ -68,20 +67,32 @@
     @SuppressWarnings("unchecked")
     PlotInfoPanel() {
                 
-        setLayout(new FlowLayout(FlowLayout.LEFT));
+        setLayout(new FlowLayout(FlowLayout.CENTER));
 
         JPanel leftPanel = new JPanel();
         leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
-           
-        JPanel buttonPanel = new JPanel();
+        leftPanel.setPreferredSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
+        
+        Dimension filler = new Dimension(0, 10);
+        
+        // Save button.
         saveButton = new JButton("Save Plots ...");
         saveButton.setActionCommand(Commands.SAVE_SELECTED_PLOTS);
-        buttonPanel.add(saveButton);       
-        //c.anchor = GridBagConstraints.NORTHWEST;
-        leftPanel.add(buttonPanel);
-
-        plotComboBox = new JComboBox<Object>();
+        saveButton.setAlignmentX(CENTER_ALIGNMENT);
+        leftPanel.add(saveButton);
+        
+        leftPanel.add(new Box.Filler(filler, filler, filler));
+
+        // Combo box for selecting plotted object.
+        plotComboBox = new JComboBox<Object>() {
+            public Dimension getMaximumSize() {
+                Dimension max = super.getMaximumSize();
+                max.height = getPreferredSize().height;
+                return max;
+            }
+        };
         plotComboBox.setActionCommand(PLOT_SELECTED);
+        plotComboBox.setAlignmentX(CENTER_ALIGNMENT);
         plotComboBox.setRenderer(new BasicComboBoxRenderer() {
             @SuppressWarnings("rawtypes")
             public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
@@ -98,12 +109,15 @@
         plotComboBox.addActionListener(this);
         leftPanel.add(plotComboBox);
         
+        leftPanel.add(new Box.Filler(filler, filler, filler));
+        
+        // Table with plot info.
         String data[][] = new String[0][0];
         model = new DefaultTableModel(data, COLUMN_NAMES);
+        model.setColumnIdentifiers(COLUMN_NAMES);
         infoTable.setModel(model);
-        infoTable.getColumn("Field").setMinWidth(25);
-        infoTable.getColumn("Value").setMinWidth(20);
-        infoTable.setMinimumSize(new Dimension(100, 200));
+        ((DefaultTableModel)infoTable.getModel()).setRowCount(MAX_ROWS);
+        infoTable.setAlignmentX(CENTER_ALIGNMENT);
         leftPanel.add(infoTable);
         
         add(leftPanel);
@@ -185,8 +199,6 @@
     synchronized void setCurrentRegion(PlotterRegion region) {
         if (region != currentRegion) {
             currentRegion = region;
-            //if (currentRegion.title() != null)
-            //    setTitle(currentRegion.title());
             updateComboBox();
             setCurrentObject(plotComboBox.getSelectedItem());
             setupContentPane();
@@ -206,8 +218,7 @@
      * Update the info table from the state of the current AIDA object.
      */
     void updateTable() {
-        model.setRowCount(0);
-        model.setColumnIdentifiers(COLUMN_NAMES);
+        model.setRowCount(0);        
         if (currentObject instanceof IHistogram1D) {
             addRows((IHistogram1D) currentObject);
         } else if (currentObject instanceof IHistogram2D) {