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