Statistics
| Revision:

root / branches / piloto3d / libraries / libCorePlugin / src / com / iver / core / mdiManager / NewSkin.java @ 9535

History | View | Annotate | Download (30.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.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.JPopupMenu;
67
import javax.swing.KeyStroke;
68
import javax.swing.event.InternalFrameEvent;
69
import javax.swing.event.InternalFrameListener;
70

    
71
import org.apache.log4j.Logger;
72

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

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

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

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

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

    
112
    private GlassPane glassPane = new GlassPane();
113

    
114
    private DialogStackSupport dss;
115

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

    
121
    private WindowInfoSupport wis;
122

    
123
    private WindowStackSupport wss;
124

    
125
    private SingletonWindowSupport sws;
126

    
127
    private Cursor lastCursor = null;
128

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

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

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

    
148

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

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

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

    
161

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

    
173
        });
174
    }
175

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
457
        addJInternalFrame(wnd, wi);
458
    }
459

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

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

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

    
494
    /**
495
     * DOCUMENT ME!
496
     *
497
     * @param p
498
     */
499
    private void addJDialog(IWindow p) {
500
        JDialog dlg = fws.getJDialog(p);
501

    
502
        centerDialog(dlg);
503

    
504
        dlg.addWindowListener(new DialogWindowListener());
505
        dss.pushDialog(dlg);
506

    
507
        dlg.setVisible(wis.getWindowInfo(p).isVisible());
508
    }
509

    
510
    /**
511
     * @see com.iver.andami.ui.mdiManager.MDIManager#getActiveWindow()
512
     */
513
    public IWindow getActiveWindow() {
514
        JInternalFrame jif = panel.getSelectedFrame();
515

    
516
        if (jif != null) {
517
            IWindow theWindow = fws.getWindow(jif);
518
            if (theWindow == null)
519
                return null;
520
            if (theWindow.getWindowInfo().isPalette())
521
                return wss.getActiveWindow();
522
            else
523
                return fws.getWindow(jif);
524
        }
525
        // return vss.getActiveView();
526

    
527
        return null;
528
    }
529
    public IWindow getFocusWindow(){
530
             JInternalFrame jif = panel.getSelectedFrame();
531

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

    
552
    /**
553
     * @see com.iver.andami.ui.mdiManager.MDIManager#closeAllWindows()
554
     */
555
    public void closeAllWindows() {
556
        ArrayList eliminar = new ArrayList();
557
        Iterator i = fws.getWindowIterator();
558

    
559
        while (i.hasNext()) {
560
            eliminar.add((IWindow) i.next());
561
        }
562

    
563
        for (Iterator iter = eliminar.iterator(); iter.hasNext();) {
564
            IWindow vista = (IWindow) iter.next();
565
            closeWindow(vista);
566
        }
567
    }
568

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

    
590
    /**
591
     * DOCUMENT ME!
592
     *
593
     * @param dialog
594
     * @throws RuntimeException
595
     *             DOCUMENT ME!
596
     */
597
    private void closeJDialog() {
598
        JDialog dlg = dss.popDialog();
599

    
600
        dlg.setVisible(false);
601

    
602
        IWindow s = (IWindow) fws.getWindow(dlg);
603

    
604
        callWindowClosed(s);
605

    
606
        fws.closeWindow(s);
607

    
608
        // Si es singleton se desasocia el modelo con la vista
609
        if (s instanceof SingletonWindow) {
610
            sws.closeWindow((SingletonWindow) s);
611
        }
612
    }
613

    
614
    /**
615
     * DOCUMENT ME!
616
     *
617
     * @param window
618
     *            DOCUMENT ME!
619
     */
620
    private void callWindowClosed(IWindow window) {
621
        if (window instanceof IWindowListener) {
622
            ((IWindowListener) window).windowClosed();
623
        }
624
    }
625

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

    
640
    /**
641
     * DOCUMENT ME!
642
     *
643
     * @param frame
644
     */
645
    private void closeJInternalFrame(JInternalFrame frame) {
646
        try {
647
            IWindow s = (IWindow) fws.getWindow(frame);
648

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

    
659
    /**
660
     * @see com.iver.andami.plugins.IExtension#initialize()
661
     */
662
    public void initialize() {
663
    }
664

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

    
674
    /**
675
     * @see com.iver.andami.plugins.IExtension#isEnabled()
676
     */
677
    public boolean isEnabled() {
678
        // TODO Auto-generated method stub
679
        return false;
680
    }
681

    
682
    /**
683
     * @see com.iver.andami.plugins.IExtension#isVisible()
684
     */
685
    public boolean isVisible() {
686
        // TODO Auto-generated method stub
687
        return true;
688
    }
689

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

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

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

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

    
743
            // activatedInternalFramesStack.push(e.getInternalFrame());
744

    
745
            IWindow panel = fws.getWindow((JInternalFrame) e.getSource());
746

    
747
            WindowInfo wi = wis.getWindowInfo(panel);
748
            if (wi.isPalette())
749
                return;
750

    
751
            wss.setActive(panel);
752

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

    
769
        }
770

    
771
        /**
772
         * @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
773
         */
774
        public void internalFrameClosed(InternalFrameEvent e) {
775
        }
776

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

    
785
            JInternalFrame c = (JInternalFrame) e.getSource();
786
            WindowInfo wi = wis.getWindowInfo((IWindow) fws.getWindow(c));
787

    
788
            IWindow win = fws.getWindow(c);
789
            callWindowClosed(win);
790
            boolean alwaysLive;
791
            if (win instanceof SingletonWindow) {
792
                sws.closeWindow((SingletonWindow) win);
793
            }
794

    
795
            fws.closeWindow(win);
796

    
797
            panel.remove(c);
798

    
799
            wss.remove(win);
800

    
801
            if (!wi.isPalette())
802
                mainFrame.enableControls();
803
            panel.repaint();
804

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

    
821
        }
822

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

    
838
        }
839

    
840
        /**
841
         * @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
842
         */
843
        public void internalFrameDeiconified(InternalFrameEvent e) {
844
            mainFrame.enableControls();
845
        }
846

    
847
        /**
848
         * @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
849
         */
850
        public void internalFrameIconified(InternalFrameEvent e) {
851
            mainFrame.enableControls();
852
        }
853

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

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

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

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

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

    
928
        return (IWindow[]) winList.toArray(new IWindow[0]);
929
    }
930

    
931
    public void setMaximum(IWindow v, boolean bMaximum) throws PropertyVetoException
932
    {
933
        JInternalFrame f = fws.getJInternalFrame(v);
934
        f.setMaximum(bMaximum);
935
    }
936

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

    
965
                if (wi.isMaximized()) {
966
                        try {
967
                                f.setMaximum(true);
968
                        } catch (PropertyVetoException e) {
969
                                // TODO Auto-generated catch block
970
                                //e.printStackTrace();
971
                        }
972
                        f.setNormalBounds(wi.getNormalBounds());
973
                }
974
                activateJInternalFrame(f);
975
   }
976
    
977
    public void refresh(IWindow win) {
978
            Component frame = fws.getFrame(win);
979
            if (frame!=null)
980
                    frame.setVisible(true);
981
    }
982

    
983

    
984

    
985
}