version 1.1.9
[debian/openrocket] / src / net / sf / openrocket / gui / main / SimulationRunDialog.java
index 9b94ec615c58ae282b792121109b816e3a0cb651..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;
        
@@ -83,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");
@@ -91,6 +93,12 @@ 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];
@@ -109,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");
                
@@ -129,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) {
@@ -265,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();
@@ -369,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);
@@ -389,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);