View Javadoc

    1   package nl.tudelft.simulation.dsol.gui.menu.actions;
    2
    3   import java.awt.event.ActionEvent;
    4   import java.awt.event.KeyEvent;
    5
    6   import javax.swing.AbstractAction;
    7   import javax.swing.Action;
    8   import javax.swing.KeyStroke;
    9
    10  import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
    11  import nl.tudelft.simulation.dsol.gui.animation3D.Animation3DFrame;
    12  import nl.tudelft.simulation.logger.Logger;
    13
    14  /***
    15   * @author roy chin
    16   *
    17   * ir. R.T.H. Chin sk.tbm.tudelft.nl
    18   */
    19  public class ViewAnimation3dAction extends AbstractAction
    20  {
    21  	/*** application the application */
    22  	private DSOLApplicationInterface application = null;
    23
    24  	/***
    25  	 * constructs a new ViewContextAction
    26  	 *
    27  	 * @param application the application
    28  	 */
    29  	public ViewAnimation3dAction(final DSOLApplicationInterface application)
    30  	{
    31  		super("3D animation");
    32  		this.application = application;
    33  		this.putValue(Action.MNEMONIC_KEY, new Integer('3'));
    34  		this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
    35  				KeyEvent.VK_F5, 0));
    36  		this.setEnabled(true);
    37  	}
    38
    39  	/***
    40  	 * @see java.awt.event.ActionListener#actionPerformed
    41  	 *      (java.awt.event.ActionEvent)
    42  	 */
    43  	public void actionPerformed(final ActionEvent arg0)
    44  	{
    45  		try
    46  		{
    47  			boolean running = false;
    48  			try
    49  			{
    50  				if (this.application.getExperiment().getSimulator().isRunning())
    51  				{
    52  					running = true;
    53  					this.application.getExperiment().getSimulator().stop();
    54  				}
    55  			} catch (NullPointerException nullPointerException)
    56  			{
    57  				// This was meant to happen
    58  				nullPointerException = null;
    59  			}
    60  			Animation3DFrame.initialize(ViewAnimation3dAction.this.application);
    61  			if (running)
    62  			{
    63  				this.application.getExperiment().getSimulator().start();
    64  			}
    65  		} catch (Exception exception)
    66  		{
    67  			Logger.warning(this, "actionPerformed", exception);
    68  		}
    69  	}
    70  }