svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / mdiManager / NewSkin.java @ 39395
History | View | Annotate | Download (42 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 org.gvsig.coreplugin.mdiManager; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.Component; |
46 |
import java.awt.Container; |
47 |
import java.awt.Cursor; |
48 |
import java.awt.Dimension; |
49 |
import java.awt.Graphics; |
50 |
import java.awt.KeyEventDispatcher; |
51 |
import java.awt.Point; |
52 |
import java.awt.event.ActionEvent; |
53 |
import java.awt.event.ActionListener; |
54 |
import java.awt.event.ComponentEvent; |
55 |
import java.awt.event.ComponentListener; |
56 |
import java.awt.event.KeyEvent; |
57 |
import java.awt.event.WindowAdapter; |
58 |
import java.awt.event.WindowEvent; |
59 |
import java.beans.PropertyVetoException; |
60 |
import java.util.ArrayList; |
61 |
import java.util.HashMap; |
62 |
import java.util.Hashtable; |
63 |
import java.util.Iterator; |
64 |
import java.util.Map; |
65 |
import java.util.TreeMap; |
66 |
|
67 |
import javax.swing.DefaultDesktopManager; |
68 |
import javax.swing.DesktopManager; |
69 |
import javax.swing.ImageIcon; |
70 |
import javax.swing.JDesktopPane; |
71 |
import javax.swing.JDialog; |
72 |
import javax.swing.JFrame; |
73 |
import javax.swing.JInternalFrame; |
74 |
import javax.swing.JLayeredPane; |
75 |
import javax.swing.JPanel; |
76 |
import javax.swing.JPopupMenu; |
77 |
import javax.swing.JScrollPane; |
78 |
import javax.swing.KeyStroke; |
79 |
import javax.swing.SwingUtilities; |
80 |
import javax.swing.event.InternalFrameEvent; |
81 |
import javax.swing.event.InternalFrameListener; |
82 |
|
83 |
import org.gvsig.andami.IconThemeHelper; |
84 |
import org.gvsig.andami.PluginServices; |
85 |
import org.gvsig.andami.plugins.Extension; |
86 |
import org.gvsig.andami.ui.mdiFrame.GlassPane; |
87 |
import org.gvsig.andami.ui.mdiFrame.MDIFrame; |
88 |
import org.gvsig.andami.ui.mdiFrame.NewStatusBar; |
89 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
90 |
import org.gvsig.andami.ui.mdiManager.IWindowListener; |
91 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
92 |
import org.gvsig.andami.ui.mdiManager.MDIUtilities; |
93 |
import org.gvsig.andami.ui.mdiManager.SingletonDialogAlreadyShownException; |
94 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
95 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
96 |
import org.gvsig.andami.ui.theme.Theme; |
97 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
98 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE; |
99 |
import org.gvsig.tools.task.RunnableWithParameters; |
100 |
import org.slf4j.Logger; |
101 |
import org.slf4j.LoggerFactory; |
102 |
|
103 |
|
104 |
/**
|
105 |
*
|
106 |
*/
|
107 |
public class NewSkin extends Extension implements MDIManager{ |
108 |
private static final int DefaultXMargin = 20; // Added for the method 'centreJInternalFrame' |
109 |
private static final int DefaultYMargin = 20; // Added for the method 'centreJInternalFrame' |
110 |
private static final int MinimumXMargin = 130; // Added for the method 'centreJInternalFrame' |
111 |
private static final int MinimumYMargin = 60; // Added for the method 'centreJInternalFrame' |
112 |
|
113 |
|
114 |
/**
|
115 |
* Variable privada <code>desktopManager</code> para usarlo cuando sale
|
116 |
* una ventana que no queremos que nos restaure las que tenemos maximizadas.
|
117 |
* Justo antes de usar el setMaximize(false), le pegamos el cambiazo.
|
118 |
*/
|
119 |
private static DesktopManager desktopManager = new DefaultDesktopManager(); |
120 |
|
121 |
/** log */
|
122 |
private static Logger logger = LoggerFactory.getLogger(NewSkin.class.getName()); |
123 |
|
124 |
/** Panel de la MDIFrame */
|
125 |
private MyDesktopPane panel = new MyDesktopPane(); |
126 |
|
127 |
/** MDIFrame */
|
128 |
private MDIFrame mainFrame;
|
129 |
|
130 |
private GlassPane glassPane = new GlassPane(); |
131 |
|
132 |
private DialogStackSupport dss;
|
133 |
|
134 |
/**
|
135 |
* Associates JInternalFrames with the IWindow they contain
|
136 |
*/
|
137 |
private FrameWindowSupport fws;
|
138 |
|
139 |
private WindowInfoSupport wis;
|
140 |
|
141 |
private WindowStackSupport wss;
|
142 |
|
143 |
private SingletonWindowSupport sws;
|
144 |
|
145 |
private Cursor lastCursor = null; |
146 |
private ImageIcon image; |
147 |
private String typeDesktop; |
148 |
|
149 |
private int alignCounter = 1; |
150 |
|
151 |
//Anyade barras de scroll
|
152 |
private void addScrolledDesktopPanel( JFrame parent, MyDesktopPane desktopPane) { |
153 |
JPanel toppanel;
|
154 |
|
155 |
toppanel = new JPanel(); |
156 |
toppanel.setLayout(new BorderLayout()); |
157 |
toppanel.setPreferredSize(new Dimension(200,200)); |
158 |
toppanel.setBackground(Color.RED);
|
159 |
|
160 |
JScrollPane scrollPanel = new JScrollPane(desktopPane); |
161 |
|
162 |
toppanel.add(scrollPanel, BorderLayout.CENTER);
|
163 |
|
164 |
parent.getContentPane().add(toppanel, BorderLayout.CENTER);
|
165 |
} |
166 |
|
167 |
public JDesktopPane getDesktopPane() { |
168 |
return this.panel; |
169 |
} |
170 |
|
171 |
/*
|
172 |
* @see com.iver.andami.ui.mdiManager.MDIManager#init(com.iver.andami.ui.mdiFrame.MDIFrame)
|
173 |
*/
|
174 |
public void init(MDIFrame f) { |
175 |
|
176 |
// Inicializa el Frame y la consola
|
177 |
mainFrame = f; |
178 |
mainFrame.setGlassPane(glassPane); |
179 |
panel.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
|
180 |
|
181 |
//Anyade barras de scroll
|
182 |
//mainFrame.getContentPane().add(panel, BorderLayout.CENTER);
|
183 |
addScrolledDesktopPanel(mainFrame,panel); |
184 |
|
185 |
panel.setDesktopManager(desktopManager); |
186 |
|
187 |
fws = createFrameWindowSupport(mainFrame); |
188 |
dss = new DialogStackSupport(mainFrame);
|
189 |
sws = new SingletonWindowSupport(wis, fws);
|
190 |
wis = new WindowInfoSupport(mainFrame, fws, sws);
|
191 |
fws.setVis(wis); |
192 |
wss = new WindowStackSupport(wis);
|
193 |
|
194 |
|
195 |
// TODO (jaume) esto no deber�a de estar aqu�...
|
196 |
// molar�a m�s en un di�logo de preferencias
|
197 |
// es s�lo una prueba
|
198 |
KeyStroke controlTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_MASK); |
199 |
|
200 |
PluginServices.registerKeyStroke(controlTab, new KeyEventDispatcher() { |
201 |
|
202 |
public boolean dispatchKeyEvent(KeyEvent e) { |
203 |
IWindow[] views = getAllWindows();
|
204 |
if (views.length<=0 || e.getID() == KeyEvent.KEY_PRESSED) |
205 |
return false; |
206 |
|
207 |
|
208 |
int current = 0; |
209 |
for (int i = 0; i < views.length; i++) { |
210 |
if (views[i].equals(getActiveWindow())) {
|
211 |
current = i; |
212 |
break;
|
213 |
} |
214 |
} |
215 |
addWindow(views[(current +1) % views.length]);
|
216 |
return true; |
217 |
} |
218 |
|
219 |
}); |
220 |
} |
221 |
|
222 |
/**
|
223 |
* Create the {@link FrameWindowSupport} instance
|
224 |
*
|
225 |
* @param mainFrame
|
226 |
*
|
227 |
*/
|
228 |
protected FrameWindowSupport createFrameWindowSupport(MDIFrame mainFrame) {
|
229 |
return new FrameWindowSupport(mainFrame); |
230 |
} |
231 |
|
232 |
/* (non-javadoc)
|
233 |
* @see com.iver.andami.ui.mdiManager.MDIManager#addWindow(com.iver.andami.ui.mdiManager.IWindow)
|
234 |
*/
|
235 |
public IWindow addWindow(final IWindow p) throws SingletonDialogAlreadyShownException { |
236 |
|
237 |
if( !SwingUtilities.isEventDispatchThread() ) { |
238 |
RunnableWithParameters action = new RunnableWithParameters() {
|
239 |
public void run() { |
240 |
this.returnValue = addWindow(p);
|
241 |
} |
242 |
}; |
243 |
try {
|
244 |
SwingUtilities.invokeAndWait(action);
|
245 |
} catch (Exception e) { |
246 |
logger.info("Can't add window from othrer thread that EventDispatch",e );
|
247 |
IllegalThreadStateException e2 = new IllegalThreadStateException(); |
248 |
e2.initCause(e); |
249 |
throw e2;
|
250 |
} |
251 |
return (IWindow) action.getReturnValue();
|
252 |
} |
253 |
|
254 |
// se obtiene la informaci�n de la vista
|
255 |
WindowInfo wi = wis.getWindowInfo(p); |
256 |
|
257 |
// Se comprueban las incompatibilidades que pudieran haber en la vista
|
258 |
MDIUtilities.checkWindowInfo(wi); |
259 |
if ((p instanceof SingletonWindow) && (wi.isModal())) { |
260 |
throw new RuntimeException("A modal view cannot be a SingletonView"); |
261 |
} |
262 |
|
263 |
/*
|
264 |
* Se obtiene la referencia a la vista anterior por si es una singleton
|
265 |
* y est� siendo mostrada. Se obtiene su informaci�n si ya fue mostrada
|
266 |
*/
|
267 |
boolean singletonPreviouslyAdded = false; |
268 |
|
269 |
if (p instanceof SingletonWindow) { |
270 |
SingletonWindow sw = (SingletonWindow) p; |
271 |
if (sws.registerWindow(sw.getClass(), sw.getWindowModel(), wi)) {
|
272 |
singletonPreviouslyAdded = true;
|
273 |
} |
274 |
} |
275 |
|
276 |
if (singletonPreviouslyAdded) {
|
277 |
// Si la vista no est� actualmente abierta
|
278 |
if (!sws.contains((SingletonWindow) p)) {
|
279 |
JInternalFrame frame = fws.getJInternalFrame(p);
|
280 |
sws.openSingletonWindow((SingletonWindow) p, frame); |
281 |
addJInternalFrame(frame, wi); |
282 |
wss.add(p, new ActionListener() { |
283 |
public void actionPerformed(ActionEvent e) { |
284 |
IWindow v = wis.getWindowById(Integer.parseInt(e
|
285 |
.getActionCommand())); |
286 |
JInternalFrame f = fws.getJInternalFrame(v);
|
287 |
activateJInternalFrame(f); |
288 |
} |
289 |
}); |
290 |
return p;
|
291 |
} else {
|
292 |
// La vista est� actualmente abierta
|
293 |
JInternalFrame frame = (JInternalFrame) sws |
294 |
.getFrame((SingletonWindow) p); |
295 |
activateJInternalFrame(frame); |
296 |
wss.setActive(p); |
297 |
return fws.getWindow((JInternalFrame) frame); |
298 |
} |
299 |
} else {
|
300 |
if (wi.isModal()) {
|
301 |
addJDialog(p); |
302 |
} else {
|
303 |
// Se sit�a la vista en la pila de vistas
|
304 |
wss.add(p, new ActionListener() { |
305 |
public void actionPerformed(ActionEvent e) { |
306 |
IWindow v = wis.getWindowById(Integer.parseInt(e
|
307 |
.getActionCommand())); |
308 |
JInternalFrame f = fws.getJInternalFrame(v);
|
309 |
activateJInternalFrame(f); |
310 |
} |
311 |
}); |
312 |
addJInternalFrame(p); |
313 |
} |
314 |
|
315 |
return p;
|
316 |
} |
317 |
} |
318 |
|
319 |
public SingletonWindow getSingletonWindow(Class windowClass, Object model) { |
320 |
JInternalFrame frame = (JInternalFrame) sws.getFrame(windowClass,model); |
321 |
if( frame == null ) { |
322 |
return null; |
323 |
} |
324 |
return (SingletonWindow) fws.getWindow((JInternalFrame) frame); |
325 |
} |
326 |
|
327 |
|
328 |
|
329 |
/* (non-javadoc)
|
330 |
* @see com.iver.andami.ui.mdiManager.MDIManager#addWindow(com.iver.andami.ui.mdiManager.IWindow)
|
331 |
*/
|
332 |
public IWindow addCentredWindow(IWindow p) throws SingletonDialogAlreadyShownException { |
333 |
IWindow window = addWindow(p); |
334 |
if (!p.getWindowInfo().isModal()) {
|
335 |
centreFrame(window); |
336 |
} |
337 |
return window;
|
338 |
} |
339 |
|
340 |
public IWindow addWindow(IWindow p, int align) throws SingletonDialogAlreadyShownException { |
341 |
boolean singletonPreviouslyAdded = false; |
342 |
WindowInfo wi = wis.getWindowInfo(p); |
343 |
|
344 |
if (p instanceof SingletonWindow) { |
345 |
SingletonWindow sw = (SingletonWindow) p; |
346 |
if (sws.registerWindow(sw.getClass(), sw.getWindowModel(), wi)) {
|
347 |
singletonPreviouslyAdded = true;
|
348 |
} |
349 |
} |
350 |
IWindow window = addWindow(p); |
351 |
if( !window.getWindowInfo().isModal() ) {
|
352 |
// if the window is modal at this oint is already closed
|
353 |
if( !singletonPreviouslyAdded ) {
|
354 |
alignFrame(window,align); |
355 |
} |
356 |
} |
357 |
return window;
|
358 |
} |
359 |
|
360 |
|
361 |
/**
|
362 |
* Centres the Frame in the contentPane of the MainFrame.
|
363 |
* If the frame can't be showed completely, it tries to show its top-left
|
364 |
* corner.
|
365 |
*
|
366 |
* @author Pablo Piqueras Bartolom�
|
367 |
*
|
368 |
* @param panel The IWindow to centre
|
369 |
*/
|
370 |
public synchronized void centreFrame(final IWindow panel) { |
371 |
if( !SwingUtilities.isEventDispatchThread() ) { |
372 |
SwingUtilities.invokeLater( new Runnable() { |
373 |
public void run() { |
374 |
centreFrame(panel); |
375 |
} |
376 |
}); |
377 |
return;
|
378 |
} |
379 |
Component window = fws.getFrame(panel);
|
380 |
if (window==null) return; |
381 |
|
382 |
// The top-left square of frame reference
|
383 |
Point newReferencePoint = new Point(); |
384 |
|
385 |
// A reference to the panel where the JInternalFrame will be displayed
|
386 |
Container contentPane = ((JFrame)PluginServices.getMainFrame()).getContentPane(); |
387 |
|
388 |
// Get the NewStatusBar component
|
389 |
NewStatusBar newStatusBar = ((NewStatusBar)contentPane.getComponent(1));
|
390 |
JDesktopPane jDesktopPane = this.getDesktopPane(); |
391 |
|
392 |
int visibleWidth = contentPane.getWidth() - contentPane.getX(); // The last substraction is for if there is any menu,... at left |
393 |
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 |
394 |
int freeWidth = visibleWidth - window.getWidth();
|
395 |
int freeHeight = visibleHeight - window.getHeight();
|
396 |
|
397 |
// Calculate the new point reference (Assure that the top-left corner is showed)
|
398 |
if (freeWidth < 0) |
399 |
{ |
400 |
if (visibleWidth > MinimumXMargin)
|
401 |
newReferencePoint.x = DefaultXMargin; |
402 |
else
|
403 |
newReferencePoint.x = 0;
|
404 |
} |
405 |
else
|
406 |
newReferencePoint.x = freeWidth / 2;
|
407 |
|
408 |
if (freeHeight < 0) |
409 |
{ |
410 |
if (visibleHeight > MinimumYMargin)
|
411 |
newReferencePoint.y = DefaultYMargin; |
412 |
else
|
413 |
newReferencePoint.y = 0;
|
414 |
} |
415 |
else
|
416 |
newReferencePoint.y = freeHeight / 2;
|
417 |
|
418 |
// Set the new location for this JInternalFrame
|
419 |
window.setLocation(newReferencePoint); |
420 |
} |
421 |
|
422 |
public synchronized void alignFrame(final IWindow panel, final int mode) { |
423 |
if( !SwingUtilities.isEventDispatchThread() ) { |
424 |
SwingUtilities.invokeLater( new Runnable() { |
425 |
public void run() { |
426 |
alignFrame(panel,mode); |
427 |
} |
428 |
}); |
429 |
return;
|
430 |
} |
431 |
Component window = fws.getFrame(panel);
|
432 |
if (window==null) { |
433 |
return;
|
434 |
} |
435 |
|
436 |
// The top-left square of frame reference
|
437 |
Point newReferencePoint = new Point(); |
438 |
|
439 |
// A reference to the panel where the JInternalFrame will be displayed
|
440 |
Container contentPane = ((JFrame)PluginServices.getMainFrame()).getContentPane(); |
441 |
|
442 |
// Get the NewStatusBar component
|
443 |
NewStatusBar newStatusBar = ((NewStatusBar)contentPane.getComponent(1));
|
444 |
JDesktopPane jDesktopPane = this.getDesktopPane(); |
445 |
|
446 |
int visibleWidth = contentPane.getWidth() - contentPane.getX(); // The last substraction is for if there is any menu,... at left |
447 |
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 |
448 |
|
449 |
// ---------------------------------------------------------------
|
450 |
// |FIRST_LINE_START(23) PAGE_START(19) FIRST_LINE_END(24) |
|
451 |
// | |
|
452 |
// | |
|
453 |
// |LINE_START(21) CENTER(10) LINE_END(22)|
|
454 |
// | |
|
455 |
// | |
|
456 |
// |LAST_LINE_START(25) PAGE_END(20) LAST_LINE_END(26) |
|
457 |
// ---------------------------------------------------------------
|
458 |
|
459 |
switch (mode) {
|
460 |
case ALIGN_FIRST_LINE_START:
|
461 |
newReferencePoint.x = DefaultXMargin; |
462 |
newReferencePoint.y = DefaultYMargin; |
463 |
break;
|
464 |
|
465 |
case ALIGN_PAGE_START:
|
466 |
newReferencePoint.x = visibleWidth / 2;
|
467 |
newReferencePoint.y = DefaultYMargin; |
468 |
break;
|
469 |
|
470 |
case ALIGN_FIRST_LINE_END:
|
471 |
newReferencePoint.x = visibleWidth - window.getWidth() - DefaultXMargin; |
472 |
newReferencePoint.y = DefaultYMargin; |
473 |
break;
|
474 |
|
475 |
case ALIGN_FIRST_LINE_END_CASCADE:
|
476 |
newReferencePoint.x = visibleWidth - window.getWidth() - (int)(DefaultXMargin + (DefaultXMargin*1.5*this.alignCounter)); |
477 |
newReferencePoint.y = DefaultYMargin + (int)(DefaultYMargin*1.5*this.alignCounter); |
478 |
if( ++this.alignCounter >5 ) { |
479 |
this.alignCounter = 0; |
480 |
} |
481 |
break;
|
482 |
|
483 |
case ALIGN_LINE_START:
|
484 |
newReferencePoint.x = DefaultXMargin; |
485 |
newReferencePoint.y = visibleHeight / 2;
|
486 |
break;
|
487 |
|
488 |
case ALIGN_LINE_END:
|
489 |
newReferencePoint.x = visibleWidth - window.getWidth() - DefaultXMargin; |
490 |
newReferencePoint.y = visibleHeight / 2;
|
491 |
break;
|
492 |
|
493 |
case ALIGN_LAST_LINE_START:
|
494 |
newReferencePoint.x = DefaultXMargin; |
495 |
newReferencePoint.y = visibleHeight - window.getHeight() - DefaultYMargin; |
496 |
break;
|
497 |
|
498 |
case ALIGN_PAGE_END:
|
499 |
newReferencePoint.x = visibleWidth / 2;
|
500 |
newReferencePoint.y = visibleHeight - window.getHeight() - DefaultYMargin; |
501 |
break;
|
502 |
|
503 |
case ALIGN_LAST_LINE_END:
|
504 |
newReferencePoint.x = visibleWidth - window.getWidth() - DefaultXMargin; |
505 |
newReferencePoint.y = visibleHeight - window.getHeight() - DefaultYMargin; |
506 |
break;
|
507 |
|
508 |
default:
|
509 |
case ALIGN_CENTER:
|
510 |
newReferencePoint.x = visibleWidth / 2;
|
511 |
newReferencePoint.y = visibleHeight / 2;
|
512 |
break;
|
513 |
} |
514 |
|
515 |
if( newReferencePoint.x < 0 ) { |
516 |
newReferencePoint.x = DefaultXMargin; |
517 |
} |
518 |
if( newReferencePoint.y < 0 ) { |
519 |
newReferencePoint.y = DefaultYMargin; |
520 |
} |
521 |
window.setLocation(newReferencePoint); |
522 |
} |
523 |
|
524 |
/**
|
525 |
* DOCUMENT ME!
|
526 |
*
|
527 |
* @param wnd
|
528 |
* DOCUMENT ME!
|
529 |
* @param wi
|
530 |
* DOCUMENT ME!
|
531 |
*/
|
532 |
private void addJInternalFrame(JInternalFrame wnd, WindowInfo wi) { |
533 |
wnd.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
534 |
wnd.addInternalFrameListener(new FrameListener());
|
535 |
|
536 |
if (wi.isModeless() || wi.isPalette()) {
|
537 |
panel.add(wnd, JDesktopPane.PALETTE_LAYER);
|
538 |
if (wi.isPalette())
|
539 |
wnd.setFocusable(false);
|
540 |
} else {
|
541 |
panel.add(wnd); |
542 |
} |
543 |
updateFrameProperties(wnd, wi); |
544 |
activateJInternalFrame(wnd); |
545 |
try{
|
546 |
wnd.setMaximum(wi.isMaximized()); |
547 |
}catch(Exception ex){ |
548 |
logger.warn("Error: ", ex);
|
549 |
} |
550 |
} |
551 |
|
552 |
private void updateFrameProperties(JInternalFrame frame, WindowInfo wi) { |
553 |
int height, width;
|
554 |
if (wi.isMaximized()) {
|
555 |
if (wi.getNormalWidth()!=-1) |
556 |
width = wi.getNormalWidth(); |
557 |
else
|
558 |
width = frame.getNormalBounds().width; |
559 |
if (wi.getNormalHeight()!=-1) |
560 |
height = wi.getNormalHeight(); |
561 |
else
|
562 |
height = frame.getNormalBounds().height; |
563 |
|
564 |
frame.setSize(width, height); |
565 |
frame.setLocation(wi.getNormalX(), wi.getNormalY()); |
566 |
} |
567 |
else {
|
568 |
if (wi.getWidth()!=-1) |
569 |
width = wi.getWidth(); |
570 |
else
|
571 |
width = frame.getWidth(); |
572 |
if (wi.getHeight()!=-1) |
573 |
height = wi.getHeight(); |
574 |
else
|
575 |
height = frame.getHeight(); |
576 |
frame.setSize(width, height); |
577 |
frame.setLocation(wi.getX(), wi.getY()); |
578 |
} |
579 |
frame.setTitle(wi.getTitle()); |
580 |
frame.setVisible(wi.isVisible()); |
581 |
frame.setResizable(wi.isResizable()); |
582 |
frame.setIconifiable(wi.isIconifiable()); |
583 |
frame.setMaximizable(wi.isMaximizable()); |
584 |
try {
|
585 |
frame.setMaximum(wi.isMaximized()); |
586 |
} catch (PropertyVetoException e) { |
587 |
// TODO Auto-generated catch block
|
588 |
//e.printStackTrace();
|
589 |
} |
590 |
} |
591 |
|
592 |
/**
|
593 |
* DOCUMENT ME!
|
594 |
*
|
595 |
* @param p
|
596 |
*/
|
597 |
private void addJInternalFrame(IWindow p) { |
598 |
WindowInfo wi = wis.getWindowInfo(p); |
599 |
|
600 |
JInternalFrame wnd = fws.getJInternalFrame(p);
|
601 |
|
602 |
if (p instanceof SingletonWindow) { |
603 |
SingletonWindow sv = (SingletonWindow) p; |
604 |
sws.openSingletonWindow(sv, wnd); |
605 |
} |
606 |
|
607 |
addJInternalFrame(wnd, wi); |
608 |
} |
609 |
|
610 |
/**
|
611 |
* DOCUMENT ME!
|
612 |
*
|
613 |
* @param wnd
|
614 |
*/
|
615 |
private void activateJInternalFrame(JInternalFrame wnd) { |
616 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
617 |
try {
|
618 |
wnd.moveToFront(); |
619 |
logger.debug("Activando " + wnd.getTitle());
|
620 |
wnd.setSelected(true);
|
621 |
wnd.setIcon(false);
|
622 |
} catch (PropertyVetoException e) { |
623 |
logger.error(e.toString()); |
624 |
} |
625 |
} |
626 |
|
627 |
/**
|
628 |
* Situa un di�logo modal en el centro de la pantalla
|
629 |
*
|
630 |
* @param d
|
631 |
* Di�logo que se quiere situar
|
632 |
*/
|
633 |
private void centerDialog(JDialog d) { |
634 |
int offSetX = d.getWidth() / 2; |
635 |
int offSetY = d.getHeight() / 2; |
636 |
|
637 |
d.setLocation((mainFrame.getWidth() / 2) - offSetX, (mainFrame
|
638 |
.getHeight() / 2)
|
639 |
- offSetY); |
640 |
} |
641 |
|
642 |
/**
|
643 |
* DOCUMENT ME!
|
644 |
*
|
645 |
* @param p
|
646 |
*/
|
647 |
private void addJDialog(IWindow p) { |
648 |
JDialog dlg = fws.getJDialog(p);
|
649 |
|
650 |
centerDialog(dlg); |
651 |
|
652 |
dlg.addWindowListener(new DialogWindowListener());
|
653 |
dss.pushDialog(dlg); |
654 |
|
655 |
dlg.setVisible(wis.getWindowInfo(p).isVisible()); |
656 |
} |
657 |
|
658 |
/*
|
659 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getActiveWindow()
|
660 |
*/
|
661 |
public IWindow getActiveWindow() {
|
662 |
JInternalFrame jif = panel.getSelectedFrame();
|
663 |
|
664 |
if (jif != null) { |
665 |
IWindow theWindow = fws.getWindow(jif); |
666 |
if (theWindow == null) |
667 |
return null; |
668 |
if (theWindow.getWindowInfo().isPalette())
|
669 |
return wss.getActiveWindow();
|
670 |
else
|
671 |
return fws.getWindow(jif);
|
672 |
} |
673 |
// return vss.getActiveView();
|
674 |
|
675 |
return null; |
676 |
} |
677 |
public IWindow getFocusWindow(){
|
678 |
JInternalFrame jif = panel.getSelectedFrame();
|
679 |
|
680 |
if (jif != null) { |
681 |
IWindow theView = fws.getWindow(jif); |
682 |
if (theView == null) |
683 |
return null; |
684 |
return fws.getWindow(jif);
|
685 |
} |
686 |
return null; |
687 |
} |
688 |
/*
|
689 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeWindow(com.iver.andami.ui.mdiManager.IWindow)
|
690 |
*/
|
691 |
public void closeWindow(final IWindow p) { |
692 |
if( !SwingUtilities.isEventDispatchThread() ) { |
693 |
SwingUtilities.invokeLater( new Runnable() { |
694 |
public void run() { |
695 |
closeWindow(p); |
696 |
} |
697 |
}); |
698 |
return;
|
699 |
} |
700 |
// Si es un di�logo modal
|
701 |
if (p.getWindowInfo().isModal()) {
|
702 |
closeJDialog(); |
703 |
} else { // Si no es modal se cierra el JInternalFrame |
704 |
closeJInternalFrame(fws.getJInternalFrame(p)); |
705 |
} |
706 |
} |
707 |
|
708 |
/*
|
709 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeAllWindows()
|
710 |
*/
|
711 |
public void closeAllWindows() { |
712 |
if( !SwingUtilities.isEventDispatchThread() ) { |
713 |
SwingUtilities.invokeLater( new Runnable() { |
714 |
public void run() { |
715 |
closeAllWindows(); |
716 |
} |
717 |
}); |
718 |
return;
|
719 |
} |
720 |
ArrayList eliminar = new ArrayList(); |
721 |
Iterator i = fws.getWindowIterator();
|
722 |
|
723 |
while (i.hasNext()) {
|
724 |
eliminar.add((IWindow) i.next()); |
725 |
} |
726 |
|
727 |
for (Iterator iter = eliminar.iterator(); iter.hasNext();) { |
728 |
IWindow vista = (IWindow) iter.next(); |
729 |
closeWindow(vista); |
730 |
} |
731 |
} |
732 |
|
733 |
/*
|
734 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getWindowInfo(com.iver.andami.ui.mdiManager.IWindow)
|
735 |
*/
|
736 |
public WindowInfo getWindowInfo(IWindow w) {
|
737 |
WindowInfo wi = wis.getWindowInfo(w); |
738 |
|
739 |
/*
|
740 |
* This is done now in vis.getWindowInfo(w)
|
741 |
*
|
742 |
* JInternalFrame f = fws.getJInternalFrame(w);
|
743 |
wi.setX(f.getX());
|
744 |
wi.setY(f.getY());
|
745 |
wi.setHeight(f.getHeight());
|
746 |
wi.setWidth(f.getWidth());
|
747 |
// isClosed() doesn't work as (I) expected, why? Using isShowing instead
|
748 |
wi.setClosed(!f.isShowing());
|
749 |
wi.setNormalBounds(f.getNormalBounds());
|
750 |
wi.setMaximized(f.isMaximum());*/
|
751 |
return wi;
|
752 |
} |
753 |
|
754 |
/**
|
755 |
* DOCUMENT ME!
|
756 |
*
|
757 |
* @param dialog
|
758 |
* @throws RuntimeException
|
759 |
* DOCUMENT ME!
|
760 |
*/
|
761 |
private void closeJDialog() { |
762 |
JDialog dlg = dss.popDialog();
|
763 |
if (dlg==null) |
764 |
return;
|
765 |
dlg.setVisible(false);
|
766 |
|
767 |
IWindow s = fws.getWindow(dlg); |
768 |
|
769 |
callWindowClosed(s); |
770 |
|
771 |
fws.closeWindow(s); |
772 |
|
773 |
// Si es singleton se desasocia el modelo con la vista
|
774 |
if (s instanceof SingletonWindow) { |
775 |
sws.closeWindow((SingletonWindow) s); |
776 |
} |
777 |
} |
778 |
|
779 |
/**
|
780 |
* If <code>window</code> implements IWindowListener, sent it
|
781 |
* the windowActivated event.
|
782 |
*
|
783 |
* @param window
|
784 |
* The IWindow which has to be notified.
|
785 |
*/
|
786 |
private void callWindowClosed(IWindow window) { |
787 |
if (window instanceof IWindowListener) { |
788 |
((IWindowListener) window).windowClosed(); |
789 |
} |
790 |
} |
791 |
|
792 |
/**
|
793 |
* If <code>window</code> implements IWindowListener, sent it
|
794 |
* the windowActivated event.
|
795 |
*
|
796 |
* @param window
|
797 |
* The IWindow which has to be notified.
|
798 |
*/
|
799 |
private void callWindowActivated(IWindow window) { |
800 |
// logger.debug("View '" + window.getWindowInfo().getTitle()
|
801 |
// + "' activated (callViewActivated)");
|
802 |
if (window instanceof IWindowListener) { |
803 |
((IWindowListener) window).windowActivated(); |
804 |
} |
805 |
} |
806 |
|
807 |
/**
|
808 |
* DOCUMENT ME!
|
809 |
*
|
810 |
* @param frame
|
811 |
*/
|
812 |
private void closeJInternalFrame(final JInternalFrame frame) { |
813 |
if( !SwingUtilities.isEventDispatchThread() ) { |
814 |
SwingUtilities.invokeLater( new Runnable() { |
815 |
public void run() { |
816 |
closeJInternalFrame(frame); |
817 |
} |
818 |
}); |
819 |
return;
|
820 |
} |
821 |
try {
|
822 |
IWindow s = (IWindow) fws.getWindow(frame); |
823 |
|
824 |
frame.setClosed(true);
|
825 |
callWindowClosed(s); |
826 |
} catch (PropertyVetoException e) { |
827 |
logger |
828 |
.error( |
829 |
"Not compatible with property veto's. Use ViewInfo instead.",
|
830 |
e); |
831 |
} |
832 |
} |
833 |
|
834 |
/*
|
835 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
836 |
*/
|
837 |
public void initialize() { |
838 |
} |
839 |
|
840 |
/*
|
841 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
842 |
*/
|
843 |
public void execute(String actionCommand) { |
844 |
if ("window-cascade".equalsIgnoreCase(actionCommand)) { |
845 |
logger.info("action window-cascade not implemented.");
|
846 |
|
847 |
} else if ("window-tile".equalsIgnoreCase(actionCommand)) { |
848 |
logger.info("action window-tile not implemented.");
|
849 |
} |
850 |
} |
851 |
|
852 |
/*
|
853 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
854 |
*/
|
855 |
public boolean isEnabled() { |
856 |
// TODO Auto-generated method stub
|
857 |
return false; |
858 |
} |
859 |
|
860 |
/*
|
861 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
862 |
*/
|
863 |
public boolean isVisible() { |
864 |
// TODO Auto-generated method stub
|
865 |
return true; |
866 |
} |
867 |
|
868 |
/*
|
869 |
* @see com.iver.andami.ui.mdiManager.MDIManager#setWaitCursor()
|
870 |
*/
|
871 |
public void setWaitCursor() { |
872 |
if (mainFrame != null) { |
873 |
if( !SwingUtilities.isEventDispatchThread() ) { |
874 |
SwingUtilities.invokeLater( new Runnable() { |
875 |
public void run() { |
876 |
setWaitCursor(); |
877 |
} |
878 |
}); |
879 |
return;
|
880 |
} |
881 |
glassPane.setVisible(true);
|
882 |
lastCursor = mainFrame.getCursor(); |
883 |
dss.setWaitCursor(); |
884 |
glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
885 |
} |
886 |
} |
887 |
|
888 |
/*
|
889 |
* @see com.iver.andami.ui.mdiManager.MDIManager#restoreCursor()
|
890 |
*/
|
891 |
public void restoreCursor() { |
892 |
if (mainFrame != null) { |
893 |
if( !SwingUtilities.isEventDispatchThread() ) { |
894 |
SwingUtilities.invokeLater( new Runnable() { |
895 |
public void run() { |
896 |
restoreCursor(); |
897 |
} |
898 |
}); |
899 |
return;
|
900 |
} |
901 |
glassPane.setVisible(false);
|
902 |
dss.restoreCursor(); |
903 |
glassPane.setCursor(lastCursor); |
904 |
} |
905 |
} |
906 |
|
907 |
/**
|
908 |
* Listener para los eventos de cerrado de los di�logos. Tiene su raz�n de
|
909 |
* ser en que los di�logos han de devolverse al pool cuando se cierran
|
910 |
*
|
911 |
* @author Fernando Gonz�lez Cort�s
|
912 |
*/
|
913 |
public class DialogWindowListener extends WindowAdapter { |
914 |
/**
|
915 |
* Captura el evento de cerrado de los di�logos con el fin de realizar
|
916 |
* tareas de mantenimiento
|
917 |
*
|
918 |
* @param e
|
919 |
* evento
|
920 |
*/
|
921 |
public void windowActivated(WindowEvent e) { |
922 |
IWindow window = fws.getWindow((Component) e.getSource());
|
923 |
callWindowActivated(window); |
924 |
|
925 |
} |
926 |
|
927 |
|
928 |
/**
|
929 |
* Captura el evento de cerrado de los di�logos con el fin de realizar
|
930 |
* tareas de mantenimiento
|
931 |
*
|
932 |
* @param e
|
933 |
* evento
|
934 |
*/
|
935 |
public void windowClosing(WindowEvent e) { |
936 |
closeJDialog(); |
937 |
} |
938 |
} |
939 |
|
940 |
/**
|
941 |
* DOCUMENT ME!
|
942 |
*/
|
943 |
public class FrameListener implements InternalFrameListener { |
944 |
/*
|
945 |
* @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent)
|
946 |
*/
|
947 |
public void internalFrameActivated(InternalFrameEvent e) { |
948 |
// logger.debug("internalFrameActivated " +
|
949 |
// e.getInternalFrame().getTitle());
|
950 |
|
951 |
// activatedInternalFramesStack.push(e.getInternalFrame());
|
952 |
|
953 |
IWindow panel = fws.getWindow((JInternalFrame) e.getSource());
|
954 |
|
955 |
WindowInfo wi = wis.getWindowInfo(panel); |
956 |
if (wi.isPalette())
|
957 |
return;
|
958 |
|
959 |
wss.setActive(panel); |
960 |
|
961 |
JInternalFrame frame = fws.getJInternalFrame(panel);
|
962 |
|
963 |
if (wi.isMaximizable()){
|
964 |
frame.setMaximizable(true);
|
965 |
} |
966 |
if (!frame.isMaximizable() && frame.isMaximum()) {
|
967 |
try {
|
968 |
frame.setMaximum(false);
|
969 |
} catch (PropertyVetoException e1) { |
970 |
} |
971 |
} |
972 |
mainFrame.enableControls(); |
973 |
if (wi.getSelectedTools()==null) { |
974 |
// this is the first time this window is activated
|
975 |
wi.setSelectedTools(new HashMap(mainFrame.getInitialSelectedTools())); |
976 |
} |
977 |
mainFrame.setSelectedTools(wi.getSelectedTools()); |
978 |
callWindowActivated(panel); |
979 |
|
980 |
} |
981 |
|
982 |
/*
|
983 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
|
984 |
*/
|
985 |
public void internalFrameClosed(InternalFrameEvent e) { |
986 |
} |
987 |
|
988 |
/*
|
989 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent)
|
990 |
*/
|
991 |
public void internalFrameClosing(InternalFrameEvent e) { |
992 |
// Se elimina la memoria del JInternalFrame si no es ALWAYS_LIVE
|
993 |
// logger.debug("internalFrameClosing " +
|
994 |
// e.getInternalFrame().getTitle());
|
995 |
|
996 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
997 |
WindowInfo wi = wis.getWindowInfo((IWindow) fws.getWindow(c)); |
998 |
|
999 |
IWindow win = fws.getWindow(c); |
1000 |
callWindowClosed(win); |
1001 |
boolean alwaysLive;
|
1002 |
if (win instanceof SingletonWindow) { |
1003 |
sws.closeWindow((SingletonWindow) win); |
1004 |
} |
1005 |
|
1006 |
fws.closeWindow(win); |
1007 |
|
1008 |
panel.remove(c); |
1009 |
|
1010 |
wss.remove(win); |
1011 |
|
1012 |
if (!wi.isPalette())
|
1013 |
mainFrame.enableControls(); |
1014 |
panel.repaint(); |
1015 |
|
1016 |
// Para activar el JInternalFrame desde la que hemos
|
1017 |
// abierto la ventana que estamos cerrando
|
1018 |
IWindow lastWindow = wss.getActiveWindow(); |
1019 |
// La activamos
|
1020 |
if (lastWindow != null) { |
1021 |
logger.debug(PluginServices.getText(this, "Devuelvo_el_foco_a_")+lastWindow.getWindowInfo().getTitle()); |
1022 |
JInternalFrame frame = fws.getJInternalFrame(lastWindow);
|
1023 |
try {
|
1024 |
frame.setSelected(true);
|
1025 |
} catch (PropertyVetoException e1) { |
1026 |
// TODO Auto-generated catch block
|
1027 |
// e1.printStackTrace();
|
1028 |
} |
1029 |
// addView(lastView);
|
1030 |
} |
1031 |
|
1032 |
} |
1033 |
|
1034 |
/*
|
1035 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent)
|
1036 |
*/
|
1037 |
public void internalFrameDeactivated(InternalFrameEvent e) { |
1038 |
// logger.debug("internalDeActivated " +
|
1039 |
// e.getInternalFrame().getTitle());
|
1040 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
1041 |
IWindow win = fws.getWindow(c); |
1042 |
if (win != null) { |
1043 |
WindowInfo wi = wis.getWindowInfo(win); |
1044 |
if (wi.isPalette())
|
1045 |
return;
|
1046 |
|
1047 |
} |
1048 |
|
1049 |
} |
1050 |
|
1051 |
/*
|
1052 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
|
1053 |
*/
|
1054 |
public void internalFrameDeiconified(InternalFrameEvent e) { |
1055 |
mainFrame.enableControls(); |
1056 |
} |
1057 |
|
1058 |
/*
|
1059 |
* @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
|
1060 |
*/
|
1061 |
public void internalFrameIconified(InternalFrameEvent e) { |
1062 |
mainFrame.enableControls(); |
1063 |
} |
1064 |
|
1065 |
/*
|
1066 |
* @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent)
|
1067 |
*/
|
1068 |
public void internalFrameOpened(InternalFrameEvent e) { |
1069 |
// logger.debug("internalFrameOpened. Source= " +
|
1070 |
// e.getSource().toString());
|
1071 |
} |
1072 |
} |
1073 |
|
1074 |
/*
|
1075 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Class,
|
1076 |
* java.lang.Object)
|
1077 |
*/
|
1078 |
public boolean closeSingletonWindow(Class viewClass, Object model) { |
1079 |
JInternalFrame frame = (JInternalFrame) sws.getFrame(viewClass, model); |
1080 |
if (frame == null) |
1081 |
return false; |
1082 |
closeJInternalFrame(frame); |
1083 |
return true; |
1084 |
} |
1085 |
|
1086 |
/*
|
1087 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Object)
|
1088 |
*/
|
1089 |
public boolean closeSingletonWindow(Object model) { |
1090 |
JInternalFrame[] frames = (JInternalFrame[]) sws.getFrames(model); |
1091 |
if (frames.length == 0) |
1092 |
return false; |
1093 |
for (int i = 0; i < frames.length; i++) { |
1094 |
closeJInternalFrame(frames[i]); |
1095 |
} |
1096 |
return true; |
1097 |
} |
1098 |
|
1099 |
/*
|
1100 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getAllWindows()
|
1101 |
*/
|
1102 |
public IWindow[] getAllWindows() { |
1103 |
ArrayList windows = new ArrayList(); |
1104 |
Iterator i = fws.getWindowIterator();
|
1105 |
|
1106 |
while (i.hasNext()) {
|
1107 |
windows.add((IWindow) i.next()); |
1108 |
} |
1109 |
return (IWindow[]) windows.toArray(new IWindow[0]); |
1110 |
} |
1111 |
|
1112 |
/*
|
1113 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getOrderedWindows()
|
1114 |
*/
|
1115 |
public IWindow[] getOrderedWindows() { |
1116 |
TreeMap windows = new TreeMap(); |
1117 |
Iterator winIterator = fws.getWindowIterator();
|
1118 |
|
1119 |
Component frame;
|
1120 |
IWindow win; |
1121 |
/**
|
1122 |
* The order of the window in the JDesktopPane. Smaller numbers
|
1123 |
* are closer to the foreground.
|
1124 |
*/
|
1125 |
int zPosition;
|
1126 |
while (winIterator.hasNext()) {
|
1127 |
win = (IWindow) winIterator.next(); |
1128 |
frame = fws.getFrame(win); |
1129 |
zPosition = panel.getPosition(frame); |
1130 |
|
1131 |
if (zPosition == -1) { |
1132 |
/*
|
1133 |
* This is a minimized window.
|
1134 |
* It will keep the -1 (first position) if it does not have the focus.
|
1135 |
* (I think this never happens. Even if visually the minimized window
|
1136 |
* appears selected, it does not have the focus), so minimized
|
1137 |
* windows will lose the first position.
|
1138 |
*/
|
1139 |
if (!frame.isFocusOwner()) {
|
1140 |
zPosition = 1000;
|
1141 |
} |
1142 |
} |
1143 |
int layer = panel.getLayer(frame);
|
1144 |
|
1145 |
if (! (frame instanceof JDialog)) { //JDialogs are not in inside the LayeredPane |
1146 |
// flatten all the layers
|
1147 |
if (layer == JLayeredPane.DEFAULT_LAYER.intValue()) { |
1148 |
zPosition+=50000;
|
1149 |
} |
1150 |
else if (layer == JLayeredPane.PALETTE_LAYER.intValue()) { |
1151 |
zPosition+=40000;
|
1152 |
} |
1153 |
else if (layer == JLayeredPane.MODAL_LAYER.intValue()) { |
1154 |
zPosition+=30000;
|
1155 |
} |
1156 |
else if (layer == JLayeredPane.POPUP_LAYER.intValue()) { |
1157 |
zPosition+=20000;
|
1158 |
} |
1159 |
else if (layer == JLayeredPane.DRAG_LAYER.intValue()) { |
1160 |
zPosition+=10000;
|
1161 |
} |
1162 |
} |
1163 |
windows.put(new Integer(zPosition), win); |
1164 |
} |
1165 |
winIterator = windows.values().iterator(); |
1166 |
ArrayList winList = new ArrayList(); |
1167 |
while (winIterator.hasNext()) {
|
1168 |
winList.add(winIterator.next()); |
1169 |
} |
1170 |
|
1171 |
return (IWindow[]) winList.toArray(new IWindow[0]); |
1172 |
} |
1173 |
public void setMaximum(final IWindow v, final boolean bMaximum) throws PropertyVetoException |
1174 |
{ |
1175 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1176 |
SwingUtilities.invokeLater( new Runnable() { |
1177 |
public void run() { |
1178 |
try {
|
1179 |
setMaximum(v,bMaximum); |
1180 |
} catch (PropertyVetoException e) { |
1181 |
logger.info("Error not in event dispatch thread",e);
|
1182 |
} |
1183 |
} |
1184 |
}); |
1185 |
return;
|
1186 |
} |
1187 |
JInternalFrame f = fws.getJInternalFrame(v);
|
1188 |
f.setMaximum(bMaximum); |
1189 |
} |
1190 |
|
1191 |
public void changeWindowInfo(IWindow w, WindowInfo wi){ |
1192 |
JInternalFrame f = fws.getJInternalFrame(w);
|
1193 |
f.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
1194 |
JDesktopPane pnl = f.getDesktopPane();
|
1195 |
pnl.remove(f); |
1196 |
int width;
|
1197 |
int height;
|
1198 |
if (wi.getWidth()!=-1) |
1199 |
width = wi.getWidth(); |
1200 |
else
|
1201 |
width = f.getWidth(); |
1202 |
if (wi.getHeight()!=-1) |
1203 |
height = wi.getHeight(); |
1204 |
else
|
1205 |
height = f.getHeight(); |
1206 |
f.setSize(new Dimension(width, height)); |
1207 |
f.setLocation(wi.getX(), wi.getY()); |
1208 |
if (wi.isPalette()) {
|
1209 |
pnl.add(f, JDesktopPane.PALETTE_LAYER);
|
1210 |
f.setFocusable(false);
|
1211 |
} else {
|
1212 |
pnl.add(f, JDesktopPane.DEFAULT_LAYER);
|
1213 |
f.setFocusable(true);
|
1214 |
if (wi.isClosed()) {
|
1215 |
closeWindow(w); |
1216 |
} |
1217 |
} |
1218 |
|
1219 |
if (wi.isMaximized()) {
|
1220 |
try {
|
1221 |
f.setMaximum(true);
|
1222 |
} catch (PropertyVetoException e) { |
1223 |
// TODO Auto-generated catch block
|
1224 |
//e.printStackTrace();
|
1225 |
} |
1226 |
f.setNormalBounds(wi.getNormalBounds()); |
1227 |
} |
1228 |
activateJInternalFrame(f); |
1229 |
} |
1230 |
|
1231 |
public void refresh(final IWindow win) { |
1232 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1233 |
SwingUtilities.invokeLater( new Runnable() { |
1234 |
public void run() { |
1235 |
refresh(win); |
1236 |
} |
1237 |
}); |
1238 |
return;
|
1239 |
} |
1240 |
Component frame = fws.getFrame(win);
|
1241 |
if (frame!=null) |
1242 |
frame.setVisible(true);
|
1243 |
} |
1244 |
|
1245 |
public void setBackgroundImage(ImageIcon image, String typeDesktop) { |
1246 |
this.image=image;
|
1247 |
this.typeDesktop=typeDesktop;
|
1248 |
|
1249 |
} |
1250 |
class MyDesktopPane extends JDesktopPane |
1251 |
{ |
1252 |
protected Map listeners = new Hashtable(); |
1253 |
|
1254 |
|
1255 |
public MyDesktopPane(){
|
1256 |
} |
1257 |
|
1258 |
public Dimension getPreferredSize() { |
1259 |
JInternalFrame[] array = this.getAllFrames(); |
1260 |
int maxX = 0; |
1261 |
int maxY = 0; |
1262 |
for (int i = 0; i < array.length; i++) { |
1263 |
int x = array[i].getX() + array[i].getWidth();
|
1264 |
if (x > maxX)
|
1265 |
maxX = x; |
1266 |
int y = array[i].getY() + array[i].getHeight();
|
1267 |
if (y > maxY)
|
1268 |
maxY = y; |
1269 |
} |
1270 |
return new Dimension(maxX, maxY); |
1271 |
} |
1272 |
|
1273 |
/**
|
1274 |
* Add an internal-frame to the desktop. Sets a component-listener on
|
1275 |
* it, which resizes the desktop if a frame is resized.
|
1276 |
*/
|
1277 |
public Component add(Component comp) { |
1278 |
super.add(comp);
|
1279 |
ComponentListener listener = new ComponentListener() { |
1280 |
public void componentResized(ComponentEvent e) { // Layout the |
1281 |
// JScrollPane
|
1282 |
getParent().getParent().validate(); |
1283 |
} |
1284 |
|
1285 |
public void componentMoved(ComponentEvent e) { |
1286 |
JInternalFrame comp = (JInternalFrame) e.getSource(); |
1287 |
|
1288 |
//no deja que la ventana se vaya hacia la izquierda o arriba
|
1289 |
if( comp.getX()<0 ) { |
1290 |
comp.setLocation(0, comp.getY());
|
1291 |
} |
1292 |
if (comp.getY()<0){ |
1293 |
comp.setLocation(comp.getX(), 0);
|
1294 |
} |
1295 |
componentResized(e); |
1296 |
} |
1297 |
public void componentShown(ComponentEvent e) { |
1298 |
} |
1299 |
|
1300 |
public void componentHidden(ComponentEvent e) { |
1301 |
} |
1302 |
|
1303 |
}; |
1304 |
comp.addComponentListener(listener); |
1305 |
listeners.put(comp, listener); |
1306 |
return comp;
|
1307 |
} |
1308 |
|
1309 |
/**
|
1310 |
* Remove an internal-frame from the desktop. Removes the
|
1311 |
* component-listener and resizes the desktop.
|
1312 |
*/
|
1313 |
public void remove(Component comp) { |
1314 |
comp.removeComponentListener((ComponentListener) listeners
|
1315 |
.get(comp)); |
1316 |
super.remove(comp);
|
1317 |
getParent().getParent().validate(); // Layout the JScrollPane
|
1318 |
} |
1319 |
|
1320 |
public void paintComponent(Graphics g){ |
1321 |
super.paintComponent(g);
|
1322 |
int x=0; |
1323 |
int y=0; |
1324 |
int w=0; |
1325 |
int h=0; |
1326 |
if (image != null) { |
1327 |
if (typeDesktop.equals(Theme.CENTERED)) {
|
1328 |
w = image.getIconWidth(); |
1329 |
h = image.getIconHeight(); |
1330 |
x = (getWidth() - w) / 2;
|
1331 |
y = (getHeight() - h) / 2;
|
1332 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
1333 |
} else if (typeDesktop.equals(Theme.EXPAND)) { |
1334 |
w = getWidth(); |
1335 |
h = getHeight(); |
1336 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
1337 |
} else if (typeDesktop.equals(Theme.MOSAIC)) { |
1338 |
int wAux = image.getIconWidth();
|
1339 |
int hAux = image.getIconHeight();
|
1340 |
int i = 0; |
1341 |
int j = 0; |
1342 |
w = wAux; |
1343 |
h = hAux; |
1344 |
while (x < getWidth()) {
|
1345 |
x = wAux * i; |
1346 |
while (y < getHeight()) {
|
1347 |
y = hAux * j; |
1348 |
j++; |
1349 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
1350 |
} |
1351 |
y = 0;
|
1352 |
j = 0;
|
1353 |
i++; |
1354 |
} |
1355 |
} |
1356 |
} |
1357 |
} |
1358 |
} |
1359 |
|
1360 |
public void showWindow(final JPanel panel, final String title, final MODE mode) { |
1361 |
// This prepare a default JPanel that implements IWindow
|
1362 |
// for the passed panel and call to the addWindow
|
1363 |
// to show it.
|
1364 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1365 |
SwingUtilities.invokeLater( new Runnable() { |
1366 |
public void run() { |
1367 |
showWindow(panel,title,mode); |
1368 |
} |
1369 |
}); |
1370 |
return;
|
1371 |
} |
1372 |
ToolsSwingLocator.getWindowManager().showWindow(panel, title, mode); |
1373 |
} |
1374 |
|
1375 |
} |