Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1003 / frameworks / _fwAndami / src / com / iver / andami / ui / mdiManager / WindowInfo.java @ 12271

History | View | Annotate | Download (24.1 KB)

1 6880 cesar
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3 11989 cesar
 * Copyright (C) 2004-2007 IVER T.I. and Generalitat Valenciana.
4 6880 cesar
 *
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 11989 cesar
import org.exolab.castor.xml.XMLException;
48
49 7345 cesar
import com.iver.andami.PluginServices;
50
import com.iver.utiles.XMLEntity;
51 6880 cesar
52 7345 cesar
53 6880 cesar
/**
54 11989 cesar
 * 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 6880 cesar
 * @author Fernando Gonz?lez Cort?s
60
 */
61
public class WindowInfo {
62 11989 cesar
        /** Specifies that the window is resizable  */
63 6880 cesar
    public static final int RESIZABLE = 1;
64
65 11989 cesar
    /** Specifies that the window is maximizable */
66 6880 cesar
    public static final int MAXIMIZABLE = 2;
67
68 11989 cesar
    /** Specifies that the window is iconifiable */
69 6880 cesar
    public static final int ICONIFIABLE = 4;
70
71 11989 cesar
    /** Specifies that the window is modal */
72 6880 cesar
    public static final int MODALDIALOG = 8;
73 11989 cesar
    /** Specifies that the window is modeless (it's on the top but doesn't block any other window) */
74 6880 cesar
    public static final int MODELESSDIALOG = 16;
75 11989 cesar
    /** Specifies that the window may be docked inside another window */
76 6880 cesar
    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 11989 cesar
92 7345 cesar
    /**
93
     * Do we want to persist the geometry of this window in the project file?
94
     */
95
    private boolean persistWindow = true;
96 6880 cesar
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 12155 jcampos
    private int x = -1;
108
    private int y = -1;
109 6880 cesar
    /**
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 8765 jjdelcerro
    private int normalHeight = -1;
117
    private int normalWidth = -1;
118 6880 cesar
    /* 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 11989 cesar
     * Returns the current x coordinate of the window's origin
139
     * (left-upper corner of the window).
140 6880 cesar
     *
141 11989 cesar
     * @return Returns the value (in pixels) of the x coordinate
142
     * of the window's origin.
143 6880 cesar
     */
144
    public int getX() {
145
        return x;
146
    }
147
148
    /**
149 11989 cesar
     * Sets the x coordinate of the window's origin
150
     * (left-upper corner of the window).
151 6880 cesar
     *
152 11989 cesar
     * @param x        The value (in pixels) of the x coordinate to set.
153 6880 cesar
     */
154
    public void setX(int x) {
155
            support.firePropertyChange("x", this.x, x);
156
            this.x = x;
157 7345 cesar
            if (!isMaximized)
158
                    this.normalX = x;
159 6880 cesar
    }
160
161
    /**
162 11989 cesar
     * 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 6880 cesar
     */
168
    public int getY() {
169
        return y;
170
    }
171
172
    /**
173 11989 cesar
     * 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 6880 cesar
     */
179
    public void setY(int y) {
180
            support.firePropertyChange("y", this.y, y);
181
        this.y = y;
182 7345 cesar
        if (!isMaximized)
183
                this.normalY = y;
184 6880 cesar
    }
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 11992 cesar
     * 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 6880 cesar
     *
225 11992 cesar
     * @param code Bit-or of the window properties.
226 6880 cesar
     *
227 11992 cesar
     * @throws IllegalStateException If incompatible properties are set together,
228
     * for example, if MODALDIALOG and MODELESSDIALGO are set together.
229 6880 cesar
     */
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 11992 cesar
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 6880 cesar
    public WindowInfo(){
261
262
    }
263
264
    /**
265 11989 cesar
     * Determines whether the associated window is iconifiable or not
266 6880 cesar
     *
267
     * @return
268
     */
269
    public boolean isIconifiable() {
270
        return iconifiable;
271
    }
272
273
    /**
274 11989 cesar
     * Determines whether the associated window is maximizable or not
275 6880 cesar
     *
276
     * @return
277
     */
278
    public boolean isMaximizable() {
279
        return maximizable;
280
    }
281
282
    /**
283 11989 cesar
     * Determines whether the associated window is resizable or not
284 6880 cesar
     *
285
     * @return
286
     */
287
    public boolean isResizable() {
288
        return resizable;
289
    }
290
291
    /**
292 11989 cesar
     * Determines whether the associated window is modal or not
293 6880 cesar
     *
294
     * @return
295
     */
296
    public boolean isModal() {
297
        return modal;
298
    }
299
300
    /**
301 11989 cesar
     * Gets the window height.
302 6880 cesar
     *
303 11989 cesar
     * @return The window height (in pixels).
304 6880 cesar
     */
305
    public int getHeight() {
306
        return height;
307
    }
308
309
    /**
310 11989 cesar
     * Gets the window width.
311 6880 cesar
     *
312 11989 cesar
     * @return The window width (in pixels).
313 6880 cesar
     */
314
    public int getWidth() {
315
        return width;
316
    }
317
318
    /**
319 11989 cesar
     * Sets the window height.
320 6880 cesar
     *
321 11989 cesar
     * @param The window height (in pixels)
322 6880 cesar
     */
323 7345 cesar
    public void setHeight(int h) {
324 8765 jjdelcerro
            if (h!=-1)
325
                    support.firePropertyChange("height", this.height, h);
326
            height = h;
327 7345 cesar
        if (!isMaximized)
328
                this.normalHeight = h;
329 6880 cesar
    }
330
331
    /**
332 11989 cesar
     * Sets the width property for the associated Window.
333 6880 cesar
     *
334 11989 cesar
     * @param w The new width.
335 6880 cesar
     */
336 7345 cesar
    public void setWidth(int w) {
337 8765 jjdelcerro
            if (w!=-1)
338
                    support.firePropertyChange("width", this.width, w);
339 7345 cesar
        width = w;
340
        if (!isMaximized)
341
                this.width = w;
342 6880 cesar
    }
343
344
    /**
345 11989 cesar
     * Gets the title property
346 6880 cesar
     *
347
     * @return
348
     */
349
    public String getTitle() {
350
        return title;
351
    }
352
353
    /**
354 11989 cesar
     * Sets the title property.
355 6880 cesar
     *
356 11989 cesar
     * @param title The new title.
357 6880 cesar
     */
358
    public void setTitle(String string) {
359
            support.firePropertyChange("title", this.title, string);
360
        title = string;
361
    }
362
363
    /**
364 11989 cesar
     * Determines whether the associated window is modeless
365
     * (it is on the top but does not block any other window)
366 6880 cesar
     *
367
     * @return
368 11992 cesar
     */
369 11995 cesar
    public boolean isModeless() {
370 6880 cesar
        return modeless;
371
    }
372
373 11989 cesar
     /**
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 6880 cesar
    public boolean isVisible() {
380
        return visible;
381
    }
382
383 11989 cesar
    /**
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 6880 cesar
    public boolean isPalette()
391
    {
392
        return palette;
393
    }
394
395 11989 cesar
    /**
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 6880 cesar
    public void setId(int id){
402
            this.id = id;
403
    }
404
405 11989 cesar
    /**
406
     * Gets the window ID.
407
     *
408
     * @return id An integer to identify the window. Different
409
     * windows must have different IDs.
410
     */
411 6880 cesar
    public int getId(){
412
            return id;
413
    }
414
415 11989 cesar
    /**
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 6880 cesar
    public void setWindowInfo(WindowInfo vi){
425
            this.resizable = vi.resizable;
426
            this.maximizable = vi.maximizable;
427 8765 jjdelcerro
            this.isMaximized = vi.isMaximized;
428 6880 cesar
            this.iconifiable = vi.iconifiable;
429
            this.modal = vi.modal;
430
            this.modeless = vi.modeless;
431 8765 jjdelcerro
            if (vi.width!=-1)
432
                    this.width = vi.width;
433
            if (vi.height!=-1)
434
                    this.height = vi.height;
435 6880 cesar
            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 8765 jjdelcerro
            if (vi.normalHeight!=-1)
441
                    this.normalHeight = vi.normalHeight;
442
            if (vi.normalWidth!=-1)
443
                    this.normalWidth = vi.normalWidth;
444 7345 cesar
            this.normalX = vi.normalX;
445
            this.normalY = vi.normalY;
446
            this.isClosed = vi.isClosed;
447
            this.persistWindow = vi.persistWindow;
448 6880 cesar
    }
449 11989 cesar
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 6880 cesar
    public void toPalette(boolean b){
459
            this.palette=b;
460
    }
461
462 11989 cesar
    /**
463
     * Gets the actionCommand of the currently selected tool for this
464
     * window.
465
     * @return
466
     */
467 6880 cesar
    public String getSelectedTool() {
468
        return selectedTool;
469
    }
470
471 11989 cesar
    /**
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 6880 cesar
    public void setSelectedTool(String selectedTool) {
479
        if (selectedTool != null)
480
            this.selectedTool = selectedTool;
481
    }
482
483 11989 cesar
    /**
484
     *  Finds out whether a window is open (showing) or closed
485
     */
486 6880 cesar
    public boolean isClosed() {
487
            return isClosed;
488
    }
489
490 11989 cesar
    /**
491
     *  Specifies whether a window is open (showing) or closed
492
     */
493 6880 cesar
    public void setClosed(boolean closed) {
494 7345 cesar
            support.firePropertyChange("closed", this.isClosed, closed);
495 6880 cesar
            this.isClosed = closed;
496
    }
497
498 11989 cesar
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 6880 cesar
    public void setNormalX(int normalX) {
508 7345 cesar
            support.firePropertyChange("normalX", this.normalX, normalX);
509 6880 cesar
            this.normalX = normalX;
510
    }
511
512 11989 cesar
    /**
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 6880 cesar
    public void setNormalY(int normalY) {
521 7345 cesar
            support.firePropertyChange("normalY", this.normalY, normalY);
522 6880 cesar
            this.normalY = normalY;
523
    }
524
525 11989 cesar
    /**
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 6880 cesar
    public void setNormalHeight(int normalHeight) {
534 7345 cesar
            support.firePropertyChange("normalHeight", this.normalHeight, normalHeight);
535 6880 cesar
            this.normalHeight = normalHeight;
536
    }
537
538 11989 cesar
    /**
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 6880 cesar
    public void setNormalWidth(int normalWidth) {
547 7345 cesar
            support.firePropertyChange("normalWidth", this.normalWidth, normalWidth);
548 6880 cesar
            this.normalWidth = normalWidth;
549
    }
550
551 11989 cesar
    /**
552
     * Specifies whether the window is maximized or not.
553
     */
554 6880 cesar
    public void setMaximized(boolean maximized) {
555 7345 cesar
            support.firePropertyChange("maximized", this.isMaximized, maximized);
556 6880 cesar
            this.isMaximized = maximized;
557
    }
558 11989 cesar
559
    /**
560
     * Specifies whether the window is maximizable or not.
561
     */
562 7516 jorpiell
    public void setMaximizable(boolean maximizable) {
563
            this.maximizable = maximizable;
564
    }
565 6880 cesar
566
    private void setBounds(int x, int y, int width, int height) {
567 7345 cesar
            support.firePropertyChange("x", this.height, x);
568 6880 cesar
            this.x = x;
569 7345 cesar
            support.firePropertyChange("y", this.height, y);
570 6880 cesar
            this.y = y;
571 7345 cesar
            support.firePropertyChange("width", this.width, width);
572 6880 cesar
            this.width = width;
573 7345 cesar
            support.firePropertyChange("height", this.height, height);
574 6880 cesar
            this.height = height;
575
    }
576 11989 cesar
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 6880 cesar
    public void setNormalBounds(int x, int y, int width, int height) {
589 7345 cesar
            support.firePropertyChange("normalX", this.normalX, x);
590 6880 cesar
            this.normalX = x;
591 7345 cesar
            support.firePropertyChange("normalY", this.normalY, y);
592 6880 cesar
            this.normalY = y;
593 8765 jjdelcerro
            support.firePropertyChange("normalWidth", this.normalWidth, width);
594 6880 cesar
            this.normalWidth = width;
595 8765 jjdelcerro
            support.firePropertyChange("normalWeight", this.normalHeight, height);
596 6880 cesar
            this.normalHeight = height;
597
    }
598 11989 cesar
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 6880 cesar
    public Rectangle getNormalBounds() {
609
            return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight());
610
    }
611
612 11989 cesar
    /**
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 6880 cesar
    public void setNormalBounds(Rectangle normalBounds) {
621 11989 cesar
            Rectangle oldBounds = new Rectangle(this.normalX, this.normalY,
622 8765 jjdelcerro
                            this.normalWidth, this.normalHeight);
623
            support.firePropertyChange("normalBounds", oldBounds, normalBounds);
624 7345 cesar
            support.firePropertyChange("normalX", this.normalX, normalBounds.x);
625 6880 cesar
            normalX = normalBounds.x;
626 7345 cesar
            support.firePropertyChange("normalY", this.normalY, normalBounds.y);
627 6880 cesar
            normalY = normalBounds.y;
628 7345 cesar
            support.firePropertyChange("normalHeight", this.normalHeight, normalBounds.height);
629 6880 cesar
            normalHeight = normalBounds.height;
630 7345 cesar
            support.firePropertyChange("normalWidth", this.normalWidth, normalBounds.width);
631 6880 cesar
            normalWidth = normalBounds.width;
632
    }
633
634 11989 cesar
    /**
635
     * Set the bounds of the window.
636
     *
637
     * @param bounds The bounds to set.
638
     */
639 6880 cesar
    public void setBounds(Rectangle bounds) {
640 7345 cesar
            support.firePropertyChange("x", this.x, bounds.x);
641 6880 cesar
            x = bounds.x;
642 7345 cesar
            support.firePropertyChange("y", this.y, bounds.y);
643 6880 cesar
            y = bounds.y;
644 7345 cesar
            support.firePropertyChange("height", this.height, bounds.height);
645 6880 cesar
            height = bounds.height;
646 7345 cesar
            support.firePropertyChange("width", this.width, bounds.width);
647 6880 cesar
            width = bounds.width;
648
    }
649
650 11989 cesar
    /**
651
     * Gets the bounds of the window.
652
     *
653
     * @return the bounds of the window.
654
     */
655 6880 cesar
    public Rectangle getBounds() {
656
            return new Rectangle(x, y, width, height);
657
    }
658
659 11989 cesar
    /**
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 6880 cesar
    public int getNormalX() {
667
            if (normalX!=0)
668
                    return this.normalX;
669
            else
670
                    return x;
671
    }
672
673 11989 cesar
    /**
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 6880 cesar
    public int getNormalY() {
681
            if (normalY!=0)
682
                    return this.normalY;
683
            else
684
                    return y;
685
    }
686
687 11989 cesar
    /**
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 6880 cesar
    public int getNormalHeight() {
695
            if (normalHeight!=0)
696
                    return this.normalHeight;
697
            else
698
                    return height;
699
    }
700
701 11989 cesar
    /**
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 6880 cesar
    public int getNormalWidth() {
709
            if (normalWidth!=0)
710
                    return this.normalWidth;
711
            else
712
                    return width;
713
    }
714
715 11989 cesar
    /**
716
     * Determines whether the window is maximized or not
717
     *
718
     * @return true if the window is maximized, false otherwise
719
     */
720 6880 cesar
    public boolean isMaximized() {
721
            return this.isMaximized;
722
    }
723 11989 cesar
724 7345 cesar
    /**
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 11989 cesar
     *
729 7345 cesar
     * @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 11989 cesar
736 7345 cesar
    /**
737
     * Set whether the geometry of this window should be persisted in the
738
     * project files.
739 11989 cesar
     *
740 7345 cesar
     * @param persist
741
     */
742
    public void setPersistence(boolean persist) {
743
            this.persistWindow = persist;
744
    }
745 11989 cesar
746 7345 cesar
    /**
747
         * Gets the window properties in an XMLEntity object, suitable
748
         * for persistence.
749
         *
750 11992 cesar
         * @return An XMLEntity object containing the window properties
751 7345 cesar
     * @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 11989 cesar
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 7345 cesar
        public static WindowInfo createFromXMLEntity(XMLEntity xml)
787
        {
788
                WindowInfo result = new WindowInfo();
789 9655 cesar
                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 7345 cesar
                        }
805
                }
806 9655 cesar
                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 7345 cesar
810
                return result;
811
        }
812 11989 cesar
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 7345 cesar
        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 6880 cesar
}