Statistics
| Revision:

root / trunk / libraries / libCorePlugin / src / com / iver / core / mdiManager / NewSkin.java @ 8284

History | View | Annotate | Download (29.8 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 com.iver.core.mdiManager;
42

    
43
import java.awt.BorderLayout;
44
import java.awt.Component;
45
import java.awt.Container;
46
import java.awt.Cursor;
47
import java.awt.Dimension;
48
import java.awt.KeyEventDispatcher;
49
import java.awt.Point;
50
import java.awt.Window;
51
import java.awt.event.ActionEvent;
52
import java.awt.event.ActionListener;
53
import java.awt.event.KeyEvent;
54
import java.awt.event.WindowAdapter;
55
import java.awt.event.WindowEvent;
56
import java.beans.PropertyVetoException;
57
import java.util.ArrayList;
58
import java.util.Collection;
59
import java.util.Iterator;
60
import java.util.TreeMap;
61

    
62
import javax.swing.DefaultDesktopManager;
63
import javax.swing.DesktopManager;
64
import javax.swing.JDesktopPane;
65
import javax.swing.JDialog;
66
import javax.swing.JFrame;
67
import javax.swing.JInternalFrame;
68
import javax.swing.JRootPane;
69
import javax.swing.KeyStroke;
70
import javax.swing.event.InternalFrameEvent;
71
import javax.swing.event.InternalFrameListener;
72

    
73
import org.apache.log4j.Logger;
74

    
75
import com.iver.andami.GlobalKeyEventDispatcher;
76
import com.iver.andami.Launcher;
77
import com.iver.andami.PluginServices;
78
import com.iver.andami.plugins.Extension;
79
import com.iver.andami.ui.mdiFrame.GlassPane;
80
import com.iver.andami.ui.mdiFrame.MDIFrame;
81
import com.iver.andami.ui.mdiFrame.NewStatusBar;
82
import com.iver.andami.ui.mdiManager.MDIManager;
83
import com.iver.andami.ui.mdiManager.MDIUtilities;
84
import com.iver.andami.ui.mdiManager.SingletonDialogAlreadyShownException;
85
import com.iver.andami.ui.mdiManager.SingletonWindow;
86
import com.iver.andami.ui.mdiManager.IWindow;
87
import com.iver.andami.ui.mdiManager.WindowInfo;
88
import com.iver.andami.ui.mdiManager.IWindowListener;
89
import com.iver.core.StatusBar;
90

    
91
/**
92
 *
93
 */
94
public class NewSkin extends Extension implements MDIManager{
95
        private static final int DefaultXMargin = 20; // Added for the method 'centreJInternalFrame'
96
        private static final int DefaultYMargin = 20; // Added for the method 'centreJInternalFrame'
97
        private static final int MinimumXMargin = 130; // Added for the method 'centreJInternalFrame'
98
        private static final int MinimumYMargin = 60; // Added for the method 'centreJInternalFrame'
99
        
100
        
101
    /**
102
     * Variable privada <code>desktopManager</code> para usarlo cuando sale
103
     * una ventana que no queremos que nos restaure las que tenemos maximizadas.
104
     * Justo antes de usar el setMaximize(false), le pegamos el cambiazo.
105
     */
106
    private static DesktopManager desktopManager = new DefaultDesktopManager();
107

    
108
    /** log */
109
    private static Logger logger = Logger.getLogger(NewSkin.class.getName());
110

    
111
    /** Panel de la MDIFrame */
112
    private JDesktopPane panel = new JDesktopPane();
113

    
114
    /** MDIFrame */
115
    private MDIFrame mainFrame;
116

    
117
    private GlassPane glassPane = new GlassPane();
118

    
119
    private DialogStackSupport dss;
120

    
121
    /**
122
     * Associates JInternalFrames with the IWindow they contain 
123
     */
124
    private FrameWindowSupport fws;
125

    
126
    private WindowInfoSupport vis;
127

    
128
    private WindowStackSupport wss;
129

    
130
    private SingletonWindowSupport sws;
131

    
132
    private Cursor lastCursor = null;
133

    
134
    /**
135
     * @see com.iver.andami.ui.mdiManager.MDIManager#init(com.iver.andami.ui.mdiFrame.MDIFrame)
136
     */
137
    public void init(MDIFrame f) {
138
        // Inicializa el Frame y la consola
139
        mainFrame = f;
140
        mainFrame.setGlassPane(glassPane);
141
        panel.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
142

    
143
        mainFrame.getContentPane().add(panel, BorderLayout.CENTER);
144
        panel.setDesktopManager(desktopManager);
145

    
146
        fws = new FrameWindowSupport(mainFrame);
147
        dss = new DialogStackSupport(mainFrame);
148
        sws = new SingletonWindowSupport(vis, fws);
149
        vis = new WindowInfoSupport(mainFrame, fws, sws);
150
        fws.setVis(vis);
151
        wss = new WindowStackSupport(vis);
152

    
153

    
154
        // TODO (jaume) esto no deber?a de estar aqu?...
155
        // molar?a m?s en un di?logo de preferencias
156
        // es s?lo una prueba
157
        KeyStroke controlTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_MASK);
158

    
159
        PluginServices.registerKeyStroke(controlTab, new KeyEventDispatcher() {
160

    
161
                        public boolean dispatchKeyEvent(KeyEvent e) {
162
                                IWindow[] views = getAllWindows();
163
                                if (views.length<=0 || e.getID() == KeyEvent.KEY_PRESSED)
164
                                        return false;
165

    
166

    
167
                                int current = 0;
168
                                for (int i = 0; i < views.length; i++) {
169
                                        if (views[i].equals(getActiveWindow())) {
170
                                                current = i;
171
                                                break;
172
                                        }
173
                                }
174
                                addWindow(views[(current +1) % views.length]);
175
                                return true;
176
                        }
177

    
178
        });
179
    }
180

    
181
    /**
182
     * @see com.iver.andami.ui.mdiManager.MDIManager#addWindow(com.iver.andami.ui.mdiManager.IWindow)
183
     */
184
    public IWindow addWindow(IWindow p) throws SingletonDialogAlreadyShownException {
185
        // se obtiene la informaci?n de la vista
186
        WindowInfo wi = vis.getWindowInfo(p);
187

    
188
        // Se comprueban las incompatibilidades que pudieran haber en la vista
189
        MDIUtilities.checkWindowInfo(wi);
190
        if ((p instanceof SingletonWindow) && (wi.isModal())) {
191
            throw new RuntimeException("A modal view cannot be a SingletonView");
192
        }
193

    
194
        /*
195
         * Se obtiene la referencia a la vista anterior por si es una singleton
196
         * y est? siendo mostrada. Se obtiene su informaci?n si ya fue mostrada
197
         */
198
        boolean singletonPreviouslyAdded = false;
199

    
200
        if (p instanceof SingletonWindow) {
201
            SingletonWindow sw = (SingletonWindow) p;
202
            if (sws.registerWindow(sw.getClass(), sw.getWindowModel(), wi)) {
203
                singletonPreviouslyAdded = true;
204
            }
205
        }
206

    
207
        if (singletonPreviouslyAdded) {
208
            // Si la vista no est? actualmente abierta
209
            if (!sws.contains((SingletonWindow) p)) {
210
                JInternalFrame frame = fws.getJInternalFrame(p);
211
                sws.openSingletonWindow((SingletonWindow) p, frame);
212
                addJInternalFrame(frame, wi);
213
                wss.add(p, new ActionListener() {
214
                    public void actionPerformed(ActionEvent e) {
215
                        IWindow v = vis.getWindowById(Integer.parseInt(e
216
                                .getActionCommand()));
217
                        JInternalFrame f = fws.getJInternalFrame(v);
218
                        activateJInternalFrame(f);
219
                    }
220
                });
221
                return p;
222
            } else {
223
                // La vista est? actualmente abierta
224
                JInternalFrame frame = (JInternalFrame) sws
225
                        .getFrame((SingletonWindow) p);
226
                activateJInternalFrame(frame);
227
                wss.setActive(p);
228
                return fws.getWindow((JInternalFrame) frame);
229
            }
230
        } else {
231
            if (wi.isModal()) {
232
                addJDialog(p);
233
            } else {
234
                // Se sit?a la vista en la pila de vistas
235
                wss.add(p, new ActionListener() {
236
                    public void actionPerformed(ActionEvent e) {
237
                        IWindow v = vis.getWindowById(Integer.parseInt(e
238
                                .getActionCommand()));
239
                        JInternalFrame f = fws.getJInternalFrame(v);
240
                        activateJInternalFrame(f);
241
                    }
242
                });
243
                addJInternalFrame(p);
244
            }
245

    
246
            return p;
247
        }
248
    }
249
    
250
    /**
251
     * Similar method as 'addView' but in this case centres the new JInternalFrame of the View in the contentPane of the MainFrame
252
     * 
253
     * @see com.iver.core.mdiManager.NewSkin#addWindow(com.iver.andami.ui.mdiManager.IWindow)
254
     * 
255
     * @author Pablo Piqueras Bartolom?
256
     */
257
        public IWindow addCentredWindow(IWindow p) throws SingletonDialogAlreadyShownException {
258
            // se obtiene la informaci?n de la vista
259
        WindowInfo vi = vis.getWindowInfo(p);
260

    
261
        // Se comprueban las incompatibilidades que pudieran haber en la vista
262
        MDIUtilities.checkWindowInfo(vi);
263
        if ((p instanceof SingletonWindow) && (vi.isModal())) {
264
            throw new RuntimeException("A modal view cannot be a SingletonView");
265
        }
266

    
267
        /*
268
         * Se obtiene la referencia a la vista anterior por si es una singleton
269
         * y est? siendo mostrada. Se obtiene su informaci?n si ya fue mostrada
270
         */
271
        boolean singletonPreviouslyAdded = false;
272

    
273
        if (p instanceof SingletonWindow) {
274
            SingletonWindow sv = (SingletonWindow) p;
275
            if (sws.registerWindow(sv.getClass(), sv.getWindowModel(), vis
276
                    .getWindowInfo(sv))) {
277
                singletonPreviouslyAdded = true;
278
            }
279
        }        
280
      
281
        if (singletonPreviouslyAdded) {
282
            // Si la vista no est? actualmente abierta
283
            if (!sws.contains((SingletonWindow) p)) {
284
                JInternalFrame frame = fws.getJInternalFrame(p);
285
                sws.openSingletonWindow((SingletonWindow) p, frame);
286
                addJInternalFrame(frame, vi);
287
                wss.add(p, new ActionListener() {
288
                    public void actionPerformed(ActionEvent e) {
289
                        IWindow w = vis.getWindowById(Integer.parseInt(e
290
                                .getActionCommand()));
291
                        JInternalFrame f = fws.getJInternalFrame(w);
292
                        centreJInternalFrame(f); // Centre this JInternalFrame
293
                        activateJInternalFrame(f);
294
                    }
295
                });
296
                return p;
297
            } else {
298
                // La vista est? actualmente abierta
299
                JInternalFrame frame = (JInternalFrame) sws
300
                        .getFrame((SingletonWindow) p);
301
                activateJInternalFrame(frame);
302
                centreJInternalFrame(frame); // Centre this JInternalFrame
303
                wss.setActive(p);
304
                return fws.getWindow((JInternalFrame) frame);
305
            }
306
        } else {
307
                centreJInternalFrame(fws.getJInternalFrame(p)); // Centre this JInternalFrame 
308
            if (vi.isModal()) {
309
                addJDialog(p);
310
            } else {
311
                // Se sit?a la vista en la pila de vistas
312
                wss.add(p, new ActionListener() {
313
                    public void actionPerformed(ActionEvent e) {
314
                        IWindow w = vis.getWindowById(Integer.parseInt(e
315
                                .getActionCommand()));
316
                        JInternalFrame f = fws.getJInternalFrame(w);                        
317
                        activateJInternalFrame(f);
318
                    }
319
                });
320
                addJInternalFrame(p);
321
            }
322

    
323
            return p;
324
        }
325
        }
326
        
327
        /**
328
         * Centres the JInternalFrame in the center of the contentPane of the MainFrame
329
         * If it can't be showed completely the JInternalFrame, tries that the top-left corner of the JInternalFrame would be showed
330
         * 
331
         * @author Pablo Piqueras Bartolom?
332
         * 
333
         * @param jInternalFrame A reference to the frame to centring
334
         */
335
        private static synchronized void centreJInternalFrame(JInternalFrame jInternalFrame) {
336
                
337
                // The top-left square of frame reference
338
                Point newReferencePoint = new Point();
339
                
340
                // A reference to the panel where the JInternalFrame will be displayed
341
                Container contentPane = ((JFrame)PluginServices.getMainFrame()).getContentPane();
342
                
343
                // Get the NewStatusBar component
344
                NewStatusBar newStatusBar = ((NewStatusBar)contentPane.getComponent(1));
345
                JDesktopPane jDesktopPane = ((JDesktopPane)contentPane.getComponent(2));
346
                
347
                int visibleWidth = contentPane.getWidth() - contentPane.getX(); // The last substraction is for if there is any menu,... at left
348
                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
349
                int freeWidth = visibleWidth - jInternalFrame.getWidth();
350
                int freeHeight = visibleHeight - jInternalFrame.getHeight();
351

    
352
                // Calculate the new point reference (Assure that the top-left corner is showed)
353
                if (freeWidth < 0)
354
                {
355
                        if (visibleWidth > MinimumXMargin)
356
                                newReferencePoint.x = DefaultXMargin;
357
                        else
358
                                newReferencePoint.x = 0;
359
                }
360
                else
361
                        newReferencePoint.x = freeWidth / 2;
362
                        
363
                if (freeHeight < 0)
364
                {
365
                        if (visibleHeight > MinimumYMargin)
366
                                newReferencePoint.y = DefaultYMargin;
367
                        else
368
                                newReferencePoint.y = 0;
369
                }
370
                else
371
                        newReferencePoint.y = freeHeight / 2;
372

    
373
                // Set the new location for this JInternalFrame
374
                jInternalFrame.setLocation(newReferencePoint);
375
        }
376
        
377
        
378
    /**
379
     * DOCUMENT ME!
380
     *
381
     * @param wnd
382
     *            DOCUMENT ME!
383
     * @param wi
384
     *            DOCUMENT ME!
385
     */
386
    private void addJInternalFrame(JInternalFrame wnd, WindowInfo wi) {
387
        wnd.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
388
        wnd.addInternalFrameListener(new FrameListener());
389
        updateFrameProperties(wnd, wi);
390
        
391
        if (wi.isModeless() || wi.isPalette()) {
392
            panel.add(wnd, JDesktopPane.PALETTE_LAYER);
393
            if (wi.isPalette())
394
                wnd.setFocusable(false);
395
        } else {
396
            panel.add(wnd);
397
        }
398

    
399
        activateJInternalFrame(wnd);
400
        try{
401
                wnd.setMaximum(wi.isMaximized());
402
        }catch(Exception ex){
403
                logger.warn("Error: ", ex);
404
        }
405
    }
406

    
407
    private void updateFrameProperties(JInternalFrame frame, WindowInfo wi) {
408
            frame.setSize(wi.getWidth(), wi.getHeight());
409
            frame.setTitle(wi.getTitle());
410
            frame.setVisible(wi.isVisible());
411
            frame.setResizable(wi.isResizable());
412
            frame.setIconifiable(wi.isIconifiable());
413
            frame.setMaximizable(wi.isMaximizable());
414
            frame.setLocation(wi.getX(), wi.getY());
415
            frame.setNormalBounds(wi.getNormalBounds());
416
            try {
417
                        frame.setMaximum(wi.isMaximized());
418
                } catch (PropertyVetoException e) {
419
                        // TODO Auto-generated catch block
420
                        //e.printStackTrace();
421
                }
422
    }
423
    
424
    /**
425
     * DOCUMENT ME!
426
     *
427
     * @param p
428
     */
429
    private void addJInternalFrame(IWindow p) {
430
        WindowInfo wi = vis.getWindowInfo(p);
431

    
432
        JInternalFrame wnd = fws.getJInternalFrame(p);
433

    
434
        if (p instanceof SingletonWindow) {
435
            SingletonWindow sv = (SingletonWindow) p;
436
            sws.openSingletonWindow(sv, wnd);
437
        }
438

    
439
        addJInternalFrame(wnd, wi);
440
    }
441

    
442
    /**
443
     * DOCUMENT ME!
444
     *
445
     * @param wnd
446
     */
447
    private void activateJInternalFrame(JInternalFrame wnd) {
448
        try {
449
            wnd.moveToFront();
450
            logger.debug("Activando " + wnd.getTitle());
451
            wnd.setSelected(true);
452
            wnd.setIcon(false);
453
        } catch (PropertyVetoException e) {
454
            logger.error(e);
455
        }
456
    }
457

    
458
    /**
459
     * Situa un di?logo modal en el centro de la pantalla
460
     *
461
     * @param d
462
     *            Di?logo que se quiere situar
463
     */
464
    private void centerDialog(JDialog d) {
465
        int offSetX = d.getWidth() / 2;
466
        int offSetY = d.getHeight() / 2;
467

    
468
        d.setLocation((mainFrame.getWidth() / 2) - offSetX, (mainFrame
469
                .getHeight() / 2)
470
                - offSetY);
471
    }
472

    
473
    /**
474
     * DOCUMENT ME!
475
     *
476
     * @param p
477
     */
478
    private void addJDialog(IWindow p) {
479
        JDialog dlg = fws.getJDialog(p);
480

    
481
        centerDialog(dlg);
482

    
483
        dlg.addWindowListener(new DialogWindowListener());
484
        dss.pushDialog(dlg);
485

    
486
        dlg.setVisible(vis.getWindowInfo(p).isVisible());
487
    }
488

    
489
    /**
490
     * @see com.iver.andami.ui.mdiManager.MDIManager#getActiveWindow()
491
     */
492
    public IWindow getActiveWindow() {
493
        JInternalFrame jif = panel.getSelectedFrame();
494

    
495
        if (jif != null) {
496
            IWindow theWindow = fws.getWindow(jif);
497
            if (theWindow == null)
498
                return null;
499
            if (theWindow.getWindowInfo().isPalette())
500
                return wss.getActiveWindow();
501
            else
502
                return fws.getWindow(jif);
503
        }
504
        // return vss.getActiveView();
505

    
506
        return null;
507
    }
508
    public IWindow getFocusWindow(){
509
             JInternalFrame jif = panel.getSelectedFrame();
510

    
511
         if (jif != null) {
512
             IWindow theView = fws.getWindow(jif);
513
             if (theView == null)
514
                 return null;
515
             return fws.getWindow(jif);
516
         }
517
         return null;
518
    }
519
    /**
520
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeWindow(com.iver.andami.ui.mdiManager.IWindow)
521
     */
522
    public void closeWindow(IWindow p) {
523
        // Si es un di?logo modal
524
        if (p.getWindowInfo().isModal()) {
525
            closeJDialog();
526
        } else { // Si no es modal se cierra el JInternalFrame
527
            closeJInternalFrame(fws.getJInternalFrame(p));
528
        }
529
    }
530

    
531
    /**
532
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeAllWindows()
533
     */
534
    public void closeAllWindows() {
535
        ArrayList eliminar = new ArrayList();
536
        Iterator i = fws.getWindowIterator();
537

    
538
        while (i.hasNext()) {
539
            eliminar.add((IWindow) i.next());
540
        }
541

    
542
        for (Iterator iter = eliminar.iterator(); iter.hasNext();) {
543
            IWindow vista = (IWindow) iter.next();
544
            closeWindow(vista);
545
        }
546
    }
547

    
548
    /**
549
     * @see com.iver.andami.ui.mdiManager.MDIManager#getWindowInfo(com.iver.andami.ui.mdiManager.IWindow)
550
     */
551
    public WindowInfo getWindowInfo(IWindow w) {
552
            WindowInfo wi = vis.getWindowInfo(w);
553
            
554
            JInternalFrame f = fws.getJInternalFrame(w);
555
            wi.setX(f.getX());
556
            wi.setY(f.getY());
557
            wi.setHeight(f.getHeight());
558
            wi.setWidth(f.getWidth());
559
            // isClosed() doesn't work as (I) expected, why? Using isShowing instead
560
            wi.setClosed(!f.isShowing());
561
            wi.setNormalBounds(f.getNormalBounds());
562
            wi.setMaximized(f.isMaximum());
563
            return wi;
564
    }
565

    
566
    /**
567
     * DOCUMENT ME!
568
     *
569
     * @param dialog
570
     * @throws RuntimeException
571
     *             DOCUMENT ME!
572
     */
573
    private void closeJDialog() {
574
        JDialog dlg = dss.popDialog();
575

    
576
        dlg.setVisible(false);
577

    
578
        IWindow s = (IWindow) fws.getWindow(dlg);
579

    
580
        callWindowClosed(s);
581

    
582
        fws.closeWindow(s);
583

    
584
        // Si es singleton se desasocia el modelo con la vista
585
        if (s instanceof SingletonWindow) {
586
            sws.closeWindow((SingletonWindow) s);
587
        }
588
    }
589

    
590
    /**
591
     * DOCUMENT ME!
592
     *
593
     * @param window
594
     *            DOCUMENT ME!
595
     */
596
    private void callWindowClosed(IWindow window) {
597
        if (window instanceof IWindowListener) {
598
            ((IWindowListener) window).windowClosed();
599
        }
600
    }
601

    
602
    /**
603
     * DOCUMENT ME!
604
     *
605
     * @param window
606
     *            DOCUMENT ME!
607
     */
608
    private void callWindowActivated(IWindow window) {
609
        logger.debug("View " + window.getWindowInfo().getTitle()
610
                + " activated (callViewActivated)");
611
        if (window instanceof IWindowListener) {
612
            ((IWindowListener) window).windowActivated();
613
        }
614
    }
615

    
616
    /**
617
     * DOCUMENT ME!
618
     *
619
     * @param frame
620
     */
621
    private void closeJInternalFrame(JInternalFrame frame) {
622
        try {
623
            IWindow s = (IWindow) fws.getWindow(frame);
624

    
625
            frame.setClosed(true);
626
            callWindowClosed(s);
627
        } catch (PropertyVetoException e) {
628
            logger
629
                    .error(
630
                            "Not compatible with property veto's. Use ViewInfo instead.",
631
                            e);
632
        }
633
    }
634

    
635
    /**
636
     * @see com.iver.andami.plugins.IExtension#initialize()
637
     */
638
    public void initialize() {
639
    }
640

    
641
    /**
642
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
643
     */
644
    public void execute(String actionCommand) {
645
        if (actionCommand.equals("cascada")) {
646
        } else if (actionCommand.equals("mosaico")) {
647
        }
648
    }
649

    
650
    /**
651
     * @see com.iver.andami.plugins.IExtension#isEnabled()
652
     */
653
    public boolean isEnabled() {
654
        // TODO Auto-generated method stub
655
        return false;
656
    }
657

    
658
    /**
659
     * @see com.iver.andami.plugins.IExtension#isVisible()
660
     */
661
    public boolean isVisible() {
662
        // TODO Auto-generated method stub
663
        return true;
664
    }
665

    
666
    /**
667
     * @see com.iver.andami.ui.mdiManager.MDIManager#setWaitCursor()
668
     */
669
    public void setWaitCursor() {
670
        if (mainFrame != null) {
671
            glassPane.setVisible(true);
672
            lastCursor = mainFrame.getCursor();
673
            dss.setWaitCursor();
674
            glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
675
        }
676
    }
677

    
678
    /**
679
     * @see com.iver.andami.ui.mdiManager.MDIManager#restoreCursor()
680
     */
681
    public void restoreCursor() {
682
        if (mainFrame != null) {
683
            glassPane.setVisible(false);
684
            dss.restoreCursor();
685
            glassPane.setCursor(lastCursor);
686
        }
687
    }
688

    
689
    /**
690
     * Listener para los eventos de cerrado de los di?logos. Tiene su raz?n de
691
     * ser en que los di?logos han de devolverse al pool cuando se cierran
692
     *
693
     * @author Fernando Gonz?lez Cort?s
694
     */
695
    public class DialogWindowListener extends WindowAdapter {
696
        /**
697
         * Captura el evento de cerrado de los di?logos con el fin de realizar
698
         * tareas de mantenimiento
699
         *
700
         * @param e
701
         *            evento
702
         */
703
        public void windowClosing(WindowEvent e) {
704
            closeJDialog();
705
        }
706
    }
707

    
708
    /**
709
     * DOCUMENT ME!
710
     */
711
    public class FrameListener implements InternalFrameListener {
712
        /**
713
         * @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent)
714
         */
715
        public void internalFrameActivated(InternalFrameEvent e) {
716
            // logger.debug("internalFrameActivated " +
717
            // e.getInternalFrame().getTitle());
718

    
719
            // activatedInternalFramesStack.push(e.getInternalFrame());
720

    
721
            IWindow panel = fws.getWindow((JInternalFrame) e.getSource());
722

    
723
            WindowInfo wi = vis.getWindowInfo(panel);
724
            if (wi.isPalette())
725
                return;
726

    
727
            wss.setActive(panel);
728

    
729
            JInternalFrame frame = fws.getJInternalFrame(panel);
730
            
731
            if (wi.isMaximizable()){
732
                    frame.setMaximizable(true);
733
            }
734
            if (!frame.isMaximizable() && frame.isMaximum()) {
735
                try {
736
                    frame.setMaximum(false);
737
                } catch (PropertyVetoException e1) {
738
                }
739
            }            
740
            mainFrame.enableControls();
741
            if (wi.getSelectedTool() != null)
742
                mainFrame.setSelectedTool(wi.getSelectedTool());
743
            callWindowActivated(panel);
744

    
745
        }
746

    
747
        /**
748
         * @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
749
         */
750
        public void internalFrameClosed(InternalFrameEvent e) {
751
        }
752

    
753
        /**
754
         * @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent)
755
         */
756
        public void internalFrameClosing(InternalFrameEvent e) {
757
            // Se elimina la memoria del JInternalFrame si no es ALWAYS_LIVE
758
            // logger.debug("internalFrameClosing " +
759
            // e.getInternalFrame().getTitle());
760

    
761
            JInternalFrame c = (JInternalFrame) e.getSource();
762
            WindowInfo wi = vis.getWindowInfo((IWindow) fws.getWindow(c));
763

    
764
            IWindow win = fws.getWindow(c);
765
            callWindowClosed(win);
766
            boolean alwaysLive;
767
            if (win instanceof SingletonWindow) {
768
                sws.closeWindow((SingletonWindow) win);
769
            }
770

    
771
            fws.closeWindow(win);
772

    
773
            panel.remove(c);
774

    
775
            wss.remove(win);
776

    
777
            if (!wi.isPalette())
778
                mainFrame.enableControls();
779
            panel.repaint();
780

    
781
            // Para activar el JInternalFrame desde la que hemos
782
            // abierto la ventana que estamos cerrando
783
            IWindow lastWindow = wss.getActiveWindow();
784
            // La activamos
785
            if (lastWindow != null) {
786
                    logger.debug(PluginServices.getText(this, "Devuelvo_el_foco_a_")+lastWindow.getWindowInfo().getTitle());
787
                JInternalFrame frame = fws.getJInternalFrame(lastWindow);
788
                try {
789
                    frame.setSelected(true);
790
                } catch (PropertyVetoException e1) {
791
                    // TODO Auto-generated catch block
792
                    // e1.printStackTrace();
793
                }
794
                // addView(lastView);
795
            }
796

    
797
        }
798

    
799
        /**
800
         * @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent)
801
         */
802
        public void internalFrameDeactivated(InternalFrameEvent e) {
803
            // logger.debug("internalDeActivated " +
804
            // e.getInternalFrame().getTitle());
805
            JInternalFrame c = (JInternalFrame) e.getSource();
806
            IWindow win = fws.getWindow(c);
807
            if (win != null) {
808
                WindowInfo wi = vis.getWindowInfo(win);
809
                if (wi.isPalette())
810
                    return;
811
                wi.setSelectedTool(mainFrame.getSelectedTool());
812
            }
813

    
814
        }
815

    
816
        /**
817
         * @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
818
         */
819
        public void internalFrameDeiconified(InternalFrameEvent e) {
820
            mainFrame.enableControls();
821
        }
822

    
823
        /**
824
         * @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
825
         */
826
        public void internalFrameIconified(InternalFrameEvent e) {
827
            mainFrame.enableControls();
828
        }
829

    
830
        /**
831
         * @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent)
832
         */
833
        public void internalFrameOpened(InternalFrameEvent e) {
834
            // logger.debug("internalFrameOpened. Source= " +
835
            // e.getSource().toString());
836
        }
837
    }
838

    
839
    /**
840
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Class,
841
     *      java.lang.Object)
842
     */
843
    public boolean closeSingletonWindow(Class viewClass, Object model) {
844
        JInternalFrame frame = sws.getFrame(viewClass, model);
845
        if (frame == null)
846
            return false;
847
        closeJInternalFrame(frame);
848
        return true;
849
    }
850

    
851
    /**
852
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Object)
853
     */
854
    public boolean closeSingletonWindow(Object model) {
855
        JInternalFrame[] frames = sws.getFrames(model);
856
        if (frames.length == 0)
857
            return false;
858
        for (int i = 0; i < frames.length; i++) {
859
            closeJInternalFrame(frames[i]);
860
        }
861
        return true;
862
    }
863

    
864
    /**
865
     * @see com.iver.andami.ui.mdiManager.MDIManager#getAllWindows()
866
     */
867
    public IWindow[] getAllWindows() {
868
        ArrayList windows = new ArrayList();
869
        Iterator i = fws.getWindowIterator();
870

    
871
        while (i.hasNext()) {
872
            windows.add((IWindow) i.next());
873
        }
874
        return (IWindow[]) windows.toArray(new IWindow[0]);
875
    }
876
    
877
    public IWindow[] getOrderedWindows() {
878
        //ArrayList windows = new ArrayList();
879
        TreeMap windows = new TreeMap();
880
        Iterator winIterator = fws.getWindowIterator();       
881
        
882
        JInternalFrame frame;
883
        IWindow win;
884
        /**
885
         * The order of the window in the JDesktopPane. Smaller numbers
886
         * are closer to the foreground.
887
         */
888
        int zPosition;
889
        while (winIterator.hasNext()) {
890
                win = (IWindow) winIterator.next();
891
                frame = fws.getJInternalFrame(win);
892
                
893
                zPosition = panel.getPosition(frame);
894
                windows.put(new Integer(zPosition), win);
895
        }
896
        winIterator = windows.values().iterator();
897
        ArrayList winList = new ArrayList();
898
        while (winIterator.hasNext()) {
899
                winList.add(winIterator.next());
900
        }
901

    
902
        return (IWindow[]) winList.toArray(new IWindow[0]);
903
    }
904

    
905
    public void setMaximum(IWindow v, boolean bMaximum) throws PropertyVetoException
906
    {
907
        JInternalFrame f = fws.getJInternalFrame(v);
908
        f.setMaximum(bMaximum);
909
    }
910

    
911
    public void changeWindowInfo(IWindow w, WindowInfo wi){
912
            JInternalFrame f = fws.getJInternalFrame(w);
913
                f.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
914
                JDesktopPane pnl = f.getDesktopPane();
915
                pnl.remove(f);
916
                f.setSize(new Dimension(wi.getWidth(),wi.getHeight()));
917
                f.setLocation(wi.getX(), wi.getY());
918
                if (wi.isPalette()) {
919
                        pnl.add(f, JDesktopPane.PALETTE_LAYER);
920
                        f.setFocusable(false);
921
                } else {
922
                        pnl.add(f, JDesktopPane.DEFAULT_LAYER);
923
                        f.setFocusable(true);
924
                        if (wi.isClosed()) {
925
                                closeWindow(w);
926
                        }
927
                }
928

    
929
                if (wi.isMaximized()) {
930
                        try {
931
                                f.setMaximum(true);
932
                        } catch (PropertyVetoException e) {
933
                                // TODO Auto-generated catch block
934
                                //e.printStackTrace();
935
                        }
936
                        f.setNormalBounds(wi.getNormalBounds());
937
                }
938
                activateJInternalFrame(f);
939
   }
940

    
941
}