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 @ 6

Revision 6, 2.4 KB checked in by jdalbey, 10 years ago (diff)

Multifile commit. Add version # to Paramics Communicator. Move Load button in Sim Mgr. Add several tests. Add package jars target.

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.SimulationManagerView;
13import tmcsim.simulationmanager.model.XmlFilter;
14
15/**
16 * LoadScriptAction is an AbstractAction that is used for loading a
17 * simulation script.  When the action is performed, the action opens
18 * a file chooser dialog.  If the user chooses a file, the action calls the
19 * SimulationMAnagerModel to load the script file.
20 * @author Matthew Cechini
21 */ 
22@SuppressWarnings("serial")
23public class LoadScriptAction extends AbstractAction {
24   
25    /** Reference to the SimulationManagerView object. */
26    private SimulationManagerView theSimManagerView = null;
27   
28    /**
29     * Constructor.
30     * @param view View class object for the Simulation Manager.
31     */ 
32    public LoadScriptAction(SimulationManagerView view) {
33        super("Load Script");
34       
35        theSimManagerView = view;       
36    }
37   
38    public void actionPerformed(ActionEvent evt) {
39        SwingUtilities.invokeLater(new Runnable(){     
40            public void run() { 
41                JFileChooser chooser = new JFileChooser(
42                        SimulationManagerView.SCRIPT_DIR);
43               
44                chooser.setDialogTitle("Open Simulation Script 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.