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