Statistics
| Revision:

root / trunk / extensions / extDockingSkin / src / main / java / org / gvsig / mdiManager / DockingManager.java @ 25007

History | View | Annotate | Download (25.8 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

    
222
                /*
223
                 * Se obtiene la referencia a la vista anterior por si es una singleton
224
                 * y est? siendo mostrada. Se obtiene su informaci?n si ya fue
225
                 * mostrada
226
                 */
227
                boolean singletonPreviouslyAdded = false;
228

    
229
                if (iWindow instanceof SingletonWindow) {
230
                        SingletonWindow sw = (SingletonWindow) iWindow;
231
                        // singletonPreviouslyAdded = singletonSupport.registerWindow(sw
232
                        // .getClass(), sw.getWindowModel(), wi);
233

    
234
                        if (singletonSupport.registerWindow(sw.getClass(), sw
235
                                        .getWindowModel(), wi)) {
236
                                singletonPreviouslyAdded = true;
237
                        }
238
                }
239

    
240
                if (singletonPreviouslyAdded) {
241
                        System.out.println("ventana tipo singleton");
242
                        if (!singletonSupport.contains((SingletonWindow) iWindow)) {
243
                                // restaurar el foco;
244
                                DockWindow frame = dockWindowSupport.getDockWindow(iWindow);
245
                                singletonSupport.openSingletonWindow((SingletonWindow) iWindow,
246
                                                frame);
247
                                addDockedWindow(iWindow, wi);
248
                                wss.add(iWindow, new ActionListener() {
249
                                        public void actionPerformed(ActionEvent e) {
250
                                                IWindow v = wis.getWindowById(Integer.parseInt(e
251
                                                                .getActionCommand()));
252
                                                DockWindow f = dockWindowSupport.getDockWindow(v);
253
                                                f.getTopLevelAncestor().requestFocus();
254
                                                f.restoreFocus();
255
                                                // activateJInternalFrame(f);
256
                                        }
257
                                });
258
                                return iWindow;
259
                        } else {
260
                                // restaurar el foco
261
                                // La vista est? actualmente abierta
262
                                DockWindow frame = (DockWindow) singletonSupport
263
                                                .getFrame((SingletonWindow) iWindow);
264
                                // activateJInternalFrame(frame);
265
                                frame.getTopLevelAncestor().requestFocus();
266
                                frame.restoreFocus();
267
                                wss.setActive(iWindow);
268
                                return dockWindowSupport.getWindow((DockWindow) frame);
269
                        }
270

    
271
                } else {
272
                        // infoRelationship.put(iWindow, wi);
273
                        if (wi.isModal()) {
274
                                addModalDialog(iWindow, wi);
275
                        } else {
276
                                if ((iWindow.getWindowProfile()
277
                                                .equals(WindowInfo.PROJECT_PROFILE))
278
                                                && (this.projectWindow != null)) {
279
                                        setProjectWindowVisible(!showProjectWindow);
280
                                } else {
281
                                        wss.add(iWindow, new ActionListener() {
282
                                                public void actionPerformed(ActionEvent e) {
283
                                                        IWindow v = wis.getWindowById(Integer.parseInt(e
284
                                                                        .getActionCommand()));
285
                                                        if (!(v.getWindowProfile()
286
                                                                        .equals(WindowInfo.PROJECT_PROFILE))
287
                                                                        && (projectWindow != null)) {
288
                                                                DockWindow f = dockWindowSupport
289
                                                                                .getDockWindow(v);
290
                                                                f.getTopLevelAncestor().requestFocus();
291
                                                                f.restoreFocus();
292
                                                        } else {
293
                                                                setProjectWindowVisible(!showProjectWindow);
294
                                                        }
295
                                                        // activateJInternalFrame(f);
296
                                                }
297
                                        });
298
                                        addDockedWindow(iWindow);
299
                                }
300
                        }
301
                }
302

    
303
                // windowRelationship.put(newWindow, iWindow);
304
                // invertedWindowRelationship.put(iWindow, newWindow);
305

    
306
                return iWindow;
307
        }
308

    
309
        protected void addModalDialog(IWindow iWindow, WindowInfo wi) {
310

    
311
                JDialog dlg = dockWindowSupport.getJDialog(iWindow);
312

    
313
                centerDialog(dlg);
314

    
315
                dlg.addWindowListener(new DockDialogWindowListener());
316
                dialogStack.pushDialog(dlg);
317

    
318
                dlg.setVisible(wis.getWindowInfo(iWindow).isVisible());
319

    
320
                // // Creating dialog
321
                // JDialog dialog = new JDialog(mainFrame, wi.getTitle());
322
                // dialog.setContentPane((Container) iWindow);
323
                // dialog.setSize(new Dimension(wi.getWidth(), wi.getHeight()));
324
                // dialog.setPreferredSize(new Dimension(wi.getHeight(),
325
                // wi.getWidth()));
326
                // centerDialog(dialog);
327
                // dialog.addWindowListener(new DialogWindowListener());
328
                // dialog.setModal(wi.isModal());
329
                //
330
                // // Pushing dialog
331
                // dialogStack.pushDialog(dialog);
332
                //
333
                // // Showing dialog
334
                // dialog.setVisible(true);
335
                //
336
                // return dialog;
337
        }
338

    
339
        private void addDockedWindow(IWindow iWindow) {
340
                WindowInfo wi = wis.getWindowInfo(iWindow);
341

    
342
                DockWindow wnd = dockWindowSupport.getDockWindow(iWindow);
343
                if (iWindow instanceof SingletonWindow) {
344
                        SingletonWindow sv = (SingletonWindow) iWindow;
345
                        singletonSupport.openSingletonWindow(sv, wnd);
346
                }
347

    
348
                addDockedWindow(iWindow, wi);
349
        }
350

    
351
        private void addDockedWindow(IWindow iWindow, WindowInfo wi) {
352
                DockWindow wnd = dockWindowSupport.getDockWindow(iWindow);
353
                wnd.addListener(new DockWindowListener());
354

    
355
                Integer type = (Integer) wnd.getIWindow().getWindowProfile();
356

    
357
                if (type != null) {
358
                        if (type.equals(WindowInfo.PROJECT_PROFILE)) {
359
                                this.projectButton.setName("project window");
360
                                // // tab.getParent().add(this.projectButton);
361
                                // tab.addTab(wnd);
362
                                SelectableToolBar[] toolBar = PluginServices.getMainFrame()
363
                                                .getToolbars();
364
                                for (int i = 0; i < toolBar.length; i++) {
365
                                        SelectableToolBar tool = toolBar[i];
366
                                        if (toolBar[i].getName().equals("gvSIG")) {
367
                                                ButtonGroup gButton = new ButtonGroup();
368
                                                tool.addButton(gButton, this.projectButton);
369
                                                gButton.add(this.hiddeButton);
370
                                                // tool.addButton(gButton, this.projectButton);
371
                                        }
372
                                        // System.err.println("toolbar : " + toolBar[i].getName() +
373
                                        // " visible " + toolBar[i].isEnabled());
374
                                }
375

    
376
                                projectWindow = wnd;
377
                        } else if (type.equals(WindowInfo.EDITOR_PROFILE)) {
378
                                DockingUtil.addWindow(wnd, rootWindow);
379
                        }
380
                        if (type.equals(WindowInfo.TOOL_PROFILE)) {
381
                                DockingUtil.addWindow(wnd, rootWindow);
382
                        }
383
                        if (type.equals(WindowInfo.PROPERTIES_PROFILE)) {
384
                                // DockingUtil.addWindow(wnd, rootWindow);
385

    
386
                                int x = (wi.getX() <= 0) ? 100 : wi.getX();
387
                                int y = (wi.getY() <= 0) ? 100 : wi.getY();
388
                                Point possition = new Point(x, y);
389
                                final FloatingWindow floatingWindow = rootWindow
390
                                                .createFloatingWindow(possition, new Dimension(wi
391
                                                                .getWidth(), wi.getHeight()), wnd);
392
                                // Show the window
393
                                floatingWindow.getTopLevelAncestor().setVisible(true);
394
                                ((JDialog) floatingWindow.getTopLevelAncestor())
395
                                                .addWindowListener(new FloatingWindowContainerListener(
396
                                                                floatingWindow));
397

    
398
                        }
399
                } else {
400
                        JOptionPane
401
                                        .showMessageDialog(
402
                                                        null,
403
                                                        "la ventana que se va a a?adir no tiene una zona predeterminada en el skin, rellenar la funcion getWindowProfile()"
404
                                                                        + "de la clase "
405
                                                                        + wnd.getIWindow().getClass());
406
                        DockingUtil.addWindow(wnd, rootWindow);
407

    
408
                }
409

    
410
                //
411
                // if (wi.getAdditionalInfo() != null
412
                // && wi.getAdditionalInfo().equals("ProjectWindow")) {
413
                // // rootWindow.getWindowBar(Direction.LEFT).addTab(wnd,
414
                // wi.getWidth());
415
                // // TabWindow tab = new TabWindow();
416
                // // tab.setSize(20, 50);
417
                //                        
418
                // projectWindow = wnd;
419
                //                        
420
                // tab = new TabWindow();
421
                // tab.setSize(20, 50);
422
                // tab.add(projectWindow);
423
                // projectWindowSise =
424
                // rootWindow.getWindowBar(Direction.LEFT).getPreferredSize();
425
                // rootWindow.getWindowBar(Direction.LEFT).add(tab);
426
                //                        
427
                // // rootWindow.getWindowBar(Direction.LEFT).add(tab);
428
                //                        
429
                // rootWindow.getWindowBar(Direction.DOWN).add(this.projectButton);
430
                //                        
431
                //                        
432
                // } else {
433
                // if (wi.isModeless()) {
434
                // final FloatingWindow floatingWindow = rootWindow
435
                // .createFloatingWindow(new Point(wi.getX(), wi.getY()),
436
                // new Dimension(wi.getWidth(), wi.getHeight()),
437
                // wnd);
438
                // // Show the window
439
                // floatingWindow.getTopLevelAncestor().setVisible(true);
440
                // ((JDialog) floatingWindow.getTopLevelAncestor())
441
                // .addWindowListener(new
442
                // FloatingWindowContainerListener(floatingWindow));
443
                // } else {
444
                // DockingUtil.addWindow(wnd, rootWindow);
445
                // }
446
                // }
447
                // DockingUtil.addWindow(wnd, rootWindow);
448
                updateDockWindowProperties(wnd, wi);
449
                if (wnd.getTopLevelAncestor() != null)
450
                        wnd.getTopLevelAncestor().requestFocus();
451
                wnd.restoreFocus();
452
                lastFocusedWindow = wnd;
453
        }
454

    
455
        private void updateDockWindowProperties(DockWindow frame, WindowInfo wi) {
456
                int height, width;
457
                frame.setName(wi.getTitle());
458
                frame.setVisible(wi.isVisible());
459
                // frame.setResizable(wi.isResizable());
460
                frame.getWindowProperties().setMinimizeEnabled(wi.isIconifiable());
461
                frame.getWindowProperties().setMaximizeEnabled(wi.isMaximizable());
462
                // try {
463
                // frame.setMaximum(wi.isMaximized());
464
                // } catch (PropertyVetoException e) {
465
                // TODO Auto-generated catch block
466
                // e.printStackTrace();
467
                // }
468
        }
469

    
470
        public IWindow addCentredWindow(IWindow iWindow)
471
                        throws SingletonDialogAlreadyShownException {
472
                // TODO Auto-generated method stub
473
                addWindow(iWindow);
474
                return iWindow;
475
        }
476

    
477
        /**
478
         * Situa un di?logo modal en el centro de la pantalla
479
         * 
480
         * @param d
481
         *            Di?logo que se quiere situar
482
         */
483
        private void centerDialog(JDialog d) {
484
                int offSetX = d.getWidth() / 2;
485
                int offSetY = d.getHeight() / 2;
486

    
487
                d.setLocation((mainFrame.getWidth() / 2) - offSetX, (mainFrame
488
                                .getHeight() / 2)
489
                                - offSetY);
490
        }
491

    
492
        public void changeWindowInfo(IWindow arg0, WindowInfo arg1) {
493
                // TODO Auto-generated method stub
494

    
495
        }
496

    
497
        public void closeAllWindows() {
498
                // TODO Auto-generated method stub
499
                System.out.println("cerrando todas");
500

    
501
                ArrayList eliminar = new ArrayList();
502
                Iterator i = dockWindowSupport.getWindowIterator();
503

    
504
                while (i.hasNext()) {
505
                        eliminar.add((IWindow) i.next());
506
                }
507

    
508
                for (Iterator iter = eliminar.iterator(); iter.hasNext();) {
509
                        IWindow vista = (IWindow) iter.next();
510
                        closeWindow(vista);
511
                }
512

    
513
        }
514

    
515
        public boolean closeSingletonWindow(Object model) {
516
                DockWindow[] frames = (DockWindow[]) singletonSupport.getFrames(model);
517
                if (frames.length == 0)
518
                        return false;
519
                for (int i = 0; i < frames.length; i++) {
520
                        closeDockWindow(frames[i]);
521
                }
522
                return true;
523
        }
524

    
525
        public boolean closeSingletonWindow(Class viewClass, Object model) {
526
                DockWindow frame = (DockWindow) singletonSupport.getFrame(viewClass,
527
                                model);
528
                if (frame == null)
529
                        return false;
530
                closeDockWindow(frame);
531
                return true;
532
        }
533

    
534
        private void closeDockWindow(DockWindow frame) {
535
                IWindow s = (IWindow) dockWindowSupport.getWindow(frame);
536

    
537
                frame.close();
538
                callWindowClosed(s);
539
        }
540

    
541
        private void callWindowClosed(IWindow window) {
542
                if (window instanceof IWindowListener) {
543
                        ((IWindowListener) window).windowClosed();
544
                }
545
        }
546

    
547
        public void closeWindow(IWindow iWindow) {
548

    
549
                if (iWindow.getWindowInfo().isModal()) {
550
                        closeJDialog();
551
                } else { // Si no es modal se cierra el JInternalFrame
552
                        closeDockWindow(dockWindowSupport.getDockWindow(iWindow));
553
                }
554

    
555
        }
556

    
557
        private void closeJDialog() {
558
                JDialog dlg = dialogStack.popDialog();
559
                if (dlg == null)
560
                        return;
561
                dlg.setVisible(false);
562

    
563
                // IWindow s = fws.getWindow(dlg);
564
                //
565
                // callWindowClosed(s);
566
                //
567
                // fws.closeWindow(s);
568
                //
569
                // // Si es singleton se desasocia el modelo con la vista
570
                // if (s instanceof SingletonWindow) {
571
                // sws.closeWindow((SingletonWindow) s);
572
                // }
573
        }
574

    
575
        public IWindow[] getAllWindows() {
576
                ArrayList windows = new ArrayList();
577
                Iterator i = dockWindowSupport.getWindowIterator();
578

    
579
                while (i.hasNext()) {
580
                        windows.add((IWindow) i.next());
581
                }
582
                return (IWindow[]) windows.toArray(new IWindow[0]);
583
        }
584

    
585
        public IWindow getActiveWindow() {
586
                // DockingWindow dw = rootWindow.getFocusedView();
587
                DockingWindow dw = null;
588
                if (dw == null)
589
                        dw = lastFocusedWindow;
590
                // System.err.println("GetfocusedView: " + dw);
591
                if (dw instanceof DockWindow) {
592
                        DockWindow view = (DockWindow) dw;
593
                        if (view != null) {
594
                                IWindow theWindow = dockWindowSupport.getWindow(view);
595
                                if (theWindow == null)
596
                                        return null;
597
                                if (theWindow.getWindowInfo().isPalette())
598
                                        return wss.getActiveWindow();
599
                                else
600
                                        return dockWindowSupport.getWindow(view);
601
                        }
602
                        // return vss.getActiveView();
603
                }
604

    
605
                return null;
606
        }
607

    
608
        public IWindow getFocusWindow() {
609
                // DockingWindow dw = rootWindow.getFocusedView();
610
                DockingWindow dw = null;
611
                if (dw == null)
612
                        dw = lastFocusedWindow;
613
                // System.err.println("GetfocusedView: " + dw);
614
                if (dw instanceof DockWindow) {
615
                        DockWindow view = (DockWindow) dw;
616
                        if (view != null) {
617
                                IWindow theView = dockWindowSupport.getWindow(view);
618
                                if (theView == null)
619
                                        return null;
620
                                // System.out.println("CAPA ACTIVA!!!!! " + view.getTitle());
621
                                return dockWindowSupport.getWindow(view);
622
                        }
623
                }
624
                return null;
625
        }
626

    
627
        public IWindow[] getOrderedWindows() {
628
                // TODO Auto-generated method stub
629
                return this.getAllWindows();
630
        }
631

    
632
        public WindowInfo getWindowInfo(IWindow iWindow) {
633
                // TODO Auto-generated method stub
634
                return this.wis.getWindowInfo(iWindow);
635
        }
636

    
637
        public void refresh(IWindow iWindow) {
638
                // TODO Auto-generated method stub
639
                rootWindow.invalidate();
640
        }
641

    
642
        public void restoreCursor() {
643
                // TODO Auto-generated method stub
644

    
645
        }
646

    
647
        public void setBackgroundImage(ImageIcon arg0, String arg1) {
648
                // TODO Auto-generated method stub
649

    
650
        }
651

    
652
        public void setMaximum(IWindow arg0, boolean arg1)
653
                        throws PropertyVetoException {
654
                // TODO Auto-generated method stub
655

    
656
        }
657

    
658
        public void setWaitCursor() {
659
                // TODO Auto-generated method stub
660

    
661
        }
662

    
663
        public void execute(String arg0) {
664
                // TODO Auto-generated method stub
665

    
666
        }
667

    
668
        public void initialize() {
669
                // TODO Auto-generated method stub
670

    
671
        }
672

    
673
        public boolean isEnabled() {
674
                // TODO Auto-generated method stub
675
                return false;
676
        }
677

    
678
        public boolean isVisible() {
679
                // TODO Auto-generated method stub
680
                return false;
681
        }
682

    
683
        private void callWindowActivated(IWindow window) {
684
                // logger.debug("View '" + window.getWindowInfo().getTitle()
685
                // + "' activated (callViewActivated)");
686
                if (window instanceof IWindowListener) {
687
                        ((IWindowListener) window).windowActivated();
688
                }
689
        }
690

    
691
        /**
692
         * Listener para los eventos de cerrado de los di?logos. Tiene su raz?n
693
         * de ser en que los di?logos han de devolverse al pool cuando se cierran
694
         * 
695
         * @author Fernando Gonz?lez Cort?s
696
         */
697
        public class DockDialogWindowListener extends WindowAdapter {
698
                /**
699
                 * Captura el evento de cerrado de los di?logos con el fin de realizar
700
                 * tareas de mantenimiento
701
                 * 
702
                 * @param e
703
                 *            evento
704
                 */
705
                public void windowActivated(WindowEvent e) {
706
                        IWindow window = dockWindowSupport.getWindow((Component) e
707
                                        .getSource());
708
                        callWindowActivated(window);
709
                }
710

    
711
                /**
712
                 * Captura el evento de cerrado de los di?logos con el fin de realizar
713
                 * tareas de mantenimiento
714
                 * 
715
                 * @param e
716
                 *            evento
717
                 */
718
                public void windowClosing(WindowEvent e) {
719
                        closeJDialog();
720
                }
721

    
722
        }
723

    
724
        /***************************************************************************
725
         * 
726
         * New listener to control de DockWindow events
727
         * 
728
         */
729

    
730
        private class DockWindowListener implements DockingWindowListener {
731

    
732
                public void viewFocusChanged(View arg0, View arg1) {
733
                        View view = arg0;
734
                        if (view instanceof DockWindow) {
735
                                DockWindow dockWindow = (DockWindow) view;
736
                                if (dockWindow == null)
737
                                        return;
738
                                WindowInfo wi = ((DockWindow) arg0).getIWindow()
739
                                                .getWindowInfo();
740

    
741
                                if (wi.isMaximizable()) {
742
                                        dockWindow.getWindowProperties().setMaximizeEnabled(true);
743
                                }
744

    
745
                                mainFrame.enableControls();
746
                                if (wi.getSelectedTools() == null) {
747
                                        // this is the first time this window is activated
748
                                        wi.setSelectedTools(new HashMap(mainFrame
749
                                                        .getInitialSelectedTools()));
750
                                }
751
                                mainFrame.setSelectedTools(wi.getSelectedTools());
752
                                callWindowActivated(dockWindow.getIWindow());
753
                                if (arg1 != null)
754
                                        lastFocusedWindow = (DockWindow) arg1;
755
                        }
756
                }
757

    
758
                public void windowAdded(DockingWindow arg0, DockingWindow arg1) {
759
                        mainFrame.enableControls();
760

    
761
                }
762

    
763
                public void windowClosed(DockingWindow view) {
764
                        if (view instanceof DockWindow) {
765
                                DockWindow dockWindow = (DockWindow) view;
766
                                WindowInfo wi = wis.getWindowInfo((IWindow) dockWindowSupport
767
                                                .getWindow(dockWindow));
768

    
769
                                IWindow win = dockWindowSupport.getWindow(dockWindow);
770
                                callWindowClosed(win);
771
                                boolean alwaysLive;
772
                                if (win instanceof SingletonWindow) {
773
                                        singletonSupport.closeWindow((SingletonWindow) win);
774
                                }
775

    
776
                                dockWindowSupport.closeWindow(win);
777

    
778
                                // panel.remove(c);
779

    
780
                                wss.remove(win);
781

    
782
                                if (!wi.isPalette())
783
                                        mainFrame.enableControls();
784
                        }
785
                        rootWindow.repaint();
786
                }
787

    
788
                public void windowClosing(DockingWindow view)
789
                                throws OperationAbortedException {
790

    
791
                }
792

    
793
                public void windowDocked(DockingWindow arg0) {
794
                        mainFrame.enableControls();
795

    
796
                }
797

    
798
                public void windowDocking(DockingWindow arg0)
799
                                throws OperationAbortedException {
800
                        // TODO Auto-generated method stub
801

    
802
                }
803

    
804
                public void windowHidden(DockingWindow arg0) {
805
                        mainFrame.enableControls();
806
                }
807

    
808
                public void windowMaximized(DockingWindow arg0) {
809
                        // TODO Auto-generated method stub
810

    
811
                        setProjectWindowVisible(!showProjectWindow);
812
                        mainFrame.enableControls();
813
                }
814

    
815
                public void windowMaximizing(DockingWindow arg0)
816
                                throws OperationAbortedException {
817
                        // TODO Auto-generated method stub
818

    
819
                        setProjectWindowVisible(!showProjectWindow);
820

    
821
                }
822

    
823
                public void windowMinimized(DockingWindow arg0) {
824
                        // TODO Auto-generated method stub
825
                        mainFrame.enableControls();
826

    
827
                }
828

    
829
                public void windowMinimizing(DockingWindow arg0)
830
                                throws OperationAbortedException {
831
                        // TODO Auto-generated method stub
832

    
833
                }
834

    
835
                public void windowRemoved(DockingWindow arg0, DockingWindow arg1) {
836
                        mainFrame.enableControls();
837

    
838
                }
839

    
840
                public void windowRestored(DockingWindow arg0) {
841
                        // TODO Auto-generated method stub
842
                        mainFrame.enableControls();
843
                }
844

    
845
                public void windowRestoring(DockingWindow arg0)
846
                                throws OperationAbortedException {
847
                        // TODO Auto-generated method stub
848

    
849
                }
850

    
851
                public void windowShown(DockingWindow arg0) {
852
                        // TODO Auto-generated method stub
853
                        mainFrame.enableControls();
854
                }
855

    
856
                public void windowUndocked(DockingWindow arg0) {
857
                        if (arg0.getTopLevelAncestor() instanceof JDialog) {
858
                                ((JDialog) arg0.getTopLevelAncestor())
859
                                                .addWindowListener(new FloatingWindowContainerListener(
860
                                                                arg0));
861
                        }
862
                        mainFrame.enableControls();
863

    
864
                }
865

    
866
                public void windowUndocking(DockingWindow arg0)
867
                                throws OperationAbortedException {
868
                        // TODO Auto-generated method stub
869

    
870
                }
871

    
872
        }
873

    
874
        private void setProjectWindowVisible(boolean show) {
875
                showProjectWindow = show;
876
                if (showProjectWindow) {
877
                        rootWindow.getWindowBar(Direction.LEFT).remove(projectWindow);
878
                        this.hiddeButton.setSelected(true);
879
                        rootWindow.validate();
880

    
881
                } else {
882
                        rootWindow.getWindowBar(Direction.LEFT).add(projectWindow);
883
                        this.projectButton.setSelected(true);
884
                        rootWindow.validate();
885
                }
886

    
887
        }
888

    
889
        public void actionPerformed(ActionEvent e) {
890
                showProjectWindow = !showProjectWindow;
891
                setProjectWindowVisible(showProjectWindow);
892

    
893
        }
894

    
895
        public boolean isShowProjectWindow() {
896
                return showProjectWindow;
897
        }
898

    
899
}