Merge pull request #1253 from RemingtonHolder/unstable
Adds Ability To Export Simulation Graph/Chart As PNG
This commit is contained in:
commit
b1067b6e48
@ -96,6 +96,7 @@ FileHelper.ALL_DESIGNS_FILTER = All rocket designs (*.ork; *.rkt)
|
|||||||
FileHelper.OPENROCKET_DESIGN_FILTER = OpenRocket designs (*.ork)
|
FileHelper.OPENROCKET_DESIGN_FILTER = OpenRocket designs (*.ork)
|
||||||
FileHelper.ROCKSIM_DESIGN_FILTER = RockSim designs (*.rkt)
|
FileHelper.ROCKSIM_DESIGN_FILTER = RockSim designs (*.rkt)
|
||||||
FileHelper.OPEN_ROCKET_COMPONENT_FILTER = OpenRocket presets (*.orc)
|
FileHelper.OPEN_ROCKET_COMPONENT_FILTER = OpenRocket presets (*.orc)
|
||||||
|
FileHelper.PNG_FILTER = PNG image (*.png)
|
||||||
FileHelper.IMAGES = Image files
|
FileHelper.IMAGES = Image files
|
||||||
|
|
||||||
|
|
||||||
@ -1273,6 +1274,7 @@ TCMotorSelPan.btn.close = Close
|
|||||||
! PlotDialog
|
! PlotDialog
|
||||||
PlotDialog.CheckBox.Showdatapoints = Show data points
|
PlotDialog.CheckBox.Showdatapoints = Show data points
|
||||||
PlotDialog.lbl.Chart = left click drag to zoom area. mouse wheel to zoom. ctrl-mouse wheel to zoom x axis only. ctrl-left click drag to pan. right click drag to zoom dynamically.
|
PlotDialog.lbl.Chart = left click drag to zoom area. mouse wheel to zoom. ctrl-mouse wheel to zoom x axis only. ctrl-left click drag to pan. right click drag to zoom dynamically.
|
||||||
|
PlotDialog.btn.exportImage = Export Image
|
||||||
|
|
||||||
ComponentTree.ttip.massoverride = mass override
|
ComponentTree.ttip.massoverride = mass override
|
||||||
ComponentTree.ttip.cgoverride = cg override
|
ComponentTree.ttip.cgoverride = cg override
|
||||||
|
@ -6,26 +6,32 @@ import java.awt.event.ActionListener;
|
|||||||
import java.awt.event.InputEvent;
|
import java.awt.event.InputEvent;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.event.ItemListener;
|
import java.awt.event.ItemListener;
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import net.sf.openrocket.gui.components.StyledLabel;
|
import net.sf.openrocket.gui.components.StyledLabel;
|
||||||
|
import net.sf.openrocket.gui.util.FileHelper;
|
||||||
import net.sf.openrocket.gui.util.GUIUtil;
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
import net.sf.openrocket.gui.util.Icons;
|
import net.sf.openrocket.gui.util.Icons;
|
||||||
|
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.startup.Preferences;
|
import net.sf.openrocket.startup.Preferences;
|
||||||
import net.sf.openrocket.gui.widgets.SelectColorButton;
|
import net.sf.openrocket.gui.widgets.SelectColorButton;
|
||||||
|
|
||||||
import org.jfree.chart.ChartPanel;
|
import org.jfree.chart.ChartPanel;
|
||||||
|
import org.jfree.chart.ChartUtilities;
|
||||||
|
import org.jfree.chart.JFreeChart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialog that shows a plot of a simulation results based on user options.
|
* Dialog that shows a plot of a simulation results based on user options.
|
||||||
@ -50,6 +56,7 @@ public class SimulationPlotDialog extends JDialog {
|
|||||||
this.add(panel);
|
this.add(panel);
|
||||||
|
|
||||||
final ChartPanel chartPanel = new SimulationChart(myPlot.getJFreeChart());
|
final ChartPanel chartPanel = new SimulationChart(myPlot.getJFreeChart());
|
||||||
|
final JFreeChart jChart = myPlot.getJFreeChart();
|
||||||
panel.add(chartPanel, "grow, wrap 20lp");
|
panel.add(chartPanel, "grow, wrap 20lp");
|
||||||
|
|
||||||
//// Description text
|
//// Description text
|
||||||
@ -108,6 +115,16 @@ public class SimulationPlotDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(button, "gapleft rel");
|
panel.add(button, "gapleft rel");
|
||||||
|
|
||||||
|
//// Print chart button
|
||||||
|
button = new SelectColorButton(trans.get("PlotDialog.btn.exportImage"));
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
doPngExport(chartPanel,jChart);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(button, "gapleft rel");
|
||||||
|
|
||||||
//// Add series selection box
|
//// Add series selection box
|
||||||
ArrayList<String> stages = new ArrayList<String>();
|
ArrayList<String> stages = new ArrayList<String>();
|
||||||
@ -141,16 +158,43 @@ public class SimulationPlotDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(button, "right");
|
panel.add(button, "right");
|
||||||
|
|
||||||
this.setLocationByPlatform(true);
|
this.setLocationByPlatform(true);
|
||||||
this.pack();
|
this.pack();
|
||||||
|
|
||||||
GUIUtil.setDisposableDialogOptions(this, button);
|
GUIUtil.setDisposableDialogOptions(this, button);
|
||||||
GUIUtil.rememberWindowSize(this);
|
GUIUtil.rememberWindowSize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean doPngExport(ChartPanel chartPanel, JFreeChart chart){
|
||||||
|
JFileChooser chooser = new JFileChooser();
|
||||||
|
chooser.setAcceptAllFileFilterUsed(false);
|
||||||
|
chooser.setFileFilter(FileHelper.PNG_FILTER);
|
||||||
|
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
|
||||||
|
|
||||||
|
//// Ensures No Problems When Choosing File
|
||||||
|
if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
File file = chooser.getSelectedFile();
|
||||||
|
if (file == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
file = FileHelper.forceExtension(file, "png");
|
||||||
|
if (!FileHelper.confirmWrite(file, this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//// Uses JFreeChart Built In PNG Export Method
|
||||||
|
try{
|
||||||
|
ChartUtilities.saveChartAsPNG(file, chart, chartPanel.getWidth(), chartPanel.getHeight());
|
||||||
|
} catch(Exception e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static method that shows a plot with the specified parameters.
|
* Static method that shows a plot with the specified parameters.
|
||||||
*
|
*
|
||||||
|
@ -56,6 +56,10 @@ public final class FileHelper {
|
|||||||
public static final FileFilter CSV_FILTER =
|
public static final FileFilter CSV_FILTER =
|
||||||
new SimpleFileFilter(trans.get("FileHelper.CSV_FILTER"), ".csv");
|
new SimpleFileFilter(trans.get("FileHelper.CSV_FILTER"), ".csv");
|
||||||
|
|
||||||
|
/** File filter for PNG files (*.png) */
|
||||||
|
public static final FileFilter PNG_FILTER =
|
||||||
|
new SimpleFileFilter(trans.get("FileHelper.PNG_FILTER"), ".png");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user