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