Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / mdiManager / WindowInfoSupport.java @ 39115

History | View | Annotate | Download (6.71 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 org.gvsig.coreplugin.mdiManager;
42

    
43
import java.awt.Dimension;
44
import java.awt.Rectangle;
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
47
import java.util.Enumeration;
48
import java.util.Hashtable;
49

    
50
import org.gvsig.andami.plugins.PluginClassLoader;
51
import org.gvsig.andami.ui.mdiFrame.MainFrame;
52
import org.gvsig.andami.ui.mdiFrame.NoSuchMenuException;
53
import org.gvsig.andami.ui.mdiManager.IWindow;
54
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
55
import org.gvsig.andami.ui.mdiManager.WindowInfo;
56

    
57

    
58

    
59
/**
60
 * This class listens to changes in WindowInfo objects, and reflects this
61
 * changes in the associated window.
62
 */
63
public class WindowInfoSupport {
64
        private static int serialId = 0;
65
        
66
        /**
67
         * Support class which associates Frames and Windows
68
         */
69
        private FrameWindowSupport fws;
70

    
71
        // Correspondencias entre las ventanas y su informacion
72
        /**
73
         * key: IWindow, value: WindowInfo
74
         */
75
        private Hashtable viewInfo = new Hashtable();
76
        /**
77
         * key: WindowInfo, value: IWindow
78
         */
79
        private Hashtable infoView = new Hashtable();
80
        private WindowPropertyChangeListener windowInfoListener = new WindowPropertyChangeListener();
81
        private SingletonWindowSupport sws;
82
        private MainFrame mdiFrame;
83

    
84
        /**
85
         * Creates a new ViewInfoSupport object.
86
         *
87
         * @param frame DOCUMENT ME!
88
         * @param fvs DOCUMENT ME!
89
         * @param svs
90
         */
91
        public WindowInfoSupport(MainFrame frame, FrameWindowSupport fvs,
92
                SingletonWindowSupport svs) {
93
                this.fws = fvs;
94
                this.sws = svs;
95
                this.mdiFrame = frame;
96
        }
97

    
98
        /**
99
         * Devuelve la vista cuyo identificador es el parametro
100
         *
101
         * @param id Identificador de la vista que se quiere obtener
102
         *
103
         * @return La vista o null si no hay ninguna vista con ese identificador
104
         */
105
        public IWindow getWindowById(int id) {
106
                Enumeration en = infoView.keys();
107

    
108
                while (en.hasMoreElements()) {
109
                        WindowInfo vi = (WindowInfo) en.nextElement();
110

    
111
                        if (vi.getId() == id) {
112
                                return (IWindow) infoView.get(vi);
113
                        }
114
                }
115

    
116
                return null;
117
        }
118

    
119
        /**
120
         * DOCUMENT ME!
121
         *
122
         * @param w DOCUMENT ME!
123
         *
124
         * @return DOCUMENT ME!
125
         */
126
        public synchronized WindowInfo getWindowInfo(IWindow w) {
127
                WindowInfo wi = (WindowInfo) viewInfo.get(w);
128

    
129
                if (wi != null) {
130
                        fws.updateWindowInfo(w, wi);
131
                }
132
                else {
133
                        wi = w.getWindowInfo();
134

    
135
                        //Para el t?tulo
136
                        if (wi.getHeight() != -1) {
137
                                wi.setHeight(wi.getHeight() + 40);
138
                        }
139

    
140
                        wi.addPropertyChangeListener(windowInfoListener);
141
                        viewInfo.put(w, wi);
142
                        infoView.put(wi, w);
143
                        wi.setId(serialId++);
144
                }
145

    
146
                return wi;
147
        }
148

    
149
        /**
150
         * DOCUMENT ME!
151
         *
152
         * @param p DOCUMENT ME!
153
         */
154
        public void deleteWindowInfo(IWindow p) {
155
                WindowInfo vi = (WindowInfo) viewInfo.remove(p);
156
                infoView.remove(vi);
157
        }
158

    
159
        /**
160
         * DOCUMENT ME!
161
         *
162
         * @author $author$
163
         * @version $Revision: 39115 $
164
         */
165
        public class WindowPropertyChangeListener implements PropertyChangeListener {
166
                /**
167
                 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
168
                 */
169
                public void propertyChange(PropertyChangeEvent evt) {
170
                        WindowInfo winInfo = (WindowInfo) evt.getSource();
171
                        IWindow win = (IWindow) infoView.get(winInfo);
172

    
173
                        if (win instanceof SingletonWindow) {
174
                                SingletonWindow sw = (SingletonWindow) win;
175

    
176
                                if (evt.getPropertyName().equals("x")) {
177
                                        sws.setX(sw, ((Integer) evt.getNewValue()).intValue());
178
                                } else if (evt.getPropertyName().equals("y")) {
179
                                        sws.setY(sw, ((Integer) evt.getNewValue()).intValue());
180
                                } else if (evt.getPropertyName().equals("height")) {
181
                                        sws.setHeight(sw, ((Integer) evt.getNewValue()).intValue());
182
                                } else if (evt.getPropertyName().equals("width")) {
183
                                        sws.setWidth(sw, ((Integer) evt.getNewValue()).intValue());
184
                                } else if (evt.getPropertyName().equals("maximized")) {
185
                                        sws.setMaximized(sw, ((Boolean) evt.getNewValue()).booleanValue());
186
                                } else if (evt.getPropertyName().equals("normalBounds")) {
187
                                        sws.setNormalBounds(sw, (Rectangle) evt.getNewValue());
188
                                } else if (evt.getPropertyName().equals("minimumSize")) {
189
                                        sws.setMinimumSize(sw, (Dimension) evt.getNewValue());
190
                                } else if (evt.getPropertyName().equals("title")) {
191
                                        sws.setTitle(sw, (String) evt.getNewValue());
192

    
193
                                        try {
194
                                                mdiFrame.changeMenuName(new String[] {
195
                                                                "Window", (String) evt.getOldValue()
196
                                                }, (String) evt.getNewValue(),
197
                                                (PluginClassLoader) getClass().getClassLoader());
198
                                        } catch (NoSuchMenuException e) {
199
                                                /*
200
                                                 * No se hace nada porque puede modificarse el t?tulo de
201
                                                 * una ventana antes de ser a?adida a Andami
202
                                                 */
203
                                        }
204
                                }
205
                        } else {
206
                                if (evt.getPropertyName().equals("x")) {
207
                                        fws.setX(win, ((Integer) evt.getNewValue()).intValue());
208
                                } else if (evt.getPropertyName().equals("y")) {
209
                                        fws.setY(win, ((Integer) evt.getNewValue()).intValue());
210
                                } else if (evt.getPropertyName().equals("height")) {
211
                                        fws.setHeight(win, ((Integer) evt.getNewValue()).intValue());
212
                                } else if (evt.getPropertyName().equals("width")) {
213
                                        fws.setWidth(win, ((Integer) evt.getNewValue()).intValue());
214
                                } else if (evt.getPropertyName().equals("minimumSize")) {
215
                                        fws.setMinimumSize(win, (Dimension) evt.getNewValue());
216
                                } else if (evt.getPropertyName().equals("title")) {
217
                                        fws.setTitle(win, (String) evt.getNewValue());
218
                                        try{
219
                                                mdiFrame.changeMenuName(new String[] {
220
                                                                "Ventana", (String) evt.getOldValue()
221
                                                }, (String) evt.getNewValue(),
222
                                                (PluginClassLoader) getClass().getClassLoader());
223
                                        } catch (NoSuchMenuException e) {
224
                                                /*
225
                                                 * No se hace nada porque puede modificarse el t?tulo de
226
                                                 * una ventana antes de ser a?adida a Andami
227
                                                 */
228
                                        }
229
                                }
230
                        }
231
                }
232
        }
233
}