root / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / NewSkin.java @ 7687
History | View | Annotate | Download (29.1 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.Container; |
46 |
import java.awt.Cursor; |
47 |
import java.awt.Dimension; |
48 |
import java.awt.KeyEventDispatcher; |
49 |
import java.awt.Point; |
50 |
import java.awt.Window; |
51 |
import java.awt.event.ActionEvent; |
52 |
import java.awt.event.ActionListener; |
53 |
import java.awt.event.KeyEvent; |
54 |
import java.awt.event.WindowAdapter; |
55 |
import java.awt.event.WindowEvent; |
56 |
import java.beans.PropertyVetoException; |
57 |
import java.util.ArrayList; |
58 |
import java.util.Collection; |
59 |
import java.util.Iterator; |
60 |
import java.util.TreeMap; |
61 |
|
62 |
import javax.swing.DefaultDesktopManager; |
63 |
import javax.swing.DesktopManager; |
64 |
import javax.swing.JDesktopPane; |
65 |
import javax.swing.JDialog; |
66 |
import javax.swing.JFrame; |
67 |
import javax.swing.JInternalFrame; |
68 |
import javax.swing.JRootPane; |
69 |
import javax.swing.KeyStroke; |
70 |
import javax.swing.event.InternalFrameEvent; |
71 |
import javax.swing.event.InternalFrameListener; |
72 |
|
73 |
import org.apache.log4j.Logger; |
74 |
|
75 |
import com.iver.andami.GlobalKeyEventDispatcher; |
76 |
import com.iver.andami.Launcher; |
77 |
import com.iver.andami.PluginServices; |
78 |
import com.iver.andami.plugins.Extension; |
79 |
import com.iver.andami.ui.mdiFrame.GlassPane; |
80 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
81 |
import com.iver.andami.ui.mdiFrame.NewStatusBar; |
82 |
import com.iver.andami.ui.mdiManager.MDIManager; |
83 |
import com.iver.andami.ui.mdiManager.MDIUtilities; |
84 |
import com.iver.andami.ui.mdiManager.SingletonDialogAlreadyShownException; |
85 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
86 |
import com.iver.andami.ui.mdiManager.IWindow; |
87 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
88 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
89 |
import com.iver.core.StatusBar; |
90 |
|
91 |
/**
|
92 |
*
|
93 |
*/
|
94 |
public class NewSkin extends Extension implements MDIManager{ |
95 |
private static final int DefaultXMargin = 20; // Added for the method 'centreJInternalFrame' |
96 |
private static final int DefaultYMargin = 20; // Added for the method 'centreJInternalFrame' |
97 |
private static final int MinimumXMargin = 130; // Added for the method 'centreJInternalFrame' |
98 |
private static final int MinimumYMargin = 60; // Added for the method 'centreJInternalFrame' |
99 |
|
100 |
|
101 |
/**
|
102 |
* Variable privada <code>desktopManager</code> para usarlo cuando sale
|
103 |
* una ventana que no queremos que nos restaure las que tenemos maximizadas.
|
104 |
* Justo antes de usar el setMaximize(false), le pegamos el cambiazo.
|
105 |
*/
|
106 |
private static DesktopManager desktopManager = new DefaultDesktopManager(); |
107 |
|
108 |
/** log */
|
109 |
private static Logger logger = Logger.getLogger(NewSkin.class.getName()); |
110 |
|
111 |
/** Panel de la MDIFrame */
|
112 |
private JDesktopPane panel = new JDesktopPane(); |
113 |
|
114 |
/** MDIFrame */
|
115 |
private MDIFrame mainFrame;
|
116 |
|
117 |
private GlassPane glassPane = new GlassPane(); |
118 |
|
119 |
private DialogStackSupport dss;
|
120 |
|
121 |
private FrameWindowSupport fvs;
|
122 |
|
123 |
private WindowInfoSupport vis;
|
124 |
|
125 |
private WindowStackSupport vss;
|
126 |
|
127 |
private SingletonWindowSupport svs;
|
128 |
|
129 |
private Cursor lastCursor = null; |
130 |
|
131 |
/**
|
132 |
* @see com.iver.andami.ui.mdiManager.MDIManager#init(com.iver.andami.ui.mdiFrame.MDIFrame)
|
133 |
*/
|
134 |
public void init(MDIFrame f) { |
135 |
// Inicializa el Frame y la consola
|
136 |
mainFrame = f; |
137 |
mainFrame.setGlassPane(glassPane); |
138 |
panel.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
|
139 |
|
140 |
mainFrame.getContentPane().add(panel, BorderLayout.CENTER);
|
141 |
panel.setDesktopManager(desktopManager); |
142 |
|
143 |
fvs = new FrameWindowSupport(mainFrame);
|
144 |
dss = new DialogStackSupport(mainFrame);
|
145 |
svs = new SingletonWindowSupport(vis, fvs);
|
146 |
vis = new WindowInfoSupport(mainFrame, fvs, svs);
|
147 |
fvs.setVis(vis); |
148 |
vss = new WindowStackSupport(vis);
|
149 |
|
150 |
|
151 |
// TODO (jaume) esto no deber?a de estar aqu?...
|
152 |
// molar?a m?s en un di?logo de preferencias
|
153 |
// es s?lo una prueba
|
154 |
KeyStroke controlTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_MASK); |
155 |
|
156 |
PluginServices.registerKeyStroke(controlTab, new KeyEventDispatcher() { |
157 |
|
158 |
public boolean dispatchKeyEvent(KeyEvent e) { |
159 |
IWindow[] views = getAllWindows();
|
160 |
if (views.length<=0 || e.getID() == KeyEvent.KEY_PRESSED) |
161 |
return false; |
162 |
|
163 |
|
164 |
int current = 0; |
165 |
for (int i = 0; i < views.length; i++) { |
166 |
if (views[i].equals(getActiveWindow())) {
|
167 |
current = i; |
168 |
break;
|
169 |
} |
170 |
} |
171 |
addWindow(views[(current +1) % views.length]);
|
172 |
return true; |
173 |
} |
174 |
|
175 |
}); |
176 |
} |
177 |
|
178 |
/**
|
179 |
* @see com.iver.andami.ui.mdiManager.MDIManager#addWindow(com.iver.andami.ui.mdiManager.IWindow)
|
180 |
*/
|
181 |
public IWindow addWindow(IWindow p) throws SingletonDialogAlreadyShownException { |
182 |
// se obtiene la informaci?n de la vista
|
183 |
WindowInfo vi = vis.getWindowInfo(p); |
184 |
|
185 |
// Se comprueban las incompatibilidades que pudieran haber en la vista
|
186 |
MDIUtilities.checkWindowInfo(vi); |
187 |
if ((p instanceof SingletonWindow) && (vi.isModal())) { |
188 |
throw new RuntimeException("A modal view cannot be a SingletonView"); |
189 |
} |
190 |
|
191 |
/*
|
192 |
* Se obtiene la referencia a la vista anterior por si es una singleton
|
193 |
* y est? siendo mostrada. Se obtiene su informaci?n si ya fue mostrada
|
194 |
*/
|
195 |
boolean singletonPreviouslyAdded = false; |
196 |
|
197 |
if (p instanceof SingletonWindow) { |
198 |
SingletonWindow sv = (SingletonWindow) p; |
199 |
if (svs.registerWindow(sv.getClass(), sv.getWindowModel(), vis
|
200 |
.getWindowInfo(sv))) { |
201 |
singletonPreviouslyAdded = true;
|
202 |
} |
203 |
} |
204 |
|
205 |
if (singletonPreviouslyAdded) {
|
206 |
// Si la vista no est? actualmente abierta
|
207 |
if (!svs.contains((SingletonWindow) p)) {
|
208 |
JInternalFrame frame = fvs.getJInternalFrame(p);
|
209 |
svs.openSingletonView((SingletonWindow) p, frame); |
210 |
addJInternalFrame(frame, vi); |
211 |
vss.add(p, new ActionListener() { |
212 |
public void actionPerformed(ActionEvent e) { |
213 |
IWindow v = vis.getWindowById(Integer.parseInt(e
|
214 |
.getActionCommand())); |
215 |
JInternalFrame f = fvs.getJInternalFrame(v);
|
216 |
activateJInternalFrame(f); |
217 |
} |
218 |
}); |
219 |
return p;
|
220 |
} else {
|
221 |
// La vista est? actualmente abierta
|
222 |
JInternalFrame frame = (JInternalFrame) svs |
223 |
.getFrame((SingletonWindow) p); |
224 |
activateJInternalFrame(frame); |
225 |
vss.setActive(p); |
226 |
return fvs.getWindow((JInternalFrame) frame); |
227 |
} |
228 |
} else {
|
229 |
if (vi.isModal()) {
|
230 |
addJDialog(p); |
231 |
} else {
|
232 |
// Se sit?a la vista en la pila de vistas
|
233 |
vss.add(p, new ActionListener() { |
234 |
public void actionPerformed(ActionEvent e) { |
235 |
IWindow v = vis.getWindowById(Integer.parseInt(e
|
236 |
.getActionCommand())); |
237 |
JInternalFrame f = fvs.getJInternalFrame(v);
|
238 |
activateJInternalFrame(f); |
239 |
} |
240 |
}); |
241 |
addJInternalFrame(p); |
242 |
} |
243 |
|
244 |
return p;
|
245 |
} |
246 |
} |
247 |
|
248 |
/**
|
249 |
* Similar method as 'addView' but in this case centres the new JInternalFrame of the View in the contentPane of the MainFrame
|
250 |
*
|
251 |
* @see com.iver.core.mdiManager.NewSkin#addWindow(com.iver.andami.ui.mdiManager.IWindow)
|
252 |
*
|
253 |
* @author Pablo Piqueras Bartolom?
|
254 |
*/
|
255 |
public IWindow addCentredWindow(IWindow p) throws SingletonDialogAlreadyShownException { |
256 |
// se obtiene la informaci?n de la vista
|
257 |
WindowInfo vi = vis.getWindowInfo(p); |
258 |
|
259 |
// Se comprueban las incompatibilidades que pudieran haber en la vista
|
260 |
MDIUtilities.checkWindowInfo(vi); |
261 |
if ((p instanceof SingletonWindow) && (vi.isModal())) { |
262 |
throw new RuntimeException("A modal view cannot be a SingletonView"); |
263 |
} |
264 |
|
265 |
/*
|
266 |
* Se obtiene la referencia a la vista anterior por si es una singleton
|
267 |
* y est? siendo mostrada. Se obtiene su informaci?n si ya fue mostrada
|
268 |
*/
|
269 |
boolean singletonPreviouslyAdded = false; |
270 |
|
271 |
if (p instanceof SingletonWindow) { |
272 |
SingletonWindow sv = (SingletonWindow) p; |
273 |
if (svs.registerWindow(sv.getClass(), sv.getWindowModel(), vis
|
274 |
.getWindowInfo(sv))) { |
275 |
singletonPreviouslyAdded = true;
|
276 |
} |
277 |
} |
278 |
|
279 |
if (singletonPreviouslyAdded) {
|
280 |
// Si la vista no est? actualmente abierta
|
281 |
if (!svs.contains((SingletonWindow) p)) {
|
282 |
JInternalFrame frame = fvs.getJInternalFrame(p);
|
283 |
svs.openSingletonView((SingletonWindow) p, frame); |
284 |
addJInternalFrame(frame, vi); |
285 |
vss.add(p, new ActionListener() { |
286 |
public void actionPerformed(ActionEvent e) { |
287 |
IWindow v = vis.getWindowById(Integer.parseInt(e
|
288 |
.getActionCommand())); |
289 |
JInternalFrame f = fvs.getJInternalFrame(v);
|
290 |
centreJInternalFrame(f); // Centre this JInternalFrame
|
291 |
activateJInternalFrame(f); |
292 |
} |
293 |
}); |
294 |
return p;
|
295 |
} else {
|
296 |
// La vista est? actualmente abierta
|
297 |
JInternalFrame frame = (JInternalFrame) svs |
298 |
.getFrame((SingletonWindow) p); |
299 |
activateJInternalFrame(frame); |
300 |
centreJInternalFrame(frame); // Centre this JInternalFrame
|
301 |
vss.setActive(p); |
302 |
return fvs.getWindow((JInternalFrame) frame); |
303 |
} |
304 |
} else {
|
305 |
centreJInternalFrame(fvs.getJInternalFrame(p)); // Centre this JInternalFrame
|
306 |
if (vi.isModal()) {
|
307 |
addJDialog(p); |
308 |
} else {
|
309 |
// Se sit?a la vista en la pila de vistas
|
310 |
vss.add(p, new ActionListener() { |
311 |
public void actionPerformed(ActionEvent e) { |
312 |
IWindow v = vis.getWindowById(Integer.parseInt(e
|
313 |
.getActionCommand())); |
314 |
JInternalFrame f = fvs.getJInternalFrame(v);
|
315 |
activateJInternalFrame(f); |
316 |
} |
317 |
}); |
318 |
addJInternalFrame(p); |
319 |
} |
320 |
|
321 |
return p;
|
322 |
} |
323 |
} |
324 |
|
325 |
/**
|
326 |
* Centres the JInternalFrame in the center of the contentPane of the MainFrame
|
327 |
* If it can't be showed completely the JInternalFrame, tries that the top-left corner of the JInternalFrame would be showed
|
328 |
*
|
329 |
* @author Pablo Piqueras Bartolom?
|
330 |
*
|
331 |
* @param jInternalFrame A reference to the frame to centring
|
332 |
*/
|
333 |
private static synchronized void centreJInternalFrame(JInternalFrame jInternalFrame) { |
334 |
|
335 |
// The top-left square of frame reference
|
336 |
Point newReferencePoint = new Point(); |
337 |
|
338 |
// A reference to the panel where the JInternalFrame will be displayed
|
339 |
Container contentPane = ((JFrame)PluginServices.getMainFrame()).getContentPane(); |
340 |
|
341 |
// Get the NewStatusBar component
|
342 |
NewStatusBar newStatusBar = ((NewStatusBar)contentPane.getComponent(1));
|
343 |
JDesktopPane jDesktopPane = ((JDesktopPane)contentPane.getComponent(2)); |
344 |
|
345 |
int visibleWidth = contentPane.getWidth() - contentPane.getX(); // The last substraction is for if there is any menu,... at left |
346 |
int visibleHeight = contentPane.getHeight() - newStatusBar.getHeight() - contentPane.getY() - Math.abs(jDesktopPane.getY() - contentPane.getY()); // The last substraction is for if there is any menu,... at top |
347 |
int freeWidth = visibleWidth - jInternalFrame.getWidth();
|
348 |
int freeHeight = visibleHeight - jInternalFrame.getHeight();
|
349 |
|
350 |
// Calculate the new point reference (Assure that the top-left corner is showed)
|
351 |
if (freeWidth < 0) |
352 |
{ |
353 |
if (visibleWidth > MinimumXMargin)
|
354 |
newReferencePoint.x = DefaultXMargin; |
355 |
else
|
356 |
newReferencePoint.x = 0;
|
357 |
} |
358 |
else
|
359 |
newReferencePoint.x = freeWidth / 2;
|
360 |
|
361 |
if (freeHeight < 0) |
362 |
{ |
363 |
if (visibleHeight > MinimumYMargin)
|
364 |
newReferencePoint.y = DefaultYMargin; |
365 |
else
|
366 |
newReferencePoint.y = 0;
|
367 |
} |
368 |
else
|
369 |
newReferencePoint.y = freeHeight / 2;
|
370 |
|
371 |
// Set the new location for this JInternalFrame
|
372 |
jInternalFrame.setLocation(newReferencePoint); |
373 |
} |
374 |
|
375 |
|
376 |
/**
|
377 |
* DOCUMENT ME!
|
378 |
*
|
379 |
* @param wnd
|
380 |
* DOCUMENT ME!
|
381 |
* @param vi
|
382 |
* DOCUMENT ME!
|
383 |
*/
|
384 |
private void addJInternalFrame(JInternalFrame wnd, WindowInfo vi) { |
385 |
wnd.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
386 |
wnd.addInternalFrameListener(new FrameListener());
|
387 |
|
388 |
if (vi.isModeless() || vi.isPalette()) {
|
389 |
panel.add(wnd, JDesktopPane.PALETTE_LAYER);
|
390 |
if (vi.isPalette())
|
391 |
wnd.setFocusable(false);
|
392 |
} else {
|
393 |
panel.add(wnd); |
394 |
} |
395 |
|
396 |
activateJInternalFrame(wnd); |
397 |
try{
|
398 |
wnd.setMaximum(vi.isMaximized()); |
399 |
}catch(Exception ex){ |
400 |
logger.warn("Error: ", ex);
|
401 |
} |
402 |
} |
403 |
|
404 |
/**
|
405 |
* DOCUMENT ME!
|
406 |
*
|
407 |
* @param p
|
408 |
*/
|
409 |
private void addJInternalFrame(IWindow p) { |
410 |
WindowInfo vi = vis.getWindowInfo(p); |
411 |
|
412 |
JInternalFrame wnd = fvs.getJInternalFrame(p);
|
413 |
|
414 |
if (p instanceof SingletonWindow) { |
415 |
SingletonWindow sv = (SingletonWindow) p; |
416 |
svs.openSingletonView(sv, wnd); |
417 |
} |
418 |
|
419 |
addJInternalFrame(wnd, vi); |
420 |
} |
421 |
|
422 |
/**
|
423 |
* DOCUMENT ME!
|
424 |
*
|
425 |
* @param wnd
|
426 |
*/
|
427 |
private void activateJInternalFrame(JInternalFrame wnd) { |
428 |
try {
|
429 |
wnd.moveToFront(); |
430 |
logger.debug("Activando " + wnd.getTitle());
|
431 |
wnd.setSelected(true);
|
432 |
wnd.setIcon(false);
|
433 |
} catch (PropertyVetoException e) { |
434 |
logger.error(e); |
435 |
} |
436 |
} |
437 |
|
438 |
/**
|
439 |
* Situa un di?logo modal en el centro de la pantalla
|
440 |
*
|
441 |
* @param d
|
442 |
* Di?logo que se quiere situar
|
443 |
*/
|
444 |
private void centerDialog(JDialog d) { |
445 |
int offSetX = d.getWidth() / 2; |
446 |
int offSetY = d.getHeight() / 2; |
447 |
|
448 |
d.setLocation((mainFrame.getWidth() / 2) - offSetX, (mainFrame
|
449 |
.getHeight() / 2)
|
450 |
- offSetY); |
451 |
} |
452 |
|
453 |
/**
|
454 |
* DOCUMENT ME!
|
455 |
*
|
456 |
* @param p
|
457 |
*/
|
458 |
private void addJDialog(IWindow p) { |
459 |
JDialog dlg = fvs.getJDialog(p);
|
460 |
|
461 |
centerDialog(dlg); |
462 |
|
463 |
dlg.addWindowListener(new DialogWindowListener());
|
464 |
dss.pushDialog(dlg); |
465 |
|
466 |
dlg.setVisible(vis.getWindowInfo(p).isVisible()); |
467 |
} |
468 |
|
469 |
/**
|
470 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getActiveWindow()
|
471 |
*/
|
472 |
public IWindow getActiveWindow() {
|
473 |
JInternalFrame jif = panel.getSelectedFrame();
|
474 |
|
475 |
if (jif != null) { |
476 |
IWindow theView = fvs.getWindow(jif); |
477 |
if (theView == null) |
478 |
return null; |
479 |
if (theView.getWindowInfo().isPalette())
|
480 |
return vss.getActiveWindow();
|
481 |
else
|
482 |
return fvs.getWindow(jif);
|
483 |
} |
484 |
// return vss.getActiveView();
|
485 |
|
486 |
return null; |
487 |
} |
488 |
public IWindow getFocusWindow(){
|
489 |
JInternalFrame jif = panel.getSelectedFrame();
|
490 |
|
491 |
if (jif != null) { |
492 |
IWindow theView = fvs.getWindow(jif); |
493 |
if (theView == null) |
494 |
return null; |
495 |
return fvs.getWindow(jif);
|
496 |
} |
497 |
return null; |
498 |
} |
499 |
/**
|
500 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeWindow(com.iver.andami.ui.mdiManager.IWindow)
|
501 |
*/
|
502 |
public void closeWindow(IWindow p) { |
503 |
// Si es un di?logo modal
|
504 |
if (p.getWindowInfo().isModal()) {
|
505 |
closeJDialog(); |
506 |
} else { // Si no es modal se cierra el JInternalFrame |
507 |
closeJInternalFrame(fvs.getJInternalFrame(p)); |
508 |
} |
509 |
} |
510 |
|
511 |
/**
|
512 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeAllWindows()
|
513 |
*/
|
514 |
public void closeAllWindows() { |
515 |
ArrayList eliminar = new ArrayList(); |
516 |
Iterator i = fvs.getWindowIterator();
|
517 |
|
518 |
while (i.hasNext()) {
|
519 |
eliminar.add((IWindow) i.next()); |
520 |
} |
521 |
|
522 |
for (Iterator iter = eliminar.iterator(); iter.hasNext();) { |
523 |
IWindow vista = (IWindow) iter.next(); |
524 |
closeWindow(vista); |
525 |
} |
526 |
} |
527 |
|
528 |
/**
|
529 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getWindowInfo(com.iver.andami.ui.mdiManager.IWindow)
|
530 |
*/
|
531 |
public WindowInfo getWindowInfo(IWindow v) {
|
532 |
//ViewInfo vi = new ViewInfo();
|
533 |
WindowInfo vi = vis.getWindowInfo(v); |
534 |
JInternalFrame f = fvs.getJInternalFrame(v);
|
535 |
vi.setX(f.getX()); |
536 |
vi.setY(f.getY()); |
537 |
vi.setHeight(f.getHeight()); |
538 |
vi.setWidth(f.getWidth()); |
539 |
// isClosed() doesn't work as (I) expected, why? Using isShowing instead
|
540 |
vi.setClosed(!f.isShowing()); |
541 |
vi.setNormalBounds(f.getNormalBounds()); |
542 |
vi.setMaximized(f.isMaximum()); |
543 |
return vi;
|
544 |
} |
545 |
|
546 |
/**
|
547 |
* DOCUMENT ME!
|
548 |
*
|
549 |
* @param dialog
|
550 |
* @throws RuntimeException
|
551 |
* DOCUMENT ME!
|
552 |
*/
|
553 |
private void closeJDialog() { |
554 |
JDialog dlg = dss.popDialog();
|
555 |
|
556 |
dlg.setVisible(false);
|
557 |
|
558 |
IWindow s = (IWindow) fvs.getWindow(dlg); |
559 |
|
560 |
callWindowClosed(s); |
561 |
|
562 |
fvs.closeWindow(s); |
563 |
|
564 |
// Si es singleton se desasocia el modelo con la vista
|
565 |
if (s instanceof SingletonWindow) { |
566 |
svs.closeView((SingletonWindow) s); |
567 |
} |
568 |
} |
569 |
|
570 |
/**
|
571 |
* DOCUMENT ME!
|
572 |
*
|
573 |
* @param view
|
574 |
* DOCUMENT ME!
|
575 |
*/
|
576 |
private void callWindowClosed(IWindow view) { |
577 |
if (view instanceof IWindowListener) { |
578 |
((IWindowListener) view).windowClosed(); |
579 |
} |
580 |
} |
581 |
|
582 |
/**
|
583 |
* DOCUMENT ME!
|
584 |
*
|
585 |
* @param view
|
586 |
* DOCUMENT ME!
|
587 |
*/
|
588 |
private void callWindowActivated(IWindow view) { |
589 |
logger.debug("View " + view.getWindowInfo().getTitle()
|
590 |
+ " activated (callViewActivated)");
|
591 |
if (view instanceof IWindowListener) { |
592 |
((IWindowListener) view).windowActivated(); |
593 |
} |
594 |
} |
595 |
|
596 |
/**
|
597 |
* DOCUMENT ME!
|
598 |
*
|
599 |
* @param frame
|
600 |
*/
|
601 |
private void closeJInternalFrame(JInternalFrame frame) { |
602 |
try {
|
603 |
IWindow s = (IWindow) fvs.getWindow(frame); |
604 |
|
605 |
frame.setClosed(true);
|
606 |
callWindowClosed(s); |
607 |
} catch (PropertyVetoException e) { |
608 |
logger |
609 |
.error( |
610 |
"Not compatible with property veto's. Use ViewInfo instead.",
|
611 |
e); |
612 |
} |
613 |
} |
614 |
|
615 |
/**
|
616 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
617 |
*/
|
618 |
public void initialize() { |
619 |
} |
620 |
|
621 |
/**
|
622 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
623 |
*/
|
624 |
public void execute(String actionCommand) { |
625 |
if (actionCommand.equals("cascada")) { |
626 |
} else if (actionCommand.equals("mosaico")) { |
627 |
} |
628 |
} |
629 |
|
630 |
/**
|
631 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
632 |
*/
|
633 |
public boolean isEnabled() { |
634 |
// TODO Auto-generated method stub
|
635 |
return false; |
636 |
} |
637 |
|
638 |
/**
|
639 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
640 |
*/
|
641 |
public boolean isVisible() { |
642 |
// TODO Auto-generated method stub
|
643 |
return true; |
644 |
} |
645 |
|
646 |
/**
|
647 |
* @see com.iver.andami.ui.mdiManager.MDIManager#setWaitCursor()
|
648 |
*/
|
649 |
public void setWaitCursor() { |
650 |
if (mainFrame != null) { |
651 |
glassPane.setVisible(true);
|
652 |
lastCursor = mainFrame.getCursor(); |
653 |
dss.setWaitCursor(); |
654 |
glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
655 |
} |
656 |
} |
657 |
|
658 |
/**
|
659 |
* @see com.iver.andami.ui.mdiManager.MDIManager#restoreCursor()
|
660 |
*/
|
661 |
public void restoreCursor() { |
662 |
if (mainFrame != null) { |
663 |
glassPane.setVisible(false);
|
664 |
dss.restoreCursor(); |
665 |
glassPane.setCursor(lastCursor); |
666 |
} |
667 |
} |
668 |
|
669 |
/**
|
670 |
* Listener para los eventos de cerrado de los di?logos. Tiene su raz?n de
|
671 |
* ser en que los di?logos han de devolverse al pool cuando se cierran
|
672 |
*
|
673 |
* @author Fernando Gonz?lez Cort?s
|
674 |
*/
|
675 |
public class DialogWindowListener extends WindowAdapter { |
676 |
/**
|
677 |
* Captura el evento de cerrado de los di?logos con el fin de realizar
|
678 |
* tareas de mantenimiento
|
679 |
*
|
680 |
* @param e
|
681 |
* evento
|
682 |
*/
|
683 |
public void windowClosing(WindowEvent e) { |
684 |
closeJDialog(); |
685 |
} |
686 |
} |
687 |
|
688 |
/**
|
689 |
* DOCUMENT ME!
|
690 |
*/
|
691 |
public class FrameListener implements InternalFrameListener { |
692 |
/**
|
693 |
* @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent)
|
694 |
*/
|
695 |
public void internalFrameActivated(InternalFrameEvent e) { |
696 |
// logger.debug("internalFrameActivated " +
|
697 |
// e.getInternalFrame().getTitle());
|
698 |
|
699 |
// activatedInternalFramesStack.push(e.getInternalFrame());
|
700 |
|
701 |
IWindow panel = fvs.getWindow((JInternalFrame) e.getSource());
|
702 |
|
703 |
WindowInfo vi = vis.getWindowInfo(panel); |
704 |
if (vi.isPalette())
|
705 |
return;
|
706 |
|
707 |
vss.setActive(panel); |
708 |
|
709 |
JInternalFrame frame = fvs.getJInternalFrame(panel);
|
710 |
|
711 |
if (vi.isMaximizable()){
|
712 |
frame.setMaximizable(true);
|
713 |
} |
714 |
if (!frame.isMaximizable() && frame.isMaximum()) {
|
715 |
try {
|
716 |
frame.setMaximum(false);
|
717 |
} catch (PropertyVetoException e1) { |
718 |
} |
719 |
} |
720 |
mainFrame.enableControls(); |
721 |
if (vi.getSelectedTool() != null) |
722 |
mainFrame.setSelectedTool(vi.getSelectedTool()); |
723 |
callWindowActivated(panel); |
724 |
|
725 |
} |
726 |
|
727 |
/**
|
728 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
|
729 |
*/
|
730 |
public void internalFrameClosed(InternalFrameEvent e) { |
731 |
} |
732 |
|
733 |
/**
|
734 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent)
|
735 |
*/
|
736 |
public void internalFrameClosing(InternalFrameEvent e) { |
737 |
// Se elimina la memoria del JInternalFrame si no es ALWAYS_LIVE
|
738 |
// logger.debug("internalFrameClosing " +
|
739 |
// e.getInternalFrame().getTitle());
|
740 |
|
741 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
742 |
WindowInfo vi = vis.getWindowInfo((IWindow) fvs.getWindow(c)); |
743 |
|
744 |
IWindow view = fvs.getWindow(c); |
745 |
callWindowClosed(view); |
746 |
boolean alwaysLive;
|
747 |
if (view instanceof SingletonWindow) { |
748 |
svs.closeView((SingletonWindow) view); |
749 |
} |
750 |
|
751 |
fvs.closeWindow(view); |
752 |
|
753 |
panel.remove(c); |
754 |
|
755 |
vss.remove(view); |
756 |
|
757 |
if (!vi.isPalette())
|
758 |
mainFrame.enableControls(); |
759 |
panel.repaint(); |
760 |
|
761 |
// Para activar el JInternalFrame desde la que hemos
|
762 |
// abierto la ventana que estamos cerrando
|
763 |
IWindow lastView = vss.getActiveWindow(); |
764 |
// La activamos
|
765 |
if (lastView != null) { |
766 |
System.err.println("Devuelvo el foco a " |
767 |
+ lastView.getWindowInfo().getTitle()); |
768 |
JInternalFrame frame = fvs.getJInternalFrame(lastView);
|
769 |
try {
|
770 |
frame.setSelected(true);
|
771 |
} catch (PropertyVetoException e1) { |
772 |
// TODO Auto-generated catch block
|
773 |
// e1.printStackTrace();
|
774 |
} |
775 |
// addView(lastView);
|
776 |
} |
777 |
|
778 |
} |
779 |
|
780 |
/**
|
781 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent)
|
782 |
*/
|
783 |
public void internalFrameDeactivated(InternalFrameEvent e) { |
784 |
// logger.debug("internalDeActivated " +
|
785 |
// e.getInternalFrame().getTitle());
|
786 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
787 |
IWindow andamiView = fvs.getWindow(c); |
788 |
if (andamiView != null) { |
789 |
WindowInfo vi = vis.getWindowInfo(andamiView); |
790 |
if (vi.isPalette())
|
791 |
return;
|
792 |
vi.setSelectedTool(mainFrame.getSelectedTool()); |
793 |
} |
794 |
|
795 |
} |
796 |
|
797 |
/**
|
798 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
|
799 |
*/
|
800 |
public void internalFrameDeiconified(InternalFrameEvent e) { |
801 |
mainFrame.enableControls(); |
802 |
} |
803 |
|
804 |
/**
|
805 |
* @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
|
806 |
*/
|
807 |
public void internalFrameIconified(InternalFrameEvent e) { |
808 |
mainFrame.enableControls(); |
809 |
} |
810 |
|
811 |
/**
|
812 |
* @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent)
|
813 |
*/
|
814 |
public void internalFrameOpened(InternalFrameEvent e) { |
815 |
// logger.debug("internalFrameOpened. Source= " +
|
816 |
// e.getSource().toString());
|
817 |
} |
818 |
} |
819 |
|
820 |
/**
|
821 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Class,
|
822 |
* java.lang.Object)
|
823 |
*/
|
824 |
public boolean closeSingletonWindow(Class viewClass, Object model) { |
825 |
JInternalFrame frame = svs.getFrame(viewClass, model);
|
826 |
if (frame == null) |
827 |
return false; |
828 |
closeJInternalFrame(frame); |
829 |
return true; |
830 |
} |
831 |
|
832 |
/**
|
833 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Object)
|
834 |
*/
|
835 |
public boolean closeSingletonWindow(Object model) { |
836 |
JInternalFrame[] frames = svs.getFrames(model); |
837 |
if (frames.length == 0) |
838 |
return false; |
839 |
for (int i = 0; i < frames.length; i++) { |
840 |
closeJInternalFrame(frames[i]); |
841 |
} |
842 |
return true; |
843 |
} |
844 |
|
845 |
/**
|
846 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getAllWindows()
|
847 |
*/
|
848 |
public IWindow[] getAllWindows() { |
849 |
ArrayList windows = new ArrayList(); |
850 |
Iterator i = fvs.getWindowIterator();
|
851 |
|
852 |
while (i.hasNext()) {
|
853 |
windows.add((IWindow) i.next()); |
854 |
} |
855 |
return (IWindow[]) windows.toArray(new IWindow[0]); |
856 |
} |
857 |
|
858 |
public IWindow[] getOrderedWindows() { |
859 |
//ArrayList windows = new ArrayList();
|
860 |
TreeMap windows = new TreeMap(); |
861 |
Iterator winIterator = fvs.getWindowIterator();
|
862 |
|
863 |
JInternalFrame frame;
|
864 |
IWindow win; |
865 |
/**
|
866 |
* The order of the window in the JDesktopPane. Smaller numbers
|
867 |
* are closer to the foreground.
|
868 |
*/
|
869 |
int zPosition;
|
870 |
while (winIterator.hasNext()) {
|
871 |
win = (IWindow) winIterator.next(); |
872 |
frame = fvs.getJInternalFrame(win); |
873 |
|
874 |
zPosition = panel.getPosition(frame); |
875 |
windows.put(new Integer(zPosition), win); |
876 |
} |
877 |
winIterator = windows.values().iterator(); |
878 |
ArrayList winList = new ArrayList(); |
879 |
while (winIterator.hasNext()) {
|
880 |
winList.add(winIterator.next()); |
881 |
} |
882 |
|
883 |
return (IWindow[]) winList.toArray(new IWindow[0]); |
884 |
} |
885 |
|
886 |
public void setMaximum(IWindow v, boolean bMaximum) throws PropertyVetoException |
887 |
{ |
888 |
JInternalFrame f = fvs.getJInternalFrame(v);
|
889 |
f.setMaximum(bMaximum); |
890 |
} |
891 |
|
892 |
public void changeWindowInfo(IWindow v, WindowInfo vi){ |
893 |
JInternalFrame f = fvs.getJInternalFrame(v);
|
894 |
f.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
895 |
JDesktopPane pnl = f.getDesktopPane();
|
896 |
pnl.remove(f); |
897 |
f.setSize(new Dimension(vi.getWidth(),vi.getHeight())); |
898 |
f.setLocation(vi.getX(), vi.getY()); |
899 |
if (vi.isPalette()) {
|
900 |
pnl.add(f, JDesktopPane.PALETTE_LAYER);
|
901 |
f.setFocusable(false);
|
902 |
} else {
|
903 |
pnl.add(f, JDesktopPane.DEFAULT_LAYER);
|
904 |
f.setFocusable(true);
|
905 |
if (vi.isClosed()) {
|
906 |
closeWindow(v); |
907 |
} |
908 |
} |
909 |
|
910 |
if (vi.isMaximized()) {
|
911 |
try {
|
912 |
f.setMaximum(true);
|
913 |
} catch (PropertyVetoException e) { |
914 |
// TODO Auto-generated catch block
|
915 |
//e.printStackTrace();
|
916 |
} |
917 |
f.setNormalBounds(vi.getNormalBounds()); |
918 |
} |
919 |
activateJInternalFrame(f); |
920 |
} |
921 |
|
922 |
} |