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