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