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