Statistics
| Revision:

svn-gvsig-desktop / trunk / frameworks / _fwAndami / src / com / iver / andami / ui / mdiManager / WindowInfo.java @ 9655

History | View | Annotate | Download (15.9 KB)

1
/* 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
import com.iver.andami.PluginServices;
48
import com.iver.utiles.XMLEntity;
49

    
50

    
51
/**
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
    
85
    /**
86
     * Do we want to persist the geometry of this window in the project file?
87
     */
88
    private boolean persistWindow = true;
89

    
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
    private int x = 0;
101
    private int y = 0;
102
    /**
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
    private int normalHeight = -1;
110
    private int normalWidth = -1;
111
    /* 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
     * Returns the current x coordinate of the window's origin.
132
     *
133
     * @return Returns the value (in pixels) of the x coordinate
134
     * of the window's origin.
135
     */
136
    public int getX() {
137
        return x;
138
    }
139

    
140
    /**
141
     * Sets the x coordinate of the window's origin.
142
     *
143
     * @param x        The value (in pixels) of the x coordinate to set.
144
     */
145
    public void setX(int x) {
146
            support.firePropertyChange("x", this.x, x);
147
            this.x = x;
148
            if (!isMaximized)
149
                    this.normalX = x;
150
    }
151

    
152
    /**
153
     * DOCUMENT ME!
154
     *
155
     * @return Returns the y.
156
     */
157
    public int getY() {
158
        return y;
159
    }
160

    
161
    /**
162
     * DOCUMENT ME!
163
     *
164
     * @param y The y to set.
165
     */
166
    public void setY(int y) {
167
            support.firePropertyChange("y", this.y, y);
168
        this.y = y;
169
        if (!isMaximized)
170
                this.normalY = y;
171
    }
172

    
173
    /**
174
     * DOCUMENT ME!
175
     *
176
     * @param listener
177
     */
178
    public void addPropertyChangeListener(PropertyChangeListener listener) {
179
        support.addPropertyChangeListener(listener);
180
    }
181

    
182
    /**
183
     * DOCUMENT ME!
184
     *
185
     * @param listener
186
     */
187
    public void removePropertyChangeListener(PropertyChangeListener listener) {
188
        support.removePropertyChangeListener(listener);
189
    }
190

    
191
    /**
192
     * Establece las propiedades de la vista
193
     *
194
     * @param code Bit-or de las propiedades de la vista
195
     *
196
     * @throws IllegalStateException DOCUMENT ME!
197
     */
198
    public WindowInfo(int code) {
199
        resizable = (code % 2) > 0;
200
        code = code / 2;
201
        maximizable = (code % 2) > 0;
202
        code = code / 2;
203
        iconifiable = (code % 2) > 0;
204
        code = code / 2;
205
        modal = (code % 2) > 0;
206
        code = code / 2;
207
        modeless = (code % 2) > 0;
208
        code = code / 2;
209
        palette = (code % 2) > 0;
210

    
211
        if (modal && modeless) {
212
            throw new IllegalStateException("modal && modeless");
213
        }
214
    }
215

    
216
    public WindowInfo(){
217

    
218
    }
219

    
220
    /**
221
     * Si es iconificable
222
     *
223
     * @return
224
     */
225
    public boolean isIconifiable() {
226
        return iconifiable;
227
    }
228

    
229
    /**
230
     * Si es maximizable
231
     *
232
     * @return
233
     */
234
    public boolean isMaximizable() {
235
        return maximizable;
236
    }
237

    
238
    /**
239
     * Si es resizable
240
     *
241
     * @return
242
     */
243
    public boolean isResizable() {
244
        return resizable;
245
    }
246

    
247
    /**
248
     * Devuelve si el di?logo es modal
249
     *
250
     * @return
251
     */
252
    public boolean isModal() {
253
        return modal;
254
    }
255

    
256
    /**
257
     * Obtiene la altura de la vista
258
     *
259
     * @return
260
     */
261
    public int getHeight() {
262
        return height;
263
    }
264

    
265
    /**
266
     * Obtiene la anchura de la vista
267
     *
268
     * @return
269
     */
270
    public int getWidth() {
271
        return width;
272
    }
273

    
274
    /**
275
     * establece la propiedad altura
276
     *
277
     * @param h
278
     */
279
    public void setHeight(int h) {
280
            if (h!=-1)
281
                    support.firePropertyChange("height", this.height, h);
282
            height = h;
283
        if (!isMaximized)
284
                this.normalHeight = h;
285
    }
286

    
287
    /**
288
     * establece la propiedad anchura
289
     *
290
     * @param i
291
     */
292
    public void setWidth(int w) {
293
            if (w!=-1)
294
                    support.firePropertyChange("width", this.width, w);
295
        width = w;
296
        if (!isMaximized)
297
                this.width = w;
298
    }
299

    
300
    /**
301
     * obtiene la propiedad titulo
302
     *
303
     * @return
304
     */
305
    public String getTitle() {
306
        return title;
307
    }
308

    
309
    /**
310
     * establece la propiedad titulo
311
     *
312
     * @param string
313
     */
314
    public void setTitle(String string) {
315
            support.firePropertyChange("title", this.title, string);
316
        title = string;
317
    }
318

    
319
    /**
320
     * DOCUMENT ME!
321
     *
322
     * @return
323
     */
324
    public boolean isModeless() {
325
        return modeless;
326
    }
327

    
328
    /**
329
     * DOCUMENT ME!
330
     *
331
     * @return
332
     */
333
    public boolean isVisible() {
334
        return visible;
335
    }
336

    
337
    public boolean isPalette()
338
    {
339
        return palette;
340
    }
341

    
342
    public void setId(int id){
343
            this.id = id;
344
    }
345

    
346
    public int getId(){
347
            return id;
348
    }
349

    
350
    public void setWindowInfo(WindowInfo vi){
351
            this.resizable = vi.resizable;
352
            this.maximizable = vi.maximizable;
353
            this.isMaximized = vi.isMaximized;
354
            this.iconifiable = vi.iconifiable;
355
            this.modal = vi.modal;
356
            this.modeless = vi.modeless;
357
            if (vi.width!=-1)
358
                    this.width = vi.width;
359
            if (vi.height!=-1)
360
                    this.height = vi.height;
361
            this.x = vi.x;
362
            this.y = vi.y;
363
            this.visible = vi.visible;
364
            this.title = vi.title;
365
            this.id = vi.id;
366
            if (vi.normalHeight!=-1)
367
                    this.normalHeight = vi.normalHeight;
368
            if (vi.normalWidth!=-1)
369
                    this.normalWidth = vi.normalWidth;
370
            this.normalX = vi.normalX;
371
            this.normalY = vi.normalY;
372
            this.isClosed = vi.isClosed;
373
            this.persistWindow = vi.persistWindow;
374
    }
375
    public void toPalette(boolean b){
376
            this.palette=b;
377
    }
378

    
379
    public String getSelectedTool() {
380
        return selectedTool;
381
    }
382

    
383
    public void setSelectedTool(String selectedTool) {
384
        if (selectedTool != null)
385
            this.selectedTool = selectedTool;
386
    }
387

    
388
    /* Finds out whether a view is open (showing) or closed */
389
    public boolean isClosed() {
390
            return isClosed;
391
    }
392

    
393
    /* Specifies whether a view is open (showing) or closed */
394
    public void setClosed(boolean closed) {
395
            support.firePropertyChange("closed", this.isClosed, closed);
396
            this.isClosed = closed;
397
    }
398

    
399
    public void setNormalX(int normalX) {
400
            support.firePropertyChange("normalX", this.normalX, normalX);
401
            this.normalX = normalX;
402
    }
403

    
404
    public void setNormalY(int normalY) {
405
            support.firePropertyChange("normalY", this.normalY, normalY);
406
            this.normalY = normalY;
407
    }
408

    
409
    public void setNormalHeight(int normalHeight) {
410
            support.firePropertyChange("normalHeight", this.normalHeight, normalHeight);
411
            this.normalHeight = normalHeight;
412
    }
413

    
414
    public void setNormalWidth(int normalWidth) {
415
            support.firePropertyChange("normalWidth", this.normalWidth, normalWidth);
416
            this.normalWidth = normalWidth;
417
    }
418

    
419

    
420
    public void setMaximized(boolean maximized) {
421
            support.firePropertyChange("maximized", this.isMaximized, maximized);
422
            this.isMaximized = maximized;
423
    }
424
    
425
    public void setMaximizable(boolean maximizable) {
426
            this.maximizable = maximizable;
427
    }
428

    
429
    private void setBounds(int x, int y, int width, int height) {
430
            support.firePropertyChange("x", this.height, x);
431
            this.x = x;
432
            support.firePropertyChange("y", this.height, y);
433
            this.y = y;
434
            support.firePropertyChange("width", this.width, width);
435
            this.width = width;
436
            support.firePropertyChange("height", this.height, height);
437
            this.height = height;
438
    }
439

    
440
    public void setNormalBounds(int x, int y, int width, int height) {
441
            support.firePropertyChange("normalX", this.normalX, x);
442
            this.normalX = x;
443
            support.firePropertyChange("normalY", this.normalY, y);
444
            this.normalY = y;
445
            support.firePropertyChange("normalWidth", this.normalWidth, width);
446
            this.normalWidth = width;
447
            support.firePropertyChange("normalWeight", this.normalHeight, height);
448
            this.normalHeight = height;
449
    }
450

    
451
    public Rectangle getNormalBounds() {
452
            return new Rectangle(getNormalX(), getNormalY(), getNormalWidth(), getNormalHeight());
453
    }
454

    
455
    public void setNormalBounds(Rectangle normalBounds) {
456
            Rectangle oldBounds = new Rectangle(this.normalX, this.normalY, 
457
                            this.normalWidth, this.normalHeight);
458
            support.firePropertyChange("normalBounds", oldBounds, normalBounds);
459
            support.firePropertyChange("normalX", this.normalX, normalBounds.x);
460
            normalX = normalBounds.x;
461
            support.firePropertyChange("normalY", this.normalY, normalBounds.y);
462
            normalY = normalBounds.y;
463
            support.firePropertyChange("normalHeight", this.normalHeight, normalBounds.height);
464
            normalHeight = normalBounds.height;
465
            support.firePropertyChange("normalWidth", this.normalWidth, normalBounds.width);
466
            normalWidth = normalBounds.width;
467
    }
468

    
469
    public void setBounds(Rectangle bounds) {
470
            support.firePropertyChange("x", this.x, bounds.x);
471
            x = bounds.x;
472
            support.firePropertyChange("y", this.y, bounds.y);
473
            y = bounds.y;
474
            support.firePropertyChange("height", this.height, bounds.height);
475
            height = bounds.height;
476
            support.firePropertyChange("width", this.width, bounds.width);
477
            width = bounds.width;
478
    }
479

    
480
    public Rectangle getBounds() {
481
            return new Rectangle(x, y, width, height);
482
    }
483

    
484
    public int getNormalX() {
485
            if (normalX!=0)
486
                    return this.normalX;
487
            else
488
                    return x;
489
    }
490

    
491
    public int getNormalY() {
492
            if (normalY!=0)
493
                    return this.normalY;
494
            else
495
                    return y;
496
    }
497

    
498
    public int getNormalHeight() {
499
            if (normalHeight!=0)
500
                    return this.normalHeight;
501
            else
502
                    return height;
503
    }
504

    
505
    public int getNormalWidth() {
506
            if (normalWidth!=0)
507
                    return this.normalWidth;
508
            else
509
                    return width;
510
    }
511

    
512
    public boolean isMaximized() {
513
            return this.isMaximized;
514
    }
515
    
516
    /**
517
     * Checks if the geometry of this window should be persisted in the
518
     * project file. This is set by the persistWindow(boolean) method,
519
     * and the default value is true.
520
     * 
521
     * @return True if the geometry of this window should be persisted
522
     * in the project files, false otherwise.
523
     */
524
    public boolean checkPersistence() {
525
            return this.persistWindow;
526
    }
527
    
528
    /**
529
     * Set whether the geometry of this window should be persisted in the
530
     * project files.
531
     * 
532
     * @param persist
533
     */
534
    public void setPersistence(boolean persist) {
535
            this.persistWindow = persist;
536
    }
537
    
538
    /**
539
         * Gets the window properties in an XMLEntity object, suitable
540
         * for persistence.
541
         *
542
         * @return An XMLEntity object containing the window properties, or null if the window was set as
543
         * not persistent
544
     * @throws SaveException
545
         * @throws XMLException
546
         * @throws SaveException
547
         */
548
        public XMLEntity getXMLEntity() {
549
                XMLEntity xml = new XMLEntity();
550
                xml.setName("ViewInfoProperties");
551
                xml.putProperty("X", this.getX());
552
                xml.putProperty("Y", this.getY());
553
                xml.putProperty("Width", this.getWidth());
554
                xml.putProperty("Height", this.getHeight());
555
                xml.putProperty("isVisible", this.isVisible());
556
                xml.putProperty("isResizable", this.isResizable());
557
                xml.putProperty("isMaximizable", this.isMaximizable());
558
                xml.putProperty("isModal", this.isModal());
559
                xml.putProperty("isModeless", this.isModeless());
560
                xml.putProperty("isClosed", this.isClosed());
561
                if (this.isMaximized()==true) {
562
                        xml.putProperty("isMaximized", this.isMaximized());
563
                        xml.putProperty("normalX", this.getNormalX());
564
                        xml.putProperty("normalY", this.getNormalY());
565
                        xml.putProperty("normalWidth", this.getNormalWidth());
566
                        xml.putProperty("normalHeight", this.getNormalHeight());
567
                }
568
                return xml;
569
        }
570
        
571
        
572
        public static WindowInfo createFromXMLEntity(XMLEntity xml)
573
        {
574
                WindowInfo result = new WindowInfo();
575
                try {
576
                        result.setX(xml.getIntProperty("X"));
577
                        result.setY(xml.getIntProperty("Y"));
578
                        result.setHeight(xml.getIntProperty("Height"));
579
                        result.setWidth(xml.getIntProperty("Width"));
580
                        result.setClosed(xml.getBooleanProperty("isClosed"));
581
                        if (xml.contains("isMaximized")) {
582
                                boolean maximized = xml.getBooleanProperty("isMaximized");
583
                                result.setMaximized(maximized);
584
                                if (maximized==true) {
585
                                        result.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
586
                                }
587
                                else {
588
                                        result.setNormalBounds(result.getBounds());
589
                                }
590
                        }
591
                }
592
                catch (com.iver.utiles.NotExistInXMLEntity ex) {
593
                        PluginServices.getLogger().warn(PluginServices.getText(null, "Window_properties_not_stored_correctly_Window_state_will_not_be_restored"));
594
                }
595

    
596
                return result;
597
        }
598
        
599
        public void getPropertiesFromXMLEntity(XMLEntity xml)
600
        {
601
                this.x = xml.getIntProperty("X");
602
                this.y = xml.getIntProperty("Y");
603
                this.height = xml.getIntProperty("Height");
604
                this.width = xml.getIntProperty("Width");
605
                this.isClosed = xml.getBooleanProperty("isClosed");
606
                if (xml.contains("isMaximized")) {
607
                        boolean maximized = xml.getBooleanProperty("isMaximized");
608
                        this.isMaximized = maximized;
609
                        if (maximized==true) {
610
                                this.setNormalBounds(xml.getIntProperty("normalX"), xml.getIntProperty("normalY"), xml.getIntProperty("normalWidth"), xml.getIntProperty("normalHeight"));
611
                        }
612
                }
613
        }
614
}