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.gui.DSOLApplicationInterface;
18  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
19  import nl.tudelft.simulation.event.EventInterface;
20  import nl.tudelft.simulation.event.EventListenerInterface;
21  import nl.tudelft.simulation.logger.Logger;
22  
23  /***
24   * The StepAction <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 StepAction extends SimulatorAction implements
36  		EventListenerInterface
37  {
38  	/***
39  	 * constructs a new ShowGridAction
40  	 * 
41  	 * @param application the application
42  	 */
43  	public StepAction(final DSOLApplicationInterface application)
44  	{
45  		super("step", application);
46  		this
47  				.putValue(
48  						Action.SMALL_ICON,
49  						new ImageIcon(
50  								this
51  										.getClass()
52  										.getResource(
53  												"/toolbarButtonGraphics/media/StepForward16.gif")));
54  	}
55  
56  	/***
57  	 * @see java.awt.event.ActionListener
58  	 *      #actionPerformed(java.awt.event.ActionEvent)
59  	 */
60  	public void actionPerformed(final ActionEvent event)
61  	{
62  		try
63  		{
64  			super.simulator.step();
65  		} catch (Exception exception)
66  		{
67  			Logger.warning(this, "actionPerformed", exception);
68  		}
69  	}
70  
71  	/***
72  	 * @see nl.tudelft.simulation.event.EventListenerInterface
73  	 *      #notify(nl.tudelft.simulation.event.EventInterface)
74  	 */
75  	public void notify(final EventInterface event)
76  	{
77  		super.notify(event);
78  		this.setEnabled(false);
79  		if (event.getType().equals(SimulatorInterface.START_EVENT))
80  		{
81  			this.setEnabled(false);
82  			return;
83  		}
84  		if (event.getType().equals(SimulatorInterface.STOP_EVENT))
85  		{
86  			this.setEnabled(true);
87  			return;
88  		}
89  	}
90  }