Statistics
| Revision:

root / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / mdiManager / WindowInfo.java @ 24987

History | View | Annotate | Download (31.8 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.Dimension;
44
import java.awt.Rectangle;
45
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeSupport;
47
import java.util.HashMap;
48

    
49
import org.exolab.castor.xml.XMLException;
50

    
51
import com.iver.andami.PluginServices;
52
import com.iver.utiles.XMLEntity;
53

    
54

    
55
/**
56
 * This class represents the state of the associated window.
57
 * The <code>set</code> methods (<code>setX</code>, <code>setY</code>,
58
 * <code>setHeight</code>, etc) are immediately reflected on the
59
 * window.
60
 * 
61
 * The <code>update</code> methods doesn't update the window, because
62
 * they are used to update the WindowInfo object when the associated
63
 * window was modified by user interaction.
64
 *
65
 * @author Fernando Gonz?lez Cort?s
66
 */
67
public class WindowInfo {
68
        /** Specifies that the window is resizable  */
69
    public static final int RESIZABLE = 1;
70

    
71
    /** Specifies that the window is maximizable */
72
    public static final int MAXIMIZABLE = 2;
73

    
74
    /** Specifies that the window is iconifiable */
75
    public static final int ICONIFIABLE = 4;
76

    
77
    /** Specifies that the window is modal */
78
    public static final int MODALDIALOG = 8;
79
    /** Specifies that the window is modeless (it's on the top but doesn't block any other window) */
80
    public static final int MODELESSDIALOG = 16;
81
    /** Specifies that the window may be docked inside another window */
82
    public static final int PALETTE = 32;
83
    
84
    
85
    /** Specifies that this window has an editor profile */
86
    public static final Integer EDITOR_PROFILE = new Integer(1);
87
    /** Specifies that this window has an editor profile */
88
    public static final Integer TOOL_PROFILE = new Integer(2);
89
    /** Specifies that this window has an editor profile */
90
    public static final Integer PROJECT_PROFILE = new Integer(3);
91
    /** Specifies that this window has an editor profile */
92
    public static final Integer PROPERTIES_PROFILE = new Integer(4);
93
    /** Specifies that this window has an editor profile */
94
    public static final Integer DIALOG_PROFILE = new Integer(5);
95
    
96
    private PropertyChangeSupport support = new PropertyChangeSupport(this);
97

    
98
    /** DOCUMENT ME! */
99
    private boolean resizable = false;
100

    
101
    /** DOCUMENT ME! */
102
    private boolean maximizable = false;
103

    
104
    /** DOCUMENT ME! */
105
    private boolean iconifiable = false;
106

    
107
    /** DOCUMENT ME! */
108
    private boolean modal = false;
109
    private boolean modeless = false;
110

    
111
    /**
112
     * Do we want to persist the geometry of this window in the project file?
113
     */
114
    private boolean persistWindow = true;
115

    
116
    /**
117
     * Se usa para poner una ventana de tipo paleta, por
118
     * encima de las dem?s. Equivale a poner usar
119
     * JDesktopPane.PALETTE_LAYER
120
     */
121
    private boolean palette = false;
122
    
123
    private String additionalInfo = null;
124

    
125
    /** These properties store the dimension and position of the frame */
126
    private int width = -1;
127
    private int height = -1;
128
    private int x = -1;
129
    private int y = -1;
130
    /**
131
     * These properties store the position and dimension of the frame when it is not maximized
132
     * (so that it can be restored to its original size). They are equal to the not-normal properties
133
     * when the frame is not maximized, and different when the frame is maximized.
134
     */
135
    private int normalX = 0;
136
    private int normalY = 0;
137
    private int normalHeight = -1;
138
    private int normalWidth = -1;
139
    
140
    /** The minimum allowed size for this window. */
141
    private Dimension minSize = null;
142
    
143
    /* Whether the window is maximized */
144
    private boolean isMaximized = false;
145
    private boolean visible = true;
146
    /* Whether the window is closed */
147
    private boolean isClosed = false;
148

    
149

    
150
    /** DOCUMENT ME! */
151
    private String title;
152

    
153
    private int id;
154

    
155
    /**
156
     * ActionCommand del tool seleccionado. Lo usamos
157
     * para activar el tool que estaba seleccionado en
158
     * la vista, cuando volvemos a ella.
159
     */
160
    private HashMap selectedTools = null;
161
    // this should be the same value defined at plugin-config.xsd
162
    private String defaultGroup = "unico";
163

    
164
    /**
165
     * Adds a PropertyChangeListener to the listener list. The listener will be
166
     * notified about changes in this object.
167
     *
168
     * @param listener
169
     */
170
    public void addPropertyChangeListener(PropertyChangeListener listener) {
171
        support.addPropertyChangeListener(listener);
172
    }
173

    
174
    /**
175
     * Remove a PropertyChangeListener from the listener list. The listener will
176
     * not be notified anymore about changes in this object.
177
     *
178
     * @param listener
179
     */
180
    public void removePropertyChangeListener(PropertyChangeListener listener) {
181
        support.removePropertyChangeListener(listener);
182
    }
183

    
184
    /**
185
     * Creates a new WindowInfo object with the provided properties.
186
     * Valid properties include:
187
     * <ul>
188
     * <li>WindowInfo.MODALDIALOG</li>
189
     * <li>WindowInfo.MODELESSDIALOG</li>
190
     * <li>WindowInfo.PALETTE</li>
191
     * <li>WindowInfo.ICONIFIABLE</li>
192
     * <li>WindowInfo.RESIZABLE</li>
193
     * <li>WindowInfo.MAXIMIZABLE</li>
194
     * 
195
     * <p>Properties can be set together by using the binary OR operator
196
     * "<b>|</b>". For example:</p>
197
     * 
198
     * <p><code>WindowInfo wi = new WindowInfo(WindowInfo.MODELESSDIALOG 
199
     *   |WindowInfo.ICONIFIABLE|WindowInfo.RESIZABLE).</code></p>
200
     *   
201
     * <p>The WindowInfo.MODELESSDIALOG and WindowInfo.MODALDIALOG properties
202
     * cannot be set at the same time</p> 
203
     *
204
     * @param code Bit-or of the window properties.
205
     *
206
     * @throws IllegalStateException If incompatible properties are set together,
207
     * for example, if MODALDIALOG and MODELESSDIALGO are set together.
208
     */
209
    public WindowInfo(int code) {
210
        resizable = (code % 2) > 0;
211
        code = code / 2;
212
        maximizable = (code % 2) > 0;
213
        code = code / 2;
214
        iconifiable = (code % 2) > 0;
215
        code = code / 2;
216
        modal = (code % 2) > 0;
217
        code = code / 2;
218
        modeless = (code % 2) > 0;
219
        code = code / 2;
220
        palette = (code % 2) > 0;
221

    
222
        if (modal && modeless) {
223
            throw new IllegalStateException("modal && modeless");
224
        }
225
    }
226

    
227
    /**
228
     * Creates a new WindowInfo object with the default properties:
229
     * <ul>
230
     * <li>not resizable</li>
231
     * <li>not maximizable</li>
232
     * <li>not iconifiable</li>
233
     * <li>not modal</li>
234
     * <li>not modeless</li>
235
     * <li>not palette</li>
236
     * </uil>
237
     *
238
     */
239
    public WindowInfo(){
240

    
241
    }
242
    
243
    /**
244
     * Returns the current x coordinate of the window's origin
245
     * (left-upper corner of the window).
246
     *
247
     * @return Returns the value (in pixels) of the x coordinate
248
     * of the window's origin.
249
     */
250
    public int getX() {
251
        return x;
252
    }
253

    
254
    /**
255
     * Sets the x coordinate of the window's origin
256
     * (left-upper corner of the window).
257
     *
258
     * @param x        The value (in pixels) of the x coordinate to set.
259
     */
260
    public void setX(int x) {
261
            support.firePropertyChange("x", this.x, x);
262
            this.x = x;
263
            if (!isMaximized)
264
                    this.normalX = x;
265
    }
266
    
267
    /**
268
     * Updates the value of the x coordinate for this WindowInfo
269
     * object. It doesn't get reflected on the window (use
270
     * setX for that).
271
     * 
272
     * @param x The value (in pixels) of the x coordinate
273
     */
274
    public void updateX(int x) {
275
            this.x = x;
276
            if (!isMaximized)
277
                    this.normalX = x;
278
    }
279

    
280
    /**
281
     * Gets the value of the y coordinate for the origin
282
     * (left-upper corner of the window) of the associated
283
     * window.
284
     * 
285
     * @return Returns the y coordinate (in pixels).
286
     */
287
    public int getY() {
288
        return y;
289
    }
290

    
291
    /**
292
     * Sets the value of the y coordinate for the origin
293
     * (left-upper corner of the window) of the associated
294
     * window.
295
     * 
296
     * @param y The value (in pixels) of the y coordinate
297
     */
298
    public void setY(int y) {
299
            support.firePropertyChange("y", this.y, y);
300
        this.y = y;
301
        if (!isMaximized)
302
                this.normalY = y;
303
    }
304
    
305
    /**
306
     * Updates the value of the y coordinate for this WindowInfo
307
     * object. It doesn't get reflected on the window (use
308
     * setY for that).
309
     * 
310
     * @param y The value (in pixels) of the y coordinate
311
     */
312
    public void updateY(int y) {
313
            this.y = y;
314
            if (!isMaximized)
315
                    this.normalY = y;
316
    }
317

    
318
    /**
319
     * Determines whether the associated window is iconifiable or not
320
     *
321
     * @return
322
     */
323
    public boolean isIconifiable() {
324
        return iconifiable;
325
    }
326

    
327
    /**
328
     * Determines whether the associated window is maximizable or not
329
     *
330
     * @return
331
     */
332
    public boolean isMaximizable() {
333
        return maximizable;
334
    }
335

    
336
    /**
337
     * Determines whether the associated window is resizable or not
338
     *
339
     * @return
340
     */
341
    public boolean isResizable() {
342
        return resizable;
343
    }
344

    
345
    /**
346
     * Determines whether the associated window is modal or not
347
     *
348
     * @return
349
     */
350
    public boolean isModal() {
351
        return modal;
352
    }
353

    
354
    /**
355
     * Gets the window height.
356
     *
357
     * @return The window height (in pixels).
358
     */
359
    public int getHeight() {
360
        return height;
361
    }
362

    
363
    /**
364
     * Gets the window width.
365
     *
366
     * @return The window width (in pixels).
367
     */
368
    public int getWidth() {
369
        return width;
370
    }
371

    
372
    /**
373
     * Sets the window height.
374
     *
375
     * @param The window height (in pixels)
376
     */
377
    public void setHeight(int height) {
378
            if (height!=-1)
379
                    support.firePropertyChange("height", this.height, height);
380
            this.height = height;
381
        if (!isMaximized)
382
                this.normalHeight = height;
383
    }
384
    
385
    /**
386
     * Updates the height property for this WindowInfo
387
     * object. It doesn't get reflected on the window (use
388
     * <code>setHeight</code> for that).
389
     * 
390
     * @param height The height value for this WindowInfo object
391
     */
392
    public void updateHeight(int height) {
393
            this.height = height;
394
        if (!isMaximized)
395
                this.normalHeight = height;
396
    }
397

    
398
    /**
399
     * Sets the width property for the associated Window.
400
     *
401
     * @param w The new width.
402
     */
403
    public void setWidth(int w) {
404
            if (w!=-1)
405
                    support.firePropertyChange("width", this.width, w);
406
        width = w;
407
        if (!isMaximized)
408
                this.normalWidth = w;
409
    }
410
    
411
    /**
412
     * Updates the width property for for this WindowInfo
413
     * object. It doesn't get reflected on the window (use
414
     * <code>setWidth</code> for that).
415
     * 
416
     * @param height The height value for this WindowInfo object
417
     */
418
    public void updateWidth(int width) {
419
            this.width = width;
420
        if (!isMaximized)
421
                this.normalWidth = width;
422
    }
423

    
424
    /**
425
     * Gets the title property
426
     *
427
     * @return
428
     */
429
    public String getTitle() {
430
        return title;
431
    }
432

    
433
    /**
434
     * Sets the title property.
435
     *
436
     * @param title The new title.
437
     */
438
    public void setTitle(String title) {
439
            support.firePropertyChange("title", this.title, title);
440
        this.title = title;
441
    }
442
    
443
    /**
444
     * Updates the title property for for this WindowInfo
445
     * object. It doesn't get reflected on the window (use
446
     * <code>setTitle</code> for that).
447
     * 
448
     * @param title The title value for this WindowInfo object
449
     */
450
    public void updateTitle(String title) {
451
            this.title = title;
452
    }
453

    
454
    /**
455
     * Determines whether the associated window is modeless
456
     * (it is on the top but does not block any other window)
457
     *
458
     * @return
459
     */
460
    public boolean isModeless() {
461
        return modeless;
462
    }
463

    
464
     /**
465
      * Determines whether the associated window is visible
466
      *
467
      * @return true if the associated window is visible, false
468
      * if it is hidden
469
      */
470
    public boolean isVisible() {
471
        return visible;
472
    }
473

    
474
    /**
475
     * Determines whether the associated dockable window is
476
     * currently in palette status or docked.
477
     *
478
     * @return true if the window is currently in palette status,
479
     * false if it is docked in another window
480
     */
481
    public boolean isPalette()
482
    {
483
        return palette;
484
    }
485

    
486
    /**
487
     * Sets the window's ID.
488
     * 
489
     * @param id An integer to identify the window. Different
490
     * windows must have different IDs.
491
     */
492
    public void setId(int id){
493
            this.id = id;
494
    }
495

    
496
    /**
497
     * Gets the window ID.
498
     * 
499
     * @return id An integer to identify the window. Different
500
     * windows must have different IDs.
501
     */
502
    public int getId(){
503
            return id;
504
    }
505

    
506
    /**
507
     * Updates all the properties in this object so that
508
     * they match the properties of the provided
509
     * <code>wi</code> object. The changes are not reflected on the
510
     * window, just the WindowInfo object is updated.
511
     * 
512
     * @param vi A WindowInfo object containing the new
513
     * properties of the window.
514
     */
515
    public void setWindowInfo(WindowInfo vi){
516
            this.resizable = vi.resizable;
517
            this.maximizable = vi.maximizable;
518
            this.isMaximized = vi.isMaximized;
519
            this.iconifiable = vi.iconifiable;
520
            this.additionalInfo = vi.additionalInfo;
521
            this.modal = vi.modal;
522
            this.modeless = vi.modeless;
523
            if (vi.width!=-1)
524
                    this.width = vi.width;
525
            if (vi.height!=-1)
526
                    this.height = vi.height;
527
            this.x = vi.x;
528
            this.y = vi.y;
529
            this.visible = vi.visible;
530
            this.title = vi.title;
531
            this.id = vi.id;
532
            if (vi.normalHeight!=-1)
533
                    this.normalHeight = vi.normalHeight;
534
            if (vi.normalWidth!=-1)
535
                    this.normalWidth = vi.normalWidth;
536
            this.normalX = vi.normalX;
537
            this.normalY = vi.normalY;
538
            this.isClosed = vi.isClosed;
539
            this.persistWindow = vi.persistWindow;
540
    }
541
    
542
    /**
543
     * Sets whether the window is in palette mode or is in docked mode. 
544
     * This method <b>does not</b> update the window status, it just
545
     * updates the WindowInfo object. Use the IWindowTransform interface
546
     * to actually change the window status.
547
     * 
548
     * @param b
549
     */
550
    public void toPalette(boolean b){
551
            this.palette=b;
552
    }
553

    
554
    /**
555
     * Gets the list of selected tools for this window.
556
     * 
557
     * @return A HashMap containing pairs (group, actionCommand), which
558
     * are the selected tools for this window. 
559
     */
560
    public HashMap getSelectedTools() {
561
        return selectedTools;
562
    }
563

    
564
    /**
565
     * Use {@link setSelectedTools(HashMap selectedTool)} 
566
     * 
567
     * @param selectedTool
568
     * @deprecated
569
     */
570
    public void setSelectedTool(String selectedTool) {
571
        if (selectedTool != null)
572
            selectedTools.put(defaultGroup ,selectedTool);
573
    }
574
    
575
    /**
576
     * Sets the list of selected tools for this window.
577

578
     * @param selectedTools  A HashMap containing pairs
579
     * (group, actionCommand), which will be set as the selected tools
580
     * for this window. 
581
     */
582
    public void setSelectedTools(HashMap selectedTools) {
583
        if (selectedTools != null)
584
            this.selectedTools = selectedTools;
585
    }
586

    
587
    /** Finds out whether a view is open (showing) or closed */
588
    public boolean isClosed() {
589
            return isClosed;
590
    }
591

    
592
    /** Specifies whether a view is open (showing) or closed */
593
    public void setClosed(boolean closed) {
594
            support.firePropertyChange("closed", this.isClosed, closed);
595
            this.isClosed = closed;
596
    }
597

    
598
    /**
599
     * Updates the closed property for this WindowInfo
600
     * object. It doesn't get reflected on the window (use
601
     * <code>setClosed</code> for that).
602
     * 
603
     * @param closed The new closed property for this WindowInfo object
604
     */
605
    public void updateClosed(boolean closed) {
606
            this.isClosed = closed;
607
    }
608
    
609
    /**
610
     * Sets the normalX property for this WindowInfo object. This sets the X
611
     * position that the window would have when it gets restored from the
612
     * maximized state.
613
     * 
614
     * @param normalX The new normalX property for this WindowInfo object
615
     */
616
    public void setNormalX(int normalX) {
617
            if (!isMaximized()) {
618
                    setX(normalX);
619
            }
620
            else {
621
                    support.firePropertyChange("normalX", this.normalX, normalX);
622
                    this.normalX = normalX;
623
            }
624
    }
625
    
626
    /**
627
     * Updates the normalX property for this WindowInfo
628
     * object. It doesn't get reflected on the window (use
629
     * <code>setNormalX</code> for that).
630
     * 
631
     * @param normalX The new normalX property for this WindowInfo object
632
     */
633
    public void updateNormalX(int normalX) {
634
            this.normalX = normalX;
635
            if (!isMaximized())
636
                    x = normalX;
637
    }
638

    
639
    /**
640
     * Sets the normalY property for this WindowInfo object. This sets the Y
641
     * position that the window would have when it gets restored from the
642
     * maximized state.
643
     * 
644
     * @param normalY The new normalY property for this WindowInfo object
645
     */
646
    public void setNormalY(int normalY) {
647
            if (!isMaximized()) {
648
                    setY(normalY);
649
            }
650
            else {
651
                    support.firePropertyChange("normalY", this.normalY, normalY);
652
                    this.normalY = normalY;
653
            }
654
    }
655
    
656
    /**
657
     * Updates the normalY property for this WindowInfo
658
     * object. It doesn't get reflected on the window (use
659
     * <code>setNormalY</code> for that).
660
     * 
661
     * @param normalY The new normalY property for this WindowInfo object
662
     */
663
    public void updateNormalY(int normalY) {
664
            this.normalY = normalY;
665
            if (!isMaximized())
666
                    y = normalY;
667
    }
668

    
669
    /**
670
     * Sets the normalHeight property for this WindowInfo object. This sets the height
671
     * position that the window would have when it gets restored from the
672
     * maximized state.
673
     * 
674
     * @param normalY The new normalHeight property for this WindowInfo object
675
     */
676
    public void setNormalHeight(int normalHeight) {
677
            if (!isMaximized) {
678
                    setHeight(normalHeight);
679
            }
680
            else {
681
                    support.firePropertyChange("normalHeight", this.normalHeight, normalHeight);
682
                    this.normalHeight = normalHeight;
683
            }
684
    }
685
    
686
    /**
687
     * Updates the normalHeight property for this WindowInfo
688
     * object. It doesn't get reflected on the window (use
689
     * <code>setNormalHeight</code> for that).
690
     * 
691
     * @param normalHeight The new normalHeight property for this WindowInfo object
692
     */
693
    public void updateNormalHeight(int normalHeight) {
694
            this.normalHeight = normalHeight;
695
            if (!isMaximized) {
696
                    this.height = normalHeight;
697
            }
698
    }
699

    
700
    /**
701
     * Sets the normalWidth property for this WindowInfo object. This sets the width
702
     * position that the window would have when it gets restored from the
703
     * maximized state.
704
     * 
705
     * @param normalY The new normalWidth property for this WindowInfo object
706
     */
707
    public void setNormalWidth(int normalWidth) {
708
            if (!isMaximized()) {
709
                    setWidth(normalWidth);
710
            }
711
            else {
712
                    support.firePropertyChange("normalWidth", this.normalWidth, normalWidth);
713
                    this.normalWidth = normalWidth;
714
            }
715
    }
716
    
717
    /**
718
     * Sets the minimum allowed size for the associated window. If null is provided,
719
     * the minimum size is disabled (and thus
720
     * the window can be resized to any size).
721
     * 
722
     * @param minSize The minimum allowed size for the associated window.
723
     */
724
    public void setMinimumSize(Dimension minSize) {
725
            support.firePropertyChange("minimumSize", this.minSize, minSize);
726
            this.minSize = minSize;
727
    }
728

    
729
    /**
730
     * Updates the minimum allowed size for the associated window. It doesn't
731
     * get reflected on the window (use <code>setMinimumSize</code> for that).
732
     * 
733
     * @param minSize The minimum allowed size for the associated window.
734
     */
735
    public void updateMinimumSize(Dimension minSize) {
736
            this.minSize = minSize;
737
    }
738
    
739
    /**
740
     * Gets the minimum allowed size for the associated window.
741
     * 
742
     * @return minSize The minimum allowed size for the associated window.
743
     */
744
    public Dimension getMinimumSize() {
745
            return minSize;
746
    }
747
    
748
    /**
749
     * Updates the normalWidth property for this WindowInfo
750
     * object. It doesn't get reflected on the window (use
751
     * <code>setNormalWidth</code> for that).
752
     * 
753
     * @param normalWidth The new normalHeight property for this WindowInfo object
754
     */
755
    public void updateNormalWidth(int normalWidth) {
756
            this.normalWidth = normalWidth;
757
            if (!isMaximized())
758
                    this.width = normalWidth;
759
    }
760

    
761
    /**
762
     * Maximize the associated window
763
     * 
764
     * @param maximized
765
     */
766
    public void setMaximized(boolean maximized) {
767
            support.firePropertyChange("maximized", this.isMaximized, maximized);
768
            this.isMaximized = maximized;
769
    }
770
    
771
    /**
772
     * Updates the maximized property for this WindowInfo
773
     * object. It doesn't get reflected on the window (use
774
     * <code>setMaximized</code> for that).
775
     * 
776
     * @param maximized The new maximized property for this WindowInfo object
777
     */
778
    public void updateMaximized(boolean maximized) {
779
            this.isMaximized = maximized;
780
    }
781

    
782
    public void setMaximizable(boolean maximizable) {
783
            this.maximizable = maximizable;
784
    }
785

    
786
    /**
787
     * Sets the bounds of the associated window.
788
     * 
789
     * @param x
790
     * @param y
791
     * @param width
792
     * @param height
793
     */
794
    private void setBounds(int x, int y, int width, int height) {
795
            setX(x);
796
            setY(y);
797
            setWidth(width);
798
            setHeight(height);
799
    }
800
    
801
    /**
802
     * Updates the bounds for this WindowInfo object. It doesn't get reflected
803
     * on the window (use <code>setBounds</code> for that).
804
     * 
805
     * @param x
806
     * @param y
807
     * @param width
808
     * @param height
809
     */
810
    public void updateBounds(int x, int y, int width, int height) {
811
            this.x = x;
812
            this.y = y;
813
            this.width = width;
814
            this.height = height;
815
            if (!isMaximized()) {
816
                    this.normalX = x;
817
                    this.normalY = y;
818
                    this.normalWidth = width;
819
                    this.normalHeight = height;
820
            }
821
    }
822

    
823
    /**
824
     * Sets the normal bounds of the associated window. This sets the bounds
825
     * that the window would have when it gets restored from the
826
     * maximized state.
827
     * 
828
     * @param x
829
     * @param y
830
     * @param width
831
     * @param height
832
     */
833
    public void setNormalBounds(int x, int y, int width, int height) {
834
            setNormalX(x);
835
            setNormalY(y);
836
            setNormalWidth(width);
837
            setNormalHeight(height);
838
    }
839
    
840
    /**
841
     * Updates the normal bounds for this WindowInfo object. It doesn't get
842
     * reflected on the window (use <code>setNormalBounds</code> for that).
843
     * 
844
     * @param x
845
     * @param y
846
     * @param width
847
     * @param height
848
     */
849
    public void updateNormalBounds(int x, int y, int width, int height) {
850
                this.normalX = x;
851
                this.normalY = y;
852
                this.normalWidth = width;
853
                this.normalHeight = height;
854
            if (!isMaximized()) {
855
                this.x = x;
856
                this.y = y;
857
                this.width = width;
858
                this.height = height;
859
            }
860
    }
861

    
862
    /**
863
     * Gets the normal bounds of the associated window. This gets the bounds
864
     * that the window would have when it gets restored from the
865
     * maximized state.
866
     * 
867
     * @return The normal bounds of the associated window.
868
     */
869
    public Rectangle getNormalBounds() {
870
            return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight());
871
    }
872

    
873
    /**
874
     * Sets the normal bounds of the associated window. This sets the bounds
875
     * that the window would have when it gets restored from the
876
     * maximized state.
877
     * 
878
     * @param normalBounds
879
     */
880
    public void setNormalBounds(Rectangle normalBounds) {
881
            setNormalBounds(normalBounds.x, normalBounds.y, normalBounds.width, normalBounds.height);
882
    }
883
 
884
    /**
885
     * Updates the normal bounds for this WindowInfo object. It doesn't get
886
     * reflected on the window (use <code>setNormalBounds</code> for that).
887
     * 
888
     * @param normalBounds
889
     */
890
    public void updateNormalBounds(Rectangle normalBounds) {
891
            updateNormalBounds(normalBounds.x, normalBounds.y, normalBounds.width, normalBounds.height);
892
    }
893
    
894
    /**
895
     * Sets the bounds of the associated window.
896
     * 
897
     * @param bounds
898
     */
899
    public void setBounds(Rectangle bounds) {
900
            setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
901
    }
902
    
903
    /**
904
     * Updates the bounds for this WindowInfo object. It doesn't get reflected
905
     * on the window (use <code>setBounds</code> for that).
906
     * 
907
     * @param bounds
908
     */
909
    public void updateBounds(Rectangle bounds) {
910
            updateBounds(bounds.x, bounds.y, bounds.width, bounds.height);
911
    }
912

    
913
    /**
914
     * Gets the bounds of the associated window.
915
     * 
916
     * @return The bounds of the associated window.
917
     */
918
    public Rectangle getBounds() {
919
            return new Rectangle(x, y, width, height);
920
    }
921

    
922
    public int getNormalX() {
923
            if (normalX!=0)
924
                    return this.normalX;
925
            else
926
                    return x;
927
    }
928

    
929
    /**
930
     * Gets the x coordinate of the window's origin when the window is not
931
     * maximized. When the window is maximized, gets the y coordinate that
932
     * it will have when it gets restored
933
     * 
934
     * @return the normal y coordinate of the window's origin
935
     */
936
    public int getNormalY() {
937
            if (normalY!=0)
938
                    return this.normalY;
939
            else
940
                    return y;
941
    }
942

    
943
    /**
944
     * Gets the height of the window's origin when the window is not
945
     * maximized. When the window is maximized, gets the height that
946
     * it will have when it gets restored
947
     * 
948
     * @return the normal height of the window
949
     */
950
    public int getNormalHeight() {
951
            if (normalHeight!=0)
952
                    return this.normalHeight;
953
            else
954
                    return height;
955
    }
956

    
957
    /**
958
     * Gets the width of the window's origin when the window is not
959
     * maximized. When the window is maximized, gets the width that
960
     * it will have when it gets restored
961
     * 
962
     * @return the normal width of the window
963
     */
964
    public int getNormalWidth() {
965
            if (normalWidth!=0)
966
                    return this.normalWidth;
967
            else
968
                    return width;
969
    }
970

    
971
    /**
972
     * Determines whether the window is maximized or not
973
     * 
974
     * @return true if the window is maximized, false otherwise
975
     */
976
    public boolean isMaximized() {
977
            return this.isMaximized;
978
    }
979

    
980
    /**
981
     * Checks if the geometry of this window should be persisted in the
982
     * project file. This is set by the persistWindow(boolean) method,
983
     * and the default value is true.
984
     *
985
     * @return True if the geometry of this window should be persisted
986
     * in the project files, false otherwise.
987
     */
988
    public boolean checkPersistence() {
989
            return this.persistWindow;
990
    }
991

    
992
    /**
993
     * Set whether the geometry of this window should be persisted in the
994
     * project files.
995
     *
996
     * @param persist
997
     */
998
    public void setPersistence(boolean persist) {
999
            this.persistWindow = persist;
1000
    }
1001

    
1002
    /**
1003
         * Gets the window properties in an XMLEntity object, suitable
1004
         * for persistence.
1005
         *
1006
         * @return An XMLEntity object containing the window properties,
1007
         * or null if the window was set as not persistent
1008
     * @throws SaveException
1009
         * @throws XMLException
1010
         */
1011
        public XMLEntity getXMLEntity() {
1012
                if (checkPersistence()==false) {
1013
                        return null;
1014
                }
1015
                XMLEntity xml = new XMLEntity();
1016
                xml.setName("ViewInfoProperties");
1017
                xml.putProperty("X", this.getX(), false);
1018
                xml.putProperty("Y", this.getY(), false);
1019
                xml.putProperty("Width", this.getWidth(), false);
1020
                xml.putProperty("Height", this.getHeight(), false);
1021
                xml.putProperty("isVisible", this.isVisible(), false);
1022
                xml.putProperty("isResizable", this.isResizable(), false);
1023
                xml.putProperty("isMaximizable", this.isMaximizable(), false);
1024
                xml.putProperty("isModal", this.isModal(), false);
1025
                xml.putProperty("isModeless", this.isModeless(), false);
1026
                xml.putProperty("isClosed", this.isClosed(), false);
1027
                xml.putProperty("ParentName", this.getAdditionalInfo(), false);
1028
                if (this.isMaximized()==true) {
1029
                        xml.putProperty("isMaximized", this.isMaximized(), false);
1030
                        xml.putProperty("normalX", this.getNormalX(), false);
1031
                        xml.putProperty("normalY", this.getNormalY(), false);
1032
                        xml.putProperty("normalWidth", this.getNormalWidth(), false);
1033
                        xml.putProperty("normalHeight", this.getNormalHeight(), false);
1034
                }
1035
                return xml;
1036
        }
1037

    
1038
        /**
1039
         * Creates a WindowInfo object from an XMLEntity containing the
1040
         * window properties.
1041
         *  
1042
         * @param xml An XMLEntity object containing the window properties
1043
         * 
1044
         * @return A new WindowInfo object, containing the properties
1045
         * specified in the XMLEntity parameters 
1046
         */
1047
        public static WindowInfo createFromXMLEntity(XMLEntity xml)
1048
        {
1049
                WindowInfo result = new WindowInfo();
1050
                try {
1051
                        result.setX(xml.getIntProperty("X"));
1052
                        result.setY(xml.getIntProperty("Y"));
1053
                        result.setHeight(xml.getIntProperty("Height"));
1054
                        result.setWidth(xml.getIntProperty("Width"));
1055
                        result.setClosed(xml.getBooleanProperty("isClosed"));
1056
                        result.setAdditionalInfo(xml.getStringProperty("AdditionalInfo"));
1057
                        if (xml.contains("isMaximized")) {
1058
                                boolean maximized = xml.getBooleanProperty("isMaximized");
1059
                                result.setMaximized(maximized);
1060
                                if (maximized==true) {
1061
                                        result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
1062
                                }
1063
                                else {
1064
                                        result.setNormalBounds(result.getBounds());
1065
                                }
1066
                        }
1067
                }
1068
                catch (com.iver.utiles.NotExistInXMLEntity ex) {
1069
                        PluginServices.getLogger().warn(PluginServices.getText(null, "Window_properties_not_stored_correctly_Window_state_will_not_be_restored"));
1070
                }
1071

    
1072
                return result;
1073
        }
1074

    
1075
        /**
1076
         * Updates this WindowInfo object according to the properties
1077
         * provided by the XMLEntity parameter.
1078
         *  
1079
         * @param xml An XMLEntity object containing the window properties
1080
         */
1081
        public void getPropertiesFromXMLEntity(XMLEntity xml)
1082
        {
1083
                this.x = xml.getIntProperty("X");
1084
                this.y = xml.getIntProperty("Y");
1085
                this.height = xml.getIntProperty("Height");
1086
                this.width = xml.getIntProperty("Width");
1087
                this.isClosed = xml.getBooleanProperty("isClosed");
1088
                this.additionalInfo = xml.getStringProperty("AdditionalInfo");
1089
                if (xml.contains("isMaximized")) {
1090
                        boolean maximized = xml.getBooleanProperty("isMaximized");
1091
                        this.isMaximized = maximized;
1092
                        if (maximized==true) {
1093
                                this.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
1094
                        }
1095
                }
1096
        }
1097

    
1098
        /**
1099
         * Obtiene informaci?n adicional de la ventana. Esta etiqueta podr? llevar cualquier
1100
         * tipo de informaci?n que queramos almacenar.
1101
         * @return Informaci?n adicional
1102
         */
1103
        public String getAdditionalInfo() {
1104
                return additionalInfo;
1105
        }
1106

    
1107
        /**
1108
         * Asigna informaci?n adicional de la ventana. Esta etiqueta podr? llevar cualquier
1109
         * tipo de informaci?n que queramos almacenar.
1110
         * @return Informaci?n adicional
1111
         */
1112
        public void setAdditionalInfo(String additionalInfo) {
1113
                this.additionalInfo = additionalInfo;
1114
        }
1115

    
1116
}