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

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

Initial Import of project files

Line 
1package tmcsim.simulationmanager.actions;
2
3import java.awt.event.ActionEvent;
4import java.util.logging.Level;
5import java.util.logging.Logger;
6
7import javax.swing.AbstractAction;
8import javax.swing.JSpinner;
9import javax.swing.SpinnerNumberModel;
10
11import tmcsim.common.ScriptException;
12import tmcsim.common.SimulationException;
13import tmcsim.common.CADEnums.PARAMICS_STATUS;
14import tmcsim.simulationmanager.SimulationManagerView;
15
16/**
17 * LoadParamicsNetworkAction is an AbstractAction that is used for loading
18 * a Paramics traffic network.  When the action is performed, the action gets
19 * the network ID from the NetworkIDSpinner in the SimulationManagerView.  The
20 * action sets the paramics status to SENDING_NETWORK_ID and calls the
21 * SimulationManagerModel to load the Paramics network.
22 * <br/>
23 * <br/>
24 * The NETWORK_ID_SPINNER key should be assigned the NetworkIDSpinner object
25 * from the SimulationManagerView object.
26 * @author Matthew Cechini
27 */
28@SuppressWarnings("serial")
29public class LoadParamicsNetworkAction extends AbstractAction {
30   
31    /**
32     * This key string is used to reference the NetworkIDSpinner object
33     * from the SimulationManagerView object.
34     */
35    public static final String NETWORK_ID_SPINNER = "NETWORK_ID_SPINNER";
36   
37    /** Reference to the SimulationManagerView object. */
38    private SimulationManagerView theSimManagerView = null;
39   
40    /**
41     * Constructor.
42     * @param view View class object for the Simulation Manager.
43     */ 
44    public LoadParamicsNetworkAction(SimulationManagerView view) {
45        super("Load Network");
46       
47        theSimManagerView = view;
48    }
49
50    public void actionPerformed(ActionEvent evt) {
51        if(getValue(NETWORK_ID_SPINNER) == null) {
52            Logger.getLogger("tmcsim.simulationmanager.actions").logp(
53                    Level.WARNING, "LoadParamicsNetworkAction", 
54                    "actionPerformed", 
55                    "Object for NETWORK_ID_SPINNER is null.");
56            return;
57        }
58       
59        Runnable loadNetworkRunnable = new Runnable(){     
60            public void run() { 
61                try { 
62               
63                    int id = ((SpinnerNumberModel) ((JSpinner) getValue(NETWORK_ID_SPINNER))
64                            .getModel()).getNumber().intValue();
65                   
66                    theSimManagerView.setParamicsStatus(
67                            PARAMICS_STATUS.SENDING_NETWORK_ID);
68                           
69                    theSimManagerView.getModel().loadParamicsNetwork(id);
70                     
71                }
72                catch (NumberFormatException nfe) {
73                    theSimManagerView.ScriptExceptionHandler(
74                            new ScriptException("Invalid Network ID"));
75                }
76                catch (ScriptException se) {
77                    theSimManagerView.ScriptExceptionHandler(se);
78                }
79                catch (SimulationException se) {
80                    theSimManagerView.SimulationExceptionHandler(se);   
81                }           
82            }
83        };
84
85        Thread theThread = new Thread(loadNetworkRunnable);
86        theThread.start();
87    }
88
89}
Note: See TracBrowser for help on using the repository browser.