Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / mdiManager / WindowStackSupport.java @ 29630

History | View | Annotate | Download (4.22 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 org.gvsig.coreplugin.mdiManager;
42

    
43
import java.awt.event.ActionListener;
44
import java.util.Hashtable;
45
import java.util.Vector;
46

    
47
import org.gvsig.andami.PluginServices;
48
import org.gvsig.andami.plugins.config.generate.Menu;
49
import org.gvsig.andami.ui.mdiManager.IWindow;
50
import org.gvsig.andami.ui.mdiManager.WindowInfo;
51

    
52

    
53
/**
54
 *
55
 */
56
public class WindowStackSupport {
57
        private Vector vistas = new Vector();
58

    
59
        private WindowInfoSupport vis;
60

    
61
        private Hashtable viewMenu = new Hashtable();
62

    
63
        /**
64
         * @param vis
65
         */
66
        public WindowStackSupport(WindowInfoSupport vis) {
67
                this.vis = vis;
68
        }
69

    
70
        public void add(IWindow v, final ActionListener listener) {
71
                vistas.add(v);
72
                WindowInfo vi = vis.getWindowInfo(v);
73
                int id = vi.getId();
74
                Menu m = new Menu();
75
                m.setActionCommand(""+id);
76
                m.setTooltip(PluginServices.getText(this, "activa_la_ventana"));
77
                m.setText("Ventana/"+vi.getTitle());
78
                viewMenu.put(v, m);
79
                PluginServices.getMainFrame().addMenu(m, listener, PluginServices.getPluginServices(this).getClassLoader() );
80
        }
81

    
82
        public void remove(IWindow v){
83
                Menu m = (Menu) viewMenu.get(v);
84
                if (m == null) return;
85
                PluginServices.getMainFrame().removeMenu(m);
86
                viewMenu.remove(v);
87
                vistas.remove(v);
88
        }
89

    
90
        /**
91
         * FJP: No se usa, y no s? para qu? estaba pensado.
92
         */
93
        public void ctrltab(){
94
                IWindow v = (IWindow) vistas.remove(vistas.size() - 1);
95
                vistas.add(0, v);
96
        }
97

    
98
        public IWindow getActiveWindow(){
99
                if (vistas.size() == 0) return null;
100
        int index = vistas.size()-1;
101
        while (index >= 0)
102
        {
103
            IWindow aux = (IWindow) vistas.get(index);
104
            if (!aux.getWindowInfo().isPalette())
105
            {
106
//                System.err.println("getActiveView = " + aux.getWindowInfo().getTitle());
107
                return aux;
108
            }
109
            index--;
110
        }
111
        return null;
112
        }
113
    /**
114
     * Se utiliza cuando ya est? abierta la vista para indicar
115
     * que la pasamos a activa. De esta forma evitamos que el
116
     * getActiveView devuelva algo que no es.
117
     * En realidad lo que haces es mover la vista a la ?ltima
118
     * posici?n.
119
     * @param v
120
     */
121
    public void setActive(IWindow v)
122
    {
123
        IWindow copia = null;
124
        boolean bCopiar = false;
125
        // Si es de tipo palette, no se pone como activa.
126
        // De esta forma, nunca nos la devolver?.... Bueno,
127
        // igual si cerramos la de encima. Voy a ponerle en
128
        // getActiveView que si es de tipo Palette, devuelva la
129
        // de abajo.
130
        if (v.getWindowInfo().isPalette()) return;
131

    
132
        for (int i=0; i < vistas.size(); i++)
133
        {
134
            IWindow aux = (IWindow) vistas.get(i);
135
            if (aux == v)
136
            {
137
                copia = aux;
138
                bCopiar = true;
139
            }
140
            if (bCopiar)
141
            {
142
                if (i < vistas.size()-1)
143
                {
144
                    IWindow siguiente = (IWindow) vistas.get(i+1);
145
                    vistas.set(i,siguiente);
146
                }
147
                else // La ?ltima
148
                    vistas.set(i,copia);
149
            }
150
        } // for
151
    }
152
}