1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.gui.animation2D;
11
12 import java.awt.BorderLayout;
13 import java.awt.Dimension;
14 import java.awt.FlowLayout;
15 import java.awt.geom.Rectangle2D;
16
17 import javax.swing.JButton;
18 import javax.swing.JFrame;
19 import javax.swing.JPanel;
20
21 import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
22 import nl.tudelft.simulation.dsol.gui.animation2D.actions.HomeAction;
23 import nl.tudelft.simulation.dsol.gui.animation2D.actions.PanDownAction;
24 import nl.tudelft.simulation.dsol.gui.animation2D.actions.PanLeftAction;
25 import nl.tudelft.simulation.dsol.gui.animation2D.actions.PanRightAction;
26 import nl.tudelft.simulation.dsol.gui.animation2D.actions.PanUpAction;
27 import nl.tudelft.simulation.dsol.gui.animation2D.actions.ShowGridAction;
28 import nl.tudelft.simulation.dsol.gui.animation2D.actions.ZoomInAction;
29 import nl.tudelft.simulation.dsol.gui.animation2D.actions.ZoomOutAction;
30
31 /***
32 * The AnimationFrame <br>
33 * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
34 * General Public License (LGPL) </a>, no warranty.
35 *
36 * @version $Revision$ $Date$
37 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
38 * Jacobs </a>
39 */
40 public class AnimationFrame extends JFrame
41 {
42 /***
43 * Constructor for AnimationFrame.
44 *
45 * @param application the application
46 */
47 public AnimationFrame(final DSOLApplicationInterface application)
48 {
49 this("Animation window", application);
50 }
51
52 /***
53 * Constructor for AnimationFrame.
54 *
55 * @param name the name of the frame
56 * @param application the application
57 */
58 public AnimationFrame(final String name,
59 final DSOLApplicationInterface application)
60 {
61 super(name);
62 this.getContentPane().setLayout(new BorderLayout());
63 Rectangle2D extent = null;
64 String extentString = application.getProperties().getProperty(
65 "dsol-gui.animation.panel.extent");
66 if (extentString != null)
67 {
68 double[] values = new double[4];
69 for (int i = 0; i < 3; i++)
70 {
71 values[i] = new Double(extentString.substring(0, extentString
72 .indexOf(";"))).doubleValue();
73 extentString = extentString
74 .substring(extentString.indexOf(";") + 1);
75 }
76 values[3] = new Double(extentString).doubleValue();
77 extent = new Rectangle2D.Double(values[0], values[1], values[2],
78 values[3]);
79 } else
80 {
81 extent = new Rectangle2D.Double(-100, -100, 200, 200);
82 }
83 String sizeString = application.getProperties().getProperty(
84 "dsol-gui.animation.panel.size");
85 Dimension size = new Dimension(600, 600);
86 if (sizeString != null)
87 {
88 double width = new Double(sizeString.substring(0, sizeString
89 .indexOf(";"))).doubleValue();
90 double height = new Double(sizeString.substring(sizeString
91 .indexOf(";") + 1)).doubleValue();
92 size = new Dimension((int) width, (int) height);
93 }
94 AnimationPanel panel = new AnimationPanel(extent, size, application);
95 this.getContentPane().add(panel, BorderLayout.CENTER);
96 this.getContentPane().add(new ButtonPanel(panel), BorderLayout.SOUTH);
97 this.pack();
98 this.setVisible(true);
99 panel.requestFocus();
100 }
101
102 /***
103 * The ButtonPanel class
104 */
105 public static class ButtonPanel extends JPanel
106 {
107 /***
108 * constructs a new ButtonPanel
109 *
110 * @param target the target to control
111 */
112 public ButtonPanel(final GridPanel target)
113 {
114 this.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 1));
115
116 JButton zoomIn = new JButton(new ZoomInAction(target));
117 JButton zoomOut = new JButton(new ZoomOutAction(target));
118 JButton left = new JButton(new PanLeftAction(target));
119 JButton right = new JButton(new PanRightAction(target));
120 JButton up = new JButton(new PanUpAction(target));
121 JButton down = new JButton(new PanDownAction(target));
122 JButton grid = new JButton(new ShowGridAction(target));
123 JButton home = new JButton(new HomeAction(target));
124 this.add(zoomIn);
125 this.add(zoomOut);
126 this.add(left);
127 this.add(right);
128 this.add(up);
129 this.add(down);
130 this.add(grid);
131 this.add(home);
132 }
133 }
134 }