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