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