LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  April 2015

HPS-SVN April 2015

Subject:

r2649 - in /java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application: PlotInfoPanel.java PlotPanel.java model/RunModel.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Wed, 1 Apr 2015 20:27:11 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (232 lines)

Author: [log in to unmask]
Date: Wed Apr  1 13:27:06 2015
New Revision: 2649

Log:
Fix saving plot tab to file.  HPSJAVA-479

Modified:
    java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/PlotInfoPanel.java
    java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/PlotPanel.java
    java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/model/RunModel.java

Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/PlotInfoPanel.java
 =============================================================================
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/PlotInfoPanel.java	(original)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/PlotInfoPanel.java	Wed Apr  1 13:27:06 2015
@@ -76,7 +76,7 @@
         Dimension filler = new Dimension(0, 10);
         
         // Save button.
-        saveButton = new JButton("Save Plots ...");
+        saveButton = new JButton("Save Current Plot Tab ...");
         saveButton.setActionCommand(Commands.SAVE_SELECTED_PLOTS);
         saveButton.setAlignmentX(CENTER_ALIGNMENT);
         leftPanel.add(saveButton);

Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/PlotPanel.java
 =============================================================================
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/PlotPanel.java	(original)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/PlotPanel.java	Wed Apr  1 13:27:06 2015
@@ -1,19 +1,24 @@
 package org.hps.monitoring.application;
 
 import hep.aida.IPlotter;
+import hep.aida.jfree.plotter.Plotter;
 
 import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 
+import javax.imageio.ImageIO;
 import javax.swing.JFileChooser;
 import javax.swing.JPanel;
 import javax.swing.JTabbedPane;
+import javax.swing.filechooser.FileNameExtensionFilter;
 
 import org.hps.monitoring.application.util.DialogUtil;
+import org.hps.monitoring.plotting.ExportPdf;
 import org.hps.monitoring.plotting.MonitoringPlotFactory;
 
 /**
@@ -39,7 +44,7 @@
      * Get the indices of the current selected tabs.
      * @return The indices of the current tabs.
      */
-    int[] getSelectedTabs() {
+    int[] getSelectedTabIndices() {
         int[] indices = new int[2];
         indices[0] = plotPane.getSelectedIndex();
         Component component = plotPane.getSelectedComponent();
@@ -49,9 +54,13 @@
         return indices;
     }
     
+    Component getSelectedTab() {
+        return ((JTabbedPane) plotPane.getSelectedComponent()).getSelectedComponent();
+    }
+    
     public void actionPerformed(ActionEvent event) {
         if (event.getActionCommand().equals(Commands.SAVE_SELECTED_PLOTS)) {
-            int[] indices = getSelectedTabs();
+            int[] indices = getSelectedTabIndices();
             IPlotter plotter = MonitoringPlotFactory.getPlotterRegistry().find(indices[0], indices[1]);
             if (plotter != null) {
                 savePlotter(plotter);
@@ -61,20 +70,26 @@
         }
     }
             
-    static final String DEFAULT_FORMAT = "png";
     void savePlotter(IPlotter plotter) {
         JFileChooser fc = new JFileChooser();
         fc.setAcceptAllFileFilterUsed(false);
         fc.setDialogTitle("Save Plots - " + plotter.title());
         fc.setCurrentDirectory(new File("."));
+        fc.setAcceptAllFileFilterUsed(false);
+        fc.setFileFilter(new FileNameExtensionFilter("PNG file", "png"));
+        fc.addChoosableFileFilter(new FileNameExtensionFilter("JPG file", "jpg"));
+        fc.addChoosableFileFilter(new FileNameExtensionFilter("GIF file", "gif"));
         int r = fc.showSaveDialog(this);
         if (r == JFileChooser.APPROVE_OPTION) {                        
             String path = fc.getSelectedFile().getPath();
-            if (path.lastIndexOf(".") == -1) {
-                path += "." + DEFAULT_FORMAT;
+            FileNameExtensionFilter filter = (FileNameExtensionFilter) fc.getFileFilter();
+            if (!path.endsWith("." + filter.getExtensions()[0])) {
+                path += "." + filter.getExtensions()[0];
             }
+            BufferedImage image = ExportPdf.getImage(getSelectedTab());
             try {
-                plotter.writeToFile(path);
+                ImageIO.write(image, filter.getExtensions()[0], new File(path));
+                DialogUtil.showInfoDialog(this, "Plots Saved", "Plots from panel were saved to" + '\n' + path);
             } catch (IOException e) {
                 e.printStackTrace();
                 DialogUtil.showErrorDialog(this, "Error Saving Plots", "There was an error saving the plots.");

Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/model/RunModel.java
 =============================================================================
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/model/RunModel.java	(original)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/model/RunModel.java	Wed Apr  1 13:27:06 2015
@@ -42,11 +42,19 @@
         this.runNumber = runNumber;
         this.firePropertyChange(RUN_NUMBER_PROPERTY, oldValue, this.runNumber);
     }
+    
+    public int getRunNumber() {
+        return this.runNumber;
+    }
 
     public void setStartDate(Date startDate) {
         Date oldValue = this.startDate;
         this.startDate = startDate;
         this.firePropertyChange(START_DATE_PROPERTY, oldValue, this.startDate);
+    }
+    
+    public Date getStartDate() {
+        return startDate;
     }
 
     public void setEndDate(Date endDate) {
@@ -54,11 +62,19 @@
         this.endDate = endDate;
         this.firePropertyChange(END_DATE_PROPERTY, oldValue, this.endDate);
     }
+    
+    public Date getEndDate() {
+        return endDate;
+    }
 
     public void setRunLength(int runLength) {
         Integer oldValue = this.runLength;
         this.runLength = runLength;
         this.firePropertyChange(RUN_LENGTH_PROPERTY, oldValue, this.runLength);
+    }
+    
+    public int getRunLength() {
+        return runLength;
     }
 
     public void computeRunLength() {
@@ -74,11 +90,19 @@
         this.totalEvents = totalEvents;
         this.firePropertyChange(TOTAL_EVENTS_PROPERTY, oldValue, this.totalEvents);
     }
+    
+    public int getTotalEvents() {
+        return totalEvents;
+    }
 
     public void setEventsReceived(int eventsReceived) {
         Integer oldValue = this.eventsReceived;
         this.eventsReceived = eventsReceived;
         this.firePropertyChange(EVENTS_RECEIVED_PROPERTY, oldValue, this.eventsReceived);
+    }
+    
+    public int getEventsReceived() {
+        return eventsReceived;
     }
 
     public void setElapsedTime(int elapsedTime) {
@@ -86,11 +110,19 @@
         this.elapsedTime = elapsedTime;
         this.firePropertyChange(ELAPSED_TIME_PROPERTY, oldValue, this.elapsedTime);
     }
+    
+    public int getElapsedTime() {
+        return elapsedTime;
+    }
 
     public void setDataReceived(double dataReceived) {
         Double oldValue = this.dataReceived;
         this.dataReceived = dataReceived;
         this.firePropertyChange(DATA_RECEIVED_PROPERTY, oldValue, this.dataReceived);
+    }
+    
+    public double getDataReceived() {
+        return dataReceived;
     }
 
     public void addDataReceived(double addDataReceived) {
@@ -103,16 +135,28 @@
         this.firePropertyChange(EVENT_NUMBER_PROPERTY, oldValue, this.eventNumber);
     }
     
+    public int getEventNumber() {
+        return eventNumber;
+    }
+    
     public void setDataRate(double dataRate) {
         Double oldValue = this.dataRate;
         this.dataRate = dataRate;
         this.firePropertyChange(DATA_RATE_PROPERTY, oldValue, this.dataRate);
+    }
+    
+    public double getDataRate() {
+        return dataRate;
     }
         
     public void setEventRate(double eventRate) {
         Double oldValue = this.eventRate;
         this.eventRate = eventRate;
         this.firePropertyChange(EVENT_RATE_PROPERTY, oldValue, this.eventRate);
+    }
+    
+    public double getEventRate() {
+        return eventRate;
     }
     
     public void reset() {
@@ -124,5 +168,5 @@
         setRunNumber(0);
         setStartDate(null);
         setTotalEvents(0);
-    }
+    }    
 }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use