root / branches / gvSIG_03_SLD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / legendmanager / panels / FPanelLegendBreaks.java @ 2102
History | View | Annotate | Download (24.7 KB)
1 |
/*
|
---|---|
2 |
* Created on 30-abr-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.gui.thememanager.legendmanager.panels; |
48 |
|
49 |
import java.awt.BorderLayout; |
50 |
import java.awt.Color; |
51 |
import java.awt.GridBagConstraints; |
52 |
import java.awt.GridBagLayout; |
53 |
import java.awt.Insets; |
54 |
import java.awt.event.ActionEvent; |
55 |
import java.awt.event.ActionListener; |
56 |
import java.text.NumberFormat; |
57 |
import java.util.ArrayList; |
58 |
import java.util.Date; |
59 |
|
60 |
import javax.swing.DefaultComboBoxModel; |
61 |
import javax.swing.JButton; |
62 |
import javax.swing.JComboBox; |
63 |
import javax.swing.JLabel; |
64 |
import javax.swing.JOptionPane; |
65 |
import javax.swing.JPanel; |
66 |
import javax.swing.JTextField; |
67 |
|
68 |
import org.apache.log4j.Logger; |
69 |
|
70 |
import com.hardcode.gdbms.engine.data.DataSource; |
71 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
72 |
import com.hardcode.gdbms.engine.values.FloatValue; |
73 |
import com.hardcode.gdbms.engine.values.IntValue; |
74 |
import com.hardcode.gdbms.engine.values.LongValue; |
75 |
import com.hardcode.gdbms.engine.values.NullValue; |
76 |
import com.hardcode.gdbms.engine.values.Value; |
77 |
import com.iver.andami.PluginServices; |
78 |
import com.iver.cit.gvsig.fmap.DriverException; |
79 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
80 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
81 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
82 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
83 |
import com.iver.cit.gvsig.fmap.rendering.FInterval; |
84 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
85 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
86 |
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
87 |
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel; |
88 |
|
89 |
|
90 |
/**
|
91 |
* DOCUMENT ME!
|
92 |
*
|
93 |
* @author fjp To change the template for this generated type comment go to
|
94 |
* Window>Preferences>Java>Code Generation>Code and
|
95 |
* Comments
|
96 |
*/
|
97 |
public class FPanelLegendBreaks extends JPanel implements ILegendPanel { |
98 |
private static Logger logger = Logger.getLogger(FPanelLegendBreaks.class.getName()); |
99 |
private MyListener listener = new MyListener(); |
100 |
|
101 |
// private TOC m_TOC;
|
102 |
private VectorialIntervalLegend m_Renderer;
|
103 |
private ClassifiableVectorial m_lyr;
|
104 |
private FSymbolTable m_symbolTable = new FSymbolTable("intervals"); |
105 |
private JComboBox m_cboFields; |
106 |
private JComboBox m_cboIntervalType; |
107 |
private JTextField m_txtNumIntervals; |
108 |
private ColorChooserPanel m_colorChooser1;
|
109 |
private ColorChooserPanel m_colorChooser2;
|
110 |
private JButton m_btnDeleteAll; |
111 |
private JButton m_btnDelete; |
112 |
private FInterval[] intervals; |
113 |
///private int tipoClasificacion = VectorialIntervalLegend.NATURAL_INTERVALS;
|
114 |
private int count = 0; |
115 |
|
116 |
/**
|
117 |
*
|
118 |
*/
|
119 |
public FPanelLegendBreaks() {
|
120 |
super();
|
121 |
initComponents(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* EQUAL INTERVAL Devuelve un Array con el n?mero de intervalos que se
|
126 |
* quieren crear. Los intervalos se crean con un tama?o igual entre ellos.
|
127 |
*
|
128 |
* @param numIntervals n?mero de intervalos
|
129 |
* @param minValue Valor m?nimo.
|
130 |
* @param maxValue Valor m?ximo.
|
131 |
*
|
132 |
* @return Array con los intervalos.
|
133 |
*/
|
134 |
FInterval[] calculateEqualIntervals(int numIntervals, |
135 |
double minValue, double maxValue,String fieldName) { |
136 |
FInterval[] theIntervalArray = new FInterval[numIntervals]; |
137 |
double step = (maxValue - minValue) / numIntervals;
|
138 |
|
139 |
if (numIntervals>1){ |
140 |
theIntervalArray[0] = new FInterval(minValue,minValue+step); |
141 |
for (int i = 1; i < numIntervals-1; i++) { |
142 |
theIntervalArray[i] = new FInterval(minValue + (i * step)+0.01, |
143 |
minValue + ((i + 1) * step));
|
144 |
} |
145 |
theIntervalArray[numIntervals-1] = new FInterval(minValue + ((numIntervals-1) * step)+0.01,maxValue); |
146 |
}else{
|
147 |
theIntervalArray[0] = new FInterval(minValue, maxValue); |
148 |
} |
149 |
return theIntervalArray;
|
150 |
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* NATURAL INTERVAL Devuelve un Array con el n?mero de intervalos que se
|
155 |
* quieren crear. Los intervalos se distribuyen de forma natural.
|
156 |
*
|
157 |
* @param numIntervals n?mero de intervalos
|
158 |
* @param minValue Valor m?nimo.
|
159 |
* @param maxValue Valor m?ximo.
|
160 |
*
|
161 |
* @return Array con los intervalos.
|
162 |
*/
|
163 |
FInterval[] calculateNaturalIntervals(int numIntervals, double minValue, |
164 |
double maxValue,String fieldName) { |
165 |
|
166 |
NaturalIntervalGenerator intervalGenerator = new NaturalIntervalGenerator(((AlphanumericData) m_lyr),fieldName,numIntervals);
|
167 |
|
168 |
try {
|
169 |
intervalGenerator.generarIntervalos(); |
170 |
} catch (DriverException e) {
|
171 |
e.printStackTrace(); |
172 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
173 |
e.printStackTrace(); |
174 |
} |
175 |
int numIntervalsGen=intervalGenerator.getNumIntervals()-1; |
176 |
if (numIntervalsGen==-1){ |
177 |
//TODO cuando no puede calcular los intervalos.
|
178 |
numIntervalsGen=1;
|
179 |
} |
180 |
FInterval[] theIntervalArray = new FInterval[numIntervalsGen]; |
181 |
if (numIntervalsGen>1){ |
182 |
|
183 |
theIntervalArray[0] = new FInterval(minValue, intervalGenerator.getValorRuptura(0)); |
184 |
for (int i = 1; i < numIntervalsGen-1; i++) { |
185 |
theIntervalArray[i] = new FInterval(intervalGenerator.getValInit(
|
186 |
i-1), intervalGenerator.getValorRuptura(i));
|
187 |
} |
188 |
|
189 |
theIntervalArray[numIntervalsGen-1] = new FInterval(intervalGenerator.getValInit( |
190 |
numIntervalsGen-2), maxValue);
|
191 |
}else{
|
192 |
theIntervalArray[numIntervalsGen-1] = new FInterval(minValue, maxValue); |
193 |
} |
194 |
return theIntervalArray;
|
195 |
} |
196 |
|
197 |
/**
|
198 |
* QUANTILE INTERVAL Devuelve un Array con el n?mero de intervalos que se
|
199 |
* quieren crear. Los intervalos se distribuyen de forma quantile.
|
200 |
*
|
201 |
* @param numIntervals n?mero de intervalos
|
202 |
* @param minValue Valor m?nimo.
|
203 |
* @param maxValue Valor m?ximo.
|
204 |
*
|
205 |
* @return Array con los intervalos.
|
206 |
*/
|
207 |
FInterval[] calculateQuantileIntervals(int numIntervals, double minValue, |
208 |
double maxValue,String fieldName) { |
209 |
QuantileIntervalGenerator intervalGenerator = new QuantileIntervalGenerator(((AlphanumericData) m_lyr),fieldName,numIntervals);
|
210 |
|
211 |
try {
|
212 |
intervalGenerator.generarIntervalos(); |
213 |
} catch (DriverException e) {
|
214 |
e.printStackTrace(); |
215 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
216 |
e.printStackTrace(); |
217 |
} |
218 |
int numIntervalsGen=intervalGenerator.getNumIntervalGen();
|
219 |
FInterval[] theIntervalArray = new FInterval[numIntervalsGen]; |
220 |
if (intervalGenerator.getNumIntervalGen()>1){ |
221 |
theIntervalArray[0] = new FInterval(minValue, intervalGenerator.getValRuptura(0)); |
222 |
for (int i = 1; i < numIntervalsGen-1; i++) { |
223 |
theIntervalArray[i] = new FInterval(intervalGenerator.getValInit(
|
224 |
i-1), intervalGenerator.getValRuptura(i));
|
225 |
} |
226 |
|
227 |
theIntervalArray[numIntervalsGen-1] = new FInterval(intervalGenerator.getValInit( |
228 |
numIntervalsGen-2), maxValue);
|
229 |
}else{
|
230 |
theIntervalArray[numIntervalsGen-1] = new FInterval(minValue, maxValue); |
231 |
} |
232 |
return theIntervalArray;
|
233 |
|
234 |
|
235 |
/* double numQ = count / numIntervals;
|
236 |
|
237 |
for (int i = 0; i < count; i++) {
|
238 |
}
|
239 |
|
240 |
return theIntervalArray;
|
241 |
*/
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* DOCUMENT ME!
|
246 |
*/
|
247 |
protected void initComponents() { |
248 |
/* JLabel label = new JLabel();
|
249 |
label.setIcon(new javax.swing.ImageIcon(Abrir.class.getClassLoader()
|
250 |
.getResource("images/ValoresUnicos.png")));
|
251 |
limagen[1] = new JLabel();
|
252 |
limagen[1] = label; */
|
253 |
JPanel botonestabla = new JPanel(); |
254 |
|
255 |
JButton btnAddAll = new JButton(PluginServices.getText(this, |
256 |
"Calcular_intervalos"));
|
257 |
btnAddAll.setActionCommand("ADD_ALL_VALUES");
|
258 |
botonestabla.add(btnAddAll); |
259 |
|
260 |
JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir")); |
261 |
btnAdd.setActionCommand("ADD_VALUE");
|
262 |
btnAdd.addActionListener(listener); |
263 |
botonestabla.add(btnAdd); |
264 |
|
265 |
m_btnDeleteAll = new JButton(PluginServices.getText(this, "Quitar_todos")); |
266 |
m_btnDeleteAll.setActionCommand("REMOVE_ALL");
|
267 |
m_btnDeleteAll.addActionListener(listener); |
268 |
botonestabla.add(m_btnDeleteAll); |
269 |
|
270 |
m_btnDelete = new JButton(PluginServices.getText(this, "Quitar")); |
271 |
m_btnDelete.setActionCommand("REMOVE");
|
272 |
m_btnDelete.addActionListener(listener); |
273 |
botonestabla.add(m_btnDelete); |
274 |
|
275 |
m_btnDeleteAll.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
|
276 |
public void propertyChange(java.beans.PropertyChangeEvent e) { |
277 |
if ((e.getPropertyName().equals("enabled"))) { |
278 |
System.out.println("propertyChange(enabled)"); // TODO Auto-generated property Event stub "enabled" |
279 |
} |
280 |
} |
281 |
}); |
282 |
m_btnDelete.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
|
283 |
public void propertyChange(java.beans.PropertyChangeEvent e) { |
284 |
if ((e.getPropertyName().equals("enabled"))) { |
285 |
System.out.println("propertyChange(enabled)"); // TODO Auto-generated property Event stub "enabled" |
286 |
} |
287 |
} |
288 |
}); |
289 |
btnAddAll.addActionListener(listener); |
290 |
|
291 |
JPanel ptabla = new JPanel(); |
292 |
ptabla.setLayout(new BorderLayout()); |
293 |
|
294 |
m_cboFields = new JComboBox(); |
295 |
m_cboFields.setActionCommand("FIELD_SELECTED");
|
296 |
m_cboFields.addActionListener(listener); |
297 |
m_cboFields.setVisible(true);
|
298 |
|
299 |
JPanel pAux1 = new JPanel(); |
300 |
|
301 |
/* pAux1.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
302 |
"Campo de clasificaci?n",
|
303 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
|
304 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); */
|
305 |
|
306 |
// pAux1.setPreferredSize(new Dimension(300,50));
|
307 |
GridBagLayout gridBag = new GridBagLayout(); |
308 |
pAux1.setLayout(gridBag); |
309 |
|
310 |
GridBagConstraints c = new GridBagConstraints(); |
311 |
|
312 |
c.anchor = GridBagConstraints.WEST;
|
313 |
|
314 |
JLabel lblFieldClassification = new JLabel(PluginServices.getText( |
315 |
this, "Campo_de_clasificacion")); |
316 |
c.gridx = 0;
|
317 |
c.gridy = 0;
|
318 |
c.insets = new Insets(5, 5, 2, 2); |
319 |
c.gridwidth = 1;
|
320 |
gridBag.setConstraints(lblFieldClassification, c); |
321 |
pAux1.add(lblFieldClassification); |
322 |
|
323 |
c.gridx = 1;
|
324 |
c.gridy = 0;
|
325 |
gridBag.setConstraints(m_cboFields, c); |
326 |
pAux1.add(m_cboFields); |
327 |
|
328 |
JLabel lblNumIntervals = new JLabel(PluginServices.getText(this, |
329 |
"No_de_intervalos") + ":"); |
330 |
c.gridx = 3;
|
331 |
c.gridy = 0;
|
332 |
gridBag.setConstraints(lblNumIntervals, c); |
333 |
pAux1.add(lblNumIntervals); |
334 |
|
335 |
m_txtNumIntervals = new JTextField(4); |
336 |
c.gridx = 4;
|
337 |
c.gridy = 0;
|
338 |
gridBag.setConstraints(m_txtNumIntervals, c); |
339 |
m_txtNumIntervals.setText("5");
|
340 |
pAux1.add(m_txtNumIntervals); |
341 |
|
342 |
JLabel lblIntervalType = new JLabel(PluginServices.getText(this, |
343 |
"tipo_de_intervalo"));
|
344 |
c.gridx = 0;
|
345 |
c.gridy = 1;
|
346 |
c.insets = new Insets(5, 5, 2, 2); |
347 |
c.gridwidth = 1;
|
348 |
gridBag.setConstraints(lblIntervalType, c); |
349 |
pAux1.add(lblIntervalType); |
350 |
|
351 |
m_cboIntervalType = new JComboBox(); |
352 |
m_cboIntervalType.setActionCommand("INTERVAL_TYPE");
|
353 |
m_cboIntervalType.addActionListener(listener); |
354 |
m_cboIntervalType.addItem("EQUAL_INTERVALS");
|
355 |
m_cboIntervalType.addItem("NATURAL_INTERVALS");
|
356 |
m_cboIntervalType.addItem("QUANTILE_INTERVALS");
|
357 |
m_cboIntervalType.setVisible(true);
|
358 |
|
359 |
c.gridx = 1;
|
360 |
c.gridy = 1;
|
361 |
gridBag.setConstraints(m_cboIntervalType, c); |
362 |
pAux1.add(m_cboIntervalType); |
363 |
|
364 |
c.insets = new Insets(2, 2, 2, 2); |
365 |
|
366 |
JLabel lblColor1 = new JLabel(PluginServices.getText(this, |
367 |
"Color_inicio") + ":"); |
368 |
c.gridx = 0;
|
369 |
c.gridy = 2;
|
370 |
gridBag.setConstraints(lblColor1, c); |
371 |
pAux1.add(lblColor1); |
372 |
|
373 |
m_colorChooser1 = new ColorChooserPanel();
|
374 |
m_colorChooser1.setColor(Color.red);
|
375 |
m_colorChooser1.setAlpha(255);
|
376 |
c.gridx = 1;
|
377 |
c.gridy = 2;
|
378 |
gridBag.setConstraints(m_colorChooser1, c); |
379 |
pAux1.add(m_colorChooser1); |
380 |
|
381 |
JLabel lblColor2 = new JLabel(PluginServices.getText(this, "Color_final") + |
382 |
":");
|
383 |
c.gridx = 3;
|
384 |
c.gridy = 2;
|
385 |
gridBag.setConstraints(lblColor2, c); |
386 |
pAux1.add(lblColor2); |
387 |
|
388 |
m_colorChooser2 = new ColorChooserPanel();
|
389 |
m_colorChooser2.setColor(Color.blue);
|
390 |
m_colorChooser2.setAlpha(255);
|
391 |
c.gridx = 4;
|
392 |
c.gridy = 2;
|
393 |
gridBag.setConstraints(m_colorChooser2, c); |
394 |
pAux1.add(m_colorChooser2); |
395 |
|
396 |
ptabla.add(m_symbolTable, BorderLayout.CENTER);
|
397 |
this.setLayout(new BorderLayout()); |
398 |
this.add(pAux1, BorderLayout.NORTH); |
399 |
this.add(ptabla, BorderLayout.CENTER); |
400 |
this.add(botonestabla, BorderLayout.SOUTH); |
401 |
} |
402 |
|
403 |
/**
|
404 |
* Damos una primera pasada para saber los l?mites inferior y superior y
|
405 |
* rellenar un array con los valores. Luego dividimos ese array en
|
406 |
* intervalos.
|
407 |
*/
|
408 |
private void fillTableValues() { |
409 |
FInterval[] arrayIntervalos = null; |
410 |
DataSource elRs;
|
411 |
m_symbolTable.removeAllItems(); |
412 |
|
413 |
try {
|
414 |
elRs = ((AlphanumericData) m_lyr).getRecordset(); |
415 |
logger.debug("elRs.start()");
|
416 |
elRs.start(); |
417 |
|
418 |
int idField = -1; |
419 |
int numIntervalos=1; |
420 |
try{
|
421 |
numIntervalos= Integer.parseInt(m_txtNumIntervals.getText());
|
422 |
}catch (NumberFormatException e) { |
423 |
System.out.println("Foramto de n?mero erroneo"); |
424 |
} |
425 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
426 |
System.out.println("Nombre del campo de clasificaci?n: " + |
427 |
fieldName); |
428 |
m_Renderer.setFieldName(fieldName); |
429 |
|
430 |
String nomField = m_Renderer.getFieldName();
|
431 |
|
432 |
// Cogemos el tipo de gradaci?n de colores que quiere el usuario y
|
433 |
// Creamos el primer y ?ltimo color.
|
434 |
Color startColor = m_colorChooser1.getColor();
|
435 |
m_Renderer.setStartColor(startColor); |
436 |
|
437 |
Color endColor = m_colorChooser2.getColor();
|
438 |
m_Renderer.setEndColor(endColor); |
439 |
|
440 |
|
441 |
|
442 |
for (int i = 0; i < elRs.getFieldCount(); i++) { |
443 |
String nomAux = elRs.getFieldName(i).trim();
|
444 |
|
445 |
if (nomField.compareToIgnoreCase(nomAux) == 0) { |
446 |
idField = i; |
447 |
|
448 |
break;
|
449 |
} |
450 |
} |
451 |
|
452 |
if (idField == -1) { |
453 |
System.err.println("Campo no reconocido " + nomField); |
454 |
|
455 |
return;
|
456 |
} |
457 |
|
458 |
///m_symbolTable.removeAllItems();
|
459 |
///m_valuesCache = new Object[m_lyr.getSource().getShapeCount()];
|
460 |
int numSymbols = 0; |
461 |
FSymbol theSymbol; |
462 |
Date valorDate;
|
463 |
double minValue = Double.MAX_VALUE; |
464 |
double maxValue = Double.MIN_VALUE; |
465 |
Date minValueDate = null; |
466 |
Date maxValueDate = null; |
467 |
|
468 |
VectorialIntervalLegend auxLegend; |
469 |
auxLegend = LegendFactory.createVectorialIntervalLegend(m_lyr.getShapeType()); |
470 |
|
471 |
Value clave; |
472 |
Object resul;
|
473 |
int symbolType = 0; |
474 |
count = 0;
|
475 |
|
476 |
for (int j = 0; j < elRs.getRowCount(); j++) { |
477 |
clave = elRs.getFieldValue(j, idField); |
478 |
|
479 |
FInterval interval = auxLegend.getInterval(clave); |
480 |
|
481 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
|
482 |
if (auxLegend.getSymbolByInterval(interval) == null) { |
483 |
//si no esta creado el simbolo se crea
|
484 |
double valor = 0; |
485 |
symbolType = m_lyr.getShapeType(); |
486 |
|
487 |
if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.IntValue") { |
488 |
valor = ((IntValue) clave).getValue(); |
489 |
} else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.DoubleValue") { |
490 |
valor = ((DoubleValue) clave).getValue(); |
491 |
} else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.FloatValue") { |
492 |
valor = ((FloatValue) clave).getValue(); |
493 |
} else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.LongValue") { |
494 |
valor = ((LongValue) clave).getValue(); |
495 |
} else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.DateValue") { |
496 |
//TODO POR IMPLEMENTAR
|
497 |
///valorDate = elRs.getFieldValueAsDate(idField);
|
498 |
///if (valorDate.before(minValueDate)) minValueDate = valorDate;
|
499 |
///if (valorDate.after(maxValueDate)) maxValueDate = valorDate;
|
500 |
} |
501 |
|
502 |
if (valor < minValue) {
|
503 |
minValue = (double) valor;
|
504 |
} |
505 |
|
506 |
if (valor > maxValue) {
|
507 |
maxValue = (double) valor;
|
508 |
} |
509 |
} |
510 |
|
511 |
count++; |
512 |
} |
513 |
|
514 |
switch (m_Renderer.getIntervalType()) {
|
515 |
case VectorialIntervalLegend.EQUAL_INTERVALS:
|
516 |
arrayIntervalos = calculateEqualIntervals(numIntervalos, |
517 |
minValue, maxValue,fieldName); |
518 |
|
519 |
break;
|
520 |
|
521 |
case VectorialIntervalLegend.NATURAL_INTERVALS:
|
522 |
arrayIntervalos = calculateNaturalIntervals(numIntervalos, |
523 |
minValue, maxValue,fieldName); |
524 |
|
525 |
break;
|
526 |
|
527 |
case VectorialIntervalLegend.QUANTILE_INTERVALS:
|
528 |
arrayIntervalos = calculateQuantileIntervals(numIntervalos, |
529 |
minValue, maxValue,fieldName); |
530 |
|
531 |
break;
|
532 |
} |
533 |
|
534 |
intervals = arrayIntervalos; |
535 |
|
536 |
FInterval elIntervalo; |
537 |
NumberFormat.getInstance().setMaximumFractionDigits(2); |
538 |
m_Renderer.clear(); |
539 |
|
540 |
int r;
|
541 |
int g;
|
542 |
int b;
|
543 |
int stepR;
|
544 |
int stepG;
|
545 |
int stepB;
|
546 |
r = startColor.getRed(); |
547 |
g = startColor.getGreen(); |
548 |
b = startColor.getBlue(); |
549 |
stepR = (endColor.getRed() - r) / arrayIntervalos.length; |
550 |
stepG = (endColor.getGreen() - g) / arrayIntervalos.length; |
551 |
stepB = (endColor.getBlue() - b) / arrayIntervalos.length; |
552 |
for (int k = 0; k < arrayIntervalos.length; k++) { |
553 |
elIntervalo = arrayIntervalos[k]; |
554 |
|
555 |
// clave = elIntervalo; // elIntervalo.getMin() + " - " + elIntervalo.getMax();
|
556 |
// System.out.println("k = " + k + " clave = " + clave);
|
557 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
|
558 |
// if (!m_Renderer.m_symbolList.containsKey(elIntervalo)) {
|
559 |
//si no esta creado el simbolo se crea
|
560 |
theSymbol = new FSymbol(symbolType, new Color(r, g, b)); |
561 |
theSymbol.setDescription(NumberFormat.getInstance().format(elIntervalo.getMin()) +
|
562 |
" - " +
|
563 |
NumberFormat.getInstance().format(elIntervalo.getMax()));
|
564 |
|
565 |
//////////////////////////////////////
|
566 |
// CALCULAMOS UN COLOR APROPIADO
|
567 |
r = r + stepR; |
568 |
g = g + stepG; |
569 |
b = b + stepB; |
570 |
|
571 |
/////////////////////////////////
|
572 |
m_Renderer.addSymbol(elIntervalo, theSymbol); |
573 |
System.out.println("addSymbol = " + elIntervalo + |
574 |
" theSymbol = " + theSymbol.getDescription());
|
575 |
numSymbols++; |
576 |
|
577 |
if (numSymbols > 100) { |
578 |
JOptionPane.showMessageDialog(this, |
579 |
"M?s 100 de s?mbolos no aportan informaci?n en un plano. Por favor, revise el campo seleccionado.");
|
580 |
|
581 |
break;
|
582 |
} |
583 |
|
584 |
// }
|
585 |
} // for
|
586 |
|
587 |
System.out.println("Num. Simbolos = " + |
588 |
m_Renderer.getValues().length); |
589 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(), |
590 |
m_Renderer.getValues(), m_Renderer.getDescriptions()); |
591 |
elRs.stop(); |
592 |
} catch (DriverException e) {
|
593 |
// TODO Auto-generated catch block
|
594 |
e.printStackTrace(); |
595 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
596 |
e.printStackTrace(); |
597 |
} |
598 |
|
599 |
m_btnDeleteAll.setEnabled(true);
|
600 |
m_btnDelete.setEnabled(true);
|
601 |
} |
602 |
|
603 |
/**
|
604 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo
|
605 |
* el symbolList, si no tambi?n el arrayKeys y el defaultRenderer
|
606 |
*/
|
607 |
private void fillSymbolListFromTable() { |
608 |
String clave;
|
609 |
FSymbol theSymbol; |
610 |
FInterval theInterval = null;
|
611 |
|
612 |
// Borramos las anteriores listas:
|
613 |
m_Renderer.clear(); |
614 |
|
615 |
boolean bRestoValores = false; // PONERLO EN UN CHECKBOX |
616 |
double from = 0; |
617 |
double to = 0; |
618 |
String[] arraySplit = new String[2]; |
619 |
int hasta;
|
620 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
621 |
m_Renderer.setFieldName(fieldName); |
622 |
|
623 |
if (bRestoValores) {
|
624 |
hasta = m_symbolTable.getRowCount() - 1;
|
625 |
} else {
|
626 |
hasta = m_symbolTable.getRowCount(); |
627 |
} |
628 |
|
629 |
for (int row = 0; row < m_symbolTable.getRowCount(); row++) { |
630 |
// clave = m_symbolTable.getFieldValue(row,1);
|
631 |
theInterval = (FInterval) m_symbolTable.getFieldValue(row, 1);
|
632 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(row, 0);
|
633 |
theSymbol.setDescription((String) m_symbolTable.getFieldValue(row, 2)); |
634 |
m_Renderer.addSymbol(theInterval, theSymbol); |
635 |
|
636 |
///m_Renderer.m_legendIntervals.add(theInterval);
|
637 |
} |
638 |
|
639 |
if (bRestoValores) {
|
640 |
//m_Renderer.m_bUseDefaultSymbol = true;
|
641 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(hasta, 0);
|
642 |
m_Renderer.setDefaultSymbol(theSymbol); |
643 |
} |
644 |
} |
645 |
|
646 |
/**
|
647 |
* DOCUMENT ME!
|
648 |
*/
|
649 |
private void fillFieldNames() { |
650 |
DataSource rs = null; |
651 |
ArrayList nomFields = null; |
652 |
|
653 |
try {
|
654 |
rs = ((AlphanumericData) m_lyr).getRecordset(); |
655 |
logger.debug("rs.start()");
|
656 |
rs.start(); |
657 |
|
658 |
nomFields = new ArrayList(); |
659 |
|
660 |
Value val; |
661 |
|
662 |
for (int i = 0; i < rs.getFieldCount(); i++) { |
663 |
//TODO deber?a de existir un getFieldType
|
664 |
val = rs.getFieldValue(0, i);
|
665 |
|
666 |
if (val.getClass() == NullValue.class) {
|
667 |
continue;
|
668 |
} |
669 |
|
670 |
if ((val.getClass() == IntValue.class) ||
|
671 |
(val.getClass() == DoubleValue.class) || |
672 |
(val.getClass() == FloatValue.class) || |
673 |
(val.getClass() == LongValue.class)) { |
674 |
nomFields.add(rs.getFieldName(i).trim()); |
675 |
} |
676 |
} |
677 |
|
678 |
rs.stop(); |
679 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
680 |
e1.printStackTrace(); |
681 |
} catch (DriverException e) {
|
682 |
e.printStackTrace(); |
683 |
} |
684 |
|
685 |
/* ArrayList nomFields = new ArrayList();
|
686 |
for (int i = 0; i < rs.getFieldsCount(); i++) {
|
687 |
if ((rs.getFieldType(i) == FRecordset.INTEGER) ||
|
688 |
(rs.getFieldType(i) == FRecordset.DECIMAL) ||
|
689 |
(rs.getFieldType(i) == FRecordset.DATE))
|
690 |
{
|
691 |
nomFields.add(rs.getFieldName(i).trim());
|
692 |
}
|
693 |
|
694 |
}
|
695 |
*/
|
696 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray()); |
697 |
m_cboFields.setModel(cM); |
698 |
|
699 |
// fieldsListValor.setSelectedIndex(0);
|
700 |
m_symbolTable.removeAllItems(); |
701 |
} |
702 |
|
703 |
/**
|
704 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer,
|
705 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
706 |
*/
|
707 |
public void setLayer(FLayer lyr, Legend r) { |
708 |
// m_TOC = t;
|
709 |
// OJO, COMPROBAR ANTES SI ES DE TIPO VECTORIAL
|
710 |
// m_lyr = (FLyrVect) t.getFirstLyrVectSelected();
|
711 |
m_lyr = (ClassifiableVectorial) lyr; |
712 |
fillFieldNames(); |
713 |
|
714 |
if (r instanceof VectorialIntervalLegend) { |
715 |
m_Renderer = (VectorialIntervalLegend) r; |
716 |
m_cboFields.getModel().setSelectedItem(m_Renderer.getFieldName()); |
717 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(), |
718 |
m_Renderer.getValues(), m_Renderer.getDescriptions()); |
719 |
m_colorChooser1.setColor(m_Renderer.getStartColor()); |
720 |
m_colorChooser2.setColor(m_Renderer.getEndColor()); |
721 |
m_colorChooser1.repaint(); |
722 |
m_colorChooser2.repaint(); |
723 |
} else {
|
724 |
try {
|
725 |
// Si la capa viene con otro tipo de leyenda, creamos
|
726 |
// una nueva del tipo que maneja este panel
|
727 |
m_Renderer = new VectorialIntervalLegend(m_lyr.getShapeType());
|
728 |
} catch (DriverException e) {
|
729 |
// TODO Auto-generated catch block
|
730 |
e.printStackTrace(); |
731 |
} |
732 |
} |
733 |
m_cboIntervalType.setSelectedIndex(m_Renderer.getIntervalType()); |
734 |
} |
735 |
|
736 |
/**
|
737 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
738 |
*/
|
739 |
public Legend getLegend() {
|
740 |
fillSymbolListFromTable(); |
741 |
|
742 |
return m_Renderer;
|
743 |
} |
744 |
|
745 |
/**
|
746 |
* DOCUMENT ME!
|
747 |
*
|
748 |
* @author Vicente Caballero Navarro
|
749 |
*/
|
750 |
class MyListener implements ActionListener { |
751 |
//private FLyrShp m_layer;
|
752 |
// private FPanelLegendValues m_Parent;
|
753 |
public MyListener() { // FPanelLegendValues p) { |
754 |
|
755 |
// m_Parent = p;
|
756 |
} |
757 |
|
758 |
/**
|
759 |
* DOCUMENT ME!
|
760 |
*
|
761 |
* @param e DOCUMENT ME!
|
762 |
*/
|
763 |
public void actionPerformed(ActionEvent e) { |
764 |
// rellenarValue();
|
765 |
System.out.println("ActionEvent con " + e.getActionCommand()); |
766 |
|
767 |
//modificar el combobox de valor
|
768 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
769 |
JComboBox cb = (JComboBox) e.getSource(); |
770 |
String fieldName = (String) cb.getSelectedItem(); |
771 |
System.out.println("Nombre del campo: " + fieldName); |
772 |
m_symbolTable.removeAllItems(); |
773 |
|
774 |
m_Renderer.setFieldName(fieldName); |
775 |
} else if (e.getActionCommand() == "INTERVAL_TYPE") { |
776 |
JComboBox cb = (JComboBox) e.getSource(); |
777 |
|
778 |
if (m_Renderer!=null && cb.getSelectedIndex() != m_Renderer.getIntervalType()) { |
779 |
m_Renderer.setIntervalType(cb.getSelectedIndex()); |
780 |
m_symbolTable.removeAllItems(); |
781 |
} |
782 |
|
783 |
} |
784 |
|
785 |
//A?adir todos los elementos por valor
|
786 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
787 |
fillTableValues(); |
788 |
} |
789 |
|
790 |
//A?adir un ?nico elemento
|
791 |
if (e.getActionCommand() == "ADD_VALUE") { |
792 |
/* a?adir("Nuevo_Valor");
|
793 |
aceptar.setEnabled(true);
|
794 |
quitartodo.setEnabled(true);
|
795 |
quitar.setEnabled(true); */
|
796 |
} |
797 |
|
798 |
//Vacia la tabla
|
799 |
if (e.getActionCommand() == "REMOVE_ALL") { |
800 |
m_symbolTable.removeAllItems(); |
801 |
|
802 |
// aceptar.setEnabled(false);
|
803 |
} |
804 |
|
805 |
//Quitar solo el elemento seleccionado
|
806 |
if (e.getActionCommand() == "REMOVE") { |
807 |
m_symbolTable.removeSelectedRows(); |
808 |
} |
809 |
} |
810 |
} |
811 |
} |