View Javadoc

1   /*
2    * @(#) CloseExperiment.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.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 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  public class CloseExperimentAction extends AbstractAction implements
41  		EventListenerInterface
42  {
43  	/*** the parent */
44  	private DSOLApplicationInterface application = null;
45  
46  	/***
47  	 * constructs a new OpenFileAction
48  	 * 
49  	 * @param application the parent application
50  	 */
51  	public CloseExperimentAction(final DSOLApplicationInterface application)
52  	{
53  		super("Close");
54  		this.application = application;
55  		this.putValue(Action.MNEMONIC_KEY, new Integer('s'));
56  		this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
57  				KeyEvent.VK_F4, InputEvent.CTRL_DOWN_MASK));
58  		this.setEnabled(false);
59  		try
60  		{
61  			this.application.addListener(this,
62  					DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT);
63  			this.notify(new Event(
64  					DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT,
65  					this.application, this.application.getExperiment()));
66  		} catch (RemoteException exception)
67  		{
68  			Logger.warning(this, "CloseExperimentAction", exception);
69  		}
70  	}
71  
72  	/***
73  	 * @see java.awt.event.ActionListener
74  	 *      #actionPerformed(java.awt.event.ActionEvent)
75  	 */
76  	public void actionPerformed(final ActionEvent event)
77  	{
78  		this.application.setExperiment(null);
79  	}
80  
81  	/***
82  	 * @see nl.tudelft.simulation.event.EventListenerInterface
83  	 *      #notify(nl.tudelft.simulation.event.EventInterface)
84  	 */
85  	public void notify(final EventInterface event)
86  	{
87  		if (event.getSource().equals(this.application)
88  				&& event.getType().equals(
89  						DSOLApplicationInterface.EXPERIMENT_CHANGED_EVENT))
90  		{
91  			if (event.getContent() == null)
92  			{
93  				this.setEnabled(false);
94  			} else
95  			{
96  				this.setEnabled(true);
97  			}
98  		}
99  	}
100 }