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