1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.gui.menu.actions;
11
12 import java.awt.event.ActionEvent;
13 import java.awt.event.InputEvent;
14 import java.awt.event.KeyEvent;
15 import java.rmi.RemoteException;
16
17 import javax.swing.AbstractAction;
18 import javax.swing.Action;
19 import javax.swing.KeyStroke;
20
21 import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
22 import nl.tudelft.simulation.event.Event;
23 import nl.tudelft.simulation.event.EventInterface;
24 import nl.tudelft.simulation.event.EventListenerInterface;
25 import nl.tudelft.simulation.logger.Logger;
26
27 /***
28 * The CloseExperiment action <br>
29 * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
30 * University of Technology </a>, the Netherlands. <br>
31 * See for project information <a
32 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
33 * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
34 * General Public License (LGPL) </a>, no warranty.
35 *
36 * @version $Revision$ $Date$
37 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja">Peter Jacobs </a>
38 */
39 public class CloseExperimentAction extends AbstractAction implements
40 EventListenerInterface
41 {
42 /*** the parent */
43 private DSOLApplicationInterface application = null;
44
45 /***
46 * constructs a new OpenFileAction
47 *
48 * @param application the parent application
49 */
50 public CloseExperimentAction(final DSOLApplicationInterface application)
51 {
52 super("Close");
53 this.application = application;
54 this.putValue(Action.MNEMONIC_KEY, new Integer('s'));
55 this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
56 KeyEvent.VK_F4, InputEvent.CTRL_DOWN_MASK));
57 this.setEnabled(false);
58 try
59 {
60 this.application.addListener(this,
61 DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT);
62 this.notify(new Event(
63 DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT,
64 this.application, this.application.getExperiment()));
65 } catch (RemoteException exception)
66 {
67 Logger.warning(this, "CloseExperimentAction", exception);
68 }
69 }
70
71 /***
72 * @see java.awt.event.ActionListener
73 * #actionPerformed(java.awt.event.ActionEvent)
74 */
75 public void actionPerformed(final ActionEvent event)
76 {
77 this.application.setExperiment(null);
78 }
79
80 /***
81 * @see nl.tudelft.simulation.event.EventListenerInterface
82 * #notify(nl.tudelft.simulation.event.EventInterface)
83 */
84 public void notify(final EventInterface event)
85 {
86 if (event.getSource().equals(this.application)
87 && event.getType().equals(
88 DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT))
89 {
90 if (event.getContent() == null)
91 {
92 this.setEnabled(false);
93 } else
94 {
95 this.setEnabled(true);
96 }
97 }
98 }
99 }