Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / libraries / libCorePlugin / src / com / iver / core / mdiManager / WindowStackSupport.java @ 8745

History | View | Annotate | Download (4.41 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.event.ActionEvent;
44
import java.awt.event.ActionListener;
45
import java.lang.reflect.InvocationTargetException;
46
import java.util.Hashtable;
47
import java.util.Vector;
48

    
49
import javax.swing.SwingUtilities;
50

    
51
import com.iver.andami.PluginServices;
52
import com.iver.andami.persistence.generate.PluginsStatus;
53
import com.iver.andami.plugins.config.generate.Menu;
54
import com.iver.andami.ui.mdiManager.IWindow;
55
import com.iver.andami.ui.mdiManager.WindowInfo;
56

    
57
/**
58
 * 
59
 */
60
public class WindowStackSupport {
61
        private Vector vistas = new Vector();
62
        
63
        private WindowInfoSupport vis;
64
        
65
        private Hashtable viewMenu = new Hashtable();
66
        
67
        /**
68
         * @param vis
69
         */
70
        public WindowStackSupport(WindowInfoSupport vis) {
71
                this.vis = vis;
72
        }
73

    
74
        public void add(IWindow v, final ActionListener listener) {
75
                vistas.add(v);
76
                WindowInfo vi = vis.getWindowInfo(v);
77
                int id = vi.getId();
78
                Menu m = new Menu();
79
                m.setActionCommand(""+id);
80
                m.setTooltip(PluginServices.getText(this, "activa_la_ventana"));
81
                m.setText("ventana/"+vi.getTitle());
82
                viewMenu.put(v, m);
83
                PluginServices.getMainFrame().addMenu(m, listener, PluginServices.getPluginServices(this).getClassLoader() );
84
        }
85
        
86
        public void remove(IWindow v){
87
                Menu m = (Menu) viewMenu.get(v);
88
                if (m == null) return;
89
                PluginServices.getMainFrame().removeMenu(m);
90
                viewMenu.remove(v);
91
                vistas.remove(v);
92
        }
93
        
94
        /**
95
         * FJP: No se usa, y no s? para qu? estaba pensado. 
96
         */
97
        public void ctrltab(){
98
                IWindow v = (IWindow) vistas.remove(vistas.size() - 1);
99
                vistas.add(0, v);
100
        }
101
        
102
        public IWindow getActiveWindow(){
103
                if (vistas.size() == 0) return null;
104
        int index = vistas.size()-1;
105
        while (index >= 0)
106
        {
107
            IWindow aux = (IWindow) vistas.get(index);
108
            if (!aux.getWindowInfo().isPalette())
109
            {
110
                System.err.println("getActiveView = " + aux.getWindowInfo().getTitle());
111
                return aux;
112
            }
113
            index--;
114
        }
115
        return null;
116
        }
117
    /**
118
     * Se utiliza cuando ya est? abierta la vista para indicar
119
     * que la pasamos a activa. De esta forma evitamos que el
120
     * getActiveView devuelva algo que no es. 
121
     * En realidad lo que haces es mover la vista a la ?ltima
122
     * posici?n.
123
     * @param v
124
     */
125
    public void setActive(IWindow v)
126
    {
127
        IWindow copia = null;
128
        boolean bCopiar = false;
129
        // Si es de tipo palette, no se pone como activa.
130
        // De esta forma, nunca nos la devolver?.... Bueno, 
131
        // igual si cerramos la de encima. Voy a ponerle en
132
        // getActiveView que si es de tipo Palette, devuelva la
133
        // de abajo.
134
        if (v.getWindowInfo().isPalette()) return;
135
        
136
        for (int i=0; i < vistas.size(); i++)
137
        {
138
            IWindow aux = (IWindow) vistas.get(i);
139
            if (aux == v)
140
            {
141
                copia = aux;
142
                bCopiar = true;
143
            }
144
            if (bCopiar)
145
            {
146
                if (i < vistas.size()-1)
147
                {
148
                    IWindow siguiente = (IWindow) vistas.get(i+1);
149
                    vistas.set(i,siguiente);
150
                }
151
                else // La ?ltima
152
                    vistas.set(i,copia);
153
            }
154
        } // for
155
    }
156
}