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