root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / mdiManager / WindowStackSupport.java @ 39408
History | View | Annotate | Download (5.26 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 |
/*
|
80 |
* We need to add CTRL modifier because
|
81 |
* our key stroke manager will
|
82 |
* not add default modifier (because we need to
|
83 |
* deal with F3, F7, etc, not CTRL+F3 etc)
|
84 |
*/
|
85 |
key[0] = "ctrl+1"; |
86 |
key[1] = "ctrl+2"; |
87 |
key[2] = "ctrl+3"; |
88 |
key[3] = "ctrl+4"; |
89 |
key[4] = "ctrl+5"; |
90 |
key[5] = "ctrl+6"; |
91 |
key[6] = "ctrl+7"; |
92 |
key[7] = "ctrl+8"; |
93 |
key[8] = "ctrl+9"; |
94 |
key[9] = "ctrl+0"; |
95 |
} |
96 |
|
97 |
public void add(IWindow v, final ActionListener listener) { |
98 |
vistas.add(v); |
99 |
WindowInfo vi = vis.getWindowInfo(v); |
100 |
int id = vi.getId();
|
101 |
Menu m = new Menu(); |
102 |
m.setActionCommand(""+id);
|
103 |
m.setTooltip(PluginServices.getText(this, "activa_la_ventana")); |
104 |
m.setText("Window/"+vi.getTitle());
|
105 |
/* get the first free mnemonic (if any) and assign */
|
106 |
for ( int i=0; i < 10; i++) { |
107 |
if ( key_free[i]) {
|
108 |
m.setKey(key[i]); |
109 |
key_free[i] = false;
|
110 |
break;
|
111 |
} |
112 |
} |
113 |
viewMenu.put(v, m); |
114 |
PluginServices.getMainFrame().addMenu(m, listener, PluginServices.getPluginServices(this).getClassLoader() );
|
115 |
} |
116 |
|
117 |
public void remove(IWindow v){ |
118 |
Menu m = (Menu) viewMenu.get(v); |
119 |
if (m == null) return; |
120 |
/* free keyboard shortut taken by this window (if any) */
|
121 |
if ( m.getKey() != null ) { |
122 |
for ( int i=0; i < 10; i++ ) { |
123 |
if ( m.getKey() == key[i]) {
|
124 |
key_free[i] = true;
|
125 |
break;
|
126 |
} |
127 |
} |
128 |
} |
129 |
PluginServices.getMainFrame().removeMenu(m); |
130 |
viewMenu.remove(v); |
131 |
vistas.remove(v); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* FJP: No se usa, y no s? para qu? estaba pensado.
|
136 |
*/
|
137 |
public void ctrltab(){ |
138 |
IWindow v = (IWindow) vistas.remove(vistas.size() - 1);
|
139 |
vistas.add(0, v);
|
140 |
} |
141 |
|
142 |
public IWindow getActiveWindow(){
|
143 |
if (vistas.size() == 0) return null; |
144 |
int index = vistas.size()-1; |
145 |
while (index >= 0) |
146 |
{ |
147 |
IWindow aux = (IWindow) vistas.get(index); |
148 |
if (!aux.getWindowInfo().isPalette())
|
149 |
{ |
150 |
// System.err.println("getActiveView = " + aux.getWindowInfo().getTitle());
|
151 |
return aux;
|
152 |
} |
153 |
index--; |
154 |
} |
155 |
return null; |
156 |
} |
157 |
/**
|
158 |
* Se utiliza cuando ya est? abierta la vista para indicar
|
159 |
* que la pasamos a activa. De esta forma evitamos que el
|
160 |
* getActiveView devuelva algo que no es.
|
161 |
* En realidad lo que haces es mover la vista a la ?ltima
|
162 |
* posici?n.
|
163 |
* @param v
|
164 |
*/
|
165 |
public void setActive(IWindow v) |
166 |
{ |
167 |
IWindow copia = null;
|
168 |
boolean bCopiar = false; |
169 |
// Si es de tipo palette, no se pone como activa.
|
170 |
// De esta forma, nunca nos la devolver?.... Bueno,
|
171 |
// igual si cerramos la de encima. Voy a ponerle en
|
172 |
// getActiveView que si es de tipo Palette, devuelva la
|
173 |
// de abajo.
|
174 |
if (v.getWindowInfo().isPalette()) return; |
175 |
|
176 |
for (int i=0; i < vistas.size(); i++) |
177 |
{ |
178 |
IWindow aux = (IWindow) vistas.get(i); |
179 |
if (aux == v)
|
180 |
{ |
181 |
copia = aux; |
182 |
bCopiar = true;
|
183 |
} |
184 |
if (bCopiar)
|
185 |
{ |
186 |
if (i < vistas.size()-1) |
187 |
{ |
188 |
IWindow siguiente = (IWindow) vistas.get(i+1);
|
189 |
vistas.set(i,siguiente); |
190 |
} |
191 |
else // La ?ltima |
192 |
vistas.set(i,copia); |
193 |
} |
194 |
} // for
|
195 |
} |
196 |
} |