root / tags / v10_RC2c / frameworks / _fwAndami / src / com / iver / andami / ui / mdiManager / WindowInfo.java @ 8745
History | View | Annotate | Download (15.1 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.andami.ui.mdiManager; |
42 |
|
43 |
import java.awt.Rectangle; |
44 |
import java.beans.PropertyChangeListener; |
45 |
import java.beans.PropertyChangeSupport; |
46 |
|
47 |
import com.iver.andami.PluginServices; |
48 |
import com.iver.utiles.XMLEntity; |
49 |
|
50 |
|
51 |
/**
|
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 |
|
85 |
/**
|
86 |
* Do we want to persist the geometry of this window in the project file?
|
87 |
*/
|
88 |
private boolean persistWindow = true; |
89 |
|
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 |
if (!isMaximized)
|
148 |
this.normalX = x;
|
149 |
} |
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 |
if (!isMaximized)
|
169 |
this.normalY = y;
|
170 |
} |
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 |
* @param h
|
277 |
*/
|
278 |
public void setHeight(int h) { |
279 |
support.firePropertyChange("height", this.height, h); |
280 |
height = h; |
281 |
if (!isMaximized)
|
282 |
this.normalHeight = h;
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* establece la propiedad anchura
|
287 |
*
|
288 |
* @param i
|
289 |
*/
|
290 |
public void setWidth(int w) { |
291 |
support.firePropertyChange("width", this.width, w); |
292 |
width = w; |
293 |
if (!isMaximized)
|
294 |
this.width = w;
|
295 |
} |
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 |
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 |
} |
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 |
support.firePropertyChange("closed", this.isClosed, closed); |
388 |
this.isClosed = closed;
|
389 |
} |
390 |
|
391 |
public void setNormalX(int normalX) { |
392 |
support.firePropertyChange("normalX", this.normalX, normalX); |
393 |
this.normalX = normalX;
|
394 |
} |
395 |
|
396 |
public void setNormalY(int normalY) { |
397 |
support.firePropertyChange("normalY", this.normalY, normalY); |
398 |
this.normalY = normalY;
|
399 |
} |
400 |
|
401 |
public void setNormalHeight(int normalHeight) { |
402 |
support.firePropertyChange("normalHeight", this.normalHeight, normalHeight); |
403 |
this.normalHeight = normalHeight;
|
404 |
} |
405 |
|
406 |
public void setNormalWidth(int normalWidth) { |
407 |
support.firePropertyChange("normalWidth", this.normalWidth, normalWidth); |
408 |
this.normalWidth = normalWidth;
|
409 |
} |
410 |
|
411 |
|
412 |
public void setMaximized(boolean maximized) { |
413 |
support.firePropertyChange("maximized", this.isMaximized, maximized); |
414 |
this.isMaximized = maximized;
|
415 |
} |
416 |
|
417 |
public void setMaximizable(boolean maximizable) { |
418 |
this.maximizable = maximizable;
|
419 |
} |
420 |
|
421 |
private void setBounds(int x, int y, int width, int height) { |
422 |
support.firePropertyChange("x", this.height, x); |
423 |
this.x = x;
|
424 |
support.firePropertyChange("y", this.height, y); |
425 |
this.y = y;
|
426 |
support.firePropertyChange("width", this.width, width); |
427 |
this.width = width;
|
428 |
support.firePropertyChange("height", this.height, height); |
429 |
this.height = height;
|
430 |
} |
431 |
|
432 |
public void setNormalBounds(int x, int y, int width, int height) { |
433 |
support.firePropertyChange("normalX", this.normalX, x); |
434 |
this.normalX = x;
|
435 |
support.firePropertyChange("normalY", this.normalY, y); |
436 |
this.normalY = y;
|
437 |
support.firePropertyChange("width", this.width, width); |
438 |
this.normalWidth = width;
|
439 |
support.firePropertyChange("height", this.height, height); |
440 |
this.normalHeight = height;
|
441 |
} |
442 |
|
443 |
public Rectangle getNormalBounds() { |
444 |
return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight()); |
445 |
} |
446 |
|
447 |
public void setNormalBounds(Rectangle normalBounds) { |
448 |
support.firePropertyChange("normalX", this.normalX, normalBounds.x); |
449 |
normalX = normalBounds.x; |
450 |
support.firePropertyChange("normalY", this.normalY, normalBounds.y); |
451 |
normalY = normalBounds.y; |
452 |
support.firePropertyChange("normalHeight", this.normalHeight, normalBounds.height); |
453 |
normalHeight = normalBounds.height; |
454 |
support.firePropertyChange("normalWidth", this.normalWidth, normalBounds.width); |
455 |
normalWidth = normalBounds.width; |
456 |
} |
457 |
|
458 |
public void setBounds(Rectangle bounds) { |
459 |
support.firePropertyChange("x", this.x, bounds.x); |
460 |
x = bounds.x; |
461 |
support.firePropertyChange("y", this.y, bounds.y); |
462 |
y = bounds.y; |
463 |
support.firePropertyChange("height", this.height, bounds.height); |
464 |
height = bounds.height; |
465 |
support.firePropertyChange("width", this.width, bounds.width); |
466 |
width = bounds.width; |
467 |
} |
468 |
|
469 |
public Rectangle getBounds() { |
470 |
return new Rectangle(x, y, width, height); |
471 |
} |
472 |
|
473 |
public int getNormalX() { |
474 |
if (normalX!=0) |
475 |
return this.normalX; |
476 |
else
|
477 |
return x;
|
478 |
} |
479 |
|
480 |
public int getNormalY() { |
481 |
if (normalY!=0) |
482 |
return this.normalY; |
483 |
else
|
484 |
return y;
|
485 |
} |
486 |
|
487 |
public int getNormalHeight() { |
488 |
if (normalHeight!=0) |
489 |
return this.normalHeight; |
490 |
else
|
491 |
return height;
|
492 |
} |
493 |
|
494 |
public int getNormalWidth() { |
495 |
if (normalWidth!=0) |
496 |
return this.normalWidth; |
497 |
else
|
498 |
return width;
|
499 |
} |
500 |
|
501 |
public boolean isMaximized() { |
502 |
return this.isMaximized; |
503 |
} |
504 |
|
505 |
/**
|
506 |
* Checks if the geometry of this window should be persisted in the
|
507 |
* project file. This is set by the persistWindow(boolean) method,
|
508 |
* and the default value is true.
|
509 |
*
|
510 |
* @return True if the geometry of this window should be persisted
|
511 |
* in the project files, false otherwise.
|
512 |
*/
|
513 |
public boolean checkPersistence() { |
514 |
return this.persistWindow; |
515 |
} |
516 |
|
517 |
/**
|
518 |
* Set whether the geometry of this window should be persisted in the
|
519 |
* project files.
|
520 |
*
|
521 |
* @param persist
|
522 |
*/
|
523 |
public void setPersistence(boolean persist) { |
524 |
this.persistWindow = persist;
|
525 |
} |
526 |
|
527 |
/**
|
528 |
* Gets the window properties in an XMLEntity object, suitable
|
529 |
* for persistence.
|
530 |
*
|
531 |
* @return An XMLEntity object containing the window properties, or null if the window was set as
|
532 |
* not persistent
|
533 |
* @throws SaveException
|
534 |
* @throws XMLException
|
535 |
* @throws SaveException
|
536 |
*/
|
537 |
public XMLEntity getXMLEntity() {
|
538 |
XMLEntity xml = new XMLEntity();
|
539 |
xml.setName("ViewInfoProperties");
|
540 |
xml.putProperty("X", this.getX()); |
541 |
xml.putProperty("Y", this.getY()); |
542 |
xml.putProperty("Width", this.getWidth()); |
543 |
xml.putProperty("Height", this.getHeight()); |
544 |
xml.putProperty("isVisible", this.isVisible()); |
545 |
xml.putProperty("isResizable", this.isResizable()); |
546 |
xml.putProperty("isMaximizable", this.isMaximizable()); |
547 |
xml.putProperty("isModal", this.isModal()); |
548 |
xml.putProperty("isModeless", this.isModeless()); |
549 |
xml.putProperty("isClosed", this.isClosed()); |
550 |
if (this.isMaximized()==true) { |
551 |
xml.putProperty("isMaximized", this.isMaximized()); |
552 |
xml.putProperty("normalX", this.getNormalX()); |
553 |
xml.putProperty("normalY", this.getNormalY()); |
554 |
xml.putProperty("normalWidth", this.getNormalWidth()); |
555 |
xml.putProperty("normalHeight", this.getNormalHeight()); |
556 |
} |
557 |
return xml;
|
558 |
} |
559 |
|
560 |
|
561 |
public static WindowInfo createFromXMLEntity(XMLEntity xml) |
562 |
{ |
563 |
WindowInfo result = new WindowInfo();
|
564 |
result.setX(xml.getIntProperty("X"));
|
565 |
result.setY(xml.getIntProperty("Y"));
|
566 |
result.setHeight(xml.getIntProperty("Height"));
|
567 |
result.setWidth(xml.getIntProperty("Width"));
|
568 |
result.setClosed(xml.getBooleanProperty("isClosed"));
|
569 |
if (xml.contains("isMaximized")) { |
570 |
boolean maximized = xml.getBooleanProperty("isMaximized"); |
571 |
result.setMaximized(maximized); |
572 |
if (maximized==true) { |
573 |
result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight")); |
574 |
} |
575 |
else {
|
576 |
result.setNormalBounds(result.getBounds()); |
577 |
} |
578 |
} |
579 |
|
580 |
return result;
|
581 |
} |
582 |
|
583 |
public void getPropertiesFromXMLEntity(XMLEntity xml) |
584 |
{ |
585 |
this.x = xml.getIntProperty("X"); |
586 |
this.y = xml.getIntProperty("Y"); |
587 |
this.height = xml.getIntProperty("Height"); |
588 |
this.width = xml.getIntProperty("Width"); |
589 |
this.isClosed = xml.getBooleanProperty("isClosed"); |
590 |
if (xml.contains("isMaximized")) { |
591 |
boolean maximized = xml.getBooleanProperty("isMaximized"); |
592 |
this.isMaximized = maximized;
|
593 |
if (maximized==true) { |
594 |
this.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight")); |
595 |
} |
596 |
} |
597 |
} |
598 |
} |