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