View Javadoc

1   /*
2    * @(#) ShowGridAction.java Oct 24, 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.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 2003 <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/gpl.html">General Public
30   * License (GPL) </a>, no warranty <br>
31   * 
32   * @version 1.0 18.10.2003 <br>
33   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
34   *         Jacobs </a>
35   */
36  public class StepAction extends SimulatorAction implements
37  		EventListenerInterface
38  {
39  	/***
40  	 * constructs a new ShowGridAction
41  	 * 
42  	 * @param application the application
43  	 */
44  	public StepAction(final DSOLApplicationInterface application)
45  	{
46  		super("step", application);
47  		this
48  				.putValue(
49  						Action.SMALL_ICON,
50  						new ImageIcon(
51  								this
52  										.getClass()
53  										.getResource(
54  												"/toolbarButtonGraphics/media/StepForward16.gif")));
55  	}
56  
57  	/***
58  	 * @see java.awt.event.ActionListener
59  	 *      #actionPerformed(java.awt.event.ActionEvent)
60  	 */
61  	public void actionPerformed(final ActionEvent event)
62  	{
63  		try
64  		{
65  			super.simulator.step();
66  		} catch (Exception exception)
67  		{
68  			Logger.warning(this, "actionPerformed", exception);
69  		}
70  	}
71  
72  	/***
73  	 * @see nl.tudelft.simulation.event.EventListenerInterface
74  	 *      #notify(nl.tudelft.simulation.event.EventInterface)
75  	 */
76  	public void notify(final EventInterface event)
77  	{
78  		super.notify(event);
79  		this.setEnabled(false);
80  		if (event.getType().equals(SimulatorInterface.START_EVENT))
81  		{
82  			this.setEnabled(false);
83  			return;
84  		}
85  		if (event.getType().equals(SimulatorInterface.STOP_EVENT))
86  		{
87  			this.setEnabled(true);
88  			return;
89  		}
90  	}
91  }