svn-gvsig-desktop / trunk / extensions / ext3Dgui / src / com / iver / ai2 / gvsig3dgui / skin / JDialogFrameWindowSupport.java @ 16096
History | View | Annotate | Download (9 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 com.iver.ai2.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 com.iver.andami.ui.mdiFrame.MDIFrame; |
56 |
import com.iver.andami.ui.mdiManager.IWindow; |
57 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
58 |
import com.iver.core.mdiManager.FrameWindowSupport; |
59 |
import com.iver.core.mdiManager.WindowInfoSupport; |
60 |
|
61 |
/**
|
62 |
*
|
63 |
*/
|
64 |
public class JDialogFrameWindowSupport extends FrameWindowSupport { |
65 |
|
66 |
private Hashtable frameView = new Hashtable(); |
67 |
private Hashtable viewFrame = new Hashtable(); |
68 |
private Image icon; |
69 |
private JDialogWindowInfoSupport vis;
|
70 |
private JFrame mainFrame; |
71 |
|
72 |
public JDialogFrameWindowSupport(MDIFrame mainFrame) {
|
73 |
super(mainFrame);
|
74 |
this.mainFrame = mainFrame;
|
75 |
icon = mainFrame.getIconImage(); |
76 |
} |
77 |
|
78 |
public Iterator getWindowIterator(){ |
79 |
return viewFrame.keySet().iterator();
|
80 |
} |
81 |
|
82 |
public boolean contains(IWindow v){ |
83 |
return viewFrame.containsKey(v);
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* @param wnd
|
88 |
* @return
|
89 |
*/
|
90 |
public boolean contains(JDialog wnd) { |
91 |
return frameView.contains(wnd);
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* DOCUMENT ME!
|
96 |
*
|
97 |
* @param p DOCUMENT ME!
|
98 |
*
|
99 |
* @return DOCUMENT ME!
|
100 |
*/
|
101 |
public JDialog getJDialog(IWindow p) { |
102 |
JDialog dlg = (JDialog) viewFrame.get(p); |
103 |
|
104 |
if (dlg == null) { |
105 |
WindowInfo vi = vis.getWindowInfo(p); |
106 |
JDialog nuevo = new JDialog(mainFrame); |
107 |
|
108 |
nuevo.getContentPane().add((JPanel) p);
|
109 |
nuevo.setSize(getWidth(p, vi), getHeight(p, vi) + 30);
|
110 |
nuevo.setTitle(vi.getTitle()); |
111 |
nuevo.setResizable(vi.isResizable()); |
112 |
|
113 |
viewFrame.put(p, nuevo); |
114 |
frameView.put(nuevo, p); |
115 |
|
116 |
nuevo.setModal(vi.isModal()); |
117 |
return nuevo;
|
118 |
} else {
|
119 |
return dlg;
|
120 |
} |
121 |
} |
122 |
|
123 |
/**
|
124 |
* DOCUMENT ME!
|
125 |
*
|
126 |
* @param p DOCUMENT ME!
|
127 |
*
|
128 |
* @return DOCUMENT ME!
|
129 |
*/
|
130 |
public JDialog getFrame(IWindow p) { |
131 |
JDialog frame = (JDialog) viewFrame.get(p); |
132 |
|
133 |
if (frame == null) { |
134 |
JDialog nuevo = createFrame(p);
|
135 |
viewFrame.put(p, nuevo); |
136 |
frameView.put(nuevo, p); |
137 |
vis.getWindowInfo(p); // to update the windowInfo object
|
138 |
return nuevo;
|
139 |
} else {
|
140 |
return frame;
|
141 |
} |
142 |
} |
143 |
|
144 |
public JDialog createFrame(IWindow p) |
145 |
{ |
146 |
WindowInfo windowInfo = vis.getWindowInfo(p); |
147 |
JDialog frame = new JDialog(mainFrame, false); |
148 |
frame.getContentPane().add((JPanel) p);
|
149 |
frame.setTitle(windowInfo.getTitle()); |
150 |
frame.setBounds(calculateBounds(p, windowInfo)); |
151 |
frame.setVisible(windowInfo.isVisible()); |
152 |
frame.setResizable(windowInfo.isResizable()); |
153 |
frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
154 |
return frame;
|
155 |
} |
156 |
|
157 |
public IWindow getWindow(Component dlg){ |
158 |
return (IWindow) frameView.get(dlg);
|
159 |
} |
160 |
|
161 |
public Component getComponent(IWindow window) { |
162 |
return (Component) viewFrame.get(window); |
163 |
} |
164 |
|
165 |
public void closeWindow(IWindow v){ |
166 |
Object c = viewFrame.remove(v);
|
167 |
frameView.remove(c); |
168 |
} |
169 |
|
170 |
/**
|
171 |
* DOCUMENT ME!
|
172 |
*
|
173 |
* @param v DOCUMENT ME!
|
174 |
* @param x DOCUMENT ME!
|
175 |
*/
|
176 |
public void setX(IWindow w, int x) { |
177 |
Window frame = (Window) viewFrame.get(w); |
178 |
frame.setLocation(x, frame.getY()); |
179 |
} |
180 |
|
181 |
/**
|
182 |
* DOCUMENT ME!
|
183 |
*
|
184 |
* @param v DOCUMENT ME!
|
185 |
* @param y DOCUMENT ME!
|
186 |
*/
|
187 |
public void setY(IWindow w, int y) { |
188 |
Window frame = (Window) viewFrame.get(w); |
189 |
frame.setLocation(frame.getX(), y); |
190 |
} |
191 |
|
192 |
/**
|
193 |
* DOCUMENT ME!
|
194 |
*
|
195 |
* @param v DOCUMENT ME!
|
196 |
* @param height DOCUMENT ME!
|
197 |
*/
|
198 |
public void setHeight(IWindow w, int height) { |
199 |
Window frame = (Window) viewFrame.get(w); |
200 |
frame.setSize(frame.getWidth(), height); |
201 |
} |
202 |
|
203 |
/**
|
204 |
* DOCUMENT ME!
|
205 |
*
|
206 |
* @param v DOCUMENT ME!
|
207 |
* @param width DOCUMENT ME!
|
208 |
*/
|
209 |
public void setWidth(IWindow w, int width) { |
210 |
Window frame = (Window) viewFrame.get(w); |
211 |
frame.setSize(width, frame.getHeight()); |
212 |
} |
213 |
|
214 |
/**
|
215 |
* DOCUMENT ME!
|
216 |
*
|
217 |
* @param v DOCUMENT ME!
|
218 |
* @param title DOCUMENT ME!
|
219 |
*/
|
220 |
public void setTitle(IWindow w, String title) { |
221 |
Window frame = (Window) viewFrame.get(w); |
222 |
if (frame instanceof JFrame) { |
223 |
((JFrame)frame).setTitle(title);
|
224 |
} |
225 |
else if (frame instanceof JDialog) { |
226 |
((JDialog)frame).setTitle(title);
|
227 |
} |
228 |
} |
229 |
|
230 |
/**
|
231 |
* DOCUMENT ME!
|
232 |
*
|
233 |
* @param vis The vis to set.
|
234 |
*/
|
235 |
public void setVis(JDialogWindowInfoSupport vis) { |
236 |
this.vis = vis;
|
237 |
} |
238 |
|
239 |
/**
|
240 |
* DOCUMENT ME!
|
241 |
*
|
242 |
* @param v DOCUMENT ME!
|
243 |
*
|
244 |
* @return DOCUMENT ME!
|
245 |
*/
|
246 |
private int getWidth(IWindow v, WindowInfo wi) { |
247 |
if (wi.getWidth() == -1) { |
248 |
JPanel p = (JPanel) v; |
249 |
|
250 |
return p.getSize().width;
|
251 |
} else {
|
252 |
return wi.getWidth();
|
253 |
} |
254 |
} |
255 |
|
256 |
/**
|
257 |
* DOCUMENT ME!
|
258 |
*
|
259 |
* @param v DOCUMENT ME!
|
260 |
*
|
261 |
* @return DOCUMENT ME!
|
262 |
*/
|
263 |
private int getHeight(IWindow v, WindowInfo wi) { |
264 |
if (wi.getHeight() == -1) { |
265 |
JPanel p = (JPanel) v; |
266 |
|
267 |
return p.getSize().height;
|
268 |
} else {
|
269 |
return wi.getHeight();
|
270 |
} |
271 |
} |
272 |
|
273 |
private Rectangle calculateBounds(IWindow win, WindowInfo wi) { |
274 |
Rectangle bounds = new Rectangle(); |
275 |
if (wi.getWidth() == -1) { |
276 |
JPanel p = (JPanel) win; |
277 |
|
278 |
bounds.width = p.getSize().width; |
279 |
} else {
|
280 |
bounds.width = wi.getWidth(); |
281 |
} |
282 |
|
283 |
if (wi.getHeight() == -1) { |
284 |
JPanel p = (JPanel) win; |
285 |
|
286 |
bounds.height = p.getSize().height; |
287 |
} else {
|
288 |
bounds.height = wi.getHeight(); |
289 |
} |
290 |
|
291 |
Rectangle frame = mainFrame.getBounds();
|
292 |
if (wi.getX() == -1) { |
293 |
bounds.x = frame.x + (int)(Math.random()*(frame.width-bounds.width)); |
294 |
if (bounds.x<0) |
295 |
bounds.x = 0;
|
296 |
} else {
|
297 |
bounds.x = wi.getX(); |
298 |
} |
299 |
if (wi.getY() == -1) { |
300 |
// 135: because we don't want it to be placed at the upmost part of the window
|
301 |
bounds.y = frame.y + 135 + (int)(Math.random()*(frame.height-bounds.height-135)); |
302 |
if (bounds.y<0) |
303 |
bounds.y = 135;
|
304 |
} else {
|
305 |
bounds.y = wi.getY(); |
306 |
} |
307 |
return bounds;
|
308 |
} |
309 |
|
310 |
private void updateWindowInfo(Container container, WindowInfo windowInfo) { |
311 |
windowInfo.setWidth(container.getWidth()); |
312 |
windowInfo.setHeight(container.getHeight()); |
313 |
windowInfo.setX(container.getX()); |
314 |
windowInfo.setY(container.getY()); |
315 |
windowInfo.setClosed(!container.isShowing()); |
316 |
if (container instanceof JFrame) { |
317 |
JFrame frame = (JFrame) container; |
318 |
if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) { |
319 |
windowInfo.setMaximized(true);
|
320 |
} |
321 |
else {
|
322 |
windowInfo.setMaximized(false);
|
323 |
windowInfo.setNormalBounds(frame.getBounds()); |
324 |
} |
325 |
} |
326 |
} |
327 |
|
328 |
/**
|
329 |
* Updates the windowInfo object, so that it correctly reflects the
|
330 |
* current frame properties.
|
331 |
*
|
332 |
* @param win
|
333 |
* @param windowInfo The WindowInfo object to update
|
334 |
*/
|
335 |
public void updateWindowInfo(IWindow win, WindowInfo windowInfo) { |
336 |
Object o = viewFrame.get(win);
|
337 |
if (windowInfo!=null && o!=null) { |
338 |
if (o instanceof Container) { |
339 |
updateWindowInfo((Container) o, windowInfo);
|
340 |
} |
341 |
} |
342 |
} |
343 |
} |