1 package org.opentrafficsim.gui;
2
3 import java.awt.Frame;
4
5 import javax.swing.JFrame;
6 import javax.swing.JPanel;
7
8 import org.opentrafficsim.simulationengine.WrappableSimulation;
9
10 /**
11 * Wrap a DSOL simulator, or any (descendant of a) JPanel in a JFrame (wrap it in a window). The window will be maximized.
12 * <p>
13 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15 * <p>
16 * $LastChangedDate: 2018-09-19 13:55:45 +0200 (Wed, 19 Sep 2018) $, @version $Revision: 4006 $, by $Author: averbraeck $,
17 * initial version 16 dec. 2014 <br>
18 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20 */
21 public class SimulatorFrame extends JFrame
22 {
23
24 /** */
25 private static final long serialVersionUID = 20141216L;
26
27 /**
28 * Wrap a JPanel in a JFrame.
29 * @param title String; title for the JFrame
30 * @param panel JPanel; the JPanel that will become the contentPane of the JFrame
31 */
32 public SimulatorFrame(final String title, final JPanel panel)
33 {
34 super();
35 setTitle(title);
36 setContentPane(panel);
37 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
38 pack();
39 setExtendedState(Frame.MAXIMIZED_BOTH);
40 setVisible(true);
41 }
42
43 /**
44 * Wrap a WrappableSimulation in a JFrame.
45 * @param simulation WrappableSimulation; the simulation that will be shown in the JFrame
46 * @param panel JPanel; this should be the JPanel of the simulation
47 */
48 public SimulatorFrame(final WrappableSimulation simulation, final JPanel panel)
49 {
50 super();
51 setTitle(simulation.shortName());
52 setContentPane(panel);
53 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
54 pack();
55 setExtendedState(Frame.MAXIMIZED_BOTH);
56 setVisible(true);
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public final String toString()
62 {
63 return "SimulatorFrame []";
64 }
65 }