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