Initial commit
[debian/openrocket] / src / net / sf / openrocket / simulation / listeners / InterruptListener.java
1 package net.sf.openrocket.simulation.listeners;
2
3 import java.util.Collection;
4
5 import net.sf.openrocket.simulation.FlightEvent;
6 import net.sf.openrocket.simulation.SimulationStatus;
7 import net.sf.openrocket.simulation.exception.SimulationCancelledException;
8
9
10 /**
11  * A simulation listener that throws a {@link SimulationCancelledException} if
12  * this thread has been interrupted.  The conditions is checked every time a step
13  * is taken.
14  * 
15  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
16  */
17 public class InterruptListener extends AbstractSimulationListener {
18         
19         public static final InterruptListener INSTANCE = new InterruptListener();
20
21         @Override
22         public Collection<FlightEvent> stepTaken(SimulationStatus status) 
23         throws SimulationCancelledException {
24
25                 if (Thread.interrupted()) {
26                         throw new SimulationCancelledException("The simulation was interrupted.");
27                 }
28
29                 return null;
30         }
31 }