| 1 | package tmcsim.simulationmanager.actions; |
|---|
| 2 | |
|---|
| 3 | import java.awt.event.ActionEvent; |
|---|
| 4 | |
|---|
| 5 | import javax.swing.AbstractAction; |
|---|
| 6 | import javax.swing.JOptionPane; |
|---|
| 7 | |
|---|
| 8 | import tmcsim.common.ScriptException; |
|---|
| 9 | import tmcsim.common.SimulationException; |
|---|
| 10 | import tmcsim.simulationmanager.SimulationManagerView; |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * StartSimulationAction is an AbstractAction that is used for starting |
|---|
| 14 | * the simulation. When the action is performed, |
|---|
| 15 | * the action calls the SimulationManagerModel to start the |
|---|
| 16 | * simulation. |
|---|
| 17 | * @author Matthew Cechini |
|---|
| 18 | */ |
|---|
| 19 | @SuppressWarnings("serial") |
|---|
| 20 | public class StartSimulationAction extends AbstractAction { |
|---|
| 21 | |
|---|
| 22 | /** Reference to the SimulationManagerView object. */ |
|---|
| 23 | private SimulationManagerView theSimManagerView = null; |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | * Constructor. |
|---|
| 27 | * @param View class object for the Simulation Manager. |
|---|
| 28 | */ |
|---|
| 29 | public StartSimulationAction(SimulationManagerView view) { |
|---|
| 30 | super("Start"); |
|---|
| 31 | |
|---|
| 32 | theSimManagerView = view; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | public void actionPerformed(ActionEvent evt) { |
|---|
| 36 | Runnable startRunnable = new Runnable(){ |
|---|
| 37 | public void run() |
|---|
| 38 | { |
|---|
| 39 | // Remove this check because Paramics is no longer used as of 2017 |
|---|
| 40 | // if(!theSimManagerView.isConnectedToParamics()) { |
|---|
| 41 | // if (JOptionPane.showConfirmDialog(null, "Connection has not been " + |
|---|
| 42 | // "made to the Paramics Traffic Modeler. Do you wish " + |
|---|
| 43 | // "to continue?", "Paramics Connection", |
|---|
| 44 | // JOptionPane.YES_NO_OPTION, |
|---|
| 45 | // JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) { |
|---|
| 46 | // return; |
|---|
| 47 | // } |
|---|
| 48 | // } |
|---|
| 49 | |
|---|
| 50 | try { |
|---|
| 51 | theSimManagerView.getModel().startSimulation(); |
|---|
| 52 | } |
|---|
| 53 | catch (ScriptException se) { |
|---|
| 54 | theSimManagerView.ScriptExceptionHandler(se); |
|---|
| 55 | } |
|---|
| 56 | catch (SimulationException se) { |
|---|
| 57 | theSimManagerView.SimulationExceptionHandler(se); |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | Thread theThread = new Thread(startRunnable); |
|---|
| 63 | theThread.start(); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | } |
|---|