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;
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;
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;
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");
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];
// 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");
// 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) {
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();
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);
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);