View Javadoc

1   /*
2    * @(#) Editor2DFrame.java 20-jul-2004 Copyright (c) 2002-2005 Delft University
3    * of Technology Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights
4    * reserved. This software is proprietary information of Delft University of
5    * Technology The code is published under the Lesser General Public License
6    */
7   package nl.tudelft.simulation.dsol.gui.editor2D;
8   
9   import java.awt.BorderLayout;
10  import java.awt.Container;
11  import java.awt.Dimension;
12  import java.awt.geom.Rectangle2D;
13  
14  import javax.swing.SwingConstants;
15  
16  import nl.tudelft.simulation.dsol.gui.DSOLApplicationInterface;
17  import nl.tudelft.simulation.language.swing.JMultiToolbarFrame;
18  
19  /***
20   * Editor2DFrame.java <br>
21   * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
22   * University of Technology </a>, the Netherlands. <br>
23   * See for project information <a
24   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
25   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
26   * General Public License (LGPL) </a>, no warranty.
27   * 
28   * @version $Revision$ $Date$
29   * @author <a href="http://www.tbm.tudelft.nl/webstaf/royc/index.htm">Roy Chin
30   *         </a>
31   */
32  public class Editor2DFrame extends JMultiToolbarFrame
33  {
34  
35  	/*** The application */
36  	private DSOLApplicationInterface application = null;
37  
38  	/*** Navigation toolbar */
39  	private NavigationToolbar navigationToolbar = null;
40  
41  	/*** Editor toolbar */
42  	private EditorToolbar editorToolbar = null;
43  
44  	/*** The editable animation editor2DPanel */
45  	private Editor2DPanel editor2DPanel = null;
46  
47  	/***
48  	 * Constructs a new frame
49  	 * 
50  	 * @param application The application
51  	 */
52  	public Editor2DFrame(final DSOLApplicationInterface application)
53  	{
54  		super();
55  		this.application = application;
56  
57  		// Initialize the frame
58  		this.initialize();
59  	}
60  
61  	/***
62  	 * Initialize the frame
63  	 */
64  	private void initialize()
65  	{
66  		this.setSize(640, 480);
67  		this.setTitle("Animation Editor 2D");
68  
69  		Container pane = this.getContentPane();
70  		pane.setLayout(new BorderLayout());
71  
72  		// Initialize animation editor2DPanel
73  
74  		Rectangle2D extent = null;
75  		String extentString = this.application.getProperties().getProperty(
76  				"dsol-gui.animation.panel.extent");
77  		if (extentString != null)
78  		{
79  			double[] values = new double[4];
80  			for (int i = 0; i < 3; i++)
81  			{
82  				values[i] = new Double(extentString.substring(0, extentString
83  						.indexOf(";"))).doubleValue();
84  				extentString = extentString
85  						.substring(extentString.indexOf(";") + 1);
86  			}
87  			values[3] = new Double(extentString).doubleValue();
88  			extent = new Rectangle2D.Double(values[0], values[1], values[2],
89  					values[3]);
90  		} else
91  		{
92  			extent = new Rectangle2D.Double(-100, -100, 200, 200);
93  		}
94  		String sizeString = this.application.getProperties().getProperty(
95  				"dsol-gui.animation.panel.size");
96  		Dimension size = new Dimension(600, 600);
97  		if (sizeString != null)
98  		{
99  			double width = new Double(sizeString.substring(0, sizeString
100 					.indexOf(";"))).doubleValue();
101 			double height = new Double(sizeString.substring(sizeString
102 					.indexOf(";") + 1)).doubleValue();
103 			size = new Dimension((int) width, (int) height);
104 		}
105 
106 		this.editor2DPanel = this.createAnimationPanel();
107 		// Set the editor mode to select
108 		this.editor2DPanel.setSelectedMode(Editor2DPanel.MODE_SELECT);
109 		this.editor2DPanel.getExtent().setRect(extent);
110 		this.editor2DPanel.setSize(size);
111 		this.editor2DPanel.setFocusable(true);
112 		this.editor2DPanel.setFocusCycleRoot(true);
113 		this.editor2DPanel.setFocusTraversalKeysEnabled(true);
114 
115 		// Create menubar
116 		MenuBar menuBar = new MenuBar(this, this.application);
117 		this.setJMenuBar(menuBar);
118 
119 		// Create panels;
120 		// pane.add(new
121 		// NavigationToolbar(editor2DPanel),BorderLayout.NORTH);
122 		// pane.add(new EditorToolbar(),BorderLayout.WEST);
123 		this.navigationToolbar = new NavigationToolbar(this.editor2DPanel);
124 		this.addJToolBar(this.navigationToolbar, SwingConstants.TOP);
125 		this.editorToolbar = new EditorToolbar(this.application,
126 				this.editor2DPanel);
127 		this.addJToolBar(this.editorToolbar, SwingConstants.LEFT);
128 		pane.add(this.editor2DPanel, BorderLayout.CENTER);
129 
130 		// What to do to exit
131 		addWindowListener(new java.awt.event.WindowAdapter()
132 		{
133 
134 			public void windowClosing(final java.awt.event.WindowEvent evt)
135 			{
136 				Editor2DFrame.this.closeFrame();
137 			}
138 		});
139 
140 		this.pack();
141 		this.setVisible(true);
142 	}
143 
144 	/***
145 	 * Create the animation panel
146 	 * 
147 	 * @return a panel
148 	 */
149 	private Editor2DPanel createAnimationPanel()
150 	{
151 		Rectangle2D extent = null;
152 		String extentString = this.application.getProperties().getProperty(
153 				"dsol-gui.animation.editor2DPanel.extent");
154 		if (extentString != null)
155 		{
156 			double[] values = new double[4];
157 			for (int i = 0; i < 3; i++)
158 			{
159 				values[i] = new Double(extentString.substring(0, extentString
160 						.indexOf(";"))).doubleValue();
161 				extentString = extentString
162 						.substring(extentString.indexOf(";") + 1);
163 			}
164 			values[3] = new Double(extentString).doubleValue();
165 			extent = new Rectangle2D.Double(values[0], values[1], values[2],
166 					values[3]);
167 		} else
168 		{
169 			extent = new Rectangle2D.Double(-100, -100, 200, 200);
170 		}
171 		String sizeString = this.application.getProperties().getProperty(
172 				"dsol-gui.animation.editor2DPanel.size");
173 		Dimension size = new Dimension(600, 600);
174 		if (sizeString != null)
175 		{
176 			double width = new Double(sizeString.substring(0, sizeString
177 					.indexOf(";"))).doubleValue();
178 			double height = new Double(sizeString.substring(sizeString
179 					.indexOf(";") + 1)).doubleValue();
180 			size = new Dimension((int) width, (int) height);
181 		}
182 		Editor2DPanel panel = new Editor2DPanel(extent, size, this.application);
183 		return panel;
184 	}
185 
186 	/***
187 	 * Close this frame
188 	 */
189 	protected void closeFrame()
190 	{
191 		this.setVisible(false);
192 	}
193 
194 	/***
195 	 * @return Returns the editorToolbar.
196 	 */
197 	public EditorToolbar getEditorToolbar()
198 	{
199 		return this.editorToolbar;
200 	}
201 
202 	/***
203 	 * @return Returns the navigationTooolbar.
204 	 */
205 	public NavigationToolbar getNavigationToolbar()
206 	{
207 		return this.navigationToolbar;
208 	}
209 
210 	/***
211 	 * @return Returns the editor2DPanel.
212 	 */
213 	public Editor2DPanel getEditableAnimationPanel()
214 	{
215 		return this.editor2DPanel;
216 	}
217 }