Statistics
| Revision:

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

History | View | Annotate | Download (32.3 KB)

1 6880 cesar
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3 11992 cesar
 * Copyright (C) 2004-2007 IVER T.I. and Generalitat Valenciana.
4 6880 cesar
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.andami.ui.mdiManager;
42
43 9994 cesar
import java.awt.Dimension;
44 6880 cesar
import java.awt.Rectangle;
45
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeSupport;
47 10643 cesar
import java.util.HashMap;
48 6880 cesar
49 9750 jaume
import org.exolab.castor.xml.XMLException;
50
51 7447 cesar
import com.iver.andami.PluginServices;
52
import com.iver.utiles.XMLEntity;
53 6880 cesar
54 7447 cesar
55 6880 cesar
/**
56 9963 cesar
 * This class represents the state of the associated window.
57
 * The <code>set</code> methods (<code>setX</code>, <code>setY</code>,
58 11992 cesar
 * <code>setHeight</code>, etc) are immediately reflected on the
59 9963 cesar
 * window.
60 25553 vcaballero
 *
61 9963 cesar
 * 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 6880 cesar
 *
65
 * @author Fernando Gonz?lez Cort?s
66
 */
67
public class WindowInfo {
68 11992 cesar
        /** Specifies that the window is resizable  */
69 6880 cesar
    public static final int RESIZABLE = 1;
70
71 9963 cesar
    /** Specifies that the window is maximizable */
72 6880 cesar
    public static final int MAXIMIZABLE = 2;
73
74 9963 cesar
    /** Specifies that the window is iconifiable */
75 6880 cesar
    public static final int ICONIFIABLE = 4;
76
77 9963 cesar
    /** Specifies that the window is modal */
78 6880 cesar
    public static final int MODALDIALOG = 8;
79 11992 cesar
    /** Specifies that the window is modeless (it's on the top but doesn't block any other window) */
80 6880 cesar
    public static final int MODELESSDIALOG = 16;
81 11992 cesar
    /** Specifies that the window may be docked inside another window */
82 6880 cesar
    public static final int PALETTE = 32;
83 29750 vcaballero
    /** Specifies that the window may be closed */
84
    public static final int NOTCLOSABLE = 64;
85 25553 vcaballero
86
87 24987 jcampos
    /** 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 25553 vcaballero
98 6880 cesar
    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 29750 vcaballero
    private boolean notclosable = false;
113 9750 jaume
114 7447 cesar
    /**
115
     * Do we want to persist the geometry of this window in the project file?
116
     */
117
    private boolean persistWindow = true;
118 6880 cesar
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 25553 vcaballero
126 12224 nacho
    private String additionalInfo = null;
127 6880 cesar
128
    /** These properties store the dimension and position of the frame */
129
    private int width = -1;
130
    private int height = -1;
131 11826 cesar
    private int x = -1;
132
    private int y = -1;
133 6880 cesar
    /**
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 8374 cesar
    private int normalHeight = -1;
141
    private int normalWidth = -1;
142 25553 vcaballero
143 9994 cesar
    /** The minimum allowed size for this window. */
144
    private Dimension minSize = null;
145 25553 vcaballero
146 6880 cesar
    /* 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 10687 cesar
    private HashMap selectedTools = null;
164 10643 cesar
    // this should be the same value defined at plugin-config.xsd
165
    private String defaultGroup = "unico";
166 6880 cesar
167
    /**
168 11992 cesar
     * Adds a PropertyChangeListener to the listener list. The listener will be
169
     * notified about changes in this object.
170 6880 cesar
     *
171
     * @param listener
172
     */
173
    public void addPropertyChangeListener(PropertyChangeListener listener) {
174
        support.addPropertyChangeListener(listener);
175
    }
176
177
    /**
178 11992 cesar
     * Remove a PropertyChangeListener from the listener list. The listener will
179
     * not be notified anymore about changes in this object.
180 6880 cesar
     *
181
     * @param listener
182
     */
183
    public void removePropertyChangeListener(PropertyChangeListener listener) {
184
        support.removePropertyChangeListener(listener);
185
    }
186
187
    /**
188 11992 cesar
     * 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 25553 vcaballero
     *
198 11992 cesar
     * <p>Properties can be set together by using the binary OR operator
199
     * "<b>|</b>". For example:</p>
200 25553 vcaballero
     *
201
     * <p><code>WindowInfo wi = new WindowInfo(WindowInfo.MODELESSDIALOG
202 11992 cesar
     *   |WindowInfo.ICONIFIABLE|WindowInfo.RESIZABLE).</code></p>
203 25553 vcaballero
     *
204 11992 cesar
     * <p>The WindowInfo.MODELESSDIALOG and WindowInfo.MODALDIALOG properties
205 25553 vcaballero
     * cannot be set at the same time</p>
206 6880 cesar
     *
207 11992 cesar
     * @param code Bit-or of the window properties.
208 6880 cesar
     *
209 11992 cesar
     * @throws IllegalStateException If incompatible properties are set together,
210
     * for example, if MODALDIALOG and MODELESSDIALGO are set together.
211 6880 cesar
     */
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 29750 vcaballero
        code = code / 2;
225
        notclosable = (code % 2) > 0;
226 6880 cesar
227
        if (modal && modeless) {
228
            throw new IllegalStateException("modal && modeless");
229
        }
230
    }
231
232 11992 cesar
    /**
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 6880 cesar
    public WindowInfo(){
245
246
    }
247 25553 vcaballero
248 9963 cesar
    /**
249 11992 cesar
     * Returns the current x coordinate of the window's origin
250
     * (left-upper corner of the window).
251 9963 cesar
     *
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 6880 cesar
259
    /**
260 11992 cesar
     * Sets the x coordinate of the window's origin
261
     * (left-upper corner of the window).
262 9963 cesar
     *
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 25553 vcaballero
272 9963 cesar
    /**
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 25553 vcaballero
     *
277 9963 cesar
     * @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 11992 cesar
     * Gets the value of the y coordinate for the origin
287
     * (left-upper corner of the window) of the associated
288 9994 cesar
     * window.
289 25553 vcaballero
     *
290 9994 cesar
     * @return Returns the y coordinate (in pixels).
291 9963 cesar
     */
292
    public int getY() {
293
        return y;
294
    }
295
296
    /**
297 11992 cesar
     * Sets the value of the y coordinate for the origin
298
     * (left-upper corner of the window) of the associated
299 9994 cesar
     * window.
300 25553 vcaballero
     *
301 9994 cesar
     * @param y The value (in pixels) of the y coordinate
302 9963 cesar
     */
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 25553 vcaballero
310 9963 cesar
    /**
311 9994 cesar
     * Updates the value of the y coordinate for this WindowInfo
312 9963 cesar
     * object. It doesn't get reflected on the window (use
313
     * setY for that).
314 25553 vcaballero
     *
315 9963 cesar
     * @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 29750 vcaballero
     * Determines whether the associated window is closable or not
325
     *
326
     * @return
327
     */
328
    public boolean isNotClosable() {
329
        return notclosable;
330
    }
331
332
    /**
333 11992 cesar
     * Determines whether the associated window is iconifiable or not
334 6880 cesar
     *
335
     * @return
336
     */
337
    public boolean isIconifiable() {
338
        return iconifiable;
339
    }
340
341
    /**
342 11992 cesar
     * Determines whether the associated window is maximizable or not
343 6880 cesar
     *
344
     * @return
345
     */
346
    public boolean isMaximizable() {
347
        return maximizable;
348
    }
349
350
    /**
351 11992 cesar
     * Determines whether the associated window is resizable or not
352 6880 cesar
     *
353
     * @return
354
     */
355
    public boolean isResizable() {
356
        return resizable;
357
    }
358
359
    /**
360 11992 cesar
     * Determines whether the associated window is modal or not
361 6880 cesar
     *
362
     * @return
363
     */
364
    public boolean isModal() {
365
        return modal;
366
    }
367
368
    /**
369 9994 cesar
     * Gets the window height.
370 6880 cesar
     *
371 9994 cesar
     * @return The window height (in pixels).
372 6880 cesar
     */
373
    public int getHeight() {
374
        return height;
375
    }
376
377
    /**
378 9994 cesar
     * Gets the window width.
379 6880 cesar
     *
380 9994 cesar
     * @return The window width (in pixels).
381 6880 cesar
     */
382
    public int getWidth() {
383
        return width;
384
    }
385
386
    /**
387 9994 cesar
     * Sets the window height.
388 6880 cesar
     *
389 9994 cesar
     * @param The window height (in pixels)
390 6880 cesar
     */
391 9963 cesar
    public void setHeight(int height) {
392
            if (height!=-1)
393
                    support.firePropertyChange("height", this.height, height);
394
            this.height = height;
395 7447 cesar
        if (!isMaximized)
396 9963 cesar
                this.normalHeight = height;
397 6880 cesar
    }
398 25553 vcaballero
399 9963 cesar
    /**
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 25553 vcaballero
     *
404 9963 cesar
     * @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 6880 cesar
412
    /**
413 9963 cesar
     * Sets the width property for the associated Window.
414 6880 cesar
     *
415 9963 cesar
     * @param w The new width.
416 6880 cesar
     */
417 7447 cesar
    public void setWidth(int w) {
418 8374 cesar
            if (w!=-1)
419
                    support.firePropertyChange("width", this.width, w);
420 7447 cesar
        width = w;
421
        if (!isMaximized)
422 9963 cesar
                this.normalWidth = w;
423 6880 cesar
    }
424 25553 vcaballero
425 9963 cesar
    /**
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 25553 vcaballero
     *
430 9963 cesar
     * @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 6880 cesar
438
    /**
439 9963 cesar
     * Gets the title property
440 6880 cesar
     *
441
     * @return
442
     */
443
    public String getTitle() {
444
        return title;
445
    }
446
447
    /**
448 9963 cesar
     * Sets the title property.
449 6880 cesar
     *
450 9963 cesar
     * @param title The new title.
451 6880 cesar
     */
452 9963 cesar
    public void setTitle(String title) {
453
            support.firePropertyChange("title", this.title, title);
454
        this.title = title;
455 6880 cesar
    }
456 25553 vcaballero
457 9963 cesar
    /**
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 25553 vcaballero
     *
462 9963 cesar
     * @param title The title value for this WindowInfo object
463
     */
464
    public void updateTitle(String title) {
465
            this.title = title;
466
    }
467 6880 cesar
468
    /**
469 11992 cesar
     * Determines whether the associated window is modeless
470
     * (it is on the top but does not block any other window)
471 6880 cesar
     *
472
     * @return
473
     */
474
    public boolean isModeless() {
475
        return modeless;
476
    }
477
478 11992 cesar
     /**
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 6880 cesar
    public boolean isVisible() {
485
        return visible;
486
    }
487
488 11992 cesar
    /**
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 6880 cesar
    public boolean isPalette()
496
    {
497
        return palette;
498
    }
499
500 11992 cesar
    /**
501
     * Sets the window's ID.
502 25553 vcaballero
     *
503 11992 cesar
     * @param id An integer to identify the window. Different
504
     * windows must have different IDs.
505
     */
506 6880 cesar
    public void setId(int id){
507
            this.id = id;
508
    }
509
510 11992 cesar
    /**
511
     * Gets the window ID.
512 25553 vcaballero
     *
513 11992 cesar
     * @return id An integer to identify the window. Different
514
     * windows must have different IDs.
515
     */
516 6880 cesar
    public int getId(){
517
            return id;
518
    }
519
520 11992 cesar
    /**
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 25553 vcaballero
     *
526 11992 cesar
     * @param vi A WindowInfo object containing the new
527
     * properties of the window.
528
     */
529 6880 cesar
    public void setWindowInfo(WindowInfo vi){
530
            this.resizable = vi.resizable;
531
            this.maximizable = vi.maximizable;
532 8321 cesar
            this.isMaximized = vi.isMaximized;
533 6880 cesar
            this.iconifiable = vi.iconifiable;
534 12224 nacho
            this.additionalInfo = vi.additionalInfo;
535 6880 cesar
            this.modal = vi.modal;
536
            this.modeless = vi.modeless;
537 29750 vcaballero
            this.notclosable = vi.notclosable;
538 8374 cesar
            if (vi.width!=-1)
539
                    this.width = vi.width;
540
            if (vi.height!=-1)
541
                    this.height = vi.height;
542 6880 cesar
            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 8374 cesar
            if (vi.normalHeight!=-1)
548
                    this.normalHeight = vi.normalHeight;
549
            if (vi.normalWidth!=-1)
550
                    this.normalWidth = vi.normalWidth;
551 7447 cesar
            this.normalX = vi.normalX;
552
            this.normalY = vi.normalY;
553
            this.isClosed = vi.isClosed;
554
            this.persistWindow = vi.persistWindow;
555 6880 cesar
    }
556 25553 vcaballero
557 11992 cesar
    /**
558 25553 vcaballero
     * Sets whether the window is in palette mode or is in docked mode.
559 11992 cesar
     * 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 25553 vcaballero
     *
563 11992 cesar
     * @param b
564
     */
565 6880 cesar
    public void toPalette(boolean b){
566
            this.palette=b;
567
    }
568
569 11992 cesar
    /**
570
     * Gets the list of selected tools for this window.
571 25553 vcaballero
     *
572 11992 cesar
     * @return A HashMap containing pairs (group, actionCommand), which
573 25553 vcaballero
     * are the selected tools for this window.
574 11992 cesar
     */
575 10650 cesar
    public HashMap getSelectedTools() {
576 10643 cesar
        return selectedTools;
577 6880 cesar
    }
578
579 10643 cesar
    /**
580 25553 vcaballero
     * Use {@link setSelectedTools(HashMap selectedTool)}
581
     *
582 10643 cesar
     * @param selectedTool
583
     * @deprecated
584
     */
585 6880 cesar
    public void setSelectedTool(String selectedTool) {
586
        if (selectedTool != null)
587 10643 cesar
            selectedTools.put(defaultGroup ,selectedTool);
588 6880 cesar
    }
589 25553 vcaballero
590 11992 cesar
    /**
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 25553 vcaballero
     * for this window.
596 11992 cesar
     */
597 10643 cesar
    public void setSelectedTools(HashMap selectedTools) {
598
        if (selectedTools != null)
599
            this.selectedTools = selectedTools;
600
    }
601 6880 cesar
602 9994 cesar
    /** Finds out whether a view is open (showing) or closed */
603 6880 cesar
    public boolean isClosed() {
604
            return isClosed;
605
    }
606
607 9994 cesar
    /** Specifies whether a view is open (showing) or closed */
608 6880 cesar
    public void setClosed(boolean closed) {
609 7447 cesar
            support.firePropertyChange("closed", this.isClosed, closed);
610 6880 cesar
            this.isClosed = closed;
611
    }
612
613 9963 cesar
    /**
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 25553 vcaballero
     *
618 9963 cesar
     * @param closed The new closed property for this WindowInfo object
619
     */
620
    public void updateClosed(boolean closed) {
621
            this.isClosed = closed;
622
    }
623 25553 vcaballero
624 9963 cesar
    /**
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 25553 vcaballero
     *
629 9963 cesar
     * @param normalX The new normalX property for this WindowInfo object
630
     */
631 6880 cesar
    public void setNormalX(int normalX) {
632 9963 cesar
            if (!isMaximized()) {
633
                    setX(normalX);
634
            }
635
            else {
636
                    support.firePropertyChange("normalX", this.normalX, normalX);
637
                    this.normalX = normalX;
638
            }
639
    }
640 25553 vcaballero
641 9963 cesar
    /**
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 25553 vcaballero
     *
646 9963 cesar
     * @param normalX The new normalX property for this WindowInfo object
647
     */
648
    public void updateNormalX(int normalX) {
649 6880 cesar
            this.normalX = normalX;
650 9963 cesar
            if (!isMaximized())
651
                    x = normalX;
652 6880 cesar
    }
653
654 9963 cesar
    /**
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 25553 vcaballero
     *
659 9963 cesar
     * @param normalY The new normalY property for this WindowInfo object
660
     */
661 6880 cesar
    public void setNormalY(int normalY) {
662 9963 cesar
            if (!isMaximized()) {
663
                    setY(normalY);
664
            }
665
            else {
666
                    support.firePropertyChange("normalY", this.normalY, normalY);
667
                    this.normalY = normalY;
668
            }
669
    }
670 25553 vcaballero
671 9963 cesar
    /**
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 25553 vcaballero
     *
676 9963 cesar
     * @param normalY The new normalY property for this WindowInfo object
677
     */
678
    public void updateNormalY(int normalY) {
679 6880 cesar
            this.normalY = normalY;
680 9963 cesar
            if (!isMaximized())
681
                    y = normalY;
682 6880 cesar
    }
683
684 9963 cesar
    /**
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 25553 vcaballero
     *
689 9963 cesar
     * @param normalY The new normalHeight property for this WindowInfo object
690
     */
691 6880 cesar
    public void setNormalHeight(int normalHeight) {
692 9963 cesar
            if (!isMaximized) {
693
                    setHeight(normalHeight);
694
            }
695
            else {
696
                    support.firePropertyChange("normalHeight", this.normalHeight, normalHeight);
697
                    this.normalHeight = normalHeight;
698
            }
699
    }
700 25553 vcaballero
701 9963 cesar
    /**
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 25553 vcaballero
     *
706 9963 cesar
     * @param normalHeight The new normalHeight property for this WindowInfo object
707
     */
708
    public void updateNormalHeight(int normalHeight) {
709 6880 cesar
            this.normalHeight = normalHeight;
710 9963 cesar
            if (!isMaximized) {
711
                    this.height = normalHeight;
712
            }
713 6880 cesar
    }
714
715 9963 cesar
    /**
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 25553 vcaballero
     *
720 9963 cesar
     * @param normalY The new normalWidth property for this WindowInfo object
721
     */
722 6880 cesar
    public void setNormalWidth(int normalWidth) {
723 9963 cesar
            if (!isMaximized()) {
724
                    setWidth(normalWidth);
725
            }
726
            else {
727
                    support.firePropertyChange("normalWidth", this.normalWidth, normalWidth);
728
                    this.normalWidth = normalWidth;
729
            }
730
    }
731 25553 vcaballero
732 9994 cesar
    /**
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 25553 vcaballero
     *
737 9994 cesar
     * @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 9963 cesar
744
    /**
745 9994 cesar
     * 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 25553 vcaballero
     *
748 9994 cesar
     * @param minSize The minimum allowed size for the associated window.
749
     */
750
    public void updateMinimumSize(Dimension minSize) {
751
            this.minSize = minSize;
752
    }
753 25553 vcaballero
754 9994 cesar
    /**
755
     * Gets the minimum allowed size for the associated window.
756 25553 vcaballero
     *
757 9994 cesar
     * @return minSize The minimum allowed size for the associated window.
758
     */
759
    public Dimension getMinimumSize() {
760
            return minSize;
761
    }
762 25553 vcaballero
763 9994 cesar
    /**
764 9963 cesar
     * 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 25553 vcaballero
     *
768 9963 cesar
     * @param normalWidth The new normalHeight property for this WindowInfo object
769
     */
770
    public void updateNormalWidth(int normalWidth) {
771 6880 cesar
            this.normalWidth = normalWidth;
772 9963 cesar
            if (!isMaximized())
773
                    this.width = normalWidth;
774 6880 cesar
    }
775
776 9963 cesar
    /**
777
     * Maximize the associated window
778 25553 vcaballero
     *
779 9963 cesar
     * @param maximized
780
     */
781 6880 cesar
    public void setMaximized(boolean maximized) {
782 7447 cesar
            support.firePropertyChange("maximized", this.isMaximized, maximized);
783 6880 cesar
            this.isMaximized = maximized;
784
    }
785 25553 vcaballero
786 9963 cesar
    /**
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 25553 vcaballero
     *
791 9963 cesar
     * @param maximized The new maximized property for this WindowInfo object
792
     */
793
    public void updateMaximized(boolean maximized) {
794
            this.isMaximized = maximized;
795
    }
796 9750 jaume
797 7397 maquerol
    public void setMaximizable(boolean maximizable) {
798
            this.maximizable = maximizable;
799
    }
800 6880 cesar
801 9994 cesar
    /**
802
     * Sets the bounds of the associated window.
803 25553 vcaballero
     *
804 9994 cesar
     * @param x
805
     * @param y
806
     * @param width
807
     * @param height
808
     */
809 6880 cesar
    private void setBounds(int x, int y, int width, int height) {
810 9963 cesar
            setX(x);
811
            setY(y);
812
            setWidth(width);
813
            setHeight(height);
814
    }
815 25553 vcaballero
816 9963 cesar
    /**
817
     * Updates the bounds for this WindowInfo object. It doesn't get reflected
818 9994 cesar
     * on the window (use <code>setBounds</code> for that).
819 25553 vcaballero
     *
820 9963 cesar
     * @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 6880 cesar
            this.x = x;
827
            this.y = y;
828
            this.width = width;
829
            this.height = height;
830 9963 cesar
            if (!isMaximized()) {
831
                    this.normalX = x;
832
                    this.normalY = y;
833
                    this.normalWidth = width;
834
                    this.normalHeight = height;
835
            }
836 6880 cesar
    }
837
838 9994 cesar
    /**
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 25553 vcaballero
     *
843 9994 cesar
     * @param x
844
     * @param y
845
     * @param width
846
     * @param height
847
     */
848 6880 cesar
    public void setNormalBounds(int x, int y, int width, int height) {
849 9963 cesar
            setNormalX(x);
850
            setNormalY(y);
851
            setNormalWidth(width);
852
            setNormalHeight(height);
853 6880 cesar
    }
854 25553 vcaballero
855 9963 cesar
    /**
856
     * Updates the normal bounds for this WindowInfo object. It doesn't get
857 9994 cesar
     * reflected on the window (use <code>setNormalBounds</code> for that).
858 25553 vcaballero
     *
859 9963 cesar
     * @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 6880 cesar
877 9994 cesar
    /**
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 25553 vcaballero
     *
882 9994 cesar
     * @return The normal bounds of the associated window.
883
     */
884 6880 cesar
    public Rectangle getNormalBounds() {
885
            return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight());
886
    }
887
888 9994 cesar
    /**
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 25553 vcaballero
     *
893 9994 cesar
     * @param normalBounds
894
     */
895 6880 cesar
    public void setNormalBounds(Rectangle normalBounds) {
896 9963 cesar
            setNormalBounds(normalBounds.x, normalBounds.y, normalBounds.width, normalBounds.height);
897 6880 cesar
    }
898 25553 vcaballero
899 9994 cesar
    /**
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 25553 vcaballero
     *
903 9994 cesar
     * @param normalBounds
904
     */
905 9963 cesar
    public void updateNormalBounds(Rectangle normalBounds) {
906
            updateNormalBounds(normalBounds.x, normalBounds.y, normalBounds.width, normalBounds.height);
907
    }
908 25553 vcaballero
909 9994 cesar
    /**
910
     * Sets the bounds of the associated window.
911 25553 vcaballero
     *
912 9994 cesar
     * @param bounds
913
     */
914 6880 cesar
    public void setBounds(Rectangle bounds) {
915 9963 cesar
            setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
916 6880 cesar
    }
917 25553 vcaballero
918 9994 cesar
    /**
919
     * Updates the bounds for this WindowInfo object. It doesn't get reflected
920
     * on the window (use <code>setBounds</code> for that).
921 25553 vcaballero
     *
922 9994 cesar
     * @param bounds
923
     */
924 9963 cesar
    public void updateBounds(Rectangle bounds) {
925
            updateBounds(bounds.x, bounds.y, bounds.width, bounds.height);
926
    }
927 6880 cesar
928 9994 cesar
    /**
929
     * Gets the bounds of the associated window.
930 25553 vcaballero
     *
931 9994 cesar
     * @return The bounds of the associated window.
932
     */
933 6880 cesar
    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 11992 cesar
    /**
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 25553 vcaballero
     *
949 11992 cesar
     * @return the normal y coordinate of the window's origin
950
     */
951 6880 cesar
    public int getNormalY() {
952
            if (normalY!=0)
953
                    return this.normalY;
954
            else
955
                    return y;
956
    }
957
958 11992 cesar
    /**
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 25553 vcaballero
     *
963 11992 cesar
     * @return the normal height of the window
964
     */
965 6880 cesar
    public int getNormalHeight() {
966
            if (normalHeight!=0)
967
                    return this.normalHeight;
968
            else
969
                    return height;
970
    }
971
972 11992 cesar
    /**
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 25553 vcaballero
     *
977 11992 cesar
     * @return the normal width of the window
978
     */
979 6880 cesar
    public int getNormalWidth() {
980
            if (normalWidth!=0)
981
                    return this.normalWidth;
982
            else
983
                    return width;
984
    }
985
986 11992 cesar
    /**
987
     * Determines whether the window is maximized or not
988 25553 vcaballero
     *
989 11992 cesar
     * @return true if the window is maximized, false otherwise
990
     */
991 6880 cesar
    public boolean isMaximized() {
992
            return this.isMaximized;
993
    }
994 9750 jaume
995 7447 cesar
    /**
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 9750 jaume
     *
1000 7447 cesar
     * @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 9750 jaume
1007 7447 cesar
    /**
1008
     * Set whether the geometry of this window should be persisted in the
1009
     * project files.
1010 9750 jaume
     *
1011 7447 cesar
     * @param persist
1012
     */
1013
    public void setPersistence(boolean persist) {
1014
            this.persistWindow = persist;
1015
    }
1016 9750 jaume
1017 7447 cesar
    /**
1018
         * Gets the window properties in an XMLEntity object, suitable
1019
         * for persistence.
1020
         *
1021 11992 cesar
         * @return An XMLEntity object containing the window properties,
1022
         * or null if the window was set as not persistent
1023 7447 cesar
     * @throws SaveException
1024
         * @throws XMLException
1025
         */
1026
        public XMLEntity getXMLEntity() {
1027 11992 cesar
                if (checkPersistence()==false) {
1028
                        return null;
1029
                }
1030 7447 cesar
                XMLEntity xml = new XMLEntity();
1031
                xml.setName("ViewInfoProperties");
1032 10621 cesar
                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 29750 vcaballero
                xml.putProperty("isNotClosable", this.isNotClosable(), false);
1043 25553 vcaballero
                xml.putProperty("AdditionalInfo", this.getAdditionalInfo(), false);
1044 7447 cesar
                if (this.isMaximized()==true) {
1045 10621 cesar
                        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 7447 cesar
                }
1051
                return xml;
1052
        }
1053 9750 jaume
1054 11992 cesar
        /**
1055
         * Creates a WindowInfo object from an XMLEntity containing the
1056
         * window properties.
1057 25553 vcaballero
         *
1058 11992 cesar
         * @param xml An XMLEntity object containing the window properties
1059 25553 vcaballero
         *
1060 11992 cesar
         * @return A new WindowInfo object, containing the properties
1061 25553 vcaballero
         * specified in the XMLEntity parameters
1062 11992 cesar
         */
1063 7447 cesar
        public static WindowInfo createFromXMLEntity(XMLEntity xml)
1064
        {
1065
                WindowInfo result = new WindowInfo();
1066 9655 cesar
                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 29750 vcaballero
                        result.setNotClosable(xml.getBooleanProperty("isNotClosable"));
1073 12224 nacho
                        result.setAdditionalInfo(xml.getStringProperty("AdditionalInfo"));
1074 9655 cesar
                        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 7447 cesar
                        }
1084
                }
1085 9655 cesar
                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 7447 cesar
1089
                return result;
1090
        }
1091 9750 jaume
1092 29750 vcaballero
        public void setNotClosable(boolean b) {
1093
                notclosable=b;
1094
        }
1095
1096 11992 cesar
        /**
1097
         * Updates this WindowInfo object according to the properties
1098
         * provided by the XMLEntity parameter.
1099 25553 vcaballero
         *
1100 11992 cesar
         * @param xml An XMLEntity object containing the window properties
1101
         */
1102 7447 cesar
        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 29750 vcaballero
                this.notclosable = xml.getBooleanProperty("isNotClosable");
1110 12224 nacho
                this.additionalInfo = xml.getStringProperty("AdditionalInfo");
1111 7447 cesar
                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 12224 nacho
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 6880 cesar
}