svn-gvsig-desktop / tags / v1_1_Build_1010 / frameworks / _fwAndami / src / com / iver / andami / ui / mdiManager / WindowInfo.java @ 12804
History | View | Annotate | Download (24.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004-2007 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 org.exolab.castor.xml.XMLException; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.utiles.XMLEntity; |
51 |
|
52 |
|
53 |
/**
|
54 |
* This class represents the state of the associated window.
|
55 |
* The <code>set</code> methods (<code>setX</code>, <code>setY</code>,
|
56 |
* <code>setHeight</code>, etc) are immediately reflected on the
|
57 |
* window.
|
58 |
*
|
59 |
* @author Fernando Gonz?lez Cort?s
|
60 |
*/
|
61 |
public class WindowInfo { |
62 |
/** Specifies that the window is resizable */
|
63 |
public static final int RESIZABLE = 1; |
64 |
|
65 |
/** Specifies that the window is maximizable */
|
66 |
public static final int MAXIMIZABLE = 2; |
67 |
|
68 |
/** Specifies that the window is iconifiable */
|
69 |
public static final int ICONIFIABLE = 4; |
70 |
|
71 |
/** Specifies that the window is modal */
|
72 |
public static final int MODALDIALOG = 8; |
73 |
/** Specifies that the window is modeless (it's on the top but doesn't block any other window) */
|
74 |
public static final int MODELESSDIALOG = 16; |
75 |
/** Specifies that the window may be docked inside another window */
|
76 |
public static final int PALETTE = 32; |
77 |
private PropertyChangeSupport support = new PropertyChangeSupport(this); |
78 |
|
79 |
/** DOCUMENT ME! */
|
80 |
private boolean resizable = false; |
81 |
|
82 |
/** DOCUMENT ME! */
|
83 |
private boolean maximizable = false; |
84 |
|
85 |
/** DOCUMENT ME! */
|
86 |
private boolean iconifiable = false; |
87 |
|
88 |
/** DOCUMENT ME! */
|
89 |
private boolean modal = false; |
90 |
private boolean modeless = false; |
91 |
|
92 |
/**
|
93 |
* Do we want to persist the geometry of this window in the project file?
|
94 |
*/
|
95 |
private boolean persistWindow = true; |
96 |
|
97 |
/**
|
98 |
* Se usa para poner una ventana de tipo paleta, por
|
99 |
* encima de las dem?s. Equivale a poner usar
|
100 |
* JDesktopPane.PALETTE_LAYER
|
101 |
*/
|
102 |
private boolean palette = false; |
103 |
|
104 |
/** These properties store the dimension and position of the frame */
|
105 |
private int width = -1; |
106 |
private int height = -1; |
107 |
private int x = -1; |
108 |
private int y = -1; |
109 |
/**
|
110 |
* These properties store the position and dimension of the frame when it is not maximized
|
111 |
* (so that it can be restored to its original size). They are equal to the not-normal properties
|
112 |
* when the frame is not maximized, and different when the frame is maximized.
|
113 |
*/
|
114 |
private int normalX = 0; |
115 |
private int normalY = 0; |
116 |
private int normalHeight = -1; |
117 |
private int normalWidth = -1; |
118 |
/* Whether the window is maximized */
|
119 |
private boolean isMaximized = false; |
120 |
private boolean visible = true; |
121 |
/* Whether the window is closed */
|
122 |
private boolean isClosed = false; |
123 |
|
124 |
|
125 |
/** DOCUMENT ME! */
|
126 |
private String title; |
127 |
|
128 |
private int id; |
129 |
|
130 |
/**
|
131 |
* ActionCommand del tool seleccionado. Lo usamos
|
132 |
* para activar el tool que estaba seleccionado en
|
133 |
* la vista, cuando volvemos a ella.
|
134 |
*/
|
135 |
private String selectedTool; |
136 |
|
137 |
/**
|
138 |
* Returns the current x coordinate of the window's origin
|
139 |
* (left-upper corner of the window).
|
140 |
*
|
141 |
* @return Returns the value (in pixels) of the x coordinate
|
142 |
* of the window's origin.
|
143 |
*/
|
144 |
public int getX() { |
145 |
return x;
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* Sets the x coordinate of the window's origin
|
150 |
* (left-upper corner of the window).
|
151 |
*
|
152 |
* @param x The value (in pixels) of the x coordinate to set.
|
153 |
*/
|
154 |
public void setX(int x) { |
155 |
support.firePropertyChange("x", this.x, x); |
156 |
this.x = x;
|
157 |
if (!isMaximized)
|
158 |
this.normalX = x;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Gets the value of the y coordinate for the origin
|
163 |
* (left-upper corner of the window) of the associated
|
164 |
* window.
|
165 |
*
|
166 |
* @return Returns the y coordinate (in pixels).
|
167 |
*/
|
168 |
public int getY() { |
169 |
return y;
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Sets the value of the y coordinate for the origin
|
174 |
* (left-upper corner of the window) of the associated
|
175 |
* window.
|
176 |
*
|
177 |
* @param y The value (in pixels) of the y coordinate
|
178 |
*/
|
179 |
public void setY(int y) { |
180 |
support.firePropertyChange("y", this.y, y); |
181 |
this.y = y;
|
182 |
if (!isMaximized)
|
183 |
this.normalY = y;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* DOCUMENT ME!
|
188 |
*
|
189 |
* @param listener
|
190 |
*/
|
191 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
192 |
support.addPropertyChangeListener(listener); |
193 |
} |
194 |
|
195 |
/**
|
196 |
* DOCUMENT ME!
|
197 |
*
|
198 |
* @param listener
|
199 |
*/
|
200 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
201 |
support.removePropertyChangeListener(listener); |
202 |
} |
203 |
|
204 |
/**
|
205 |
* Creates a new WindowInfo object with the provided properties.
|
206 |
* Valid properties include:
|
207 |
* <ul>
|
208 |
* <li>WindowInfo.MODALDIALOG</li>
|
209 |
* <li>WindowInfo.MODELESSDIALOG</li>
|
210 |
* <li>WindowInfo.PALETTE</li>
|
211 |
* <li>WindowInfo.ICONIFIABLE</li>
|
212 |
* <li>WindowInfo.RESIZABLE</li>
|
213 |
* <li>WindowInfo.MAXIMIZABLE</li>
|
214 |
*
|
215 |
* <p>Properties can be set together by using the binary OR operator
|
216 |
* "<b>|</b>". For example:</p>
|
217 |
*
|
218 |
* <p><code>WindowInfo wi = new WindowInfo(WindowInfo.MODELESSDIALOG
|
219 |
* |WindowInfo.ICONIFIABLE|WindowInfo.RESIZABLE).</code></p>
|
220 |
*
|
221 |
* <p>The WindowInfo.MODELESSDIALOG and WindowInfo.MODALDIALOG properties
|
222 |
* cannot be set at the same time</p>
|
223 |
*
|
224 |
*
|
225 |
* @param code Bit-or of the window properties.
|
226 |
*
|
227 |
* @throws IllegalStateException If incompatible properties are set together,
|
228 |
* for example, if MODALDIALOG and MODELESSDIALGO are set together.
|
229 |
*/
|
230 |
public WindowInfo(int code) { |
231 |
resizable = (code % 2) > 0; |
232 |
code = code / 2;
|
233 |
maximizable = (code % 2) > 0; |
234 |
code = code / 2;
|
235 |
iconifiable = (code % 2) > 0; |
236 |
code = code / 2;
|
237 |
modal = (code % 2) > 0; |
238 |
code = code / 2;
|
239 |
modeless = (code % 2) > 0; |
240 |
code = code / 2;
|
241 |
palette = (code % 2) > 0; |
242 |
|
243 |
if (modal && modeless) {
|
244 |
throw new IllegalStateException("modal && modeless"); |
245 |
} |
246 |
} |
247 |
|
248 |
/**
|
249 |
* Creates a new WindowInfo object with the default properties:
|
250 |
* <ul>
|
251 |
* <li>not resizable</li>
|
252 |
* <li>not maximizable</li>
|
253 |
* <li>not iconifiable</li>
|
254 |
* <li>not modal</li>
|
255 |
* <li>not modeless</li>
|
256 |
* <li>not palette</li>
|
257 |
* </uil>
|
258 |
*
|
259 |
*/
|
260 |
public WindowInfo(){
|
261 |
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* Determines whether the associated window is iconifiable or not
|
266 |
*
|
267 |
* @return
|
268 |
*/
|
269 |
public boolean isIconifiable() { |
270 |
return iconifiable;
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* Determines whether the associated window is maximizable or not
|
275 |
*
|
276 |
* @return
|
277 |
*/
|
278 |
public boolean isMaximizable() { |
279 |
return maximizable;
|
280 |
} |
281 |
|
282 |
/**
|
283 |
* Determines whether the associated window is resizable or not
|
284 |
*
|
285 |
* @return
|
286 |
*/
|
287 |
public boolean isResizable() { |
288 |
return resizable;
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* Determines whether the associated window is modal or not
|
293 |
*
|
294 |
* @return
|
295 |
*/
|
296 |
public boolean isModal() { |
297 |
return modal;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* Gets the window height.
|
302 |
*
|
303 |
* @return The window height (in pixels).
|
304 |
*/
|
305 |
public int getHeight() { |
306 |
return height;
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* Gets the window width.
|
311 |
*
|
312 |
* @return The window width (in pixels).
|
313 |
*/
|
314 |
public int getWidth() { |
315 |
return width;
|
316 |
} |
317 |
|
318 |
/**
|
319 |
* Sets the window height.
|
320 |
*
|
321 |
* @param The window height (in pixels)
|
322 |
*/
|
323 |
public void setHeight(int h) { |
324 |
if (h!=-1) |
325 |
support.firePropertyChange("height", this.height, h); |
326 |
height = h; |
327 |
if (!isMaximized)
|
328 |
this.normalHeight = h;
|
329 |
} |
330 |
|
331 |
/**
|
332 |
* Sets the width property for the associated Window.
|
333 |
*
|
334 |
* @param w The new width.
|
335 |
*/
|
336 |
public void setWidth(int w) { |
337 |
if (w!=-1) |
338 |
support.firePropertyChange("width", this.width, w); |
339 |
width = w; |
340 |
if (!isMaximized)
|
341 |
this.width = w;
|
342 |
} |
343 |
|
344 |
/**
|
345 |
* Gets the title property
|
346 |
*
|
347 |
* @return
|
348 |
*/
|
349 |
public String getTitle() { |
350 |
return title;
|
351 |
} |
352 |
|
353 |
/**
|
354 |
* Sets the title property.
|
355 |
*
|
356 |
* @param title The new title.
|
357 |
*/
|
358 |
public void setTitle(String string) { |
359 |
support.firePropertyChange("title", this.title, string); |
360 |
title = string; |
361 |
} |
362 |
|
363 |
/**
|
364 |
* Determines whether the associated window is modeless
|
365 |
* (it is on the top but does not block any other window)
|
366 |
*
|
367 |
* @return
|
368 |
*/
|
369 |
public boolean isModeless() { |
370 |
return modeless;
|
371 |
} |
372 |
|
373 |
/**
|
374 |
* Determines whether the associated window is visible
|
375 |
*
|
376 |
* @return true if the associated window is visible, false
|
377 |
* if it is hidden
|
378 |
*/
|
379 |
public boolean isVisible() { |
380 |
return visible;
|
381 |
} |
382 |
|
383 |
/**
|
384 |
* Determines whether the associated dockable window is
|
385 |
* currently in palette status or docked.
|
386 |
*
|
387 |
* @return true if the window is currently in palette status,
|
388 |
* false if it is docked in another window
|
389 |
*/
|
390 |
public boolean isPalette() |
391 |
{ |
392 |
return palette;
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* Sets the window's ID.
|
397 |
*
|
398 |
* @param id An integer to identify the window. Different
|
399 |
* windows must have different IDs.
|
400 |
*/
|
401 |
public void setId(int id){ |
402 |
this.id = id;
|
403 |
} |
404 |
|
405 |
/**
|
406 |
* Gets the window ID.
|
407 |
*
|
408 |
* @return id An integer to identify the window. Different
|
409 |
* windows must have different IDs.
|
410 |
*/
|
411 |
public int getId(){ |
412 |
return id;
|
413 |
} |
414 |
|
415 |
/**
|
416 |
* Updates all the properties in this object so that
|
417 |
* they match the properties of the provided
|
418 |
* <code>wi</code> object. The changes are not reflected on the
|
419 |
* window, just the WindowInfo object is updated.
|
420 |
*
|
421 |
* @param vi A WindowInfo object containing the new
|
422 |
* properties of the window.
|
423 |
*/
|
424 |
public void setWindowInfo(WindowInfo vi){ |
425 |
this.resizable = vi.resizable;
|
426 |
this.maximizable = vi.maximizable;
|
427 |
this.isMaximized = vi.isMaximized;
|
428 |
this.iconifiable = vi.iconifiable;
|
429 |
this.modal = vi.modal;
|
430 |
this.modeless = vi.modeless;
|
431 |
if (vi.width!=-1) |
432 |
this.width = vi.width;
|
433 |
if (vi.height!=-1) |
434 |
this.height = vi.height;
|
435 |
this.x = vi.x;
|
436 |
this.y = vi.y;
|
437 |
this.visible = vi.visible;
|
438 |
this.title = vi.title;
|
439 |
this.id = vi.id;
|
440 |
if (vi.normalHeight!=-1) |
441 |
this.normalHeight = vi.normalHeight;
|
442 |
if (vi.normalWidth!=-1) |
443 |
this.normalWidth = vi.normalWidth;
|
444 |
this.normalX = vi.normalX;
|
445 |
this.normalY = vi.normalY;
|
446 |
this.isClosed = vi.isClosed;
|
447 |
this.persistWindow = vi.persistWindow;
|
448 |
} |
449 |
|
450 |
/**
|
451 |
* Sets whether the window is in palette mode or is in docked mode.
|
452 |
* This method <b>does not</b> update the window status, it just
|
453 |
* updates the WindowInfo object. Use the IWindowTransform interface
|
454 |
* to actually change the window status.
|
455 |
*
|
456 |
* @param b
|
457 |
*/
|
458 |
public void toPalette(boolean b){ |
459 |
this.palette=b;
|
460 |
} |
461 |
|
462 |
/**
|
463 |
* Gets the actionCommand of the currently selected tool for this
|
464 |
* window.
|
465 |
* @return
|
466 |
*/
|
467 |
public String getSelectedTool() { |
468 |
return selectedTool;
|
469 |
} |
470 |
|
471 |
/**
|
472 |
* Sets the actionCommand of the currently selected tool for this
|
473 |
* window.
|
474 |
|
475 |
* @param selectedTool The actionCommand of the tool which is
|
476 |
* going to be selected for this window.
|
477 |
*/
|
478 |
public void setSelectedTool(String selectedTool) { |
479 |
if (selectedTool != null) |
480 |
this.selectedTool = selectedTool;
|
481 |
} |
482 |
|
483 |
/**
|
484 |
* Finds out whether a window is open (showing) or closed
|
485 |
*/
|
486 |
public boolean isClosed() { |
487 |
return isClosed;
|
488 |
} |
489 |
|
490 |
/**
|
491 |
* Specifies whether a window is open (showing) or closed
|
492 |
*/
|
493 |
public void setClosed(boolean closed) { |
494 |
support.firePropertyChange("closed", this.isClosed, closed); |
495 |
this.isClosed = closed;
|
496 |
} |
497 |
|
498 |
|
499 |
/**
|
500 |
* Sets the x coordinate of the window's origin
|
501 |
* when the window is not maximized. When the window is maximized,
|
502 |
* it does not change the current window's position, but the
|
503 |
* window will have this x coordinate when it gets restored.
|
504 |
*
|
505 |
* @param normalX The value (in pixels) of the x coordinate to set.
|
506 |
*/
|
507 |
public void setNormalX(int normalX) { |
508 |
support.firePropertyChange("normalX", this.normalX, normalX); |
509 |
this.normalX = normalX;
|
510 |
} |
511 |
|
512 |
/**
|
513 |
* Sets the y coordinate of the window's origin
|
514 |
* when the window is not maximized. When the window is maximized,
|
515 |
* it does not change the current window's position, but the
|
516 |
* window will have this y coordinate when it gets restored.
|
517 |
*
|
518 |
* @param normalY The value (in pixels) of the y coordinate to set.
|
519 |
*/
|
520 |
public void setNormalY(int normalY) { |
521 |
support.firePropertyChange("normalY", this.normalY, normalY); |
522 |
this.normalY = normalY;
|
523 |
} |
524 |
|
525 |
/**
|
526 |
* Sets the height of the window
|
527 |
* when the window is not maximized. When the window is maximized,
|
528 |
* it does not change the current window's height, but the
|
529 |
* window will have this height when it gets restored.
|
530 |
*
|
531 |
* @param normalHeight The height (in pixels) to set.
|
532 |
*/
|
533 |
public void setNormalHeight(int normalHeight) { |
534 |
support.firePropertyChange("normalHeight", this.normalHeight, normalHeight); |
535 |
this.normalHeight = normalHeight;
|
536 |
} |
537 |
|
538 |
/**
|
539 |
* Sets the width of the window
|
540 |
* when the window is not maximized. When the window is maximized,
|
541 |
* it does not change the current window's width, but the
|
542 |
* window will have this width when it gets restored.
|
543 |
*
|
544 |
* @param normalWidth The width (in pixels) to set.
|
545 |
*/
|
546 |
public void setNormalWidth(int normalWidth) { |
547 |
support.firePropertyChange("normalWidth", this.normalWidth, normalWidth); |
548 |
this.normalWidth = normalWidth;
|
549 |
} |
550 |
|
551 |
/**
|
552 |
* Specifies whether the window is maximized or not.
|
553 |
*/
|
554 |
public void setMaximized(boolean maximized) { |
555 |
support.firePropertyChange("maximized", this.isMaximized, maximized); |
556 |
this.isMaximized = maximized;
|
557 |
} |
558 |
|
559 |
/**
|
560 |
* Specifies whether the window is maximizable or not.
|
561 |
*/
|
562 |
public void setMaximizable(boolean maximizable) { |
563 |
this.maximizable = maximizable;
|
564 |
} |
565 |
|
566 |
private void setBounds(int x, int y, int width, int height) { |
567 |
support.firePropertyChange("x", this.height, x); |
568 |
this.x = x;
|
569 |
support.firePropertyChange("y", this.height, y); |
570 |
this.y = y;
|
571 |
support.firePropertyChange("width", this.width, width); |
572 |
this.width = width;
|
573 |
support.firePropertyChange("height", this.height, height); |
574 |
this.height = height;
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* Sets the bounds of the window
|
579 |
* when the window is not maximized. When the window is maximized,
|
580 |
* it does not change the current window's bounds, but the
|
581 |
* window will have this bounds when it gets restored.
|
582 |
*
|
583 |
* @param x The normal x (in pixels) to set.
|
584 |
* @param y The normal y (in pixels) to set.
|
585 |
* @param width The normal width (in pixels) to set.
|
586 |
* @param height The normal height (in pixels) to set.
|
587 |
*/
|
588 |
public void setNormalBounds(int x, int y, int width, int height) { |
589 |
support.firePropertyChange("normalX", this.normalX, x); |
590 |
this.normalX = x;
|
591 |
support.firePropertyChange("normalY", this.normalY, y); |
592 |
this.normalY = y;
|
593 |
support.firePropertyChange("normalWidth", this.normalWidth, width); |
594 |
this.normalWidth = width;
|
595 |
support.firePropertyChange("normalWeight", this.normalHeight, height); |
596 |
this.normalHeight = height;
|
597 |
} |
598 |
|
599 |
/**
|
600 |
* Gets the bounds of the window
|
601 |
* when the window is not maximized. When the window is maximized,
|
602 |
* it gets the bounds that the window will have when it gets restored.
|
603 |
*
|
604 |
* @return the bounds of the window when the window is not maximized,
|
605 |
* or if it is maximized, the bounds that the window will have when
|
606 |
* it gets restored
|
607 |
*/
|
608 |
public Rectangle getNormalBounds() { |
609 |
return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight()); |
610 |
} |
611 |
|
612 |
/**
|
613 |
* Sets the bounds of the window
|
614 |
* when the window is not maximized. When the window is maximized,
|
615 |
* it does not change the current window's bounds, but the
|
616 |
* window will have this bounds when it gets restored.
|
617 |
*
|
618 |
* @param normalBounds The normal bounds to set
|
619 |
*/
|
620 |
public void setNormalBounds(Rectangle normalBounds) { |
621 |
Rectangle oldBounds = new Rectangle(this.normalX, this.normalY, |
622 |
this.normalWidth, this.normalHeight); |
623 |
support.firePropertyChange("normalBounds", oldBounds, normalBounds);
|
624 |
support.firePropertyChange("normalX", this.normalX, normalBounds.x); |
625 |
normalX = normalBounds.x; |
626 |
support.firePropertyChange("normalY", this.normalY, normalBounds.y); |
627 |
normalY = normalBounds.y; |
628 |
support.firePropertyChange("normalHeight", this.normalHeight, normalBounds.height); |
629 |
normalHeight = normalBounds.height; |
630 |
support.firePropertyChange("normalWidth", this.normalWidth, normalBounds.width); |
631 |
normalWidth = normalBounds.width; |
632 |
} |
633 |
|
634 |
/**
|
635 |
* Set the bounds of the window.
|
636 |
*
|
637 |
* @param bounds The bounds to set.
|
638 |
*/
|
639 |
public void setBounds(Rectangle bounds) { |
640 |
support.firePropertyChange("x", this.x, bounds.x); |
641 |
x = bounds.x; |
642 |
support.firePropertyChange("y", this.y, bounds.y); |
643 |
y = bounds.y; |
644 |
support.firePropertyChange("height", this.height, bounds.height); |
645 |
height = bounds.height; |
646 |
support.firePropertyChange("width", this.width, bounds.width); |
647 |
width = bounds.width; |
648 |
} |
649 |
|
650 |
/**
|
651 |
* Gets the bounds of the window.
|
652 |
*
|
653 |
* @return the bounds of the window.
|
654 |
*/
|
655 |
public Rectangle getBounds() { |
656 |
return new Rectangle(x, y, width, height); |
657 |
} |
658 |
|
659 |
/**
|
660 |
* Gets the x coordinate of the window's origin when the window is not
|
661 |
* maximized. When the window is maximized, gets the x coordinate that
|
662 |
* it will have when it gets restored
|
663 |
*
|
664 |
* @return the normal x coordinate of the window's origin
|
665 |
*/
|
666 |
public int getNormalX() { |
667 |
if (normalX!=0) |
668 |
return this.normalX; |
669 |
else
|
670 |
return x;
|
671 |
} |
672 |
|
673 |
/**
|
674 |
* Gets the x coordinate of the window's origin when the window is not
|
675 |
* maximized. When the window is maximized, gets the y coordinate that
|
676 |
* it will have when it gets restored
|
677 |
*
|
678 |
* @return the normal y coordinate of the window's origin
|
679 |
*/
|
680 |
public int getNormalY() { |
681 |
if (normalY!=0) |
682 |
return this.normalY; |
683 |
else
|
684 |
return y;
|
685 |
} |
686 |
|
687 |
/**
|
688 |
* Gets the height of the window's origin when the window is not
|
689 |
* maximized. When the window is maximized, gets the height that
|
690 |
* it will have when it gets restored
|
691 |
*
|
692 |
* @return the normal height of the window
|
693 |
*/
|
694 |
public int getNormalHeight() { |
695 |
if (normalHeight!=0) |
696 |
return this.normalHeight; |
697 |
else
|
698 |
return height;
|
699 |
} |
700 |
|
701 |
/**
|
702 |
* Gets the width of the window's origin when the window is not
|
703 |
* maximized. When the window is maximized, gets the width that
|
704 |
* it will have when it gets restored
|
705 |
*
|
706 |
* @return the normal width of the window
|
707 |
*/
|
708 |
public int getNormalWidth() { |
709 |
if (normalWidth!=0) |
710 |
return this.normalWidth; |
711 |
else
|
712 |
return width;
|
713 |
} |
714 |
|
715 |
/**
|
716 |
* Determines whether the window is maximized or not
|
717 |
*
|
718 |
* @return true if the window is maximized, false otherwise
|
719 |
*/
|
720 |
public boolean isMaximized() { |
721 |
return this.isMaximized; |
722 |
} |
723 |
|
724 |
/**
|
725 |
* Checks if the geometry of this window should be persisted in the
|
726 |
* project file. This is set by the persistWindow(boolean) method,
|
727 |
* and the default value is true.
|
728 |
*
|
729 |
* @return True if the geometry of this window should be persisted
|
730 |
* in the project files, false otherwise.
|
731 |
*/
|
732 |
public boolean checkPersistence() { |
733 |
return this.persistWindow; |
734 |
} |
735 |
|
736 |
/**
|
737 |
* Set whether the geometry of this window should be persisted in the
|
738 |
* project files.
|
739 |
*
|
740 |
* @param persist
|
741 |
*/
|
742 |
public void setPersistence(boolean persist) { |
743 |
this.persistWindow = persist;
|
744 |
} |
745 |
|
746 |
/**
|
747 |
* Gets the window properties in an XMLEntity object, suitable
|
748 |
* for persistence.
|
749 |
*
|
750 |
* @return An XMLEntity object containing the window properties
|
751 |
* @throws SaveException
|
752 |
* @throws XMLException
|
753 |
*/
|
754 |
public XMLEntity getXMLEntity() {
|
755 |
XMLEntity xml = new XMLEntity();
|
756 |
xml.setName("ViewInfoProperties");
|
757 |
xml.putProperty("X", this.getX()); |
758 |
xml.putProperty("Y", this.getY()); |
759 |
xml.putProperty("Width", this.getWidth()); |
760 |
xml.putProperty("Height", this.getHeight()); |
761 |
xml.putProperty("isVisible", this.isVisible()); |
762 |
xml.putProperty("isResizable", this.isResizable()); |
763 |
xml.putProperty("isMaximizable", this.isMaximizable()); |
764 |
xml.putProperty("isModal", this.isModal()); |
765 |
xml.putProperty("isModeless", this.isModeless()); |
766 |
xml.putProperty("isClosed", this.isClosed()); |
767 |
if (this.isMaximized()==true) { |
768 |
xml.putProperty("isMaximized", this.isMaximized()); |
769 |
xml.putProperty("normalX", this.getNormalX()); |
770 |
xml.putProperty("normalY", this.getNormalY()); |
771 |
xml.putProperty("normalWidth", this.getNormalWidth()); |
772 |
xml.putProperty("normalHeight", this.getNormalHeight()); |
773 |
} |
774 |
return xml;
|
775 |
} |
776 |
|
777 |
/**
|
778 |
* Creates a WindowInfo object from an XMLEntity containing the
|
779 |
* window properties.
|
780 |
*
|
781 |
* @param xml An XMLEntity object containing the window properties
|
782 |
*
|
783 |
* @return A new WindowInfo object, containing the properties
|
784 |
* specified in the XMLEntity parameters
|
785 |
*/
|
786 |
public static WindowInfo createFromXMLEntity(XMLEntity xml) |
787 |
{ |
788 |
WindowInfo result = new WindowInfo();
|
789 |
try {
|
790 |
result.setX(xml.getIntProperty("X"));
|
791 |
result.setY(xml.getIntProperty("Y"));
|
792 |
result.setHeight(xml.getIntProperty("Height"));
|
793 |
result.setWidth(xml.getIntProperty("Width"));
|
794 |
result.setClosed(xml.getBooleanProperty("isClosed"));
|
795 |
if (xml.contains("isMaximized")) { |
796 |
boolean maximized = xml.getBooleanProperty("isMaximized"); |
797 |
result.setMaximized(maximized); |
798 |
if (maximized==true) { |
799 |
result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight")); |
800 |
} |
801 |
else {
|
802 |
result.setNormalBounds(result.getBounds()); |
803 |
} |
804 |
} |
805 |
} |
806 |
catch (com.iver.utiles.NotExistInXMLEntity ex) {
|
807 |
PluginServices.getLogger().warn(PluginServices.getText(null, "Window_properties_not_stored_correctly_Window_state_will_not_be_restored")); |
808 |
} |
809 |
|
810 |
return result;
|
811 |
} |
812 |
|
813 |
/**
|
814 |
* Updates this WindowInfo object according to the properties
|
815 |
* provided by the XMLEntity parameter.
|
816 |
*
|
817 |
* @param xml An XMLEntity object containing the window properties
|
818 |
*/
|
819 |
public void getPropertiesFromXMLEntity(XMLEntity xml) |
820 |
{ |
821 |
this.x = xml.getIntProperty("X"); |
822 |
this.y = xml.getIntProperty("Y"); |
823 |
this.height = xml.getIntProperty("Height"); |
824 |
this.width = xml.getIntProperty("Width"); |
825 |
this.isClosed = xml.getBooleanProperty("isClosed"); |
826 |
if (xml.contains("isMaximized")) { |
827 |
boolean maximized = xml.getBooleanProperty("isMaximized"); |
828 |
this.isMaximized = maximized;
|
829 |
if (maximized==true) { |
830 |
this.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight")); |
831 |
} |
832 |
} |
833 |
} |
834 |
} |