major optimization updates
[debian/openrocket] / src / net / sf / openrocket / gui / main / SimulationRunDialog.java
index c37ceef22d6b8ba9c05182a1e35b5a858ad515bf..1788515e78f62b0a16beb18e43d9145cd4994d8b 100644 (file)
@@ -25,6 +25,7 @@ import javax.swing.JProgressBar;
 import net.miginfocom.swing.MigLayout;
 import net.sf.openrocket.document.Simulation;
 import net.sf.openrocket.gui.dialogs.DetailDialog;
+import net.sf.openrocket.l10n.Translator;
 import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.rocketcomponent.Configuration;
 import net.sf.openrocket.rocketcomponent.MotorMount;
@@ -46,7 +47,9 @@ import net.sf.openrocket.util.Prefs;
 
 public class SimulationRunDialog extends JDialog {
        private static final LogHelper log = Application.getLogger();
+       private static final Translator trans = Application.getTranslator();
        
+
        /** Update the dialog status every this many ms */
        private static final long UPDATE_MS = 200;
        
@@ -69,7 +72,13 @@ public class SimulationRunDialog extends JDialog {
        private final JProgressBar progressBar;
        
 
+       /*
+        * NOTE:  Care must be used when accessing the simulation parameters, since they
+        * are being run in another thread.  Mutexes are used to avoid concurrent usage, which
+        * will result in an exception being thrown!
+        */
        private final Simulation[] simulations;
+       private final String[] simulationNames;
        private final SimulationWorker[] simulationWorkers;
        private final SimulationStatus[] simulationStatuses;
        private final double[] simulationMaxAltitude;
@@ -77,7 +86,8 @@ public class SimulationRunDialog extends JDialog {
        private final boolean[] simulationDone;
        
        public SimulationRunDialog(Window window, Simulation... simulations) {
-               super(window, "Running simulations...", Dialog.ModalityType.DOCUMENT_MODAL);
+               //// Running simulations...
+               super(window, trans.get("SimuRunDlg.title.RunSim"), Dialog.ModalityType.DOCUMENT_MODAL);
                
                if (simulations.length == 0) {
                        throw new IllegalArgumentException("Called with no simulations to run");
@@ -85,8 +95,15 @@ public class SimulationRunDialog extends JDialog {
                
                this.simulations = simulations;
                
+
+               // Randomize the simulation random seeds
+               for (Simulation sim : simulations) {
+                       sim.getOptions().randomizeSeed();
+               }
+               
                // Initialize the simulations
                int n = simulations.length;
+               simulationNames = new String[n];
                simulationWorkers = new SimulationWorker[n];
                simulationStatuses = new SimulationStatus[n];
                simulationMaxAltitude = new double[n];
@@ -94,6 +111,7 @@ public class SimulationRunDialog extends JDialog {
                simulationDone = new boolean[n];
                
                for (int i = 0; i < n; i++) {
+                       simulationNames[i] = simulations[i].getName();
                        simulationWorkers[i] = new InteractiveSimulationWorker(simulations[i], i);
                        executor.execute(simulationWorkers[i]);
                }
@@ -101,18 +119,21 @@ public class SimulationRunDialog extends JDialog {
                // Build the dialog
                JPanel panel = new JPanel(new MigLayout("fill", "[][grow]"));
                
-               simLabel = new JLabel("Running ...");
+               //// Running ...
+               simLabel = new JLabel(trans.get("SimuRunDlg.lbl.Running"));
                panel.add(simLabel, "spanx, wrap para");
-               
-               panel.add(new JLabel("Simulation time: "), "gapright para");
+               //// Simulation time: 
+               panel.add(new JLabel(trans.get("SimuRunDlg.lbl.Simutime") + " "), "gapright para");
                timeLabel = new JLabel("");
                panel.add(timeLabel, "growx, wrap rel");
                
-               panel.add(new JLabel("Altitude: "));
+               //// Altitude:
+               panel.add(new JLabel(trans.get("SimuRunDlg.lbl.Altitude") + " "));
                altLabel = new JLabel("");
                panel.add(altLabel, "growx, wrap rel");
                
-               panel.add(new JLabel("Velocity: "));
+               //// Velocity:
+               panel.add(new JLabel(trans.get("SimuRunDlg.lbl.Velocity") + " "));
                velLabel = new JLabel("");
                panel.add(velLabel, "growx, wrap para");
                
@@ -121,7 +142,7 @@ public class SimulationRunDialog extends JDialog {
                
 
                // Add cancel button
-               JButton cancel = new JButton("Cancel");
+               JButton cancel = new JButton(trans.get("dlg.but.cancel"));
                cancel.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -201,7 +222,7 @@ public class SimulationRunDialog extends JDialog {
                log.debug("Progressbar value " + progress);
                
                // Update the simulation fields
-               simLabel.setText("Running " + simulations[index].getName());
+               simLabel.setText("Running " + simulationNames[index]);
                if (simulationStatuses[index] == null) {
                        log.debug("No simulation status data available, setting empty labels");
                        timeLabel.setText("");
@@ -257,7 +278,7 @@ public class SimulationRunDialog extends JDialog {
                        double launchBurn = 0;
                        double otherBurn = 0;
                        Configuration config = simulation.getConfiguration();
-                       String id = simulation.getConditions().getMotorConfigurationID();
+                       String id = simulation.getOptions().getMotorConfigurationID();
                        Iterator<MotorMount> iterator = config.motorIterator();
                        while (iterator.hasNext()) {
                                MotorMount m = iterator.next();
@@ -372,7 +393,8 @@ public class SimulationRunDialog extends JDialog {
                                
                                DetailDialog.showDetailedMessageDialog(SimulationRunDialog.this,
                                                new Object[] {
-                                                               "Unable to simulate:",
+                                                               //// Unable to simulate:
+                                                               trans.get("SimuRunDlg.msg.Unabletosim"),
                                                                t.getMessage()
                                                },
                                                null, simulation.getName(), JOptionPane.ERROR_MESSAGE);
@@ -381,7 +403,8 @@ public class SimulationRunDialog extends JDialog {
                                
                                DetailDialog.showDetailedMessageDialog(SimulationRunDialog.this,
                                                new Object[] {
-                                                               "A error occurred during the simulation:",
+                                                               //// A error occurred during the simulation:
+                                                               trans.get("SimuRunDlg.msg.errorOccurred"),
                                                                t.getMessage()
                                                },
                                                stackTrace, simulation.getName(), JOptionPane.ERROR_MESSAGE);
@@ -392,10 +415,11 @@ public class SimulationRunDialog extends JDialog {
                                t.printStackTrace();
                                DetailDialog.showDetailedMessageDialog(SimulationRunDialog.this,
                                                new Object[] {
-                                                               "An exception occurred during the simulation:",
+                                                               //// An exception occurred during the simulation:
+                                                               trans.get("SimuRunDlg.msg.AnException1"),
                                                                t.getMessage(),
                                                                simulation.getSimulationListeners().isEmpty() ?
-                                                                               "Please report this as a bug along with the details below." : ""
+                                                                               trans.get("SimuRunDlg.msg.AnException2") : ""
                                                },
                                                stackTrace, simulation.getName(), JOptionPane.ERROR_MESSAGE);
                                
@@ -404,8 +428,10 @@ public class SimulationRunDialog extends JDialog {
                                t.printStackTrace();
                                DetailDialog.showDetailedMessageDialog(SimulationRunDialog.this,
                                                new Object[] {
-                                                               "A computation error occurred during the simulation.",
-                                                               "Please report this as a bug along with the details below."
+                                                               //// A computation error occurred during the simulation.
+                                                               trans.get("SimuRunDlg.msg.AssertionError1"),
+                                                               //// Please report this as a bug along with the details below.
+                                                               trans.get("SimuRunDlg.msg.AssertionError2")
                                                },
                                                stackTrace, simulation.getName(), JOptionPane.ERROR_MESSAGE);
                                
@@ -414,9 +440,10 @@ public class SimulationRunDialog extends JDialog {
                                // Probably an Error
                                DetailDialog.showDetailedMessageDialog(SimulationRunDialog.this,
                                                new Object[] {
-                                                               "An unknown error was encountered during the simulation.",
-                                                               "The program may be unstable, you should save all your designs " +
-                                                                               "and restart OpenRocket now!"
+                                                               //// An unknown error was encountered during the simulation.
+                                                               trans.get("SimuRunDlg.msg.unknownerror1"),
+                                                               //// The program may be unstable, you should save all your designs and restart OpenRocket now!
+                                                               trans.get("SimuRunDlg.msg.unknownerror2")
                                                },
                                                stackTrace, simulation.getName(), JOptionPane.ERROR_MESSAGE);