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