root / branches / v2_0_0_prep / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / skin / JDialogFrameWindowSupport.java @ 29938
History | View | Annotate | Download (8.96 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.gvsig3dgui.skin; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.Container; |
45 |
import java.awt.Image; |
46 |
import java.awt.Rectangle; |
47 |
import java.awt.Window; |
48 |
import java.util.Hashtable; |
49 |
import java.util.Iterator; |
50 |
|
51 |
import javax.swing.JDialog; |
52 |
import javax.swing.JFrame; |
53 |
import javax.swing.JPanel; |
54 |
|
55 |
import org.gvsig.andami.ui.mdiFrame.MDIFrame; |
56 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
57 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
58 |
import org.gvsig.coreplugin.mdiManager.FrameWindowSupport; |
59 |
|
60 |
/**
|
61 |
*
|
62 |
*/
|
63 |
public class JDialogFrameWindowSupport extends FrameWindowSupport { |
64 |
|
65 |
private Hashtable frameView = new Hashtable(); |
66 |
private Hashtable viewFrame = new Hashtable(); |
67 |
private Image icon; |
68 |
private JDialogWindowInfoSupport vis;
|
69 |
private JFrame mainFrame; |
70 |
|
71 |
public JDialogFrameWindowSupport(MDIFrame mainFrame) {
|
72 |
super(mainFrame);
|
73 |
this.mainFrame = mainFrame;
|
74 |
icon = mainFrame.getIconImage(); |
75 |
} |
76 |
|
77 |
public Iterator getWindowIterator(){ |
78 |
return viewFrame.keySet().iterator();
|
79 |
} |
80 |
|
81 |
public boolean contains(IWindow v){ |
82 |
return viewFrame.containsKey(v);
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* @param wnd
|
87 |
* @return
|
88 |
*/
|
89 |
public boolean contains(JDialog wnd) { |
90 |
return frameView.contains(wnd);
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* DOCUMENT ME!
|
95 |
*
|
96 |
* @param p DOCUMENT ME!
|
97 |
*
|
98 |
* @return DOCUMENT ME!
|
99 |
*/
|
100 |
public JDialog getJDialog(IWindow p) { |
101 |
JDialog dlg = (JDialog) viewFrame.get(p); |
102 |
|
103 |
if (dlg == null) { |
104 |
WindowInfo vi = vis.getWindowInfo(p); |
105 |
JDialog nuevo = new JDialog(mainFrame); |
106 |
|
107 |
nuevo.getContentPane().add((JPanel) p);
|
108 |
nuevo.setSize(getWidth(p, vi), getHeight(p, vi) + 30);
|
109 |
nuevo.setTitle(vi.getTitle()); |
110 |
nuevo.setResizable(vi.isResizable()); |
111 |
|
112 |
viewFrame.put(p, nuevo); |
113 |
frameView.put(nuevo, p); |
114 |
|
115 |
nuevo.setModal(vi.isModal()); |
116 |
return nuevo;
|
117 |
} else {
|
118 |
return dlg;
|
119 |
} |
120 |
} |
121 |
|
122 |
/**
|
123 |
* DOCUMENT ME!
|
124 |
*
|
125 |
* @param p DOCUMENT ME!
|
126 |
*
|
127 |
* @return DOCUMENT ME!
|
128 |
*/
|
129 |
public JDialog getFrame(IWindow p) { |
130 |
JDialog frame = (JDialog) viewFrame.get(p); |
131 |
|
132 |
if (frame == null) { |
133 |
JDialog nuevo = createFrame(p);
|
134 |
viewFrame.put(p, nuevo); |
135 |
frameView.put(nuevo, p); |
136 |
vis.getWindowInfo(p); // to update the windowInfo object
|
137 |
return nuevo;
|
138 |
} else {
|
139 |
return frame;
|
140 |
} |
141 |
} |
142 |
|
143 |
public JDialog createFrame(IWindow p) |
144 |
{ |
145 |
WindowInfo windowInfo = vis.getWindowInfo(p); |
146 |
JDialog frame = new JDialog(mainFrame, false); |
147 |
frame.getContentPane().add((JPanel) p);
|
148 |
frame.setTitle(windowInfo.getTitle()); |
149 |
frame.setBounds(calculateBounds(p, windowInfo)); |
150 |
frame.setVisible(windowInfo.isVisible()); |
151 |
frame.setResizable(windowInfo.isResizable()); |
152 |
frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
153 |
return frame;
|
154 |
} |
155 |
|
156 |
public IWindow getWindow(Component dlg){ |
157 |
return (IWindow) frameView.get(dlg);
|
158 |
} |
159 |
|
160 |
public Component getComponent(IWindow window) { |
161 |
return (Component) viewFrame.get(window); |
162 |
} |
163 |
|
164 |
public void closeWindow(IWindow v){ |
165 |
Object c = viewFrame.remove(v);
|
166 |
frameView.remove(c); |
167 |
} |
168 |
|
169 |
/**
|
170 |
* DOCUMENT ME!
|
171 |
*
|
172 |
* @param v DOCUMENT ME!
|
173 |
* @param x DOCUMENT ME!
|
174 |
*/
|
175 |
public void setX(IWindow w, int x) { |
176 |
Window frame = (Window) viewFrame.get(w); |
177 |
frame.setLocation(x, frame.getY()); |
178 |
} |
179 |
|
180 |
/**
|
181 |
* DOCUMENT ME!
|
182 |
*
|
183 |
* @param v DOCUMENT ME!
|
184 |
* @param y DOCUMENT ME!
|
185 |
*/
|
186 |
public void setY(IWindow w, int y) { |
187 |
Window frame = (Window) viewFrame.get(w); |
188 |
frame.setLocation(frame.getX(), y); |
189 |
} |
190 |
|
191 |
/**
|
192 |
* DOCUMENT ME!
|
193 |
*
|
194 |
* @param v DOCUMENT ME!
|
195 |
* @param height DOCUMENT ME!
|
196 |
*/
|
197 |
public void setHeight(IWindow w, int height) { |
198 |
Window frame = (Window) viewFrame.get(w); |
199 |
frame.setSize(frame.getWidth(), height); |
200 |
} |
201 |
|
202 |
/**
|
203 |
* DOCUMENT ME!
|
204 |
*
|
205 |
* @param v DOCUMENT ME!
|
206 |
* @param width DOCUMENT ME!
|
207 |
*/
|
208 |
public void setWidth(IWindow w, int width) { |
209 |
Window frame = (Window) viewFrame.get(w); |
210 |
frame.setSize(width, frame.getHeight()); |
211 |
} |
212 |
|
213 |
/**
|
214 |
* DOCUMENT ME!
|
215 |
*
|
216 |
* @param v DOCUMENT ME!
|
217 |
* @param title DOCUMENT ME!
|
218 |
*/
|
219 |
public void setTitle(IWindow w, String title) { |
220 |
Window frame = (Window) viewFrame.get(w); |
221 |
if (frame instanceof JFrame) { |
222 |
((JFrame)frame).setTitle(title);
|
223 |
} |
224 |
else if (frame instanceof JDialog) { |
225 |
((JDialog)frame).setTitle(title);
|
226 |
} |
227 |
} |
228 |
|
229 |
/**
|
230 |
* DOCUMENT ME!
|
231 |
*
|
232 |
* @param vis The vis to set.
|
233 |
*/
|
234 |
public void setVis(JDialogWindowInfoSupport vis) { |
235 |
this.vis = vis;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* DOCUMENT ME!
|
240 |
*
|
241 |
* @param v DOCUMENT ME!
|
242 |
*
|
243 |
* @return DOCUMENT ME!
|
244 |
*/
|
245 |
private int getWidth(IWindow v, WindowInfo wi) { |
246 |
if (wi.getWidth() == -1) { |
247 |
JPanel p = (JPanel) v; |
248 |
|
249 |
return p.getSize().width;
|
250 |
} else {
|
251 |
return wi.getWidth();
|
252 |
} |
253 |
} |
254 |
|
255 |
/**
|
256 |
* DOCUMENT ME!
|
257 |
*
|
258 |
* @param v DOCUMENT ME!
|
259 |
*
|
260 |
* @return DOCUMENT ME!
|
261 |
*/
|
262 |
private int getHeight(IWindow v, WindowInfo wi) { |
263 |
if (wi.getHeight() == -1) { |
264 |
JPanel p = (JPanel) v; |
265 |
|
266 |
return p.getSize().height;
|
267 |
} else {
|
268 |
return wi.getHeight();
|
269 |
} |
270 |
} |
271 |
|
272 |
private Rectangle calculateBounds(IWindow win, WindowInfo wi) { |
273 |
Rectangle bounds = new Rectangle(); |
274 |
if (wi.getWidth() == -1) { |
275 |
JPanel p = (JPanel) win; |
276 |
|
277 |
bounds.width = p.getSize().width; |
278 |
} else {
|
279 |
bounds.width = wi.getWidth(); |
280 |
} |
281 |
|
282 |
if (wi.getHeight() == -1) { |
283 |
JPanel p = (JPanel) win; |
284 |
|
285 |
bounds.height = p.getSize().height; |
286 |
} else {
|
287 |
bounds.height = wi.getHeight(); |
288 |
} |
289 |
|
290 |
Rectangle frame = mainFrame.getBounds();
|
291 |
if (wi.getX() == -1) { |
292 |
bounds.x = frame.x + (int)(Math.random()*(frame.width-bounds.width)); |
293 |
if (bounds.x<0) |
294 |
bounds.x = 0;
|
295 |
} else {
|
296 |
bounds.x = wi.getX(); |
297 |
} |
298 |
if (wi.getY() == -1) { |
299 |
// 135: because we don't want it to be placed at the upmost part of the window
|
300 |
bounds.y = frame.y + 135 + (int)(Math.random()*(frame.height-bounds.height-135)); |
301 |
if (bounds.y<0) |
302 |
bounds.y = 135;
|
303 |
} else {
|
304 |
bounds.y = wi.getY(); |
305 |
} |
306 |
return bounds;
|
307 |
} |
308 |
|
309 |
private void updateWindowInfo(Container container, WindowInfo windowInfo) { |
310 |
windowInfo.setWidth(container.getWidth()); |
311 |
windowInfo.setHeight(container.getHeight()); |
312 |
windowInfo.setX(container.getX()); |
313 |
windowInfo.setY(container.getY()); |
314 |
windowInfo.setClosed(!container.isShowing()); |
315 |
if (container instanceof JFrame) { |
316 |
JFrame frame = (JFrame) container; |
317 |
if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) { |
318 |
windowInfo.setMaximized(true);
|
319 |
} |
320 |
else {
|
321 |
windowInfo.setMaximized(false);
|
322 |
windowInfo.setNormalBounds(frame.getBounds()); |
323 |
} |
324 |
} |
325 |
} |
326 |
|
327 |
/**
|
328 |
* Updates the windowInfo object, so that it correctly reflects the
|
329 |
* current frame properties.
|
330 |
*
|
331 |
* @param win
|
332 |
* @param windowInfo The WindowInfo object to update
|
333 |
*/
|
334 |
public void updateWindowInfo(IWindow win, WindowInfo windowInfo) { |
335 |
Object o = viewFrame.get(win);
|
336 |
if (windowInfo!=null && o!=null) { |
337 |
if (o instanceof Container) { |
338 |
updateWindowInfo((Container) o, windowInfo);
|
339 |
} |
340 |
} |
341 |
} |
342 |
} |