1
2
3
4
5
6
7
8
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.SimulatorInterface;
19 import nl.tudelft.simulation.event.EventInterface;
20 import nl.tudelft.simulation.event.EventListenerInterface;
21 import nl.tudelft.simulation.logger.Logger;
22
23 /***
24 * The StartAction <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 StartAction extends SimulatorAction implements
37 EventListenerInterface
38 {
39 /***
40 * constructs a new ShowGridAction
41 *
42 * @param application the application
43 */
44 public StartAction(final DSOLApplicationInterface application)
45 {
46 super("start", application);
47 this.putValue(Action.SMALL_ICON, new ImageIcon(this.getClass()
48 .getResource("/toolbarButtonGraphics/media/Play16.gif")));
49 }
50
51 /***
52 * @see java.awt.event.ActionListener
53 * #actionPerformed(java.awt.event.ActionEvent)
54 */
55 public void actionPerformed(final ActionEvent event)
56 {
57 try
58 {
59 if (new Double(this.simulator.getSimulatorTime()).isNaN())
60 {
61 this.application.getExperiment().start();
62 return;
63 }
64 super.simulator.start();
65 } catch (Exception exception)
66 {
67 Logger.warning(this, "actionPerformed", exception);
68 }
69 }
70
71 /***
72 * @see nl.tudelft.simulation.event.EventListenerInterface
73 * #notify(nl.tudelft.simulation.event.EventInterface)
74 */
75 public void notify(final EventInterface event)
76 {
77 super.notify(event);
78 if (event.getType().equals(SimulatorInterface.START_EVENT))
79 {
80 this.setEnabled(false);
81 return;
82 }
83 if (event.getType().equals(SimulatorInterface.STOP_EVENT))
84 {
85 this.setEnabled(true);
86 return;
87 }
88 }
89 }