root / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / gui / properties / dialog / RegistrableTabPanel.java @ 13916
History | View | Annotate | Download (6.34 KB)
1 | 12425 | nacho | /* 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 | 13599 | bsanchez | import java.lang.reflect.Constructor; |
22 | import java.lang.reflect.InvocationTargetException; |
||
23 | 12425 | nacho | 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 | 13622 | bsanchez | import org.gvsig.raster.util.RasterToolsUtil; |
31 | |||
32 | 13277 | nacho | import com.iver.cit.gvsig.fmap.layers.FLayer; |
33 | 12425 | nacho | 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 | 13654 | bsanchez | private static final long serialVersionUID = 4520599168652663582L; |
44 | 12425 | nacho | |
45 | 13589 | bsanchez | private ExtensionPoints extensionPoints = null; |
46 | private ExtensionPoint extensionPoint = null; |
||
47 | 13674 | bsanchez | public boolean accepted = false; |
48 | 12425 | nacho | |
49 | 13589 | bsanchez | static public Hashtable initialProperties = new Hashtable(); |
50 | 12425 | nacho | /**
|
51 | 13589 | bsanchez | * Tama?o en X del panel
|
52 | */
|
||
53 | protected int sizePanelX = 0; |
||
54 | 12425 | nacho | |
55 | /**
|
||
56 | 13589 | bsanchez | * Tama?o en Y del panel
|
57 | */
|
||
58 | protected int sizePanelY = 0; |
||
59 | 12425 | nacho | |
60 | /**
|
||
61 | * Constructor. Inicializa los paneles y propiedades
|
||
62 | * @param props Propiedades
|
||
63 | 13622 | bsanchez | * @throws EmptyTabsException
|
64 | 12425 | nacho | */
|
65 | 13622 | bsanchez | public RegistrableTabPanel(FLayer lyr) throws EmptyTabsException { |
66 | loadTabsFromExtensionPoints(lyr); |
||
67 | 12425 | nacho | getTabPane().addChangeListener(this);
|
68 | } |
||
69 | |||
70 | /**
|
||
71 | * Load register tabs inside the panel, reading these from extension points.
|
||
72 | 13622 | bsanchez | * @throws EmptyTabsException
|
73 | 12425 | nacho | */
|
74 | 13622 | bsanchez | private void loadTabsFromExtensionPoints(FLayer lyr) throws EmptyTabsException { |
75 | 12425 | nacho | extensionPoints = ExtensionPointsSingleton.getInstance(); |
76 | extensionPoint = (ExtensionPoint) extensionPoints.get("RasterSEPropertiesDialog");
|
||
77 | if (extensionPoint == null) |
||
78 | return;
|
||
79 | Iterator iterator = extensionPoint.keySet().iterator();
|
||
80 | 13622 | bsanchez | |
81 | Exception lastException = null; |
||
82 | int contTabs = 0; |
||
83 | 12425 | nacho | while (iterator.hasNext()) {
|
84 | try {
|
||
85 | String key = (String) iterator.next(); |
||
86 | 13589 | bsanchez | |
87 | 13599 | bsanchez | Class class1 = (Class) extensionPoint.get(key); |
88 | Constructor constructor = class1.getConstructor(null); |
||
89 | JPanel panel = (JPanel) constructor.newInstance(null); |
||
90 | |||
91 | 13600 | bsanchez | if (panel instanceof IRegistrablePanel) { |
92 | 13589 | bsanchez | ((IRegistrablePanel) panel).setLayer(lyr); |
93 | 13622 | bsanchez | if (((IRegistrablePanel) panel).isVisiblePanel() && ((IRegistrablePanel) panel).getLayerClass().isInstance(lyr)) {
|
94 | ((IRegistrablePanel) panel).initializeUI(); |
||
95 | super.addTab(((IRegistrablePanel) panel).getID(), panel);
|
||
96 | contTabs++; |
||
97 | } |
||
98 | 13600 | bsanchez | } |
99 | 13599 | bsanchez | } catch (NoSuchMethodException e) { |
100 | 13622 | bsanchez | lastException = e; |
101 | 13599 | bsanchez | } catch (IllegalArgumentException e) { |
102 | 13622 | bsanchez | lastException = e; |
103 | 13599 | bsanchez | } catch (InstantiationException e) { |
104 | 13622 | bsanchez | lastException = e; |
105 | 13599 | bsanchez | } catch (IllegalAccessException e) { |
106 | 13622 | bsanchez | lastException = e; |
107 | 13599 | bsanchez | } catch (InvocationTargetException e) { |
108 | 13622 | bsanchez | lastException = e; |
109 | 12425 | nacho | } catch (ClassCastException e) { |
110 | 13622 | bsanchez | lastException = e; |
111 | 12425 | nacho | } |
112 | } |
||
113 | 13622 | bsanchez | |
114 | 13626 | bsanchez | if (lastException != null) |
115 | RasterToolsUtil.messageBoxError("No se pudo crear correctamente el panel de propiedades.", this, lastException); |
||
116 | 13622 | bsanchez | |
117 | if (contTabs == 0) |
||
118 | throw new EmptyTabsException(lastException); |
||
119 | 12425 | nacho | } |
120 | |||
121 | /**
|
||
122 | 13627 | bsanchez | * Obtiene el indice del tab seleccionado
|
123 | * @return N?mero de tab seleccionado
|
||
124 | */
|
||
125 | 12425 | nacho | 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 | 13654 | bsanchez | public void execAction(int action) { |
156 | 13630 | bsanchez | for (int i = 0; i < super.getTabPane().getTabCount(); i++) { |
157 | if (!(getTabPane().getComponent(i) instanceof IRegistrablePanel)) |
||
158 | continue;
|
||
159 | 12425 | nacho | try {
|
160 | 13630 | bsanchez | IRegistrablePanel panel = (IRegistrablePanel) getTabPane().getComponent(i); |
161 | 12425 | nacho | switch (action) {
|
162 | case 0: |
||
163 | 13674 | bsanchez | accepted = true;
|
164 | 12425 | nacho | 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 | 13674 | bsanchez | |
219 | public boolean isAccepted() { |
||
220 | return accepted;
|
||
221 | } |
||
222 | 12425 | nacho | } |