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