Add preference saving for decimal places & exponential notation

This commit is contained in:
SiboVG 2022-06-11 03:49:52 +02:00
parent 34279641c9
commit e6622c7326
3 changed files with 9 additions and 4 deletions

View File

@ -46,6 +46,8 @@ public abstract class Preferences implements ChangeSource {
public static final String DEFAULT_MACH_NUMBER = "DefaultMachNumber";
// Preferences related to data export
public static final String EXPORT_FIELD_SEPARATOR = "ExportFieldSeparator";
public static final String EXPORT_DECIMAL_PLACES = "ExportDecimalPlaces";
public static final String EXPORT_EXPONENTIAL_NOTATION = "ExportExponentialNotation";
public static final String EXPORT_SIMULATION_COMMENT = "ExportSimulationComment";
public static final String EXPORT_FIELD_NAME_COMMENT = "ExportFieldDescriptionComment";
public static final String EXPORT_EVENT_COMMENTS = "ExportEventComments";

View File

@ -10,6 +10,7 @@ import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.util.SaveCSVWorker;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.startup.Preferences;
@ -75,17 +76,17 @@ public class CsvOptionPanel extends JPanel {
label.setToolTipText(trans.get("SimExpPan.lbl.DecimalPlaces.ttip"));
panel.add(label, "gapright unrel");
SpinnerModel dpModel = new SpinnerNumberModel(3, 0, 15, 1);
SpinnerModel dpModel = new SpinnerNumberModel(Application.getPreferences().getInt(Preferences.EXPORT_DECIMAL_PLACES, SaveCSVWorker.DEFAULT_DECIMAL_PLACES),
0, 15, 1);
decimalPlacesSpinner = new JSpinner(dpModel);
decimalPlacesSpinner.setToolTipText(trans.get("SimExpPan.lbl.DecimalPlaces.ttip"));
panel.add(decimalPlacesSpinner, "growx, wrap");
// TODO: preferences + action
//// Exponential notation
exponentialNotationCheckbox = new JCheckBox(trans.get("SimExpPan.lbl.ExponentialNotation"));
exponentialNotationCheckbox.setToolTipText(trans.get("SimExpPan.lbl.ExponentialNotation.ttip"));
exponentialNotationCheckbox.setSelected(Application.getPreferences().getBoolean(Preferences.EXPORT_EXPONENTIAL_NOTATION, true));
panel.add(exponentialNotationCheckbox);
// TODO: preferences + action
this.add(panel, "growx, wrap unrel");
@ -149,6 +150,8 @@ public class CsvOptionPanel extends JPanel {
*/
public void storePreferences() {
Application.getPreferences().putString(Preferences.EXPORT_FIELD_SEPARATOR, getFieldSeparator());
Application.getPreferences().putInt(Preferences.EXPORT_DECIMAL_PLACES, getDecimalPlaces());
Application.getPreferences().putBoolean(Preferences.EXPORT_EXPONENTIAL_NOTATION, isExponentialNotation());
Application.getPreferences().putString(Preferences.EXPORT_COMMENT_CHARACTER, getCommentCharacter());
for (int i = 0; i < options.length; i++) {
Application.getPreferences().putBoolean("csvOptions." + baseClassName + "." + i, options[i].isSelected());

View File

@ -23,7 +23,7 @@ import net.sf.openrocket.util.BugException;
public class SaveCSVWorker extends SwingWorker<Void, Void> {
private static final int BYTES_PER_FIELD_PER_POINT = 7;
private static final int DEFAULT_DECIMAL_PLACES = 3;
public static final int DEFAULT_DECIMAL_PLACES = 3;
private final File file;
private final Simulation simulation;