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.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 2002-2005 <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/lesser.html">Lesser
    31   * General Public License (LGPL) </a>, no warranty.
    32   *
    33   * @version $Revision$ $Date$
    34   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja">Peter Jacobs </a>
    35   */
    36  public class FastForwardAction extends SimulatorAction implements
    37  		EventListenerInterface
    38  {
    39
    40  	/***
    41  	 * constructs a new FastForwardAction
    42  	 *
    43  	 * @param application the application
    44  	 */
    45  	public FastForwardAction(final DSOLApplicationInterface application)
    46  	{
    47  		super("fastForward", application);
    48  		this
    49  				.putValue(
    50  						Action.SMALL_ICON,
    51  						new ImageIcon(
    52  								this
    53  										.getClass()
    54  										.getResource(
    55  												"/toolbarButtonGraphics/media/FastForward16.gif")));
    56  	}
    57
    58  	/***
    59  	 * @see java.awt.event.ActionListener
    60  	 *      #actionPerformed(java.awt.event.ActionEvent)
    61  	 */
    62  	public void actionPerformed(final ActionEvent event)
    63  	{
    64  		try
    65  		{
    66  			((Animator) super.simulator).setAnimationDelay(0);
    67  			if (new Double(this.simulator.getSimulatorTime()).isNaN())
    68  			{
    69  				this.application.getExperiment().start();
    70  				return;
    71  			}
    72  			super.simulator.start();
    73  		} catch (Exception exception)
    74  		{
    75  			Logger.warning(this, "actionPerformed", exception);
    76  		}
    77  	}
    78
    79  	/***
    80  	 * @see nl.tudelft.simulation.event.EventListenerInterface
    81  	 *      #notify(nl.tudelft.simulation.event.EventInterface)
    82  	 */
    83  	public void notify(final EventInterface event)
    84  	{
    85  		super.notify(event);
    86  		if (event.getType().equals(SimulatorInterface.START_EVENT))
    87  		{
    88  			this.setEnabled(false);
    89  			return;
    90  		}
    91  		if (event.getType().equals(SimulatorInterface.STOP_EVENT))
    92  		{
    93  			this.setEnabled(true);
    94  			return;
    95  		}
    96  	}
    97  }