package net.sf.openrocket.database;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.material.MaterialStorage;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.MathUtil;
-import net.sf.openrocket.util.Prefs;
/**
// Add user-defined materials
- for (Material m : ((Prefs) Application.getPreferences()).getUserMaterials()) {
+ for (Material m : ((SwingPreferences) Application.getPreferences()).getUserMaterials()) {
switch (m.getType()) {
case LINE:
LINE_MATERIAL.add(m);
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.util.FileHelper;
import net.sf.openrocket.gui.util.GUIUtil;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.gui.util.SaveCSVWorker;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.simulation.FlightData;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.unit.UnitGroup;
-import net.sf.openrocket.util.Prefs;
public class SimulationExportPanel extends JPanel {
selected = new boolean[types.length];
units = new Unit[types.length];
for (int i = 0; i < types.length; i++) {
- selected[i] = ((Prefs) Application.getPreferences()).isExportSelected(types[i]);
+ selected[i] = ((SwingPreferences) Application.getPreferences()).isExportSelected(types[i]);
units[i] = types[i].getUnitGroup().getDefaultUnit();
}
private void doExport() {
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(FileHelper.CSV_FILE_FILTER);
- chooser.setCurrentDirectory(((Prefs) Application.getPreferences()).getDefaultDirectory());
+ chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
return;
// Store preferences and export
int n = 0;
- ((Prefs) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
+ ((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
for (int i = 0; i < selected.length; i++) {
- ((Prefs) Application.getPreferences()).setExportSelected(types[i], selected[i]);
+ ((SwingPreferences) Application.getPreferences()).setExportSelected(types[i], selected[i]);
if (selected[i])
n++;
}
import net.sf.openrocket.gui.components.StyledLabel.Style;
import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.gui.util.GUIUtil;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Invalidatable;
import net.sf.openrocket.util.LineStyle;
-import net.sf.openrocket.util.Prefs;
public class RocketComponentConfig extends JPanel {
public void actionPerformed(ActionEvent e) {
Color c = component.getColor();
if (c == null) {
- c = ((Prefs) Application.getPreferences()).getDefaultColor(component.getClass());
+ c = ((SwingPreferences) Application.getPreferences()).getDefaultColor(component.getClass());
}
//// Choose color
if (colorDefault.isSelected())
component.setColor(null);
else
- component.setColor(((Prefs) Application.getPreferences()).getDefaultColor(component.getClass()));
+ component.setColor(((SwingPreferences) Application.getPreferences()).getDefaultColor(component.getClass()));
}
});
panel.add(colorDefault, "wrap para");
@Override
public void actionPerformed(ActionEvent e) {
if (component.getColor() != null) {
- ((Prefs) Application.getPreferences()).setDefaultColor(component.getClass(), component.getColor());
+ ((SwingPreferences) Application.getPreferences()).setDefaultColor(component.getClass(), component.getColor());
component.setColor(null);
}
if (component.getLineStyle() != null) {
private Color getColor() {
Color c = component.getColor();
if (c == null) {
- c = ((Prefs) Application.getPreferences()).getDefaultColor(component.getClass());
+ c = ((SwingPreferences) Application.getPreferences()).getDefaultColor(component.getClass());
}
return c;
}
import net.sf.openrocket.gui.print.components.RocketPrintTree;
import net.sf.openrocket.gui.util.FileHelper;
import net.sf.openrocket.gui.util.GUIUtil;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
-import net.sf.openrocket.util.Prefs;
/**
* This class isolates the Swing components used to create a panel that is added to a standard Java print dialog.
private JButton cancel;
- private final static Prefs prefs = (Prefs) Application.getPreferences();
+ private final static SwingPreferences prefs = (SwingPreferences) Application.getPreferences();
/**
* Constructor.
dir = dir.getParentFile();
}
if (dir == null) {
- dir = ((Prefs) Application.getPreferences()).getDefaultDirectory();
+ dir = prefs.getDefaultDirectory();
}
chooser.setCurrentDirectory(dir);
import net.sf.openrocket.gui.dialogs.motor.MotorSelector;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.BugException;
-import net.sf.openrocket.util.Prefs;
import net.sf.openrocket.utils.MotorCorrelation;
import org.jfree.chart.ChartColor;
//// Hide very similar thrust curves
hideSimilarBox = new JCheckBox(trans.get("TCMotorSelPan.checkbox.hideSimilar"));
GUIUtil.changeFontSize(hideSimilarBox, -1);
- hideSimilarBox.setSelected(Application.getPreferences().getBoolean(Prefs.MOTOR_HIDE_SIMILAR, true));
+ hideSimilarBox.setSelected(Application.getPreferences().getBoolean(SwingPreferences.MOTOR_HIDE_SIMILAR, true));
hideSimilarBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- Application.getPreferences().putBoolean(Prefs.MOTOR_HIDE_SIMILAR, hideSimilarBox.isSelected());
+ Application.getPreferences().putBoolean(SwingPreferences.MOTOR_HIDE_SIMILAR, hideSimilarBox.isSelected());
updateData();
}
});
// Sets the filter:
- int showMode = Application.getPreferences().getChoice(Prefs.MOTOR_DIAMETER_FILTER, SHOW_MAX, SHOW_EXACT);
+ int showMode = Application.getPreferences().getChoice(SwingPreferences.MOTOR_DIAMETER_FILTER, SHOW_MAX, SHOW_EXACT);
filterComboBox.setSelectedIndex(showMode);
}
// Store selected motor in preferences node, set all others to false
- Preferences prefs = ((Prefs) Application.getPreferences()).getNode(Prefs.PREFERRED_THRUST_CURVE_MOTOR_NODE);
+ Preferences prefs = ((SwingPreferences) Application.getPreferences()).getNode(SwingPreferences.PREFERRED_THRUST_CURVE_MOTOR_NODE);
for (ThrustCurveMotor m : set.getMotors()) {
String digest = MotorDigest.digestMotor(m);
prefs.putBoolean(digest, m == motor);
// Find which motor has been used the most recently
List<ThrustCurveMotor> list = set.getMotors();
- Preferences prefs = ((Prefs) Application.getPreferences()).getNode(Prefs.PREFERRED_THRUST_CURVE_MOTOR_NODE);
+ Preferences prefs = ((SwingPreferences) Application.getPreferences()).getNode(SwingPreferences.PREFERRED_THRUST_CURVE_MOTOR_NODE);
for (ThrustCurveMotor m : list) {
String digest = MotorDigest.digestMotor(m);
if (prefs.getBoolean(digest, false)) {
import net.sf.openrocket.gui.scalefigure.ScaleScrollPane;
import net.sf.openrocket.gui.util.FileHelper;
import net.sf.openrocket.gui.util.GUIUtil;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.optimization.general.OptimizationException;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.Named;
-import net.sf.openrocket.util.Prefs;
import net.sf.openrocket.util.TextUtil;
import com.itextpdf.text.Font;
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(FileHelper.CSV_FILE_FILTER);
- chooser.setCurrentDirectory(((Prefs) Application.getPreferences()).getDefaultDirectory());
+ chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
chooser.setAccessory(csvOptions);
if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
import net.sf.openrocket.gui.components.StyledLabel.Style;
import net.sf.openrocket.gui.dialogs.UpdateInfoDialog;
import net.sf.openrocket.gui.util.GUIUtil;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.gui.util.SimpleFileFilter;
import net.sf.openrocket.l10n.L10N;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.BuildProperties;
import net.sf.openrocket.util.Named;
-import net.sf.openrocket.util.Prefs;
import net.sf.openrocket.util.Utils;
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
- ((Prefs) Application.getPreferences()).storeDefaultUnits();
+ ((SwingPreferences) Application.getPreferences()).storeDefaultUnits();
}
});
userLocale = L10N.toLocale(locale);
}
List<Named<Locale>> locales = new ArrayList<Named<Locale>>();
- for (Locale l : Prefs.getSupportedLocales()) {
+ for (Locale l : SwingPreferences.getSupportedLocales()) {
locales.add(new Named<Locale>(l, l.getDisplayLanguage()));
}
Collections.sort(locales);
//// Position to insert new body components:
panel.add(new JLabel(trans.get("pref.dlg.lbl.Positiontoinsert")), "gapright para");
- panel.add(new JComboBox(new PrefChoiseSelector(Prefs.BODY_COMPONENT_INSERT_POSITION_KEY,
+ panel.add(new JComboBox(new PrefChoiseSelector(Preferences.BODY_COMPONENT_INSERT_POSITION_KEY,
//// Always ask
//// Insert in middle
//// Add to end
//// Confirm deletion of simulations:
panel.add(new JLabel(trans.get("pref.dlg.lbl.Confirmdeletion")));
- panel.add(new JComboBox(new PrefBooleanSelector(Prefs.CONFIRM_DELETE_SIMULATION,
+ panel.add(new JComboBox(new PrefBooleanSelector(Preferences.CONFIRM_DELETE_SIMULATION,
//// Delete
//// Confirm
trans.get("pref.dlg.PrefBooleanSelector1"),
//// User-defined thrust curves:
panel.add(new JLabel(trans.get("pref.dlg.lbl.User-definedthrust")), "spanx, wrap");
final JTextField field = new JTextField();
- List<File> files = ((Prefs) Application.getPreferences()).getUserThrustCurveFiles();
+ List<File> files = ((SwingPreferences) Application.getPreferences()).getUserThrustCurveFiles();
String str = "";
for (File file : files) {
if (str.length() > 0) {
list.add(new File(s));
}
}
- ((Prefs) Application.getPreferences()).setUserThrustCurveFiles(list);
+ ((SwingPreferences) Application.getPreferences()).setUserThrustCurveFiles(list);
}
});
panel.add(field, "w 100px, gapright unrel, spanx, growx, split");
@Override
public void actionPerformed(ActionEvent e) {
// First one sets to the default, but does not un-set the pref
- field.setText(((Prefs)Application.getPreferences()).getDefaultUserThrustCurveFile().getAbsolutePath());
- ((Prefs) Application.getPreferences()).setUserThrustCurveFiles(null);
+ field.setText(((SwingPreferences)Application.getPreferences()).getDefaultUserThrustCurveFile().getAbsolutePath());
+ ((SwingPreferences) Application.getPreferences()).setUserThrustCurveFiles(null);
}
});
panel.add(button, "wrap");
UpdateInfoDialog infoDialog = new UpdateInfoDialog(info);
infoDialog.setVisible(true);
if (infoDialog.isReminderSelected()) {
- Application.getPreferences().putString(Prefs.LAST_UPDATE, "");
+ Application.getPreferences().putString(SwingPreferences.LAST_UPDATE, "");
} else {
- Application.getPreferences().putString(Prefs.LAST_UPDATE, info.getLatestVersion());
+ Application.getPreferences().putString(SwingPreferences.LAST_UPDATE, info.getLatestVersion());
}
}
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.gui.util.OpenFileWorker;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.gui.util.SaveFileWorker;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.MemoryManagement;
import net.sf.openrocket.util.MemoryManagement.MemoryData;
-import net.sf.openrocket.util.Prefs;
import net.sf.openrocket.util.Reflection;
import net.sf.openrocket.util.TestRockets;
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(true);
- chooser.setCurrentDirectory(((Prefs) Application.getPreferences()).getDefaultDirectory());
+ chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
int option = chooser.showOpenDialog(this);
if (option != JFileChooser.APPROVE_OPTION) {
log.user("Decided not to open files, option=" + option);
return;
}
- ((Prefs) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
+ ((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
File[] files = chooser.getSelectedFiles();
log.user("Opening files " + Arrays.toString(files));
new StorageOptionChooser(document, document.getDefaultStorageOptions());
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(FileHelper.OPENROCKET_DESIGN_FILTER);
- chooser.setCurrentDirectory(((Prefs) Application.getPreferences()).getDefaultDirectory());
+ chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
chooser.setAccessory(storageChooser);
if (document.getFile() != null)
chooser.setSelectedFile(document.getFile());
return false;
}
- ((Prefs) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
+ ((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
storageChooser.storeOptions(document.getDefaultStorageOptions());
file = FileHelper.ensureExtension(file, "ork");
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.dialogs.DetailDialog;
import net.sf.openrocket.gui.util.GUIUtil;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.rocketcomponent.Configuration;
import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.MathUtil;
-import net.sf.openrocket.util.Prefs;
public class SimulationRunDialog extends JDialog {
* dialogs to run in parallel, ie. they both have their own executor service.
*/
private final ExecutorService executor = Executors.newFixedThreadPool(
- Prefs.getMaxThreadCount());
+ SwingPreferences.getMaxThreadCount());
private final JLabel simLabel, timeLabel, altLabel, velLabel;
import net.sf.openrocket.gui.figureelements.FigureElement;
import net.sf.openrocket.gui.figureelements.RocketInfo;
import net.sf.openrocket.gui.scalefigure.RocketPanel;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.masscalc.BasicMassCalculator;
import net.sf.openrocket.masscalc.MassCalculator;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.Coordinate;
-import net.sf.openrocket.util.Prefs;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
Rocket duplicate = theRocket.copyWithOriginalID();
FlightData flight = null;
try {
- Simulation simulation = ((Prefs)Application.getPreferences()).getBackgroundSimulation(duplicate);
+ Simulation simulation = ((SwingPreferences)Application.getPreferences()).getBackgroundSimulation(duplicate);
simulation.getOptions().setMotorConfigurationID(motorId);
simulation.simulate();
flight = simulation.getSimulatedData();
import net.sf.openrocket.gui.figureelements.FigureElement;
import net.sf.openrocket.gui.main.ExceptionHandler;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.rocketcomponent.Configuration;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.LineStyle;
import net.sf.openrocket.util.MathUtil;
-import net.sf.openrocket.util.Prefs;
import net.sf.openrocket.util.Reflection;
import net.sf.openrocket.util.Transformation;
// Set component color and line style
Color color = c.getColor();
if (color == null) {
- color = ((Prefs) Application.getPreferences()).getDefaultColor(c.getClass());
+ color = ((SwingPreferences) Application.getPreferences()).getDefaultColor(c.getClass());
}
g2.setColor(color);
// Draw motors
String motorID = configuration.getMotorConfigurationID();
- Color fillColor = ((Prefs)Application.getPreferences()).getMotorFillColor();
- Color borderColor = ((Prefs)Application.getPreferences()).getMotorBorderColor();
+ Color fillColor = ((SwingPreferences)Application.getPreferences()).getMotorFillColor();
+ Color borderColor = ((SwingPreferences)Application.getPreferences()).getMotorBorderColor();
Iterator<MotorMount> iterator = configuration.motorIterator();
while (iterator.hasNext()) {
MotorMount mount = iterator.next();
import net.sf.openrocket.gui.figureelements.RocketInfo;
import net.sf.openrocket.gui.main.SimulationWorker;
import net.sf.openrocket.gui.main.componenttree.ComponentTreeModel;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.masscalc.BasicMassCalculator;
import net.sf.openrocket.masscalc.MassCalculator;
import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.MathUtil;
-import net.sf.openrocket.util.Prefs;
import net.sf.openrocket.util.StateChangeListener;
/**
*/
private static final Executor backgroundSimulationExecutor;
static {
- backgroundSimulationExecutor = Executors.newFixedThreadPool(Prefs.getMaxThreadCount(),
+ backgroundSimulationExecutor = Executors.newFixedThreadPool(SwingPreferences.getMaxThreadCount(),
new ThreadFactory() {
private ThreadFactory factory = Executors.defaultThreadFactory();
//////// Flight simulation in background
// Check whether to compute or not
- if (!((Prefs) Application.getPreferences()).computeFlightInBackground()) {
+ if (!((SwingPreferences) Application.getPreferences()).computeFlightInBackground()) {
extraText.setFlightData(null);
extraText.setCalculatingData(false);
stopBackgroundSimulation();
extraText.setCalculatingData(true);
Rocket duplicate = (Rocket) configuration.getRocket().copy();
- Simulation simulation = ((Prefs)Application.getPreferences()).getBackgroundSimulation(duplicate);
+ Simulation simulation = ((SwingPreferences)Application.getPreferences()).getBackgroundSimulation(duplicate);
simulation.getOptions().setMotorConfigurationID(
configuration.getMotorConfigurationID());
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Invalidatable;
import net.sf.openrocket.util.MemoryManagement;
-import net.sf.openrocket.util.Prefs;
public class GUIUtil {
private static final LogHelper log = Application.getLogger();
@Override
public void componentResized(ComponentEvent e) {
log.debug("Storing size of " + window.getClass().getName() + ": " + window.getSize());
- ((Prefs) Application.getPreferences()).setWindowSize(window.getClass(), window.getSize());
+ ((SwingPreferences) Application.getPreferences()).setWindowSize(window.getClass(), window.getSize());
if (window instanceof JFrame) {
if ((((JFrame) window).getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) {
log.debug("Storing maximized state of " + window.getClass().getName());
- ((Prefs) Application.getPreferences()).setWindowMaximized(window.getClass());
+ ((SwingPreferences) Application.getPreferences()).setWindowMaximized(window.getClass());
}
}
}
});
- if (((Prefs) Application.getPreferences()).isWindowMaximized(window.getClass())) {
+ if (((SwingPreferences) Application.getPreferences()).isWindowMaximized(window.getClass())) {
if (window instanceof JFrame) {
((JFrame) window).setExtendedState(JFrame.MAXIMIZED_BOTH);
}
} else {
- Dimension dim = ((Prefs) Application.getPreferences()).getWindowSize(window.getClass());
+ Dimension dim = ((SwingPreferences) Application.getPreferences()).getWindowSize(window.getClass());
if (dim != null) {
window.setSize(dim);
}
window.addComponentListener(new ComponentAdapter() {
@Override
public void componentMoved(ComponentEvent e) {
- ((Prefs) Application.getPreferences()).setWindowPosition(window.getClass(), window.getLocation());
+ ((SwingPreferences) Application.getPreferences()).setWindowPosition(window.getClass(), window.getLocation());
}
});
// Set window position according to preferences, and set prefs when moving
- Point position = ((Prefs) Application.getPreferences()).getWindowPosition(window.getClass());
+ Point position = ((SwingPreferences) Application.getPreferences()).getWindowPosition(window.getClass());
if (position != null) {
window.setLocationByPlatform(false);
window.setLocation(position);
--- /dev/null
+package net.sf.openrocket.gui.util;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
+
+import net.sf.openrocket.arch.SystemInfo;
+import net.sf.openrocket.document.Simulation;
+import net.sf.openrocket.gui.main.ExceptionHandler;
+import net.sf.openrocket.logging.LogHelper;
+import net.sf.openrocket.material.Material;
+import net.sf.openrocket.rocketcomponent.BodyComponent;
+import net.sf.openrocket.rocketcomponent.FinSet;
+import net.sf.openrocket.rocketcomponent.InternalComponent;
+import net.sf.openrocket.rocketcomponent.LaunchLug;
+import net.sf.openrocket.rocketcomponent.MassObject;
+import net.sf.openrocket.rocketcomponent.RecoveryDevice;
+import net.sf.openrocket.rocketcomponent.Rocket;
+import net.sf.openrocket.rocketcomponent.RocketComponent;
+import net.sf.openrocket.simulation.FlightDataType;
+import net.sf.openrocket.simulation.RK4SimulationStepper;
+import net.sf.openrocket.simulation.SimulationOptions;
+import net.sf.openrocket.startup.Application;
+import net.sf.openrocket.unit.UnitGroup;
+import net.sf.openrocket.util.BugException;
+import net.sf.openrocket.util.BuildProperties;
+
+
+public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
+ private static final LogHelper log = Application.getLogger();
+
+ private static final String SPLIT_CHARACTER = "|";
+
+
+ private static final List<Locale> SUPPORTED_LOCALES;
+ static {
+ List<Locale> list = new ArrayList<Locale>();
+ for (String lang : new String[] { "en", "de", "es", "fr" }) {
+ list.add(new Locale(lang));
+ }
+ SUPPORTED_LOCALES = Collections.unmodifiableList(list);
+ }
+
+
+ /**
+ * Whether to use the debug-node instead of the normal node.
+ */
+ private static final boolean DEBUG;
+ static {
+ DEBUG = (System.getProperty("openrocket.debug.prefs") != null);
+ }
+
+ /**
+ * Whether to clear all preferences at application startup. This has an effect only
+ * if DEBUG is true.
+ */
+ private static final boolean CLEARPREFS = true;
+
+ /**
+ * The node name to use in the Java preferences storage.
+ */
+ private static final String NODENAME = (DEBUG ? "OpenRocket-debug" : "OpenRocket");
+
+ private final Preferences PREFNODE;
+
+
+ public SwingPreferences() {
+ Preferences root = Preferences.userRoot();
+ if (DEBUG && CLEARPREFS) {
+ try {
+ if (root.nodeExists(NODENAME)) {
+ root.node(NODENAME).removeNode();
+ }
+ } catch (BackingStoreException e) {
+ throw new BugException("Unable to clear preference node", e);
+ }
+ }
+ PREFNODE = root.node(NODENAME);
+ }
+
+
+ private static final HashMap<Class<?>, String> DEFAULT_COLORS =
+ new HashMap<Class<?>, String>();
+ static {
+ DEFAULT_COLORS.put(BodyComponent.class, "0,0,240");
+ DEFAULT_COLORS.put(FinSet.class, "0,0,200");
+ DEFAULT_COLORS.put(LaunchLug.class, "0,0,180");
+ DEFAULT_COLORS.put(InternalComponent.class, "170,0,100");
+ DEFAULT_COLORS.put(MassObject.class, "0,0,0");
+ DEFAULT_COLORS.put(RecoveryDevice.class, "255,0,0");
+ }
+
+
+
+ //////////////////////
+
+
+
+ /**
+ * Store the current OpenRocket version into the preferences to allow for preferences migration.
+ */
+ private void storeVersion() {
+ PREFNODE.put("OpenRocketVersion", BuildProperties.getVersion());
+ }
+
+ /**
+ * Return a string preference.
+ *
+ * @param key the preference key.
+ * @param def the default if no preference is stored
+ * @return the preference value
+ */
+ @Override
+ public String getString(String key, String def) {
+ return PREFNODE.get(key, def);
+ }
+
+ @Override
+ public String getString( String directory, String key, String defaultValue ) {
+ Preferences p = PREFNODE.node(directory);
+ return p.get(key,defaultValue);
+ }
+
+ /**
+ * Set a string preference.
+ *
+ * @param key the preference key
+ * @param value the value to set, or <code>null</code> to remove the key
+ */
+ @Override
+ public void putString(String key, String value) {
+ if (value == null) {
+ PREFNODE.remove(key);
+ } else {
+ PREFNODE.put(key, value);
+ }
+ storeVersion();
+ }
+
+ @Override
+ public void putString(String directory, String key, String value ) {
+ Preferences p = PREFNODE.node(directory);
+ if ( value == null ) {
+ p.remove(key);
+ } else {
+ p.put(key,value);
+ }
+ storeVersion();
+ }
+
+ /**
+ * Return a boolean preference.
+ *
+ * @param key the preference key
+ * @param def the default if no preference is stored
+ * @return the preference value
+ */
+ @Override
+ public boolean getBoolean(String key, boolean def) {
+ return PREFNODE.getBoolean(key, def);
+ }
+
+ /**
+ * Set a boolean preference.
+ *
+ * @param key the preference key
+ * @param value the value to set
+ */
+ @Override
+ public void putBoolean(String key, boolean value) {
+ PREFNODE.putBoolean(key, value);
+ storeVersion();
+ }
+
+ @Override
+ public int getInt( String key, int defaultValue ) {
+ return PREFNODE.getInt(key, defaultValue);
+ }
+
+ @Override
+ public void putInt( String key , int value ) {
+ PREFNODE.putInt(key, value );
+ storeVersion();
+ }
+
+ @Override
+ public double getDouble(String key, double defaultValue) {
+ return PREFNODE.getDouble(key, defaultValue );
+ }
+
+ @Override
+ public void putDouble(String key, double value) {
+ PREFNODE.putDouble(key,value);
+ storeVersion();
+ }
+
+
+
+ /**
+ * Return a preferences object for the specified node name.
+ *
+ * @param nodeName the node name
+ * @return the preferences object for that node
+ */
+ public Preferences getNode(String nodeName) {
+ return PREFNODE.node(nodeName);
+ }
+
+
+ //////////////////
+
+
+ public static List<Locale> getSupportedLocales() {
+ return SUPPORTED_LOCALES;
+ }
+
+ public File getDefaultDirectory() {
+ String file = getString("defaultDirectory", null);
+ if (file == null)
+ return null;
+ return new File(file);
+ }
+
+ public void setDefaultDirectory(File dir) {
+ String d;
+ if (dir == null) {
+ d = null;
+ } else {
+ d = dir.getAbsolutePath();
+ }
+ putString("defaultDirectory", d);
+ storeVersion();
+ }
+
+
+ /**
+ * Return a list of files/directories to be loaded as custom thrust curves.
+ * <p>
+ * If this property has not been set, the directory "ThrustCurves" in the user
+ * application directory will be used. The directory will be created if it does not
+ * exist.
+ *
+ * @return a list of files to load as thrust curves.
+ */
+ public List<File> getUserThrustCurveFiles() {
+ List<File> list = new ArrayList<File>();
+
+ String files = getString(USER_THRUST_CURVES_KEY, null);
+ if (files == null) {
+ // Default to application directory
+ File tcdir = getDefaultUserThrustCurveFile();
+ if (!tcdir.isDirectory()) {
+ tcdir.mkdirs();
+ }
+ list.add(tcdir);
+ } else {
+ for (String file : files.split("\\" + SPLIT_CHARACTER)) {
+ file = file.trim();
+ if (file.length() > 0) {
+ list.add(new File(file));
+ }
+ }
+ }
+
+ return list;
+ }
+
+ public File getDefaultUserThrustCurveFile() {
+ File appdir = SystemInfo.getUserApplicationDirectory();
+ File tcdir = new File(appdir, "ThrustCurves");
+ return tcdir;
+ }
+
+
+ /**
+ * Set the list of files/directories to be loaded as custom thrust curves.
+ *
+ * @param files the files to load, or <code>null</code> to reset to default value.
+ */
+ public void setUserThrustCurveFiles(List<File> files) {
+ if (files == null) {
+ putString(USER_THRUST_CURVES_KEY, null);
+ return;
+ }
+
+ String str = "";
+
+ for (File file : files) {
+ if (str.length() > 0) {
+ str += SPLIT_CHARACTER;
+ }
+ str += file.getAbsolutePath();
+ }
+ putString(USER_THRUST_CURVES_KEY, str);
+ }
+
+ public Color getMotorBorderColor() {
+ // TODO: MEDIUM: Motor color (settable?)
+ return new Color(0, 0, 0, 200);
+ }
+
+
+ public Color getMotorFillColor() {
+ // TODO: MEDIUM: Motor fill color (settable?)
+ return new Color(0, 0, 0, 100);
+ }
+
+ public Color getDefaultColor(Class<? extends RocketComponent> c) {
+ String color = get("componentColors", c, DEFAULT_COLORS);
+ if (color == null)
+ return Color.BLACK;
+
+ net.sf.openrocket.util.Color clr = parseColor(color);
+ if (clr != null) {
+ return ColorConversion.toAwtColor(clr);
+ } else {
+ return Color.BLACK;
+ }
+ }
+
+ public final void setDefaultColor(Class<? extends RocketComponent> c, Color color) {
+ if (color == null)
+ return;
+ putString("componentColors", c.getSimpleName(), stringifyColor(ColorConversion.fromAwtColor(color)));
+ }
+
+
+
+ public static int getMaxThreadCount() {
+ return Runtime.getRuntime().availableProcessors();
+ }
+
+
+
+ public Point getWindowPosition(Class<?> c) {
+ int x, y;
+ String pref = PREFNODE.node("windows").get("position." + c.getCanonicalName(), null);
+
+ if (pref == null)
+ return null;
+
+ if (pref.indexOf(',') < 0)
+ return null;
+
+ try {
+ x = Integer.parseInt(pref.substring(0, pref.indexOf(',')));
+ y = Integer.parseInt(pref.substring(pref.indexOf(',') + 1));
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ return new Point(x, y);
+ }
+
+ public void setWindowPosition(Class<?> c, Point p) {
+ PREFNODE.node("windows").put("position." + c.getCanonicalName(), "" + p.x + "," + p.y);
+ storeVersion();
+ }
+
+
+
+
+ public Dimension getWindowSize(Class<?> c) {
+ int x, y;
+ String pref = PREFNODE.node("windows").get("size." + c.getCanonicalName(), null);
+
+ if (pref == null)
+ return null;
+
+ if (pref.indexOf(',') < 0)
+ return null;
+
+ try {
+ x = Integer.parseInt(pref.substring(0, pref.indexOf(',')));
+ y = Integer.parseInt(pref.substring(pref.indexOf(',') + 1));
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ return new Dimension(x, y);
+ }
+
+
+ public boolean isWindowMaximized(Class<?> c) {
+ String pref = PREFNODE.node("windows").get("size." + c.getCanonicalName(), null);
+ return "max".equals(pref);
+ }
+
+ public void setWindowSize(Class<?> c, Dimension d) {
+ PREFNODE.node("windows").put("size." + c.getCanonicalName(), "" + d.width + "," + d.height);
+ storeVersion();
+ }
+
+ public void setWindowMaximized(Class<?> c) {
+ PREFNODE.node("windows").put("size." + c.getCanonicalName(), "max");
+ storeVersion();
+ }
+
+ /**
+ * this class returns a java.awt.Color object for the specified key.
+ * you can pass (java.awt.Color) null to the second argument to
+ * disambiguate
+ */
+ public Color getColor( String key, Color defaultValue ) {
+ net.sf.openrocket.util.Color c = super.getColor(key, (net.sf.openrocket.util.Color) null);
+ if ( c == null ) {
+ return defaultValue;
+ }
+ return ColorConversion.toAwtColor(c);
+ }
+
+ /**
+ *
+ */
+ public void putColor( String key, Color value ) {
+ net.sf.openrocket.util.Color c = ColorConversion.fromAwtColor(value);
+ super.putColor(key, c);
+ }
+
+ //// Printing
+
+
+ //// Background flight data computation
+
+ public boolean computeFlightInBackground() {
+ return PREFNODE.getBoolean("backgroundFlight", true);
+ }
+
+ public Simulation getBackgroundSimulation(Rocket rocket) {
+ Simulation s = new Simulation(rocket);
+ SimulationOptions cond = s.getOptions();
+
+ cond.setTimeStep(RK4SimulationStepper.RECOMMENDED_TIME_STEP * 2);
+ cond.setWindSpeedAverage(1.0);
+ cond.setWindSpeedDeviation(0.1);
+ cond.setLaunchRodLength(5);
+ return s;
+ }
+
+
+
+ ///////// Export variables
+
+ public boolean isExportSelected(FlightDataType type) {
+ Preferences prefs = PREFNODE.node("exports");
+ return prefs.getBoolean(type.getName(), false);
+ }
+
+ public void setExportSelected(FlightDataType type, boolean selected) {
+ Preferences prefs = PREFNODE.node("exports");
+ prefs.putBoolean(type.getName(), selected);
+ }
+
+
+
+ ///////// Default unit storage
+
+ public void loadDefaultUnits() {
+ Preferences prefs = PREFNODE.node("units");
+ try {
+
+ for (String key : prefs.keys()) {
+ UnitGroup group = UnitGroup.UNITS.get(key);
+ if (group == null)
+ continue;
+
+ try {
+ group.setDefaultUnit(prefs.get(key, null));
+ } catch (IllegalArgumentException ignore) {
+ }
+ }
+
+ } catch (BackingStoreException e) {
+ ExceptionHandler.handleErrorCondition(e);
+ }
+ }
+
+ public void storeDefaultUnits() {
+ Preferences prefs = PREFNODE.node("units");
+
+ for (String key : UnitGroup.UNITS.keySet()) {
+ UnitGroup group = UnitGroup.UNITS.get(key);
+ if (group == null || group.getUnitCount() < 2)
+ continue;
+
+ prefs.put(key, group.getDefaultUnit().getUnit());
+ }
+ }
+
+
+
+ //// Material storage
+
+
+ /**
+ * Add a user-defined material to the preferences. The preferences are
+ * first checked for an existing material matching the provided one using
+ * {@link Material#equals(Object)}.
+ *
+ * @param m the material to add.
+ */
+ public void addUserMaterial(Material m) {
+ Preferences prefs = PREFNODE.node("userMaterials");
+
+
+ // Check whether material already exists
+ if (getUserMaterials().contains(m)) {
+ return;
+ }
+
+ // Add material using next free key (key is not used when loading)
+ String mat = m.toStorableString();
+ for (int i = 0;; i++) {
+ String key = "material" + i;
+ if (prefs.get(key, null) == null) {
+ prefs.put(key, mat);
+ return;
+ }
+ }
+ }
+
+
+ /**
+ * Remove a user-defined material from the preferences. The matching is performed
+ * using {@link Material#equals(Object)}.
+ *
+ * @param m the material to remove.
+ */
+ public void removeUserMaterial(Material m) {
+ Preferences prefs = PREFNODE.node("userMaterials");
+
+ try {
+
+ // Iterate through materials and remove all keys with a matching material
+ for (String key : prefs.keys()) {
+ String value = prefs.get(key, null);
+ try {
+
+ Material existing = Material.fromStorableString(value, true);
+ if (existing.equals(m)) {
+ prefs.remove(key);
+ }
+
+ } catch (IllegalArgumentException ignore) {
+ }
+
+ }
+
+ } catch (BackingStoreException e) {
+ throw new IllegalStateException("Cannot read preferences!", e);
+ }
+ }
+
+
+ /**
+ * Return a set of all user-defined materials in the preferences. The materials
+ * are created marked as user-defined.
+ *
+ * @return a set of all user-defined materials.
+ */
+ public Set<Material> getUserMaterials() {
+ Preferences prefs = PREFNODE.node("userMaterials");
+
+ HashSet<Material> materials = new HashSet<Material>();
+ try {
+
+ for (String key : prefs.keys()) {
+ String value = prefs.get(key, null);
+ try {
+
+ Material m = Material.fromStorableString(value, true);
+ materials.add(m);
+
+ } catch (IllegalArgumentException e) {
+ log.warn("Illegal material string " + value);
+ }
+
+ }
+
+ } catch (BackingStoreException e) {
+ throw new IllegalStateException("Cannot read preferences!", e);
+ }
+
+ return materials;
+ }
+
+
+ //// Helper methods
+
+}
import net.sf.openrocket.database.Database;
import net.sf.openrocket.database.DatabaseListener;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.startup.Application;
-import net.sf.openrocket.util.Prefs;
/**
* Class for storing changes to user-added materials. The materials are stored to
@Override
public void elementAdded(Material material, Database<Material> source) {
if (material.isUserDefined()) {
- ((Prefs) Application.getPreferences()).addUserMaterial(material);
+ ((SwingPreferences) Application.getPreferences()).addUserMaterial(material);
}
}
@Override
public void elementRemoved(Material material, Database<Material> source) {
- ((Prefs) Application.getPreferences()).removeUserMaterial(material);
+ ((SwingPreferences) Application.getPreferences()).removeUserMaterial(material);
}
}
import java.util.Locale;
import java.util.prefs.Preferences;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.DebugTranslator;
import net.sf.openrocket.l10n.L10N;
import net.sf.openrocket.l10n.ResourceBundleTranslator;
import net.sf.openrocket.logging.LogLevel;
import net.sf.openrocket.logging.LogLevelBufferLogger;
import net.sf.openrocket.logging.PrintStreamLogger;
-import net.sf.openrocket.util.Prefs;
/**
// Initialize logging first so we can use it
initializeLogging();
- Application.setPreferences( new Prefs() );
+ Application.setPreferences( new SwingPreferences() );
// Setup the translations
initializeL10n();
import net.sf.openrocket.gui.main.ExceptionHandler;
import net.sf.openrocket.gui.main.Splash;
import net.sf.openrocket.gui.util.GUIUtil;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.gui.util.SimpleFileFilter;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.util.BuildProperties;
-import net.sf.openrocket.util.Prefs;
/**
* The second class in the OpenRocket startup sequence. This class can assume the
ToolTipManager.sharedInstance().setDismissDelay(30000);
// Load defaults
- ((Prefs) Application.getPreferences()).loadDefaultUnits();
+ ((SwingPreferences) Application.getPreferences()).loadDefaultUnits();
// Load motors etc.
log.info("Loading databases");
thrustCurveCount = list.size();
// Load the user-defined thrust curves
- for (File file : ((Prefs) Application.getPreferences()).getUserThrustCurveFiles()) {
+ for (File file : ((SwingPreferences) Application.getPreferences()).getUserThrustCurveFiles()) {
log.info("Loading motors from " + file);
list = MotorLoaderHelper.load(file);
for (Motor m : list) {
timer.stop();
String current = BuildProperties.getVersion();
- String last = Application.getPreferences().getString(Prefs.LAST_UPDATE, "");
+ String last = Application.getPreferences().getString(Preferences.LAST_UPDATE, "");
UpdateInfo info = updateInfo.getUpdateInfo();
if (info != null && info.getLatestVersion() != null &&
UpdateInfoDialog infoDialog = new UpdateInfoDialog(info);
infoDialog.setVisible(true);
if (infoDialog.isReminderSelected()) {
- Application.getPreferences().putString(Prefs.LAST_UPDATE, "");
+ Application.getPreferences().putString(Preferences.LAST_UPDATE, "");
} else {
- Application.getPreferences().putString(Prefs.LAST_UPDATE, info.getLatestVersion());
+ Application.getPreferences().putString(Preferences.LAST_UPDATE, info.getLatestVersion());
}
}
}
+++ /dev/null
-package net.sf.openrocket.util;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Point;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.Preferences;
-
-import net.sf.openrocket.arch.SystemInfo;
-import net.sf.openrocket.document.Simulation;
-import net.sf.openrocket.gui.main.ExceptionHandler;
-import net.sf.openrocket.gui.util.ColorConversion;
-import net.sf.openrocket.logging.LogHelper;
-import net.sf.openrocket.material.Material;
-import net.sf.openrocket.rocketcomponent.BodyComponent;
-import net.sf.openrocket.rocketcomponent.FinSet;
-import net.sf.openrocket.rocketcomponent.InternalComponent;
-import net.sf.openrocket.rocketcomponent.LaunchLug;
-import net.sf.openrocket.rocketcomponent.MassObject;
-import net.sf.openrocket.rocketcomponent.RecoveryDevice;
-import net.sf.openrocket.rocketcomponent.Rocket;
-import net.sf.openrocket.rocketcomponent.RocketComponent;
-import net.sf.openrocket.simulation.FlightDataType;
-import net.sf.openrocket.simulation.RK4SimulationStepper;
-import net.sf.openrocket.simulation.SimulationOptions;
-import net.sf.openrocket.startup.Application;
-import net.sf.openrocket.unit.UnitGroup;
-
-
-public class Prefs extends net.sf.openrocket.startup.Preferences {
- private static final LogHelper log = Application.getLogger();
-
- private static final String SPLIT_CHARACTER = "|";
-
-
- private static final List<Locale> SUPPORTED_LOCALES;
- static {
- List<Locale> list = new ArrayList<Locale>();
- for (String lang : new String[] { "en", "de", "es", "fr" }) {
- list.add(new Locale(lang));
- }
- SUPPORTED_LOCALES = Collections.unmodifiableList(list);
- }
-
-
- /**
- * Whether to use the debug-node instead of the normal node.
- */
- private static final boolean DEBUG;
- static {
- DEBUG = (System.getProperty("openrocket.debug.prefs") != null);
- }
-
- /**
- * Whether to clear all preferences at application startup. This has an effect only
- * if DEBUG is true.
- */
- private static final boolean CLEARPREFS = true;
-
- /**
- * The node name to use in the Java preferences storage.
- */
- private static final String NODENAME = (DEBUG ? "OpenRocket-debug" : "OpenRocket");
-
- /**
- * Return whether to use additional safety code checks.
- */
- public static boolean useSafetyChecks() {
- // Currently default to false unless openrocket.debug.safetycheck is defined
- String s = System.getProperty("openrocket.debug.safetycheck");
- if (s != null && !(s.equalsIgnoreCase("false") || s.equalsIgnoreCase("off"))) {
- return true;
- }
- return false;
- }
-
- private final Preferences PREFNODE;
-
-
- public Prefs() {
- Preferences root = Preferences.userRoot();
- if (DEBUG && CLEARPREFS) {
- try {
- if (root.nodeExists(NODENAME)) {
- root.node(NODENAME).removeNode();
- }
- } catch (BackingStoreException e) {
- throw new BugException("Unable to clear preference node", e);
- }
- }
- PREFNODE = root.node(NODENAME);
- }
-
-
- private static final HashMap<Class<?>, String> DEFAULT_COLORS =
- new HashMap<Class<?>, String>();
- static {
- DEFAULT_COLORS.put(BodyComponent.class, "0,0,240");
- DEFAULT_COLORS.put(FinSet.class, "0,0,200");
- DEFAULT_COLORS.put(LaunchLug.class, "0,0,180");
- DEFAULT_COLORS.put(InternalComponent.class, "170,0,100");
- DEFAULT_COLORS.put(MassObject.class, "0,0,0");
- DEFAULT_COLORS.put(RecoveryDevice.class, "255,0,0");
- }
-
-
-
- //////////////////////
-
-
-
- /**
- * Store the current OpenRocket version into the preferences to allow for preferences migration.
- */
- private void storeVersion() {
- PREFNODE.put("OpenRocketVersion", BuildProperties.getVersion());
- }
-
- /**
- * Return a string preference.
- *
- * @param key the preference key.
- * @param def the default if no preference is stored
- * @return the preference value
- */
- @Override
- public String getString(String key, String def) {
- return PREFNODE.get(key, def);
- }
-
- @Override
- public String getString( String directory, String key, String defaultValue ) {
- Preferences p = PREFNODE.node(directory);
- return p.get(key,defaultValue);
- }
-
- /**
- * Set a string preference.
- *
- * @param key the preference key
- * @param value the value to set, or <code>null</code> to remove the key
- */
- @Override
- public void putString(String key, String value) {
- if (value == null) {
- PREFNODE.remove(key);
- } else {
- PREFNODE.put(key, value);
- }
- storeVersion();
- }
-
- @Override
- public void putString(String directory, String key, String value ) {
- Preferences p = PREFNODE.node(directory);
- if ( value == null ) {
- p.remove(key);
- } else {
- p.put(key,value);
- }
- storeVersion();
- }
-
- /**
- * Return a boolean preference.
- *
- * @param key the preference key
- * @param def the default if no preference is stored
- * @return the preference value
- */
- @Override
- public boolean getBoolean(String key, boolean def) {
- return PREFNODE.getBoolean(key, def);
- }
-
- /**
- * Set a boolean preference.
- *
- * @param key the preference key
- * @param value the value to set
- */
- @Override
- public void putBoolean(String key, boolean value) {
- PREFNODE.putBoolean(key, value);
- storeVersion();
- }
-
- @Override
- public int getInt( String key, int defaultValue ) {
- return PREFNODE.getInt(key, defaultValue);
- }
-
- @Override
- public void putInt( String key , int value ) {
- PREFNODE.putInt(key, value );
- storeVersion();
- }
-
- @Override
- public double getDouble(String key, double defaultValue) {
- return PREFNODE.getDouble(key, defaultValue );
- }
-
- @Override
- public void putDouble(String key, double value) {
- PREFNODE.putDouble(key,value);
- storeVersion();
- }
-
-
-
- /**
- * Return a preferences object for the specified node name.
- *
- * @param nodeName the node name
- * @return the preferences object for that node
- */
- public Preferences getNode(String nodeName) {
- return PREFNODE.node(nodeName);
- }
-
-
- //////////////////
-
-
- public static List<Locale> getSupportedLocales() {
- return SUPPORTED_LOCALES;
- }
-
- public File getDefaultDirectory() {
- String file = getString("defaultDirectory", null);
- if (file == null)
- return null;
- return new File(file);
- }
-
- public void setDefaultDirectory(File dir) {
- String d;
- if (dir == null) {
- d = null;
- } else {
- d = dir.getAbsolutePath();
- }
- putString("defaultDirectory", d);
- storeVersion();
- }
-
-
- /**
- * Return a list of files/directories to be loaded as custom thrust curves.
- * <p>
- * If this property has not been set, the directory "ThrustCurves" in the user
- * application directory will be used. The directory will be created if it does not
- * exist.
- *
- * @return a list of files to load as thrust curves.
- */
- public List<File> getUserThrustCurveFiles() {
- List<File> list = new ArrayList<File>();
-
- String files = getString(USER_THRUST_CURVES_KEY, null);
- if (files == null) {
- // Default to application directory
- File tcdir = getDefaultUserThrustCurveFile();
- if (!tcdir.isDirectory()) {
- tcdir.mkdirs();
- }
- list.add(tcdir);
- } else {
- for (String file : files.split("\\" + SPLIT_CHARACTER)) {
- file = file.trim();
- if (file.length() > 0) {
- list.add(new File(file));
- }
- }
- }
-
- return list;
- }
-
- public File getDefaultUserThrustCurveFile() {
- File appdir = SystemInfo.getUserApplicationDirectory();
- File tcdir = new File(appdir, "ThrustCurves");
- return tcdir;
- }
-
-
- /**
- * Set the list of files/directories to be loaded as custom thrust curves.
- *
- * @param files the files to load, or <code>null</code> to reset to default value.
- */
- public void setUserThrustCurveFiles(List<File> files) {
- if (files == null) {
- putString(USER_THRUST_CURVES_KEY, null);
- return;
- }
-
- String str = "";
-
- for (File file : files) {
- if (str.length() > 0) {
- str += SPLIT_CHARACTER;
- }
- str += file.getAbsolutePath();
- }
- putString(USER_THRUST_CURVES_KEY, str);
- }
-
- public Color getMotorBorderColor() {
- // TODO: MEDIUM: Motor color (settable?)
- return new Color(0, 0, 0, 200);
- }
-
-
- public Color getMotorFillColor() {
- // TODO: MEDIUM: Motor fill color (settable?)
- return new Color(0, 0, 0, 100);
- }
-
- public Color getDefaultColor(Class<? extends RocketComponent> c) {
- String color = get("componentColors", c, DEFAULT_COLORS);
- if (color == null)
- return Color.BLACK;
-
- net.sf.openrocket.util.Color clr = parseColor(color);
- if (clr != null) {
- return ColorConversion.toAwtColor(clr);
- } else {
- return Color.BLACK;
- }
- }
-
- public final void setDefaultColor(Class<? extends RocketComponent> c, Color color) {
- if (color == null)
- return;
- putString("componentColors", c.getSimpleName(), stringifyColor(ColorConversion.fromAwtColor(color)));
- }
-
-
-
- public static int getMaxThreadCount() {
- return Runtime.getRuntime().availableProcessors();
- }
-
-
-
- public Point getWindowPosition(Class<?> c) {
- int x, y;
- String pref = PREFNODE.node("windows").get("position." + c.getCanonicalName(), null);
-
- if (pref == null)
- return null;
-
- if (pref.indexOf(',') < 0)
- return null;
-
- try {
- x = Integer.parseInt(pref.substring(0, pref.indexOf(',')));
- y = Integer.parseInt(pref.substring(pref.indexOf(',') + 1));
- } catch (NumberFormatException e) {
- return null;
- }
- return new Point(x, y);
- }
-
- public void setWindowPosition(Class<?> c, Point p) {
- PREFNODE.node("windows").put("position." + c.getCanonicalName(), "" + p.x + "," + p.y);
- storeVersion();
- }
-
-
-
-
- public Dimension getWindowSize(Class<?> c) {
- int x, y;
- String pref = PREFNODE.node("windows").get("size." + c.getCanonicalName(), null);
-
- if (pref == null)
- return null;
-
- if (pref.indexOf(',') < 0)
- return null;
-
- try {
- x = Integer.parseInt(pref.substring(0, pref.indexOf(',')));
- y = Integer.parseInt(pref.substring(pref.indexOf(',') + 1));
- } catch (NumberFormatException e) {
- return null;
- }
- return new Dimension(x, y);
- }
-
-
- public boolean isWindowMaximized(Class<?> c) {
- String pref = PREFNODE.node("windows").get("size." + c.getCanonicalName(), null);
- return "max".equals(pref);
- }
-
- public void setWindowSize(Class<?> c, Dimension d) {
- PREFNODE.node("windows").put("size." + c.getCanonicalName(), "" + d.width + "," + d.height);
- storeVersion();
- }
-
- public void setWindowMaximized(Class<?> c) {
- PREFNODE.node("windows").put("size." + c.getCanonicalName(), "max");
- storeVersion();
- }
-
- /**
- * this class returns a java.awt.Color object for the specified key.
- * you can pass (java.awt.Color) null to the second argument to
- * disambiguate
- */
- public Color getColor( String key, Color defaultValue ) {
- net.sf.openrocket.util.Color c = super.getColor(key, (net.sf.openrocket.util.Color) null);
- if ( c == null ) {
- return defaultValue;
- }
- return ColorConversion.toAwtColor(c);
- }
-
- /**
- *
- */
- public void putColor( String key, Color value ) {
- net.sf.openrocket.util.Color c = ColorConversion.fromAwtColor(value);
- super.putColor(key, c);
- }
-
- //// Printing
-
-
- //// Background flight data computation
-
- public boolean computeFlightInBackground() {
- return PREFNODE.getBoolean("backgroundFlight", true);
- }
-
- public Simulation getBackgroundSimulation(Rocket rocket) {
- Simulation s = new Simulation(rocket);
- SimulationOptions cond = s.getOptions();
-
- cond.setTimeStep(RK4SimulationStepper.RECOMMENDED_TIME_STEP * 2);
- cond.setWindSpeedAverage(1.0);
- cond.setWindSpeedDeviation(0.1);
- cond.setLaunchRodLength(5);
- return s;
- }
-
-
-
- ///////// Export variables
-
- public boolean isExportSelected(FlightDataType type) {
- Preferences prefs = PREFNODE.node("exports");
- return prefs.getBoolean(type.getName(), false);
- }
-
- public void setExportSelected(FlightDataType type, boolean selected) {
- Preferences prefs = PREFNODE.node("exports");
- prefs.putBoolean(type.getName(), selected);
- }
-
-
-
- ///////// Default unit storage
-
- public void loadDefaultUnits() {
- Preferences prefs = PREFNODE.node("units");
- try {
-
- for (String key : prefs.keys()) {
- UnitGroup group = UnitGroup.UNITS.get(key);
- if (group == null)
- continue;
-
- try {
- group.setDefaultUnit(prefs.get(key, null));
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- } catch (BackingStoreException e) {
- ExceptionHandler.handleErrorCondition(e);
- }
- }
-
- public void storeDefaultUnits() {
- Preferences prefs = PREFNODE.node("units");
-
- for (String key : UnitGroup.UNITS.keySet()) {
- UnitGroup group = UnitGroup.UNITS.get(key);
- if (group == null || group.getUnitCount() < 2)
- continue;
-
- prefs.put(key, group.getDefaultUnit().getUnit());
- }
- }
-
-
-
- //// Material storage
-
-
- /**
- * Add a user-defined material to the preferences. The preferences are
- * first checked for an existing material matching the provided one using
- * {@link Material#equals(Object)}.
- *
- * @param m the material to add.
- */
- public void addUserMaterial(Material m) {
- Preferences prefs = PREFNODE.node("userMaterials");
-
-
- // Check whether material already exists
- if (getUserMaterials().contains(m)) {
- return;
- }
-
- // Add material using next free key (key is not used when loading)
- String mat = m.toStorableString();
- for (int i = 0;; i++) {
- String key = "material" + i;
- if (prefs.get(key, null) == null) {
- prefs.put(key, mat);
- return;
- }
- }
- }
-
-
- /**
- * Remove a user-defined material from the preferences. The matching is performed
- * using {@link Material#equals(Object)}.
- *
- * @param m the material to remove.
- */
- public void removeUserMaterial(Material m) {
- Preferences prefs = PREFNODE.node("userMaterials");
-
- try {
-
- // Iterate through materials and remove all keys with a matching material
- for (String key : prefs.keys()) {
- String value = prefs.get(key, null);
- try {
-
- Material existing = Material.fromStorableString(value, true);
- if (existing.equals(m)) {
- prefs.remove(key);
- }
-
- } catch (IllegalArgumentException ignore) {
- }
-
- }
-
- } catch (BackingStoreException e) {
- throw new IllegalStateException("Cannot read preferences!", e);
- }
- }
-
-
- /**
- * Return a set of all user-defined materials in the preferences. The materials
- * are created marked as user-defined.
- *
- * @return a set of all user-defined materials.
- */
- public Set<Material> getUserMaterials() {
- Preferences prefs = PREFNODE.node("userMaterials");
-
- HashSet<Material> materials = new HashSet<Material>();
- try {
-
- for (String key : prefs.keys()) {
- String value = prefs.get(key, null);
- try {
-
- Material m = Material.fromStorableString(value, true);
- materials.add(m);
-
- } catch (IllegalArgumentException e) {
- log.warn("Illegal material string " + value);
- }
-
- }
-
- } catch (BackingStoreException e) {
- throw new IllegalStateException("Cannot read preferences!", e);
- }
-
- return materials;
- }
-
-
- //// Helper methods
-
-}
import java.util.List;
import junit.framework.TestCase;
+import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
-import net.sf.openrocket.util.Prefs;
/**
* A base class for the Rocksim tests. Includes code from the junitx.addons project.
@Override
protected void setUp() throws Exception {
super.setUp();
- Application.setPreferences( new Prefs() );
+ Application.setPreferences( new SwingPreferences() );
}
package net.sf.openrocket.util.BaseTestCase;\r
\r
+import net.sf.openrocket.gui.util.SwingPreferences;\r
import net.sf.openrocket.startup.Application;\r
-import net.sf.openrocket.util.Prefs;\r
\r
import org.junit.BeforeClass;\r
\r
@BeforeClass\r
public static void setUpApplication () {\r
\r
- Application.setPreferences( new Prefs() );\r
+ Application.setPreferences( new SwingPreferences() );\r
\r
}\r
}\r