Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / ext3Dgui / src / com / iver / ai2 / gvsig3dgui / skin / JDialogWindowInfoSupport.java @ 16096

History | View | Annotate | Download (6.64 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.ai2.gvsig3dgui.skin;
42

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

    
48
import com.iver.andami.plugins.PluginClassLoader;
49
import com.iver.andami.ui.mdiFrame.MainFrame;
50
import com.iver.andami.ui.mdiFrame.NoSuchMenuException;
51
import com.iver.andami.ui.mdiManager.IWindow;
52
import com.iver.andami.ui.mdiManager.SingletonWindow;
53
import com.iver.andami.ui.mdiManager.WindowInfo;
54
import com.iver.core.mdiManager.FrameWindowSupport;
55
import com.iver.core.mdiManager.SingletonWindowSupport;
56
import com.iver.core.mdiManager.WindowInfoSupport;
57

    
58

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

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

    
83
        /**
84
         * Creates a new ViewInfoSupport object.
85
         *
86
         * @param frame DOCUMENT ME!
87
         * @param fvs DOCUMENT ME!
88
         * @param svs
89
         */
90
        public JDialogWindowInfoSupport(MainFrame frame, FrameWindowSupport fvs,
91
                SingletonWindowSupport svs) {
92
                super(frame,fvs,svs);
93
                this.fws = (JDialogFrameWindowSupport) fvs;
94
                this.svs = (JDialogSingletonWindowSupport) 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: 1.1 $
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 v = (WindowInfo) evt.getSource();
171
                        IWindow view = (IWindow) infoView.get(v);
172

    
173
                        if (view instanceof SingletonWindow) {
174
                                SingletonWindow sv = (SingletonWindow) view;
175

    
176
                                if (evt.getPropertyName().equals("x")) {
177
                                        svs.setX(sv, ((Integer) evt.getNewValue()).intValue());
178
                                } else if (evt.getPropertyName().equals("y")) {
179
                                        svs.setY(sv, ((Integer) evt.getNewValue()).intValue());
180
                                } else if (evt.getPropertyName().equals("height")) {
181
                                        svs.setHeight(sv, ((Integer) evt.getNewValue()).intValue());
182
                                } else if (evt.getPropertyName().equals("width")) {
183
                                        svs.setWidth(sv, ((Integer) evt.getNewValue()).intValue());
184
                                } else if (evt.getPropertyName().equals("maximized")) {
185
                                        svs.setMaximized(sv, ((Boolean) evt.getNewValue()).booleanValue());
186
                                } else if (evt.getPropertyName().equals("normalBounds")) {
187
                                        // we don't do anything at the moment here
188
                                //        svs.setNormalBounds(sv, (Rectangle) evt.getNewValue());
189
                                } else if (evt.getPropertyName().equals("title")) {
190
                                        svs.setTitle(sv, (String) evt.getNewValue());
191

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