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