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