View Javadoc

    1   /*
    2    * @(#) ViewMemoryAction.java Oct 23, 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.menu.actions;
    11
    12  import java.awt.event.ActionEvent;
    13  import java.awt.event.KeyEvent;
    14
    15  import javax.swing.AbstractAction;
    16  import javax.swing.Action;
    17  import javax.swing.KeyStroke;
    18
    19  import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
    20  import nl.tudelft.simulation.dsol.gui.windows.MemoryFrame;
    21  import nl.tudelft.simulation.logger.Logger;
    22
    23  /***
    24   * The ViewMemoryAction action <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 ViewMemoryAction extends AbstractAction
    36  {
    37  	/*** application */
    38  	private DSOLApplicationInterface application = null;
    39
    40  	/***
    41  	 * constructs a new ViewContextAction
    42  	 *
    43  	 * @param application the application
    44  	 */
    45  	public ViewMemoryAction(final DSOLApplicationInterface application)
    46  	{
    47  		super("Memory");
    48  		this.application = application;
    49  		this.putValue(Action.MNEMONIC_KEY, new Integer('M'));
    50  		this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
    51  				KeyEvent.VK_F11, 0));
    52  	}
    53
    54  	/***
    55  	 * @see java.awt.event.ActionListener
    56  	 *      #actionPerformed(java.awt.event.ActionEvent)
    57  	 */
    58  	public void actionPerformed(final ActionEvent e)
    59  	{
    60  		try
    61  		{
    62  			boolean running = false;
    63  			try
    64  			{
    65  				if (this.application.getExperiment().getSimulator().isRunning())
    66  				{
    67  					running = true;
    68  					this.application.getExperiment().getSimulator().stop();
    69  				}
    70  			} catch (NullPointerException nullPointerException)
    71  			{
    72  				// This was meant to happen
    73  				nullPointerException = null;
    74  			}
    75  			new MemoryFrame();
    76  			if (running)
    77  			{
    78  				this.application.getExperiment().getSimulator().start();
    79  			}
    80  		} catch (Exception exception)
    81  		{
    82  			Logger.warning(this, "actionPerformed", exception);
    83  		}
    84  	}
    85  }