svn-gvsig-desktop / branches / v10 / frameworks / _fwAndami / src / com / iver / andami / ui / mdiManager / WindowInfo.java @ 7417
History | View | Annotate | Download (15 KB)
1 | 6880 | 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 | package com.iver.andami.ui.mdiManager; |
||
42 | |||
43 | import java.awt.Rectangle; |
||
44 | import java.beans.PropertyChangeListener; |
||
45 | import java.beans.PropertyChangeSupport; |
||
46 | |||
47 | 7345 | cesar | import com.iver.andami.PluginServices; |
48 | import com.iver.utiles.XMLEntity; |
||
49 | 6880 | cesar | |
50 | 7345 | cesar | |
51 | 6880 | cesar | /**
|
52 | * DOCUMENT ME!
|
||
53 | *
|
||
54 | * @author Fernando Gonz?lez Cort?s
|
||
55 | */
|
||
56 | public class WindowInfo { |
||
57 | /** DOCUMENT ME! */
|
||
58 | public static final int RESIZABLE = 1; |
||
59 | |||
60 | /** DOCUMENT ME! */
|
||
61 | public static final int MAXIMIZABLE = 2; |
||
62 | |||
63 | /** DOCUMENT ME! */
|
||
64 | public static final int ICONIFIABLE = 4; |
||
65 | |||
66 | /** DOCUMENT ME! */
|
||
67 | public static final int MODALDIALOG = 8; |
||
68 | public static final int MODELESSDIALOG = 16; |
||
69 | public static final int PALETTE = 32; |
||
70 | private PropertyChangeSupport support = new PropertyChangeSupport(this); |
||
71 | |||
72 | /** DOCUMENT ME! */
|
||
73 | private boolean resizable = false; |
||
74 | |||
75 | /** DOCUMENT ME! */
|
||
76 | private boolean maximizable = false; |
||
77 | |||
78 | /** DOCUMENT ME! */
|
||
79 | private boolean iconifiable = false; |
||
80 | |||
81 | /** DOCUMENT ME! */
|
||
82 | private boolean modal = false; |
||
83 | private boolean modeless = false; |
||
84 | 7345 | cesar | |
85 | /**
|
||
86 | * Do we want to persist the geometry of this window in the project file?
|
||
87 | */
|
||
88 | private boolean persistWindow = true; |
||
89 | 6880 | cesar | |
90 | /**
|
||
91 | * Se usa para poner una ventana de tipo paleta, por
|
||
92 | * encima de las dem?s. Equivale a poner usar
|
||
93 | * JDesktopPane.PALETTE_LAYER
|
||
94 | */
|
||
95 | private boolean palette = false; |
||
96 | |||
97 | /** These properties store the dimension and position of the frame */
|
||
98 | private int width = -1; |
||
99 | private int height = -1; |
||
100 | private int x = 0; |
||
101 | private int y = 0; |
||
102 | /**
|
||
103 | * These properties store the position and dimension of the frame when it is not maximized
|
||
104 | * (so that it can be restored to its original size). They are equal to the not-normal properties
|
||
105 | * when the frame is not maximized, and different when the frame is maximized.
|
||
106 | */
|
||
107 | private int normalX = 0; |
||
108 | private int normalY = 0; |
||
109 | private int normalHeight = 0; |
||
110 | private int normalWidth = 0; |
||
111 | /* Whether the window is maximized */
|
||
112 | private boolean isMaximized = false; |
||
113 | private boolean visible = true; |
||
114 | /* Whether the window is closed */
|
||
115 | private boolean isClosed = false; |
||
116 | |||
117 | |||
118 | /** DOCUMENT ME! */
|
||
119 | private String title; |
||
120 | |||
121 | private int id; |
||
122 | |||
123 | /**
|
||
124 | * ActionCommand del tool seleccionado. Lo usamos
|
||
125 | * para activar el tool que estaba seleccionado en
|
||
126 | * la vista, cuando volvemos a ella.
|
||
127 | */
|
||
128 | private String selectedTool; |
||
129 | |||
130 | /**
|
||
131 | * DOCUMENT ME!
|
||
132 | *
|
||
133 | * @return Returns the x.
|
||
134 | */
|
||
135 | public int getX() { |
||
136 | return x;
|
||
137 | } |
||
138 | |||
139 | /**
|
||
140 | * DOCUMENT ME!
|
||
141 | *
|
||
142 | * @param x The x to set.
|
||
143 | */
|
||
144 | public void setX(int x) { |
||
145 | support.firePropertyChange("x", this.x, x); |
||
146 | this.x = x;
|
||
147 | 7345 | cesar | if (!isMaximized)
|
148 | this.normalX = x;
|
||
149 | 6880 | cesar | } |
150 | |||
151 | /**
|
||
152 | * DOCUMENT ME!
|
||
153 | *
|
||
154 | * @return Returns the y.
|
||
155 | */
|
||
156 | public int getY() { |
||
157 | return y;
|
||
158 | } |
||
159 | |||
160 | /**
|
||
161 | * DOCUMENT ME!
|
||
162 | *
|
||
163 | * @param y The y to set.
|
||
164 | */
|
||
165 | public void setY(int y) { |
||
166 | support.firePropertyChange("y", this.y, y); |
||
167 | this.y = y;
|
||
168 | 7345 | cesar | if (!isMaximized)
|
169 | this.normalY = y;
|
||
170 | 6880 | cesar | } |
171 | |||
172 | /**
|
||
173 | * DOCUMENT ME!
|
||
174 | *
|
||
175 | * @param listener
|
||
176 | */
|
||
177 | public void addPropertyChangeListener(PropertyChangeListener listener) { |
||
178 | support.addPropertyChangeListener(listener); |
||
179 | } |
||
180 | |||
181 | /**
|
||
182 | * DOCUMENT ME!
|
||
183 | *
|
||
184 | * @param listener
|
||
185 | */
|
||
186 | public void removePropertyChangeListener(PropertyChangeListener listener) { |
||
187 | support.removePropertyChangeListener(listener); |
||
188 | } |
||
189 | |||
190 | /**
|
||
191 | * Establece las propiedades de la vista
|
||
192 | *
|
||
193 | * @param code Bit-or de las propiedades de la vista
|
||
194 | *
|
||
195 | * @throws IllegalStateException DOCUMENT ME!
|
||
196 | */
|
||
197 | public WindowInfo(int code) { |
||
198 | resizable = (code % 2) > 0; |
||
199 | code = code / 2;
|
||
200 | maximizable = (code % 2) > 0; |
||
201 | code = code / 2;
|
||
202 | iconifiable = (code % 2) > 0; |
||
203 | code = code / 2;
|
||
204 | modal = (code % 2) > 0; |
||
205 | code = code / 2;
|
||
206 | modeless = (code % 2) > 0; |
||
207 | code = code / 2;
|
||
208 | palette = (code % 2) > 0; |
||
209 | |||
210 | if (modal && modeless) {
|
||
211 | throw new IllegalStateException("modal && modeless"); |
||
212 | } |
||
213 | } |
||
214 | |||
215 | public WindowInfo(){
|
||
216 | |||
217 | } |
||
218 | |||
219 | /**
|
||
220 | * Si es iconificable
|
||
221 | *
|
||
222 | * @return
|
||
223 | */
|
||
224 | public boolean isIconifiable() { |
||
225 | return iconifiable;
|
||
226 | } |
||
227 | |||
228 | /**
|
||
229 | * Si es maximizable
|
||
230 | *
|
||
231 | * @return
|
||
232 | */
|
||
233 | public boolean isMaximizable() { |
||
234 | return maximizable;
|
||
235 | } |
||
236 | |||
237 | /**
|
||
238 | * Si es resizable
|
||
239 | *
|
||
240 | * @return
|
||
241 | */
|
||
242 | public boolean isResizable() { |
||
243 | return resizable;
|
||
244 | } |
||
245 | |||
246 | /**
|
||
247 | * Devuelve si el di?logo es modal
|
||
248 | *
|
||
249 | * @return
|
||
250 | */
|
||
251 | public boolean isModal() { |
||
252 | return modal;
|
||
253 | } |
||
254 | |||
255 | /**
|
||
256 | * Obtiene la altura de la vista
|
||
257 | *
|
||
258 | * @return
|
||
259 | */
|
||
260 | public int getHeight() { |
||
261 | return height;
|
||
262 | } |
||
263 | |||
264 | /**
|
||
265 | * Obtiene la anchura de la vista
|
||
266 | *
|
||
267 | * @return
|
||
268 | */
|
||
269 | public int getWidth() { |
||
270 | return width;
|
||
271 | } |
||
272 | |||
273 | /**
|
||
274 | * establece la propiedad altura
|
||
275 | *
|
||
276 | 7345 | cesar | * @param h
|
277 | 6880 | cesar | */
|
278 | 7345 | cesar | public void setHeight(int h) { |
279 | support.firePropertyChange("height", this.height, h); |
||
280 | height = h; |
||
281 | if (!isMaximized)
|
||
282 | this.normalHeight = h;
|
||
283 | 6880 | cesar | } |
284 | |||
285 | /**
|
||
286 | * establece la propiedad anchura
|
||
287 | *
|
||
288 | * @param i
|
||
289 | */
|
||
290 | 7345 | cesar | public void setWidth(int w) { |
291 | support.firePropertyChange("width", this.width, w); |
||
292 | width = w; |
||
293 | if (!isMaximized)
|
||
294 | this.width = w;
|
||
295 | 6880 | cesar | } |
296 | |||
297 | /**
|
||
298 | * obtiene la propiedad titulo
|
||
299 | *
|
||
300 | * @return
|
||
301 | */
|
||
302 | public String getTitle() { |
||
303 | return title;
|
||
304 | } |
||
305 | |||
306 | /**
|
||
307 | * establece la propiedad titulo
|
||
308 | *
|
||
309 | * @param string
|
||
310 | */
|
||
311 | public void setTitle(String string) { |
||
312 | support.firePropertyChange("title", this.title, string); |
||
313 | title = string; |
||
314 | } |
||
315 | |||
316 | /**
|
||
317 | * DOCUMENT ME!
|
||
318 | *
|
||
319 | * @return
|
||
320 | */
|
||
321 | public boolean isModeless() { |
||
322 | return modeless;
|
||
323 | } |
||
324 | |||
325 | /**
|
||
326 | * DOCUMENT ME!
|
||
327 | *
|
||
328 | * @return
|
||
329 | */
|
||
330 | public boolean isVisible() { |
||
331 | return visible;
|
||
332 | } |
||
333 | |||
334 | public boolean isPalette() |
||
335 | { |
||
336 | return palette;
|
||
337 | } |
||
338 | |||
339 | public void setId(int id){ |
||
340 | this.id = id;
|
||
341 | } |
||
342 | |||
343 | public int getId(){ |
||
344 | return id;
|
||
345 | } |
||
346 | |||
347 | public void setWindowInfo(WindowInfo vi){ |
||
348 | this.resizable = vi.resizable;
|
||
349 | this.maximizable = vi.maximizable;
|
||
350 | this.iconifiable = vi.iconifiable;
|
||
351 | this.modal = vi.modal;
|
||
352 | this.modeless = vi.modeless;
|
||
353 | this.width = vi.width;
|
||
354 | this.height = vi.height;
|
||
355 | this.x = vi.x;
|
||
356 | this.y = vi.y;
|
||
357 | this.visible = vi.visible;
|
||
358 | this.title = vi.title;
|
||
359 | this.id = vi.id;
|
||
360 | 7345 | cesar | this.normalHeight = vi.normalHeight;
|
361 | this.normalWidth = vi.normalWidth;
|
||
362 | this.normalX = vi.normalX;
|
||
363 | this.normalY = vi.normalY;
|
||
364 | this.isClosed = vi.isClosed;
|
||
365 | this.persistWindow = vi.persistWindow;
|
||
366 | 6880 | cesar | } |
367 | public void toPalette(boolean b){ |
||
368 | this.palette=b;
|
||
369 | } |
||
370 | |||
371 | public String getSelectedTool() { |
||
372 | return selectedTool;
|
||
373 | } |
||
374 | |||
375 | public void setSelectedTool(String selectedTool) { |
||
376 | if (selectedTool != null) |
||
377 | this.selectedTool = selectedTool;
|
||
378 | } |
||
379 | |||
380 | /* Finds out whether a view is open (showing) or closed */
|
||
381 | public boolean isClosed() { |
||
382 | return isClosed;
|
||
383 | } |
||
384 | |||
385 | /* Specifies whether a view is open (showing) or closed */
|
||
386 | public void setClosed(boolean closed) { |
||
387 | 7345 | cesar | support.firePropertyChange("closed", this.isClosed, closed); |
388 | 6880 | cesar | this.isClosed = closed;
|
389 | } |
||
390 | |||
391 | public void setNormalX(int normalX) { |
||
392 | 7345 | cesar | support.firePropertyChange("normalX", this.normalX, normalX); |
393 | 6880 | cesar | this.normalX = normalX;
|
394 | } |
||
395 | |||
396 | public void setNormalY(int normalY) { |
||
397 | 7345 | cesar | support.firePropertyChange("normalY", this.normalY, normalY); |
398 | 6880 | cesar | this.normalY = normalY;
|
399 | } |
||
400 | |||
401 | public void setNormalHeight(int normalHeight) { |
||
402 | 7345 | cesar | support.firePropertyChange("normalHeight", this.normalHeight, normalHeight); |
403 | 6880 | cesar | this.normalHeight = normalHeight;
|
404 | } |
||
405 | |||
406 | public void setNormalWidth(int normalWidth) { |
||
407 | 7345 | cesar | support.firePropertyChange("normalWidth", this.normalWidth, normalWidth); |
408 | 6880 | cesar | this.normalWidth = normalWidth;
|
409 | } |
||
410 | |||
411 | |||
412 | public void setMaximized(boolean maximized) { |
||
413 | 7345 | cesar | support.firePropertyChange("maximized", this.isMaximized, maximized); |
414 | 6880 | cesar | this.isMaximized = maximized;
|
415 | } |
||
416 | |||
417 | private void setBounds(int x, int y, int width, int height) { |
||
418 | 7345 | cesar | support.firePropertyChange("x", this.height, x); |
419 | 6880 | cesar | this.x = x;
|
420 | 7345 | cesar | support.firePropertyChange("y", this.height, y); |
421 | 6880 | cesar | this.y = y;
|
422 | 7345 | cesar | support.firePropertyChange("width", this.width, width); |
423 | 6880 | cesar | this.width = width;
|
424 | 7345 | cesar | support.firePropertyChange("height", this.height, height); |
425 | 6880 | cesar | this.height = height;
|
426 | } |
||
427 | |||
428 | public void setNormalBounds(int x, int y, int width, int height) { |
||
429 | 7345 | cesar | support.firePropertyChange("normalX", this.normalX, x); |
430 | 6880 | cesar | this.normalX = x;
|
431 | 7345 | cesar | support.firePropertyChange("normalY", this.normalY, y); |
432 | 6880 | cesar | this.normalY = y;
|
433 | 7345 | cesar | support.firePropertyChange("width", this.width, width); |
434 | 6880 | cesar | this.normalWidth = width;
|
435 | 7345 | cesar | support.firePropertyChange("height", this.height, height); |
436 | 6880 | cesar | this.normalHeight = height;
|
437 | } |
||
438 | |||
439 | public Rectangle getNormalBounds() { |
||
440 | return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight()); |
||
441 | } |
||
442 | |||
443 | public void setNormalBounds(Rectangle normalBounds) { |
||
444 | 7345 | cesar | support.firePropertyChange("normalX", this.normalX, normalBounds.x); |
445 | 6880 | cesar | normalX = normalBounds.x; |
446 | 7345 | cesar | support.firePropertyChange("normalY", this.normalY, normalBounds.y); |
447 | 6880 | cesar | normalY = normalBounds.y; |
448 | 7345 | cesar | support.firePropertyChange("normalHeight", this.normalHeight, normalBounds.height); |
449 | 6880 | cesar | normalHeight = normalBounds.height; |
450 | 7345 | cesar | support.firePropertyChange("normalWidth", this.normalWidth, normalBounds.width); |
451 | 6880 | cesar | normalWidth = normalBounds.width; |
452 | } |
||
453 | |||
454 | public void setBounds(Rectangle bounds) { |
||
455 | 7345 | cesar | support.firePropertyChange("x", this.x, bounds.x); |
456 | 6880 | cesar | x = bounds.x; |
457 | 7345 | cesar | support.firePropertyChange("y", this.y, bounds.y); |
458 | 6880 | cesar | y = bounds.y; |
459 | 7345 | cesar | support.firePropertyChange("height", this.height, bounds.height); |
460 | 6880 | cesar | height = bounds.height; |
461 | 7345 | cesar | support.firePropertyChange("width", this.width, bounds.width); |
462 | 6880 | cesar | width = bounds.width; |
463 | } |
||
464 | |||
465 | public Rectangle getBounds() { |
||
466 | return new Rectangle(x, y, width, height); |
||
467 | } |
||
468 | |||
469 | public int getNormalX() { |
||
470 | if (normalX!=0) |
||
471 | return this.normalX; |
||
472 | else
|
||
473 | return x;
|
||
474 | } |
||
475 | |||
476 | public int getNormalY() { |
||
477 | if (normalY!=0) |
||
478 | return this.normalY; |
||
479 | else
|
||
480 | return y;
|
||
481 | } |
||
482 | |||
483 | public int getNormalHeight() { |
||
484 | if (normalHeight!=0) |
||
485 | return this.normalHeight; |
||
486 | else
|
||
487 | return height;
|
||
488 | } |
||
489 | |||
490 | public int getNormalWidth() { |
||
491 | if (normalWidth!=0) |
||
492 | return this.normalWidth; |
||
493 | else
|
||
494 | return width;
|
||
495 | } |
||
496 | |||
497 | public boolean isMaximized() { |
||
498 | return this.isMaximized; |
||
499 | } |
||
500 | 7345 | cesar | |
501 | /**
|
||
502 | * Checks if the geometry of this window should be persisted in the
|
||
503 | * project file. This is set by the persistWindow(boolean) method,
|
||
504 | * and the default value is true.
|
||
505 | *
|
||
506 | * @return True if the geometry of this window should be persisted
|
||
507 | * in the project files, false otherwise.
|
||
508 | */
|
||
509 | public boolean checkPersistence() { |
||
510 | return this.persistWindow; |
||
511 | } |
||
512 | |||
513 | /**
|
||
514 | * Set whether the geometry of this window should be persisted in the
|
||
515 | * project files.
|
||
516 | *
|
||
517 | * @param persist
|
||
518 | */
|
||
519 | public void setPersistence(boolean persist) { |
||
520 | this.persistWindow = persist;
|
||
521 | } |
||
522 | |||
523 | /**
|
||
524 | * Gets the window properties in an XMLEntity object, suitable
|
||
525 | * for persistence.
|
||
526 | *
|
||
527 | * @return An XMLEntity object containing the window properties, or null if the window was set as
|
||
528 | * not persistent
|
||
529 | * @throws SaveException
|
||
530 | * @throws XMLException
|
||
531 | * @throws SaveException
|
||
532 | */
|
||
533 | public XMLEntity getXMLEntity() {
|
||
534 | XMLEntity xml = new XMLEntity();
|
||
535 | xml.setName("ViewInfoProperties");
|
||
536 | xml.putProperty("X", this.getX()); |
||
537 | xml.putProperty("Y", this.getY()); |
||
538 | xml.putProperty("Width", this.getWidth()); |
||
539 | xml.putProperty("Height", this.getHeight()); |
||
540 | xml.putProperty("isVisible", this.isVisible()); |
||
541 | xml.putProperty("isResizable", this.isResizable()); |
||
542 | xml.putProperty("isMaximizable", this.isMaximizable()); |
||
543 | xml.putProperty("isModal", this.isModal()); |
||
544 | xml.putProperty("isModeless", this.isModeless()); |
||
545 | xml.putProperty("isClosed", this.isClosed()); |
||
546 | if (this.isMaximized()==true) { |
||
547 | xml.putProperty("isMaximized", this.isMaximized()); |
||
548 | xml.putProperty("normalX", this.getNormalX()); |
||
549 | xml.putProperty("normalY", this.getNormalY()); |
||
550 | xml.putProperty("normalWidth", this.getNormalWidth()); |
||
551 | xml.putProperty("normalHeight", this.getNormalHeight()); |
||
552 | } |
||
553 | return xml;
|
||
554 | } |
||
555 | |||
556 | |||
557 | public static WindowInfo createFromXMLEntity(XMLEntity xml) |
||
558 | { |
||
559 | WindowInfo result = new WindowInfo();
|
||
560 | result.setX(xml.getIntProperty("X"));
|
||
561 | result.setY(xml.getIntProperty("Y"));
|
||
562 | result.setHeight(xml.getIntProperty("Height"));
|
||
563 | result.setWidth(xml.getIntProperty("Width"));
|
||
564 | result.setClosed(xml.getBooleanProperty("isClosed"));
|
||
565 | if (xml.contains("isMaximized")) { |
||
566 | boolean maximized = xml.getBooleanProperty("isMaximized"); |
||
567 | result.setMaximized(maximized); |
||
568 | if (maximized==true) { |
||
569 | result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight")); |
||
570 | } |
||
571 | else {
|
||
572 | result.setNormalBounds(result.getBounds()); |
||
573 | } |
||
574 | } |
||
575 | |||
576 | return result;
|
||
577 | } |
||
578 | |||
579 | public void getPropertiesFromXMLEntity(XMLEntity xml) |
||
580 | { |
||
581 | this.x = xml.getIntProperty("X"); |
||
582 | this.y = xml.getIntProperty("Y"); |
||
583 | this.height = xml.getIntProperty("Height"); |
||
584 | this.width = xml.getIntProperty("Width"); |
||
585 | this.isClosed = xml.getBooleanProperty("isClosed"); |
||
586 | if (xml.contains("isMaximized")) { |
||
587 | boolean maximized = xml.getBooleanProperty("isMaximized"); |
||
588 | this.isMaximized = maximized;
|
||
589 | if (maximized==true) { |
||
590 | this.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight")); |
||
591 | } |
||
592 | } |
||
593 | } |
||
594 | 6880 | cesar | } |