root / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / SingletonWindowSupport.java @ 9997
History | View | Annotate | Download (9.63 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.Dimension; |
44 |
import java.awt.Rectangle; |
45 |
import java.beans.PropertyVetoException; |
46 |
import java.util.ArrayList; |
47 |
|
48 |
import javax.swing.JComponent; |
49 |
import javax.swing.JInternalFrame; |
50 |
|
51 |
import com.iver.andami.ui.mdiManager.SingletonDialogAlreadyShownException; |
52 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
53 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
54 |
|
55 |
|
56 |
/**
|
57 |
* DOCUMENT ME!
|
58 |
*
|
59 |
* @author $author$
|
60 |
* @version $Revision: 9997 $
|
61 |
*/
|
62 |
public class SingletonWindowSupport { |
63 |
private static int singletonViewInfoID = 0; |
64 |
/** Hashtable que asocia contenido con vistas */
|
65 |
private HashMap contentWindowInfo = new HashMap(); |
66 |
private WindowInfoSupport vis;
|
67 |
private FrameWindowSupport frameWindowSupport;
|
68 |
private HashMap contentFrame = new HashMap(); |
69 |
|
70 |
/**
|
71 |
* DOCUMENT ME!
|
72 |
*
|
73 |
* @param vis DOCUMENT ME!
|
74 |
* @param fvs
|
75 |
*
|
76 |
* @see com.iver.andami.ui.mdiManager.MDIManager#init(com.iver.andami.ui.mdiFrame.MDIFrame)
|
77 |
*/
|
78 |
public SingletonWindowSupport(WindowInfoSupport vis, FrameWindowSupport fvs) {
|
79 |
this.vis = vis;
|
80 |
this.frameWindowSupport = fvs;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Devuelve una referencia a la vista si ya est? mostrada o null si la
|
85 |
* vista no ha sido a?adida o ya fue cerrada
|
86 |
*
|
87 |
* @param windowClass DOCUMENT ME!
|
88 |
* @param model DOCUMENT ME!
|
89 |
* @param wi DOCUMENT ME!
|
90 |
*
|
91 |
* @return true si la vista existe ya y false si la vista no existe
|
92 |
*
|
93 |
* @throws SingletonDialogAlreadyShownException DOCUMENT ME!
|
94 |
*/
|
95 |
public boolean registerWindow(Class windowClass, Object model, WindowInfo wi) { |
96 |
//Se comprueba si la ventana est? siendo mostrada
|
97 |
SingletonWindowInfo swi = new SingletonWindowInfo(windowClass, model);
|
98 |
|
99 |
if (contentWindowInfo.containsKey(swi)) {
|
100 |
if (wi.isModal()) {
|
101 |
throw new SingletonDialogAlreadyShownException(); |
102 |
} |
103 |
|
104 |
wi.setWindowInfo((WindowInfo)contentWindowInfo.get(swi)); |
105 |
|
106 |
return true; |
107 |
} else {
|
108 |
//La ventana singleton no estaba mostrada
|
109 |
//Se asocia el modelo con la vista
|
110 |
contentWindowInfo.put(swi, wi); |
111 |
return false; |
112 |
} |
113 |
} |
114 |
|
115 |
public void openSingletonWindow(SingletonWindow sw, JComponent frame){ |
116 |
SingletonWindowInfo swi = new SingletonWindowInfo(sw.getClass(), sw.getWindowModel());
|
117 |
contentFrame.put(swi, frame); |
118 |
} |
119 |
|
120 |
public boolean contains(SingletonWindow sw){ |
121 |
SingletonWindowInfo swi = new SingletonWindowInfo(sw.getClass(), sw.getWindowModel());
|
122 |
return contentFrame.containsKey(swi);
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* DOCUMENT ME!
|
127 |
*
|
128 |
* @param sw
|
129 |
*/
|
130 |
public void closeWindow(SingletonWindow sw) { |
131 |
SingletonWindowInfo swi = new SingletonWindowInfo(sw.getClass(), sw.getWindowModel());
|
132 |
WindowInfo windowInfo = (WindowInfo) contentWindowInfo.get(swi); |
133 |
if (windowInfo!=null) { |
134 |
frameWindowSupport.updateWindowInfo(sw, windowInfo); |
135 |
} |
136 |
contentFrame.remove(swi); |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Representa una vista singleton manteniendo el modelo y la clase de la
|
141 |
* vista que lo muestra
|
142 |
*
|
143 |
* @author Fernando Gonz?lez Cort?s
|
144 |
*/
|
145 |
public class SingletonWindowInfo { |
146 |
|
147 |
public int id; |
148 |
|
149 |
/** Clase de la vista */
|
150 |
public Class clase; |
151 |
|
152 |
/** Modelo que representa la vista */
|
153 |
public Object modelo; |
154 |
|
155 |
/**
|
156 |
* Creates a new SingletonView object.
|
157 |
*
|
158 |
* @param clase Clase de la vista
|
159 |
* @param modelo Modelo que representa la vista
|
160 |
*/
|
161 |
public SingletonWindowInfo(Class clase, Object modelo) { |
162 |
this.clase = clase;
|
163 |
this.modelo = modelo;
|
164 |
this.id = singletonViewInfoID;
|
165 |
singletonViewInfoID++; |
166 |
} |
167 |
|
168 |
/**
|
169 |
* @see java.lang.Object#equals(java.lang.Object)
|
170 |
*/
|
171 |
public boolean equals(Object obj) { |
172 |
if (obj.getClass() != SingletonWindowInfo.class) {
|
173 |
throw new IllegalArgumentException(); |
174 |
} |
175 |
|
176 |
SingletonWindowInfo s = (SingletonWindowInfo) obj; |
177 |
|
178 |
if ((clase == s.clase) && (modelo == s.modelo)) {
|
179 |
return true; |
180 |
} else {
|
181 |
return false; |
182 |
} |
183 |
} |
184 |
} |
185 |
|
186 |
private JInternalFrame getFrame(SingletonWindowInfo svi){ |
187 |
WindowInfo vi = (WindowInfo) contentWindowInfo.get(svi); |
188 |
return (JInternalFrame) contentFrame.get(svi); |
189 |
} |
190 |
|
191 |
public JInternalFrame getFrame(Class viewClass, Object model){ |
192 |
SingletonWindowInfo svi = new SingletonWindowInfo(viewClass, model);
|
193 |
return getFrame(svi);
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @param model
|
198 |
* @return
|
199 |
*/
|
200 |
public JInternalFrame[] getFrames(Object model) { |
201 |
ArrayList ret = new ArrayList(); |
202 |
|
203 |
ArrayList keys = contentFrame.getKeys();
|
204 |
for (int i = 0; i < keys.size(); i++) { |
205 |
SingletonWindowInfo svi = (SingletonWindowInfo) keys.get(i); |
206 |
|
207 |
if (svi.modelo == model){
|
208 |
ret.add(contentFrame.get(svi)); |
209 |
} |
210 |
} |
211 |
|
212 |
return (JInternalFrame[]) ret.toArray(new JInternalFrame[0]); |
213 |
} |
214 |
|
215 |
/**
|
216 |
* @param view
|
217 |
* @return
|
218 |
*/
|
219 |
public JInternalFrame getFrame(SingletonWindow sv) { |
220 |
SingletonWindowInfo svi = new SingletonWindowInfo(sv.getClass(), sv.getWindowModel());
|
221 |
return getFrame(svi);
|
222 |
} |
223 |
|
224 |
/**
|
225 |
* @param sv
|
226 |
* @param i
|
227 |
*/
|
228 |
public void setX(SingletonWindow sv, int x) { |
229 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonWindowInfo(sv.getClass(), sv.getWindowModel())); |
230 |
|
231 |
if (o == null) return; |
232 |
o.setLocation(x, o.getY()); |
233 |
} |
234 |
|
235 |
/**
|
236 |
* @param sv
|
237 |
* @param i
|
238 |
*/
|
239 |
public void setY(SingletonWindow sv, int y) { |
240 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonWindowInfo(sv.getClass(), sv.getWindowModel())); |
241 |
|
242 |
if (o == null) return; |
243 |
|
244 |
o.setLocation(o.getX(), y); |
245 |
} |
246 |
|
247 |
/**
|
248 |
* @param sv
|
249 |
* @param i
|
250 |
*/
|
251 |
public void setHeight(SingletonWindow sv, int height) { |
252 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonWindowInfo(sv.getClass(), sv.getWindowModel())); |
253 |
|
254 |
if (o == null) return; |
255 |
|
256 |
o.setSize(o.getWidth(), height); |
257 |
} |
258 |
|
259 |
/**
|
260 |
* @param sv
|
261 |
* @param i
|
262 |
*/
|
263 |
public void setWidth(SingletonWindow sv, int width) { |
264 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonWindowInfo(sv.getClass(), sv.getWindowModel())); |
265 |
|
266 |
if (o == null) return; |
267 |
o.setSize(width, o.getHeight()); |
268 |
} |
269 |
|
270 |
/**
|
271 |
* @param sw
|
272 |
* @param maximized
|
273 |
*/
|
274 |
public void setMaximized(SingletonWindow sw, boolean maximized) { |
275 |
JInternalFrame frame = (JInternalFrame) contentFrame.get(new SingletonWindowInfo(sw.getClass(), sw.getWindowModel())); |
276 |
|
277 |
if (frame == null) return; |
278 |
try {
|
279 |
frame.setMaximum(maximized); |
280 |
} catch (PropertyVetoException e) { |
281 |
// TODO Auto-generated catch block
|
282 |
//e.printStackTrace();
|
283 |
} |
284 |
} |
285 |
|
286 |
/**
|
287 |
* @param sw
|
288 |
* @param maximized
|
289 |
*/
|
290 |
public void setNormalBounds(SingletonWindow sw, Rectangle normalBounds) { |
291 |
JInternalFrame frame = (JInternalFrame) contentFrame.get(new SingletonWindowInfo(sw.getClass(), sw.getWindowModel())); |
292 |
|
293 |
if (frame == null) return; |
294 |
frame.setNormalBounds(normalBounds); |
295 |
} |
296 |
|
297 |
/**
|
298 |
* Sets the minimum allowed size for the provided singleton window.
|
299 |
*
|
300 |
* @param sw
|
301 |
* @param minSize
|
302 |
*/
|
303 |
public void setMinimumSize(SingletonWindow sw, Dimension minSize) { |
304 |
JInternalFrame frame = (JInternalFrame) contentFrame.get(new SingletonWindowInfo(sw.getClass(), sw.getWindowModel())); |
305 |
|
306 |
if (frame == null) return; |
307 |
frame.setMinimumSize(minSize); |
308 |
} |
309 |
|
310 |
/**
|
311 |
* @param sv
|
312 |
* @param string
|
313 |
*/
|
314 |
public void setTitle(SingletonWindow sv, String title) { |
315 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonWindowInfo(sv.getClass(), sv.getWindowModel())); |
316 |
|
317 |
if (o == null) return; |
318 |
o.setTitle(title); |
319 |
} |
320 |
|
321 |
private class HashMap { |
322 |
private ArrayList keys = new ArrayList(); |
323 |
private ArrayList values = new ArrayList(); |
324 |
|
325 |
public void put(SingletonWindowInfo key, Object value) { |
326 |
int index = -1; |
327 |
for (int i = 0; i < keys.size(); i++) { |
328 |
if (keys.get(i).equals(key)){
|
329 |
index = i; |
330 |
break;
|
331 |
} |
332 |
} |
333 |
|
334 |
if (index != -1){ |
335 |
keys.add(index, key); |
336 |
values.add(index, value); |
337 |
}else{
|
338 |
keys.add(key); |
339 |
values.add(value); |
340 |
} |
341 |
} |
342 |
|
343 |
public boolean containsKey(SingletonWindowInfo key){ |
344 |
for (int i = 0; i < keys.size(); i++) { |
345 |
if (keys.get(i).equals(key)){
|
346 |
return true; |
347 |
} |
348 |
} |
349 |
|
350 |
return false; |
351 |
} |
352 |
|
353 |
public Object get(SingletonWindowInfo key){ |
354 |
for (int i = 0; i < keys.size(); i++) { |
355 |
if (keys.get(i).equals(key)){
|
356 |
return values.get(i);
|
357 |
} |
358 |
} |
359 |
|
360 |
return null; |
361 |
} |
362 |
|
363 |
public void remove(SingletonWindowInfo key){ |
364 |
for (int i = 0; i < keys.size(); i++) { |
365 |
if (keys.get(i).equals(key)){
|
366 |
keys.remove(i); |
367 |
values.remove(i); |
368 |
} |
369 |
} |
370 |
} |
371 |
|
372 |
public ArrayList getKeys(){ |
373 |
return keys;
|
374 |
} |
375 |
} |
376 |
} |