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

source: tmcsimulator/trunk/src/tmcsim/simulationmanager/actions/LoadScriptAction.java @ 658

Revision 658, 2.4 KB checked in by jdalbey, 4 years ago (diff)

Replace hard-code scenario folder name in Simulation Manager with config property.

RevLine 
1package tmcsim.simulationmanager.actions;
2
3import java.awt.event.ActionEvent;
4import java.io.File;
5
6import javax.swing.AbstractAction;
7import javax.swing.JFileChooser;
8import javax.swing.SwingUtilities;
9
10import tmcsim.common.ScriptException;
11import tmcsim.common.SimulationException;
12import tmcsim.simulationmanager.SimulationManager;
13import tmcsim.simulationmanager.SimulationManagerView;
14import tmcsim.simulationmanager.model.XmlFilter;
15
16/**
17 * LoadScriptAction is an AbstractAction that is used for loading a
18 * simulation script.  When the action is performed, the action opens
19 * a file chooser dialog.  If the user chooses a file, the action calls the
20 * SimulationMAnagerModel to load the script file.
21 * @author Matthew Cechini
22 */ 
23@SuppressWarnings("serial")
24public class LoadScriptAction 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 LoadScriptAction(SimulationManagerView view) {
34        super("Load Script");
35       
36        theSimManagerView = view;       
37    }
38   
39    public void actionPerformed(ActionEvent evt) {
40        SwingUtilities.invokeLater(new Runnable(){     
41            public void run() { 
42                JFileChooser chooser = new JFileChooser(SimulationManager.SCENARIOS_DIR);
43               
44                chooser.setDialogTitle("Open Simulation Scenario File");
45                chooser.setMultiSelectionEnabled(false);       
46                chooser.setFileFilter(new XmlFilter());
47       
48                int result = chooser.showOpenDialog(null);
49               
50                File selectedFile = chooser.getSelectedFile();
51               
52                if(result == JFileChooser.APPROVE_OPTION) {
53               
54                    try{ 
55                        theSimManagerView.getModel().loadScript(selectedFile);
56                        theSimManagerView.setTitle("Simulation Manager: " + selectedFile.getName());
57                    }
58                    catch (ScriptException se) {
59                        theSimManagerView.ScriptExceptionHandler(se);
60                    }
61                    catch (SimulationException se) {
62                        theSimManagerView.SimulationExceptionHandler(se);   
63                    }
64                }
65            }
66        });
67    }
68
69}
Note: See TracBrowser for help on using the repository browser.