Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libCorePlugin / src / com / iver / core / mdiManager / WindowInfoSupport.java @ 8879

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 com.iver.andami.plugins.PluginClassLoader;
44
import com.iver.andami.ui.mdiFrame.MainFrame;
45
import com.iver.andami.ui.mdiFrame.NoSuchMenuException;
46
import com.iver.andami.ui.mdiManager.SingletonWindow;
47
import com.iver.andami.ui.mdiManager.IWindow;
48
import com.iver.andami.ui.mdiManager.WindowInfo;
49

    
50
import java.awt.Rectangle;
51
import java.beans.PropertyChangeEvent;
52
import java.beans.PropertyChangeListener;
53

    
54
import java.util.Enumeration;
55
import java.util.Hashtable;
56

    
57

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

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

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

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

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

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

    
114
                return null;
115
        }
116

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

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

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

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

    
144
                return wi;
145
        }
146

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

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

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

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

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