]> git.gag.com Git - debian/openrocket/blobdiff - src/net/sf/openrocket/gui/main/SimulationRunDialog.java
version 1.1.9
[debian/openrocket] / src / net / sf / openrocket / gui / main / SimulationRunDialog.java
index c37ceef22d6b8ba9c05182a1e35b5a858ad515bf..9ac4a3690f3c86fb9d3bd63d9295026bfed47576 100644 (file)
@@ -8,8 +8,6 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
-import java.io.CharArrayWriter;
-import java.io.PrintWriter;
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
@@ -25,6 +23,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 +45,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 +70,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 +84,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 +93,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 +109,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 +117,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(timeLabel, "growx, wmin 200lp, 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 +140,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 +220,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 +276,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();
@@ -361,18 +380,13 @@ public class SimulationRunDialog extends JDialog {
                                return; // Ignore cancellations
                        }
                        
-                       // Retrieve the stack trace in a textual form
-                       CharArrayWriter arrayWriter = new CharArrayWriter();
-                       arrayWriter.append(t.toString() + "\n" + "\n");
-                       t.printStackTrace(new PrintWriter(arrayWriter));
-                       String stackTrace = arrayWriter.toString();
-                       
                        // Analyze the exception type
                        if (t instanceof SimulationLaunchException) {
                                
                                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,51 +395,21 @@ 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);
-                               
-                       } else if (t instanceof Exception) {
-                               
-                               // TODO: MEDIUM: Check the exception handling here...
-                               t.printStackTrace();
-                               DetailDialog.showDetailedMessageDialog(SimulationRunDialog.this,
-                                               new Object[] {
-                                                               "An exception occurred during the simulation:",
-                                                               t.getMessage(),
-                                                               simulation.getSimulationListeners().isEmpty() ?
-                                                                               "Please report this as a bug along with the details below." : ""
-                                               },
-                                               stackTrace, simulation.getName(), JOptionPane.ERROR_MESSAGE);
-                               
-                       } else if (t instanceof AssertionError) {
-                               
-                               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."
-                                               },
-                                               stackTrace, simulation.getName(), JOptionPane.ERROR_MESSAGE);
+                                               null, simulation.getName(), JOptionPane.ERROR_MESSAGE);
                                
                        } else {
                                
-                               // 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!"
-                                               },
-                                               stackTrace, simulation.getName(), JOptionPane.ERROR_MESSAGE);
+                               ExceptionHandler.handleErrorCondition("An exception occurred during the simulation", t);
                                
                        }
                        simulationDone();
                }
                
                
-
                private void setSimulationProgress(double p) {
                        int exact = Math.max(progress, (int) (100 * p + 0.5));
                        progress = MathUtil.clamp(exact, 0, 100);