Move net.sf.openrocket.util.Prefs to net.sf.openrocket.gui.util.SwingPreferences.
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Tue, 13 Dec 2011 19:40:54 +0000 (19:40 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Tue, 13 Dec 2011 19:40:54 +0000 (19:40 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@230 180e2498-e6e9-4542-8430-84ac67f01cd8

20 files changed:
src/net/sf/openrocket/database/Databases.java
src/net/sf/openrocket/gui/components/SimulationExportPanel.java
src/net/sf/openrocket/gui/configdialog/RocketComponentConfig.java
src/net/sf/openrocket/gui/dialogs/PrintDialog.java
src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java
src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java
src/net/sf/openrocket/gui/dialogs/preferences/PreferencesDialog.java
src/net/sf/openrocket/gui/main/BasicFrame.java
src/net/sf/openrocket/gui/main/SimulationRunDialog.java
src/net/sf/openrocket/gui/print/DesignReport.java
src/net/sf/openrocket/gui/scalefigure/RocketFigure.java
src/net/sf/openrocket/gui/scalefigure/RocketPanel.java
src/net/sf/openrocket/gui/util/GUIUtil.java
src/net/sf/openrocket/gui/util/SwingPreferences.java [new file with mode: 0644]
src/net/sf/openrocket/material/MaterialStorage.java
src/net/sf/openrocket/startup/Startup.java
src/net/sf/openrocket/startup/Startup2.java
src/net/sf/openrocket/util/Prefs.java [deleted file]
test/net/sf/openrocket/file/rocksim/RocksimTestBase.java
test/net/sf/openrocket/util/BaseTestCase/BaseTestCase.java

index 2a7a38c14f6be2355aa9f07dd3942c3cc12cca12..fbb407e811a158bb817f1f40bda9f22112d760da 100644 (file)
@@ -1,12 +1,12 @@
 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;
 
 
 /**
@@ -95,7 +95,7 @@ public class Databases {
                
 
                // 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);
index 7261ad54539f1a2a8bce27fedb12ae9472b96c4e..69bc02f0d664070be34e200ebe1e05cd3abe7ab7 100644 (file)
@@ -23,6 +23,7 @@ import net.miginfocom.swing.MigLayout;
 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;
@@ -31,7 +32,6 @@ import net.sf.openrocket.simulation.FlightDataType;
 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 {
        
@@ -86,7 +86,7 @@ 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();
                }
                
@@ -193,7 +193,7 @@ public class SimulationExportPanel extends JPanel {
        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;
@@ -217,9 +217,9 @@ public class SimulationExportPanel extends JPanel {
                
                // 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++;
                }
index c007920854bf35e2faee3ade6dcc194a14b04a27..f4dfa8ba63a43f72eabe37f4e119d882c8eac970 100644 (file)
@@ -36,6 +36,7 @@ import net.sf.openrocket.gui.components.StyledLabel;
 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;
@@ -47,7 +48,6 @@ import net.sf.openrocket.startup.Application;
 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 {
        
@@ -379,7 +379,7 @@ 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
@@ -401,7 +401,7 @@ public class RocketComponentConfig extends JPanel {
                                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");
@@ -423,7 +423,7 @@ public class RocketComponentConfig extends JPanel {
                        @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) {
@@ -441,7 +441,7 @@ public class RocketComponentConfig extends JPanel {
        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;
        }
index 383e55716a679bcfe6707adb60cb5607307efae4..729586d3455e70e69423fbbc5200ab2942051360 100644 (file)
@@ -37,11 +37,11 @@ import net.sf.openrocket.gui.print.components.CheckTreeManager;
 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.
@@ -63,7 +63,7 @@ public class PrintDialog extends JDialog implements TreeSelectionListener {
        private JButton cancel;
        
        
-       private final static Prefs prefs = (Prefs) Application.getPreferences();
+       private final static SwingPreferences prefs = (SwingPreferences) Application.getPreferences();
        
        /**
         * Constructor.
@@ -330,7 +330,7 @@ public class PrintDialog extends JDialog implements TreeSelectionListener {
                        dir = dir.getParentFile();
                }
                if (dir == null) {
-                       dir = ((Prefs) Application.getPreferences()).getDefaultDirectory();
+                       dir = prefs.getDefaultDirectory();
                }
                chooser.setCurrentDirectory(dir);
                
index 3c35113d8d02073a22da3228692d8483009df998..7b978d958cd04c62258150e2594deb75ac9c3b57 100644 (file)
@@ -49,6 +49,7 @@ import net.sf.openrocket.gui.dialogs.motor.CloseableDialog;
 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;
@@ -57,7 +58,6 @@ import net.sf.openrocket.motor.ThrustCurveMotor;
 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;
@@ -234,11 +234,11 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
                //// 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();
                        }
                });
@@ -541,7 +541,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
 
 
                // 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);
                
 
@@ -585,7 +585,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
                }
                
                // 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);
@@ -815,7 +815,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
 
                // 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)) {
index 753ac2a13ef8cd40232895e657d694a98d02f66e..033da286717b9c5a8f485c52c00241831a75a003 100644 (file)
@@ -67,6 +67,7 @@ import net.sf.openrocket.gui.scalefigure.RocketFigure;
 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;
@@ -91,7 +92,6 @@ import net.sf.openrocket.unit.Value;
 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;
@@ -1236,7 +1236,7 @@ public class GeneralOptimizationDialog extends JDialog {
 
                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)
index 5f664d2816c35f6ff6e989fc76074a243174b48f..986c4a40e42e7253d971ca05e73658e6bee636a8 100644 (file)
@@ -37,6 +37,7 @@ import net.sf.openrocket.gui.components.StyledLabel;
 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;
@@ -47,7 +48,6 @@ import net.sf.openrocket.unit.Unit;
 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;
 
 
@@ -96,7 +96,7 @@ public class PreferencesDialog extends JDialog {
                this.addWindowListener(new WindowAdapter() {
                        @Override
                        public void windowClosed(WindowEvent e) {
-                               ((Prefs) Application.getPreferences()).storeDefaultUnits();
+                               ((SwingPreferences) Application.getPreferences()).storeDefaultUnits();
                        }
                });
                
@@ -115,7 +115,7 @@ public class PreferencesDialog extends JDialog {
                        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);
@@ -144,7 +144,7 @@ public class PreferencesDialog extends JDialog {
 
                //// 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
@@ -154,7 +154,7 @@ public class PreferencesDialog extends JDialog {
                
                //// 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"),
@@ -163,7 +163,7 @@ public class PreferencesDialog extends JDialog {
                //// 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) {
@@ -197,7 +197,7 @@ public class PreferencesDialog extends JDialog {
                                                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");
@@ -252,8 +252,8 @@ public class PreferencesDialog extends JDialog {
                        @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");
@@ -668,9 +668,9 @@ public class PreferencesDialog extends JDialog {
                        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());
                        }
                }
                
index ac88fe5831fa57001dc6774b9d1d448943ce387a..cb7bd5009d1cf92c104f48672db471cb9b0f6a45 100644 (file)
@@ -87,6 +87,7 @@ import net.sf.openrocket.gui.util.FileHelper;
 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;
@@ -99,7 +100,6 @@ import net.sf.openrocket.startup.Application;
 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;
 
@@ -1005,14 +1005,14 @@ public class BasicFrame extends JFrame {
                
                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));
@@ -1259,7 +1259,7 @@ public class BasicFrame extends JFrame {
                                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());
@@ -1276,7 +1276,7 @@ public class BasicFrame extends JFrame {
                        return false;
                }
                
-               ((Prefs) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
+               ((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
                storageChooser.storeOptions(document.getDefaultStorageOptions());
                
                file = FileHelper.ensureExtension(file, "ork");
index cc1be696683cec34d742763e29098d8af31a10aa..63248f531ce19dd78c5687130cdb1708c53f341c 100644 (file)
@@ -24,6 +24,7 @@ import net.miginfocom.swing.MigLayout;
 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;
@@ -40,7 +41,6 @@ import net.sf.openrocket.startup.Application;
 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 {
@@ -63,7 +63,7 @@ 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;
index 46810ba788ace2c004de858ccaa9b0267cadf2aa..886e225ad0f7b788db49ae8d5bbd5c370b4d68b3 100644 (file)
@@ -12,6 +12,7 @@ import net.sf.openrocket.document.Simulation;
 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;
@@ -29,7 +30,6 @@ import net.sf.openrocket.unit.Unit;
 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;
@@ -427,7 +427,7 @@ public class DesignReport {
                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();
index b19a8dd55c89d2881802c7003fdef7910685f043..62b6ded5de5832bcb28818ea9f1de4489fba1172 100644 (file)
@@ -21,6 +21,7 @@ import java.util.LinkedHashSet;
 
 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;
@@ -30,7 +31,6 @@ import net.sf.openrocket.util.BugException;
 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;
 
@@ -312,7 +312,7 @@ public class RocketFigure extends AbstractScaleFigure {
                        // 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);
                        
@@ -348,8 +348,8 @@ public class RocketFigure extends AbstractScaleFigure {
 
                // 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();
index 97ff7f3ef458c735b76d54792b3e029a6aaa4794..cf458724344b770483d96a12decd627fff37285e 100644 (file)
@@ -49,6 +49,7 @@ import net.sf.openrocket.gui.figureelements.Caret;
 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;
@@ -67,7 +68,6 @@ import net.sf.openrocket.util.ChangeSource;
 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;
 
 /**
@@ -121,7 +121,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
         */
        private static final Executor backgroundSimulationExecutor;
        static {
-               backgroundSimulationExecutor = Executors.newFixedThreadPool(Prefs.getMaxThreadCount(),
+               backgroundSimulationExecutor = Executors.newFixedThreadPool(SwingPreferences.getMaxThreadCount(),
                                new ThreadFactory() {
                                        private ThreadFactory factory = Executors.defaultThreadFactory();
                                        
@@ -564,7 +564,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
                ////////  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();
@@ -594,7 +594,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
                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());
                
index c66939b3fb11f21a640f12ebf82784bbcc9804c3..c796405c82eb63ef56ee053b516a8f2f7a42735d 100644 (file)
@@ -77,7 +77,6 @@ import net.sf.openrocket.startup.Application;
 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();
@@ -305,22 +304,22 @@ public class GUIUtil {
                        @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);
                        }
@@ -336,12 +335,12 @@ public class GUIUtil {
                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);
diff --git a/src/net/sf/openrocket/gui/util/SwingPreferences.java b/src/net/sf/openrocket/gui/util/SwingPreferences.java
new file mode 100644 (file)
index 0000000..951ce91
--- /dev/null
@@ -0,0 +1,598 @@
+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
+       
+}
index 6624283e89b16c5fe503d976538dbbe1d075b416..5438ece289afa057de607b5e57de97af77074b4c 100644 (file)
@@ -2,8 +2,8 @@ package net.sf.openrocket.material;
 
 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
@@ -16,13 +16,13 @@ public class MaterialStorage implements DatabaseListener<Material> {
        @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);
        }
 
 }
index be21dc75aa25edb801f8c125920906383015121c..d288ea76f660a8bd3f7a84e0ba34bc305bbe92a9 100644 (file)
@@ -4,6 +4,7 @@ import java.io.PrintStream;
 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;
@@ -13,7 +14,6 @@ import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.logging.LogLevel;
 import net.sf.openrocket.logging.LogLevelBufferLogger;
 import net.sf.openrocket.logging.PrintStreamLogger;
-import net.sf.openrocket.util.Prefs;
 
 
 /**
@@ -50,7 +50,7 @@ public class Startup {
                // Initialize logging first so we can use it
                initializeLogging();
                
-               Application.setPreferences( new Prefs() );
+               Application.setPreferences( new SwingPreferences() );
                
                // Setup the translations
                initializeL10n();
index e1c2e05d85b09284fc8e7ee841752e69acd1b80d..3c4f1dabfd72e3fec99a10d5f1fe7e4d0d1d1ce0 100644 (file)
@@ -24,12 +24,12 @@ import net.sf.openrocket.gui.main.BasicFrame;
 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
@@ -113,7 +113,7 @@ public class Startup2 {
                ToolTipManager.sharedInstance().setDismissDelay(30000);
                
                // Load defaults
-               ((Prefs) Application.getPreferences()).loadDefaultUnits();
+               ((SwingPreferences) Application.getPreferences()).loadDefaultUnits();
                
                // Load motors etc.
                log.info("Loading databases");
@@ -193,7 +193,7 @@ public class Startup2 {
                                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) {
@@ -243,7 +243,7 @@ public class Startup2 {
                                        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 &&
@@ -253,9 +253,9 @@ public class Startup2 {
                                                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());
                                                }
                                        }
                                }
diff --git a/src/net/sf/openrocket/util/Prefs.java b/src/net/sf/openrocket/util/Prefs.java
deleted file mode 100644 (file)
index d6a42fc..0000000
+++ /dev/null
@@ -1,609 +0,0 @@
-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
-       
-}
index 372b881ee13dcd13b0e36fd4ba2e26b0a52ae582..c3c38825206409dc73d3952c53fa1b2caa476d1a 100644 (file)
@@ -7,9 +7,9 @@ import java.lang.reflect.Field;
 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.
@@ -32,7 +32,7 @@ public abstract class RocksimTestBase extends TestCase {
        @Override
        protected void setUp() throws Exception {
                super.setUp();
-               Application.setPreferences( new Prefs() );
+               Application.setPreferences( new SwingPreferences() );
        }
 
 
index 5dce932484b8b8798867710cefc82f6472b1af2f..c5d1feb13faafe6ed121567e6a8d9068205b5736 100644 (file)
@@ -1,7 +1,7 @@
 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
@@ -10,7 +10,7 @@ public class BaseTestCase {
        @BeforeClass\r
        public static void setUpApplication () {\r
                \r
-               Application.setPreferences( new Prefs() );\r
+               Application.setPreferences( new SwingPreferences() );\r
                \r
        }\r
 }\r