source: tmcsimulator/trunk/src/tmcsim/simulationmanager/actions/GotoTimeIndexAction.java @ 559

Revision 559, 2.9 KB checked in by jdalbey, 6 years ago (diff)

Change hardcoded "scripts" as name of folder to a constant in SimulationManager?. See #228.

Line 
1package tmcsim.simulationmanager.actions;
2
3import java.awt.event.ActionEvent;
4
5import javax.swing.AbstractAction;
6import javax.swing.JOptionPane;
7
8import tmcsim.common.SimulationException;
9import tmcsim.simulationmanager.SimulationManagerView;
10import tmcsim.simulationmanager.dialogs.GotoTimeIndexDialog;
11
12/**
13 * GotoTimeIndexAction is an AbstractAction that is used for moving the
14 * simulation to a new time mark.  When the action is performed, the action
15 * shows the GotoTimeIndexDialog to prompt the user for a new time mark.
16 * If the user chooses a new time, the action asks the user to confirm
17 * the Goto action and then calls the SimulationManagerModel to pause,
18 * reset, and then goto the new simulation time.  This is is done
19 * to ensure the current simulation is paused, to clear all current
20 * incident info from the view, and then to reset the simulation time.
21 * Currently this action is invoked from "File>GoTo" menu.
22 * @author Matthew Cechini
23 */
24@SuppressWarnings("serial")
25public class GotoTimeIndexAction extends AbstractAction {
26   
27    /** Reference to the SimulationManagerView object. */
28    private SimulationManagerView theSimManagerView = null;
29   
30    /**
31     * Constructor.
32     * @param view View class object for the Simulation Manager.
33     */
34    public GotoTimeIndexAction(SimulationManagerView view) {
35        super("Goto");
36       
37        theSimManagerView = view;       
38    }
39   
40    public void actionPerformed(ActionEvent evt) {
41        Runnable gotoRunnable = new Runnable() {
42            public void run() {
43
44                try {                   
45                    GotoTimeIndexDialog gotoDialog = 
46                        new GotoTimeIndexDialog(null, theSimManagerView.getCurrentSimTime());
47                   
48                    if(gotoDialog.gotoApplied) {
49                       
50                        String gotoValue = gotoDialog.getGotoTime();
51                       
52                        if(JOptionPane.showConfirmDialog(null, 
53                                "Do you wish to reposition the simulation time to " + gotoValue,
54                                "Confirm Goto",
55                                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) 
56                        {       
57                            theSimManagerView.getModel().pauseSimulation();
58                            theSimManagerView.getModel().resetSimulation();                 
59                            theSimManagerView.getModel().gotoSimulationTime(
60                                    SimulationManagerView.stringTimeToLong(gotoValue));
61                        }
62                    }
63                }
64                catch (SimulationException se) {
65                    theSimManagerView.SimulationExceptionHandler(se);
66                }
67            }
68        };
69       
70        Thread theThread = new Thread(gotoRunnable);
71        theThread.start();
72    }
73
74}
Note: See TracBrowser for help on using the repository browser.