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.Animator;
19  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20  import nl.tudelft.simulation.event.EventInterface;
21  import nl.tudelft.simulation.event.EventListenerInterface;
22  import nl.tudelft.simulation.logger.Logger;
23  
24  /***
25   * The FastForward action <br>
26   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
27   * University of Technology </a>, the Netherlands. <br>
28   * See for project information <a
29   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
30   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
31   * License (GPL) </a>, no warranty <br>
32   * 
33   * @version 1.0 18.10.2003 <br>
34   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
35   *         Jacobs </a>
36   */
37  public class FastForwardAction extends SimulatorAction implements
38  		EventListenerInterface
39  {
40  
41  	/***
42  	 * constructs a new FastForwardAction
43  	 * 
44  	 * @param application the application
45  	 */
46  	public FastForwardAction(final DSOLApplicationInterface application)
47  	{
48  		super("fastForward", application);
49  		this
50  				.putValue(
51  						Action.SMALL_ICON,
52  						new ImageIcon(
53  								this
54  										.getClass()
55  										.getResource(
56  												"/toolbarButtonGraphics/media/FastForward16.gif")));
57  	}
58  
59  	/***
60  	 * @see java.awt.event.ActionListener
61  	 *      #actionPerformed(java.awt.event.ActionEvent)
62  	 */
63  	public void actionPerformed(final ActionEvent event)
64  	{
65  		try
66  		{
67  			((Animator) super.simulator).setAnimationDelay(0);
68  			if (new Double(this.simulator.getSimulatorTime()).isNaN())
69  			{
70  				this.application.getExperiment().start();
71  				return;
72  			}
73  			super.simulator.start();
74  		} catch (Exception exception)
75  		{
76  			Logger.warning(this, "actionPerformed", exception);
77  		}
78  	}
79  
80  	/***
81  	 * @see nl.tudelft.simulation.event.EventListenerInterface
82  	 *      #notify(nl.tudelft.simulation.event.EventInterface)
83  	 */
84  	public void notify(final EventInterface event)
85  	{
86  		super.notify(event);
87  		if (event.getType().equals(SimulatorInterface.START_EVENT))
88  		{
89  			this.setEnabled(false);
90  			return;
91  		}
92  		if (event.getType().equals(SimulatorInterface.STOP_EVENT))
93  		{
94  			this.setEnabled(true);
95  			return;
96  		}
97  	}
98  }