Statistics
| Revision:

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

History | View | Annotate | Download (15.7 KB)

1 6880 cesar
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.andami.ui.mdiManager;
42
43
import java.awt.Rectangle;
44
import java.beans.PropertyChangeListener;
45
import java.beans.PropertyChangeSupport;
46
47 7345 cesar
import com.iver.andami.PluginServices;
48
import com.iver.utiles.XMLEntity;
49 6880 cesar
50 7345 cesar
51 6880 cesar
/**
52
 * DOCUMENT ME!
53
 *
54
 * @author Fernando Gonz?lez Cort?s
55
 */
56
public class WindowInfo {
57
    /** DOCUMENT ME! */
58
    public static final int RESIZABLE = 1;
59
60
    /** DOCUMENT ME! */
61
    public static final int MAXIMIZABLE = 2;
62
63
    /** DOCUMENT ME! */
64
    public static final int ICONIFIABLE = 4;
65
66
    /** DOCUMENT ME! */
67
    public static final int MODALDIALOG = 8;
68
    public static final int MODELESSDIALOG = 16;
69
    public static final int PALETTE = 32;
70
    private PropertyChangeSupport support = new PropertyChangeSupport(this);
71
72
    /** DOCUMENT ME! */
73
    private boolean resizable = false;
74
75
    /** DOCUMENT ME! */
76
    private boolean maximizable = false;
77
78
    /** DOCUMENT ME! */
79
    private boolean iconifiable = false;
80
81
    /** DOCUMENT ME! */
82
    private boolean modal = false;
83
    private boolean modeless = false;
84 7345 cesar
85
    /**
86
     * Do we want to persist the geometry of this window in the project file?
87
     */
88
    private boolean persistWindow = true;
89 6880 cesar
90
    /**
91
     * Se usa para poner una ventana de tipo paleta, por
92
     * encima de las dem?s. Equivale a poner usar
93
     * JDesktopPane.PALETTE_LAYER
94
     */
95
    private boolean palette = false;
96
97
    /** These properties store the dimension and position of the frame */
98
    private int width = -1;
99
    private int height = -1;
100 10715 jcampos
    private int x = -1;
101
    private int y = -1;
102 6880 cesar
    /**
103
     * These properties store the position and dimension of the frame when it is not maximized
104
     * (so that it can be restored to its original size). They are equal to the not-normal properties
105
     * when the frame is not maximized, and different when the frame is maximized.
106
     */
107
    private int normalX = 0;
108
    private int normalY = 0;
109 8765 jjdelcerro
    private int normalHeight = -1;
110
    private int normalWidth = -1;
111 6880 cesar
    /* Whether the window is maximized */
112
    private boolean isMaximized = false;
113
    private boolean visible = true;
114
    /* Whether the window is closed */
115
    private boolean isClosed = false;
116
117
118
    /** DOCUMENT ME! */
119
    private String title;
120
121
    private int id;
122
123
    /**
124
     * ActionCommand del tool seleccionado. Lo usamos
125
     * para activar el tool que estaba seleccionado en
126
     * la vista, cuando volvemos a ella.
127
     */
128
    private String selectedTool;
129
130
    /**
131
     * DOCUMENT ME!
132
     *
133
     * @return Returns the x.
134
     */
135
    public int getX() {
136
        return x;
137
    }
138
139
    /**
140
     * DOCUMENT ME!
141
     *
142
     * @param x The x to set.
143
     */
144
    public void setX(int x) {
145
            support.firePropertyChange("x", this.x, x);
146
            this.x = x;
147 7345 cesar
            if (!isMaximized)
148
                    this.normalX = x;
149 6880 cesar
    }
150
151
    /**
152
     * DOCUMENT ME!
153
     *
154
     * @return Returns the y.
155
     */
156
    public int getY() {
157
        return y;
158
    }
159
160
    /**
161
     * DOCUMENT ME!
162
     *
163
     * @param y The y to set.
164
     */
165
    public void setY(int y) {
166
            support.firePropertyChange("y", this.y, y);
167
        this.y = y;
168 7345 cesar
        if (!isMaximized)
169
                this.normalY = y;
170 6880 cesar
    }
171
172
    /**
173
     * DOCUMENT ME!
174
     *
175
     * @param listener
176
     */
177
    public void addPropertyChangeListener(PropertyChangeListener listener) {
178
        support.addPropertyChangeListener(listener);
179
    }
180
181
    /**
182
     * DOCUMENT ME!
183
     *
184
     * @param listener
185
     */
186
    public void removePropertyChangeListener(PropertyChangeListener listener) {
187
        support.removePropertyChangeListener(listener);
188
    }
189
190
    /**
191
     * Establece las propiedades de la vista
192
     *
193
     * @param code Bit-or de las propiedades de la vista
194
     *
195
     * @throws IllegalStateException DOCUMENT ME!
196
     */
197
    public WindowInfo(int code) {
198
        resizable = (code % 2) > 0;
199
        code = code / 2;
200
        maximizable = (code % 2) > 0;
201
        code = code / 2;
202
        iconifiable = (code % 2) > 0;
203
        code = code / 2;
204
        modal = (code % 2) > 0;
205
        code = code / 2;
206
        modeless = (code % 2) > 0;
207
        code = code / 2;
208
        palette = (code % 2) > 0;
209
210
        if (modal && modeless) {
211
            throw new IllegalStateException("modal && modeless");
212
        }
213
    }
214
215
    public WindowInfo(){
216
217
    }
218
219
    /**
220
     * Si es iconificable
221
     *
222
     * @return
223
     */
224
    public boolean isIconifiable() {
225
        return iconifiable;
226
    }
227
228
    /**
229
     * Si es maximizable
230
     *
231
     * @return
232
     */
233
    public boolean isMaximizable() {
234
        return maximizable;
235
    }
236
237
    /**
238
     * Si es resizable
239
     *
240
     * @return
241
     */
242
    public boolean isResizable() {
243
        return resizable;
244
    }
245
246
    /**
247
     * Devuelve si el di?logo es modal
248
     *
249
     * @return
250
     */
251
    public boolean isModal() {
252
        return modal;
253
    }
254
255
    /**
256
     * Obtiene la altura de la vista
257
     *
258
     * @return
259
     */
260
    public int getHeight() {
261
        return height;
262
    }
263
264
    /**
265
     * Obtiene la anchura de la vista
266
     *
267
     * @return
268
     */
269
    public int getWidth() {
270
        return width;
271
    }
272
273
    /**
274
     * establece la propiedad altura
275
     *
276 7345 cesar
     * @param h
277 6880 cesar
     */
278 7345 cesar
    public void setHeight(int h) {
279 8765 jjdelcerro
            if (h!=-1)
280
                    support.firePropertyChange("height", this.height, h);
281
            height = h;
282 7345 cesar
        if (!isMaximized)
283
                this.normalHeight = h;
284 6880 cesar
    }
285
286
    /**
287
     * establece la propiedad anchura
288
     *
289
     * @param i
290
     */
291 7345 cesar
    public void setWidth(int w) {
292 8765 jjdelcerro
            if (w!=-1)
293
                    support.firePropertyChange("width", this.width, w);
294 7345 cesar
        width = w;
295
        if (!isMaximized)
296
                this.width = w;
297 6880 cesar
    }
298
299
    /**
300
     * obtiene la propiedad titulo
301
     *
302
     * @return
303
     */
304
    public String getTitle() {
305
        return title;
306
    }
307
308
    /**
309
     * establece la propiedad titulo
310
     *
311
     * @param string
312
     */
313
    public void setTitle(String string) {
314
            support.firePropertyChange("title", this.title, string);
315
        title = string;
316
    }
317
318
    /**
319
     * DOCUMENT ME!
320
     *
321
     * @return
322
     */
323
    public boolean isModeless() {
324
        return modeless;
325
    }
326
327
    /**
328
     * DOCUMENT ME!
329
     *
330
     * @return
331
     */
332
    public boolean isVisible() {
333
        return visible;
334
    }
335
336
    public boolean isPalette()
337
    {
338
        return palette;
339
    }
340
341
    public void setId(int id){
342
            this.id = id;
343
    }
344
345
    public int getId(){
346
            return id;
347
    }
348
349
    public void setWindowInfo(WindowInfo vi){
350
            this.resizable = vi.resizable;
351
            this.maximizable = vi.maximizable;
352 8765 jjdelcerro
            this.isMaximized = vi.isMaximized;
353 6880 cesar
            this.iconifiable = vi.iconifiable;
354
            this.modal = vi.modal;
355
            this.modeless = vi.modeless;
356 8765 jjdelcerro
            if (vi.width!=-1)
357
                    this.width = vi.width;
358
            if (vi.height!=-1)
359
                    this.height = vi.height;
360 6880 cesar
            this.x = vi.x;
361
            this.y = vi.y;
362
            this.visible = vi.visible;
363
            this.title = vi.title;
364
            this.id = vi.id;
365 8765 jjdelcerro
            if (vi.normalHeight!=-1)
366
                    this.normalHeight = vi.normalHeight;
367
            if (vi.normalWidth!=-1)
368
                    this.normalWidth = vi.normalWidth;
369 7345 cesar
            this.normalX = vi.normalX;
370
            this.normalY = vi.normalY;
371
            this.isClosed = vi.isClosed;
372
            this.persistWindow = vi.persistWindow;
373 6880 cesar
    }
374
    public void toPalette(boolean b){
375
            this.palette=b;
376
    }
377
378
    public String getSelectedTool() {
379
        return selectedTool;
380
    }
381
382
    public void setSelectedTool(String selectedTool) {
383
        if (selectedTool != null)
384
            this.selectedTool = selectedTool;
385
    }
386
387
    /* Finds out whether a view is open (showing) or closed */
388
    public boolean isClosed() {
389
            return isClosed;
390
    }
391
392
    /* Specifies whether a view is open (showing) or closed */
393
    public void setClosed(boolean closed) {
394 7345 cesar
            support.firePropertyChange("closed", this.isClosed, closed);
395 6880 cesar
            this.isClosed = closed;
396
    }
397
398
    public void setNormalX(int normalX) {
399 7345 cesar
            support.firePropertyChange("normalX", this.normalX, normalX);
400 6880 cesar
            this.normalX = normalX;
401
    }
402
403
    public void setNormalY(int normalY) {
404 7345 cesar
            support.firePropertyChange("normalY", this.normalY, normalY);
405 6880 cesar
            this.normalY = normalY;
406
    }
407
408
    public void setNormalHeight(int normalHeight) {
409 7345 cesar
            support.firePropertyChange("normalHeight", this.normalHeight, normalHeight);
410 6880 cesar
            this.normalHeight = normalHeight;
411
    }
412
413
    public void setNormalWidth(int normalWidth) {
414 7345 cesar
            support.firePropertyChange("normalWidth", this.normalWidth, normalWidth);
415 6880 cesar
            this.normalWidth = normalWidth;
416
    }
417
418
419
    public void setMaximized(boolean maximized) {
420 7345 cesar
            support.firePropertyChange("maximized", this.isMaximized, maximized);
421 6880 cesar
            this.isMaximized = maximized;
422
    }
423 7516 jorpiell
424
    public void setMaximizable(boolean maximizable) {
425
            this.maximizable = maximizable;
426
    }
427 6880 cesar
428
    private void setBounds(int x, int y, int width, int height) {
429 7345 cesar
            support.firePropertyChange("x", this.height, x);
430 6880 cesar
            this.x = x;
431 7345 cesar
            support.firePropertyChange("y", this.height, y);
432 6880 cesar
            this.y = y;
433 7345 cesar
            support.firePropertyChange("width", this.width, width);
434 6880 cesar
            this.width = width;
435 7345 cesar
            support.firePropertyChange("height", this.height, height);
436 6880 cesar
            this.height = height;
437
    }
438
439
    public void setNormalBounds(int x, int y, int width, int height) {
440 7345 cesar
            support.firePropertyChange("normalX", this.normalX, x);
441 6880 cesar
            this.normalX = x;
442 7345 cesar
            support.firePropertyChange("normalY", this.normalY, y);
443 6880 cesar
            this.normalY = y;
444 8765 jjdelcerro
            support.firePropertyChange("normalWidth", this.normalWidth, width);
445 6880 cesar
            this.normalWidth = width;
446 8765 jjdelcerro
            support.firePropertyChange("normalWeight", this.normalHeight, height);
447 6880 cesar
            this.normalHeight = height;
448
    }
449
450
    public Rectangle getNormalBounds() {
451
            return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight());
452
    }
453
454
    public void setNormalBounds(Rectangle normalBounds) {
455 8765 jjdelcerro
            Rectangle oldBounds = new Rectangle(this.normalX, this.normalY,
456
                            this.normalWidth, this.normalHeight);
457
            support.firePropertyChange("normalBounds", oldBounds, normalBounds);
458 7345 cesar
            support.firePropertyChange("normalX", this.normalX, normalBounds.x);
459 6880 cesar
            normalX = normalBounds.x;
460 7345 cesar
            support.firePropertyChange("normalY", this.normalY, normalBounds.y);
461 6880 cesar
            normalY = normalBounds.y;
462 7345 cesar
            support.firePropertyChange("normalHeight", this.normalHeight, normalBounds.height);
463 6880 cesar
            normalHeight = normalBounds.height;
464 7345 cesar
            support.firePropertyChange("normalWidth", this.normalWidth, normalBounds.width);
465 6880 cesar
            normalWidth = normalBounds.width;
466
    }
467
468
    public void setBounds(Rectangle bounds) {
469 7345 cesar
            support.firePropertyChange("x", this.x, bounds.x);
470 6880 cesar
            x = bounds.x;
471 7345 cesar
            support.firePropertyChange("y", this.y, bounds.y);
472 6880 cesar
            y = bounds.y;
473 7345 cesar
            support.firePropertyChange("height", this.height, bounds.height);
474 6880 cesar
            height = bounds.height;
475 7345 cesar
            support.firePropertyChange("width", this.width, bounds.width);
476 6880 cesar
            width = bounds.width;
477
    }
478
479
    public Rectangle getBounds() {
480
            return new Rectangle(x, y, width, height);
481
    }
482
483
    public int getNormalX() {
484
            if (normalX!=0)
485
                    return this.normalX;
486
            else
487
                    return x;
488
    }
489
490
    public int getNormalY() {
491
            if (normalY!=0)
492
                    return this.normalY;
493
            else
494
                    return y;
495
    }
496
497
    public int getNormalHeight() {
498
            if (normalHeight!=0)
499
                    return this.normalHeight;
500
            else
501
                    return height;
502
    }
503
504
    public int getNormalWidth() {
505
            if (normalWidth!=0)
506
                    return this.normalWidth;
507
            else
508
                    return width;
509
    }
510
511
    public boolean isMaximized() {
512
            return this.isMaximized;
513
    }
514 7345 cesar
515
    /**
516
     * Checks if the geometry of this window should be persisted in the
517
     * project file. This is set by the persistWindow(boolean) method,
518
     * and the default value is true.
519
     *
520
     * @return True if the geometry of this window should be persisted
521
     * in the project files, false otherwise.
522
     */
523
    public boolean checkPersistence() {
524
            return this.persistWindow;
525
    }
526
527
    /**
528
     * Set whether the geometry of this window should be persisted in the
529
     * project files.
530
     *
531
     * @param persist
532
     */
533
    public void setPersistence(boolean persist) {
534
            this.persistWindow = persist;
535
    }
536
537
    /**
538
         * Gets the window properties in an XMLEntity object, suitable
539
         * for persistence.
540
         *
541
         * @return An XMLEntity object containing the window properties, or null if the window was set as
542
         * not persistent
543
     * @throws SaveException
544
         * @throws XMLException
545
         * @throws SaveException
546
         */
547
        public XMLEntity getXMLEntity() {
548
                XMLEntity xml = new XMLEntity();
549
                xml.setName("ViewInfoProperties");
550
                xml.putProperty("X", this.getX());
551
                xml.putProperty("Y", this.getY());
552
                xml.putProperty("Width", this.getWidth());
553
                xml.putProperty("Height", this.getHeight());
554
                xml.putProperty("isVisible", this.isVisible());
555
                xml.putProperty("isResizable", this.isResizable());
556
                xml.putProperty("isMaximizable", this.isMaximizable());
557
                xml.putProperty("isModal", this.isModal());
558
                xml.putProperty("isModeless", this.isModeless());
559
                xml.putProperty("isClosed", this.isClosed());
560
                if (this.isMaximized()==true) {
561
                        xml.putProperty("isMaximized", this.isMaximized());
562
                        xml.putProperty("normalX", this.getNormalX());
563
                        xml.putProperty("normalY", this.getNormalY());
564
                        xml.putProperty("normalWidth", this.getNormalWidth());
565
                        xml.putProperty("normalHeight", this.getNormalHeight());
566
                }
567
                return xml;
568
        }
569
570
571
        public static WindowInfo createFromXMLEntity(XMLEntity xml)
572
        {
573
                WindowInfo result = new WindowInfo();
574 9655 cesar
                try {
575
                        result.setX(xml.getIntProperty("X"));
576
                        result.setY(xml.getIntProperty("Y"));
577
                        result.setHeight(xml.getIntProperty("Height"));
578
                        result.setWidth(xml.getIntProperty("Width"));
579
                        result.setClosed(xml.getBooleanProperty("isClosed"));
580
                        if (xml.contains("isMaximized")) {
581
                                boolean maximized = xml.getBooleanProperty("isMaximized");
582
                                result.setMaximized(maximized);
583
                                if (maximized==true) {
584
                                        result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
585
                                }
586
                                else {
587
                                        result.setNormalBounds(result.getBounds());
588
                                }
589 7345 cesar
                        }
590
                }
591 9655 cesar
                catch (com.iver.utiles.NotExistInXMLEntity ex) {
592
                        PluginServices.getLogger().warn(PluginServices.getText(null, "Window_properties_not_stored_correctly_Window_state_will_not_be_restored"));
593
                }
594 7345 cesar
595
                return result;
596
        }
597
598
        public void getPropertiesFromXMLEntity(XMLEntity xml)
599
        {
600
                this.x = xml.getIntProperty("X");
601
                this.y = xml.getIntProperty("Y");
602
                this.height = xml.getIntProperty("Height");
603
                this.width = xml.getIntProperty("Width");
604
                this.isClosed = xml.getBooleanProperty("isClosed");
605
                if (xml.contains("isMaximized")) {
606
                        boolean maximized = xml.getBooleanProperty("isMaximized");
607
                        this.isMaximized = maximized;
608
                        if (maximized==true) {
609
                                this.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
610
                        }
611
                }
612
        }
613 6880 cesar
}