View Javadoc

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