b0b31b35e70202a308e83a0e6ffd309a97bef25b
[debian/openrocket] / src / net / sf / openrocket / gui / print / PrintSimulationWorker.java
1 /*
2  * PrintSimulationWorker.java
3  */
4 package net.sf.openrocket.gui.print;
5
6 import net.sf.openrocket.document.Simulation;
7 import net.sf.openrocket.gui.main.SimulationWorker;
8 import net.sf.openrocket.simulation.FlightData;
9
10 /**
11  * A SimulationWorker that simulates the rocket flight in the background and sets the results to the extra text when
12  * finished.  The worker can be cancelled if necessary.
13  */
14 public class PrintSimulationWorker {
15
16     public static FlightData doit (Simulation sim) {
17         return new InnerPrintSimulationWorker(sim).doit();
18     }
19
20     static class InnerPrintSimulationWorker extends SimulationWorker {
21
22         public InnerPrintSimulationWorker (Simulation sim) {
23             super(sim);
24         }
25
26         public FlightData doit() {
27             return doInBackground();
28         }
29         @Override
30         protected void simulationDone () {
31             // Do nothing if cancelled
32             if (isCancelled()) {
33                 return;
34             }
35
36             simulation.getSimulatedData();
37         }
38
39         
40         /**
41          * Called if the simulation is interrupted due to an exception.
42          *
43          * @param t the Throwable that caused the interruption
44          */
45         @Override
46         protected void simulationInterrupted (final Throwable t) {
47         }
48     }
49 }