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.rmi.RemoteException;
15
16 import javax.swing.AbstractAction;
17 import javax.swing.Action;
18 import javax.swing.KeyStroke;
19
20 import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
21 import nl.tudelft.simulation.dsol.gui.windows.URLChooserFrame;
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 OpenURL 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 OpenURLAction extends AbstractAction implements
40 EventListenerInterface
41 {
42 /*** the parent */
43 private DSOLApplicationInterface application = null;
44
45 /***
46 * constructs a new OpenURLAction
47 *
48 * @param application the parent application
49 */
50 public OpenURLAction(final DSOLApplicationInterface application)
51 {
52 super("Open URL");
53 this.application = application;
54 this.putValue(Action.MNEMONIC_KEY, new Integer('U'));
55 this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('U',
56 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, "OpenURLAction", 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 new URLChooserFrame(this.application);
78 }
79
80 /***
81 * @see java.lang.Object#finalize()
82 */
83 protected void finalize() throws Throwable
84 {
85 this.application.removeListener(this,
86 DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT);
87 super.finalize();
88 }
89
90 /***
91 * @see nl.tudelft.simulation.event.EventListenerInterface
92 * #notify(nl.tudelft.simulation.event.EventInterface)
93 */
94 public void notify(final EventInterface event)
95 {
96 if (event.getSource().equals(this.application)
97 && event.getType().equals(
98 DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT))
99 {
100 if (event.getContent() == null)
101 {
102 this.setEnabled(true);
103 } else
104 {
105 this.setEnabled(false);
106 }
107 }
108 }
109 }