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);
- }
+ }
}
|