root / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / gui / properties / dialog / RegistrableTabPanel.java @ 13627
History | View | Annotate | Download (6.44 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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 |
package org.gvsig.raster.gui.properties.dialog; |
20 |
|
21 |
import java.lang.reflect.Constructor; |
22 |
import java.lang.reflect.InvocationTargetException; |
23 |
import java.util.Hashtable; |
24 |
import java.util.Iterator; |
25 |
|
26 |
import javax.swing.JPanel; |
27 |
import javax.swing.event.ChangeEvent; |
28 |
import javax.swing.event.ChangeListener; |
29 |
|
30 |
import org.gvsig.raster.util.RasterToolsUtil; |
31 |
|
32 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
33 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
34 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
35 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
36 |
/**
|
37 |
* Panel que contiene todos los paneles de los tabs del cuadro de dialogo
|
38 |
* de bandas y transparencias
|
39 |
*
|
40 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
41 |
*/
|
42 |
public class RegistrableTabPanel extends DefaultTabPanel implements ChangeListener { |
43 |
final private static long serialVersionUID = 0; |
44 |
|
45 |
private ExtensionPoints extensionPoints = null; |
46 |
private ExtensionPoint extensionPoint = null; |
47 |
|
48 |
static public Hashtable initialProperties = new Hashtable(); |
49 |
/**
|
50 |
* Tama?o en X del panel
|
51 |
*/
|
52 |
protected int sizePanelX = 0; |
53 |
|
54 |
/**
|
55 |
* Tama?o en Y del panel
|
56 |
*/
|
57 |
protected int sizePanelY = 0; |
58 |
|
59 |
/**
|
60 |
* Constructor. Inicializa los paneles y propiedades
|
61 |
* @param props Propiedades
|
62 |
* @throws EmptyTabsException
|
63 |
*/
|
64 |
public RegistrableTabPanel(FLayer lyr) throws EmptyTabsException { |
65 |
loadTabsFromExtensionPoints(lyr); |
66 |
getTabPane().addChangeListener(this);
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* Load register tabs inside the panel, reading these from extension points.
|
71 |
* @throws EmptyTabsException
|
72 |
*/
|
73 |
private void loadTabsFromExtensionPoints(FLayer lyr) throws EmptyTabsException { |
74 |
extensionPoints = ExtensionPointsSingleton.getInstance(); |
75 |
extensionPoint = (ExtensionPoint) extensionPoints.get("RasterSEPropertiesDialog");
|
76 |
if (extensionPoint == null) |
77 |
return;
|
78 |
Iterator iterator = extensionPoint.keySet().iterator();
|
79 |
|
80 |
Exception lastException = null; |
81 |
int contTabs = 0; |
82 |
while (iterator.hasNext()) {
|
83 |
try {
|
84 |
String key = (String) iterator.next(); |
85 |
|
86 |
Class class1 = (Class) extensionPoint.get(key); |
87 |
Constructor constructor = class1.getConstructor(null); |
88 |
JPanel panel = (JPanel) constructor.newInstance(null); |
89 |
|
90 |
if (panel instanceof IRegistrablePanel) { |
91 |
((IRegistrablePanel) panel).setLayer(lyr); |
92 |
if (((IRegistrablePanel) panel).isVisiblePanel() && ((IRegistrablePanel) panel).getLayerClass().isInstance(lyr)) {
|
93 |
((IRegistrablePanel) panel).initializeUI(); |
94 |
super.addTab(((IRegistrablePanel) panel).getID(), panel);
|
95 |
contTabs++; |
96 |
} |
97 |
} |
98 |
} catch (NoSuchMethodException e) { |
99 |
lastException = e; |
100 |
} catch (IllegalArgumentException e) { |
101 |
lastException = e; |
102 |
} catch (InstantiationException e) { |
103 |
lastException = e; |
104 |
} catch (IllegalAccessException e) { |
105 |
lastException = e; |
106 |
} catch (InvocationTargetException e) { |
107 |
lastException = e; |
108 |
} catch (ClassCastException e) { |
109 |
lastException = e; |
110 |
} |
111 |
} |
112 |
|
113 |
if (lastException != null) |
114 |
RasterToolsUtil.messageBoxError("No se pudo crear correctamente el panel de propiedades.", this, lastException); |
115 |
|
116 |
if (contTabs == 0) |
117 |
throw new EmptyTabsException(lastException); |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Obtiene el indice del tab seleccionado
|
122 |
* @return N?mero de tab seleccionado
|
123 |
*/
|
124 |
public int getSelectedTab() { |
125 |
return super.getTab().getSelectedIndex(); |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Ejecuta la acci?n de aceptar en el panel seleccionado
|
130 |
*/
|
131 |
public void acceptSelectedTab() { |
132 |
execAction(0);
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Ejecuta la acci?n de aplicar en el panel seleccionado
|
137 |
*/
|
138 |
public void applySelectedTab() { |
139 |
execAction(1);
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Ejecuta la acci?n de cancelar en el panel seleccionado
|
144 |
*/
|
145 |
public void cancelSelectedTab() { |
146 |
execAction(2);
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Ejecuta la acci?n en el panel seleccionado que se le indica en el
|
151 |
* par?metro
|
152 |
* @param action indicador de la acci?n a realizar
|
153 |
*/
|
154 |
private void execAction(int action) { |
155 |
if (extensionPoint == null) |
156 |
return;
|
157 |
if (getTab().getSelectedIndex() == -1) |
158 |
return;
|
159 |
// String title = getTab().getTitleAt(getTab().getSelectedIndex());
|
160 |
|
161 |
Iterator iterator = extensionPoint.keySet().iterator();
|
162 |
while (iterator.hasNext()) {
|
163 |
try {
|
164 |
String key = (String) iterator.next(); |
165 |
IRegistrablePanel panel = (IRegistrablePanel) extensionPoint.get(key); |
166 |
// if (key.equals(title)) {
|
167 |
switch (action) {
|
168 |
case 0: |
169 |
panel.accept(); |
170 |
break;
|
171 |
case 1: |
172 |
panel.apply(); |
173 |
break;
|
174 |
case 2: |
175 |
panel.cancel(); |
176 |
break;
|
177 |
} |
178 |
// }
|
179 |
} catch (ClassCastException e) { |
180 |
// No se ejecuta
|
181 |
continue;
|
182 |
} |
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* Asigna la visibilidad de un tab a verdadero o falso. La
|
188 |
* selecci?n del tab se hace por el identificador.
|
189 |
* @param tab Identificador del tab. Variable nom del mismo
|
190 |
* @param active True o false para visible o invisible.
|
191 |
*/
|
192 |
public void setTabVisible(String tab, boolean active){ |
193 |
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Selecciona el panel indicado por index
|
198 |
* @param index panel seleccionado
|
199 |
*/
|
200 |
public void setSelectedIndex(int index) { |
201 |
tabbedPane.setSelectedIndex(index); |
202 |
} |
203 |
|
204 |
/**
|
205 |
* Propagamos el evento de cambiar de pesta?a a todos los paneles.
|
206 |
*/
|
207 |
public void stateChanged(ChangeEvent e) { |
208 |
if(extensionPoint == null) |
209 |
return;
|
210 |
if(getTab().getSelectedIndex() == -1) |
211 |
return;
|
212 |
String title = getTab().getTitleAt(getTab().getSelectedIndex());
|
213 |
|
214 |
Iterator iterator = extensionPoint.keySet().iterator();
|
215 |
while (iterator.hasNext()) {
|
216 |
try {
|
217 |
String key = (String)iterator.next(); |
218 |
if(key.equals(title)){
|
219 |
IRegistrablePanel panel = (IRegistrablePanel)extensionPoint.get(key); |
220 |
panel.selectTab(key); |
221 |
} |
222 |
} catch (ClassCastException ex) { |
223 |
//No se ejecuta
|
224 |
continue;
|
225 |
} |
226 |
} |
227 |
} |
228 |
} |