root / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / FrameWindowSupport.java @ 10381
History | View | Annotate | Download (9.2 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.core.mdiManager; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.Image; |
46 |
import java.util.Hashtable; |
47 |
import java.util.Iterator; |
48 |
|
49 |
import javax.swing.ImageIcon; |
50 |
import javax.swing.JComponent; |
51 |
import javax.swing.JDialog; |
52 |
import javax.swing.JFrame; |
53 |
import javax.swing.JInternalFrame; |
54 |
import javax.swing.JPanel; |
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
58 |
import com.iver.andami.ui.mdiManager.IWindow; |
59 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
60 |
import com.iver.core.mdiManager.frames.ExternalFrame; |
61 |
import com.iver.core.mdiManager.frames.IFrame; |
62 |
import com.iver.core.mdiManager.frames.InternalFrame; |
63 |
|
64 |
|
65 |
/**
|
66 |
*
|
67 |
*/
|
68 |
public class FrameWindowSupport { |
69 |
private Hashtable frameView = new Hashtable(); |
70 |
private Hashtable viewFrame = new Hashtable(); |
71 |
private Image icon; |
72 |
private WindowInfoSupport vis;
|
73 |
private JFrame mainFrame; |
74 |
|
75 |
/**
|
76 |
* Creates a new FrameViewSupport object.
|
77 |
*
|
78 |
* @param i DOCUMENT ME!
|
79 |
*/
|
80 |
public FrameWindowSupport(MDIFrame mainFrame) {
|
81 |
this.mainFrame = mainFrame;
|
82 |
icon = mainFrame.getIconImage(); |
83 |
} |
84 |
|
85 |
public Iterator getWindowIterator(){ |
86 |
return viewFrame.keySet().iterator();
|
87 |
} |
88 |
|
89 |
public boolean contains(IWindow v){ |
90 |
return viewFrame.containsKey(v);
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* @param wnd
|
95 |
* @return
|
96 |
*/
|
97 |
public boolean contains(JInternalFrame wnd) { |
98 |
return frameView.contains(wnd);
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* DOCUMENT ME!
|
103 |
*
|
104 |
* @param p DOCUMENT ME!
|
105 |
*
|
106 |
* @return DOCUMENT ME!
|
107 |
*/
|
108 |
public JDialog getJDialog(IWindow p) { |
109 |
JDialog dlg = (JDialog) viewFrame.get(p); |
110 |
|
111 |
if (dlg == null) { |
112 |
WindowInfo vi = vis.getWindowInfo(p); |
113 |
ExternalFrame nuevo = new ExternalFrame(mainFrame);
|
114 |
|
115 |
nuevo.getContentPane().add((JPanel) p);
|
116 |
nuevo.setSize(getWidth(p, vi), getHeight(p, vi) + 30);
|
117 |
nuevo.setTitle(vi.getTitle()); |
118 |
nuevo.setResizable(vi.isResizable()); |
119 |
nuevo.setMinimumSize(vi.getMinimumSize()); |
120 |
|
121 |
viewFrame.put(p, nuevo); |
122 |
frameView.put(nuevo, p); |
123 |
|
124 |
nuevo.setModal(vi.isModal()); |
125 |
return nuevo;
|
126 |
} else {
|
127 |
return dlg;
|
128 |
} |
129 |
} |
130 |
|
131 |
/**
|
132 |
* DOCUMENT ME!
|
133 |
*
|
134 |
* @param p DOCUMENT ME!
|
135 |
*
|
136 |
* @return DOCUMENT ME!
|
137 |
*/
|
138 |
public JInternalFrame getJInternalFrame(IWindow p) { |
139 |
JInternalFrame frame = (JInternalFrame) viewFrame.get(p); |
140 |
|
141 |
if (frame == null) { |
142 |
//ViewInfo vi = vis.getViewInfo(p);
|
143 |
JInternalFrame nuevo = createJInternalFrame(p);
|
144 |
viewFrame.put(p, nuevo); |
145 |
frameView.put(nuevo, p); |
146 |
|
147 |
return nuevo;
|
148 |
} else {
|
149 |
return frame;
|
150 |
} |
151 |
} |
152 |
|
153 |
/**
|
154 |
* Gets the frame associated to the provided IWindow panel.
|
155 |
* The frame will usually be a JInternalFrame or a JDialog.
|
156 |
*
|
157 |
* @param panel The IWindow panel whose frame wants to be retrieved.
|
158 |
*
|
159 |
* @return The associated frame, it will usually be a JInternalFrame or
|
160 |
* a JDialog.
|
161 |
*/
|
162 |
public Component getFrame(IWindow panel) { |
163 |
Object object = viewFrame.get(panel);
|
164 |
if (object!=null && object instanceof Component) { |
165 |
return (Component) object; |
166 |
} |
167 |
else {
|
168 |
PluginServices.getLogger().error("window_not_found_"+panel.getWindowInfo().getTitle());
|
169 |
return null; |
170 |
} |
171 |
} |
172 |
|
173 |
public JInternalFrame createJInternalFrame(IWindow p) |
174 |
{ |
175 |
WindowInfo wi = vis.getWindowInfo(p); |
176 |
JInternalFrame nuevo = new InternalFrame(); |
177 |
if (icon != null){ |
178 |
nuevo.setFrameIcon(new ImageIcon(icon)); |
179 |
} |
180 |
|
181 |
nuevo.getContentPane().add((JPanel) p);
|
182 |
nuevo.setClosable(true);
|
183 |
nuevo.setSize(getWidth(p, wi), getHeight(p, wi)); |
184 |
nuevo.setTitle(wi.getTitle()); |
185 |
nuevo.setVisible(wi.isVisible()); |
186 |
nuevo.setResizable(wi.isResizable()); |
187 |
nuevo.setIconifiable(wi.isIconifiable()); |
188 |
nuevo.setMaximizable(wi.isMaximizable()); |
189 |
nuevo.setLocation(wi.getX(), wi.getY()); |
190 |
nuevo.setMinimumSize(wi.getMinimumSize()); |
191 |
|
192 |
nuevo.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
193 |
return nuevo;
|
194 |
} |
195 |
|
196 |
public IWindow getWindow(Component dlg){ |
197 |
return (IWindow) frameView.get(dlg);
|
198 |
} |
199 |
|
200 |
public void closeWindow(IWindow v){ |
201 |
Object c = viewFrame.remove(v);
|
202 |
frameView.remove(c); |
203 |
} |
204 |
|
205 |
/**
|
206 |
* DOCUMENT ME!
|
207 |
*
|
208 |
* @param v DOCUMENT ME!
|
209 |
* @param x DOCUMENT ME!
|
210 |
*/
|
211 |
public void setX(IWindow win, int x) { |
212 |
IFrame frame = (IFrame) viewFrame.get(win); |
213 |
frame.setX(x); |
214 |
} |
215 |
|
216 |
/**
|
217 |
* DOCUMENT ME!
|
218 |
*
|
219 |
* @param v DOCUMENT ME!
|
220 |
* @param y DOCUMENT ME!
|
221 |
*/
|
222 |
public void setY(IWindow win, int y) { |
223 |
IFrame frame = (IFrame) viewFrame.get(win); |
224 |
frame.setY(y); |
225 |
} |
226 |
|
227 |
/**
|
228 |
* DOCUMENT ME!
|
229 |
*
|
230 |
* @param v DOCUMENT ME!
|
231 |
* @param height DOCUMENT ME!
|
232 |
*/
|
233 |
public void setHeight(IWindow win, int height) { |
234 |
IFrame frame = (IFrame) viewFrame.get(win); |
235 |
frame.setHeight(height); |
236 |
} |
237 |
|
238 |
/**
|
239 |
* DOCUMENT ME!
|
240 |
*
|
241 |
* @param v DOCUMENT ME!
|
242 |
* @param width DOCUMENT ME!
|
243 |
*/
|
244 |
public void setWidth(IWindow win, int width) { |
245 |
IFrame frame = (IFrame) viewFrame.get(win); |
246 |
frame.setWidth(width); |
247 |
} |
248 |
|
249 |
/**
|
250 |
* DOCUMENT ME!
|
251 |
*
|
252 |
* @param v DOCUMENT ME!
|
253 |
* @param title DOCUMENT ME!
|
254 |
*/
|
255 |
public void setTitle(IWindow win, String title) { |
256 |
IFrame frame = (IFrame) viewFrame.get(win); |
257 |
frame.setTitle(title); |
258 |
} |
259 |
|
260 |
/**
|
261 |
* Sets the minimum allowed size for the provided window.
|
262 |
*
|
263 |
* @param sw
|
264 |
* @param minSize
|
265 |
*/
|
266 |
public void setMinimumSize(IWindow win, Dimension minSize) { |
267 |
IFrame frame = (IFrame) viewFrame.get(win); |
268 |
frame.setMinimumSize(minSize); |
269 |
} |
270 |
|
271 |
/**
|
272 |
* DOCUMENT ME!
|
273 |
*
|
274 |
* @param vis The vis to set.
|
275 |
*/
|
276 |
public void setVis(WindowInfoSupport vis) { |
277 |
this.vis = vis;
|
278 |
} |
279 |
|
280 |
/**
|
281 |
* DOCUMENT ME!
|
282 |
*
|
283 |
* @param v DOCUMENT ME!
|
284 |
*
|
285 |
* @return DOCUMENT ME!
|
286 |
*/
|
287 |
private int getWidth(IWindow v) { |
288 |
WindowInfo vi = vis.getWindowInfo(v); |
289 |
|
290 |
if (vi.getWidth() == -1) { |
291 |
JPanel p = (JPanel) v; |
292 |
|
293 |
return p.getSize().width;
|
294 |
} else {
|
295 |
return vi.getWidth();
|
296 |
} |
297 |
} |
298 |
|
299 |
/**
|
300 |
* DOCUMENT ME!
|
301 |
*
|
302 |
* @param v DOCUMENT ME!
|
303 |
*
|
304 |
* @return DOCUMENT ME!
|
305 |
*/
|
306 |
private int getWidth(IWindow v, WindowInfo wi) { |
307 |
if (wi.getWidth() == -1) { |
308 |
JPanel p = (JPanel) v; |
309 |
|
310 |
return p.getSize().width;
|
311 |
} else {
|
312 |
return wi.getWidth();
|
313 |
} |
314 |
} |
315 |
|
316 |
/**
|
317 |
* DOCUMENT ME!
|
318 |
*
|
319 |
* @param v DOCUMENT ME!
|
320 |
*
|
321 |
* @return DOCUMENT ME!
|
322 |
*/
|
323 |
private int getHeight(IWindow v) { |
324 |
WindowInfo vi = vis.getWindowInfo(v); |
325 |
|
326 |
if (vi.getHeight() == -1) { |
327 |
JPanel p = (JPanel) v; |
328 |
|
329 |
return p.getSize().height;
|
330 |
} else {
|
331 |
return vi.getHeight();
|
332 |
} |
333 |
} |
334 |
|
335 |
/**
|
336 |
* DOCUMENT ME!
|
337 |
*
|
338 |
* @param v DOCUMENT ME!
|
339 |
*
|
340 |
* @return DOCUMENT ME!
|
341 |
*/
|
342 |
private int getHeight(IWindow v, WindowInfo wi) { |
343 |
if (wi.getHeight() == -1) { |
344 |
JPanel p = (JPanel) v; |
345 |
|
346 |
return p.getSize().height;
|
347 |
} else {
|
348 |
return wi.getHeight();
|
349 |
} |
350 |
} |
351 |
|
352 |
public void updateWindowInfo(IWindow win, WindowInfo windowInfo) { |
353 |
Object o = viewFrame.get(win);
|
354 |
if (windowInfo!=null && o!=null) { |
355 |
if (o instanceof JComponent) { |
356 |
JComponent component = (JComponent) o; |
357 |
windowInfo.updateWidth(component.getWidth()); |
358 |
windowInfo.updateHeight(component.getHeight()); |
359 |
windowInfo.updateX(component.getX()); |
360 |
windowInfo.updateY(component.getY()); |
361 |
windowInfo.updateClosed(!component.isShowing()); |
362 |
if (component instanceof JInternalFrame) { |
363 |
JInternalFrame iframe = (JInternalFrame) component; |
364 |
windowInfo.updateNormalBounds(iframe.getNormalBounds()); |
365 |
windowInfo.updateMaximized(iframe.isMaximum()); |
366 |
} |
367 |
} |
368 |
} |
369 |
} |
370 |
} |