1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.gui.animation3D;
11
12 import java.awt.BorderLayout;
13 import java.awt.Container;
14 import java.awt.FlowLayout;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17
18 import javax.swing.JButton;
19 import javax.swing.JFrame;
20 import javax.swing.JPanel;
21
22 import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
23 import nl.tudelft.simulation.dsol.gui.panels.Statusbar;
24
25 /***
26 * Animation3DFrame, a frame for 3d animation <br>
27 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
28 * University of Technology </a>, the Netherlands. <br>
29 * See for project information <a
30 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
31 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
32 * License (GPL) </a>, no warranty <br>
33 *
34 * @version 1.0 10.05.2004 <br>
35 * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
36 * </a>
37 */
38 public final class Animation3DFrame extends JFrame implements ActionListener
39 {
40 /*** This frame */
41 private static Animation3DFrame frame = null;
42
43 /*** The application */
44 private DSOLApplicationInterface application = null;
45
46 /*** The animation 3d canvas */
47 private Animation3DCanvas animation3DPanel = null;
48
49 /*** A home button */
50 private JButton homeButton = new JButton("Home");
51
52 /***
53 * Constructs new frame
54 *
55 * @param application DSOL application
56 */
57 private Animation3DFrame(final DSOLApplicationInterface application)
58 {
59 super();
60 this.application = application;
61 this.animation3DPanel = new Animation3DCanvas(application);
62 this.initializeFrame();
63 }
64
65 /***
66 * Creates a new instance of this frame or if one already exists, then it
67 * makes it visible.
68 *
69 * @param application DSOLApplicationInterface
70 * @return frame
71 */
72 public static JFrame initialize(final DSOLApplicationInterface application)
73 {
74 if (frame != null)
75 {
76 frame.setVisible(true);
77 } else
78 {
79 frame = new Animation3DFrame(application);
80 }
81 return frame;
82 }
83
84 /***
85 * Initializes the frame
86 */
87 public void initializeFrame()
88 {
89
90
91 this.setTitle("Animation3D");
92 this.setSize(640, 480);
93
94
95
96 JPanel bottom = new JPanel();
97 bottom.setLayout(new BorderLayout());
98
99 if (this.application != null)
100 {
101 Statusbar statusbar = new Statusbar(this.application);
102 bottom.add(BorderLayout.WEST, statusbar);
103 }
104
105 JPanel east = new JPanel();
106 east.setLayout(new FlowLayout());
107 east.add(BorderLayout.EAST, this.homeButton);
108 bottom.add(BorderLayout.EAST, east);
109 this.homeButton.addActionListener(this);
110
111
112
113 Container container = this.getContentPane();
114 container.setLayout(new BorderLayout());
115 container.add(BorderLayout.CENTER, this.animation3DPanel);
116 container.add(BorderLayout.SOUTH, bottom);
117
118
119 addWindowListener(new java.awt.event.WindowAdapter()
120 {
121 public void windowClosing(final java.awt.event.WindowEvent evt)
122 {
123 closeFrame();
124 }
125 });
126
127 this.setVisible(true);
128 }
129
130 /***
131 * Close this frame
132 */
133 protected void closeFrame()
134 {
135 this.setVisible(false);
136 }
137
138 /***
139 * @see java.awt.event.ActionListener#actionPerformed
140 * (java.awt.event.ActionEvent)
141 */
142 public void actionPerformed(final ActionEvent event)
143 {
144 if (event.getSource() == this.homeButton)
145 {
146 this.animation3DPanel.getViewBranch().resetView();
147 }
148 }
149 }