1 package org.opentrafficsim.swing.gui;
2
3 import java.awt.Frame;
4 import java.awt.event.WindowAdapter;
5 import java.awt.event.WindowEvent;
6 import java.awt.geom.Rectangle2D;
7
8 import javax.swing.JPanel;
9 import javax.swing.WindowConstants;
10
11 import org.opentrafficsim.animation.gtu.colorer.DefaultSwitchableGtuColorer;
12 import org.opentrafficsim.animation.gtu.colorer.GtuColorer;
13 import org.opentrafficsim.core.dsol.OtsModelInterface;
14
15
16
17
18
19
20
21
22
23
24
25
26 public class OtsSwingApplication<T extends OtsModelInterface> extends AppearanceApplication
27 {
28
29 private static final long serialVersionUID = 20141216L;
30
31
32 public static final GtuColorer DEFAULT_COLORER = new DefaultSwitchableGtuColorer();
33
34
35 private final T model;
36
37
38 @SuppressWarnings("checkstyle:visibilitymodifier")
39 protected boolean closed = false;
40
41
42
43
44
45
46 public OtsSwingApplication(final T model, final JPanel panel)
47 {
48 super(panel);
49 this.model = model;
50 setTitle("OTS | The Open Traffic Simulator | " + model.getDescription());
51 pack();
52 setExtendedState(Frame.MAXIMIZED_BOTH);
53 setVisible(true);
54
55 setExitOnClose(true);
56 addWindowListener(new WindowAdapter()
57 {
58 @Override
59 public void windowClosing(final WindowEvent windowEvent)
60 {
61 OtsSwingApplication.this.closed = true;
62 super.windowClosing(windowEvent);
63 }
64 });
65 }
66
67
68
69
70
71
72 @SuppressWarnings("checkstyle:designforextension")
73 protected Rectangle2D makeAnimationRectangle()
74 {
75 return this.model.getNetwork().getExtent();
76 }
77
78
79
80
81 public final void setExitOnClose(final boolean exitOnClose)
82 {
83 if (exitOnClose)
84 {
85 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
86 }
87 else
88 {
89 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
90 }
91 }
92
93
94
95
96 public final boolean isClosed()
97 {
98 return this.closed;
99 }
100
101
102
103
104 public final T getModel()
105 {
106 return this.model;
107 }
108
109 }