package net.sf.openrocket.gui;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.document.StorageOptions;
+import net.sf.openrocket.file.OpenRocketSaver;
+import net.sf.openrocket.file.RocketSaver;
import net.sf.openrocket.simulation.FlightData;
import net.sf.openrocket.simulation.FlightDataBranch;
public static final double DEFAULT_SAVE_TIME_SKIP = 0.20;
+ private final OpenRocketDocument document;
+
private JRadioButton allButton;
private JRadioButton someButton;
private JRadioButton noneButton;
private JCheckBox compressButton;
+ private JLabel estimateLabel;
+
private boolean artificialEvent = false;
- public StorageOptionChooser(StorageOptions opts) {
+ public StorageOptionChooser(OpenRocketDocument doc, StorageOptions opts) {
super(new MigLayout());
+
+ this.document = doc;
+
+
+ ChangeListener changeUpdater = new ChangeListener() {
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ updateEstimate();
+ }
+ };
+ ActionListener actionUpdater = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ updateEstimate();
+ }
+ };
+
ButtonGroup buttonGroup = new ButtonGroup();
String tip;
allButton.setToolTipText("<html>Store all simulated data.<br>" +
"This can result in very large files!");
buttonGroup.add(allButton);
+ allButton.addActionListener(actionUpdater);
this.add(allButton, "spanx, wrap rel");
"Larger values result in smaller files.";
someButton.setToolTipText(tip);
buttonGroup.add(someButton);
+ someButton.addActionListener(actionUpdater);
this.add(someButton, "");
timeSpinner = new JSpinner(new SpinnerNumberModel(0.0, 0.0, 5.0, 0.1));
}
});
this.add(timeSpinner, "wmin 55lp");
+ timeSpinner.addChangeListener(changeUpdater);
JLabel label = new JLabel("seconds");
label.setToolTipText(tip);
noneButton.setToolTipText("<html>Store only the values shown in the summary table.<br>" +
"This results in the smallest files.");
buttonGroup.add(noneButton);
-
+ noneButton.addActionListener(actionUpdater);
this.add(noneButton, "spanx, wrap 20lp");
+
compressButton = new JCheckBox("Compress file");
compressButton.setToolTipText("Using compression reduces the file size significantly.");
- this.add(compressButton, "spanx");
+ compressButton.addActionListener(actionUpdater);
+ this.add(compressButton, "spanx, wrap para");
+
+
+ // Estimate is updated in loadOptions(opts)
+ estimateLabel = new JLabel("");
+ estimateLabel.setToolTipText("An estimate on how large the resulting file would " +
+ "be with the present options.");
+ this.add(estimateLabel, "spanx");
this.setBorder(BorderFactory.createCompoundBorder(
// Compression checkbox
compressButton.setSelected(opts.isCompressionEnabled());
+
+ updateEstimate();
}
+ // TODO: MEDIUM: The estimation method always uses OpenRocketSaver!
+ private static final RocketSaver ROCKET_SAVER = new OpenRocketSaver();
+
+ private void updateEstimate() {
+ StorageOptions opts = new StorageOptions();
+
+ storeOptions(opts);
+ long size = ROCKET_SAVER.estimateFileSize(document, opts);
+ size = Math.max((size+512)/1024, 1);
+
+ String formatted;
+
+ if (size >= 10000) {
+ formatted = (size/1000) + " MB";
+ } else if (size >= 1000){
+ formatted = (size/1000) + "." + ((size/100)%10) + " MB";
+ } else if (size >= 100) {
+ formatted = ((size/10)*10) + " kB";
+ } else {
+ formatted = size + " kB";
+ }
+
+ estimateLabel.setText("Estimated file size: " + formatted);
+ }
+
+
+
/**
* Asks the user the storage options using a modal dialog window if the document
* contains simulated data and the user has not explicitly set how to store the data.
}
- StorageOptionChooser chooser = new StorageOptionChooser(options);
+ StorageOptionChooser chooser = new StorageOptionChooser(document, options);
if (JOptionPane.showConfirmDialog(parent, chooser, "Save options",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) !=
return true;
}
-
}