View Javadoc

1   /*
2    * @(#) ShowGridAction.java Oct 24, 2003
3    * 
4    * Copyright (c) 2002-2005 Delft University of Technology Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the Lesser General Public License
9    */
10  package nl.tudelft.simulation.dsol.gui.actions;
11  
12  import java.awt.event.ActionEvent;
13  
14  import javax.swing.Action;
15  import javax.swing.ImageIcon;
16  
17  import nl.tudelft.simulation.dsol.experiment.Experiment;
18  import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
19  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20  import nl.tudelft.simulation.event.EventInterface;
21  import nl.tudelft.simulation.event.EventListenerInterface;
22  
23  /***
24   * The ResetAction <br>
25   * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
26   * University of Technology </a>, the Netherlands. <br>
27   * See for project information <a
28   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
29   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
30   * General Public License (LGPL) </a>, no warranty.
31   * 
32   * @version $Revision$ $Date$
33   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja">Peter Jacobs </a>
34   */
35  public class ResetAction extends SimulatorAction implements
36  		EventListenerInterface
37  {
38  	/***
39  	 * constructs a new ShowGridAction
40  	 * 
41  	 * @param application the application
42  	 */
43  	public ResetAction(final DSOLApplicationInterface application)
44  	{
45  		super("reset", application);
46  		this.putValue(Action.SMALL_ICON, new ImageIcon(this.getClass()
47  				.getResource("/toolbarButtonGraphics/general/Undo16.gif")));
48  	}
49  
50  	/***
51  	 * @see java.awt.event.ActionListener
52  	 *      #actionPerformed(java.awt.event.ActionEvent)
53  	 */
54  	public void actionPerformed(final ActionEvent event)
55  	{
56  		Experiment experiment = this.application.getExperiment();
57  		experiment.reset();
58  	}
59  
60  	/***
61  	 * @see nl.tudelft.simulation.event.EventListenerInterface
62  	 *      #notify(nl.tudelft.simulation.event.EventInterface)
63  	 */
64  	public void notify(final EventInterface event)
65  	{
66  		super.notify(event);
67  		if (event.getType().equals(SimulatorInterface.START_EVENT))
68  		{
69  			this.setEnabled(false);
70  			return;
71  		}
72  		if (event.getType().equals(SimulatorInterface.STOP_EVENT))
73  		{
74  			this.setEnabled(true);
75  			return;
76  		}
77  		if (event.getSource() instanceof Experiment
78  				&& event.getType().equals(Experiment.END_OF_EXPERIMENT_EVENT))
79  		{
80  			this.setEnabled(true);
81  		}
82  	}
83  }