Revision 1702
branches/CorePlugin_pilotoDWG/libraries/libCorePlugin/src/com/iver/core/mdiManager/SingletonViewSupport.java | ||
---|---|---|
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 java.util.ArrayList; |
|
44 |
import java.util.Comparator; |
|
45 |
import java.util.Iterator; |
|
46 |
import java.util.TreeMap; |
|
47 |
|
|
48 |
import javax.swing.JComponent; |
|
49 |
import javax.swing.JInternalFrame; |
|
50 |
|
|
51 |
import com.iver.andami.ui.mdiManager.SingletonDialogAlreadyShownException; |
|
52 |
import com.iver.andami.ui.mdiManager.SingletonView; |
|
53 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
|
54 |
|
|
55 |
|
|
56 |
/** |
|
57 |
* DOCUMENT ME! |
|
58 |
* |
|
59 |
* @author $author$ |
|
60 |
* @version $Revision$ |
|
61 |
*/ |
|
62 |
public class SingletonViewSupport { |
|
63 |
/** Hashtable que asocia contenido con vistas */ |
|
64 |
private TreeMap contentViewInfo = new TreeMap(new SingletonViewInfoComparator()); |
|
65 |
private ViewInfoSupport vis; |
|
66 |
private FrameViewSupport frameViewSupport; |
|
67 |
private TreeMap contentFrame = new TreeMap(new SingletonViewInfoComparator()); |
|
68 |
|
|
69 |
/** |
|
70 |
* DOCUMENT ME! |
|
71 |
* |
|
72 |
* @param vis DOCUMENT ME! |
|
73 |
* @param fvs |
|
74 |
* |
|
75 |
* @see com.iver.andami.ui.mdiManager.MDIManager#init(com.iver.andami.ui.mdiFrame.MDIFrame) |
|
76 |
*/ |
|
77 |
public SingletonViewSupport(ViewInfoSupport vis, FrameViewSupport fvs) { |
|
78 |
this.vis = vis; |
|
79 |
this.frameViewSupport = fvs; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Devuelve una referencia a la vista si ya est? mostrada o null si la |
|
84 |
* vista no ha sido a?adida o ya fue cerrada |
|
85 |
* |
|
86 |
* @param viewClass DOCUMENT ME! |
|
87 |
* @param model DOCUMENT ME! |
|
88 |
* @param vi DOCUMENT ME! |
|
89 |
* |
|
90 |
* @return true si la vista existe ya y false si la vista no existe |
|
91 |
* |
|
92 |
* @throws SingletonDialogAlreadyShownException DOCUMENT ME! |
|
93 |
*/ |
|
94 |
public boolean registerView(Class viewClass, Object model, ViewInfo vi) { |
|
95 |
//Se comprueba si la vista est? siendo mostrada |
|
96 |
SingletonViewInfo svi = new SingletonViewInfo(viewClass, model); |
|
97 |
|
|
98 |
if (contentViewInfo.containsKey(svi)) { |
|
99 |
if (vi.isModal()) { |
|
100 |
throw new SingletonDialogAlreadyShownException(); |
|
101 |
} |
|
102 |
|
|
103 |
vi.setViewInfo((ViewInfo)contentViewInfo.get(svi)); |
|
104 |
|
|
105 |
return true; |
|
106 |
} else { |
|
107 |
//La vista singleton no estaba mostrada |
|
108 |
//Se asocia el modelo con la vista |
|
109 |
contentViewInfo.put(svi, vi); |
|
110 |
return false; |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
public void openSingletonView(SingletonView sv, JComponent frame){ |
|
115 |
SingletonViewInfo svi = new SingletonViewInfo(sv.getClass(), sv.getViewModel()); |
|
116 |
contentFrame.put(svi, frame); |
|
117 |
} |
|
118 |
|
|
119 |
public boolean contains(SingletonView sv){ |
|
120 |
SingletonViewInfo svi = new SingletonViewInfo(sv.getClass(), sv.getViewModel()); |
|
121 |
return contentFrame.containsKey(svi); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* DOCUMENT ME! |
|
126 |
* |
|
127 |
* @param s |
|
128 |
*/ |
|
129 |
public void closeView(SingletonView s) { |
|
130 |
SingletonViewInfo svi = new SingletonViewInfo(s.getClass(), s.getViewModel()); |
|
131 |
ViewInfo viewInfo = (ViewInfo) contentViewInfo.get(svi); |
|
132 |
JInternalFrame c = (JInternalFrame) contentFrame.get(svi); |
|
133 |
viewInfo.setWidth(c.getWidth()); |
|
134 |
viewInfo.setHeight(c.getHeight()); |
|
135 |
viewInfo.setX(c.getX()); |
|
136 |
viewInfo.setY(c.getY()); |
|
137 |
|
|
138 |
contentFrame.remove(svi); |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* Representa una vista singleton manteniendo el modelo y la clase de la |
|
143 |
* vista que lo muestra |
|
144 |
* |
|
145 |
* @author Fernando Gonz?lez Cort?s |
|
146 |
*/ |
|
147 |
public class SingletonViewInfo { |
|
148 |
/** Clase de la vista */ |
|
149 |
public Class clase; |
|
150 |
|
|
151 |
/** Modelo que representa la vista */ |
|
152 |
public Object modelo; |
|
153 |
|
|
154 |
/** |
|
155 |
* Creates a new SingletonView object. |
|
156 |
* |
|
157 |
* @param clase Clase de la vista |
|
158 |
* @param modelo Modelo que representa la vista |
|
159 |
*/ |
|
160 |
public SingletonViewInfo(Class clase, Object modelo) { |
|
161 |
this.clase = clase; |
|
162 |
this.modelo = modelo; |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* @see java.lang.Object#equals(java.lang.Object) |
|
167 |
*/ |
|
168 |
public boolean equals(Object obj) { |
|
169 |
if (obj.getClass() != SingletonViewInfo.class) { |
|
170 |
throw new IllegalArgumentException(); |
|
171 |
} |
|
172 |
|
|
173 |
SingletonViewInfo s = (SingletonViewInfo) obj; |
|
174 |
|
|
175 |
if ((clase == s.clase) && (modelo == s.modelo)) { |
|
176 |
return true; |
|
177 |
} else { |
|
178 |
return false; |
|
179 |
} |
|
180 |
} |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* DOCUMENT ME! |
|
185 |
* |
|
186 |
* @author $author$ |
|
187 |
* @version $Revision$ |
|
188 |
*/ |
|
189 |
public class SingletonViewInfoComparator implements Comparator { |
|
190 |
/** |
|
191 |
* @see java.util.Comparator#compare(java.lang.Object, |
|
192 |
* java.lang.Object) |
|
193 |
*/ |
|
194 |
public int compare(Object o1, Object o2) { |
|
195 |
try{ |
|
196 |
SingletonViewInfo s1 = (SingletonViewInfo) o1; |
|
197 |
SingletonViewInfo s2 = (SingletonViewInfo) o2; |
|
198 |
|
|
199 |
if ((s1.clase.getName().equals(s2.clase.getName())) && |
|
200 |
(s1.modelo == s2.modelo)) { |
|
201 |
return 0; |
|
202 |
} else { |
|
203 |
return (s1.clase.getName() + s1.modelo + "_").compareTo(s2.clase.getName() + |
|
204 |
s2.modelo); |
|
205 |
} |
|
206 |
}catch(ClassCastException e){ |
|
207 |
e.printStackTrace(); |
|
208 |
return 0; |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
private JInternalFrame getFrame(SingletonViewInfo svi){ |
|
214 |
ViewInfo vi = (ViewInfo) contentViewInfo.get(svi); |
|
215 |
return (JInternalFrame) contentFrame.get(svi); |
|
216 |
} |
|
217 |
|
|
218 |
public JInternalFrame getFrame(Class viewClass, Object model){ |
|
219 |
SingletonViewInfo svi = new SingletonViewInfo(viewClass, model); |
|
220 |
return getFrame(svi); |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* @param model |
|
225 |
* @return |
|
226 |
*/ |
|
227 |
public JInternalFrame[] getFrames(Object model) { |
|
228 |
ArrayList ret = new ArrayList(); |
|
229 |
|
|
230 |
Iterator keys = contentFrame.keySet().iterator(); |
|
231 |
while (keys.hasNext()) { |
|
232 |
SingletonViewInfo svi = (SingletonViewInfo) keys.next(); |
|
233 |
|
|
234 |
if (svi.modelo == model){ |
|
235 |
ret.add(contentFrame.get(svi)); |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
return (JInternalFrame[]) ret.toArray(new JInternalFrame[0]); |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* @param view |
|
244 |
* @return |
|
245 |
*/ |
|
246 |
public JInternalFrame getFrame(SingletonView sv) { |
|
247 |
SingletonViewInfo svi = new SingletonViewInfo(sv.getClass(), sv.getViewModel()); |
|
248 |
return getFrame(svi); |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* @param sv |
|
253 |
* @param i |
|
254 |
*/ |
|
255 |
public void setX(SingletonView sv, int x) { |
|
256 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonViewInfo(sv.getClass(), sv.getViewModel())); |
|
257 |
|
|
258 |
if (o == null) return; |
|
259 |
o.setLocation(x, o.getY()); |
|
260 |
} |
|
261 |
|
|
262 |
/** |
|
263 |
* @param sv |
|
264 |
* @param i |
|
265 |
*/ |
|
266 |
public void setY(SingletonView sv, int y) { |
|
267 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonViewInfo(sv.getClass(), sv.getViewModel())); |
|
268 |
|
|
269 |
if (o == null) return; |
|
270 |
|
|
271 |
o.setLocation(o.getX(), y); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* @param sv |
|
276 |
* @param i |
|
277 |
*/ |
|
278 |
public void setHeight(SingletonView sv, int height) { |
|
279 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonViewInfo(sv.getClass(), sv.getViewModel())); |
|
280 |
|
|
281 |
if (o == null) return; |
|
282 |
|
|
283 |
o.setSize(o.getWidth(), height); |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* @param sv |
|
288 |
* @param i |
|
289 |
*/ |
|
290 |
public void setWidth(SingletonView sv, int width) { |
|
291 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonViewInfo(sv.getClass(), sv.getViewModel())); |
|
292 |
|
|
293 |
if (o == null) return; |
|
294 |
o.setSize(width, o.getHeight()); |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* @param sv |
|
299 |
* @param string |
|
300 |
*/ |
|
301 |
public void setTitle(SingletonView sv, String title) { |
|
302 |
JInternalFrame o = (JInternalFrame) contentFrame.get(new SingletonViewInfo(sv.getClass(), sv.getViewModel())); |
|
303 |
|
|
304 |
if (o == null) return; |
|
305 |
o.setTitle(title); |
|
306 |
} |
|
307 |
} |
|
0 | 308 |
branches/CorePlugin_pilotoDWG/libraries/libCorePlugin/src/com/iver/core/mdiManager/ViewStackSupport.java | ||
---|---|---|
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 java.awt.event.ActionEvent; |
|
44 |
import java.awt.event.ActionListener; |
|
45 |
import java.lang.reflect.InvocationTargetException; |
|
46 |
import java.util.Hashtable; |
|
47 |
import java.util.Vector; |
|
48 |
|
|
49 |
import javax.swing.SwingUtilities; |
|
50 |
|
|
51 |
import com.iver.andami.PluginServices; |
|
52 |
import com.iver.andami.persistence.generate.PluginsStatus; |
|
53 |
import com.iver.andami.plugins.config.generate.Menu; |
|
54 |
import com.iver.andami.ui.mdiManager.View; |
|
55 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
|
56 |
|
|
57 |
/** |
|
58 |
* |
|
59 |
*/ |
|
60 |
public class ViewStackSupport { |
|
61 |
private Vector vistas = new Vector(); |
|
62 |
|
|
63 |
private ViewInfoSupport vis; |
|
64 |
|
|
65 |
private Hashtable viewMenu = new Hashtable(); |
|
66 |
|
|
67 |
/** |
|
68 |
* @param vis |
|
69 |
*/ |
|
70 |
public ViewStackSupport(ViewInfoSupport vis) { |
|
71 |
this.vis = vis; |
|
72 |
} |
|
73 |
|
|
74 |
public void add(View v, final ActionListener listener) { |
|
75 |
vistas.add(v); |
|
76 |
ViewInfo vi = vis.getViewInfo(v); |
|
77 |
int id = vi.getId(); |
|
78 |
Menu m = new Menu(); |
|
79 |
m.setActionCommand(""+id); |
|
80 |
m.setTooltip("activa la ventana"); |
|
81 |
m.setText("ventana/"+vi.getTitle()); |
|
82 |
viewMenu.put(v, m); |
|
83 |
PluginServices.getMainFrame().addMenu(m, listener, PluginServices.getPluginServices(this).getClassLoader() ); |
|
84 |
} |
|
85 |
|
|
86 |
public void remove(View v){ |
|
87 |
Menu m = (Menu) viewMenu.get(v); |
|
88 |
if (m == null) return; |
|
89 |
PluginServices.getMainFrame().removeMenu(m); |
|
90 |
viewMenu.remove(v); |
|
91 |
vistas.remove(v); |
|
92 |
} |
|
93 |
|
|
94 |
public void ctrltab(){ |
|
95 |
View v = (View) vistas.remove(vistas.size() - 1); |
|
96 |
vistas.add(0, v); |
|
97 |
} |
|
98 |
|
|
99 |
public View getActiveView(){ |
|
100 |
if (vistas.size() == 0) return null; |
|
101 |
return (View) vistas.get(vistas.size() - 1); |
|
102 |
} |
|
103 |
} |
|
0 | 104 |
branches/CorePlugin_pilotoDWG/libraries/libCorePlugin/src/com/iver/core/mdiManager/NewSkin.java | ||
---|---|---|
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 java.awt.BorderLayout; |
|
44 |
import java.awt.Component; |
|
45 |
import java.awt.Cursor; |
|
46 |
import java.awt.event.ActionEvent; |
|
47 |
import java.awt.event.ActionListener; |
|
48 |
import java.awt.event.WindowAdapter; |
|
49 |
import java.awt.event.WindowEvent; |
|
50 |
import java.beans.PropertyVetoException; |
|
51 |
import java.util.ArrayList; |
|
52 |
import java.util.Iterator; |
|
53 |
|
|
54 |
import javax.swing.DefaultDesktopManager; |
|
55 |
import javax.swing.DesktopManager; |
|
56 |
import javax.swing.FocusManager; |
|
57 |
import javax.swing.JDesktopPane; |
|
58 |
import javax.swing.JDialog; |
|
59 |
import javax.swing.JInternalFrame; |
|
60 |
import javax.swing.event.InternalFrameEvent; |
|
61 |
import javax.swing.event.InternalFrameListener; |
|
62 |
|
|
63 |
import org.apache.log4j.Logger; |
|
64 |
|
|
65 |
import com.iver.andami.plugins.Extension; |
|
66 |
import com.iver.andami.ui.mdiFrame.GlassPane; |
|
67 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
|
68 |
import com.iver.andami.ui.mdiManager.MDIManager; |
|
69 |
import com.iver.andami.ui.mdiManager.MDIUtilities; |
|
70 |
import com.iver.andami.ui.mdiManager.SingletonDialogAlreadyShownException; |
|
71 |
import com.iver.andami.ui.mdiManager.SingletonView; |
|
72 |
import com.iver.andami.ui.mdiManager.View; |
|
73 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
|
74 |
import com.iver.andami.ui.mdiManager.ViewListener; |
|
75 |
|
|
76 |
|
|
77 |
/** |
|
78 |
* |
|
79 |
*/ |
|
80 |
public class NewSkin implements MDIManager, Extension { |
|
81 |
/** |
|
82 |
* Variable privada <code>desktopManager</code> para usarlo cuando sale una |
|
83 |
* ventana que no queremos que nos restaure las que tenemos maximizadas. |
|
84 |
* Justo antes de usar el setMaximize(false), le pegamos el cambiazo. |
|
85 |
*/ |
|
86 |
private static DesktopManager desktopManager = new DefaultDesktopManager(); |
|
87 |
|
|
88 |
/** log */ |
|
89 |
private static Logger logger = Logger.getLogger(NewSkin.class.getName()); |
|
90 |
|
|
91 |
/** Panel de la MDIFrame */ |
|
92 |
private JDesktopPane panel; |
|
93 |
|
|
94 |
/** MDIFrame */ |
|
95 |
private MDIFrame mainFrame; |
|
96 |
private GlassPane glassPane = new GlassPane(); |
|
97 |
private DialogStackSupport dss; |
|
98 |
private FrameViewSupport fvs; |
|
99 |
private ViewInfoSupport vis; |
|
100 |
private ViewStackSupport vss; |
|
101 |
private SingletonViewSupport svs; |
|
102 |
|
|
103 |
/** |
|
104 |
* @see com.iver.andami.ui.mdiManager.MDIManager#init(com.iver.andami.ui.mdiFrame.MDIFrame) |
|
105 |
*/ |
|
106 |
public void init(MDIFrame f) { |
|
107 |
//Inicializa el Frame y la consola |
|
108 |
mainFrame = f; |
|
109 |
mainFrame.setGlassPane(glassPane); |
|
110 |
panel = mainFrame.getDesktopPane(); |
|
111 |
panel.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); |
|
112 |
|
|
113 |
panel.setDesktopManager(desktopManager); |
|
114 |
|
|
115 |
fvs = new FrameViewSupport(mainFrame); |
|
116 |
dss = new DialogStackSupport(mainFrame); |
|
117 |
svs = new SingletonViewSupport(vis, fvs); |
|
118 |
vis = new ViewInfoSupport(mainFrame, fvs, svs); |
|
119 |
fvs.setVis(vis); |
|
120 |
vss = new ViewStackSupport(vis); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* @see com.iver.andami.ui.mdiManager.MDIManager#addView(com.iver.andami.ui.mdiManager.View) |
|
125 |
*/ |
|
126 |
public View addView(View p) throws SingletonDialogAlreadyShownException { |
|
127 |
//se obtiene la informaci?n de la vista |
|
128 |
ViewInfo vi = vis.getViewInfo(p); |
|
129 |
|
|
130 |
//Se comprueban las incompatibilidades que pudieran haber en la vista |
|
131 |
MDIUtilities.checkViewInfo(vi); |
|
132 |
if ((p instanceof SingletonView) && (vi.isModal())){ |
|
133 |
throw new RuntimeException("A modal view cannot be a SingletonView"); |
|
134 |
} |
|
135 |
|
|
136 |
/* |
|
137 |
* Se obtiene la referencia a la vista anterior por si es una singleton y est? |
|
138 |
* siendo mostrada. Se obtiene su informaci?n si ya fue mostrada |
|
139 |
*/ |
|
140 |
boolean singletonPreviouslyAdded = false; |
|
141 |
|
|
142 |
if (p instanceof SingletonView){ |
|
143 |
SingletonView sv = (SingletonView) p; |
|
144 |
if (svs.registerView(sv.getClass(), sv.getViewModel(), vis.getViewInfo(sv))){ |
|
145 |
singletonPreviouslyAdded = true; |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
if (singletonPreviouslyAdded){ |
|
150 |
//Si la vista no est? actualmente abierta |
|
151 |
if (!svs.contains((SingletonView)p)){ |
|
152 |
JInternalFrame frame = fvs.getJInternalFrame(p); |
|
153 |
svs.openSingletonView((SingletonView)p, frame); |
|
154 |
addJInternalFrame(frame, vi); |
|
155 |
vss.add(p, |
|
156 |
new ActionListener() { |
|
157 |
public void actionPerformed(ActionEvent e) { |
|
158 |
View v = vis.getViewById(Integer.parseInt( |
|
159 |
e.getActionCommand())); |
|
160 |
JInternalFrame f = fvs.getJInternalFrame(v); |
|
161 |
activateJInternalFrame(f); |
|
162 |
} |
|
163 |
}); |
|
164 |
return p; |
|
165 |
}else{ |
|
166 |
//La vista est? actualmente abierta |
|
167 |
JInternalFrame frame = (JInternalFrame) svs.getFrame((SingletonView)p); |
|
168 |
activateJInternalFrame((JInternalFrame) frame); |
|
169 |
return fvs.getView((JInternalFrame) frame); |
|
170 |
} |
|
171 |
} else { |
|
172 |
if (vi.isModal()) { |
|
173 |
addJDialog(p); |
|
174 |
} else { |
|
175 |
//Se sit?a la vista en la pila de vistas |
|
176 |
vss.add(p, |
|
177 |
new ActionListener() { |
|
178 |
public void actionPerformed(ActionEvent e) { |
|
179 |
View v = vis.getViewById(Integer.parseInt( |
|
180 |
e.getActionCommand())); |
|
181 |
JInternalFrame f = fvs.getJInternalFrame(v); |
|
182 |
activateJInternalFrame(f); |
|
183 |
} |
|
184 |
}); |
|
185 |
addJInternalFrame(p); |
|
186 |
} |
|
187 |
|
|
188 |
return p; |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* DOCUMENT ME! |
|
194 |
* |
|
195 |
* @param wnd DOCUMENT ME! |
|
196 |
* @param vi DOCUMENT ME! |
|
197 |
*/ |
|
198 |
private void addJInternalFrame(JInternalFrame wnd, ViewInfo vi) { |
|
199 |
wnd.addInternalFrameListener(new FrameListener()); |
|
200 |
|
|
201 |
wnd.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); |
|
202 |
|
|
203 |
if (vi.isModeless()) { |
|
204 |
panel.add(wnd, JDesktopPane.PALETTE_LAYER); |
|
205 |
} else { |
|
206 |
panel.add(wnd); |
|
207 |
} |
|
208 |
|
|
209 |
activateJInternalFrame(wnd); |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* DOCUMENT ME! |
|
214 |
* |
|
215 |
* @param p |
|
216 |
*/ |
|
217 |
private void addJInternalFrame(View p) { |
|
218 |
ViewInfo vi = vis.getViewInfo(p); |
|
219 |
|
|
220 |
JInternalFrame wnd = fvs.getJInternalFrame(p); |
|
221 |
|
|
222 |
if (p instanceof SingletonView){ |
|
223 |
SingletonView sv = (SingletonView) p; |
|
224 |
svs.openSingletonView(sv, wnd); |
|
225 |
} |
|
226 |
|
|
227 |
addJInternalFrame(wnd, vi); |
|
228 |
} |
|
229 |
|
|
230 |
/** |
|
231 |
* DOCUMENT ME! |
|
232 |
* |
|
233 |
* @param wnd |
|
234 |
*/ |
|
235 |
private void activateJInternalFrame(JInternalFrame wnd) { |
|
236 |
try { |
|
237 |
wnd.moveToFront(); |
|
238 |
wnd.setSelected(true); |
|
239 |
wnd.setIcon(false); |
|
240 |
} catch (PropertyVetoException e) { |
|
241 |
logger.error(e); |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* Situa un di?logo modal en el centro de la pantalla |
|
247 |
* |
|
248 |
* @param d Di?logo que se quiere situar |
|
249 |
*/ |
|
250 |
private void centerDialog(JDialog d) { |
|
251 |
int offSetX = d.getWidth() / 2; |
|
252 |
int offSetY = d.getHeight() / 2; |
|
253 |
|
|
254 |
d.setLocation((mainFrame.getWidth() / 2) - offSetX, |
|
255 |
(mainFrame.getHeight() / 2) - offSetY); |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* DOCUMENT ME! |
|
260 |
* |
|
261 |
* @param p |
|
262 |
*/ |
|
263 |
private void addJDialog(View p) { |
|
264 |
JDialog dlg = fvs.getJDialog(p); |
|
265 |
|
|
266 |
centerDialog(dlg); |
|
267 |
|
|
268 |
dlg.addWindowListener(new DialogWindowListener()); |
|
269 |
dss.pushDialog(dlg); |
|
270 |
|
|
271 |
dlg.setVisible(vis.getViewInfo(p).isVisible()); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getActiveView() |
|
276 |
*/ |
|
277 |
public View getActiveView() { |
|
278 |
JInternalFrame jif = panel.getSelectedFrame(); |
|
279 |
|
|
280 |
if (jif != null) { |
|
281 |
return fvs.getView(jif); |
|
282 |
} |
|
283 |
|
|
284 |
return null; |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeView(com.iver.andami.ui.mdiManager.View) |
|
289 |
*/ |
|
290 |
public void closeView(View p) { |
|
291 |
//Si es un di?logo modal |
|
292 |
if (p.getViewInfo().isModal()) { |
|
293 |
closeJDialog(); |
|
294 |
} else { //Si no es modal se cierra el JInternalFrame |
|
295 |
closeJInternalFrame(fvs.getJInternalFrame(p)); |
|
296 |
} |
|
297 |
} |
|
298 |
|
|
299 |
/** |
|
300 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeAllViews() |
|
301 |
*/ |
|
302 |
public void closeAllViews() { |
|
303 |
ArrayList eliminar = new ArrayList(); |
|
304 |
Iterator i = fvs.getViewIterator(); |
|
305 |
|
|
306 |
while (i.hasNext()) { |
|
307 |
eliminar.add((View) i.next()); |
|
308 |
} |
|
309 |
|
|
310 |
for (Iterator iter = eliminar.iterator(); iter.hasNext();) { |
|
311 |
View vista = (View) iter.next(); |
|
312 |
closeView(vista); |
|
313 |
} |
|
314 |
} |
|
315 |
|
|
316 |
/** |
|
317 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getViewInfo(com.iver.andami.ui.mdiManager.View) |
|
318 |
*/ |
|
319 |
public ViewInfo getViewInfo(View v) { |
|
320 |
return vis.getViewInfo(v); |
|
321 |
} |
|
322 |
|
|
323 |
/** |
|
324 |
* DOCUMENT ME! |
|
325 |
* |
|
326 |
* @param dialog |
|
327 |
* |
|
328 |
* @throws RuntimeException DOCUMENT ME! |
|
329 |
*/ |
|
330 |
private void closeJDialog() { |
|
331 |
JDialog dlg = dss.popDialog(); |
|
332 |
|
|
333 |
dlg.setVisible(false); |
|
334 |
|
|
335 |
View s = (View) fvs.getView(dlg); |
|
336 |
|
|
337 |
callViewClosed(s); |
|
338 |
|
|
339 |
fvs.closeView(s); |
|
340 |
|
|
341 |
//Si es singleton se desasocia el modelo con la vista |
|
342 |
if (s instanceof SingletonView) { |
|
343 |
svs.closeView((SingletonView) s); |
|
344 |
} |
|
345 |
} |
|
346 |
|
|
347 |
/** |
|
348 |
* DOCUMENT ME! |
|
349 |
* |
|
350 |
* @param view DOCUMENT ME! |
|
351 |
*/ |
|
352 |
private void callViewClosed(View view) { |
|
353 |
if (view instanceof ViewListener) { |
|
354 |
((ViewListener) view).viewClosed(); |
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* DOCUMENT ME! |
|
360 |
* |
|
361 |
* @param view DOCUMENT ME! |
|
362 |
*/ |
|
363 |
private void callViewActivated(View view) { |
|
364 |
if (view instanceof ViewListener) { |
|
365 |
((ViewListener) view).viewActivated(); |
|
366 |
} |
|
367 |
} |
|
368 |
|
|
369 |
/** |
|
370 |
* DOCUMENT ME! |
|
371 |
* |
|
372 |
* @param frame |
|
373 |
*/ |
|
374 |
private void closeJInternalFrame(JInternalFrame frame) { |
|
375 |
try { |
|
376 |
View s = (View) fvs.getView(frame); |
|
377 |
|
|
378 |
frame.setClosed(true); |
|
379 |
callViewClosed(s); |
|
380 |
} catch (PropertyVetoException e) { |
|
381 |
logger.error("Not compatible with property veto's. Use ViewInfo instead.", |
|
382 |
e); |
|
383 |
} |
|
384 |
} |
|
385 |
|
|
386 |
/** |
|
387 |
* @see com.iver.andami.plugins.Extension#inicializar() |
|
388 |
*/ |
|
389 |
public void inicializar() { |
|
390 |
} |
|
391 |
|
|
392 |
/** |
|
393 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String) |
|
394 |
*/ |
|
395 |
public void execute(String actionCommand) { |
|
396 |
if (actionCommand.equals("cascada")) { |
|
397 |
} else if (actionCommand.equals("mosaico")) { |
|
398 |
} |
|
399 |
} |
|
400 |
|
|
401 |
/** |
|
402 |
* @see com.iver.andami.plugins.Extension#isEnabled() |
|
403 |
*/ |
|
404 |
public boolean isEnabled() { |
|
405 |
// TODO Auto-generated method stub |
|
406 |
return false; |
|
407 |
} |
|
408 |
|
|
409 |
/** |
|
410 |
* @see com.iver.andami.plugins.Extension#isVisible() |
|
411 |
*/ |
|
412 |
public boolean isVisible() { |
|
413 |
// TODO Auto-generated method stub |
|
414 |
return true; |
|
415 |
} |
|
416 |
|
|
417 |
/** |
|
418 |
* @see com.iver.andami.ui.mdiManager.MDIManager#setWaitCursor() |
|
419 |
*/ |
|
420 |
public void setWaitCursor() { |
|
421 |
if (mainFrame != null) { |
|
422 |
glassPane.setVisible(true); |
|
423 |
mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
|
424 |
dss.setWaitCursor(); |
|
425 |
} |
|
426 |
} |
|
427 |
|
|
428 |
/** |
|
429 |
* @see com.iver.andami.ui.mdiManager.MDIManager#restoreCursor() |
|
430 |
*/ |
|
431 |
public void restoreCursor() { |
|
432 |
if (mainFrame != null) { |
|
433 |
glassPane.setVisible(false); |
|
434 |
mainFrame.setCursor(null); |
|
435 |
dss.restoreCursor(); |
|
436 |
} |
|
437 |
} |
|
438 |
|
|
439 |
/** |
|
440 |
* Listener para los eventos de cerrado de los di?logos. Tiene su raz?n de |
|
441 |
* ser en que los di?logos han de devolverse al pool cuando se cierran |
|
442 |
* |
|
443 |
* @author Fernando Gonz?lez Cort?s |
|
444 |
*/ |
|
445 |
public class DialogWindowListener extends WindowAdapter { |
|
446 |
/** |
|
447 |
* Captura el evento de cerrado de los di?logos con el fin de realizar |
|
448 |
* tareas de mantenimiento |
|
449 |
* |
|
450 |
* @param e evento |
|
451 |
*/ |
|
452 |
public void windowClosing(WindowEvent e) { |
|
453 |
closeJDialog(); |
|
454 |
} |
|
455 |
} |
|
456 |
|
|
457 |
/** |
|
458 |
* DOCUMENT ME! |
|
459 |
*/ |
|
460 |
public class FrameListener implements InternalFrameListener { |
|
461 |
/** |
|
462 |
* @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent) |
|
463 |
*/ |
|
464 |
public void internalFrameActivated(InternalFrameEvent e) { |
|
465 |
View panel = fvs.getView((JInternalFrame) e.getSource()); |
|
466 |
ViewInfo vi = vis.getViewInfo(panel); |
|
467 |
|
|
468 |
JInternalFrame frame = fvs.getJInternalFrame(panel); |
|
469 |
|
|
470 |
if (!frame.isMaximizable() && frame.isMaximum()) { |
|
471 |
try { |
|
472 |
frame.setMaximum(false); |
|
473 |
} catch (PropertyVetoException e1) { |
|
474 |
} |
|
475 |
} |
|
476 |
mainFrame.enableControls(); |
|
477 |
callViewActivated(panel); |
|
478 |
|
|
479 |
|
|
480 |
} |
|
481 |
|
|
482 |
/** |
|
483 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent) |
|
484 |
*/ |
|
485 |
public void internalFrameClosed(InternalFrameEvent e) { |
|
486 |
} |
|
487 |
|
|
488 |
/** |
|
489 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent) |
|
490 |
*/ |
|
491 |
public void internalFrameClosing(InternalFrameEvent e) { |
|
492 |
// Se elimina la memoria del JInternalFrame si no es ALWAYS_LIVE |
|
493 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
|
494 |
ViewInfo vi = vis.getViewInfo((View) fvs.getView(c)); |
|
495 |
|
|
496 |
View view = fvs.getView(c); |
|
497 |
|
|
498 |
boolean alwaysLive; |
|
499 |
if (view instanceof SingletonView) { |
|
500 |
svs.closeView((SingletonView) view); |
|
501 |
} |
|
502 |
|
|
503 |
fvs.closeView(view); |
|
504 |
|
|
505 |
panel.remove(c); |
|
506 |
|
|
507 |
vss.remove(view); |
|
508 |
|
|
509 |
mainFrame.enableControls(); |
|
510 |
|
|
511 |
panel.repaint(); |
|
512 |
} |
|
513 |
|
|
514 |
/** |
|
515 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent) |
|
516 |
*/ |
|
517 |
public void internalFrameDeactivated(InternalFrameEvent e) { |
|
518 |
} |
|
519 |
|
|
520 |
/** |
|
521 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent) |
|
522 |
*/ |
|
523 |
public void internalFrameDeiconified(InternalFrameEvent e) { |
|
524 |
mainFrame.enableControls(); |
|
525 |
} |
|
526 |
|
|
527 |
/** |
|
528 |
* @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent) |
|
529 |
*/ |
|
530 |
public void internalFrameIconified(InternalFrameEvent e) { |
|
531 |
mainFrame.enableControls(); |
|
532 |
} |
|
533 |
|
|
534 |
/** |
|
535 |
* @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent) |
|
536 |
*/ |
|
537 |
public void internalFrameOpened(InternalFrameEvent e) { |
|
538 |
} |
|
539 |
} |
|
540 |
|
|
541 |
/** |
|
542 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonView(java.lang.Class, java.lang.Object) |
|
543 |
*/ |
|
544 |
public boolean closeSingletonView(Class viewClass, Object model) { |
|
545 |
JInternalFrame frame = svs.getFrame(viewClass, model); |
|
546 |
if (frame == null) return false; |
|
547 |
closeJInternalFrame(frame); |
|
548 |
return true; |
|
549 |
} |
|
550 |
|
|
551 |
/** |
|
552 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonView(java.lang.Object) |
|
553 |
*/ |
|
554 |
public boolean closeSingletonView(Object model) { |
|
555 |
JInternalFrame[] frames = svs.getFrames(model); |
|
556 |
if (frames.length == 0) return false; |
|
557 |
for (int i = 0; i < frames.length; i++) { |
|
558 |
closeJInternalFrame(frames[i]); |
|
559 |
} |
|
560 |
return true; |
|
561 |
} |
|
562 |
} |
|
0 | 563 |
branches/CorePlugin_pilotoDWG/libraries/libCorePlugin/src/com/iver/core/mdiManager/DialogStackSupport.java | ||
---|---|---|
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 java.awt.Cursor; |
|
44 |
import java.util.ArrayList; |
|
45 |
import java.util.Iterator; |
|
46 |
|
|
47 |
import javax.swing.JDialog; |
|
48 |
|
|
49 |
import org.apache.log4j.Logger; |
|
50 |
|
|
51 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
|
52 |
|
|
53 |
|
|
54 |
/** |
|
55 |
* |
|
56 |
*/ |
|
57 |
public class DialogStackSupport{ |
|
58 |
/** log */ |
|
59 |
private static Logger logger = Logger.getLogger(DialogStackSupport.class.getName()); |
|
60 |
|
|
61 |
/** Pila de di?logos modales mostrados */ |
|
62 |
private ArrayList dialogStack = new ArrayList(0); |
|
63 |
|
|
64 |
public DialogStackSupport(MDIFrame frame){ |
|
65 |
} |
|
66 |
|
|
67 |
public void pushDialog(JDialog dlg){ |
|
68 |
dialogStack.add(dlg); |
|
69 |
} |
|
70 |
|
|
71 |
public JDialog popDialog(){ |
|
72 |
return (JDialog) dialogStack.remove(dialogStack.size() - 1); |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* @return |
|
77 |
*/ |
|
78 |
public void setWaitCursor() { |
|
79 |
for (Iterator iter = dialogStack.iterator(); iter.hasNext();) { |
|
80 |
JDialog dlg = (JDialog) iter.next(); |
|
81 |
dlg.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
|
82 |
dlg.getGlassPane().setVisible(true); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/** |
|
87 |
* |
|
88 |
*/ |
|
89 |
public void restoreCursor() { |
|
90 |
for (Iterator iter = dialogStack.iterator(); iter.hasNext();) { |
|
91 |
JDialog dlg = (JDialog) iter.next(); |
|
92 |
dlg.setCursor(null); |
|
93 |
dlg.getGlassPane().setVisible(false); |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
0 | 97 |
branches/CorePlugin_pilotoDWG/libraries/libCorePlugin/src/com/iver/core/mdiManager/FrameViewSupport.java | ||
---|---|---|
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 java.awt.Component; |
|
44 |
import java.awt.Image; |
|
45 |
import java.util.Hashtable; |
|
46 |
import java.util.Iterator; |
|
47 |
|
|
48 |
import javax.swing.ImageIcon; |
|
49 |
import javax.swing.JDialog; |
|
50 |
import javax.swing.JFrame; |
|
51 |
import javax.swing.JInternalFrame; |
|
52 |
import javax.swing.JPanel; |
|
53 |
|
|
54 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
|
55 |
import com.iver.andami.ui.mdiManager.View; |
|
56 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
|
57 |
|
|
58 |
|
|
59 |
/** |
|
60 |
* |
|
61 |
*/ |
|
62 |
public class FrameViewSupport { |
|
63 |
private Hashtable frameView = new Hashtable(); |
|
64 |
private Hashtable viewFrame = new Hashtable(); |
|
65 |
private Image icon; |
|
66 |
private ViewInfoSupport vis; |
|
67 |
private JFrame mainFrame; |
|
68 |
|
|
69 |
/** |
|
70 |
* Creates a new FrameViewSupport object. |
|
71 |
* |
|
72 |
* @param i DOCUMENT ME! |
|
73 |
*/ |
|
74 |
public FrameViewSupport(MDIFrame mainFrame) { |
|
75 |
this.mainFrame = mainFrame; |
|
76 |
icon = mainFrame.getIconImage(); |
|
77 |
} |
|
78 |
|
|
79 |
public Iterator getViewIterator(){ |
|
80 |
return viewFrame.keySet().iterator(); |
|
81 |
} |
|
82 |
|
|
83 |
public boolean contains(View v){ |
|
84 |
return viewFrame.containsKey(v); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* @param wnd |
|
89 |
* @return |
|
90 |
*/ |
|
91 |
public boolean contains(JInternalFrame wnd) { |
|
92 |
return frameView.contains(wnd); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* DOCUMENT ME! |
|
97 |
* |
|
98 |
* @param p DOCUMENT ME! |
|
99 |
* |
|
100 |
* @return DOCUMENT ME! |
|
101 |
*/ |
|
102 |
public JDialog getJDialog(View p) { |
|
103 |
JDialog dlg = (JDialog) viewFrame.get(p); |
|
104 |
|
|
105 |
if (dlg == null) { |
|
106 |
ViewInfo vi = vis.getViewInfo(p); |
|
107 |
JDialog nuevo = new JDialog(mainFrame); |
|
108 |
|
|
109 |
nuevo.getContentPane().add((JPanel) p); |
|
110 |
nuevo.setSize(getWidth(p), getHeight(p) + 30); |
|
111 |
nuevo.setTitle(vi.getTitle()); |
|
112 |
nuevo.setResizable(vi.isResizable()); |
|
113 |
|
|
114 |
viewFrame.put(p, nuevo); |
|
115 |
frameView.put(nuevo, p); |
|
116 |
|
|
117 |
nuevo.setModal(vi.isModal()); |
|
118 |
return nuevo; |
|
119 |
} else { |
|
120 |
return dlg; |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* DOCUMENT ME! |
|
126 |
* |
|
127 |
* @param p DOCUMENT ME! |
|
128 |
* |
|
129 |
* @return DOCUMENT ME! |
|
130 |
*/ |
|
131 |
public JInternalFrame getJInternalFrame(View p) { |
|
132 |
JInternalFrame frame = (JInternalFrame) viewFrame.get(p); |
|
133 |
|
|
134 |
if (frame == null) { |
|
135 |
ViewInfo vi = vis.getViewInfo(p); |
|
136 |
JInternalFrame nuevo = new JInternalFrame(); |
|
137 |
if (icon != null){ |
|
138 |
nuevo.setFrameIcon(new ImageIcon(icon)); |
|
139 |
} |
|
140 |
nuevo.getContentPane().add((JPanel) p); |
|
141 |
nuevo.setClosable(true); |
|
142 |
nuevo.setSize(getWidth(p), getHeight(p)); |
|
143 |
nuevo.setTitle(vi.getTitle()); |
|
144 |
nuevo.setVisible(vi.isVisible()); |
|
145 |
nuevo.setResizable(vi.isResizable()); |
|
146 |
nuevo.setIconifiable(vi.isIconifiable()); |
|
147 |
nuevo.setMaximizable(vi.isMaximizable()); |
|
148 |
nuevo.setLocation(vi.getX(), vi.getY()); |
|
149 |
|
|
150 |
nuevo.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); |
|
151 |
|
|
152 |
viewFrame.put(p, nuevo); |
|
153 |
frameView.put(nuevo, p); |
|
154 |
|
|
155 |
return nuevo; |
|
156 |
} else { |
|
157 |
return frame; |
|
158 |
} |
|
159 |
} |
|
160 |
|
|
161 |
public View getView(Component dlg){ |
|
162 |
return (View) frameView.get(dlg); |
|
163 |
} |
|
164 |
|
|
165 |
public void closeView(View v){ |
|
166 |
Object c = viewFrame.remove(v); |
|
167 |
frameView.remove(c); |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* DOCUMENT ME! |
|
172 |
* |
|
173 |
* @param v DOCUMENT ME! |
|
174 |
* @param x DOCUMENT ME! |
|
175 |
*/ |
|
176 |
public void setX(View v, int x) { |
|
177 |
JInternalFrame o = (JInternalFrame) viewFrame.get(v); |
|
178 |
o.setLocation(x, o.getY()); |
|
179 |
} |
|
180 |
|
|
181 |
/** |
|
182 |
* DOCUMENT ME! |
|
183 |
* |
|
184 |
* @param v DOCUMENT ME! |
|
185 |
* @param y DOCUMENT ME! |
|
186 |
*/ |
|
187 |
public void setY(View v, int y) { |
|
188 |
JInternalFrame o = (JInternalFrame) viewFrame.get(v); |
|
189 |
|
|
190 |
o.setLocation(o.getX(), y); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* DOCUMENT ME! |
|
195 |
* |
|
196 |
* @param v DOCUMENT ME! |
|
197 |
* @param height DOCUMENT ME! |
|
198 |
*/ |
|
199 |
public void setHeight(View v, int height) { |
|
200 |
JInternalFrame o = (JInternalFrame) viewFrame.get(v); |
|
201 |
|
|
202 |
o.setSize(o.getWidth(), height); |
|
203 |
} |
|
204 |
|
|
205 |
/** |
|
206 |
* DOCUMENT ME! |
|
207 |
* |
|
208 |
* @param v DOCUMENT ME! |
|
209 |
* @param width DOCUMENT ME! |
|
210 |
*/ |
|
211 |
public void setWidth(View v, int width) { |
|
212 |
JInternalFrame o = (JInternalFrame) viewFrame.get(v); |
|
213 |
|
|
214 |
o.setSize(width, o.getHeight()); |
|
215 |
} |
|
216 |
|
|
217 |
/** |
|
218 |
* DOCUMENT ME! |
|
219 |
* |
|
220 |
* @param v DOCUMENT ME! |
|
221 |
* @param title DOCUMENT ME! |
|
222 |
*/ |
|
223 |
public void setTitle(View v, String title) { |
|
224 |
JInternalFrame o = (JInternalFrame) viewFrame.get(v); |
|
225 |
o.setTitle(title); |
|
226 |
} |
|
227 |
|
|
228 |
/** |
|
229 |
* DOCUMENT ME! |
|
230 |
* |
|
231 |
* @param vis The vis to set. |
|
232 |
*/ |
|
233 |
public void setVis(ViewInfoSupport vis) { |
|
234 |
this.vis = vis; |
|
235 |
} |
|
236 |
|
|
237 |
/** |
|
238 |
* DOCUMENT ME! |
|
239 |
* |
|
240 |
* @param v DOCUMENT ME! |
|
241 |
* |
|
242 |
* @return DOCUMENT ME! |
|
243 |
*/ |
|
244 |
private int getWidth(View v) { |
|
245 |
ViewInfo vi = vis.getViewInfo(v); |
|
246 |
|
|
247 |
if (vi.getWidth() == -1) { |
|
248 |
JPanel p = (JPanel) v; |
|
249 |
|
|
250 |
return p.getSize().width; |
|
251 |
} else { |
|
252 |
return vi.getWidth(); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
/** |
|
257 |
* DOCUMENT ME! |
|
258 |
* |
|
259 |
* @param v DOCUMENT ME! |
|
260 |
* |
|
261 |
* @return DOCUMENT ME! |
|
262 |
*/ |
|
263 |
private int getHeight(View v) { |
|
264 |
ViewInfo vi = vis.getViewInfo(v); |
|
265 |
|
|
266 |
if (vi.getHeight() == -1) { |
|
267 |
JPanel p = (JPanel) v; |
|
268 |
|
|
269 |
return p.getSize().height; |
|
270 |
} else { |
|
271 |
return vi.getHeight(); |
|
272 |
} |
|
273 |
} |
|
274 |
} |
|
0 | 275 |
branches/CorePlugin_pilotoDWG/libraries/libCorePlugin/src/com/iver/core/mdiManager/ViewInfoSupport.java | ||
---|---|---|
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.View; |
|
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 |
* |
Also available in: Unified diff