1
2
3
4
5
6
7
8
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.naming.NamingException;
16 import javax.naming.event.EventContext;
17 import javax.swing.AbstractAction;
18 import javax.swing.Action;
19 import javax.swing.KeyStroke;
20
21 import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
22 import nl.tudelft.simulation.dsol.gui.windows.ContextFrame;
23 import nl.tudelft.simulation.logger.Logger;
24 import nl.tudelft.simulation.naming.InitialEventContext;
25
26 /***
27 * The ViewContext action <br>
28 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
29 * University of Technology </a>, the Netherlands. <br>
30 * See for project information <a
31 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
32 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
33 * License (GPL) </a>, no warranty <br>
34 *
35 * @version 1.0 18.10.2003 <br>
36 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
37 * Jacobs </a>
38 */
39 public class ViewContextAction extends AbstractAction
40 {
41 /*** the context */
42 private final EventContext context;
43
44 /*** application the application */
45 private DSOLApplicationInterface application = null;
46
47 /***
48 * constructs a new ViewContextAction
49 *
50 * @param application the application
51 * @throws NamingException on failure
52 */
53 public ViewContextAction(final DSOLApplicationInterface application)
54 throws NamingException
55 {
56 this(new InitialEventContext(), application);
57 }
58
59 /***
60 * constructs a new ViewContextAction
61 *
62 * @param context the specific context to view
63 * @param application the application
64 */
65 public ViewContextAction(final EventContext context,
66 final DSOLApplicationInterface application)
67 {
68 super("Context");
69 this.application = application;
70 this.putValue(Action.MNEMONIC_KEY, new Integer('C'));
71 this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
72 KeyEvent.VK_F1, 0));
73 this.context = context;
74 }
75
76 /***
77 * @see java.awt.event.ActionListener
78 * #actionPerformed(java.awt.event.ActionEvent)
79 */
80 public void actionPerformed(final ActionEvent e)
81 {
82 try
83 {
84 boolean running = false;
85 try
86 {
87 if (this.application.getExperiment().getSimulator().isRunning())
88 {
89 running = true;
90 this.application.getExperiment().getSimulator().stop();
91 }
92 } catch (NullPointerException nullPointerException)
93 {
94
95 nullPointerException = null;
96 }
97 new ContextFrame(this.context);
98 if (running)
99 {
100 this.application.getExperiment().getSimulator().start();
101 }
102 } catch (Exception exception)
103 {
104 Logger.warning(this, "actionPerformed", exception);
105 }
106 }
107 }