Statistics
| Revision:

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

History | View | Annotate | Download (32.3 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
    /** Specifies that the window may be closed */
84
    public static final int NOTCLOSABLE = 64;
85

    
86

    
87
    /** Specifies that this window has an editor profile */
88
    public static final Integer EDITOR_PROFILE = new Integer(1);
89
    /** Specifies that this window has an editor profile */
90
    public static final Integer TOOL_PROFILE = new Integer(2);
91
    /** Specifies that this window has an editor profile */
92
    public static final Integer PROJECT_PROFILE = new Integer(3);
93
    /** Specifies that this window has an editor profile */
94
    public static final Integer PROPERTIES_PROFILE = new Integer(4);
95
    /** Specifies that this window has an editor profile */
96
    public static final Integer DIALOG_PROFILE = new Integer(5);
97

    
98
    private PropertyChangeSupport support = new PropertyChangeSupport(this);
99

    
100
    /** DOCUMENT ME! */
101
    private boolean resizable = false;
102

    
103
    /** DOCUMENT ME! */
104
    private boolean maximizable = false;
105

    
106
    /** DOCUMENT ME! */
107
    private boolean iconifiable = false;
108

    
109
    /** DOCUMENT ME! */
110
    private boolean modal = false;
111
    private boolean modeless = false;
112
    private boolean notclosable = false;
113

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

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

    
126
    private String additionalInfo = null;
127

    
128
    /** These properties store the dimension and position of the frame */
129
    private int width = -1;
130
    private int height = -1;
131
    private int x = -1;
132
    private int y = -1;
133
    /**
134
     * These properties store the position and dimension of the frame when it is not maximized
135
     * (so that it can be restored to its original size). They are equal to the not-normal properties
136
     * when the frame is not maximized, and different when the frame is maximized.
137
     */
138
    private int normalX = 0;
139
    private int normalY = 0;
140
    private int normalHeight = -1;
141
    private int normalWidth = -1;
142

    
143
    /** The minimum allowed size for this window. */
144
    private Dimension minSize = null;
145

    
146
    /* Whether the window is maximized */
147
    private boolean isMaximized = false;
148
    private boolean visible = true;
149
    /* Whether the window is closed */
150
    private boolean isClosed = false;
151

    
152

    
153
    /** DOCUMENT ME! */
154
    private String title;
155

    
156
    private int id;
157

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

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

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

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

    
227
        if (modal && modeless) {
228
            throw new IllegalStateException("modal && modeless");
229
        }
230
    }
231

    
232
    /**
233
     * Creates a new WindowInfo object with the default properties:
234
     * <ul>
235
     * <li>not resizable</li>
236
     * <li>not maximizable</li>
237
     * <li>not iconifiable</li>
238
     * <li>not modal</li>
239
     * <li>not modeless</li>
240
     * <li>not palette</li>
241
     * </uil>
242
     *
243
     */
244
    public WindowInfo(){
245

    
246
    }
247

    
248
    /**
249
     * Returns the current x coordinate of the window's origin
250
     * (left-upper corner of the window).
251
     *
252
     * @return Returns the value (in pixels) of the x coordinate
253
     * of the window's origin.
254
     */
255
    public int getX() {
256
        return x;
257
    }
258

    
259
    /**
260
     * Sets the x coordinate of the window's origin
261
     * (left-upper corner of the window).
262
     *
263
     * @param x        The value (in pixels) of the x coordinate to set.
264
     */
265
    public void setX(int x) {
266
            support.firePropertyChange("x", this.x, x);
267
            this.x = x;
268
            if (!isMaximized)
269
                    this.normalX = x;
270
    }
271

    
272
    /**
273
     * Updates the value of the x coordinate for this WindowInfo
274
     * object. It doesn't get reflected on the window (use
275
     * setX for that).
276
     *
277
     * @param x The value (in pixels) of the x coordinate
278
     */
279
    public void updateX(int x) {
280
            this.x = x;
281
            if (!isMaximized)
282
                    this.normalX = x;
283
    }
284

    
285
    /**
286
     * Gets the value of the y coordinate for the origin
287
     * (left-upper corner of the window) of the associated
288
     * window.
289
     *
290
     * @return Returns the y coordinate (in pixels).
291
     */
292
    public int getY() {
293
        return y;
294
    }
295

    
296
    /**
297
     * Sets the value of the y coordinate for the origin
298
     * (left-upper corner of the window) of the associated
299
     * window.
300
     *
301
     * @param y The value (in pixels) of the y coordinate
302
     */
303
    public void setY(int y) {
304
            support.firePropertyChange("y", this.y, y);
305
        this.y = y;
306
        if (!isMaximized)
307
                this.normalY = y;
308
    }
309

    
310
    /**
311
     * Updates the value of the y coordinate for this WindowInfo
312
     * object. It doesn't get reflected on the window (use
313
     * setY for that).
314
     *
315
     * @param y The value (in pixels) of the y coordinate
316
     */
317
    public void updateY(int y) {
318
            this.y = y;
319
            if (!isMaximized)
320
                    this.normalY = y;
321
    }
322

    
323
    /**
324
     * Determines whether the associated window is closable or not
325
     *
326
     * @return
327
     */
328
    public boolean isNotClosable() {
329
        return notclosable;
330
    }
331

    
332
    /**
333
     * Determines whether the associated window is iconifiable or not
334
     *
335
     * @return
336
     */
337
    public boolean isIconifiable() {
338
        return iconifiable;
339
    }
340

    
341
    /**
342
     * Determines whether the associated window is maximizable or not
343
     *
344
     * @return
345
     */
346
    public boolean isMaximizable() {
347
        return maximizable;
348
    }
349

    
350
    /**
351
     * Determines whether the associated window is resizable or not
352
     *
353
     * @return
354
     */
355
    public boolean isResizable() {
356
        return resizable;
357
    }
358

    
359
    /**
360
     * Determines whether the associated window is modal or not
361
     *
362
     * @return
363
     */
364
    public boolean isModal() {
365
        return modal;
366
    }
367

    
368
    /**
369
     * Gets the window height.
370
     *
371
     * @return The window height (in pixels).
372
     */
373
    public int getHeight() {
374
        return height;
375
    }
376

    
377
    /**
378
     * Gets the window width.
379
     *
380
     * @return The window width (in pixels).
381
     */
382
    public int getWidth() {
383
        return width;
384
    }
385

    
386
    /**
387
     * Sets the window height.
388
     *
389
     * @param The window height (in pixels)
390
     */
391
    public void setHeight(int height) {
392
            if (height!=-1)
393
                    support.firePropertyChange("height", this.height, height);
394
            this.height = height;
395
        if (!isMaximized)
396
                this.normalHeight = height;
397
    }
398

    
399
    /**
400
     * Updates the height property for this WindowInfo
401
     * object. It doesn't get reflected on the window (use
402
     * <code>setHeight</code> for that).
403
     *
404
     * @param height The height value for this WindowInfo object
405
     */
406
    public void updateHeight(int height) {
407
            this.height = height;
408
        if (!isMaximized)
409
                this.normalHeight = height;
410
    }
411

    
412
    /**
413
     * Sets the width property for the associated Window.
414
     *
415
     * @param w The new width.
416
     */
417
    public void setWidth(int w) {
418
            if (w!=-1)
419
                    support.firePropertyChange("width", this.width, w);
420
        width = w;
421
        if (!isMaximized)
422
                this.normalWidth = w;
423
    }
424

    
425
    /**
426
     * Updates the width property for for this WindowInfo
427
     * object. It doesn't get reflected on the window (use
428
     * <code>setWidth</code> for that).
429
     *
430
     * @param height The height value for this WindowInfo object
431
     */
432
    public void updateWidth(int width) {
433
            this.width = width;
434
        if (!isMaximized)
435
                this.normalWidth = width;
436
    }
437

    
438
    /**
439
     * Gets the title property
440
     *
441
     * @return
442
     */
443
    public String getTitle() {
444
        return title;
445
    }
446

    
447
    /**
448
     * Sets the title property.
449
     *
450
     * @param title The new title.
451
     */
452
    public void setTitle(String title) {
453
            support.firePropertyChange("title", this.title, title);
454
        this.title = title;
455
    }
456

    
457
    /**
458
     * Updates the title property for for this WindowInfo
459
     * object. It doesn't get reflected on the window (use
460
     * <code>setTitle</code> for that).
461
     *
462
     * @param title The title value for this WindowInfo object
463
     */
464
    public void updateTitle(String title) {
465
            this.title = title;
466
    }
467

    
468
    /**
469
     * Determines whether the associated window is modeless
470
     * (it is on the top but does not block any other window)
471
     *
472
     * @return
473
     */
474
    public boolean isModeless() {
475
        return modeless;
476
    }
477

    
478
     /**
479
      * Determines whether the associated window is visible
480
      *
481
      * @return true if the associated window is visible, false
482
      * if it is hidden
483
      */
484
    public boolean isVisible() {
485
        return visible;
486
    }
487

    
488
    /**
489
     * Determines whether the associated dockable window is
490
     * currently in palette status or docked.
491
     *
492
     * @return true if the window is currently in palette status,
493
     * false if it is docked in another window
494
     */
495
    public boolean isPalette()
496
    {
497
        return palette;
498
    }
499

    
500
    /**
501
     * Sets the window's ID.
502
     *
503
     * @param id An integer to identify the window. Different
504
     * windows must have different IDs.
505
     */
506
    public void setId(int id){
507
            this.id = id;
508
    }
509

    
510
    /**
511
     * Gets the window ID.
512
     *
513
     * @return id An integer to identify the window. Different
514
     * windows must have different IDs.
515
     */
516
    public int getId(){
517
            return id;
518
    }
519

    
520
    /**
521
     * Updates all the properties in this object so that
522
     * they match the properties of the provided
523
     * <code>wi</code> object. The changes are not reflected on the
524
     * window, just the WindowInfo object is updated.
525
     *
526
     * @param vi A WindowInfo object containing the new
527
     * properties of the window.
528
     */
529
    public void setWindowInfo(WindowInfo vi){
530
            this.resizable = vi.resizable;
531
            this.maximizable = vi.maximizable;
532
            this.isMaximized = vi.isMaximized;
533
            this.iconifiable = vi.iconifiable;
534
            this.additionalInfo = vi.additionalInfo;
535
            this.modal = vi.modal;
536
            this.modeless = vi.modeless;
537
            this.notclosable = vi.notclosable;
538
            if (vi.width!=-1)
539
                    this.width = vi.width;
540
            if (vi.height!=-1)
541
                    this.height = vi.height;
542
            this.x = vi.x;
543
            this.y = vi.y;
544
            this.visible = vi.visible;
545
            this.title = vi.title;
546
            this.id = vi.id;
547
            if (vi.normalHeight!=-1)
548
                    this.normalHeight = vi.normalHeight;
549
            if (vi.normalWidth!=-1)
550
                    this.normalWidth = vi.normalWidth;
551
            this.normalX = vi.normalX;
552
            this.normalY = vi.normalY;
553
            this.isClosed = vi.isClosed;
554
            this.persistWindow = vi.persistWindow;
555
    }
556

    
557
    /**
558
     * Sets whether the window is in palette mode or is in docked mode.
559
     * This method <b>does not</b> update the window status, it just
560
     * updates the WindowInfo object. Use the IWindowTransform interface
561
     * to actually change the window status.
562
     *
563
     * @param b
564
     */
565
    public void toPalette(boolean b){
566
            this.palette=b;
567
    }
568

    
569
    /**
570
     * Gets the list of selected tools for this window.
571
     *
572
     * @return A HashMap containing pairs (group, actionCommand), which
573
     * are the selected tools for this window.
574
     */
575
    public HashMap getSelectedTools() {
576
        return selectedTools;
577
    }
578

    
579
    /**
580
     * Use {@link setSelectedTools(HashMap selectedTool)}
581
     *
582
     * @param selectedTool
583
     * @deprecated
584
     */
585
    public void setSelectedTool(String selectedTool) {
586
        if (selectedTool != null)
587
            selectedTools.put(defaultGroup ,selectedTool);
588
    }
589

    
590
    /**
591
     * Sets the list of selected tools for this window.
592

593
     * @param selectedTools  A HashMap containing pairs
594
     * (group, actionCommand), which will be set as the selected tools
595
     * for this window.
596
     */
597
    public void setSelectedTools(HashMap selectedTools) {
598
        if (selectedTools != null)
599
            this.selectedTools = selectedTools;
600
    }
601

    
602
    /** Finds out whether a view is open (showing) or closed */
603
    public boolean isClosed() {
604
            return isClosed;
605
    }
606

    
607
    /** Specifies whether a view is open (showing) or closed */
608
    public void setClosed(boolean closed) {
609
            support.firePropertyChange("closed", this.isClosed, closed);
610
            this.isClosed = closed;
611
    }
612

    
613
    /**
614
     * Updates the closed property for this WindowInfo
615
     * object. It doesn't get reflected on the window (use
616
     * <code>setClosed</code> for that).
617
     *
618
     * @param closed The new closed property for this WindowInfo object
619
     */
620
    public void updateClosed(boolean closed) {
621
            this.isClosed = closed;
622
    }
623

    
624
    /**
625
     * Sets the normalX property for this WindowInfo object. This sets the X
626
     * position that the window would have when it gets restored from the
627
     * maximized state.
628
     *
629
     * @param normalX The new normalX property for this WindowInfo object
630
     */
631
    public void setNormalX(int normalX) {
632
            if (!isMaximized()) {
633
                    setX(normalX);
634
            }
635
            else {
636
                    support.firePropertyChange("normalX", this.normalX, normalX);
637
                    this.normalX = normalX;
638
            }
639
    }
640

    
641
    /**
642
     * Updates the normalX property for this WindowInfo
643
     * object. It doesn't get reflected on the window (use
644
     * <code>setNormalX</code> for that).
645
     *
646
     * @param normalX The new normalX property for this WindowInfo object
647
     */
648
    public void updateNormalX(int normalX) {
649
            this.normalX = normalX;
650
            if (!isMaximized())
651
                    x = normalX;
652
    }
653

    
654
    /**
655
     * Sets the normalY property for this WindowInfo object. This sets the Y
656
     * position that the window would have when it gets restored from the
657
     * maximized state.
658
     *
659
     * @param normalY The new normalY property for this WindowInfo object
660
     */
661
    public void setNormalY(int normalY) {
662
            if (!isMaximized()) {
663
                    setY(normalY);
664
            }
665
            else {
666
                    support.firePropertyChange("normalY", this.normalY, normalY);
667
                    this.normalY = normalY;
668
            }
669
    }
670

    
671
    /**
672
     * Updates the normalY property for this WindowInfo
673
     * object. It doesn't get reflected on the window (use
674
     * <code>setNormalY</code> for that).
675
     *
676
     * @param normalY The new normalY property for this WindowInfo object
677
     */
678
    public void updateNormalY(int normalY) {
679
            this.normalY = normalY;
680
            if (!isMaximized())
681
                    y = normalY;
682
    }
683

    
684
    /**
685
     * Sets the normalHeight property for this WindowInfo object. This sets the height
686
     * position that the window would have when it gets restored from the
687
     * maximized state.
688
     *
689
     * @param normalY The new normalHeight property for this WindowInfo object
690
     */
691
    public void setNormalHeight(int normalHeight) {
692
            if (!isMaximized) {
693
                    setHeight(normalHeight);
694
            }
695
            else {
696
                    support.firePropertyChange("normalHeight", this.normalHeight, normalHeight);
697
                    this.normalHeight = normalHeight;
698
            }
699
    }
700

    
701
    /**
702
     * Updates the normalHeight property for this WindowInfo
703
     * object. It doesn't get reflected on the window (use
704
     * <code>setNormalHeight</code> for that).
705
     *
706
     * @param normalHeight The new normalHeight property for this WindowInfo object
707
     */
708
    public void updateNormalHeight(int normalHeight) {
709
            this.normalHeight = normalHeight;
710
            if (!isMaximized) {
711
                    this.height = normalHeight;
712
            }
713
    }
714

    
715
    /**
716
     * Sets the normalWidth property for this WindowInfo object. This sets the width
717
     * position that the window would have when it gets restored from the
718
     * maximized state.
719
     *
720
     * @param normalY The new normalWidth property for this WindowInfo object
721
     */
722
    public void setNormalWidth(int normalWidth) {
723
            if (!isMaximized()) {
724
                    setWidth(normalWidth);
725
            }
726
            else {
727
                    support.firePropertyChange("normalWidth", this.normalWidth, normalWidth);
728
                    this.normalWidth = normalWidth;
729
            }
730
    }
731

    
732
    /**
733
     * Sets the minimum allowed size for the associated window. If null is provided,
734
     * the minimum size is disabled (and thus
735
     * the window can be resized to any size).
736
     *
737
     * @param minSize The minimum allowed size for the associated window.
738
     */
739
    public void setMinimumSize(Dimension minSize) {
740
            support.firePropertyChange("minimumSize", this.minSize, minSize);
741
            this.minSize = minSize;
742
    }
743

    
744
    /**
745
     * Updates the minimum allowed size for the associated window. It doesn't
746
     * get reflected on the window (use <code>setMinimumSize</code> for that).
747
     *
748
     * @param minSize The minimum allowed size for the associated window.
749
     */
750
    public void updateMinimumSize(Dimension minSize) {
751
            this.minSize = minSize;
752
    }
753

    
754
    /**
755
     * Gets the minimum allowed size for the associated window.
756
     *
757
     * @return minSize The minimum allowed size for the associated window.
758
     */
759
    public Dimension getMinimumSize() {
760
            return minSize;
761
    }
762

    
763
    /**
764
     * Updates the normalWidth property for this WindowInfo
765
     * object. It doesn't get reflected on the window (use
766
     * <code>setNormalWidth</code> for that).
767
     *
768
     * @param normalWidth The new normalHeight property for this WindowInfo object
769
     */
770
    public void updateNormalWidth(int normalWidth) {
771
            this.normalWidth = normalWidth;
772
            if (!isMaximized())
773
                    this.width = normalWidth;
774
    }
775

    
776
    /**
777
     * Maximize the associated window
778
     *
779
     * @param maximized
780
     */
781
    public void setMaximized(boolean maximized) {
782
            support.firePropertyChange("maximized", this.isMaximized, maximized);
783
            this.isMaximized = maximized;
784
    }
785

    
786
    /**
787
     * Updates the maximized property for this WindowInfo
788
     * object. It doesn't get reflected on the window (use
789
     * <code>setMaximized</code> for that).
790
     *
791
     * @param maximized The new maximized property for this WindowInfo object
792
     */
793
    public void updateMaximized(boolean maximized) {
794
            this.isMaximized = maximized;
795
    }
796

    
797
    public void setMaximizable(boolean maximizable) {
798
            this.maximizable = maximizable;
799
    }
800

    
801
    /**
802
     * Sets the bounds of the associated window.
803
     *
804
     * @param x
805
     * @param y
806
     * @param width
807
     * @param height
808
     */
809
    private void setBounds(int x, int y, int width, int height) {
810
            setX(x);
811
            setY(y);
812
            setWidth(width);
813
            setHeight(height);
814
    }
815

    
816
    /**
817
     * Updates the bounds for this WindowInfo object. It doesn't get reflected
818
     * on the window (use <code>setBounds</code> for that).
819
     *
820
     * @param x
821
     * @param y
822
     * @param width
823
     * @param height
824
     */
825
    public void updateBounds(int x, int y, int width, int height) {
826
            this.x = x;
827
            this.y = y;
828
            this.width = width;
829
            this.height = height;
830
            if (!isMaximized()) {
831
                    this.normalX = x;
832
                    this.normalY = y;
833
                    this.normalWidth = width;
834
                    this.normalHeight = height;
835
            }
836
    }
837

    
838
    /**
839
     * Sets the normal bounds of the associated window. This sets the bounds
840
     * that the window would have when it gets restored from the
841
     * maximized state.
842
     *
843
     * @param x
844
     * @param y
845
     * @param width
846
     * @param height
847
     */
848
    public void setNormalBounds(int x, int y, int width, int height) {
849
            setNormalX(x);
850
            setNormalY(y);
851
            setNormalWidth(width);
852
            setNormalHeight(height);
853
    }
854

    
855
    /**
856
     * Updates the normal bounds for this WindowInfo object. It doesn't get
857
     * reflected on the window (use <code>setNormalBounds</code> for that).
858
     *
859
     * @param x
860
     * @param y
861
     * @param width
862
     * @param height
863
     */
864
    public void updateNormalBounds(int x, int y, int width, int height) {
865
                this.normalX = x;
866
                this.normalY = y;
867
                this.normalWidth = width;
868
                this.normalHeight = height;
869
            if (!isMaximized()) {
870
                this.x = x;
871
                this.y = y;
872
                this.width = width;
873
                this.height = height;
874
            }
875
    }
876

    
877
    /**
878
     * Gets the normal bounds of the associated window. This gets the bounds
879
     * that the window would have when it gets restored from the
880
     * maximized state.
881
     *
882
     * @return The normal bounds of the associated window.
883
     */
884
    public Rectangle getNormalBounds() {
885
            return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight());
886
    }
887

    
888
    /**
889
     * Sets the normal bounds of the associated window. This sets the bounds
890
     * that the window would have when it gets restored from the
891
     * maximized state.
892
     *
893
     * @param normalBounds
894
     */
895
    public void setNormalBounds(Rectangle normalBounds) {
896
            setNormalBounds(normalBounds.x, normalBounds.y, normalBounds.width, normalBounds.height);
897
    }
898

    
899
    /**
900
     * Updates the normal bounds for this WindowInfo object. It doesn't get
901
     * reflected on the window (use <code>setNormalBounds</code> for that).
902
     *
903
     * @param normalBounds
904
     */
905
    public void updateNormalBounds(Rectangle normalBounds) {
906
            updateNormalBounds(normalBounds.x, normalBounds.y, normalBounds.width, normalBounds.height);
907
    }
908

    
909
    /**
910
     * Sets the bounds of the associated window.
911
     *
912
     * @param bounds
913
     */
914
    public void setBounds(Rectangle bounds) {
915
            setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
916
    }
917

    
918
    /**
919
     * Updates the bounds for this WindowInfo object. It doesn't get reflected
920
     * on the window (use <code>setBounds</code> for that).
921
     *
922
     * @param bounds
923
     */
924
    public void updateBounds(Rectangle bounds) {
925
            updateBounds(bounds.x, bounds.y, bounds.width, bounds.height);
926
    }
927

    
928
    /**
929
     * Gets the bounds of the associated window.
930
     *
931
     * @return The bounds of the associated window.
932
     */
933
    public Rectangle getBounds() {
934
            return new Rectangle(x, y, width, height);
935
    }
936

    
937
    public int getNormalX() {
938
            if (normalX!=0)
939
                    return this.normalX;
940
            else
941
                    return x;
942
    }
943

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

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

    
972
    /**
973
     * Gets the width of the window's origin when the window is not
974
     * maximized. When the window is maximized, gets the width that
975
     * it will have when it gets restored
976
     *
977
     * @return the normal width of the window
978
     */
979
    public int getNormalWidth() {
980
            if (normalWidth!=0)
981
                    return this.normalWidth;
982
            else
983
                    return width;
984
    }
985

    
986
    /**
987
     * Determines whether the window is maximized or not
988
     *
989
     * @return true if the window is maximized, false otherwise
990
     */
991
    public boolean isMaximized() {
992
            return this.isMaximized;
993
    }
994

    
995
    /**
996
     * Checks if the geometry of this window should be persisted in the
997
     * project file. This is set by the persistWindow(boolean) method,
998
     * and the default value is true.
999
     *
1000
     * @return True if the geometry of this window should be persisted
1001
     * in the project files, false otherwise.
1002
     */
1003
    public boolean checkPersistence() {
1004
            return this.persistWindow;
1005
    }
1006

    
1007
    /**
1008
     * Set whether the geometry of this window should be persisted in the
1009
     * project files.
1010
     *
1011
     * @param persist
1012
     */
1013
    public void setPersistence(boolean persist) {
1014
            this.persistWindow = persist;
1015
    }
1016

    
1017
    /**
1018
         * Gets the window properties in an XMLEntity object, suitable
1019
         * for persistence.
1020
         *
1021
         * @return An XMLEntity object containing the window properties,
1022
         * or null if the window was set as not persistent
1023
     * @throws SaveException
1024
         * @throws XMLException
1025
         */
1026
        public XMLEntity getXMLEntity() {
1027
                if (checkPersistence()==false) {
1028
                        return null;
1029
                }
1030
                XMLEntity xml = new XMLEntity();
1031
                xml.setName("ViewInfoProperties");
1032
                xml.putProperty("X", this.getX(), false);
1033
                xml.putProperty("Y", this.getY(), false);
1034
                xml.putProperty("Width", this.getWidth(), false);
1035
                xml.putProperty("Height", this.getHeight(), false);
1036
                xml.putProperty("isVisible", this.isVisible(), false);
1037
                xml.putProperty("isResizable", this.isResizable(), false);
1038
                xml.putProperty("isMaximizable", this.isMaximizable(), false);
1039
                xml.putProperty("isModal", this.isModal(), false);
1040
                xml.putProperty("isModeless", this.isModeless(), false);
1041
                xml.putProperty("isClosed", this.isClosed(), false);
1042
                xml.putProperty("isNotClosable", this.isNotClosable(), false);
1043
                xml.putProperty("AdditionalInfo", this.getAdditionalInfo(), false);
1044
                if (this.isMaximized()==true) {
1045
                        xml.putProperty("isMaximized", this.isMaximized(), false);
1046
                        xml.putProperty("normalX", this.getNormalX(), false);
1047
                        xml.putProperty("normalY", this.getNormalY(), false);
1048
                        xml.putProperty("normalWidth", this.getNormalWidth(), false);
1049
                        xml.putProperty("normalHeight", this.getNormalHeight(), false);
1050
                }
1051
                return xml;
1052
        }
1053

    
1054
        /**
1055
         * Creates a WindowInfo object from an XMLEntity containing the
1056
         * window properties.
1057
         *
1058
         * @param xml An XMLEntity object containing the window properties
1059
         *
1060
         * @return A new WindowInfo object, containing the properties
1061
         * specified in the XMLEntity parameters
1062
         */
1063
        public static WindowInfo createFromXMLEntity(XMLEntity xml)
1064
        {
1065
                WindowInfo result = new WindowInfo();
1066
                try {
1067
                        result.setX(xml.getIntProperty("X"));
1068
                        result.setY(xml.getIntProperty("Y"));
1069
                        result.setHeight(xml.getIntProperty("Height"));
1070
                        result.setWidth(xml.getIntProperty("Width"));
1071
                        result.setClosed(xml.getBooleanProperty("isClosed"));
1072
                        result.setNotClosable(xml.getBooleanProperty("isNotClosable"));
1073
                        result.setAdditionalInfo(xml.getStringProperty("AdditionalInfo"));
1074
                        if (xml.contains("isMaximized")) {
1075
                                boolean maximized = xml.getBooleanProperty("isMaximized");
1076
                                result.setMaximized(maximized);
1077
                                if (maximized==true) {
1078
                                        result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
1079
                                }
1080
                                else {
1081
                                        result.setNormalBounds(result.getBounds());
1082
                                }
1083
                        }
1084
                }
1085
                catch (com.iver.utiles.NotExistInXMLEntity ex) {
1086
                        PluginServices.getLogger().warn(PluginServices.getText(null, "Window_properties_not_stored_correctly_Window_state_will_not_be_restored"));
1087
                }
1088

    
1089
                return result;
1090
        }
1091

    
1092
        public void setNotClosable(boolean b) {
1093
                notclosable=b;
1094
        }
1095

    
1096
        /**
1097
         * Updates this WindowInfo object according to the properties
1098
         * provided by the XMLEntity parameter.
1099
         *
1100
         * @param xml An XMLEntity object containing the window properties
1101
         */
1102
        public void getPropertiesFromXMLEntity(XMLEntity xml)
1103
        {
1104
                this.x = xml.getIntProperty("X");
1105
                this.y = xml.getIntProperty("Y");
1106
                this.height = xml.getIntProperty("Height");
1107
                this.width = xml.getIntProperty("Width");
1108
                this.isClosed = xml.getBooleanProperty("isClosed");
1109
                this.notclosable = xml.getBooleanProperty("isNotClosable");
1110
                this.additionalInfo = xml.getStringProperty("AdditionalInfo");
1111
                if (xml.contains("isMaximized")) {
1112
                        boolean maximized = xml.getBooleanProperty("isMaximized");
1113
                        this.isMaximized = maximized;
1114
                        if (maximized==true) {
1115
                                this.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
1116
                        }
1117
                }
1118
        }
1119

    
1120
        /**
1121
         * Obtiene informaci?n adicional de la ventana. Esta etiqueta podr? llevar cualquier
1122
         * tipo de informaci?n que queramos almacenar.
1123
         * @return Informaci?n adicional
1124
         */
1125
        public String getAdditionalInfo() {
1126
                return additionalInfo;
1127
        }
1128

    
1129
        /**
1130
         * Asigna informaci?n adicional de la ventana. Esta etiqueta podr? llevar cualquier
1131
         * tipo de informaci?n que queramos almacenar.
1132
         * @return Informaci?n adicional
1133
         */
1134
        public void setAdditionalInfo(String additionalInfo) {
1135
                this.additionalInfo = additionalInfo;
1136
        }
1137

    
1138
}