svn-gvsig-desktop / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / NewSkin.java @ 951
History | View | Annotate | Download (11.5 KB)
1 |
package com.iver.core.mdiManager; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Cursor; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.awt.event.WindowAdapter; |
8 |
import java.awt.event.WindowEvent; |
9 |
import java.beans.PropertyVetoException; |
10 |
import java.util.ArrayList; |
11 |
import java.util.Iterator; |
12 |
|
13 |
import javax.swing.DefaultDesktopManager; |
14 |
import javax.swing.DesktopManager; |
15 |
import javax.swing.JDesktopPane; |
16 |
import javax.swing.JDialog; |
17 |
import javax.swing.JInternalFrame; |
18 |
import javax.swing.event.InternalFrameEvent; |
19 |
import javax.swing.event.InternalFrameListener; |
20 |
|
21 |
import org.apache.log4j.Logger; |
22 |
|
23 |
import com.iver.andami.plugins.Extension; |
24 |
import com.iver.andami.ui.mdiFrame.GlassPane; |
25 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
26 |
import com.iver.andami.ui.mdiManager.MDIManager; |
27 |
import com.iver.andami.ui.mdiManager.MDIUtilities; |
28 |
import com.iver.andami.ui.mdiManager.SingletonDialogAlreadyShownException; |
29 |
import com.iver.andami.ui.mdiManager.SingletonView; |
30 |
import com.iver.andami.ui.mdiManager.View; |
31 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
32 |
import com.iver.andami.ui.mdiManager.ViewListener; |
33 |
|
34 |
|
35 |
/**
|
36 |
*
|
37 |
*/
|
38 |
public class NewSkin implements MDIManager, Extension { |
39 |
/**
|
40 |
* Variable privada <code>desktopManager</code> para usarlo cuando sale una
|
41 |
* ventana que no queremos que nos restaure las que tenemos maximizadas.
|
42 |
* Justo antes de usar el setMaximize(false), le pegamos el cambiazo.
|
43 |
*/
|
44 |
private static DesktopManager desktopManager = new DefaultDesktopManager(); |
45 |
|
46 |
/** log */
|
47 |
private static Logger logger = Logger.getLogger(NewSkin.class.getName()); |
48 |
|
49 |
/** Panel de la MDIFrame */
|
50 |
private JDesktopPane panel = new JDesktopPane(); |
51 |
|
52 |
/** MDIFrame */
|
53 |
private MDIFrame mainFrame;
|
54 |
private GlassPane glassPane = new GlassPane(); |
55 |
private DialogStackSupport dss;
|
56 |
private FrameViewSupport fvs;
|
57 |
private ViewInfoSupport vis;
|
58 |
private ViewStackSupport vss;
|
59 |
private SingletonViewSupport svs;
|
60 |
|
61 |
/**
|
62 |
* @see com.iver.andami.ui.mdiManager.MDIManager#init(com.iver.andami.ui.mdiFrame.MDIFrame)
|
63 |
*/
|
64 |
public void init(MDIFrame f) { |
65 |
//Inicializa el Frame y la consola
|
66 |
mainFrame = f; |
67 |
mainFrame.setGlassPane(glassPane); |
68 |
panel.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
|
69 |
|
70 |
mainFrame.getContentPane().add(panel, BorderLayout.CENTER);
|
71 |
panel.setDesktopManager(desktopManager); |
72 |
|
73 |
fvs = new FrameViewSupport(mainFrame);
|
74 |
dss = new DialogStackSupport(mainFrame);
|
75 |
vis = new ViewInfoSupport(fvs);
|
76 |
fvs.setVis(vis); |
77 |
vss = new ViewStackSupport(vis);
|
78 |
svs = new SingletonViewSupport(vis, fvs);
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* @see com.iver.andami.ui.mdiManager.MDIManager#addView(com.iver.andami.ui.mdiManager.View)
|
83 |
*/
|
84 |
public View addView(View p) throws SingletonDialogAlreadyShownException { |
85 |
//se obtiene la informaci?n de la vista
|
86 |
ViewInfo vi = vis.getViewInfo(p); |
87 |
|
88 |
//Se comprueban las incompatibilidades que pudieran haber en la vista
|
89 |
MDIUtilities.checkViewInfo(vi); |
90 |
|
91 |
/*
|
92 |
* Se obtiene la referencia a la vista anterior por si es una singleton y est?
|
93 |
* siendo mostrada. Se obtiene su informaci?n si ya fue mostrada
|
94 |
*/
|
95 |
View anterior = svs.getView(p);
|
96 |
|
97 |
if (anterior != p) {
|
98 |
vis.deleteViewInfo(p); |
99 |
vi = vis.getViewInfo(anterior); |
100 |
|
101 |
if (!fvs.contains(p)){
|
102 |
JInternalFrame frame = fvs.getJInternalFrame(p);
|
103 |
addJInternalFrame(frame, vi); |
104 |
}else{
|
105 |
JInternalFrame frame = fvs.getJInternalFrame(anterior);
|
106 |
activateJInternalFrame(frame); |
107 |
} |
108 |
|
109 |
return anterior;
|
110 |
} else {
|
111 |
if (vi.isModal()) {
|
112 |
addJDialog(anterior); |
113 |
} else {
|
114 |
//Se sit?a la vista en la pila de vistas
|
115 |
vss.add(p, |
116 |
new ActionListener() { |
117 |
public void actionPerformed(ActionEvent e) { |
118 |
View v = vis.getViewById(Integer.parseInt( |
119 |
e.getActionCommand())); |
120 |
JInternalFrame f = fvs.getJInternalFrame(v);
|
121 |
activateJInternalFrame(f); |
122 |
} |
123 |
}); |
124 |
addJInternalFrame(anterior); |
125 |
} |
126 |
|
127 |
return p;
|
128 |
} |
129 |
} |
130 |
|
131 |
/**
|
132 |
* DOCUMENT ME!
|
133 |
*
|
134 |
* @param wnd DOCUMENT ME!
|
135 |
* @param vi DOCUMENT ME!
|
136 |
*/
|
137 |
private void addJInternalFrame(JInternalFrame wnd, ViewInfo vi) { |
138 |
wnd.addInternalFrameListener(new FrameListener());
|
139 |
|
140 |
wnd.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
141 |
|
142 |
if (vi.isModeless()) {
|
143 |
panel.add(wnd, JDesktopPane.PALETTE_LAYER);
|
144 |
} else {
|
145 |
panel.add(wnd); |
146 |
} |
147 |
|
148 |
activateJInternalFrame(wnd); |
149 |
} |
150 |
|
151 |
/**
|
152 |
* DOCUMENT ME!
|
153 |
*
|
154 |
* @param p
|
155 |
*/
|
156 |
private void addJInternalFrame(View p) { |
157 |
ViewInfo vi = vis.getViewInfo(p); |
158 |
|
159 |
JInternalFrame wnd = fvs.getJInternalFrame(p);
|
160 |
|
161 |
addJInternalFrame(wnd, vi); |
162 |
} |
163 |
|
164 |
/**
|
165 |
* DOCUMENT ME!
|
166 |
*
|
167 |
* @param wnd
|
168 |
*/
|
169 |
private void activateJInternalFrame(JInternalFrame wnd) { |
170 |
try {
|
171 |
wnd.moveToFront(); |
172 |
wnd.setSelected(true);
|
173 |
wnd.setIcon(false);
|
174 |
} catch (PropertyVetoException e) { |
175 |
logger.error(e); |
176 |
} |
177 |
} |
178 |
|
179 |
/**
|
180 |
* Situa un di?logo modal en el centro de la pantalla
|
181 |
*
|
182 |
* @param d Di?logo que se quiere situar
|
183 |
*/
|
184 |
private void centerDialog(JDialog d) { |
185 |
int offSetX = d.getWidth() / 2; |
186 |
int offSetY = d.getHeight() / 2; |
187 |
|
188 |
d.setLocation((mainFrame.getWidth() / 2) - offSetX,
|
189 |
(mainFrame.getHeight() / 2) - offSetY);
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* DOCUMENT ME!
|
194 |
*
|
195 |
* @param p
|
196 |
*/
|
197 |
private void addJDialog(View p) { |
198 |
JDialog dlg = fvs.getJDialog(p);
|
199 |
|
200 |
centerDialog(dlg); |
201 |
|
202 |
dlg.addWindowListener(new DialogWindowListener());
|
203 |
dss.pushDialog(dlg); |
204 |
|
205 |
dlg.setVisible(vis.getViewInfo(p).isVisible()); |
206 |
} |
207 |
|
208 |
/**
|
209 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getActiveView()
|
210 |
*/
|
211 |
public View getActiveView() { |
212 |
JInternalFrame jif = panel.getSelectedFrame();
|
213 |
|
214 |
if (jif != null) { |
215 |
return fvs.getView(jif);
|
216 |
} |
217 |
|
218 |
return null; |
219 |
} |
220 |
|
221 |
/**
|
222 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeView(com.iver.andami.ui.mdiManager.View)
|
223 |
*/
|
224 |
public void closeView(View p) { |
225 |
//Si es un di?logo modal
|
226 |
if (p.getViewInfo().isModal()) {
|
227 |
closeJDialog(fvs.getJDialog(p)); |
228 |
} else { //Si no es modal se cierra el JInternalFrame |
229 |
closeJInternalFrame(fvs.getJInternalFrame(p)); |
230 |
} |
231 |
} |
232 |
|
233 |
/**
|
234 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeAllViews()
|
235 |
*/
|
236 |
public void closeAllViews() { |
237 |
ArrayList eliminar = new ArrayList(); |
238 |
Iterator i = fvs.getViewIterator();
|
239 |
|
240 |
while (i.hasNext()) {
|
241 |
eliminar.add((View) i.next());
|
242 |
} |
243 |
|
244 |
for (Iterator iter = eliminar.iterator(); iter.hasNext();) { |
245 |
View vista = (View) iter.next(); |
246 |
closeView(vista); |
247 |
} |
248 |
} |
249 |
|
250 |
/**
|
251 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getViewInfo(com.iver.andami.ui.mdiManager.View)
|
252 |
*/
|
253 |
public ViewInfo getViewInfo(View v) { |
254 |
return vis.getViewInfo(v);
|
255 |
} |
256 |
|
257 |
/**
|
258 |
* DOCUMENT ME!
|
259 |
*
|
260 |
* @param dialog
|
261 |
*
|
262 |
* @throws RuntimeException DOCUMENT ME!
|
263 |
*/
|
264 |
private void closeJDialog(JDialog dialog) { |
265 |
JDialog dlg = dss.popDialog();
|
266 |
|
267 |
if (dlg != dialog) {
|
268 |
throw new RuntimeException( |
269 |
"S?lo se puede cerrar el ?ltimo di?logo modal abierto");
|
270 |
} |
271 |
|
272 |
dlg.setVisible(false);
|
273 |
|
274 |
View s = (View) fvs.getView(dlg); |
275 |
|
276 |
callViewClosed(s); |
277 |
|
278 |
fvs.closeView(s); |
279 |
|
280 |
//Si es singleton se desasocia el modelo con la vista
|
281 |
if (s instanceof SingletonView) { |
282 |
svs.closeView((SingletonView) s); |
283 |
} |
284 |
} |
285 |
|
286 |
/**
|
287 |
* DOCUMENT ME!
|
288 |
*
|
289 |
* @param view DOCUMENT ME!
|
290 |
*/
|
291 |
private void callViewClosed(View view) { |
292 |
if (view instanceof ViewListener) { |
293 |
((ViewListener) view).viewClosed(); |
294 |
} |
295 |
} |
296 |
|
297 |
/**
|
298 |
* DOCUMENT ME!
|
299 |
*
|
300 |
* @param view DOCUMENT ME!
|
301 |
*/
|
302 |
private void callViewActivated(View view) { |
303 |
if (view instanceof ViewListener) { |
304 |
((ViewListener) view).viewActivated(); |
305 |
} |
306 |
} |
307 |
|
308 |
/**
|
309 |
* DOCUMENT ME!
|
310 |
*
|
311 |
* @param frame
|
312 |
*/
|
313 |
private void closeJInternalFrame(JInternalFrame frame) { |
314 |
try {
|
315 |
View s = (View) fvs.getView(frame); |
316 |
|
317 |
frame.setClosed(true);
|
318 |
callViewClosed(s); |
319 |
|
320 |
//Si es singleton se desasocia el modelo con la vista
|
321 |
if (s instanceof SingletonView) { |
322 |
svs.closeView((SingletonView) s); |
323 |
} |
324 |
|
325 |
vss.remove(s); |
326 |
} catch (PropertyVetoException e) { |
327 |
logger.error("Not compatible with property veto's. Use ViewInfo instead.",
|
328 |
e); |
329 |
} |
330 |
} |
331 |
|
332 |
/**
|
333 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
334 |
*/
|
335 |
public void inicializar() { |
336 |
} |
337 |
|
338 |
/**
|
339 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
340 |
*/
|
341 |
public void execute(String actionCommand) { |
342 |
if (actionCommand.equals("cascada")) { |
343 |
} else if (actionCommand.equals("mosaico")) { |
344 |
} |
345 |
} |
346 |
|
347 |
/**
|
348 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
349 |
*/
|
350 |
public boolean isEnabled() { |
351 |
// TODO Auto-generated method stub
|
352 |
return false; |
353 |
} |
354 |
|
355 |
/**
|
356 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
357 |
*/
|
358 |
public boolean isVisible() { |
359 |
// TODO Auto-generated method stub
|
360 |
return true; |
361 |
} |
362 |
|
363 |
/**
|
364 |
* @see com.iver.andami.ui.mdiManager.MDIManager#setWaitCursor()
|
365 |
*/
|
366 |
public void setWaitCursor() { |
367 |
if (mainFrame != null) { |
368 |
glassPane.setVisible(true);
|
369 |
mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
370 |
dss.setWaitCursor(); |
371 |
} |
372 |
} |
373 |
|
374 |
/**
|
375 |
* @see com.iver.andami.ui.mdiManager.MDIManager#restoreCursor()
|
376 |
*/
|
377 |
public void restoreCursor() { |
378 |
if (mainFrame != null) { |
379 |
glassPane.setVisible(false);
|
380 |
mainFrame.setCursor(null);
|
381 |
dss.restoreCursor(); |
382 |
} |
383 |
} |
384 |
|
385 |
/**
|
386 |
* Listener para los eventos de cerrado de los di?logos. Tiene su raz?n de
|
387 |
* ser en que los di?logos han de devolverse al pool cuando se cierran
|
388 |
*
|
389 |
* @author Fernando Gonz?lez Cort?s
|
390 |
*/
|
391 |
public class DialogWindowListener extends WindowAdapter { |
392 |
/**
|
393 |
* Captura el evento de cerrado de los di?logos con el fin de realizar
|
394 |
* tareas de mantenimiento
|
395 |
*
|
396 |
* @param e evento
|
397 |
*/
|
398 |
public void windowClosing(WindowEvent e) { |
399 |
closeJDialog((JDialog) e.getSource());
|
400 |
} |
401 |
} |
402 |
|
403 |
/**
|
404 |
* DOCUMENT ME!
|
405 |
*/
|
406 |
public class FrameListener implements InternalFrameListener { |
407 |
/**
|
408 |
* @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent)
|
409 |
*/
|
410 |
public void internalFrameActivated(InternalFrameEvent e) { |
411 |
View panel = fvs.getView((JInternalFrame) e.getSource()); |
412 |
ViewInfo vi = vis.getViewInfo(panel); |
413 |
|
414 |
JInternalFrame frame = fvs.getJInternalFrame(panel);
|
415 |
|
416 |
if (!frame.isMaximizable() && frame.isMaximum()) {
|
417 |
try {
|
418 |
frame.setMaximum(false);
|
419 |
} catch (PropertyVetoException e1) { |
420 |
} |
421 |
} |
422 |
mainFrame.enableControls(); |
423 |
callViewActivated(panel); |
424 |
|
425 |
|
426 |
} |
427 |
|
428 |
/**
|
429 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
|
430 |
*/
|
431 |
public void internalFrameClosed(InternalFrameEvent e) { |
432 |
} |
433 |
|
434 |
/**
|
435 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent)
|
436 |
*/
|
437 |
public void internalFrameClosing(InternalFrameEvent e) { |
438 |
// Se elimina la memoria del JInternalFrame si no es ALWAYS_LIVE
|
439 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
440 |
ViewInfo vi = vis.getViewInfo((View) fvs.getView(c));
|
441 |
|
442 |
View view = fvs.getView(c);
|
443 |
|
444 |
boolean alwaysLive;
|
445 |
if (view instanceof SingletonView) { |
446 |
svs.closeView((SingletonView) view); |
447 |
} |
448 |
|
449 |
fvs.closeView(view); |
450 |
|
451 |
panel.remove(c); |
452 |
|
453 |
vss.remove(view); |
454 |
|
455 |
mainFrame.enableControls(); |
456 |
|
457 |
panel.repaint(); |
458 |
} |
459 |
|
460 |
/**
|
461 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent)
|
462 |
*/
|
463 |
public void internalFrameDeactivated(InternalFrameEvent e) { |
464 |
} |
465 |
|
466 |
/**
|
467 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
|
468 |
*/
|
469 |
public void internalFrameDeiconified(InternalFrameEvent e) { |
470 |
mainFrame.enableControls(); |
471 |
} |
472 |
|
473 |
/**
|
474 |
* @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
|
475 |
*/
|
476 |
public void internalFrameIconified(InternalFrameEvent e) { |
477 |
mainFrame.enableControls(); |
478 |
} |
479 |
|
480 |
/**
|
481 |
* @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent)
|
482 |
*/
|
483 |
public void internalFrameOpened(InternalFrameEvent e) { |
484 |
} |
485 |
} |
486 |
} |