gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / mdiManager / WindowStackSupport.java @ 682
History | View | Annotate | Download (5 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.coreplugin.mdiManager; |
25 |
|
26 |
import java.awt.event.ActionListener; |
27 |
import java.util.Hashtable; |
28 |
import java.util.Vector; |
29 |
|
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.plugins.config.generate.Menu; |
32 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
33 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
34 |
|
35 |
|
36 |
/**
|
37 |
*
|
38 |
*/
|
39 |
public class WindowStackSupport { |
40 |
/* arrays for dynamically assigned shortcut keys */
|
41 |
private boolean[] key_free; |
42 |
private String[] key; |
43 |
|
44 |
private Vector vistas = new Vector(); |
45 |
|
46 |
private WindowInfoSupport vis;
|
47 |
|
48 |
private Hashtable viewMenu = new Hashtable(); |
49 |
|
50 |
/**
|
51 |
* @param vis
|
52 |
*/
|
53 |
public WindowStackSupport(WindowInfoSupport vis) {
|
54 |
this.vis = vis;
|
55 |
|
56 |
/* restart window key shortcut numbering */
|
57 |
key_free = new boolean[10]; |
58 |
for ( int i = 0; i < 10; i ++ ) { |
59 |
key_free[i] = true;
|
60 |
} |
61 |
key = new java.lang.String[10]; |
62 |
/*
|
63 |
* We need to add CTRL modifier because
|
64 |
* our key stroke manager will
|
65 |
* not add default modifier (because we need to
|
66 |
* deal with F3, F7, etc, not CTRL+F3 etc)
|
67 |
*/
|
68 |
key[0] = "ctrl+1"; |
69 |
key[1] = "ctrl+2"; |
70 |
key[2] = "ctrl+3"; |
71 |
key[3] = "ctrl+4"; |
72 |
key[4] = "ctrl+5"; |
73 |
key[5] = "ctrl+6"; |
74 |
key[6] = "ctrl+7"; |
75 |
key[7] = "ctrl+8"; |
76 |
key[8] = "ctrl+9"; |
77 |
key[9] = "ctrl+0"; |
78 |
} |
79 |
|
80 |
public void add(IWindow v, final ActionListener listener) { |
81 |
vistas.add(v); |
82 |
WindowInfo vi = vis.getWindowInfo(v); |
83 |
int id = vi.getId();
|
84 |
Menu m = new Menu(); |
85 |
m.setActionCommand(""+id);
|
86 |
m.setTooltip(PluginServices.getText(this, "activa_la_ventana")); |
87 |
m.setText("Window/"+vi.getTitle());
|
88 |
/* get the first free mnemonic (if any) and assign */
|
89 |
for ( int i=0; i < 10; i++) { |
90 |
if ( key_free[i]) {
|
91 |
m.setKey(key[i]); |
92 |
key_free[i] = false;
|
93 |
break;
|
94 |
} |
95 |
} |
96 |
viewMenu.put(v, m); |
97 |
PluginServices.getMainFrame().addMenu(m, listener, PluginServices.getPluginServices(this).getClassLoader() );
|
98 |
} |
99 |
|
100 |
public void remove(IWindow v){ |
101 |
Menu m = (Menu) viewMenu.get(v); |
102 |
if (m == null) return; |
103 |
/* free keyboard shortut taken by this window (if any) */
|
104 |
if ( m.getKey() != null ) { |
105 |
for ( int i=0; i < 10; i++ ) { |
106 |
if ( m.getKey() == key[i]) {
|
107 |
key_free[i] = true;
|
108 |
break;
|
109 |
} |
110 |
} |
111 |
} |
112 |
PluginServices.getMainFrame().removeMenu(m); |
113 |
viewMenu.remove(v); |
114 |
vistas.remove(v); |
115 |
} |
116 |
|
117 |
/**
|
118 |
* FJP: No se usa, y no s? para qu? estaba pensado.
|
119 |
*/
|
120 |
public void ctrltab(){ |
121 |
IWindow v = (IWindow) vistas.remove(vistas.size() - 1);
|
122 |
vistas.add(0, v);
|
123 |
} |
124 |
|
125 |
public IWindow getActiveWindow(){
|
126 |
if (vistas.size() == 0) return null; |
127 |
int index = vistas.size()-1; |
128 |
while (index >= 0) |
129 |
{ |
130 |
IWindow aux = (IWindow) vistas.get(index); |
131 |
if (!aux.getWindowInfo().isPalette())
|
132 |
{ |
133 |
// System.err.println("getActiveView = " + aux.getWindowInfo().getTitle());
|
134 |
return aux;
|
135 |
} |
136 |
index--; |
137 |
} |
138 |
return null; |
139 |
} |
140 |
/**
|
141 |
* Se utiliza cuando ya est? abierta la vista para indicar
|
142 |
* que la pasamos a activa. De esta forma evitamos que el
|
143 |
* getActiveView devuelva algo que no es.
|
144 |
* En realidad lo que haces es mover la vista a la ?ltima
|
145 |
* posici?n.
|
146 |
* @param v
|
147 |
*/
|
148 |
public void setActive(IWindow v) |
149 |
{ |
150 |
IWindow copia = null;
|
151 |
boolean bCopiar = false; |
152 |
// Si es de tipo palette, no se pone como activa.
|
153 |
// De esta forma, nunca nos la devolver?.... Bueno,
|
154 |
// igual si cerramos la de encima. Voy a ponerle en
|
155 |
// getActiveView que si es de tipo Palette, devuelva la
|
156 |
// de abajo.
|
157 |
if (v.getWindowInfo().isPalette()) return; |
158 |
|
159 |
for (int i=0; i < vistas.size(); i++) |
160 |
{ |
161 |
IWindow aux = (IWindow) vistas.get(i); |
162 |
if (aux == v)
|
163 |
{ |
164 |
copia = aux; |
165 |
bCopiar = true;
|
166 |
} |
167 |
if (bCopiar)
|
168 |
{ |
169 |
if (i < vistas.size()-1) |
170 |
{ |
171 |
IWindow siguiente = (IWindow) vistas.get(i+1);
|
172 |
vistas.set(i,siguiente); |
173 |
} |
174 |
else // La ?ltima |
175 |
vistas.set(i,copia); |
176 |
} |
177 |
} // for
|
178 |
} |
179 |
} |