Statistics
| Revision:

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

History | View | Annotate | Download (30.5 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.event.ActionEvent;
51
import java.awt.event.ActionListener;
52
import java.awt.event.KeyEvent;
53
import java.awt.event.WindowAdapter;
54
import java.awt.event.WindowEvent;
55
import java.beans.PropertyVetoException;
56
import java.util.ArrayList;
57
import java.util.Iterator;
58
import java.util.TreeMap;
59

    
60
import javax.swing.DefaultDesktopManager;
61
import javax.swing.DesktopManager;
62
import javax.swing.JDesktopPane;
63
import javax.swing.JDialog;
64
import javax.swing.JFrame;
65
import javax.swing.JInternalFrame;
66
import javax.swing.KeyStroke;
67
import javax.swing.event.InternalFrameEvent;
68
import javax.swing.event.InternalFrameListener;
69

    
70
import org.apache.log4j.Logger;
71

    
72
import com.iver.andami.PluginServices;
73
import com.iver.andami.plugins.Extension;
74
import com.iver.andami.ui.mdiFrame.GlassPane;
75
import com.iver.andami.ui.mdiFrame.MDIFrame;
76
import com.iver.andami.ui.mdiFrame.NewStatusBar;
77
import com.iver.andami.ui.mdiManager.IWindow;
78
import com.iver.andami.ui.mdiManager.IWindowListener;
79
import com.iver.andami.ui.mdiManager.MDIManager;
80
import com.iver.andami.ui.mdiManager.MDIUtilities;
81
import com.iver.andami.ui.mdiManager.SingletonDialogAlreadyShownException;
82
import com.iver.andami.ui.mdiManager.SingletonWindow;
83
import com.iver.andami.ui.mdiManager.WindowInfo;
84

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

    
102
    /** log */
103
    private static Logger logger = Logger.getLogger(NewSkin.class.getName());
104

    
105
    /** Panel de la MDIFrame */
106
    private JDesktopPane panel = new JDesktopPane();
107

    
108
    /** MDIFrame */
109
    private MDIFrame mainFrame;
110

    
111
    private GlassPane glassPane = new GlassPane();
112

    
113
    private DialogStackSupport dss;
114

    
115
    /**
116
     * Associates JInternalFrames with the IWindow they contain 
117
     */
118
    private FrameWindowSupport fws;
119

    
120
    private WindowInfoSupport wis;
121

    
122
    private WindowStackSupport wss;
123

    
124
    private SingletonWindowSupport sws;
125

    
126
    private Cursor lastCursor = null;
127

    
128
    /**
129
     * @see com.iver.andami.ui.mdiManager.MDIManager#init(com.iver.andami.ui.mdiFrame.MDIFrame)
130
     */
131
    public void init(MDIFrame f) {
132
        // Inicializa el Frame y la consola
133
        mainFrame = f;
134
        mainFrame.setGlassPane(glassPane);
135
        panel.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
136

    
137
        mainFrame.getContentPane().add(panel, BorderLayout.CENTER);
138
        panel.setDesktopManager(desktopManager);
139

    
140
        fws = new FrameWindowSupport(mainFrame);
141
        dss = new DialogStackSupport(mainFrame);
142
        sws = new SingletonWindowSupport(wis, fws);
143
        wis = new WindowInfoSupport(mainFrame, fws, sws);
144
        fws.setVis(wis);
145
        wss = new WindowStackSupport(wis);
146

    
147

    
148
        // TODO (jaume) esto no deber?a de estar aqu?...
149
        // molar?a m?s en un di?logo de preferencias
150
        // es s?lo una prueba
151
        KeyStroke controlTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_MASK);
152

    
153
        PluginServices.registerKeyStroke(controlTab, new KeyEventDispatcher() {
154

    
155
                        public boolean dispatchKeyEvent(KeyEvent e) {
156
                                IWindow[] views = getAllWindows();
157
                                if (views.length<=0 || e.getID() == KeyEvent.KEY_PRESSED)
158
                                        return false;
159

    
160

    
161
                                int current = 0;
162
                                for (int i = 0; i < views.length; i++) {
163
                                        if (views[i].equals(getActiveWindow())) {
164
                                                current = i;
165
                                                break;
166
                                        }
167
                                }
168
                                addWindow(views[(current +1) % views.length]);
169
                                return true;
170
                        }
171

    
172
        });
173
    }
174

    
175
    /**
176
     * @see com.iver.andami.ui.mdiManager.MDIManager#addWindow(com.iver.andami.ui.mdiManager.IWindow)
177
     */
178
    public IWindow addWindow(IWindow p) throws SingletonDialogAlreadyShownException {
179
        // se obtiene la informaci?n de la vista
180
        WindowInfo wi = wis.getWindowInfo(p);
181

    
182
        // Se comprueban las incompatibilidades que pudieran haber en la vista
183
        MDIUtilities.checkWindowInfo(wi);
184
        if ((p instanceof SingletonWindow) && (wi.isModal())) {
185
            throw new RuntimeException("A modal view cannot be a SingletonView");
186
        }
187

    
188
        /*
189
         * Se obtiene la referencia a la vista anterior por si es una singleton
190
         * y est? siendo mostrada. Se obtiene su informaci?n si ya fue mostrada
191
         */
192
        boolean singletonPreviouslyAdded = false;
193

    
194
        if (p instanceof SingletonWindow) {
195
            SingletonWindow sw = (SingletonWindow) p;
196
            if (sws.registerWindow(sw.getClass(), sw.getWindowModel(), wi)) {
197
                singletonPreviouslyAdded = true;
198
            }
199
        }
200

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

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

    
255
        // Se comprueban las incompatibilidades que pudieran haber en la vista
256
        MDIUtilities.checkWindowInfo(vi);
257
        if ((p instanceof SingletonWindow) && (vi.isModal())) {
258
            throw new RuntimeException("A modal view cannot be a SingletonView");
259
        }
260

    
261
        /*
262
         * Se obtiene la referencia a la vista anterior por si es una singleton
263
         * y est? siendo mostrada. Se obtiene su informaci?n si ya fue mostrada
264
         */
265
        boolean singletonPreviouslyAdded = false;
266

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

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

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

    
367
                // Set the new location for this JInternalFrame
368
                jInternalFrame.setLocation(newReferencePoint);
369
        }
370
        
371
        
372
    /**
373
     * DOCUMENT ME!
374
     *
375
     * @param wnd
376
     *            DOCUMENT ME!
377
     * @param wi
378
     *            DOCUMENT ME!
379
     */
380
    private void addJInternalFrame(JInternalFrame wnd, WindowInfo wi) {
381
        wnd.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
382
        wnd.addInternalFrameListener(new FrameListener());
383
        
384
        if (wi.isModeless() || wi.isPalette()) {
385
            panel.add(wnd, JDesktopPane.PALETTE_LAYER);
386
            if (wi.isPalette())
387
                wnd.setFocusable(false);
388
        } else {
389
            panel.add(wnd);
390
        }
391
        updateFrameProperties(wnd, wi);
392
        
393
        activateJInternalFrame(wnd);
394
        try{
395
                wnd.setMaximum(wi.isMaximized());
396
        }catch(Exception ex){
397
                logger.warn("Error: ", ex);
398
        }
399
    }
400

    
401
    private void updateFrameProperties(JInternalFrame frame, WindowInfo wi) {
402
            int height, width;
403
            if (wi.isMaximized()) {
404
                    if (wi.getNormalWidth()!=-1)
405
                            width = wi.getNormalWidth();
406
                    else
407
                            width = frame.getNormalBounds().width;
408
                    if (wi.getNormalHeight()!=-1)
409
                            height = wi.getNormalHeight();
410
                    else
411
                            height = frame.getNormalBounds().height;
412
                    
413
                    frame.setSize(width, height);
414
                    frame.setLocation(wi.getNormalX(), wi.getNormalY());
415
            }
416
            else {
417
                    if (wi.getWidth()!=-1)
418
                            width = wi.getWidth();
419
                    else
420
                            width = frame.getWidth();
421
                    if (wi.getHeight()!=-1)
422
                            height = wi.getHeight();
423
                    else
424
                            height = frame.getHeight();
425
                    frame.setSize(width, height);
426
                frame.setLocation(wi.getX(), wi.getY());                    
427
            }
428
            frame.setTitle(wi.getTitle());
429
            frame.setVisible(wi.isVisible());
430
            frame.setResizable(wi.isResizable());
431
            frame.setIconifiable(wi.isIconifiable());
432
            frame.setMaximizable(wi.isMaximizable());
433
            try {
434
                        frame.setMaximum(wi.isMaximized());
435
                } catch (PropertyVetoException e) {
436
                        // TODO Auto-generated catch block
437
                        //e.printStackTrace();
438
                }
439
    }
440
    
441
    /**
442
     * DOCUMENT ME!
443
     *
444
     * @param p
445
     */
446
    private void addJInternalFrame(IWindow p) {
447
        WindowInfo wi = wis.getWindowInfo(p);
448

    
449
        JInternalFrame wnd = fws.getJInternalFrame(p);
450

    
451
        if (p instanceof SingletonWindow) {
452
            SingletonWindow sv = (SingletonWindow) p;
453
            sws.openSingletonWindow(sv, wnd);
454
        }
455

    
456
        addJInternalFrame(wnd, wi);
457
    }
458

    
459
    /**
460
     * DOCUMENT ME!
461
     *
462
     * @param wnd
463
     */
464
    private void activateJInternalFrame(JInternalFrame wnd) {
465
        try {
466
            wnd.moveToFront();
467
            logger.debug("Activando " + wnd.getTitle());
468
            wnd.setSelected(true);
469
            wnd.setIcon(false);
470
        } catch (PropertyVetoException e) {
471
            logger.error(e);
472
        }
473
    }
474

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

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

    
490
    /**
491
     * DOCUMENT ME!
492
     *
493
     * @param p
494
     */
495
    private void addJDialog(IWindow p) {
496
        JDialog dlg = fws.getJDialog(p);
497

    
498
        centerDialog(dlg);
499

    
500
        dlg.addWindowListener(new DialogWindowListener());
501
        dss.pushDialog(dlg);
502

    
503
        dlg.setVisible(wis.getWindowInfo(p).isVisible());
504
    }
505

    
506
    /**
507
     * @see com.iver.andami.ui.mdiManager.MDIManager#getActiveWindow()
508
     */
509
    public IWindow getActiveWindow() {
510
        JInternalFrame jif = panel.getSelectedFrame();
511

    
512
        if (jif != null) {
513
            IWindow theWindow = fws.getWindow(jif);
514
            if (theWindow == null)
515
                return null;
516
            if (theWindow.getWindowInfo().isPalette())
517
                return wss.getActiveWindow();
518
            else
519
                return fws.getWindow(jif);
520
        }
521
        // return vss.getActiveView();
522

    
523
        return null;
524
    }
525
    public IWindow getFocusWindow(){
526
             JInternalFrame jif = panel.getSelectedFrame();
527

    
528
         if (jif != null) {
529
             IWindow theView = fws.getWindow(jif);
530
             if (theView == null)
531
                 return null;
532
             return fws.getWindow(jif);
533
         }
534
         return null;
535
    }
536
    /**
537
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeWindow(com.iver.andami.ui.mdiManager.IWindow)
538
     */
539
    public void closeWindow(IWindow p) {
540
        // Si es un di?logo modal
541
        if (p.getWindowInfo().isModal()) {
542
            closeJDialog();
543
        } else { // Si no es modal se cierra el JInternalFrame
544
            closeJInternalFrame(fws.getJInternalFrame(p));
545
        }
546
    }
547

    
548
    /**
549
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeAllWindows()
550
     */
551
    public void closeAllWindows() {
552
        ArrayList eliminar = new ArrayList();
553
        Iterator i = fws.getWindowIterator();
554

    
555
        while (i.hasNext()) {
556
            eliminar.add((IWindow) i.next());
557
        }
558

    
559
        for (Iterator iter = eliminar.iterator(); iter.hasNext();) {
560
            IWindow vista = (IWindow) iter.next();
561
            closeWindow(vista);
562
        }
563
    }
564

    
565
    /**
566
     * @see com.iver.andami.ui.mdiManager.MDIManager#getWindowInfo(com.iver.andami.ui.mdiManager.IWindow)
567
     */
568
    public WindowInfo getWindowInfo(IWindow w) {
569
            WindowInfo wi = wis.getWindowInfo(w);
570
            
571
    /*        
572
     * This is done now in vis.getWindowInfo(w)
573
     * 
574
     * JInternalFrame f = fws.getJInternalFrame(w);
575
            wi.setX(f.getX());
576
            wi.setY(f.getY());
577
            wi.setHeight(f.getHeight());
578
            wi.setWidth(f.getWidth());
579
            // isClosed() doesn't work as (I) expected, why? Using isShowing instead
580
            wi.setClosed(!f.isShowing());
581
            wi.setNormalBounds(f.getNormalBounds());
582
            wi.setMaximized(f.isMaximum());*/
583
            return wi;
584
    }
585

    
586
    /**
587
     * DOCUMENT ME!
588
     *
589
     * @param dialog
590
     * @throws RuntimeException
591
     *             DOCUMENT ME!
592
     */
593
    private void closeJDialog() {
594
        JDialog dlg = dss.popDialog();
595

    
596
        dlg.setVisible(false);
597

    
598
        IWindow s = (IWindow) fws.getWindow(dlg);
599

    
600
        callWindowClosed(s);
601

    
602
        fws.closeWindow(s);
603

    
604
        // Si es singleton se desasocia el modelo con la vista
605
        if (s instanceof SingletonWindow) {
606
            sws.closeWindow((SingletonWindow) s);
607
        }
608
    }
609

    
610
    /**
611
     * DOCUMENT ME!
612
     *
613
     * @param window
614
     *            DOCUMENT ME!
615
     */
616
    private void callWindowClosed(IWindow window) {
617
        if (window instanceof IWindowListener) {
618
            ((IWindowListener) window).windowClosed();
619
        }
620
    }
621

    
622
    /**
623
     * DOCUMENT ME!
624
     *
625
     * @param window
626
     *            DOCUMENT ME!
627
     */
628
    private void callWindowActivated(IWindow window) {
629
        logger.debug("View " + window.getWindowInfo().getTitle()
630
                + " activated (callViewActivated)");
631
        if (window instanceof IWindowListener) {
632
            ((IWindowListener) window).windowActivated();
633
        }
634
    }
635

    
636
    /**
637
     * DOCUMENT ME!
638
     *
639
     * @param frame
640
     */
641
    private void closeJInternalFrame(JInternalFrame frame) {
642
        try {
643
            IWindow s = (IWindow) fws.getWindow(frame);
644

    
645
            frame.setClosed(true);
646
            callWindowClosed(s);
647
        } catch (PropertyVetoException e) {
648
            logger
649
                    .error(
650
                            "Not compatible with property veto's. Use ViewInfo instead.",
651
                            e);
652
        }
653
    }
654

    
655
    /**
656
     * @see com.iver.andami.plugins.IExtension#initialize()
657
     */
658
    public void initialize() {
659
    }
660

    
661
    /**
662
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
663
     */
664
    public void execute(String actionCommand) {
665
        if (actionCommand.equals("cascada")) {
666
        } else if (actionCommand.equals("mosaico")) {
667
        }
668
    }
669

    
670
    /**
671
     * @see com.iver.andami.plugins.IExtension#isEnabled()
672
     */
673
    public boolean isEnabled() {
674
        // TODO Auto-generated method stub
675
        return false;
676
    }
677

    
678
    /**
679
     * @see com.iver.andami.plugins.IExtension#isVisible()
680
     */
681
    public boolean isVisible() {
682
        // TODO Auto-generated method stub
683
        return true;
684
    }
685

    
686
    /**
687
     * @see com.iver.andami.ui.mdiManager.MDIManager#setWaitCursor()
688
     */
689
    public void setWaitCursor() {
690
        if (mainFrame != null) {
691
            glassPane.setVisible(true);
692
            lastCursor = mainFrame.getCursor();
693
            dss.setWaitCursor();
694
            glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
695
        }
696
    }
697

    
698
    /**
699
     * @see com.iver.andami.ui.mdiManager.MDIManager#restoreCursor()
700
     */
701
    public void restoreCursor() {
702
        if (mainFrame != null) {
703
            glassPane.setVisible(false);
704
            dss.restoreCursor();
705
            glassPane.setCursor(lastCursor);
706
        }
707
    }
708

    
709
    /**
710
     * Listener para los eventos de cerrado de los di?logos. Tiene su raz?n de
711
     * ser en que los di?logos han de devolverse al pool cuando se cierran
712
     *
713
     * @author Fernando Gonz?lez Cort?s
714
     */
715
    public class DialogWindowListener extends WindowAdapter {
716
        /**
717
         * Captura el evento de cerrado de los di?logos con el fin de realizar
718
         * tareas de mantenimiento
719
         *
720
         * @param e
721
         *            evento
722
         */
723
        public void windowClosing(WindowEvent e) {
724
            closeJDialog();
725
        }
726
    }
727

    
728
    /**
729
     * DOCUMENT ME!
730
     */
731
    public class FrameListener implements InternalFrameListener {
732
        /**
733
         * @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent)
734
         */
735
        public void internalFrameActivated(InternalFrameEvent e) {
736
            // logger.debug("internalFrameActivated " +
737
            // e.getInternalFrame().getTitle());
738

    
739
            // activatedInternalFramesStack.push(e.getInternalFrame());
740

    
741
            IWindow panel = fws.getWindow((JInternalFrame) e.getSource());
742

    
743
            WindowInfo wi = wis.getWindowInfo(panel);
744
            if (wi.isPalette())
745
                return;
746

    
747
            wss.setActive(panel);
748

    
749
            JInternalFrame frame = fws.getJInternalFrame(panel);
750
            
751
            if (wi.isMaximizable()){
752
                    frame.setMaximizable(true);
753
            }
754
            if (!frame.isMaximizable() && frame.isMaximum()) {
755
                try {
756
                    frame.setMaximum(false);
757
                } catch (PropertyVetoException e1) {
758
                }
759
            }            
760
            mainFrame.enableControls();
761
            if (wi.getSelectedTool() != null)
762
                mainFrame.setSelectedTool(wi.getSelectedTool());
763
            callWindowActivated(panel);
764

    
765
        }
766

    
767
        /**
768
         * @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
769
         */
770
        public void internalFrameClosed(InternalFrameEvent e) {
771
        }
772

    
773
        /**
774
         * @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent)
775
         */
776
        public void internalFrameClosing(InternalFrameEvent e) {
777
            // Se elimina la memoria del JInternalFrame si no es ALWAYS_LIVE
778
            // logger.debug("internalFrameClosing " +
779
            // e.getInternalFrame().getTitle());
780

    
781
            JInternalFrame c = (JInternalFrame) e.getSource();
782
            WindowInfo wi = wis.getWindowInfo((IWindow) fws.getWindow(c));
783

    
784
            IWindow win = fws.getWindow(c);
785
            callWindowClosed(win);
786
            boolean alwaysLive;
787
            if (win instanceof SingletonWindow) {
788
                sws.closeWindow((SingletonWindow) win);
789
            }
790

    
791
            fws.closeWindow(win);
792

    
793
            panel.remove(c);
794

    
795
            wss.remove(win);
796

    
797
            if (!wi.isPalette())
798
                mainFrame.enableControls();
799
            panel.repaint();
800

    
801
            // Para activar el JInternalFrame desde la que hemos
802
            // abierto la ventana que estamos cerrando
803
            IWindow lastWindow = wss.getActiveWindow();
804
            // La activamos
805
            if (lastWindow != null) {
806
                    logger.debug(PluginServices.getText(this, "Devuelvo_el_foco_a_")+lastWindow.getWindowInfo().getTitle());
807
                JInternalFrame frame = fws.getJInternalFrame(lastWindow);
808
                try {
809
                    frame.setSelected(true);
810
                } catch (PropertyVetoException e1) {
811
                    // TODO Auto-generated catch block
812
                    // e1.printStackTrace();
813
                }
814
                // addView(lastView);
815
            }
816

    
817
        }
818

    
819
        /**
820
         * @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent)
821
         */
822
        public void internalFrameDeactivated(InternalFrameEvent e) {
823
            // logger.debug("internalDeActivated " +
824
            // e.getInternalFrame().getTitle());
825
            JInternalFrame c = (JInternalFrame) e.getSource();
826
            IWindow win = fws.getWindow(c);
827
            if (win != null) {
828
                WindowInfo wi = wis.getWindowInfo(win);
829
                if (wi.isPalette())
830
                    return;
831
                wi.setSelectedTool(mainFrame.getSelectedTool());
832
            }
833

    
834
        }
835

    
836
        /**
837
         * @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
838
         */
839
        public void internalFrameDeiconified(InternalFrameEvent e) {
840
            mainFrame.enableControls();
841
        }
842

    
843
        /**
844
         * @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
845
         */
846
        public void internalFrameIconified(InternalFrameEvent e) {
847
            mainFrame.enableControls();
848
        }
849

    
850
        /**
851
         * @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent)
852
         */
853
        public void internalFrameOpened(InternalFrameEvent e) {
854
            // logger.debug("internalFrameOpened. Source= " +
855
            // e.getSource().toString());
856
        }
857
    }
858

    
859
    /**
860
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Class,
861
     *      java.lang.Object)
862
     */
863
    public boolean closeSingletonWindow(Class viewClass, Object model) {
864
        JInternalFrame frame = sws.getFrame(viewClass, model);
865
        if (frame == null)
866
            return false;
867
        closeJInternalFrame(frame);
868
        return true;
869
    }
870

    
871
    /**
872
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeSingletonWindow(java.lang.Object)
873
     */
874
    public boolean closeSingletonWindow(Object model) {
875
        JInternalFrame[] frames = sws.getFrames(model);
876
        if (frames.length == 0)
877
            return false;
878
        for (int i = 0; i < frames.length; i++) {
879
            closeJInternalFrame(frames[i]);
880
        }
881
        return true;
882
    }
883

    
884
    /**
885
     * @see com.iver.andami.ui.mdiManager.MDIManager#getAllWindows()
886
     */
887
    public IWindow[] getAllWindows() {
888
        ArrayList windows = new ArrayList();
889
        Iterator i = fws.getWindowIterator();
890

    
891
        while (i.hasNext()) {
892
            windows.add((IWindow) i.next());
893
        }
894
        return (IWindow[]) windows.toArray(new IWindow[0]);
895
    }
896
    
897
    /**
898
     * @see com.iver.andami.ui.mdiManager.MDIManager#getOrderedWindows()
899
     */
900
    public IWindow[] getOrderedWindows() {
901
        //ArrayList windows = new ArrayList();
902
        TreeMap windows = new TreeMap();
903
        Iterator winIterator = fws.getWindowIterator();       
904
        
905
        Component frame;
906
        IWindow win;
907
        /**
908
         * The order of the window in the JDesktopPane. Smaller numbers
909
         * are closer to the foreground.
910
         */
911
        int zPosition;
912
        while (winIterator.hasNext()) {
913
                win = (IWindow) winIterator.next();
914
                frame = fws.getFrame(win);
915
                    zPosition = panel.getPosition(frame);
916
                    windows.put(new Integer(zPosition), win);
917
        }
918
        winIterator = windows.values().iterator();
919
        ArrayList winList = new ArrayList();
920
        while (winIterator.hasNext()) {
921
                winList.add(winIterator.next());
922
        }
923

    
924
        return (IWindow[]) winList.toArray(new IWindow[0]);
925
    }
926

    
927
    public void setMaximum(IWindow v, boolean bMaximum) throws PropertyVetoException
928
    {
929
        JInternalFrame f = fws.getJInternalFrame(v);
930
        f.setMaximum(bMaximum);
931
    }
932

    
933
    public void changeWindowInfo(IWindow w, WindowInfo wi){
934
            JInternalFrame f = fws.getJInternalFrame(w);
935
                f.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
936
                JDesktopPane pnl = f.getDesktopPane();
937
                pnl.remove(f);
938
                int width;
939
                int height;
940
                if (wi.getWidth()!=-1)
941
                        width = wi.getWidth();
942
                else
943
                        width = f.getWidth();
944
                if (wi.getHeight()!=-1)
945
                        height = wi.getHeight();
946
                else
947
                        height = f.getHeight();
948
                f.setSize(new Dimension(width, height));
949
                f.setLocation(wi.getX(), wi.getY());
950
                if (wi.isPalette()) {
951
                        pnl.add(f, JDesktopPane.PALETTE_LAYER);
952
                        f.setFocusable(false);
953
                } else {
954
                        pnl.add(f, JDesktopPane.DEFAULT_LAYER);
955
                        f.setFocusable(true);
956
                        if (wi.isClosed()) {
957
                                closeWindow(w);
958
                        }
959
                }
960

    
961
                if (wi.isMaximized()) {
962
                        try {
963
                                f.setMaximum(true);
964
                        } catch (PropertyVetoException e) {
965
                                // TODO Auto-generated catch block
966
                                //e.printStackTrace();
967
                        }
968
                        f.setNormalBounds(wi.getNormalBounds());
969
                }
970
                activateJInternalFrame(f);
971
   }
972

    
973
}