Statistics
| Revision:

root / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / ViewInfoSupport.java @ 6877

History | View | Annotate | Download (5.79 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.SingletonView;
47
import com.iver.andami.ui.mdiManager.IWindow;
48
import com.iver.andami.ui.mdiManager.ViewInfo;
49

    
50
import java.beans.PropertyChangeEvent;
51
import java.beans.PropertyChangeListener;
52

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

    
56

    
57
/**
58
 *
59
 */
60
public class ViewInfoSupport {
61
        private static int serialId = 0;
62
        private FrameViewSupport fvs;
63

    
64
        /** Correspondencias entre las vistas y su informacion */
65
        private Hashtable viewInfo = new Hashtable();
66
        private Hashtable infoView = new Hashtable();
67
        private ViewPropertyChangeListener viewInfoListener = new ViewPropertyChangeListener();
68
        private SingletonViewSupport svs;
69
        private MainFrame mdiFrame;
70

    
71
        /**
72
         * Creates a new ViewInfoSupport object.
73
         *
74
         * @param frame DOCUMENT ME!
75
         * @param fvs DOCUMENT ME!
76
         * @param svs
77
         */
78
        public ViewInfoSupport(MainFrame frame, FrameViewSupport fvs,
79
                SingletonViewSupport svs) {
80
                this.fvs = fvs;
81
                this.svs = svs;
82
                this.mdiFrame = frame;
83
        }
84

    
85
        /**
86
         * Devuelve la vista cuyo identificador es el parametro
87
         *
88
         * @param id Identificador de la vista que se quiere obtener
89
         *
90
         * @return La vista o null si no hay ninguna vista con ese identificador
91
         */
92
        public IWindow getViewById(int id) {
93
                Enumeration en = infoView.keys();
94

    
95
                while (en.hasMoreElements()) {
96
                        ViewInfo vi = (ViewInfo) en.nextElement();
97

    
98
                        if (vi.getId() == id) {
99
                                return (IWindow) infoView.get(vi);
100
                        }
101
                }
102

    
103
                return null;
104
        }
105

    
106
        /**
107
         * DOCUMENT ME!
108
         *
109
         * @param v DOCUMENT ME!
110
         *
111
         * @return DOCUMENT ME!
112
         */
113
        public synchronized ViewInfo getViewInfo(IWindow v) {
114
                ViewInfo vi = (ViewInfo) viewInfo.get(v);
115

    
116
                if (vi == null) {
117
                        vi = v.getViewInfo();
118

    
119
                        //Para el t?tulo
120
                        if (vi.getHeight() != -1) {
121
                                vi.setHeight(vi.getHeight() + 40);
122
                        }
123

    
124
                        vi.addPropertyChangeListener(viewInfoListener);
125
                        viewInfo.put(v, vi);
126
                        infoView.put(vi, v);
127
                        vi.setId(serialId++);
128
                }
129

    
130
                return vi;
131
        }
132

    
133
        /**
134
         * DOCUMENT ME!
135
         *
136
         * @param p DOCUMENT ME!
137
         */
138
        public void deleteViewInfo(IWindow p) {
139
                ViewInfo vi = (ViewInfo) viewInfo.remove(p);
140
                infoView.remove(vi);
141
        }
142

    
143
        /**
144
         * DOCUMENT ME!
145
         *
146
         * @author $author$
147
         * @version $Revision: 6877 $
148
         */
149
        public class ViewPropertyChangeListener implements PropertyChangeListener {
150
                /**
151
                 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
152
                 */
153
                public void propertyChange(PropertyChangeEvent evt) {
154
                        ViewInfo v = (ViewInfo) evt.getSource();
155
                        IWindow view = (IWindow) infoView.get(v);
156

    
157
                        if (view instanceof SingletonView) {
158
                                SingletonView sv = (SingletonView) view;
159

    
160
                                if (evt.getPropertyName().equals("x")) {
161
                                        svs.setX(sv, ((Integer) evt.getNewValue()).intValue());
162
                                } else if (evt.getPropertyName().equals("y")) {
163
                                        svs.setY(sv, ((Integer) evt.getNewValue()).intValue());
164
                                } else if (evt.getPropertyName().equals("height")) {
165
                                        svs.setHeight(sv, ((Integer) evt.getNewValue()).intValue());
166
                                } else if (evt.getPropertyName().equals("width")) {
167
                                        svs.setWidth(sv, ((Integer) evt.getNewValue()).intValue());
168
                                } else if (evt.getPropertyName().equals("title")) {
169
                                        svs.setTitle(sv, (String) evt.getNewValue());
170

    
171
                                        try {
172
                                                mdiFrame.changeMenuName(new String[] {
173
                                                                "ventana", (String) evt.getOldValue()
174
                                                        }, (String) evt.getNewValue(),
175
                                                        (PluginClassLoader) getClass().getClassLoader());
176
                                        } catch (NoSuchMenuException e) {
177
                                                /*
178
                                                 * No se hace nada porque puede modificarse el t?tulo de
179
                                                 * una ventana antes de ser a?adida a Andami
180
                                                 */
181
                                        }
182
                                }
183
                        } else {
184
                                if (evt.getPropertyName().equals("x")) {
185
                                        fvs.setX(view, ((Integer) evt.getNewValue()).intValue());
186
                                } else if (evt.getPropertyName().equals("y")) {
187
                                        fvs.setY(view, ((Integer) evt.getNewValue()).intValue());
188
                                } else if (evt.getPropertyName().equals("height")) {
189
                                        fvs.setHeight(view, ((Integer) evt.getNewValue()).intValue());
190
                                } else if (evt.getPropertyName().equals("width")) {
191
                                        fvs.setWidth(view, ((Integer) evt.getNewValue()).intValue());
192
                                } else if (evt.getPropertyName().equals("title")) {
193
                                        fvs.setTitle(view, (String) evt.getNewValue());
194
                                        try{
195
                                                mdiFrame.changeMenuName(new String[] {
196
                                                                "ventana", (String) evt.getOldValue()
197
                                                        }, (String) evt.getNewValue(),
198
                                                        (PluginClassLoader) getClass().getClassLoader());
199
                                        } catch (NoSuchMenuException e) {
200
                                                /*
201
                                                 * No se hace nada porque puede modificarse el t?tulo de
202
                                                 * una ventana antes de ser a?adida a Andami
203
                                                 */
204
                                        }
205
                                }
206
                        }
207
                }
208
        }
209
}