View Javadoc

1   /*
2    * @(#) OpenURLAction.java Oct 23, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
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 2003 <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/gpl.html">General Public
34   * License (GPL) </a>, no warranty <br>
35   * 
36   * @version 1.0 18.10.2003 <br>
37   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
38   *         Jacobs </a>
39   */
40  
41  public class OpenURLAction extends AbstractAction implements
42  		EventListenerInterface
43  {
44  	/*** the parent */
45  	private DSOLApplicationInterface application = null;
46  
47  	/***
48  	 * constructs a new OpenURLAction
49  	 * 
50  	 * @param application the parent application
51  	 */
52  	public OpenURLAction(final DSOLApplicationInterface application)
53  	{
54  		super("Open URL");
55  		this.application = application;
56  		this.putValue(Action.MNEMONIC_KEY, new Integer('U'));
57  		this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('U',
58  				InputEvent.CTRL_DOWN_MASK));
59  		this.setEnabled(false);
60  		try
61  		{
62  			this.application.addListener(this,
63  					DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT);
64  			this.notify(new Event(
65  					DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT,
66  					this.application, this.application.getExperiment()));
67  		} catch (RemoteException exception)
68  		{
69  			Logger.warning(this, "OpenURLAction", exception);
70  		}
71  	}
72  
73  	/***
74  	 * @see java.awt.event.ActionListener
75  	 *      #actionPerformed(java.awt.event.ActionEvent)
76  	 */
77  	public void actionPerformed(final ActionEvent event)
78  	{
79  		new URLChooserFrame(this.application);
80  	}
81  
82  	/***
83  	 * @see java.lang.Object#finalize()
84  	 */
85  	protected void finalize() throws Throwable
86  	{
87  		this.application.removeListener(this,
88  				DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT);
89  		super.finalize();
90  	}
91  
92  	/***
93  	 * @see nl.tudelft.simulation.event.EventListenerInterface
94  	 *      #notify(nl.tudelft.simulation.event.EventInterface)
95  	 */
96  	public void notify(final EventInterface event)
97  	{
98  		if (event.getSource().equals(this.application)
99  				&& event.getType().equals(
100 						DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT))
101 		{
102 			if (event.getContent() == null)
103 			{
104 				this.setEnabled(true);
105 			} else
106 			{
107 				this.setEnabled(false);
108 			}
109 		}
110 	}
111 }