root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / mdiManager / WindowInfoSupport.java @ 38564
History | View | Annotate | Download (6.71 KB)
1 | 6892 | cesar | /* 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 | 29630 | jpiera | package org.gvsig.coreplugin.mdiManager; |
42 | 6892 | cesar | |
43 | 9997 | cesar | 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 | 29630 | jpiera | 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 | 6892 | cesar | |
57 | |||
58 | 29630 | jpiera | |
59 | 6892 | cesar | /**
|
60 | 9997 | cesar | * This class listens to changes in WindowInfo objects, and reflects this
|
61 | * changes in the associated window.
|
||
62 | 6892 | cesar | */
|
63 | public class WindowInfoSupport { |
||
64 | private static int serialId = 0; |
||
65 | 8838 | cesar | |
66 | /**
|
||
67 | * Support class which associates Frames and Windows
|
||
68 | */
|
||
69 | private FrameWindowSupport fws;
|
||
70 | 6892 | cesar | |
71 | 7450 | cesar | // Correspondencias entre las ventanas y su informacion
|
72 | /**
|
||
73 | * key: IWindow, value: WindowInfo
|
||
74 | */
|
||
75 | 6892 | cesar | private Hashtable viewInfo = new Hashtable(); |
76 | 7450 | cesar | /**
|
77 | * key: WindowInfo, value: IWindow
|
||
78 | */
|
||
79 | 6892 | cesar | private Hashtable infoView = new Hashtable(); |
80 | private WindowPropertyChangeListener windowInfoListener = new WindowPropertyChangeListener(); |
||
81 | 9997 | cesar | private SingletonWindowSupport sws;
|
82 | 6892 | cesar | 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 | 8838 | cesar | this.fws = fvs;
|
94 | 9997 | cesar | this.sws = svs;
|
95 | 6892 | cesar | 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 | 7450 | cesar | * @param w DOCUMENT ME!
|
123 | 6892 | cesar | *
|
124 | * @return DOCUMENT ME!
|
||
125 | */
|
||
126 | 7450 | cesar | public synchronized WindowInfo getWindowInfo(IWindow w) { |
127 | WindowInfo wi = (WindowInfo) viewInfo.get(w); |
||
128 | 6892 | cesar | |
129 | 8838 | cesar | if (wi != null) { |
130 | fws.updateWindowInfo(w, wi); |
||
131 | } |
||
132 | else {
|
||
133 | 7450 | cesar | wi = w.getWindowInfo(); |
134 | 6892 | cesar | |
135 | //Para el t?tulo
|
||
136 | 7450 | cesar | if (wi.getHeight() != -1) { |
137 | wi.setHeight(wi.getHeight() + 40);
|
||
138 | 6892 | cesar | } |
139 | |||
140 | 7450 | cesar | wi.addPropertyChangeListener(windowInfoListener); |
141 | viewInfo.put(w, wi); |
||
142 | infoView.put(wi, w); |
||
143 | wi.setId(serialId++); |
||
144 | 6892 | cesar | } |
145 | |||
146 | 7450 | cesar | return wi;
|
147 | 6892 | cesar | } |
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$
|
||
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 | 9997 | cesar | WindowInfo winInfo = (WindowInfo) evt.getSource(); |
171 | IWindow win = (IWindow) infoView.get(winInfo); |
||
172 | 6892 | cesar | |
173 | 9997 | cesar | if (win instanceof SingletonWindow) { |
174 | SingletonWindow sw = (SingletonWindow) win; |
||
175 | 6892 | cesar | |
176 | if (evt.getPropertyName().equals("x")) { |
||
177 | 9997 | cesar | sws.setX(sw, ((Integer) evt.getNewValue()).intValue());
|
178 | 6892 | cesar | } else if (evt.getPropertyName().equals("y")) { |
179 | 9997 | cesar | sws.setY(sw, ((Integer) evt.getNewValue()).intValue());
|
180 | 6892 | cesar | } else if (evt.getPropertyName().equals("height")) { |
181 | 9997 | cesar | sws.setHeight(sw, ((Integer) evt.getNewValue()).intValue());
|
182 | 6892 | cesar | } else if (evt.getPropertyName().equals("width")) { |
183 | 9997 | cesar | sws.setWidth(sw, ((Integer) evt.getNewValue()).intValue());
|
184 | 8321 | cesar | } else if (evt.getPropertyName().equals("maximized")) { |
185 | 9997 | cesar | sws.setMaximized(sw, ((Boolean) evt.getNewValue()).booleanValue());
|
186 | 8321 | cesar | } else if (evt.getPropertyName().equals("normalBounds")) { |
187 | 9997 | cesar | sws.setNormalBounds(sw, (Rectangle) evt.getNewValue());
|
188 | } else if (evt.getPropertyName().equals("minimumSize")) { |
||
189 | sws.setMinimumSize(sw, (Dimension) evt.getNewValue());
|
||
190 | 6892 | cesar | } else if (evt.getPropertyName().equals("title")) { |
191 | 9997 | cesar | sws.setTitle(sw, (String) evt.getNewValue());
|
192 | 6892 | cesar | |
193 | try {
|
||
194 | mdiFrame.changeMenuName(new String[] { |
||
195 | 13794 | cesar | "Ventana", (String) evt.getOldValue() |
196 | 9997 | cesar | }, (String) evt.getNewValue(),
|
197 | (PluginClassLoader) getClass().getClassLoader()); |
||
198 | 6892 | cesar | } 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 | 9997 | cesar | fws.setX(win, ((Integer) evt.getNewValue()).intValue());
|
208 | 6892 | cesar | } else if (evt.getPropertyName().equals("y")) { |
209 | 9997 | cesar | fws.setY(win, ((Integer) evt.getNewValue()).intValue());
|
210 | 6892 | cesar | } else if (evt.getPropertyName().equals("height")) { |
211 | 9997 | cesar | fws.setHeight(win, ((Integer) evt.getNewValue()).intValue());
|
212 | 6892 | cesar | } else if (evt.getPropertyName().equals("width")) { |
213 | 9997 | cesar | fws.setWidth(win, ((Integer) evt.getNewValue()).intValue());
|
214 | } else if (evt.getPropertyName().equals("minimumSize")) { |
||
215 | fws.setMinimumSize(win, (Dimension) evt.getNewValue());
|
||
216 | 6892 | cesar | } else if (evt.getPropertyName().equals("title")) { |
217 | 9997 | cesar | fws.setTitle(win, (String) evt.getNewValue());
|
218 | 6892 | cesar | try{
|
219 | mdiFrame.changeMenuName(new String[] { |
||
220 | 13794 | cesar | "Ventana", (String) evt.getOldValue() |
221 | 9997 | cesar | }, (String) evt.getNewValue(),
|
222 | (PluginClassLoader) getClass().getClassLoader()); |
||
223 | 6892 | cesar | } 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 | } |