19 |
19 |
package org.gvsig.rastertools.properties.panels;
|
20 |
20 |
|
21 |
21 |
import java.awt.Color;
|
22 |
|
import java.io.IOException;
|
23 |
22 |
|
24 |
23 |
import javax.swing.JPanel;
|
25 |
24 |
|
26 |
25 |
import org.gvsig.gui.beans.checkslidertext.CheckColorSliderTextContainer;
|
27 |
26 |
import org.gvsig.gui.beans.doubleslider.DoubleSliderEvent;
|
28 |
27 |
import org.gvsig.gui.beans.doubleslider.DoubleSliderListener;
|
29 |
|
import org.gvsig.raster.util.RasterToolsUtil;
|
30 |
28 |
/**
|
31 |
29 |
* Panel con los 3 campos para introducir listas de valores RGB. Este gestiona
|
32 |
30 |
* los eventos de FocusListener para validar que los valores que se introducen
|
... | ... | |
43 |
41 |
private int[] rangeRed = null;
|
44 |
42 |
private int[] rangeGreen = null;
|
45 |
43 |
private int[] rangeBlue = null;
|
46 |
|
private boolean validValue = false;
|
47 |
44 |
CheckColorSliderTextContainer tRed = null;
|
48 |
45 |
CheckColorSliderTextContainer tGreen = null;
|
49 |
46 |
CheckColorSliderTextContainer tBlue = null;
|
... | ... | |
126 |
123 |
}
|
127 |
124 |
|
128 |
125 |
/**
|
129 |
|
* Obtiene el rango de valores a partir de la cadena de texto introducida por
|
130 |
|
* el usuario. Sirve para parsear el contenido de los campos de texto que
|
131 |
|
* contienen listas de valores para RGB.
|
132 |
|
*
|
133 |
|
* @param values
|
134 |
|
*/
|
135 |
|
public static int[] stringToInterval(String values) throws IOException {
|
136 |
|
int[] rangeTransparency = new int[2];
|
137 |
|
|
138 |
|
boolean dots = false;
|
139 |
|
for (int i = 0; i < values.length(); i++) {
|
140 |
|
char c = values.charAt(i);
|
141 |
|
if (c != ':' && (c < 48 || c > 57))
|
142 |
|
throw new IOException("Caracteres incorrectos en la cadena.");
|
143 |
|
if (c == ':' && dots)
|
144 |
|
throw new IOException("Se repite el caracter :.");
|
145 |
|
if (c == ':' && !dots)
|
146 |
|
dots = true;
|
147 |
|
if (c == ':' && (i == 0 || i == (values.length() - 1)))
|
148 |
|
throw new IOException("No puede comenzar ni acabar por :.");
|
149 |
|
}
|
150 |
|
|
151 |
|
if (dots) {
|
152 |
|
String[] interv = values.split(":");
|
153 |
|
int val1 = Integer.parseInt(interv[0]);
|
154 |
|
int val2 = Integer.parseInt(interv[1]);
|
155 |
|
if (val1 > 255 || val2 > 255)
|
156 |
|
throw new IOException("Valor de pixel erroneo.");
|
157 |
|
else {
|
158 |
|
if (val1 < val2) {
|
159 |
|
rangeTransparency[0] = val1;
|
160 |
|
rangeTransparency[1] = val2;
|
161 |
|
} else {
|
162 |
|
rangeTransparency[0] = val2;
|
163 |
|
rangeTransparency[1] = val1;
|
164 |
|
}
|
165 |
|
return rangeTransparency;
|
166 |
|
}
|
167 |
|
} else {
|
168 |
|
rangeTransparency[0] = rangeTransparency[1] = Integer.parseInt(values);
|
169 |
|
if (rangeTransparency[0] > 255)
|
170 |
|
throw new IOException("Valor de pixel erroneo.");
|
171 |
|
return rangeTransparency;
|
172 |
|
}
|
173 |
|
}
|
174 |
|
|
175 |
|
/**
|
176 |
126 |
* Obtiene la lista de valores del campo Blue.
|
177 |
127 |
*
|
178 |
128 |
* @return array multidimensional con los intervalos
|
... | ... | |
198 |
148 |
}
|
199 |
149 |
|
200 |
150 |
/**
|
201 |
|
* Obtiene true si los valores de RGB que han introducido son
|
202 |
|
* validos y false si no lo son.
|
203 |
|
* @return
|
204 |
|
*/
|
205 |
|
public boolean isValidValue() {
|
206 |
|
return validValue;
|
207 |
|
}
|
208 |
|
|
209 |
|
/**
|
210 |
151 |
* Activa o desactiva el control
|
211 |
152 |
* @param enable True activa el control y false lo desactiva
|
212 |
153 |
*/
|
... | ... | |
278 |
219 |
* encarga de la validaci?n de datos y actualizar los rangos de selecci?n
|
279 |
220 |
*/
|
280 |
221 |
public void validateValues() {
|
281 |
|
validValue = true;
|
282 |
|
rangeRed = null;
|
283 |
|
rangeGreen = null;
|
284 |
|
rangeBlue = null;
|
285 |
|
if (getTRed().isChecked()) {
|
286 |
|
try {
|
287 |
|
rangeRed = TranspByPixelRGBInputPanel.stringToInterval(getTRed().getValue() + "");
|
288 |
|
} catch (IOException exc) {
|
289 |
|
RasterToolsUtil.debug("Error al parsear el intervalo", this, exc);
|
290 |
|
getTRed().setChecked(false);
|
291 |
|
validValue = false;
|
292 |
|
}
|
293 |
|
}
|
|
222 |
rangeRed = new int[] {0, 255};
|
|
223 |
rangeGreen = new int[] {0, 255};
|
|
224 |
rangeBlue = new int[] {0, 255};
|
294 |
225 |
|
295 |
|
if (getTGreen().isChecked()) {
|
296 |
|
try {
|
297 |
|
rangeGreen = TranspByPixelRGBInputPanel.stringToInterval(getTGreen().getValue() + "");
|
298 |
|
} catch (IOException exc) {
|
299 |
|
RasterToolsUtil.debug("Error al parsear el intervalo", this, exc);
|
300 |
|
getTGreen().setChecked(false);
|
301 |
|
validValue = false;
|
302 |
|
}
|
303 |
|
}
|
|
226 |
if (getTRed().isChecked())
|
|
227 |
rangeRed[0] = rangeRed[1] = getTRed().getValue();
|
304 |
228 |
|
305 |
|
if (getTBlue().isChecked()) {
|
306 |
|
try {
|
307 |
|
rangeBlue = TranspByPixelRGBInputPanel.stringToInterval(getTBlue().getValue() + "");
|
308 |
|
} catch (IOException exc) {
|
309 |
|
RasterToolsUtil.debug("Error al parsear el intervalo", this, exc);
|
310 |
|
getTBlue().setChecked(false);
|
311 |
|
validValue = false;
|
312 |
|
}
|
313 |
|
}
|
|
229 |
if (getTGreen().isChecked())
|
|
230 |
rangeGreen[0] = rangeGreen[1] = getTGreen().getValue();
|
|
231 |
|
|
232 |
if (getTBlue().isChecked())
|
|
233 |
rangeBlue[0] = rangeBlue[1] = getTBlue().getValue();
|
314 |
234 |
}
|
315 |
235 |
|
316 |
236 |
/*
|