Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / mdiManager / WindowInfo.java @ 42039

History | View | Annotate | Download (37.6 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.andami.ui.mdiManager;
25

    
26
import java.awt.Dimension;
27
import java.awt.Rectangle;
28
import java.beans.PropertyChangeListener;
29
import java.beans.PropertyChangeSupport;
30
import java.util.HashMap;
31
import java.util.Map;
32

    
33
import org.exolab.castor.xml.XMLException;
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.persistence.PersistenceManager;
38
import org.gvsig.tools.persistence.Persistent;
39
import org.gvsig.tools.persistence.PersistentState;
40
import org.gvsig.tools.persistence.exception.PersistenceException;
41
import org.gvsig.tools.util.Callable;
42
import org.gvsig.utils.XMLEntity;
43

    
44

    
45

    
46
/**
47
 * This class represents the state of the associated window.
48
 * The <code>set</code> methods (<code>setX</code>, <code>setY</code>,
49
 * <code>setHeight</code>, etc) are immediately reflected on the
50
 * window.
51
 *
52
 * The <code>update</code> methods doesn't update the window, because
53
 * they are used to update the WindowInfo object when the associated
54
 * window was modified by user interaction.
55
 *
56
 * @author Fernando Gonz?lez Cort?s
57
 */
58
public class WindowInfo implements Persistent{
59
        
60
        public static final String PERSISTENCE_DEFINITION_NAME = "WindowInfo";
61

    
62
        /** Specifies that the window is resizable  */
63
    public static final int RESIZABLE = 1;
64

    
65
    /** Specifies that the window is maximizable */
66
    public static final int MAXIMIZABLE = 2;
67

    
68
    /** Specifies that the window is iconifiable */
69
    public static final int ICONIFIABLE = 4;
70

    
71
    /** Specifies that the window is modal */
72
    public static final int MODALDIALOG = 8;
73
    /** Specifies that the window is modeless (it's on the top but doesn't block any other window) */
74
    public static final int MODELESSDIALOG = 16;
75
    /** Specifies that the window may be docked inside another window */
76
    public static final int PALETTE = 32;
77
    /** Specifies that the window may be closed */
78
    public static final int NOTCLOSABLE = 64;
79

    
80

    
81
    /** Specifies that this window has an editor profile */
82
    public static final Integer EDITOR_PROFILE = new Integer(1);
83
    /** Specifies that this window has an editor profile */
84
    public static final Integer TOOL_PROFILE = new Integer(2);
85
    /** Specifies that this window has an editor profile */
86
    public static final Integer PROJECT_PROFILE = new Integer(3);
87
    /** Specifies that this window has an editor profile */
88
    public static final Integer PROPERTIES_PROFILE = new Integer(4);
89
    /** Specifies that this window has an editor profile */
90
    public static final Integer DIALOG_PROFILE = new Integer(5);
91

    
92
    private PropertyChangeSupport support = new PropertyChangeSupport(this);
93

    
94
    /** DOCUMENT ME! */
95
    private boolean resizable = false;
96

    
97
    /** DOCUMENT ME! */
98
    private boolean maximizable = false;
99

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

    
103
    /** DOCUMENT ME! */
104
    private boolean modal = false;
105
    private boolean modeless = false;
106
    private boolean notclosable = false;
107
    
108
    /**
109
     * Do we want to persist the geometry of this window in the project file?
110
     */
111
    private boolean persistWindow = true;
112

    
113
    /**
114
     * Se usa para poner una ventana de tipo paleta, por
115
     * encima de las dem?s. Equivale a poner usar
116
     * JDesktopPane.PALETTE_LAYER
117
     */
118
    private boolean palette = false;
119

    
120
    private String additionalInfo = null;
121

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

    
137
    /** The minimum allowed size for this window. */
138
    private Dimension minSize = null;
139

    
140
    /* Whether the window is maximized */
141
    private boolean isMaximized = false;
142
    private boolean visible = true;
143
    /* Whether the window is closed */
144
    private boolean isClosed = false;
145

    
146

    
147
    /** DOCUMENT ME! */
148
    private String title;
149

    
150
    private int id;
151

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

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

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

    
182
    /**
183
     * Creates a new WindowInfo object with the provided properties.
184
     * Valid properties include:
185
     * <ul>
186
     * <li>WindowInfo.MODALDIALOG</li>
187
     * <li>WindowInfo.MODELESSDIALOG</li>
188
     * <li>WindowInfo.PALETTE</li>
189
     * <li>WindowInfo.ICONIFIABLE</li>
190
     * <li>WindowInfo.RESIZABLE</li>
191
     * <li>WindowInfo.MAXIMIZABLE</li>
192
     *
193
     * <p>Properties can be set together by using the binary OR operator
194
     * "<b>|</b>". For example:</p>
195
     *
196
     * <p><code>WindowInfo wi = new WindowInfo(WindowInfo.MODELESSDIALOG
197
     *   |WindowInfo.ICONIFIABLE|WindowInfo.RESIZABLE).</code></p>
198
     *
199
     * <p>The WindowInfo.MODELESSDIALOG and WindowInfo.MODALDIALOG properties
200
     * cannot be set at the same time</p>
201
     *
202
     * @param code Bit-or of the window properties.
203
     *
204
     * @throws IllegalStateException If incompatible properties are set together,
205
     * for example, if MODALDIALOG and MODELESSDIALGO are set together.
206
     */
207
    public WindowInfo(int code) {
208
        resizable = (code % 2) > 0;
209
        code = code / 2;
210
        maximizable = (code % 2) > 0;
211
        code = code / 2;
212
        iconifiable = (code % 2) > 0;
213
        code = code / 2;
214
        modal = (code % 2) > 0;
215
        code = code / 2;
216
        modeless = (code % 2) > 0;
217
        code = code / 2;
218
        palette = (code % 2) > 0;
219
        code = code / 2;
220
        notclosable = (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 closable or not
466
     *
467
     * @return
468
     */
469
    public boolean isNotClosable() {
470
        return notclosable;
471
    }
472
    
473
    /**
474
     * Sets notclosable property 
475
     *
476
     * @return
477
     */
478
    public void setNotClosable(boolean b) {
479
        notclosable = b;
480
    }
481

    
482
     /**
483
      * Determines whether the associated window is visible
484
      *
485
      * @return true if the associated window is visible, false
486
      * if it is hidden
487
      */
488
    public boolean isVisible() {
489
        return visible;
490
    }
491

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

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

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

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

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

    
573
    /**
574
     * Gets the list of selected tools for this window.
575
     *
576
     * @return A HashMap containing pairs (group, actionCommand), which
577
     * are the selected tools for this window.
578
     */
579
    @SuppressWarnings("rawtypes")
580
        public Map getSelectedTools() {
581
        return selectedTools;
582
    }
583

    
584
    /**
585
     * Use {@link setSelectedTools(HashMap selectedTool)}
586
     *
587
     * @param selectedTool
588
     * @deprecated
589
     */
590
    @SuppressWarnings("unchecked")
591
        public void setSelectedTool(String selectedTool) {
592
        if (selectedTool != null)
593
            selectedTools.put(defaultGroup ,selectedTool);
594
    }
595

    
596
    /**
597
     * Sets the list of selected tools for this window.
598

599
     * @param selectedTools  A HashMap containing pairs
600
     * (group, actionCommand), which will be set as the selected tools
601
     * for this window.
602
     */
603
    @SuppressWarnings("rawtypes")
604
        public void setSelectedTools(Map selectedTools) {
605
        if (selectedTools != null)
606
            this.selectedTools = selectedTools;
607
    }
608

    
609
    /** Finds out whether a view is open (showing) or closed */
610
    public boolean isClosed() {
611
            return isClosed;
612
    }
613
    
614
    /** Specifies whether a view is open (showing) or closed */
615
    public void setClosed(boolean closed) {
616
            support.firePropertyChange("closed", this.isClosed, closed);
617
            this.isClosed = closed;
618
    }
619

    
620
    /**
621
     * Updates the closed property for this WindowInfo
622
     * object. It doesn't get reflected on the window (use
623
     * <code>setClosed</code> for that).
624
     *
625
     * @param closed The new closed property for this WindowInfo object
626
     */
627
    public void updateClosed(boolean closed) {
628
            this.isClosed = closed;
629
    }
630

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

    
648
    /**
649
     * Updates the normalX property for this WindowInfo
650
     * object. It doesn't get reflected on the window (use
651
     * <code>setNormalX</code> for that).
652
     *
653
     * @param normalX The new normalX property for this WindowInfo object
654
     */
655
    public void updateNormalX(int normalX) {
656
            this.normalX = normalX;
657
            if (!isMaximized())
658
                    x = normalX;
659
    }
660

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

    
678
    /**
679
     * Updates the normalY property for this WindowInfo
680
     * object. It doesn't get reflected on the window (use
681
     * <code>setNormalY</code> for that).
682
     *
683
     * @param normalY The new normalY property for this WindowInfo object
684
     */
685
    public void updateNormalY(int normalY) {
686
            this.normalY = normalY;
687
            if (!isMaximized())
688
                    y = normalY;
689
    }
690

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

    
708
    /**
709
     * Updates the normalHeight property for this WindowInfo
710
     * object. It doesn't get reflected on the window (use
711
     * <code>setNormalHeight</code> for that).
712
     *
713
     * @param normalHeight The new normalHeight property for this WindowInfo object
714
     */
715
    public void updateNormalHeight(int normalHeight) {
716
            this.normalHeight = normalHeight;
717
            if (!isMaximized) {
718
                    this.height = normalHeight;
719
            }
720
    }
721

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

    
739
    /**
740
     * Sets the minimum allowed size for the associated window. If null is provided,
741
     * the minimum size is disabled (and thus
742
     * the window can be resized to any size).
743
     *
744
     * @param minSize The minimum allowed size for the associated window.
745
     */
746
    public void setMinimumSize(Dimension minSize) {
747
            support.firePropertyChange("minimumSize", this.minSize, minSize);
748
            this.minSize = minSize;
749
    }
750

    
751
    /**
752
     * Updates the minimum allowed size for the associated window. It doesn't
753
     * get reflected on the window (use <code>setMinimumSize</code> for that).
754
     *
755
     * @param minSize The minimum allowed size for the associated window.
756
     */
757
    public void updateMinimumSize(Dimension minSize) {
758
            this.minSize = minSize;
759
    }
760

    
761
    /**
762
     * Gets the minimum allowed size for the associated window.
763
     *
764
     * @return minSize The minimum allowed size for the associated window.
765
     */
766
    public Dimension getMinimumSize() {
767
            return minSize;
768
    }
769

    
770
    /**
771
     * Updates the normalWidth property for this WindowInfo
772
     * object. It doesn't get reflected on the window (use
773
     * <code>setNormalWidth</code> for that).
774
     *
775
     * @param normalWidth The new normalHeight property for this WindowInfo object
776
     */
777
    public void updateNormalWidth(int normalWidth) {
778
            this.normalWidth = normalWidth;
779
            if (!isMaximized())
780
                    this.width = normalWidth;
781
    }
782

    
783
    /**
784
     * Maximize the associated window
785
     *
786
     * @param maximized
787
     */
788
    public void setMaximized(boolean maximized) {
789
            support.firePropertyChange("maximized", this.isMaximized, maximized);
790
            this.isMaximized = maximized;
791
    }
792

    
793
    /**
794
     * Updates the maximized property for this WindowInfo
795
     * object. It doesn't get reflected on the window (use
796
     * <code>setMaximized</code> for that).
797
     *
798
     * @param maximized The new maximized property for this WindowInfo object
799
     */
800
    public void updateMaximized(boolean maximized) {
801
            this.isMaximized = maximized;
802
    }
803

    
804
    public void setMaximizable(boolean maximizable) {
805
            this.maximizable = maximizable;
806
    }
807

    
808
    /**
809
     * Sets the bounds of the associated window.
810
     *
811
     * @param x
812
     * @param y
813
     * @param width
814
     * @param height
815
     */
816
    private void setBounds(int x, int y, int width, int height) {
817
            setX(x);
818
            setY(y);
819
            setWidth(width);
820
            setHeight(height);
821
    }
822

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

    
845
    /**
846
     * Sets the normal bounds of the associated window. This sets the bounds
847
     * that the window would have when it gets restored from the
848
     * maximized state.
849
     *
850
     * @param x
851
     * @param y
852
     * @param width
853
     * @param height
854
     */
855
    public void setNormalBounds(int x, int y, int width, int height) {
856
            setNormalX(x);
857
            setNormalY(y);
858
            setNormalWidth(width);
859
            setNormalHeight(height);
860
    }
861

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

    
884
    /**
885
     * Gets the normal bounds of the associated window. This gets the bounds
886
     * that the window would have when it gets restored from the
887
     * maximized state.
888
     *
889
     * @return The normal bounds of the associated window.
890
     */
891
    public Rectangle getNormalBounds() {
892
            return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight());
893
    }
894

    
895
    /**
896
     * Sets the normal bounds of the associated window. This sets the bounds
897
     * that the window would have when it gets restored from the
898
     * maximized state.
899
     *
900
     * @param normalBounds
901
     */
902
    public void setNormalBounds(Rectangle normalBounds) {
903
            setNormalBounds(normalBounds.x, normalBounds.y, normalBounds.width, normalBounds.height);
904
    }
905

    
906
    /**
907
     * Updates the normal bounds for this WindowInfo object. It doesn't get
908
     * reflected on the window (use <code>setNormalBounds</code> for that).
909
     *
910
     * @param normalBounds
911
     */
912
    public void updateNormalBounds(Rectangle normalBounds) {
913
            updateNormalBounds(normalBounds.x, normalBounds.y, normalBounds.width, normalBounds.height);
914
    }
915

    
916
    /**
917
     * Sets the bounds of the associated window.
918
     *
919
     * @param bounds
920
     */
921
    public void setBounds(Rectangle bounds) {
922
            setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
923
    }
924

    
925
    /**
926
     * Updates the bounds for this WindowInfo object. It doesn't get reflected
927
     * on the window (use <code>setBounds</code> for that).
928
     *
929
     * @param bounds
930
     */
931
    public void updateBounds(Rectangle bounds) {
932
            updateBounds(bounds.x, bounds.y, bounds.width, bounds.height);
933
    }
934

    
935
    /**
936
     * Gets the bounds of the associated window.
937
     *
938
     * @return The bounds of the associated window.
939
     */
940
    public Rectangle getBounds() {
941
            return new Rectangle(x, y, width, height);
942
    }
943

    
944
    public int getNormalX() {
945
            if (normalX!=0)
946
                    return this.normalX;
947
            else
948
                    return x;
949
    }
950

    
951
    /**
952
     * Gets the x coordinate of the window's origin when the window is not
953
     * maximized. When the window is maximized, gets the y coordinate that
954
     * it will have when it gets restored
955
     *
956
     * @return the normal y coordinate of the window's origin
957
     */
958
    public int getNormalY() {
959
            if (normalY!=0)
960
                    return this.normalY;
961
            else
962
                    return y;
963
    }
964

    
965
    /**
966
     * Gets the height of the window's origin when the window is not
967
     * maximized. When the window is maximized, gets the height that
968
     * it will have when it gets restored
969
     *
970
     * @return the normal height of the window
971
     */
972
    public int getNormalHeight() {
973
            if (normalHeight!=0)
974
                    return this.normalHeight;
975
            else
976
                    return height;
977
    }
978

    
979
    /**
980
     * Gets the width of the window's origin when the window is not
981
     * maximized. When the window is maximized, gets the width that
982
     * it will have when it gets restored
983
     *
984
     * @return the normal width of the window
985
     */
986
    public int getNormalWidth() {
987
            if (normalWidth!=0)
988
                    return this.normalWidth;
989
            else
990
                    return width;
991
    }
992

    
993
    /**
994
     * Determines whether the window is maximized or not
995
     *
996
     * @return true if the window is maximized, false otherwise
997
     */
998
    public boolean isMaximized() {
999
            return this.isMaximized;
1000
    }
1001

    
1002
    /**
1003
     * Checks if the geometry of this window should be persisted in the
1004
     * project file. This is set by the persistWindow(boolean) method,
1005
     * and the default value is true.
1006
     *
1007
     * @return True if the geometry of this window should be persisted
1008
     * in the project files, false otherwise.
1009
     */
1010
    public boolean checkPersistence() {
1011
            return this.persistWindow;
1012
    }
1013

    
1014
    /**
1015
     * Set whether the geometry of this window should be persisted in the
1016
     * project files.
1017
     *
1018
     * @param persist
1019
     */
1020
    public void setPersistence(boolean persist) {
1021
            this.persistWindow = persist;
1022
    }
1023

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

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

    
1096
                return result;
1097
        }
1098

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

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

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

    
1141
        public void saveToState(PersistentState state) throws PersistenceException {
1142
            state.set("resizable", this.resizable);
1143
            state.set("maximizable", this.maximizable);
1144
            state.set("iconifiable", this.iconifiable);
1145
            state.set("modal", this.modal);
1146
            state.set("modeless", this.modeless);
1147
            state.set("notclosable", this.notclosable);
1148
            state.set("persistWindow", this.persistWindow); //OJO ?Obsoleto?
1149
            state.set("palette", this.palette);
1150
            state.set("additionalInfo", this.additionalInfo);
1151
            state.set("width", this.width);
1152
            state.set("height", this.height);
1153
            state.set("x", this.x);
1154
            state.set("y", this.y);
1155
            state.set("normalX", this.normalX);
1156
            state.set("normalY", this.normalY);
1157
            state.set("normalHeight", this.normalHeight);
1158
            state.set("normalWidth", this.normalWidth);
1159
            state.set("minSize", this.minSize);
1160
            state.set("isMaximized", this.isMaximized);
1161
            state.set("visible", this.visible);
1162
            state.set("isClosed", this.isClosed);
1163
            state.set("title", this.title);
1164
            state.set("id", this.id); //OJO
1165
            state.set("selectedTools", this.selectedTools); //OJO
1166
            state.set("defaultGroup", this.defaultGroup); //OJO
1167
        }
1168

    
1169
        @SuppressWarnings("rawtypes")
1170
        public void loadFromState(PersistentState state)
1171
                        throws PersistenceException {
1172
            this.resizable = state.getBoolean("resizable");
1173
            this.maximizable = state.getBoolean("maximizable");
1174
            this.iconifiable = state.getBoolean("iconifiable");
1175
            this.modal = state.getBoolean("modal");
1176
            this.modeless = state.getBoolean("modeless");
1177
            this.notclosable = state.getBoolean("notclosable");
1178
            this.persistWindow = state.getBoolean("persistWindow"); //OJO ?Obsoleto?
1179
            this.palette = state.getBoolean("palette");
1180
            this.additionalInfo = state.getString("additionalInfo");
1181
            this.width = state.getInt("width");
1182
            this.height = state.getInt("height");
1183
            this.x = state.getInt("x");
1184
            this.y = state.getInt("y");
1185
            this.normalX = state.getInt("normalX");
1186
            this.normalY = state.getInt("normalY");
1187
            this.normalHeight = state.getInt("normalHeight");
1188
            this.normalWidth = state.getInt("normalWidth");
1189
            this.minSize = (Dimension)state.get("minSize");
1190
            this.isMaximized = state.getBoolean("isMaximized");
1191
            this.visible = state.getBoolean("visible");
1192
            this.isClosed = state.getBoolean("isClosed");
1193
            this.title = state.getString("title");
1194
            this.id = state.getInt("id");
1195
            this.setSelectedTools(state.getMap("selectedTools"));
1196
            this.defaultGroup = state.getString("defaultGroup"); //OJO
1197
        }
1198

    
1199
        
1200
    public static class RegisterPersistence implements Callable {
1201

    
1202
        public Object call() throws Exception {
1203
                    PersistenceManager manager = ToolsLocator.getPersistenceManager();
1204
                    DynStruct definition = manager.getDefinition(PERSISTENCE_DEFINITION_NAME);
1205
                    if ( definition == null ){
1206
                        definition = manager.addDefinition(
1207
                            WindowInfo.class,
1208
                            PERSISTENCE_DEFINITION_NAME,
1209
                            "WindowInfo persistence definition",
1210
                            null, 
1211
                            null
1212
                        );
1213
                        definition.addDynFieldBoolean("resizable").setMandatory(true);
1214
                        definition.addDynFieldBoolean("maximizable").setMandatory(true);
1215
                        definition.addDynFieldBoolean("iconifiable").setMandatory(true);
1216
                        definition.addDynFieldBoolean("modal").setMandatory(true);
1217
                        definition.addDynFieldBoolean("modeless").setMandatory(true);
1218
                        definition.addDynFieldBoolean("notclosable").setMandatory(true);
1219
                        definition.addDynFieldBoolean("persistWindow").setMandatory(true);
1220
                        definition.addDynFieldBoolean("palette").setMandatory(true);
1221
                        definition.addDynFieldString("additionalInfo").setMandatory(false);
1222
                        definition.addDynFieldInt("width").setMandatory(true);
1223
                        definition.addDynFieldInt("height").setMandatory(true);
1224
                        definition.addDynFieldInt("x").setMandatory(true);
1225
                        definition.addDynFieldInt("y").setMandatory(true);
1226
                        definition.addDynFieldInt("normalX").setMandatory(true);
1227
                        definition.addDynFieldInt("normalY").setMandatory(true);
1228
                        definition.addDynFieldInt("normalHeight").setMandatory(true);
1229
                        definition.addDynFieldInt("normalWidth").setMandatory(true);
1230
                        definition.addDynFieldObject("minSize").setMandatory(false).setClassOfValue(Dimension.class);
1231
                        definition.addDynFieldBoolean("isMaximized").setMandatory(true);
1232
                        definition.addDynFieldBoolean("visible").setMandatory(true);
1233
                        definition.addDynFieldBoolean("isClosed").setMandatory(true);
1234
                        definition.addDynFieldString("title").setMandatory(true);
1235
                        definition.addDynFieldInt("id").setMandatory(true);
1236
                        definition.addDynFieldMap("selectedTools").setMandatory(false)
1237
                            .setClassOfItems(String.class);
1238
                        definition.addDynFieldString("defaultGroup").setMandatory(true);
1239
                    }
1240
                return Boolean.TRUE;
1241
        }
1242
    }
1243
}