root / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / NewSkin.java @ 10168
History | View | Annotate | Download (28.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.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.JPopupMenu; |
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.PluginServices; |
76 |
import com.iver.andami.plugins.Extension; |
77 |
import com.iver.andami.ui.mdiFrame.GlassPane; |
78 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
79 |
import com.iver.andami.ui.mdiFrame.NewStatusBar; |
80 |
import com.iver.andami.ui.mdiManager.IWindow; |
81 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
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.WindowInfo; |
87 |
import com.iver.andami.ui.theme.Theme; |
88 |
|
89 |
/**
|
90 |
*
|
91 |
*/
|
92 |
public class NewSkin extends Extension implements MDIManager{ |
93 |
private static final int DefaultXMargin = 20; // Added for the method 'centreJInternalFrame' |
94 |
private static final int DefaultYMargin = 20; // Added for the method 'centreJInternalFrame' |
95 |
private static final int MinimumXMargin = 130; // Added for the method 'centreJInternalFrame' |
96 |
private static final int MinimumYMargin = 60; // Added for the method 'centreJInternalFrame' |
97 |
|
98 |
|
99 |
/**
|
100 |
* Variable privada <code>desktopManager</code> para usarlo cuando sale
|
101 |
* una ventana que no queremos que nos restaure las que tenemos maximizadas.
|
102 |
* Justo antes de usar el setMaximize(false), le pegamos el cambiazo.
|
103 |
*/
|
104 |
private static DesktopManager desktopManager = new DefaultDesktopManager(); |
105 |
|
106 |
/** log */
|
107 |
private static Logger logger = Logger.getLogger(NewSkin.class.getName()); |
108 |
|
109 |
/** Panel de la MDIFrame */
|
110 |
private MyDesktopPane panel = new MyDesktopPane(); |
111 |
|
112 |
/** MDIFrame */
|
113 |
private MDIFrame mainFrame;
|
114 |
|
115 |
private GlassPane glassPane = new GlassPane(); |
116 |
|
117 |
private DialogStackSupport dss;
|
118 |
|
119 |
/**
|
120 |
* Associates JInternalFrames with the IWindow they contain
|
121 |
*/
|
122 |
private FrameWindowSupport fws;
|
123 |
|
124 |
private WindowInfoSupport wis;
|
125 |
|
126 |
private WindowStackSupport wss;
|
127 |
|
128 |
private SingletonWindowSupport sws;
|
129 |
|
130 |
private Cursor lastCursor = null; |
131 |
private ImageIcon image; |
132 |
private String typeDesktop; |
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(wis, fws);
|
149 |
wis = new WindowInfoSupport(mainFrame, fws, sws);
|
150 |
fws.setVis(wis); |
151 |
wss = new WindowStackSupport(wis);
|
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 |
/* (non-javadoc)
|
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 = wis.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 = wis.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 = wis.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 |
/* (non-javadoc)
|
251 |
* @see com.iver.andami.ui.mdiManager.MDIManager#addWindow(com.iver.andami.ui.mdiManager.IWindow)
|
252 |
*/
|
253 |
public IWindow addCentredWindow(IWindow p) throws SingletonDialogAlreadyShownException { |
254 |
IWindow window = addWindow(p); |
255 |
centreFrame(window); |
256 |
return window;
|
257 |
} |
258 |
|
259 |
|
260 |
/**
|
261 |
* Centres the Frame in the contentPane of the MainFrame.
|
262 |
* If the frame can't be showed completely, it tries to show its top-left
|
263 |
* corner.
|
264 |
*
|
265 |
* @author Pablo Piqueras Bartolom?
|
266 |
*
|
267 |
* @param panel The IWindow to centre
|
268 |
*/
|
269 |
public synchronized void centreFrame(IWindow panel) { |
270 |
Component window = fws.getFrame(panel);
|
271 |
if (window==null) return; |
272 |
|
273 |
// The top-left square of frame reference
|
274 |
Point newReferencePoint = new Point(); |
275 |
|
276 |
// A reference to the panel where the JInternalFrame will be displayed
|
277 |
Container contentPane = ((JFrame)PluginServices.getMainFrame()).getContentPane(); |
278 |
|
279 |
// Get the NewStatusBar component
|
280 |
NewStatusBar newStatusBar = ((NewStatusBar)contentPane.getComponent(1));
|
281 |
JDesktopPane jDesktopPane = ((JDesktopPane)contentPane.getComponent(2)); |
282 |
|
283 |
int visibleWidth = contentPane.getWidth() - contentPane.getX(); // The last substraction is for if there is any menu,... at left |
284 |
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 |
285 |
int freeWidth = visibleWidth - window.getWidth();
|
286 |
int freeHeight = visibleHeight - window.getHeight();
|
287 |
|
288 |
// Calculate the new point reference (Assure that the top-left corner is showed)
|
289 |
if (freeWidth < 0) |
290 |
{ |
291 |
if (visibleWidth > MinimumXMargin)
|
292 |
newReferencePoint.x = DefaultXMargin; |
293 |
else
|
294 |
newReferencePoint.x = 0;
|
295 |
} |
296 |
else
|
297 |
newReferencePoint.x = freeWidth / 2;
|
298 |
|
299 |
if (freeHeight < 0) |
300 |
{ |
301 |
if (visibleHeight > MinimumYMargin)
|
302 |
newReferencePoint.y = DefaultYMargin; |
303 |
else
|
304 |
newReferencePoint.y = 0;
|
305 |
} |
306 |
else
|
307 |
newReferencePoint.y = freeHeight / 2;
|
308 |
|
309 |
// Set the new location for this JInternalFrame
|
310 |
window.setLocation(newReferencePoint); |
311 |
} |
312 |
|
313 |
|
314 |
/**
|
315 |
* DOCUMENT ME!
|
316 |
*
|
317 |
* @param wnd
|
318 |
* DOCUMENT ME!
|
319 |
* @param wi
|
320 |
* DOCUMENT ME!
|
321 |
*/
|
322 |
private void addJInternalFrame(JInternalFrame wnd, WindowInfo wi) { |
323 |
wnd.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
324 |
wnd.addInternalFrameListener(new FrameListener());
|
325 |
|
326 |
if (wi.isModeless() || wi.isPalette()) {
|
327 |
panel.add(wnd, JDesktopPane.PALETTE_LAYER);
|
328 |
if (wi.isPalette())
|
329 |
wnd.setFocusable(false);
|
330 |
} else {
|
331 |
panel.add(wnd); |
332 |
} |
333 |
updateFrameProperties(wnd, wi); |
334 |
|
335 |
activateJInternalFrame(wnd); |
336 |
try{
|
337 |
wnd.setMaximum(wi.isMaximized()); |
338 |
}catch(Exception ex){ |
339 |
logger.warn("Error: ", ex);
|
340 |
} |
341 |
} |
342 |
|
343 |
private void updateFrameProperties(JInternalFrame frame, WindowInfo wi) { |
344 |
int height, width;
|
345 |
if (wi.isMaximized()) {
|
346 |
if (wi.getNormalWidth()!=-1) |
347 |
width = wi.getNormalWidth(); |
348 |
else
|
349 |
width = frame.getNormalBounds().width; |
350 |
if (wi.getNormalHeight()!=-1) |
351 |
height = wi.getNormalHeight(); |
352 |
else
|
353 |
height = frame.getNormalBounds().height; |
354 |
|
355 |
frame.setSize(width, height); |
356 |
frame.setLocation(wi.getNormalX(), wi.getNormalY()); |
357 |
} |
358 |
else {
|
359 |
if (wi.getWidth()!=-1) |
360 |
width = wi.getWidth(); |
361 |
else
|
362 |
width = frame.getWidth(); |
363 |
if (wi.getHeight()!=-1) |
364 |
height = wi.getHeight(); |
365 |
else
|
366 |
height = frame.getHeight(); |
367 |
frame.setSize(width, height); |
368 |
frame.setLocation(wi.getX(), wi.getY()); |
369 |
} |
370 |
frame.setTitle(wi.getTitle()); |
371 |
frame.setVisible(wi.isVisible()); |
372 |
frame.setResizable(wi.isResizable()); |
373 |
frame.setIconifiable(wi.isIconifiable()); |
374 |
frame.setMaximizable(wi.isMaximizable()); |
375 |
try {
|
376 |
frame.setMaximum(wi.isMaximized()); |
377 |
} catch (PropertyVetoException e) { |
378 |
// TODO Auto-generated catch block
|
379 |
//e.printStackTrace();
|
380 |
} |
381 |
} |
382 |
|
383 |
/**
|
384 |
* DOCUMENT ME!
|
385 |
*
|
386 |
* @param p
|
387 |
*/
|
388 |
private void addJInternalFrame(IWindow p) { |
389 |
WindowInfo wi = wis.getWindowInfo(p); |
390 |
|
391 |
JInternalFrame wnd = fws.getJInternalFrame(p);
|
392 |
|
393 |
if (p instanceof SingletonWindow) { |
394 |
SingletonWindow sv = (SingletonWindow) p; |
395 |
sws.openSingletonWindow(sv, wnd); |
396 |
} |
397 |
|
398 |
addJInternalFrame(wnd, wi); |
399 |
} |
400 |
|
401 |
/**
|
402 |
* DOCUMENT ME!
|
403 |
*
|
404 |
* @param wnd
|
405 |
*/
|
406 |
private void activateJInternalFrame(JInternalFrame wnd) { |
407 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
408 |
try {
|
409 |
wnd.moveToFront(); |
410 |
logger.debug("Activando " + wnd.getTitle());
|
411 |
wnd.setSelected(true);
|
412 |
wnd.setIcon(false);
|
413 |
} catch (PropertyVetoException e) { |
414 |
logger.error(e); |
415 |
} |
416 |
} |
417 |
|
418 |
/**
|
419 |
* Situa un di?logo modal en el centro de la pantalla
|
420 |
*
|
421 |
* @param d
|
422 |
* Di?logo que se quiere situar
|
423 |
*/
|
424 |
private void centerDialog(JDialog d) { |
425 |
int offSetX = d.getWidth() / 2; |
426 |
int offSetY = d.getHeight() / 2; |
427 |
|
428 |
d.setLocation((mainFrame.getWidth() / 2) - offSetX, (mainFrame
|
429 |
.getHeight() / 2)
|
430 |
- offSetY); |
431 |
} |
432 |
|
433 |
/**
|
434 |
* DOCUMENT ME!
|
435 |
*
|
436 |
* @param p
|
437 |
*/
|
438 |
private void addJDialog(IWindow p) { |
439 |
JDialog dlg = fws.getJDialog(p);
|
440 |
|
441 |
centerDialog(dlg); |
442 |
|
443 |
dlg.addWindowListener(new DialogWindowListener());
|
444 |
dss.pushDialog(dlg); |
445 |
|
446 |
dlg.setVisible(wis.getWindowInfo(p).isVisible()); |
447 |
} |
448 |
|
449 |
/**
|
450 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getActiveWindow()
|
451 |
*/
|
452 |
public IWindow getActiveWindow() {
|
453 |
JInternalFrame jif = panel.getSelectedFrame();
|
454 |
|
455 |
if (jif != null) { |
456 |
IWindow theWindow = fws.getWindow(jif); |
457 |
if (theWindow == null) |
458 |
return null; |
459 |
if (theWindow.getWindowInfo().isPalette())
|
460 |
return wss.getActiveWindow();
|
461 |
else
|
462 |
return fws.getWindow(jif);
|
463 |
} |
464 |
// return vss.getActiveView();
|
465 |
|
466 |
return null; |
467 |
} |
468 |
public IWindow getFocusWindow(){
|
469 |
JInternalFrame jif = panel.getSelectedFrame();
|
470 |
|
471 |
if (jif != null) { |
472 |
IWindow theView = fws.getWindow(jif); |
473 |
if (theView == null) |
474 |
return null; |
475 |
return fws.getWindow(jif);
|
476 |
} |
477 |
return null; |
478 |
} |
479 |
/**
|
480 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeWindow(com.iver.andami.ui.mdiManager.IWindow)
|
481 |
*/
|
482 |
public void closeWindow(IWindow p) { |
483 |
// Si es un di?logo modal
|
484 |
if (p.getWindowInfo().isModal()) {
|
485 |
closeJDialog(); |
486 |
} else { // Si no es modal se cierra el JInternalFrame |
487 |
closeJInternalFrame(fws.getJInternalFrame(p)); |
488 |
} |
489 |
} |
490 |
|
491 |
/**
|
492 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeAllWindows()
|
493 |
*/
|
494 |
public void closeAllWindows() { |
495 |
ArrayList eliminar = new ArrayList(); |
496 |
Iterator i = fws.getWindowIterator();
|
497 |
|
498 |
while (i.hasNext()) {
|
499 |
eliminar.add((IWindow) i.next()); |
500 |
} |
501 |
|
502 |
for (Iterator iter = eliminar.iterator(); iter.hasNext();) { |
503 |
IWindow vista = (IWindow) iter.next(); |
504 |
closeWindow(vista); |
505 |
} |
506 |
} |
507 |
|
508 |
/**
|
509 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getWindowInfo(com.iver.andami.ui.mdiManager.IWindow)
|
510 |
*/
|
511 |
public WindowInfo getWindowInfo(IWindow w) {
|
512 |
WindowInfo wi = wis.getWindowInfo(w); |
513 |
|
514 |
/*
|
515 |
* This is done now in vis.getWindowInfo(w)
|
516 |
*
|
517 |
* JInternalFrame f = fws.getJInternalFrame(w);
|
518 |
wi.setX(f.getX());
|
519 |
wi.setY(f.getY());
|
520 |
wi.setHeight(f.getHeight());
|
521 |
wi.setWidth(f.getWidth());
|
522 |
// isClosed() doesn't work as (I) expected, why? Using isShowing instead
|
523 |
wi.setClosed(!f.isShowing());
|
524 |
wi.setNormalBounds(f.getNormalBounds());
|
525 |
wi.setMaximized(f.isMaximum());*/
|
526 |
return wi;
|
527 |
} |
528 |
|
529 |
/**
|
530 |
* DOCUMENT ME!
|
531 |
*
|
532 |
* @param dialog
|
533 |
* @throws RuntimeException
|
534 |
* DOCUMENT ME!
|
535 |
*/
|
536 |
private void closeJDialog() { |
537 |
JDialog dlg = dss.popDialog();
|
538 |
|
539 |
dlg.setVisible(false);
|
540 |
|
541 |
IWindow s = (IWindow) fws.getWindow(dlg); |
542 |
|
543 |
callWindowClosed(s); |
544 |
|
545 |
fws.closeWindow(s); |
546 |
|
547 |
// Si es singleton se desasocia el modelo con la vista
|
548 |
if (s instanceof SingletonWindow) { |
549 |
sws.closeWindow((SingletonWindow) s); |
550 |
} |
551 |
} |
552 |
|
553 |
/**
|
554 |
* DOCUMENT ME!
|
555 |
*
|
556 |
* @param window
|
557 |
* DOCUMENT ME!
|
558 |
*/
|
559 |
private void callWindowClosed(IWindow window) { |
560 |
if (window instanceof IWindowListener) { |
561 |
((IWindowListener) window).windowClosed(); |
562 |
} |
563 |
} |
564 |
|
565 |
/**
|
566 |
* DOCUMENT ME!
|
567 |
*
|
568 |
* @param window
|
569 |
* DOCUMENT ME!
|
570 |
*/
|
571 |
private void callWindowActivated(IWindow window) { |
572 |
logger.debug("View " + window.getWindowInfo().getTitle()
|
573 |
+ " activated (callViewActivated)");
|
574 |
if (window instanceof IWindowListener) { |
575 |
((IWindowListener) window).windowActivated(); |
576 |
} |
577 |
} |
578 |
|
579 |
/**
|
580 |
* DOCUMENT ME!
|
581 |
*
|
582 |
* @param frame
|
583 |
*/
|
584 |
private void closeJInternalFrame(JInternalFrame frame) { |
585 |
try {
|
586 |
IWindow s = (IWindow) fws.getWindow(frame); |
587 |
|
588 |
frame.setClosed(true);
|
589 |
callWindowClosed(s); |
590 |
} catch (PropertyVetoException e) { |
591 |
logger |
592 |
.error( |
593 |
"Not compatible with property veto's. Use ViewInfo instead.",
|
594 |
e); |
595 |
} |
596 |
} |
597 |
|
598 |
/**
|
599 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
600 |
*/
|
601 |
public void initialize() { |
602 |
} |
603 |
|
604 |
/**
|
605 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
606 |
*/
|
607 |
public void execute(String actionCommand) { |
608 |
if (actionCommand.equals("cascada")) { |
609 |
} else if (actionCommand.equals("mosaico")) { |
610 |
} |
611 |
} |
612 |
|
613 |
/**
|
614 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
615 |
*/
|
616 |
public boolean isEnabled() { |
617 |
// TODO Auto-generated method stub
|
618 |
return false; |
619 |
} |
620 |
|
621 |
/**
|
622 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
623 |
*/
|
624 |
public boolean isVisible() { |
625 |
// TODO Auto-generated method stub
|
626 |
return true; |
627 |
} |
628 |
|
629 |
/**
|
630 |
* @see com.iver.andami.ui.mdiManager.MDIManager#setWaitCursor()
|
631 |
*/
|
632 |
public void setWaitCursor() { |
633 |
if (mainFrame != null) { |
634 |
glassPane.setVisible(true);
|
635 |
lastCursor = mainFrame.getCursor(); |
636 |
dss.setWaitCursor(); |
637 |
glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
638 |
} |
639 |
} |
640 |
|
641 |
/**
|
642 |
* @see com.iver.andami.ui.mdiManager.MDIManager#restoreCursor()
|
643 |
*/
|
644 |
public void restoreCursor() { |
645 |
if (mainFrame != null) { |
646 |
glassPane.setVisible(false);
|
647 |
dss.restoreCursor(); |
648 |
glassPane.setCursor(lastCursor); |
649 |
} |
650 |
} |
651 |
|
652 |
/**
|
653 |
* Listener para los eventos de cerrado de los di?logos. Tiene su raz?n de
|
654 |
* ser en que los di?logos han de devolverse al pool cuando se cierran
|
655 |
*
|
656 |
* @author Fernando Gonz?lez Cort?s
|
657 |
*/
|
658 |
public class DialogWindowListener extends WindowAdapter { |
659 |
/**
|
660 |
* Captura el evento de cerrado de los di?logos con el fin de realizar
|
661 |
* tareas de mantenimiento
|
662 |
*
|
663 |
* @param e
|
664 |
* evento
|
665 |
*/
|
666 |
public void windowClosing(WindowEvent e) { |
667 |
closeJDialog(); |
668 |
} |
669 |
} |
670 |
|
671 |
/**
|
672 |
* DOCUMENT ME!
|
673 |
*/
|
674 |
public class FrameListener implements InternalFrameListener { |
675 |
/**
|
676 |
* @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent)
|
677 |
*/
|
678 |
public void internalFrameActivated(InternalFrameEvent e) { |
679 |
// logger.debug("internalFrameActivated " +
|
680 |
// e.getInternalFrame().getTitle());
|
681 |
|
682 |
// activatedInternalFramesStack.push(e.getInternalFrame());
|
683 |
|
684 |
IWindow panel = fws.getWindow((JInternalFrame) e.getSource());
|
685 |
|
686 |
WindowInfo wi = wis.getWindowInfo(panel); |
687 |
if (wi.isPalette())
|
688 |
return;
|
689 |
|
690 |
wss.setActive(panel); |
691 |
|
692 |
JInternalFrame frame = fws.getJInternalFrame(panel);
|
693 |
|
694 |
if (wi.isMaximizable()){
|
695 |
frame.setMaximizable(true);
|
696 |
} |
697 |
if (!frame.isMaximizable() && frame.isMaximum()) {
|
698 |
try {
|
699 |
frame.setMaximum(false);
|
700 |
} catch (PropertyVetoException e1) { |
701 |
} |
702 |
} |
703 |
mainFrame.enableControls(); |
704 |
if (wi.getSelectedTool() != null) |
705 |
mainFrame.setSelectedTool(wi.getSelectedTool()); |
706 |
callWindowActivated(panel); |
707 |
|
708 |
} |
709 |
|
710 |
/**
|
711 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
|
712 |
*/
|
713 |
public void internalFrameClosed(InternalFrameEvent e) { |
714 |
} |
715 |
|
716 |
/**
|
717 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent)
|
718 |
*/
|
719 |
public void internalFrameClosing(InternalFrameEvent e) { |
720 |
// Se elimina la memoria del JInternalFrame si no es ALWAYS_LIVE
|
721 |
// logger.debug("internalFrameClosing " +
|
722 |
// e.getInternalFrame().getTitle());
|
723 |
|
724 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
725 |
WindowInfo wi = wis.getWindowInfo((IWindow) fws.getWindow(c)); |
726 |
|
727 |
IWindow win = fws.getWindow(c); |
728 |
callWindowClosed(win); |
729 |
boolean alwaysLive;
|
730 |
if (win instanceof SingletonWindow) { |
731 |
sws.closeWindow((SingletonWindow) win); |
732 |
} |
733 |
|
734 |
fws.closeWindow(win); |
735 |
|
736 |
panel.remove(c); |
737 |
|
738 |
wss.remove(win); |
739 |
|
740 |
if (!wi.isPalette())
|
741 |
mainFrame.enableControls(); |
742 |
panel.repaint(); |
743 |
|
744 |
// Para activar el JInternalFrame desde la que hemos
|
745 |
// abierto la ventana que estamos cerrando
|
746 |
IWindow lastWindow = wss.getActiveWindow(); |
747 |
// La activamos
|
748 |
if (lastWindow != null) { |
749 |
logger.debug(PluginServices.getText(this, "Devuelvo_el_foco_a_")+lastWindow.getWindowInfo().getTitle()); |
750 |
JInternalFrame frame = fws.getJInternalFrame(lastWindow);
|
751 |
try {
|
752 |
frame.setSelected(true);
|
753 |
} catch (PropertyVetoException e1) { |
754 |
// TODO Auto-generated catch block
|
755 |
// e1.printStackTrace();
|
756 |
} |
757 |
// addView(lastView);
|
758 |
} |
759 |
|
760 |
} |
761 |
|
762 |
/**
|
763 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent)
|
764 |
*/
|
765 |
public void internalFrameDeactivated(InternalFrameEvent e) { |
766 |
// logger.debug("internalDeActivated " +
|
767 |
// e.getInternalFrame().getTitle());
|
768 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
769 |
IWindow win = fws.getWindow(c); |
770 |
if (win != null) { |
771 |
WindowInfo wi = wis.getWindowInfo(win); |
772 |
if (wi.isPalette())
|
773 |
return;
|
774 |
wi.setSelectedTool(mainFrame.getSelectedTool()); |
775 |
} |
776 |
|
777 |
} |
778 |
|
779 |
/**
|
780 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
|
781 |
*/
|
782 |
public void internalFrameDeiconified(InternalFrameEvent e) { |
783 |
mainFrame.enableControls(); |
784 |
} |
785 |
|
786 |
/**
|
787 |
* @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
|
788 |
*/
|
789 |
public void internalFrameIconified(InternalFrameEvent e) { |
790 |
mainFrame.enableControls(); |
791 |
} |
792 |
|
793 |
/**
|
794 |
* @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent)
|
795 |
*/
|
796 |
public void internalFrameOpened(InternalFrameEvent e) { |
797 |
// logger.debug("internalFrameOpened. Source= " +
|
798 |
// e.getSource().toString());
|
799 |
} |
800 |
} |
801 |
|
802 |
/**
|
803 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Class,
|
804 |
* java.lang.Object)
|
805 |
*/
|
806 |
public boolean closeSingletonWindow(Class viewClass, Object model) { |
807 |
JInternalFrame frame = sws.getFrame(viewClass, model);
|
808 |
if (frame == null) |
809 |
return false; |
810 |
closeJInternalFrame(frame); |
811 |
return true; |
812 |
} |
813 |
|
814 |
/**
|
815 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Object)
|
816 |
*/
|
817 |
public boolean closeSingletonWindow(Object model) { |
818 |
JInternalFrame[] frames = sws.getFrames(model); |
819 |
if (frames.length == 0) |
820 |
return false; |
821 |
for (int i = 0; i < frames.length; i++) { |
822 |
closeJInternalFrame(frames[i]); |
823 |
} |
824 |
return true; |
825 |
} |
826 |
|
827 |
/**
|
828 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getAllWindows()
|
829 |
*/
|
830 |
public IWindow[] getAllWindows() { |
831 |
ArrayList windows = new ArrayList(); |
832 |
Iterator i = fws.getWindowIterator();
|
833 |
|
834 |
while (i.hasNext()) {
|
835 |
windows.add((IWindow) i.next()); |
836 |
} |
837 |
return (IWindow[]) windows.toArray(new IWindow[0]); |
838 |
} |
839 |
|
840 |
/**
|
841 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getOrderedWindows()
|
842 |
*/
|
843 |
public IWindow[] getOrderedWindows() { |
844 |
//ArrayList windows = new ArrayList();
|
845 |
TreeMap windows = new TreeMap(); |
846 |
Iterator winIterator = fws.getWindowIterator();
|
847 |
|
848 |
Component frame;
|
849 |
IWindow win; |
850 |
/**
|
851 |
* The order of the window in the JDesktopPane. Smaller numbers
|
852 |
* are closer to the foreground.
|
853 |
*/
|
854 |
int zPosition;
|
855 |
while (winIterator.hasNext()) {
|
856 |
win = (IWindow) winIterator.next(); |
857 |
frame = fws.getFrame(win); |
858 |
zPosition = panel.getPosition(frame); |
859 |
windows.put(new Integer(zPosition), win); |
860 |
} |
861 |
winIterator = windows.values().iterator(); |
862 |
ArrayList winList = new ArrayList(); |
863 |
while (winIterator.hasNext()) {
|
864 |
winList.add(winIterator.next()); |
865 |
} |
866 |
|
867 |
return (IWindow[]) winList.toArray(new IWindow[0]); |
868 |
} |
869 |
public void setMaximum(IWindow v, boolean bMaximum) throws PropertyVetoException |
870 |
{ |
871 |
JInternalFrame f = fws.getJInternalFrame(v);
|
872 |
f.setMaximum(bMaximum); |
873 |
} |
874 |
|
875 |
public void changeWindowInfo(IWindow w, WindowInfo wi){ |
876 |
JInternalFrame f = fws.getJInternalFrame(w);
|
877 |
f.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
878 |
JDesktopPane pnl = f.getDesktopPane();
|
879 |
pnl.remove(f); |
880 |
int width;
|
881 |
int height;
|
882 |
if (wi.getWidth()!=-1) |
883 |
width = wi.getWidth(); |
884 |
else
|
885 |
width = f.getWidth(); |
886 |
if (wi.getHeight()!=-1) |
887 |
height = wi.getHeight(); |
888 |
else
|
889 |
height = f.getHeight(); |
890 |
f.setSize(new Dimension(width, height)); |
891 |
f.setLocation(wi.getX(), wi.getY()); |
892 |
if (wi.isPalette()) {
|
893 |
pnl.add(f, JDesktopPane.PALETTE_LAYER);
|
894 |
f.setFocusable(false);
|
895 |
} else {
|
896 |
pnl.add(f, JDesktopPane.DEFAULT_LAYER);
|
897 |
f.setFocusable(true);
|
898 |
if (wi.isClosed()) {
|
899 |
closeWindow(w); |
900 |
} |
901 |
} |
902 |
|
903 |
if (wi.isMaximized()) {
|
904 |
try {
|
905 |
f.setMaximum(true);
|
906 |
} catch (PropertyVetoException e) { |
907 |
// TODO Auto-generated catch block
|
908 |
//e.printStackTrace();
|
909 |
} |
910 |
f.setNormalBounds(wi.getNormalBounds()); |
911 |
} |
912 |
activateJInternalFrame(f); |
913 |
} |
914 |
|
915 |
public void setBackgroundImage(ImageIcon image, String typeDesktop) { |
916 |
this.image=image;
|
917 |
this.typeDesktop=typeDesktop;
|
918 |
|
919 |
} |
920 |
class MyDesktopPane extends JDesktopPane |
921 |
{ |
922 |
public MyDesktopPane(){
|
923 |
} |
924 |
public void paintComponent(Graphics g){ |
925 |
super.paintComponent(g);
|
926 |
int x=0; |
927 |
int y=0; |
928 |
int w=0; |
929 |
int h=0; |
930 |
if (image != null) { |
931 |
if (typeDesktop.equals(Theme.CENTERED)) {
|
932 |
w = image.getIconWidth(); |
933 |
h = image.getIconHeight(); |
934 |
x = (getWidth() - w) / 2;
|
935 |
y = (getHeight() - h) / 2;
|
936 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
937 |
} else if (typeDesktop.equals(Theme.EXPAND)) { |
938 |
w = getWidth(); |
939 |
h = getHeight(); |
940 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
941 |
} else if (typeDesktop.equals(Theme.MOSAIC)) { |
942 |
int wAux = image.getIconWidth();
|
943 |
int hAux = image.getIconHeight();
|
944 |
int i = 0; |
945 |
int j = 0; |
946 |
w = wAux; |
947 |
h = hAux; |
948 |
while (x < getWidth()) {
|
949 |
x = wAux * i; |
950 |
while (y < getHeight()) {
|
951 |
y = hAux * j; |
952 |
j++; |
953 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
954 |
} |
955 |
y = 0;
|
956 |
j = 0;
|
957 |
i++; |
958 |
} |
959 |
} |
960 |
} |
961 |
} |
962 |
} |
963 |
} |