Statistics
| Revision:

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

History | View | Annotate | Download (5.03 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
        /* arrays for dynamically assigned shortcut keys */
58
        private boolean[] key_free;
59
        private String[] key;
60
        
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
                /* restart window key shortcut numbering */
74
                key_free = new boolean[10];
75
                for ( int i = 0; i < 10; i ++ ) {
76
                        key_free[i] = true;
77
                }
78
                key = new java.lang.String[10];
79
                key[0] = "1";
80
                key[1] = "2";
81
                key[2] = "3";
82
                key[3] = "4";
83
                key[4] = "5";
84
                key[5] = "6";
85
                key[6] = "7";
86
                key[7] = "8";
87
                key[8] = "9";
88
                key[9] = "0";
89
        }
90

    
91
        public void add(IWindow v, final ActionListener listener) {
92
                vistas.add(v);
93
                WindowInfo vi = vis.getWindowInfo(v);
94
                int id = vi.getId();
95
                Menu m = new Menu();
96
                m.setActionCommand(""+id);
97
                m.setTooltip(PluginServices.getText(this, "activa_la_ventana"));
98
                m.setText("Window/"+vi.getTitle());
99
                /* get the first free mnemonic (if any) and assign */
100
                for ( int i=0; i < 10; i++) {
101
                        if ( key_free[i]) {
102
                                m.setKey(key[i]);
103
                                key_free[i] = false;
104
                                break;
105
                        }
106
                }
107
                viewMenu.put(v, m);
108
                PluginServices.getMainFrame().addMenu(m, listener, PluginServices.getPluginServices(this).getClassLoader() );
109
        }
110

    
111
        public void remove(IWindow v){
112
                Menu m = (Menu) viewMenu.get(v);
113
                if (m == null) return;
114
                /* free keyboard shortut taken by this window (if any) */
115
                if ( m.getKey() != null ) {
116
                        for ( int i=0; i < 10; i++ ) {
117
                                if ( m.getKey() == key[i]) {
118
                                        key_free[i] = true;
119
                                        break;
120
                                }
121
                        }
122
                }
123
                PluginServices.getMainFrame().removeMenu(m);
124
                viewMenu.remove(v);
125
                vistas.remove(v);
126
        }
127

    
128
        /**
129
         * FJP: No se usa, y no s? para qu? estaba pensado.
130
         */
131
        public void ctrltab(){
132
                IWindow v = (IWindow) vistas.remove(vistas.size() - 1);
133
                vistas.add(0, v);
134
        }
135

    
136
        public IWindow getActiveWindow(){
137
                if (vistas.size() == 0) return null;
138
        int index = vistas.size()-1;
139
        while (index >= 0)
140
        {
141
            IWindow aux = (IWindow) vistas.get(index);
142
            if (!aux.getWindowInfo().isPalette())
143
            {
144
//                System.err.println("getActiveView = " + aux.getWindowInfo().getTitle());
145
                return aux;
146
            }
147
            index--;
148
        }
149
        return null;
150
        }
151
    /**
152
     * Se utiliza cuando ya est? abierta la vista para indicar
153
     * que la pasamos a activa. De esta forma evitamos que el
154
     * getActiveView devuelva algo que no es.
155
     * En realidad lo que haces es mover la vista a la ?ltima
156
     * posici?n.
157
     * @param v
158
     */
159
    public void setActive(IWindow v)
160
    {
161
        IWindow copia = null;
162
        boolean bCopiar = false;
163
        // Si es de tipo palette, no se pone como activa.
164
        // De esta forma, nunca nos la devolver?.... Bueno,
165
        // igual si cerramos la de encima. Voy a ponerle en
166
        // getActiveView que si es de tipo Palette, devuelva la
167
        // de abajo.
168
        if (v.getWindowInfo().isPalette()) return;
169

    
170
        for (int i=0; i < vistas.size(); i++)
171
        {
172
            IWindow aux = (IWindow) vistas.get(i);
173
            if (aux == v)
174
            {
175
                copia = aux;
176
                bCopiar = true;
177
            }
178
            if (bCopiar)
179
            {
180
                if (i < vistas.size()-1)
181
                {
182
                    IWindow siguiente = (IWindow) vistas.get(i+1);
183
                    vistas.set(i,siguiente);
184
                }
185
                else // La ?ltima
186
                    vistas.set(i,copia);
187
            }
188
        } // for
189
    }
190
}