Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/simulationmanager/actions/ConnectToParamicsAction.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/tmcsim/simulationmanager/actions/ConnectToParamicsAction.java @ 2

Revision 2, 2.8 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

RevLine 
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.common.CADEnums.PARAMICS_STATUS;
10import tmcsim.simulationmanager.SimulationManagerView;
11
12/**
13 * ConnectToParamicsAction is an AbstractAction that is used for connecting
14 * and disconnecting to/from the Paramics traffic modeler.  When the action
15 * is performed, the action determines whether a connection currently exists.
16 * If no connection has been made, the paramics status is set to CONNECTING and
17 * the SimulationManagerModel is called to connect to the Paramics communicator.
18 * If a connection has been made, the action prompts the user to confirm the
19 * disconnection and then calls the SimulationManagerModel to disconnect from
20 * Paramics.
21 * @author Matthew Cechini
22 */
23@SuppressWarnings("serial")
24public class ConnectToParamicsAction extends AbstractAction {
25
26    /** Reference to the SimulationManagerView object. */
27    private SimulationManagerView theSimManagerView = null;
28   
29    /**
30     * Constructor.
31     * @param view View class object for the Simulation Manager.
32     */     
33    public ConnectToParamicsAction(SimulationManagerView view) {
34        super("Connect to Paramics");
35       
36        theSimManagerView = view;
37    }
38   
39    public void actionPerformed(ActionEvent evt) {
40        Runnable connectRunnable = new Runnable(){     
41            public void run() { 
42                if(!theSimManagerView.isConnectedToParamics()) {
43                    try{ 
44                        theSimManagerView.setParamicsStatus(PARAMICS_STATUS.CONNECTING);
45                       
46                        theSimManagerView.getModel().connectToParamics();               
47                    }
48                    catch (SimulationException se) {
49                        theSimManagerView.SimulationExceptionHandler(se);   
50                    }
51                }
52                else {   
53                    if(JOptionPane.showConfirmDialog(null, 
54                            "Disconnecting from paramics will require \n" +
55                            "  restarting the Paramics Communicator.  \n" +
56                            "           Do you wish to continue?") == JOptionPane.YES_OPTION) {
57                       
58                        try { 
59                            theSimManagerView.getModel().disconnectFromParamics();                 
60                        }
61                        catch (SimulationException se) {
62                            theSimManagerView.SimulationExceptionHandler(se);   
63                        }                   
64                    }
65                }           
66            }
67        };
68
69        Thread theThread = new Thread(connectRunnable);
70        theThread.start();
71    }
72
73}
Note: See TracBrowser for help on using the repository browser.