svn-gvsig-desktop / trunk / extensions / extDockingSkin / src / main / java / org / gvsig / mdiManager / DockingManager.java @ 25020
History | View | Annotate | Download (27.2 KB)
1 |
package org.gvsig.mdiManager; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.Point; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.WindowAdapter; |
10 |
import java.awt.event.WindowEvent; |
11 |
import java.beans.PropertyVetoException; |
12 |
import java.util.ArrayList; |
13 |
import java.util.HashMap; |
14 |
import java.util.Iterator; |
15 |
|
16 |
import javax.swing.AbstractButton; |
17 |
import javax.swing.ButtonGroup; |
18 |
import javax.swing.ButtonModel; |
19 |
import javax.swing.ImageIcon; |
20 |
import javax.swing.JDialog; |
21 |
import javax.swing.JLabel; |
22 |
import javax.swing.JOptionPane; |
23 |
import javax.swing.JToggleButton; |
24 |
|
25 |
import net.infonode.docking.DockingWindow; |
26 |
import net.infonode.docking.DockingWindowListener; |
27 |
import net.infonode.docking.FloatingWindow; |
28 |
import net.infonode.docking.OperationAbortedException; |
29 |
import net.infonode.docking.RootWindow; |
30 |
import net.infonode.docking.SplitWindow; |
31 |
import net.infonode.docking.TabWindow; |
32 |
import net.infonode.docking.View; |
33 |
import net.infonode.docking.properties.RootWindowProperties; |
34 |
import net.infonode.docking.util.DeveloperUtil; |
35 |
import net.infonode.docking.util.DockingUtil; |
36 |
import net.infonode.docking.util.PropertiesUtil; |
37 |
import net.infonode.docking.util.ViewMap; |
38 |
import net.infonode.util.Direction; |
39 |
|
40 |
import org.apache.log4j.Logger; |
41 |
|
42 |
import com.iver.andami.PluginServices; |
43 |
import com.iver.andami.plugins.Extension; |
44 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
45 |
import com.iver.andami.ui.mdiFrame.SelectableToolBar; |
46 |
import com.iver.andami.ui.mdiManager.IWindow; |
47 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
48 |
import com.iver.andami.ui.mdiManager.MDIManager; |
49 |
import com.iver.andami.ui.mdiManager.SingletonDialogAlreadyShownException; |
50 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
51 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
52 |
|
53 |
public class DockingManager extends Extension implements MDIManager, |
54 |
ActionListener {
|
55 |
private MDIFrame mainFrame;
|
56 |
// private HashMap<Object, IWindow> windowRelationship;
|
57 |
// private HashMap<IWindow, Object> invertedWindowRelationship;
|
58 |
// private HashMap<IWindow, WindowInfo> infoRelationship;
|
59 |
private static Logger logger = Logger.getLogger(DockingManager.class |
60 |
.getName()); |
61 |
|
62 |
public static final int PROJECT_MANAGER = 0; |
63 |
public static final int VIEWS = 1; |
64 |
public static final int TOOLS = 2; |
65 |
|
66 |
private TabWindow tabProject;
|
67 |
private TabWindow tabViews;
|
68 |
private TabWindow tabTools;
|
69 |
private TabWindow tabRootWindow;
|
70 |
private RootWindow rootWindow;
|
71 |
|
72 |
private DialogStack dialogStack;
|
73 |
|
74 |
private SingletonSupport singletonSupport;
|
75 |
private DockWindowSupport dockWindowSupport;
|
76 |
private DockWindowStack wss;
|
77 |
private DockInfoSupport wis;
|
78 |
|
79 |
private DockWindow lastFocusedWindow = null; |
80 |
private JToggleButton projectButton; |
81 |
private DockWindow projectWindow;
|
82 |
boolean showProjectWindow = true; |
83 |
|
84 |
private Dimension projectWindowSise; |
85 |
private JToggleButton hiddeButton; |
86 |
|
87 |
/**
|
88 |
* Associates JInternalFrames with the IWindow they contain
|
89 |
*/
|
90 |
public void init(MDIFrame frame) { |
91 |
|
92 |
this.mainFrame = frame;
|
93 |
|
94 |
dockWindowSupport = new DockWindowSupport(mainFrame, rootWindow);
|
95 |
dialogStack = new DialogStack();
|
96 |
singletonSupport = new SingletonSupport();
|
97 |
wis = new DockInfoSupport(mainFrame, dockWindowSupport,
|
98 |
singletonSupport); |
99 |
wss = new DockWindowStack(wis);
|
100 |
dockWindowSupport.setVis(wis); |
101 |
|
102 |
singletonSupport.setDockInfoSupport(wis); |
103 |
singletonSupport.setDockWindowSupport(dockWindowSupport); |
104 |
|
105 |
singletonSupport.rootWindow = this.rootWindow;
|
106 |
|
107 |
initDockingSystem(); |
108 |
|
109 |
// TODO Auto-generated method stub
|
110 |
mainFrame = frame; |
111 |
|
112 |
// contentPanel.getWindowBar(Direction.LEFT).setEnabled(true);
|
113 |
// contentPanel.getWindowBar(Direction.DOWN).setEnabled(true);
|
114 |
// contentPanel.getWindowBar(Direction.RIGHT).setEnabled(true);
|
115 |
// contentPanel.setWindow(new SplitWindow(true, 0.4f, new SplitWindow(
|
116 |
// false, views[0], new SplitWindow(false, views[1], views[2])),
|
117 |
// new TabWindow(new DockingWindow[] { views[3], views[4] })));
|
118 |
|
119 |
// contentPanel.setWindow(new SplitWindow(true, 0.35f,
|
120 |
// windowingLayout[PROJECT_MANAGER],
|
121 |
// new SplitWindow(false,0.7f,
|
122 |
// windowingLayout[VIEWS],
|
123 |
// windowingLayout[TOOLS])));
|
124 |
// DeveloperUtil.createWindowLayoutFrame("Debug Layout Window",
|
125 |
// contentPanel)
|
126 |
// .setVisible(true);
|
127 |
|
128 |
// windowRelationship = new HashMap<Object, IWindow>();
|
129 |
// invertedWindowRelationship = new HashMap<IWindow, Object>();
|
130 |
// infoRelationship = new HashMap<IWindow, WindowInfo>();
|
131 |
mainFrame.getContentPane().add(rootWindow, BorderLayout.CENTER);
|
132 |
// contentPanel.split(dockingwindow, direccion, ni guarra)
|
133 |
} |
134 |
|
135 |
private void initDockingSystem() { |
136 |
// TODO Auto-generated method stub
|
137 |
|
138 |
// Creating view map
|
139 |
View[] views = new View[20]; |
140 |
ViewMap viewMap = new ViewMap();
|
141 |
for (int i = 0; i < views.length; i++) { |
142 |
views[i] = new View("View " + i, null, new JLabel("This is view " |
143 |
+ i + "!"));
|
144 |
viewMap.addView(i, views[i]); |
145 |
|
146 |
} |
147 |
// Creating views tab window
|
148 |
tabProject = new TabWindow();
|
149 |
// Adding views to the tab
|
150 |
// tabProject.addTab(views[0]);
|
151 |
// tabProject.addTab(views[1]);
|
152 |
// tabProject.addTab(views[2]);
|
153 |
tabProject.setPreferredMinimizeDirection(Direction.LEFT); |
154 |
|
155 |
// Creating views tab window
|
156 |
tabViews = new TabWindow();
|
157 |
// Adding views to the tab
|
158 |
// tabViews.addTab(views[3]);
|
159 |
// tabViews.addTab(views[4]);
|
160 |
// tabViews.addTab(views[5]);
|
161 |
tabViews.setPreferredMinimizeDirection(Direction.RIGHT); |
162 |
|
163 |
// Creating views tab window
|
164 |
tabTools = new TabWindow();
|
165 |
// Adding views to the tab
|
166 |
// tabTools.addTab(views[6]);
|
167 |
// tabTools.addTab(views[7]);
|
168 |
// tabTools.addTab(views[8]);
|
169 |
tabTools.setPreferredMinimizeDirection(Direction.DOWN); |
170 |
|
171 |
// Creating the main tab window
|
172 |
tabRootWindow = new TabWindow();
|
173 |
// Creating the split window
|
174 |
SplitWindow splitRootWindow = new SplitWindow(true, 0.35f, tabProject, |
175 |
new SplitWindow(false, 0.7f, tabViews, tabTools)); |
176 |
// Adding the split to the tab
|
177 |
tabRootWindow.addTab(splitRootWindow); |
178 |
|
179 |
// Creating the root window
|
180 |
rootWindow = new RootWindow(true, null);// DockingUtil.createRootWindow( |
181 |
// new
|
182 |
// StringViewMap(), true);
|
183 |
|
184 |
singletonSupport.rootWindow = rootWindow; |
185 |
|
186 |
// Setting up the root window
|
187 |
rootWindow.getWindowBar(Direction.LEFT).setEnabled(true);
|
188 |
rootWindow.getWindowBar(Direction.DOWN).setEnabled(true);
|
189 |
rootWindow.getWindowBar(Direction.RIGHT).setEnabled(true);
|
190 |
|
191 |
RootWindowProperties titleBarStyleProperties = PropertiesUtil |
192 |
.createTitleBarStyleRootWindowProperties(); |
193 |
|
194 |
// Setting the style to the root window
|
195 |
rootWindow.getRootWindowProperties().addSuperObject( |
196 |
titleBarStyleProperties); |
197 |
|
198 |
// Only for test
|
199 |
DeveloperUtil |
200 |
.createWindowLayoutFrame("Debug Layout Window", rootWindow)
|
201 |
.setVisible(true);
|
202 |
|
203 |
// Button for the project window.
|
204 |
projectButton = new JToggleButton("projet window"); |
205 |
hiddeButton = new JToggleButton("Hidde project button"); |
206 |
|
207 |
projectButton.addActionListener(this);
|
208 |
|
209 |
} |
210 |
|
211 |
public IWindow addWindow(IWindow iWindow)
|
212 |
throws SingletonDialogAlreadyShownException {
|
213 |
// se obtiene la informaci�n de la vista
|
214 |
WindowInfo wi = iWindow.getWindowInfo(); |
215 |
// New window object
|
216 |
Object newWindow = null; |
217 |
|
218 |
if ((iWindow instanceof SingletonWindow) && (wi.isModal())) { |
219 |
throw new RuntimeException("A modal view cannot be a SingletonView"); |
220 |
} |
221 |
if ((iWindow.getWindowProfile() == WindowInfo.DIALOG_PROFILE) && (wi.isModeless())) {
|
222 |
throw new RuntimeException("A modeless view cannot have the DIALOG_PROFILE property"); |
223 |
} |
224 |
|
225 |
/*
|
226 |
* Se obtiene la referencia a la vista anterior por si es una singleton
|
227 |
* y est� siendo mostrada. Se obtiene su informaci�n si ya fue
|
228 |
* mostrada
|
229 |
*/
|
230 |
boolean singletonPreviouslyAdded = false; |
231 |
|
232 |
if (iWindow instanceof SingletonWindow) { |
233 |
SingletonWindow sw = (SingletonWindow) iWindow; |
234 |
// singletonPreviouslyAdded = singletonSupport.registerWindow(sw
|
235 |
// .getClass(), sw.getWindowModel(), wi);
|
236 |
|
237 |
if (singletonSupport.registerWindow(sw.getClass(), sw
|
238 |
.getWindowModel(), wi)) { |
239 |
singletonPreviouslyAdded = true;
|
240 |
} |
241 |
} |
242 |
|
243 |
if (singletonPreviouslyAdded) {
|
244 |
System.out.println("ventana tipo singleton"); |
245 |
if (!singletonSupport.contains((SingletonWindow) iWindow)) {
|
246 |
// restaurar el foco;
|
247 |
DockWindow frame = dockWindowSupport.getDockWindow(iWindow); |
248 |
singletonSupport.openSingletonWindow((SingletonWindow) iWindow, |
249 |
frame); |
250 |
addDockedWindow(iWindow, wi); |
251 |
wss.add(iWindow, new ActionListener() { |
252 |
public void actionPerformed(ActionEvent e) { |
253 |
IWindow v = wis.getWindowById(Integer.parseInt(e
|
254 |
.getActionCommand())); |
255 |
DockWindow f = dockWindowSupport.getDockWindow(v); |
256 |
//f.getTopLevelAncestor().requestFocus();
|
257 |
//f.restoreFocus();
|
258 |
f.requestFocus(); |
259 |
wss.setActive(v); |
260 |
// activateJInternalFrame(f);
|
261 |
} |
262 |
}); |
263 |
return iWindow;
|
264 |
} else {
|
265 |
// restaurar el foco
|
266 |
// La vista est� actualmente abierta
|
267 |
DockWindow frame = (DockWindow) singletonSupport |
268 |
.getFrame((SingletonWindow) iWindow); |
269 |
// activateJInternalFrame(frame);
|
270 |
//frame.getTopLevelAncestor().requestFocus();
|
271 |
//frame.restoreFocus();
|
272 |
frame.requestFocus(); |
273 |
wss.setActive(iWindow); |
274 |
return dockWindowSupport.getWindow((DockWindow) frame);
|
275 |
} |
276 |
|
277 |
} else {
|
278 |
// infoRelationship.put(iWindow, wi);
|
279 |
if (wi.isModal()) {
|
280 |
addModalDialog(iWindow, wi); |
281 |
} else {
|
282 |
if ((iWindow.getWindowProfile()
|
283 |
.equals(WindowInfo.PROJECT_PROFILE)) |
284 |
&& (this.projectWindow != null)) { |
285 |
setProjectWindowVisible(!showProjectWindow); |
286 |
} else {
|
287 |
wss.add(iWindow, new ActionListener() { |
288 |
public void actionPerformed(ActionEvent e) { |
289 |
IWindow v = wis.getWindowById(Integer.parseInt(e
|
290 |
.getActionCommand())); |
291 |
if (!(v.getWindowProfile()
|
292 |
.equals(WindowInfo.PROJECT_PROFILE)) |
293 |
&& (projectWindow != null)) {
|
294 |
DockWindow f = dockWindowSupport |
295 |
.getDockWindow(v); |
296 |
//f.getTopLevelAncestor().requestFocus();
|
297 |
//f.restoreFocus();
|
298 |
f.requestFocus(); |
299 |
wss.setActive(v); |
300 |
} else {
|
301 |
setProjectWindowVisible(!showProjectWindow); |
302 |
} |
303 |
// activateJInternalFrame(f);
|
304 |
} |
305 |
}); |
306 |
addDockedWindow(iWindow); |
307 |
} |
308 |
} |
309 |
} |
310 |
|
311 |
// windowRelationship.put(newWindow, iWindow);
|
312 |
// invertedWindowRelationship.put(iWindow, newWindow);
|
313 |
|
314 |
return iWindow;
|
315 |
} |
316 |
|
317 |
protected void addModalDialog(IWindow iWindow, WindowInfo wi) { |
318 |
|
319 |
JDialog dlg = dockWindowSupport.getJDialog(iWindow);
|
320 |
|
321 |
centerDialog(dlg); |
322 |
|
323 |
dlg.addWindowListener(new DockDialogWindowListener());
|
324 |
dialogStack.pushDialog(dlg); |
325 |
|
326 |
dlg.setVisible(wis.getWindowInfo(iWindow).isVisible()); |
327 |
|
328 |
// // Creating dialog
|
329 |
// JDialog dialog = new JDialog(mainFrame, wi.getTitle());
|
330 |
// dialog.setContentPane((Container) iWindow);
|
331 |
// dialog.setSize(new Dimension(wi.getWidth(), wi.getHeight()));
|
332 |
// dialog.setPreferredSize(new Dimension(wi.getHeight(),
|
333 |
// wi.getWidth()));
|
334 |
// centerDialog(dialog);
|
335 |
// dialog.addWindowListener(new DialogWindowListener());
|
336 |
// dialog.setModal(wi.isModal());
|
337 |
//
|
338 |
// // Pushing dialog
|
339 |
// dialogStack.pushDialog(dialog);
|
340 |
//
|
341 |
// // Showing dialog
|
342 |
// dialog.setVisible(true);
|
343 |
//
|
344 |
// return dialog;
|
345 |
} |
346 |
|
347 |
private void addDockedWindow(IWindow iWindow) { |
348 |
WindowInfo wi = wis.getWindowInfo(iWindow); |
349 |
|
350 |
DockWindow wnd = dockWindowSupport.getDockWindow(iWindow); |
351 |
if (iWindow instanceof SingletonWindow) { |
352 |
SingletonWindow sv = (SingletonWindow) iWindow; |
353 |
singletonSupport.openSingletonWindow(sv, wnd); |
354 |
} |
355 |
|
356 |
addDockedWindow(iWindow, wi); |
357 |
} |
358 |
|
359 |
private void addDockedWindow(IWindow iWindow, WindowInfo wi) { |
360 |
DockWindow wnd = dockWindowSupport.getDockWindow(iWindow); |
361 |
wnd.addListener(new DockWindowListener());
|
362 |
|
363 |
Integer type = (Integer) wnd.getIWindow().getWindowProfile(); |
364 |
System.out.println("Class iWindow: " + iWindow.getClass()); |
365 |
if (type != null) { |
366 |
if (type.equals(WindowInfo.PROJECT_PROFILE)) {
|
367 |
this.projectButton.setName("project window"); |
368 |
// // tab.getParent().add(this.projectButton);
|
369 |
// tab.addTab(wnd);
|
370 |
SelectableToolBar[] toolBar = PluginServices.getMainFrame()
|
371 |
.getToolbars(); |
372 |
for (int i = 0; i < toolBar.length; i++) { |
373 |
SelectableToolBar tool = toolBar[i]; |
374 |
if (toolBar[i].getName().equals("gvSIG")) { |
375 |
ButtonGroup gButton = new ButtonGroup(); |
376 |
tool.addButton(gButton, this.projectButton);
|
377 |
gButton.add(this.hiddeButton);
|
378 |
// tool.addButton(gButton, this.projectButton);
|
379 |
} |
380 |
// System.err.println("toolbar : " + toolBar[i].getName() +
|
381 |
// " visible " + toolBar[i].isEnabled());
|
382 |
} |
383 |
|
384 |
projectWindow = wnd; |
385 |
} else if (type.equals(WindowInfo.EDITOR_PROFILE)) { |
386 |
DockingUtil.addWindow(wnd, rootWindow); |
387 |
} |
388 |
if (type.equals(WindowInfo.TOOL_PROFILE)) {
|
389 |
rootWindow.getWindowBar(Direction.DOWN).addTab(wnd); |
390 |
} |
391 |
if (type.equals(WindowInfo.PROPERTIES_PROFILE)) {
|
392 |
// DockingUtil.addWindow(wnd, rootWindow);
|
393 |
|
394 |
int x = (wi.getX() <= 0) ? 100 : wi.getX(); |
395 |
int y = (wi.getY() <= 0) ? 100 : wi.getY(); |
396 |
Point possition = new Point(x, y); |
397 |
final FloatingWindow floatingWindow = rootWindow
|
398 |
.createFloatingWindow(possition, new Dimension(wi |
399 |
.getWidth(), wi.getHeight()), wnd); |
400 |
// Show the window
|
401 |
floatingWindow.getTopLevelAncestor().setVisible(true);
|
402 |
((JDialog) floatingWindow.getTopLevelAncestor())
|
403 |
.addWindowListener(new FloatingWindowContainerListener(
|
404 |
floatingWindow)); |
405 |
// DockingUtil.addWindow(wnd, rootWindow);
|
406 |
|
407 |
|
408 |
} |
409 |
} else {
|
410 |
JOptionPane
|
411 |
.showMessageDialog( |
412 |
null,
|
413 |
"la ventana que se va a a�adir no tiene una zona predeterminada en el skin, rellenar la funcion getWindowProfile()"
|
414 |
+ "de la clase "
|
415 |
+ wnd.getIWindow().getClass()); |
416 |
DockingUtil.addWindow(wnd, rootWindow); |
417 |
|
418 |
} |
419 |
|
420 |
//
|
421 |
// if (wi.getAdditionalInfo() != null
|
422 |
// && wi.getAdditionalInfo().equals("ProjectWindow")) {
|
423 |
// // rootWindow.getWindowBar(Direction.LEFT).addTab(wnd,
|
424 |
// wi.getWidth());
|
425 |
// // TabWindow tab = new TabWindow();
|
426 |
// // tab.setSize(20, 50);
|
427 |
//
|
428 |
// projectWindow = wnd;
|
429 |
//
|
430 |
// tab = new TabWindow();
|
431 |
// tab.setSize(20, 50);
|
432 |
// tab.add(projectWindow);
|
433 |
// projectWindowSise =
|
434 |
// rootWindow.getWindowBar(Direction.LEFT).getPreferredSize();
|
435 |
// rootWindow.getWindowBar(Direction.LEFT).add(tab);
|
436 |
//
|
437 |
// // rootWindow.getWindowBar(Direction.LEFT).add(tab);
|
438 |
//
|
439 |
// rootWindow.getWindowBar(Direction.DOWN).add(this.projectButton);
|
440 |
//
|
441 |
//
|
442 |
// } else {
|
443 |
// if (wi.isModeless()) {
|
444 |
// final FloatingWindow floatingWindow = rootWindow
|
445 |
// .createFloatingWindow(new Point(wi.getX(), wi.getY()),
|
446 |
// new Dimension(wi.getWidth(), wi.getHeight()),
|
447 |
// wnd);
|
448 |
// // Show the window
|
449 |
// floatingWindow.getTopLevelAncestor().setVisible(true);
|
450 |
// ((JDialog) floatingWindow.getTopLevelAncestor())
|
451 |
// .addWindowListener(new
|
452 |
// FloatingWindowContainerListener(floatingWindow));
|
453 |
// } else {
|
454 |
// DockingUtil.addWindow(wnd, rootWindow);
|
455 |
// }
|
456 |
// }
|
457 |
// DockingUtil.addWindow(wnd, rootWindow);
|
458 |
updateDockWindowProperties(wnd, wi); |
459 |
//if (wnd.getTopLevelAncestor() != null)
|
460 |
// wnd.getTopLevelAncestor().requestFocus();
|
461 |
//wnd.restoreFocus();
|
462 |
wnd.requestFocus(); |
463 |
lastFocusedWindow = wnd; |
464 |
} |
465 |
|
466 |
private void updateDockWindowProperties(DockWindow frame, WindowInfo wi) { |
467 |
int height, width;
|
468 |
frame.setName(wi.getTitle()); |
469 |
frame.setVisible(wi.isVisible()); |
470 |
// frame.setResizable(wi.isResizable());
|
471 |
frame.getWindowProperties().setMinimizeEnabled(wi.isIconifiable()); |
472 |
frame.getWindowProperties().setMaximizeEnabled(wi.isMaximizable()); |
473 |
// try {
|
474 |
// frame.setMaximum(wi.isMaximized());
|
475 |
// } catch (PropertyVetoException e) {
|
476 |
// TODO Auto-generated catch block
|
477 |
// e.printStackTrace();
|
478 |
// }
|
479 |
} |
480 |
|
481 |
public IWindow addCentredWindow(IWindow iWindow)
|
482 |
throws SingletonDialogAlreadyShownException {
|
483 |
// TODO Auto-generated method stub
|
484 |
addWindow(iWindow); |
485 |
return iWindow;
|
486 |
} |
487 |
|
488 |
/**
|
489 |
* Situa un di�logo modal en el centro de la pantalla
|
490 |
*
|
491 |
* @param d
|
492 |
* Di�logo que se quiere situar
|
493 |
*/
|
494 |
private void centerDialog(JDialog d) { |
495 |
int offSetX = d.getWidth() / 2; |
496 |
int offSetY = d.getHeight() / 2; |
497 |
|
498 |
d.setLocation((mainFrame.getWidth() / 2) - offSetX, (mainFrame
|
499 |
.getHeight() / 2)
|
500 |
- offSetY); |
501 |
} |
502 |
|
503 |
public void changeWindowInfo(IWindow arg0, WindowInfo arg1) { |
504 |
// TODO Auto-generated method stub
|
505 |
|
506 |
} |
507 |
|
508 |
public void closeAllWindows() { |
509 |
// TODO Auto-generated method stub
|
510 |
System.out.println("cerrando todas"); |
511 |
|
512 |
ArrayList eliminar = new ArrayList(); |
513 |
Iterator i = dockWindowSupport.getWindowIterator();
|
514 |
|
515 |
while (i.hasNext()) {
|
516 |
eliminar.add((IWindow) i.next()); |
517 |
} |
518 |
|
519 |
for (Iterator iter = eliminar.iterator(); iter.hasNext();) { |
520 |
IWindow vista = (IWindow) iter.next(); |
521 |
closeWindow(vista); |
522 |
} |
523 |
|
524 |
} |
525 |
|
526 |
public boolean closeSingletonWindow(Object model) { |
527 |
DockWindow[] frames = (DockWindow[]) singletonSupport.getFrames(model); |
528 |
if (frames.length == 0) |
529 |
return false; |
530 |
for (int i = 0; i < frames.length; i++) { |
531 |
closeDockWindow(frames[i]); |
532 |
} |
533 |
return true; |
534 |
} |
535 |
|
536 |
public boolean closeSingletonWindow(Class viewClass, Object model) { |
537 |
DockWindow frame = (DockWindow) singletonSupport.getFrame(viewClass, |
538 |
model); |
539 |
if (frame == null) |
540 |
return false; |
541 |
closeDockWindow(frame); |
542 |
return true; |
543 |
} |
544 |
|
545 |
private void closeDockWindow(DockWindow frame) { |
546 |
IWindow s = (IWindow) dockWindowSupport.getWindow(frame); |
547 |
|
548 |
frame.close(); |
549 |
callWindowClosed(s); |
550 |
} |
551 |
|
552 |
private void callWindowClosed(IWindow window) { |
553 |
if (window instanceof IWindowListener) { |
554 |
((IWindowListener) window).windowClosed(); |
555 |
} |
556 |
} |
557 |
|
558 |
public void closeWindow(IWindow iWindow) { |
559 |
|
560 |
if (iWindow.getWindowInfo().isModal()) {
|
561 |
closeJDialog(); |
562 |
} else { // Si no es modal se cierra el JInternalFrame |
563 |
closeDockWindow(dockWindowSupport.getDockWindow(iWindow)); |
564 |
} |
565 |
|
566 |
} |
567 |
|
568 |
private void closeJDialog() { |
569 |
JDialog dlg = dialogStack.popDialog();
|
570 |
if (dlg == null) |
571 |
return;
|
572 |
dlg.setVisible(false);
|
573 |
|
574 |
// IWindow s = fws.getWindow(dlg);
|
575 |
//
|
576 |
// callWindowClosed(s);
|
577 |
//
|
578 |
// fws.closeWindow(s);
|
579 |
//
|
580 |
// // Si es singleton se desasocia el modelo con la vista
|
581 |
// if (s instanceof SingletonWindow) {
|
582 |
// sws.closeWindow((SingletonWindow) s);
|
583 |
// }
|
584 |
} |
585 |
|
586 |
public IWindow[] getAllWindows() { |
587 |
ArrayList windows = new ArrayList(); |
588 |
Iterator i = dockWindowSupport.getWindowIterator();
|
589 |
|
590 |
while (i.hasNext()) {
|
591 |
windows.add((IWindow) i.next()); |
592 |
} |
593 |
return (IWindow[]) windows.toArray(new IWindow[0]); |
594 |
} |
595 |
|
596 |
public IWindow getActiveWindow() {
|
597 |
// DockingWindow dw = rootWindow.getFocusedView();
|
598 |
DockingWindow dw = null;
|
599 |
if (dw == null) |
600 |
dw = lastFocusedWindow; |
601 |
// System.err.println("GetfocusedView: " + dw);
|
602 |
if (dw instanceof DockWindow) { |
603 |
DockWindow view = (DockWindow) dw; |
604 |
if (view != null) { |
605 |
IWindow theWindow = dockWindowSupport.getWindow(view); |
606 |
if (theWindow == null) |
607 |
return null; |
608 |
if (theWindow.getWindowInfo().isPalette())
|
609 |
return wss.getActiveWindow();
|
610 |
else
|
611 |
return dockWindowSupport.getWindow(view);
|
612 |
} |
613 |
// return vss.getActiveView();
|
614 |
} |
615 |
|
616 |
return null; |
617 |
} |
618 |
|
619 |
public IWindow getFocusWindow() {
|
620 |
// DockingWindow dw = rootWindow.getFocusedView();
|
621 |
DockingWindow dw = null;
|
622 |
if (dw == null) |
623 |
dw = lastFocusedWindow; |
624 |
// System.err.println("GetfocusedView: " + dw);
|
625 |
if (dw instanceof DockWindow) { |
626 |
DockWindow view = (DockWindow) dw; |
627 |
if (view != null) { |
628 |
IWindow theView = dockWindowSupport.getWindow(view); |
629 |
if (theView == null) |
630 |
return null; |
631 |
// System.out.println("CAPA ACTIVA!!!!! " + view.getTitle());
|
632 |
return dockWindowSupport.getWindow(view);
|
633 |
} |
634 |
} |
635 |
return null; |
636 |
} |
637 |
|
638 |
public IWindow[] getOrderedWindows() { |
639 |
// TODO Auto-generated method stub
|
640 |
return this.getAllWindows(); |
641 |
} |
642 |
|
643 |
public WindowInfo getWindowInfo(IWindow iWindow) {
|
644 |
// TODO Auto-generated method stub
|
645 |
return this.wis.getWindowInfo(iWindow); |
646 |
} |
647 |
|
648 |
public void refresh(IWindow iWindow) { |
649 |
// TODO Auto-generated method stub
|
650 |
rootWindow.invalidate(); |
651 |
} |
652 |
|
653 |
public void restoreCursor() { |
654 |
// TODO Auto-generated method stub
|
655 |
|
656 |
} |
657 |
|
658 |
public void setBackgroundImage(ImageIcon arg0, String arg1) { |
659 |
// TODO Auto-generated method stub
|
660 |
|
661 |
} |
662 |
|
663 |
public void setMaximum(IWindow arg0, boolean arg1) |
664 |
throws PropertyVetoException { |
665 |
// TODO Auto-generated method stub
|
666 |
|
667 |
} |
668 |
|
669 |
public void setWaitCursor() { |
670 |
// TODO Auto-generated method stub
|
671 |
|
672 |
} |
673 |
|
674 |
public void execute(String arg0) { |
675 |
// TODO Auto-generated method stub
|
676 |
|
677 |
} |
678 |
|
679 |
public void initialize() { |
680 |
// TODO Auto-generated method stub
|
681 |
|
682 |
} |
683 |
|
684 |
public boolean isEnabled() { |
685 |
// TODO Auto-generated method stub
|
686 |
return false; |
687 |
} |
688 |
|
689 |
public boolean isVisible() { |
690 |
// TODO Auto-generated method stub
|
691 |
return false; |
692 |
} |
693 |
|
694 |
private void callWindowActivated(IWindow window) { |
695 |
// logger.debug("View '" + window.getWindowInfo().getTitle()
|
696 |
// + "' activated (callViewActivated)");
|
697 |
if (window instanceof IWindowListener) { |
698 |
((IWindowListener) window).windowActivated(); |
699 |
} |
700 |
} |
701 |
|
702 |
/**
|
703 |
* Listener para los eventos de cerrado de los di�logos. Tiene su raz�n
|
704 |
* de ser en que los di�logos han de devolverse al pool cuando se cierran
|
705 |
*
|
706 |
* @author Fernando Gonz�lez Cort�s
|
707 |
*/
|
708 |
public class DockDialogWindowListener extends WindowAdapter { |
709 |
/**
|
710 |
* Captura el evento de cerrado de los di�logos con el fin de realizar
|
711 |
* tareas de mantenimiento
|
712 |
*
|
713 |
* @param e
|
714 |
* evento
|
715 |
*/
|
716 |
public void windowActivated(WindowEvent e) { |
717 |
IWindow window = dockWindowSupport.getWindow((Component) e
|
718 |
.getSource()); |
719 |
callWindowActivated(window); |
720 |
} |
721 |
|
722 |
/**
|
723 |
* Captura el evento de cerrado de los di�logos con el fin de realizar
|
724 |
* tareas de mantenimiento
|
725 |
*
|
726 |
* @param e
|
727 |
* evento
|
728 |
*/
|
729 |
public void windowClosing(WindowEvent e) { |
730 |
closeJDialog(); |
731 |
} |
732 |
|
733 |
} |
734 |
|
735 |
/***************************************************************************
|
736 |
*
|
737 |
* New listener to control de DockWindow events
|
738 |
*
|
739 |
*/
|
740 |
|
741 |
private class DockWindowListener implements DockingWindowListener { |
742 |
|
743 |
public void viewFocusChanged(View arg0, View arg1) { |
744 |
View view = arg0;
|
745 |
if (view instanceof DockWindow) { |
746 |
DockWindow dockWindow = (DockWindow) view; |
747 |
if (dockWindow == null) |
748 |
return;
|
749 |
WindowInfo wi = dockWindow.getIWindow() |
750 |
.getWindowInfo(); |
751 |
|
752 |
if (wi.isMaximizable()) {
|
753 |
dockWindow.getWindowProperties().setMaximizeEnabled(true);
|
754 |
} |
755 |
|
756 |
mainFrame.enableControls(); |
757 |
if (wi.getSelectedTools() == null) { |
758 |
// this is the first time this window is activated
|
759 |
wi.setSelectedTools(new HashMap(mainFrame |
760 |
.getInitialSelectedTools())); |
761 |
} |
762 |
mainFrame.setSelectedTools(wi.getSelectedTools()); |
763 |
callWindowActivated(dockWindow.getIWindow()); |
764 |
if (arg1 != null) |
765 |
lastFocusedWindow = (DockWindow) arg1; |
766 |
} |
767 |
} |
768 |
|
769 |
public void windowAdded(DockingWindow arg0, DockingWindow arg1) { |
770 |
DockingWindow view = arg1; |
771 |
if (view instanceof DockWindow) { |
772 |
DockWindow dockWindow = (DockWindow) view; |
773 |
if (dockWindow == null) |
774 |
return;
|
775 |
WindowInfo wi = dockWindow.getIWindow() |
776 |
.getWindowInfo(); |
777 |
|
778 |
if (wi.isMaximizable()) {
|
779 |
dockWindow.getWindowProperties().setMaximizeEnabled(true);
|
780 |
} |
781 |
|
782 |
mainFrame.enableControls(); |
783 |
if (wi.getSelectedTools() == null) { |
784 |
// this is the first time this window is activated
|
785 |
wi.setSelectedTools(new HashMap(mainFrame |
786 |
.getInitialSelectedTools())); |
787 |
} |
788 |
mainFrame.setSelectedTools(wi.getSelectedTools()); |
789 |
callWindowActivated(dockWindow.getIWindow()); |
790 |
lastFocusedWindow = dockWindow; |
791 |
} |
792 |
mainFrame.enableControls(); |
793 |
rootWindow.validate(); |
794 |
} |
795 |
|
796 |
public void windowClosed(DockingWindow view) { |
797 |
if (view instanceof DockWindow) { |
798 |
DockWindow dockWindow = (DockWindow) view; |
799 |
WindowInfo wi = wis.getWindowInfo((IWindow) dockWindowSupport |
800 |
.getWindow(dockWindow)); |
801 |
|
802 |
IWindow win = dockWindowSupport.getWindow(dockWindow); |
803 |
callWindowClosed(win); |
804 |
boolean alwaysLive;
|
805 |
if (win instanceof SingletonWindow) { |
806 |
singletonSupport.closeWindow((SingletonWindow) win); |
807 |
} |
808 |
|
809 |
dockWindowSupport.closeWindow(win); |
810 |
|
811 |
// panel.remove(c);
|
812 |
|
813 |
wss.remove(win); |
814 |
|
815 |
if (!wi.isPalette())
|
816 |
mainFrame.enableControls(); |
817 |
mainFrame.enableControls(); |
818 |
rootWindow.validate(); |
819 |
} |
820 |
} |
821 |
|
822 |
public void windowClosing(DockingWindow view) |
823 |
throws OperationAbortedException {
|
824 |
mainFrame.enableControls(); |
825 |
rootWindow.validate(); |
826 |
|
827 |
} |
828 |
|
829 |
public void windowDocked(DockingWindow arg0) { |
830 |
mainFrame.enableControls(); |
831 |
rootWindow.validate(); |
832 |
|
833 |
} |
834 |
|
835 |
public void windowDocking(DockingWindow arg0) |
836 |
throws OperationAbortedException {
|
837 |
mainFrame.enableControls(); |
838 |
rootWindow.validate(); |
839 |
|
840 |
} |
841 |
|
842 |
public void windowHidden(DockingWindow arg0) { |
843 |
mainFrame.enableControls(); |
844 |
rootWindow.validate(); |
845 |
} |
846 |
|
847 |
public void windowMaximized(DockingWindow arg0) { |
848 |
mainFrame.enableControls(); |
849 |
rootWindow.validate(); |
850 |
} |
851 |
|
852 |
public void windowMaximizing(DockingWindow arg0) |
853 |
throws OperationAbortedException {
|
854 |
setProjectWindowVisible(false);
|
855 |
mainFrame.enableControls(); |
856 |
rootWindow.validate(); |
857 |
|
858 |
} |
859 |
|
860 |
public void windowMinimized(DockingWindow arg0) { |
861 |
mainFrame.enableControls(); |
862 |
rootWindow.validate(); |
863 |
|
864 |
} |
865 |
|
866 |
public void windowMinimizing(DockingWindow arg0) |
867 |
throws OperationAbortedException {
|
868 |
mainFrame.enableControls(); |
869 |
rootWindow.validate(); |
870 |
|
871 |
} |
872 |
|
873 |
public void windowRemoved(DockingWindow arg0, DockingWindow arg1) { |
874 |
mainFrame.enableControls(); |
875 |
rootWindow.validate(); |
876 |
|
877 |
} |
878 |
|
879 |
public void windowRestored(DockingWindow arg0) { |
880 |
mainFrame.enableControls(); |
881 |
rootWindow.validate(); |
882 |
} |
883 |
|
884 |
public void windowRestoring(DockingWindow arg0) |
885 |
throws OperationAbortedException {
|
886 |
mainFrame.enableControls(); |
887 |
rootWindow.validate(); |
888 |
|
889 |
} |
890 |
|
891 |
public void windowShown(DockingWindow arg0) { |
892 |
mainFrame.enableControls(); |
893 |
rootWindow.validate(); |
894 |
} |
895 |
|
896 |
public void windowUndocked(DockingWindow arg0) { |
897 |
if (arg0.getTopLevelAncestor() instanceof JDialog) { |
898 |
((JDialog) arg0.getTopLevelAncestor())
|
899 |
.addWindowListener(new FloatingWindowContainerListener(
|
900 |
arg0)); |
901 |
} |
902 |
mainFrame.enableControls(); |
903 |
rootWindow.validate(); |
904 |
|
905 |
} |
906 |
|
907 |
public void windowUndocking(DockingWindow arg0) |
908 |
throws OperationAbortedException {
|
909 |
mainFrame.enableControls(); |
910 |
rootWindow.validate(); |
911 |
|
912 |
} |
913 |
|
914 |
} |
915 |
|
916 |
private void setProjectWindowVisible(boolean show) { |
917 |
showProjectWindow = show; |
918 |
if (showProjectWindow) {
|
919 |
rootWindow.getWindowBar(Direction.LEFT).remove(projectWindow); |
920 |
this.hiddeButton.setSelected(true); |
921 |
rootWindow.validate(); |
922 |
|
923 |
} else {
|
924 |
rootWindow.getWindowBar(Direction.LEFT).add(projectWindow); |
925 |
this.projectButton.setSelected(true); |
926 |
rootWindow.validate(); |
927 |
} |
928 |
|
929 |
} |
930 |
|
931 |
public void actionPerformed(ActionEvent e) { |
932 |
showProjectWindow = !showProjectWindow; |
933 |
setProjectWindowVisible(showProjectWindow); |
934 |
|
935 |
} |
936 |
|
937 |
public boolean isShowProjectWindow() { |
938 |
return showProjectWindow;
|
939 |
} |
940 |
|
941 |
} |