Statistics
| Revision:

root / tags / v1_1_Build_1005 / libraries / libCorePlugin / src / com / iver / core / mdiManager / WindowInfoSupport.java @ 12355

History | View | Annotate | Download (6.32 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.core.mdiManager;
42

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

    
49
import com.iver.andami.plugins.PluginClassLoader;
50
import com.iver.andami.ui.mdiFrame.MainFrame;
51
import com.iver.andami.ui.mdiFrame.NoSuchMenuException;
52
import com.iver.andami.ui.mdiManager.IWindow;
53
import com.iver.andami.ui.mdiManager.SingletonWindow;
54
import com.iver.andami.ui.mdiManager.WindowInfo;
55

    
56

    
57
/**
58
 *
59
 */
60
public class WindowInfoSupport {
61
        private static int serialId = 0;
62
        
63
        /**
64
         * Support class which associates Frames and Windows
65
         */
66
        private FrameWindowSupport fws;
67

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

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

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

    
105
                while (en.hasMoreElements()) {
106
                        WindowInfo vi = (WindowInfo) en.nextElement();
107

    
108
                        if (vi.getId() == id) {
109
                                return (IWindow) infoView.get(vi);
110
                        }
111
                }
112

    
113
                return null;
114
        }
115

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

    
126
                if (wi != null) {
127
                        fws.updateWindowInfo(w, wi);
128
                }
129
                else {
130
                        wi = w.getWindowInfo();
131

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

    
137
                        wi.addPropertyChangeListener(windowInfoListener);
138
                        viewInfo.put(w, wi);
139
                        infoView.put(wi, w);
140
                        wi.setId(serialId++);
141
                }
142

    
143
                return wi;
144
        }
145

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

    
156
        /**
157
         * DOCUMENT ME!
158
         *
159
         * @author $author$
160
         * @version $Revision: 11021 $
161
         */
162
        public class WindowPropertyChangeListener implements PropertyChangeListener {
163
                /**
164
                 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
165
                 */
166
                public void propertyChange(PropertyChangeEvent evt) {
167
                        WindowInfo v = (WindowInfo) evt.getSource();
168
                        IWindow view = (IWindow) infoView.get(v);
169

    
170
                        if (view instanceof SingletonWindow) {
171
                                SingletonWindow sv = (SingletonWindow) view;
172

    
173
                                if (evt.getPropertyName().equals("x")) {
174
                                        svs.setX(sv, ((Integer) evt.getNewValue()).intValue());
175
                                } else if (evt.getPropertyName().equals("y")) {
176
                                        svs.setY(sv, ((Integer) evt.getNewValue()).intValue());
177
                                } else if (evt.getPropertyName().equals("height")) {
178
                                        svs.setHeight(sv, ((Integer) evt.getNewValue()).intValue());
179
                                } else if (evt.getPropertyName().equals("width")) {
180
                                        svs.setWidth(sv, ((Integer) evt.getNewValue()).intValue());
181
                                } else if (evt.getPropertyName().equals("maximized")) {
182
                                        svs.setMaximized(sv, ((Boolean) evt.getNewValue()).booleanValue());
183
                                } else if (evt.getPropertyName().equals("normalBounds")) {
184
                                        svs.setNormalBounds(sv, (Rectangle) evt.getNewValue());
185
                                } else if (evt.getPropertyName().equals("title")) {
186
                                        svs.setTitle(sv, (String) evt.getNewValue());
187

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