root / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / WindowInfoSupport.java @ 8661
History | View | Annotate | Download (6.21 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 |
private FrameWindowSupport fvs;
|
64 |
|
65 |
// Correspondencias entre las ventanas y su informacion
|
66 |
/**
|
67 |
* key: IWindow, value: WindowInfo
|
68 |
*/
|
69 |
private Hashtable viewInfo = new Hashtable(); |
70 |
/**
|
71 |
* key: WindowInfo, value: IWindow
|
72 |
*/
|
73 |
private Hashtable infoView = new Hashtable(); |
74 |
private WindowPropertyChangeListener windowInfoListener = new WindowPropertyChangeListener(); |
75 |
private SingletonWindowSupport svs;
|
76 |
private MainFrame mdiFrame;
|
77 |
|
78 |
/**
|
79 |
* Creates a new ViewInfoSupport object.
|
80 |
*
|
81 |
* @param frame DOCUMENT ME!
|
82 |
* @param fvs DOCUMENT ME!
|
83 |
* @param svs
|
84 |
*/
|
85 |
public WindowInfoSupport(MainFrame frame, FrameWindowSupport fvs,
|
86 |
SingletonWindowSupport svs) { |
87 |
this.fvs = fvs;
|
88 |
this.svs = svs;
|
89 |
this.mdiFrame = frame;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Devuelve la vista cuyo identificador es el parametro
|
94 |
*
|
95 |
* @param id Identificador de la vista que se quiere obtener
|
96 |
*
|
97 |
* @return La vista o null si no hay ninguna vista con ese identificador
|
98 |
*/
|
99 |
public IWindow getWindowById(int id) { |
100 |
Enumeration en = infoView.keys();
|
101 |
|
102 |
while (en.hasMoreElements()) {
|
103 |
WindowInfo vi = (WindowInfo) en.nextElement(); |
104 |
|
105 |
if (vi.getId() == id) {
|
106 |
return (IWindow) infoView.get(vi);
|
107 |
} |
108 |
} |
109 |
|
110 |
return null; |
111 |
} |
112 |
|
113 |
/**
|
114 |
* DOCUMENT ME!
|
115 |
*
|
116 |
* @param w DOCUMENT ME!
|
117 |
*
|
118 |
* @return DOCUMENT ME!
|
119 |
*/
|
120 |
public synchronized WindowInfo getWindowInfo(IWindow w) { |
121 |
WindowInfo wi = (WindowInfo) viewInfo.get(w); |
122 |
|
123 |
if (wi == null) { |
124 |
wi = w.getWindowInfo(); |
125 |
|
126 |
//Para el t?tulo
|
127 |
if (wi.getHeight() != -1) { |
128 |
wi.setHeight(wi.getHeight() + 40);
|
129 |
} |
130 |
|
131 |
wi.addPropertyChangeListener(windowInfoListener); |
132 |
viewInfo.put(w, wi); |
133 |
infoView.put(wi, w); |
134 |
wi.setId(serialId++); |
135 |
} |
136 |
|
137 |
return wi;
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* DOCUMENT ME!
|
142 |
*
|
143 |
* @param p DOCUMENT ME!
|
144 |
*/
|
145 |
public void deleteWindowInfo(IWindow p) { |
146 |
WindowInfo vi = (WindowInfo) viewInfo.remove(p); |
147 |
infoView.remove(vi); |
148 |
} |
149 |
|
150 |
/**
|
151 |
* DOCUMENT ME!
|
152 |
*
|
153 |
* @author $author$
|
154 |
* @version $Revision: 8321 $
|
155 |
*/
|
156 |
public class WindowPropertyChangeListener implements PropertyChangeListener { |
157 |
/**
|
158 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
159 |
*/
|
160 |
public void propertyChange(PropertyChangeEvent evt) { |
161 |
WindowInfo v = (WindowInfo) evt.getSource(); |
162 |
IWindow view = (IWindow) infoView.get(v); |
163 |
|
164 |
if (view instanceof SingletonWindow) { |
165 |
SingletonWindow sv = (SingletonWindow) view; |
166 |
|
167 |
if (evt.getPropertyName().equals("x")) { |
168 |
svs.setX(sv, ((Integer) evt.getNewValue()).intValue());
|
169 |
} else if (evt.getPropertyName().equals("y")) { |
170 |
svs.setY(sv, ((Integer) evt.getNewValue()).intValue());
|
171 |
} else if (evt.getPropertyName().equals("height")) { |
172 |
svs.setHeight(sv, ((Integer) evt.getNewValue()).intValue());
|
173 |
} else if (evt.getPropertyName().equals("width")) { |
174 |
svs.setWidth(sv, ((Integer) evt.getNewValue()).intValue());
|
175 |
} else if (evt.getPropertyName().equals("maximized")) { |
176 |
svs.setMaximized(sv, ((Boolean) evt.getNewValue()).booleanValue());
|
177 |
} else if (evt.getPropertyName().equals("normalBounds")) { |
178 |
svs.setNormalBounds(sv, (Rectangle) evt.getNewValue());
|
179 |
} else if (evt.getPropertyName().equals("title")) { |
180 |
svs.setTitle(sv, (String) evt.getNewValue());
|
181 |
|
182 |
try {
|
183 |
mdiFrame.changeMenuName(new String[] { |
184 |
"ventana", (String) evt.getOldValue() |
185 |
}, (String) evt.getNewValue(),
|
186 |
(PluginClassLoader) getClass().getClassLoader()); |
187 |
} catch (NoSuchMenuException e) {
|
188 |
/*
|
189 |
* No se hace nada porque puede modificarse el t?tulo de
|
190 |
* una ventana antes de ser a?adida a Andami
|
191 |
*/
|
192 |
} |
193 |
} |
194 |
} else {
|
195 |
if (evt.getPropertyName().equals("x")) { |
196 |
fvs.setX(view, ((Integer) evt.getNewValue()).intValue());
|
197 |
} else if (evt.getPropertyName().equals("y")) { |
198 |
fvs.setY(view, ((Integer) evt.getNewValue()).intValue());
|
199 |
} else if (evt.getPropertyName().equals("height")) { |
200 |
fvs.setHeight(view, ((Integer) evt.getNewValue()).intValue());
|
201 |
} else if (evt.getPropertyName().equals("width")) { |
202 |
fvs.setWidth(view, ((Integer) evt.getNewValue()).intValue());
|
203 |
} else if (evt.getPropertyName().equals("title")) { |
204 |
fvs.setTitle(view, (String) evt.getNewValue());
|
205 |
try{
|
206 |
mdiFrame.changeMenuName(new String[] { |
207 |
"ventana", (String) evt.getOldValue() |
208 |
}, (String) evt.getNewValue(),
|
209 |
(PluginClassLoader) getClass().getClassLoader()); |
210 |
} catch (NoSuchMenuException e) {
|
211 |
/*
|
212 |
* No se hace nada porque puede modificarse el t?tulo de
|
213 |
* una ventana antes de ser a?adida a Andami
|
214 |
*/
|
215 |
} |
216 |
} |
217 |
} |
218 |
} |
219 |
} |
220 |
} |