svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / mdiManager / NewSkin.java @ 39415
History | View | Annotate | Download (45.9 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 |
|
351 |
if( !singletonPreviouslyAdded ) {
|
352 |
Point new_loc = this.getLocationForAlignment(p, align); |
353 |
p.getWindowInfo().setX(new_loc.x); |
354 |
p.getWindowInfo().setY(new_loc.y); |
355 |
} |
356 |
|
357 |
IWindow window = addWindow(p); |
358 |
return window;
|
359 |
} |
360 |
|
361 |
|
362 |
/**
|
363 |
* Centres the Frame in the contentPane of the MainFrame.
|
364 |
* If the frame can't be showed completely, it tries to show its top-left
|
365 |
* corner.
|
366 |
*
|
367 |
* @author Pablo Piqueras Bartolom�
|
368 |
*
|
369 |
* @param panel The IWindow to centre
|
370 |
*/
|
371 |
public synchronized void centreFrame(final IWindow panel) { |
372 |
if( !SwingUtilities.isEventDispatchThread() ) { |
373 |
SwingUtilities.invokeLater( new Runnable() { |
374 |
public void run() { |
375 |
centreFrame(panel); |
376 |
} |
377 |
}); |
378 |
return;
|
379 |
} |
380 |
Component window = fws.getFrame(panel);
|
381 |
if (window==null) return; |
382 |
|
383 |
// The top-left square of frame reference
|
384 |
Point newReferencePoint = new Point(); |
385 |
|
386 |
// A reference to the panel where the JInternalFrame will be displayed
|
387 |
Container contentPane = ((JFrame)PluginServices.getMainFrame()).getContentPane(); |
388 |
|
389 |
// Get the NewStatusBar component
|
390 |
NewStatusBar newStatusBar = ((NewStatusBar)contentPane.getComponent(1));
|
391 |
JDesktopPane jDesktopPane = this.getDesktopPane(); |
392 |
|
393 |
int visibleWidth = contentPane.getWidth() - contentPane.getX(); // The last substraction is for if there is any menu,... at left |
394 |
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 |
395 |
int freeWidth = visibleWidth - window.getWidth();
|
396 |
int freeHeight = visibleHeight - window.getHeight();
|
397 |
|
398 |
// Calculate the new point reference (Assure that the top-left corner is showed)
|
399 |
if (freeWidth < 0) |
400 |
{ |
401 |
if (visibleWidth > MinimumXMargin)
|
402 |
newReferencePoint.x = DefaultXMargin; |
403 |
else
|
404 |
newReferencePoint.x = 0;
|
405 |
} |
406 |
else
|
407 |
newReferencePoint.x = freeWidth / 2;
|
408 |
|
409 |
if (freeHeight < 0) |
410 |
{ |
411 |
if (visibleHeight > MinimumYMargin)
|
412 |
newReferencePoint.y = DefaultYMargin; |
413 |
else
|
414 |
newReferencePoint.y = 0;
|
415 |
} |
416 |
else
|
417 |
newReferencePoint.y = freeHeight / 2;
|
418 |
|
419 |
// Set the new location for this JInternalFrame
|
420 |
window.setLocation(newReferencePoint); |
421 |
} |
422 |
|
423 |
public synchronized void alignFrame(final IWindow panel, final int mode) { |
424 |
if( !SwingUtilities.isEventDispatchThread() ) { |
425 |
SwingUtilities.invokeLater( new Runnable() { |
426 |
public void run() { |
427 |
alignFrame(panel,mode); |
428 |
} |
429 |
}); |
430 |
return;
|
431 |
} |
432 |
Component window = fws.getFrame(panel);
|
433 |
if (window==null) { |
434 |
return;
|
435 |
} |
436 |
|
437 |
// The top-left square of frame reference
|
438 |
Point newReferencePoint = new Point(); |
439 |
|
440 |
// A reference to the panel where the JInternalFrame will be displayed
|
441 |
Container contentPane = ((JFrame)PluginServices.getMainFrame()).getContentPane(); |
442 |
|
443 |
// Get the NewStatusBar component
|
444 |
NewStatusBar newStatusBar = ((NewStatusBar)contentPane.getComponent(1));
|
445 |
JDesktopPane jDesktopPane = this.getDesktopPane(); |
446 |
|
447 |
int visibleWidth = contentPane.getWidth() - contentPane.getX(); // The last substraction is for if there is any menu,... at left |
448 |
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 |
449 |
|
450 |
// ---------------------------------------------------------------
|
451 |
// |FIRST_LINE_START(23) PAGE_START(19) FIRST_LINE_END(24) |
|
452 |
// | |
|
453 |
// | |
|
454 |
// |LINE_START(21) CENTER(10) LINE_END(22)|
|
455 |
// | |
|
456 |
// | |
|
457 |
// |LAST_LINE_START(25) PAGE_END(20) LAST_LINE_END(26) |
|
458 |
// ---------------------------------------------------------------
|
459 |
|
460 |
switch (mode) {
|
461 |
case ALIGN_FIRST_LINE_START:
|
462 |
newReferencePoint.x = DefaultXMargin; |
463 |
newReferencePoint.y = DefaultYMargin; |
464 |
break;
|
465 |
|
466 |
case ALIGN_PAGE_START:
|
467 |
newReferencePoint.x = visibleWidth / 2;
|
468 |
newReferencePoint.y = DefaultYMargin; |
469 |
break;
|
470 |
|
471 |
case ALIGN_FIRST_LINE_END:
|
472 |
newReferencePoint.x = visibleWidth - window.getWidth() - DefaultXMargin; |
473 |
newReferencePoint.y = DefaultYMargin; |
474 |
break;
|
475 |
|
476 |
case ALIGN_FIRST_LINE_END_CASCADE:
|
477 |
newReferencePoint.x = visibleWidth - window.getWidth() - (int)(DefaultXMargin + (DefaultXMargin*1.5*this.alignCounter)); |
478 |
newReferencePoint.y = DefaultYMargin + (int)(DefaultYMargin*1.5*this.alignCounter); |
479 |
if( ++this.alignCounter >5 ) { |
480 |
this.alignCounter = 0; |
481 |
} |
482 |
break;
|
483 |
|
484 |
case ALIGN_LINE_START:
|
485 |
newReferencePoint.x = DefaultXMargin; |
486 |
newReferencePoint.y = visibleHeight / 2;
|
487 |
break;
|
488 |
|
489 |
case ALIGN_LINE_END:
|
490 |
newReferencePoint.x = visibleWidth - window.getWidth() - DefaultXMargin; |
491 |
newReferencePoint.y = visibleHeight / 2;
|
492 |
break;
|
493 |
|
494 |
case ALIGN_LAST_LINE_START:
|
495 |
newReferencePoint.x = DefaultXMargin; |
496 |
newReferencePoint.y = visibleHeight - window.getHeight() - DefaultYMargin; |
497 |
break;
|
498 |
|
499 |
case ALIGN_PAGE_END:
|
500 |
newReferencePoint.x = visibleWidth / 2;
|
501 |
newReferencePoint.y = visibleHeight - window.getHeight() - DefaultYMargin; |
502 |
break;
|
503 |
|
504 |
case ALIGN_LAST_LINE_END:
|
505 |
newReferencePoint.x = visibleWidth - window.getWidth() - DefaultXMargin; |
506 |
newReferencePoint.y = visibleHeight - window.getHeight() - DefaultYMargin; |
507 |
break;
|
508 |
|
509 |
default:
|
510 |
case ALIGN_CENTER:
|
511 |
newReferencePoint.x = visibleWidth / 2;
|
512 |
newReferencePoint.y = visibleHeight / 2;
|
513 |
break;
|
514 |
} |
515 |
|
516 |
if( newReferencePoint.x < 0 ) { |
517 |
newReferencePoint.x = DefaultXMargin; |
518 |
} |
519 |
if( newReferencePoint.y < 0 ) { |
520 |
newReferencePoint.y = DefaultYMargin; |
521 |
} |
522 |
window.setLocation(newReferencePoint); |
523 |
} |
524 |
|
525 |
/**
|
526 |
* DOCUMENT ME!
|
527 |
*
|
528 |
* @param wnd
|
529 |
* DOCUMENT ME!
|
530 |
* @param wi
|
531 |
* DOCUMENT ME!
|
532 |
*/
|
533 |
private void addJInternalFrame(JInternalFrame wnd, WindowInfo wi) { |
534 |
wnd.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
535 |
wnd.addInternalFrameListener(new FrameListener());
|
536 |
|
537 |
if (wi.isModeless() || wi.isPalette()) {
|
538 |
panel.add(wnd, JDesktopPane.PALETTE_LAYER);
|
539 |
if (wi.isPalette())
|
540 |
wnd.setFocusable(false);
|
541 |
} else {
|
542 |
panel.add(wnd); |
543 |
} |
544 |
updateFrameProperties(wnd, wi); |
545 |
activateJInternalFrame(wnd); |
546 |
try{
|
547 |
wnd.setMaximum(wi.isMaximized()); |
548 |
}catch(Exception ex){ |
549 |
logger.warn("Error: ", ex);
|
550 |
} |
551 |
} |
552 |
|
553 |
private void updateFrameProperties(JInternalFrame frame, WindowInfo wi) { |
554 |
int height, width;
|
555 |
if (wi.isMaximized()) {
|
556 |
if (wi.getNormalWidth()!=-1) |
557 |
width = wi.getNormalWidth(); |
558 |
else
|
559 |
width = frame.getNormalBounds().width; |
560 |
if (wi.getNormalHeight()!=-1) |
561 |
height = wi.getNormalHeight(); |
562 |
else
|
563 |
height = frame.getNormalBounds().height; |
564 |
|
565 |
frame.setSize(width, height); |
566 |
frame.setLocation(wi.getNormalX(), wi.getNormalY()); |
567 |
} |
568 |
else {
|
569 |
if (wi.getWidth()!=-1) |
570 |
width = wi.getWidth(); |
571 |
else
|
572 |
width = frame.getWidth(); |
573 |
if (wi.getHeight()!=-1) |
574 |
height = wi.getHeight(); |
575 |
else
|
576 |
height = frame.getHeight(); |
577 |
frame.setSize(width, height); |
578 |
frame.setLocation(wi.getX(), wi.getY()); |
579 |
} |
580 |
frame.setTitle(wi.getTitle()); |
581 |
frame.setVisible(wi.isVisible()); |
582 |
frame.setResizable(wi.isResizable()); |
583 |
frame.setIconifiable(wi.isIconifiable()); |
584 |
frame.setMaximizable(wi.isMaximizable()); |
585 |
try {
|
586 |
frame.setMaximum(wi.isMaximized()); |
587 |
} catch (PropertyVetoException e) { |
588 |
// TODO Auto-generated catch block
|
589 |
//e.printStackTrace();
|
590 |
} |
591 |
} |
592 |
|
593 |
/**
|
594 |
* DOCUMENT ME!
|
595 |
*
|
596 |
* @param p
|
597 |
*/
|
598 |
private void addJInternalFrame(IWindow p) { |
599 |
WindowInfo wi = wis.getWindowInfo(p); |
600 |
|
601 |
JInternalFrame wnd = fws.getJInternalFrame(p);
|
602 |
|
603 |
if (p instanceof SingletonWindow) { |
604 |
SingletonWindow sv = (SingletonWindow) p; |
605 |
sws.openSingletonWindow(sv, wnd); |
606 |
} |
607 |
|
608 |
addJInternalFrame(wnd, wi); |
609 |
} |
610 |
|
611 |
/**
|
612 |
* DOCUMENT ME!
|
613 |
*
|
614 |
* @param wnd
|
615 |
*/
|
616 |
private void activateJInternalFrame(JInternalFrame wnd) { |
617 |
JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
618 |
try {
|
619 |
wnd.moveToFront(); |
620 |
logger.debug("Activando " + wnd.getTitle());
|
621 |
wnd.setSelected(true);
|
622 |
wnd.setIcon(false);
|
623 |
} catch (PropertyVetoException e) { |
624 |
logger.error(e.toString()); |
625 |
} |
626 |
} |
627 |
|
628 |
/**
|
629 |
* Situa un di�logo modal en el centro de la pantalla
|
630 |
*
|
631 |
* @param d
|
632 |
* Di�logo que se quiere situar
|
633 |
*/
|
634 |
private void centerDialog(JDialog d) { |
635 |
int offSetX = d.getWidth() / 2; |
636 |
int offSetY = d.getHeight() / 2; |
637 |
|
638 |
d.setLocation((mainFrame.getWidth() / 2) - offSetX, (mainFrame
|
639 |
.getHeight() / 2)
|
640 |
- offSetY); |
641 |
} |
642 |
|
643 |
/**
|
644 |
* DOCUMENT ME!
|
645 |
*
|
646 |
* @param p
|
647 |
*/
|
648 |
private void addJDialog(IWindow p) { |
649 |
JDialog dlg = fws.getJDialog(p);
|
650 |
|
651 |
centerDialog(dlg); |
652 |
|
653 |
dlg.addWindowListener(new DialogWindowListener());
|
654 |
dss.pushDialog(dlg); |
655 |
|
656 |
dlg.setVisible(wis.getWindowInfo(p).isVisible()); |
657 |
} |
658 |
|
659 |
/*
|
660 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getActiveWindow()
|
661 |
*/
|
662 |
public IWindow getActiveWindow() {
|
663 |
JInternalFrame jif = panel.getSelectedFrame();
|
664 |
|
665 |
if (jif != null) { |
666 |
IWindow theWindow = fws.getWindow(jif); |
667 |
if (theWindow == null) |
668 |
return null; |
669 |
if (theWindow.getWindowInfo().isPalette())
|
670 |
return wss.getActiveWindow();
|
671 |
else
|
672 |
return fws.getWindow(jif);
|
673 |
} |
674 |
// return vss.getActiveView();
|
675 |
|
676 |
return null; |
677 |
} |
678 |
public IWindow getFocusWindow(){
|
679 |
JInternalFrame jif = panel.getSelectedFrame();
|
680 |
|
681 |
if (jif != null) { |
682 |
IWindow theView = fws.getWindow(jif); |
683 |
if (theView == null) |
684 |
return null; |
685 |
return fws.getWindow(jif);
|
686 |
} |
687 |
return null; |
688 |
} |
689 |
/*
|
690 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeWindow(com.iver.andami.ui.mdiManager.IWindow)
|
691 |
*/
|
692 |
public void closeWindow(final IWindow p) { |
693 |
if( !SwingUtilities.isEventDispatchThread() ) { |
694 |
SwingUtilities.invokeLater( new Runnable() { |
695 |
public void run() { |
696 |
closeWindow(p); |
697 |
} |
698 |
}); |
699 |
return;
|
700 |
} |
701 |
// Si es un di�logo modal
|
702 |
if (p.getWindowInfo().isModal()) {
|
703 |
closeJDialog(); |
704 |
} else { // Si no es modal se cierra el JInternalFrame |
705 |
closeJInternalFrame(fws.getJInternalFrame(p)); |
706 |
} |
707 |
} |
708 |
|
709 |
/*
|
710 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeAllWindows()
|
711 |
*/
|
712 |
public void closeAllWindows() { |
713 |
if( !SwingUtilities.isEventDispatchThread() ) { |
714 |
SwingUtilities.invokeLater( new Runnable() { |
715 |
public void run() { |
716 |
closeAllWindows(); |
717 |
} |
718 |
}); |
719 |
return;
|
720 |
} |
721 |
ArrayList eliminar = new ArrayList(); |
722 |
Iterator i = fws.getWindowIterator();
|
723 |
|
724 |
while (i.hasNext()) {
|
725 |
eliminar.add((IWindow) i.next()); |
726 |
} |
727 |
|
728 |
for (Iterator iter = eliminar.iterator(); iter.hasNext();) { |
729 |
IWindow vista = (IWindow) iter.next(); |
730 |
closeWindow(vista); |
731 |
} |
732 |
} |
733 |
|
734 |
/*
|
735 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getWindowInfo(com.iver.andami.ui.mdiManager.IWindow)
|
736 |
*/
|
737 |
public WindowInfo getWindowInfo(IWindow w) {
|
738 |
WindowInfo wi = wis.getWindowInfo(w); |
739 |
|
740 |
/*
|
741 |
* This is done now in vis.getWindowInfo(w)
|
742 |
*
|
743 |
* JInternalFrame f = fws.getJInternalFrame(w);
|
744 |
wi.setX(f.getX());
|
745 |
wi.setY(f.getY());
|
746 |
wi.setHeight(f.getHeight());
|
747 |
wi.setWidth(f.getWidth());
|
748 |
// isClosed() doesn't work as (I) expected, why? Using isShowing instead
|
749 |
wi.setClosed(!f.isShowing());
|
750 |
wi.setNormalBounds(f.getNormalBounds());
|
751 |
wi.setMaximized(f.isMaximum());*/
|
752 |
return wi;
|
753 |
} |
754 |
|
755 |
/**
|
756 |
* DOCUMENT ME!
|
757 |
*
|
758 |
* @param dialog
|
759 |
* @throws RuntimeException
|
760 |
* DOCUMENT ME!
|
761 |
*/
|
762 |
private void closeJDialog() { |
763 |
JDialog dlg = dss.popDialog();
|
764 |
if (dlg==null) |
765 |
return;
|
766 |
dlg.setVisible(false);
|
767 |
|
768 |
IWindow s = fws.getWindow(dlg); |
769 |
|
770 |
callWindowClosed(s); |
771 |
|
772 |
fws.closeWindow(s); |
773 |
|
774 |
// Si es singleton se desasocia el modelo con la vista
|
775 |
if (s instanceof SingletonWindow) { |
776 |
sws.closeWindow((SingletonWindow) s); |
777 |
} |
778 |
} |
779 |
|
780 |
/**
|
781 |
* If <code>window</code> implements IWindowListener, sent it
|
782 |
* the windowActivated event.
|
783 |
*
|
784 |
* @param window
|
785 |
* The IWindow which has to be notified.
|
786 |
*/
|
787 |
private void callWindowClosed(IWindow window) { |
788 |
if (window instanceof IWindowListener) { |
789 |
((IWindowListener) window).windowClosed(); |
790 |
} |
791 |
} |
792 |
|
793 |
/**
|
794 |
* If <code>window</code> implements IWindowListener, sent it
|
795 |
* the windowActivated event.
|
796 |
*
|
797 |
* @param window
|
798 |
* The IWindow which has to be notified.
|
799 |
*/
|
800 |
private void callWindowActivated(IWindow window) { |
801 |
// logger.debug("View '" + window.getWindowInfo().getTitle()
|
802 |
// + "' activated (callViewActivated)");
|
803 |
if (window instanceof IWindowListener) { |
804 |
((IWindowListener) window).windowActivated(); |
805 |
} |
806 |
} |
807 |
|
808 |
/**
|
809 |
* DOCUMENT ME!
|
810 |
*
|
811 |
* @param frame
|
812 |
*/
|
813 |
private void closeJInternalFrame(final JInternalFrame frame) { |
814 |
if( !SwingUtilities.isEventDispatchThread() ) { |
815 |
SwingUtilities.invokeLater( new Runnable() { |
816 |
public void run() { |
817 |
closeJInternalFrame(frame); |
818 |
} |
819 |
}); |
820 |
return;
|
821 |
} |
822 |
try {
|
823 |
IWindow s = (IWindow) fws.getWindow(frame); |
824 |
|
825 |
frame.setClosed(true);
|
826 |
callWindowClosed(s); |
827 |
} catch (PropertyVetoException e) { |
828 |
logger |
829 |
.error( |
830 |
"Not compatible with property veto's. Use ViewInfo instead.",
|
831 |
e); |
832 |
} |
833 |
} |
834 |
|
835 |
/*
|
836 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
837 |
*/
|
838 |
public void initialize() { |
839 |
} |
840 |
|
841 |
/*
|
842 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
843 |
*/
|
844 |
public void execute(String actionCommand) { |
845 |
if ("window-cascade".equalsIgnoreCase(actionCommand)) { |
846 |
logger.info("action window-cascade not implemented.");
|
847 |
|
848 |
} else if ("window-tile".equalsIgnoreCase(actionCommand)) { |
849 |
logger.info("action window-tile not implemented.");
|
850 |
} |
851 |
} |
852 |
|
853 |
/*
|
854 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
855 |
*/
|
856 |
public boolean isEnabled() { |
857 |
// TODO Auto-generated method stub
|
858 |
return false; |
859 |
} |
860 |
|
861 |
/*
|
862 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
863 |
*/
|
864 |
public boolean isVisible() { |
865 |
// TODO Auto-generated method stub
|
866 |
return true; |
867 |
} |
868 |
|
869 |
/*
|
870 |
* @see com.iver.andami.ui.mdiManager.MDIManager#setWaitCursor()
|
871 |
*/
|
872 |
public void setWaitCursor() { |
873 |
if (mainFrame != null) { |
874 |
if( !SwingUtilities.isEventDispatchThread() ) { |
875 |
SwingUtilities.invokeLater( new Runnable() { |
876 |
public void run() { |
877 |
setWaitCursor(); |
878 |
} |
879 |
}); |
880 |
return;
|
881 |
} |
882 |
glassPane.setVisible(true);
|
883 |
lastCursor = mainFrame.getCursor(); |
884 |
dss.setWaitCursor(); |
885 |
glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
886 |
} |
887 |
} |
888 |
|
889 |
/*
|
890 |
* @see com.iver.andami.ui.mdiManager.MDIManager#restoreCursor()
|
891 |
*/
|
892 |
public void restoreCursor() { |
893 |
if (mainFrame != null) { |
894 |
if( !SwingUtilities.isEventDispatchThread() ) { |
895 |
SwingUtilities.invokeLater( new Runnable() { |
896 |
public void run() { |
897 |
restoreCursor(); |
898 |
} |
899 |
}); |
900 |
return;
|
901 |
} |
902 |
glassPane.setVisible(false);
|
903 |
dss.restoreCursor(); |
904 |
glassPane.setCursor(lastCursor); |
905 |
} |
906 |
} |
907 |
|
908 |
/**
|
909 |
* Listener para los eventos de cerrado de los di�logos. Tiene su raz�n de
|
910 |
* ser en que los di�logos han de devolverse al pool cuando se cierran
|
911 |
*
|
912 |
* @author Fernando Gonz�lez Cort�s
|
913 |
*/
|
914 |
public class DialogWindowListener extends WindowAdapter { |
915 |
/**
|
916 |
* Captura el evento de cerrado de los di�logos con el fin de realizar
|
917 |
* tareas de mantenimiento
|
918 |
*
|
919 |
* @param e
|
920 |
* evento
|
921 |
*/
|
922 |
public void windowActivated(WindowEvent e) { |
923 |
IWindow window = fws.getWindow((Component) e.getSource());
|
924 |
callWindowActivated(window); |
925 |
|
926 |
} |
927 |
|
928 |
|
929 |
/**
|
930 |
* Captura el evento de cerrado de los di�logos con el fin de realizar
|
931 |
* tareas de mantenimiento
|
932 |
*
|
933 |
* @param e
|
934 |
* evento
|
935 |
*/
|
936 |
public void windowClosing(WindowEvent e) { |
937 |
closeJDialog(); |
938 |
} |
939 |
} |
940 |
|
941 |
/**
|
942 |
* DOCUMENT ME!
|
943 |
*/
|
944 |
public class FrameListener implements InternalFrameListener { |
945 |
/*
|
946 |
* @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent)
|
947 |
*/
|
948 |
public void internalFrameActivated(InternalFrameEvent e) { |
949 |
// logger.debug("internalFrameActivated " +
|
950 |
// e.getInternalFrame().getTitle());
|
951 |
|
952 |
// activatedInternalFramesStack.push(e.getInternalFrame());
|
953 |
|
954 |
IWindow panel = fws.getWindow((JInternalFrame) e.getSource());
|
955 |
|
956 |
WindowInfo wi = wis.getWindowInfo(panel); |
957 |
if (wi.isPalette())
|
958 |
return;
|
959 |
|
960 |
wss.setActive(panel); |
961 |
|
962 |
JInternalFrame frame = fws.getJInternalFrame(panel);
|
963 |
|
964 |
if (wi.isMaximizable()){
|
965 |
frame.setMaximizable(true);
|
966 |
} |
967 |
if (!frame.isMaximizable() && frame.isMaximum()) {
|
968 |
try {
|
969 |
frame.setMaximum(false);
|
970 |
} catch (PropertyVetoException e1) { |
971 |
} |
972 |
} |
973 |
mainFrame.enableControls(); |
974 |
if (wi.getSelectedTools()==null) { |
975 |
// this is the first time this window is activated
|
976 |
wi.setSelectedTools(new HashMap(mainFrame.getInitialSelectedTools())); |
977 |
} |
978 |
mainFrame.setSelectedTools(wi.getSelectedTools()); |
979 |
callWindowActivated(panel); |
980 |
|
981 |
} |
982 |
|
983 |
/*
|
984 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
|
985 |
*/
|
986 |
public void internalFrameClosed(InternalFrameEvent e) { |
987 |
} |
988 |
|
989 |
/*
|
990 |
* @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent)
|
991 |
*/
|
992 |
public void internalFrameClosing(InternalFrameEvent e) { |
993 |
// Se elimina la memoria del JInternalFrame si no es ALWAYS_LIVE
|
994 |
// logger.debug("internalFrameClosing " +
|
995 |
// e.getInternalFrame().getTitle());
|
996 |
|
997 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
998 |
WindowInfo wi = wis.getWindowInfo((IWindow) fws.getWindow(c)); |
999 |
|
1000 |
IWindow win = fws.getWindow(c); |
1001 |
callWindowClosed(win); |
1002 |
boolean alwaysLive;
|
1003 |
if (win instanceof SingletonWindow) { |
1004 |
sws.closeWindow((SingletonWindow) win); |
1005 |
} |
1006 |
|
1007 |
fws.closeWindow(win); |
1008 |
|
1009 |
panel.remove(c); |
1010 |
|
1011 |
wss.remove(win); |
1012 |
|
1013 |
if (!wi.isPalette())
|
1014 |
mainFrame.enableControls(); |
1015 |
panel.repaint(); |
1016 |
|
1017 |
// Para activar el JInternalFrame desde la que hemos
|
1018 |
// abierto la ventana que estamos cerrando
|
1019 |
IWindow lastWindow = wss.getActiveWindow(); |
1020 |
// La activamos
|
1021 |
if (lastWindow != null) { |
1022 |
logger.debug(PluginServices.getText(this, "Devuelvo_el_foco_a_")+lastWindow.getWindowInfo().getTitle()); |
1023 |
JInternalFrame frame = fws.getJInternalFrame(lastWindow);
|
1024 |
try {
|
1025 |
frame.setSelected(true);
|
1026 |
} catch (PropertyVetoException e1) { |
1027 |
// TODO Auto-generated catch block
|
1028 |
// e1.printStackTrace();
|
1029 |
} |
1030 |
// addView(lastView);
|
1031 |
} |
1032 |
|
1033 |
} |
1034 |
|
1035 |
/*
|
1036 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent)
|
1037 |
*/
|
1038 |
public void internalFrameDeactivated(InternalFrameEvent e) { |
1039 |
// logger.debug("internalDeActivated " +
|
1040 |
// e.getInternalFrame().getTitle());
|
1041 |
JInternalFrame c = (JInternalFrame) e.getSource(); |
1042 |
IWindow win = fws.getWindow(c); |
1043 |
if (win != null) { |
1044 |
WindowInfo wi = wis.getWindowInfo(win); |
1045 |
if (wi.isPalette())
|
1046 |
return;
|
1047 |
|
1048 |
} |
1049 |
|
1050 |
} |
1051 |
|
1052 |
/*
|
1053 |
* @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
|
1054 |
*/
|
1055 |
public void internalFrameDeiconified(InternalFrameEvent e) { |
1056 |
mainFrame.enableControls(); |
1057 |
} |
1058 |
|
1059 |
/*
|
1060 |
* @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
|
1061 |
*/
|
1062 |
public void internalFrameIconified(InternalFrameEvent e) { |
1063 |
mainFrame.enableControls(); |
1064 |
} |
1065 |
|
1066 |
/*
|
1067 |
* @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent)
|
1068 |
*/
|
1069 |
public void internalFrameOpened(InternalFrameEvent e) { |
1070 |
// logger.debug("internalFrameOpened. Source= " +
|
1071 |
// e.getSource().toString());
|
1072 |
} |
1073 |
} |
1074 |
|
1075 |
/*
|
1076 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Class,
|
1077 |
* java.lang.Object)
|
1078 |
*/
|
1079 |
public boolean closeSingletonWindow(Class viewClass, Object model) { |
1080 |
JInternalFrame frame = (JInternalFrame) sws.getFrame(viewClass, model); |
1081 |
if (frame == null) |
1082 |
return false; |
1083 |
closeJInternalFrame(frame); |
1084 |
return true; |
1085 |
} |
1086 |
|
1087 |
/*
|
1088 |
* @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Object)
|
1089 |
*/
|
1090 |
public boolean closeSingletonWindow(Object model) { |
1091 |
JInternalFrame[] frames = (JInternalFrame[]) sws.getFrames(model); |
1092 |
if (frames.length == 0) |
1093 |
return false; |
1094 |
for (int i = 0; i < frames.length; i++) { |
1095 |
closeJInternalFrame(frames[i]); |
1096 |
} |
1097 |
return true; |
1098 |
} |
1099 |
|
1100 |
/*
|
1101 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getAllWindows()
|
1102 |
*/
|
1103 |
public IWindow[] getAllWindows() { |
1104 |
ArrayList windows = new ArrayList(); |
1105 |
Iterator i = fws.getWindowIterator();
|
1106 |
|
1107 |
while (i.hasNext()) {
|
1108 |
windows.add((IWindow) i.next()); |
1109 |
} |
1110 |
return (IWindow[]) windows.toArray(new IWindow[0]); |
1111 |
} |
1112 |
|
1113 |
/*
|
1114 |
* @see com.iver.andami.ui.mdiManager.MDIManager#getOrderedWindows()
|
1115 |
*/
|
1116 |
public IWindow[] getOrderedWindows() { |
1117 |
TreeMap windows = new TreeMap(); |
1118 |
Iterator winIterator = fws.getWindowIterator();
|
1119 |
|
1120 |
Component frame;
|
1121 |
IWindow win; |
1122 |
/**
|
1123 |
* The order of the window in the JDesktopPane. Smaller numbers
|
1124 |
* are closer to the foreground.
|
1125 |
*/
|
1126 |
int zPosition;
|
1127 |
while (winIterator.hasNext()) {
|
1128 |
win = (IWindow) winIterator.next(); |
1129 |
frame = fws.getFrame(win); |
1130 |
zPosition = panel.getPosition(frame); |
1131 |
|
1132 |
if (zPosition == -1) { |
1133 |
/*
|
1134 |
* This is a minimized window.
|
1135 |
* It will keep the -1 (first position) if it does not have the focus.
|
1136 |
* (I think this never happens. Even if visually the minimized window
|
1137 |
* appears selected, it does not have the focus), so minimized
|
1138 |
* windows will lose the first position.
|
1139 |
*/
|
1140 |
if (!frame.isFocusOwner()) {
|
1141 |
zPosition = 1000;
|
1142 |
} |
1143 |
} |
1144 |
int layer = panel.getLayer(frame);
|
1145 |
|
1146 |
if (! (frame instanceof JDialog)) { //JDialogs are not in inside the LayeredPane |
1147 |
// flatten all the layers
|
1148 |
if (layer == JLayeredPane.DEFAULT_LAYER.intValue()) { |
1149 |
zPosition+=50000;
|
1150 |
} |
1151 |
else if (layer == JLayeredPane.PALETTE_LAYER.intValue()) { |
1152 |
zPosition+=40000;
|
1153 |
} |
1154 |
else if (layer == JLayeredPane.MODAL_LAYER.intValue()) { |
1155 |
zPosition+=30000;
|
1156 |
} |
1157 |
else if (layer == JLayeredPane.POPUP_LAYER.intValue()) { |
1158 |
zPosition+=20000;
|
1159 |
} |
1160 |
else if (layer == JLayeredPane.DRAG_LAYER.intValue()) { |
1161 |
zPosition+=10000;
|
1162 |
} |
1163 |
} |
1164 |
windows.put(new Integer(zPosition), win); |
1165 |
} |
1166 |
winIterator = windows.values().iterator(); |
1167 |
ArrayList winList = new ArrayList(); |
1168 |
while (winIterator.hasNext()) {
|
1169 |
winList.add(winIterator.next()); |
1170 |
} |
1171 |
|
1172 |
return (IWindow[]) winList.toArray(new IWindow[0]); |
1173 |
} |
1174 |
public void setMaximum(final IWindow v, final boolean bMaximum) throws PropertyVetoException |
1175 |
{ |
1176 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1177 |
SwingUtilities.invokeLater( new Runnable() { |
1178 |
public void run() { |
1179 |
try {
|
1180 |
setMaximum(v,bMaximum); |
1181 |
} catch (PropertyVetoException e) { |
1182 |
logger.info("Error not in event dispatch thread",e);
|
1183 |
} |
1184 |
} |
1185 |
}); |
1186 |
return;
|
1187 |
} |
1188 |
JInternalFrame f = fws.getJInternalFrame(v);
|
1189 |
f.setMaximum(bMaximum); |
1190 |
} |
1191 |
|
1192 |
public void changeWindowInfo(IWindow w, WindowInfo wi){ |
1193 |
JInternalFrame f = fws.getJInternalFrame(w);
|
1194 |
f.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
|
1195 |
JDesktopPane pnl = f.getDesktopPane();
|
1196 |
pnl.remove(f); |
1197 |
int width;
|
1198 |
int height;
|
1199 |
if (wi.getWidth()!=-1) |
1200 |
width = wi.getWidth(); |
1201 |
else
|
1202 |
width = f.getWidth(); |
1203 |
if (wi.getHeight()!=-1) |
1204 |
height = wi.getHeight(); |
1205 |
else
|
1206 |
height = f.getHeight(); |
1207 |
f.setSize(new Dimension(width, height)); |
1208 |
f.setLocation(wi.getX(), wi.getY()); |
1209 |
if (wi.isPalette()) {
|
1210 |
pnl.add(f, JDesktopPane.PALETTE_LAYER);
|
1211 |
f.setFocusable(false);
|
1212 |
} else {
|
1213 |
pnl.add(f, JDesktopPane.DEFAULT_LAYER);
|
1214 |
f.setFocusable(true);
|
1215 |
if (wi.isClosed()) {
|
1216 |
closeWindow(w); |
1217 |
} |
1218 |
} |
1219 |
|
1220 |
if (wi.isMaximized()) {
|
1221 |
try {
|
1222 |
f.setMaximum(true);
|
1223 |
} catch (PropertyVetoException e) { |
1224 |
// TODO Auto-generated catch block
|
1225 |
//e.printStackTrace();
|
1226 |
} |
1227 |
f.setNormalBounds(wi.getNormalBounds()); |
1228 |
} |
1229 |
activateJInternalFrame(f); |
1230 |
} |
1231 |
|
1232 |
public void refresh(final IWindow win) { |
1233 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1234 |
SwingUtilities.invokeLater( new Runnable() { |
1235 |
public void run() { |
1236 |
refresh(win); |
1237 |
} |
1238 |
}); |
1239 |
return;
|
1240 |
} |
1241 |
Component frame = fws.getFrame(win);
|
1242 |
if (frame!=null) |
1243 |
frame.setVisible(true);
|
1244 |
} |
1245 |
|
1246 |
public void setBackgroundImage(ImageIcon image, String typeDesktop) { |
1247 |
this.image=image;
|
1248 |
this.typeDesktop=typeDesktop;
|
1249 |
|
1250 |
} |
1251 |
class MyDesktopPane extends JDesktopPane |
1252 |
{ |
1253 |
protected Map listeners = new Hashtable(); |
1254 |
|
1255 |
|
1256 |
public MyDesktopPane(){
|
1257 |
} |
1258 |
|
1259 |
public Dimension getPreferredSize() { |
1260 |
JInternalFrame[] array = this.getAllFrames(); |
1261 |
int maxX = 0; |
1262 |
int maxY = 0; |
1263 |
for (int i = 0; i < array.length; i++) { |
1264 |
int x = array[i].getX() + array[i].getWidth();
|
1265 |
if (x > maxX)
|
1266 |
maxX = x; |
1267 |
int y = array[i].getY() + array[i].getHeight();
|
1268 |
if (y > maxY)
|
1269 |
maxY = y; |
1270 |
} |
1271 |
return new Dimension(maxX, maxY); |
1272 |
} |
1273 |
|
1274 |
/**
|
1275 |
* Add an internal-frame to the desktop. Sets a component-listener on
|
1276 |
* it, which resizes the desktop if a frame is resized.
|
1277 |
*/
|
1278 |
public Component add(Component comp) { |
1279 |
super.add(comp);
|
1280 |
ComponentListener listener = new ComponentListener() { |
1281 |
public void componentResized(ComponentEvent e) { // Layout the |
1282 |
// JScrollPane
|
1283 |
getParent().getParent().validate(); |
1284 |
} |
1285 |
|
1286 |
public void componentMoved(ComponentEvent e) { |
1287 |
JInternalFrame comp = (JInternalFrame) e.getSource(); |
1288 |
|
1289 |
//no deja que la ventana se vaya hacia la izquierda o arriba
|
1290 |
if( comp.getX()<0 ) { |
1291 |
comp.setLocation(0, comp.getY());
|
1292 |
} |
1293 |
if (comp.getY()<0){ |
1294 |
comp.setLocation(comp.getX(), 0);
|
1295 |
} |
1296 |
componentResized(e); |
1297 |
} |
1298 |
public void componentShown(ComponentEvent e) { |
1299 |
} |
1300 |
|
1301 |
public void componentHidden(ComponentEvent e) { |
1302 |
} |
1303 |
|
1304 |
}; |
1305 |
comp.addComponentListener(listener); |
1306 |
listeners.put(comp, listener); |
1307 |
return comp;
|
1308 |
} |
1309 |
|
1310 |
/**
|
1311 |
* Remove an internal-frame from the desktop. Removes the
|
1312 |
* component-listener and resizes the desktop.
|
1313 |
*/
|
1314 |
public void remove(Component comp) { |
1315 |
comp.removeComponentListener((ComponentListener) listeners
|
1316 |
.get(comp)); |
1317 |
super.remove(comp);
|
1318 |
getParent().getParent().validate(); // Layout the JScrollPane
|
1319 |
} |
1320 |
|
1321 |
public void paintComponent(Graphics g){ |
1322 |
super.paintComponent(g);
|
1323 |
int x=0; |
1324 |
int y=0; |
1325 |
int w=0; |
1326 |
int h=0; |
1327 |
if (image != null) { |
1328 |
if (typeDesktop.equals(Theme.CENTERED)) {
|
1329 |
w = image.getIconWidth(); |
1330 |
h = image.getIconHeight(); |
1331 |
x = (getWidth() - w) / 2;
|
1332 |
y = (getHeight() - h) / 2;
|
1333 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
1334 |
} else if (typeDesktop.equals(Theme.EXPAND)) { |
1335 |
w = getWidth(); |
1336 |
h = getHeight(); |
1337 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
1338 |
} else if (typeDesktop.equals(Theme.MOSAIC)) { |
1339 |
int wAux = image.getIconWidth();
|
1340 |
int hAux = image.getIconHeight();
|
1341 |
int i = 0; |
1342 |
int j = 0; |
1343 |
w = wAux; |
1344 |
h = hAux; |
1345 |
while (x < getWidth()) {
|
1346 |
x = wAux * i; |
1347 |
while (y < getHeight()) {
|
1348 |
y = hAux * j; |
1349 |
j++; |
1350 |
g.drawImage(image.getImage(), x, y, w, h, this);
|
1351 |
} |
1352 |
y = 0;
|
1353 |
j = 0;
|
1354 |
i++; |
1355 |
} |
1356 |
} |
1357 |
} |
1358 |
} |
1359 |
} |
1360 |
|
1361 |
public void showWindow(final JPanel panel, final String title, final MODE mode) { |
1362 |
// This prepare a default JPanel that implements IWindow
|
1363 |
// for the passed panel and call to the addWindow
|
1364 |
// to show it.
|
1365 |
if( !SwingUtilities.isEventDispatchThread() ) { |
1366 |
SwingUtilities.invokeLater( new Runnable() { |
1367 |
public void run() { |
1368 |
showWindow(panel,title,mode); |
1369 |
} |
1370 |
}); |
1371 |
return;
|
1372 |
} |
1373 |
ToolsSwingLocator.getWindowManager().showWindow(panel, title, mode); |
1374 |
} |
1375 |
|
1376 |
|
1377 |
private Point getLocationForAlignment(IWindow panel, int mode) { |
1378 |
|
1379 |
// The top-left square of frame reference
|
1380 |
Point newReferencePoint = new Point(); |
1381 |
|
1382 |
// A reference to the panel where the JInternalFrame will be displayed
|
1383 |
Container contentPane = ((JFrame)PluginServices.getMainFrame()).getContentPane(); |
1384 |
|
1385 |
// Get the NewStatusBar component
|
1386 |
NewStatusBar newStatusBar = ((NewStatusBar)contentPane.getComponent(1));
|
1387 |
|
1388 |
JDesktopPane dpane = this.getDesktopPane(); |
1389 |
// The last substraction is for case when there is any menu,... at left
|
1390 |
int visibleWidth = contentPane.getWidth() - contentPane.getX();
|
1391 |
// The last substraction is for case when there is any menu,... at top
|
1392 |
int visibleHeight = contentPane.getHeight() - newStatusBar.getHeight() - contentPane.getY() - Math.abs(dpane.getY() - contentPane.getY()); |
1393 |
|
1394 |
// ---------------------------------------------------------------
|
1395 |
// |FIRST_LINE_START(23) PAGE_START(19) FIRST_LINE_END(24) |
|
1396 |
// | |
|
1397 |
// | |
|
1398 |
// |LINE_START(21) CENTER(10) LINE_END(22)|
|
1399 |
// | |
|
1400 |
// | |
|
1401 |
// |LAST_LINE_START(25) PAGE_END(20) LAST_LINE_END(26) |
|
1402 |
// ---------------------------------------------------------------
|
1403 |
|
1404 |
int win_h = panel.getWindowInfo().getHeight();
|
1405 |
int win_w = panel.getWindowInfo().getWidth();
|
1406 |
|
1407 |
switch (mode) {
|
1408 |
case ALIGN_FIRST_LINE_START:
|
1409 |
newReferencePoint.x = DefaultXMargin; |
1410 |
newReferencePoint.y = DefaultYMargin; |
1411 |
break;
|
1412 |
|
1413 |
case ALIGN_PAGE_START:
|
1414 |
newReferencePoint.x = visibleWidth / 2;
|
1415 |
newReferencePoint.y = DefaultYMargin; |
1416 |
break;
|
1417 |
|
1418 |
case ALIGN_FIRST_LINE_END:
|
1419 |
newReferencePoint.x = visibleWidth - win_w - DefaultXMargin; |
1420 |
newReferencePoint.y = DefaultYMargin; |
1421 |
break;
|
1422 |
|
1423 |
case ALIGN_FIRST_LINE_END_CASCADE:
|
1424 |
newReferencePoint.x = visibleWidth - win_w - (int)(DefaultXMargin + (DefaultXMargin*1.5*this.alignCounter)); |
1425 |
newReferencePoint.y = DefaultYMargin + (int)(DefaultYMargin*1.5*this.alignCounter); |
1426 |
if( ++this.alignCounter >5 ) { |
1427 |
this.alignCounter = 0; |
1428 |
} |
1429 |
break;
|
1430 |
|
1431 |
case ALIGN_LINE_START:
|
1432 |
newReferencePoint.x = DefaultXMargin; |
1433 |
newReferencePoint.y = visibleHeight / 2;
|
1434 |
break;
|
1435 |
|
1436 |
case ALIGN_LINE_END:
|
1437 |
newReferencePoint.x = visibleWidth - win_w - DefaultXMargin; |
1438 |
newReferencePoint.y = visibleHeight / 2;
|
1439 |
break;
|
1440 |
|
1441 |
case ALIGN_LAST_LINE_START:
|
1442 |
newReferencePoint.x = DefaultXMargin; |
1443 |
newReferencePoint.y = visibleHeight - win_h - DefaultYMargin; |
1444 |
break;
|
1445 |
|
1446 |
case ALIGN_PAGE_END:
|
1447 |
newReferencePoint.x = visibleWidth / 2;
|
1448 |
newReferencePoint.y = visibleHeight - win_h - DefaultYMargin; |
1449 |
break;
|
1450 |
|
1451 |
case ALIGN_LAST_LINE_END:
|
1452 |
newReferencePoint.x = visibleWidth - win_w - DefaultXMargin; |
1453 |
newReferencePoint.y = visibleHeight - win_h - DefaultYMargin; |
1454 |
break;
|
1455 |
|
1456 |
default:
|
1457 |
case ALIGN_CENTER:
|
1458 |
newReferencePoint.x = visibleWidth / 2;
|
1459 |
newReferencePoint.y = visibleHeight / 2;
|
1460 |
break;
|
1461 |
} |
1462 |
|
1463 |
if( newReferencePoint.x < 0 ) { |
1464 |
newReferencePoint.x = DefaultXMargin; |
1465 |
} |
1466 |
if( newReferencePoint.y < 0 ) { |
1467 |
newReferencePoint.y = DefaultYMargin; |
1468 |
} |
1469 |
|
1470 |
return newReferencePoint;
|
1471 |
} |
1472 |
|
1473 |
} |