root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / legendmanager / panels / PanelLegendBreaks.java @ 7587
History | View | Annotate | Download (34.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.thememanager.legendmanager.panels; |
42 |
|
43 |
import com.hardcode.gdbms.engine.data.DataSource; |
44 |
import com.hardcode.gdbms.engine.values.DateValue; |
45 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
46 |
import com.hardcode.gdbms.engine.values.FloatValue; |
47 |
import com.hardcode.gdbms.engine.values.IntValue; |
48 |
import com.hardcode.gdbms.engine.values.LongValue; |
49 |
import com.hardcode.gdbms.engine.values.NullValue; |
50 |
import com.hardcode.gdbms.engine.values.Value; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
|
54 |
import com.iver.cit.gvsig.fmap.DriverException; |
55 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
57 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
58 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
59 |
import com.iver.cit.gvsig.fmap.rendering.FInterval; |
60 |
import com.iver.cit.gvsig.fmap.rendering.IInterval; |
61 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
62 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
63 |
import com.iver.cit.gvsig.fmap.rendering.NullIntervalValue; |
64 |
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
65 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
66 |
|
67 |
import org.apache.log4j.Logger; |
68 |
|
69 |
import java.awt.BorderLayout; |
70 |
import java.awt.Color; |
71 |
import java.awt.event.ActionEvent; |
72 |
import java.awt.event.ActionListener; |
73 |
|
74 |
import java.sql.Types; |
75 |
import java.text.NumberFormat; |
76 |
|
77 |
import java.util.ArrayList; |
78 |
|
79 |
import javax.swing.DefaultComboBoxModel; |
80 |
import javax.swing.JButton; |
81 |
import javax.swing.JCheckBox; |
82 |
import javax.swing.JComboBox; |
83 |
import javax.swing.JLabel; |
84 |
import javax.swing.JOptionPane; |
85 |
import javax.swing.JPanel; |
86 |
import javax.swing.JTextField; |
87 |
|
88 |
|
89 |
/**
|
90 |
* DOCUMENT ME!
|
91 |
*
|
92 |
* @author Vicente Caballero Navarro
|
93 |
*/
|
94 |
public class PanelLegendBreaks extends JPanel { |
95 |
private static Logger logger = Logger.getLogger(PanelLegendBreaks.class.getName()); |
96 |
private JPanel panelN = null; |
97 |
private JLabel lblField = null; |
98 |
private JComboBox cmbField = null; |
99 |
private JLabel lblNumIntervals = null; |
100 |
private JTextField txtNumIntervals = null; |
101 |
private JLabel lblInitColor = null; |
102 |
private JLabel lblEndColor = null; |
103 |
private ColorChooserPanel colorChooserPanel = null; |
104 |
private ColorChooserPanel colorChooserPanel1 = null; |
105 |
private JCheckBox chkdefaultvalues = null; |
106 |
private JLabel lblType = null; |
107 |
private JComboBox cmbFieldType = null; |
108 |
private JPanel panelS = null; |
109 |
private JButton bintervals = null; |
110 |
private JButton bInsert = null; |
111 |
private JButton bDelAll = null; |
112 |
private JButton bDel = null; |
113 |
private int count = 0; |
114 |
private ClassifiableVectorial m_lyr;
|
115 |
private VectorialIntervalLegend m_Renderer;
|
116 |
private VectorialIntervalLegend auxLegend = null; |
117 |
private FSymbolTable m_symbolTable = new FSymbolTable("intervals"); |
118 |
private MyListener listener = new MyListener(); |
119 |
private JPanel panelC = null; |
120 |
|
121 |
/**
|
122 |
* This is the default constructor
|
123 |
*/
|
124 |
public PanelLegendBreaks() {
|
125 |
super();
|
126 |
initialize(); |
127 |
} |
128 |
|
129 |
/**
|
130 |
* This method initializes this
|
131 |
*/
|
132 |
private void initialize() { |
133 |
//this.setLayout(new BorderLayout());
|
134 |
this.setLayout(new BorderLayout()); |
135 |
this.setSize(490, 300); |
136 |
this.add(getPanelN(), java.awt.BorderLayout.NORTH);
|
137 |
this.add(getPanelS(), java.awt.BorderLayout.SOUTH);
|
138 |
this.add(getPanelC(), java.awt.BorderLayout.CENTER);
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* This method initializes panelN
|
143 |
*
|
144 |
* @return javax.swing.JPanel
|
145 |
*/
|
146 |
private JPanel getPanelN() { |
147 |
if (panelN == null) { |
148 |
lblType = new JLabel(); |
149 |
lblType.setBounds(new java.awt.Rectangle(1, 26, 122, 20)); |
150 |
lblType.setText(PluginServices.getText(this, "tipo_de_intervalo")); |
151 |
lblEndColor = new JLabel(); |
152 |
lblEndColor.setBounds(new java.awt.Rectangle(169, 49, 84, 20)); |
153 |
lblEndColor.setText(PluginServices.getText(this, "Color_final")); |
154 |
lblInitColor = new JLabel(); |
155 |
lblInitColor.setBounds(new java.awt.Rectangle(1, 49, 105, 20)); |
156 |
lblInitColor.setText(PluginServices.getText(this, "Color_inicio")); |
157 |
lblNumIntervals = new JLabel(); |
158 |
lblNumIntervals.setBounds(new java.awt.Rectangle(315, 49, 133, 20)); |
159 |
lblNumIntervals.setText(PluginServices.getText(this,
|
160 |
"No_de_intervalos"));
|
161 |
lblField = new JLabel(); |
162 |
lblField.setBounds(new java.awt.Rectangle(1, 3, 170, 20)); |
163 |
lblField.setText(PluginServices.getText(this,
|
164 |
"Campo_de_clasificacion"));
|
165 |
panelN = new JPanel(); |
166 |
panelN.setLayout(null);
|
167 |
panelN.setPreferredSize(new java.awt.Dimension(450, 75)); |
168 |
panelN.add(lblField, null);
|
169 |
panelN.add(getJComboBox(), null);
|
170 |
panelN.add(lblNumIntervals, null);
|
171 |
panelN.add(getTxtNumIntervals(), null);
|
172 |
panelN.add(lblInitColor, null);
|
173 |
panelN.add(lblEndColor, null);
|
174 |
panelN.add(getColorChooserPanel(), null);
|
175 |
panelN.add(getColorChooserPanel1(), null);
|
176 |
panelN.add(getChkdefaultvalues(), null);
|
177 |
panelN.add(lblType, null);
|
178 |
panelN.add(getJComboBox1(), null);
|
179 |
} |
180 |
|
181 |
return panelN;
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* This method initializes jComboBox
|
186 |
*
|
187 |
* @return javax.swing.JComboBox
|
188 |
*/
|
189 |
private JComboBox getJComboBox() { |
190 |
if (cmbField == null) { |
191 |
cmbField = new JComboBox(); |
192 |
cmbField.setBounds(new java.awt.Rectangle(172, 3, 312, 20)); |
193 |
cmbField.setActionCommand("FIELD_SELECTED");
|
194 |
cmbField.addActionListener(listener); |
195 |
cmbField.setVisible(true);
|
196 |
} |
197 |
|
198 |
return cmbField;
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* This method initializes txtNumIntervals
|
203 |
*
|
204 |
* @return javax.swing.JTextField
|
205 |
*/
|
206 |
private JTextField getTxtNumIntervals() { |
207 |
if (txtNumIntervals == null) { |
208 |
txtNumIntervals = new JTextField(); |
209 |
txtNumIntervals.setText("5");
|
210 |
txtNumIntervals.setBounds(new java.awt.Rectangle(449, 49, 37, 20)); |
211 |
} |
212 |
|
213 |
return txtNumIntervals;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* This method initializes colorChooserPanel
|
218 |
*
|
219 |
* @return com.iver.cit.gvsig.gui.Panels.ColorChooserPanel
|
220 |
*/
|
221 |
private ColorChooserPanel getColorChooserPanel() {
|
222 |
if (colorChooserPanel == null) { |
223 |
colorChooserPanel = new ColorChooserPanel();
|
224 |
colorChooserPanel.setBounds(new java.awt.Rectangle(108, 49, 54, 20)); |
225 |
colorChooserPanel.setAlpha(255);
|
226 |
colorChooserPanel.setColor(Color.red);
|
227 |
} |
228 |
|
229 |
return colorChooserPanel;
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* This method initializes colorChooserPanel1
|
234 |
*
|
235 |
* @return com.iver.cit.gvsig.gui.Panels.ColorChooserPanel
|
236 |
*/
|
237 |
private ColorChooserPanel getColorChooserPanel1() {
|
238 |
if (colorChooserPanel1 == null) { |
239 |
colorChooserPanel1 = new ColorChooserPanel();
|
240 |
colorChooserPanel1.setBounds(new java.awt.Rectangle(251, 49, 54, 20)); |
241 |
colorChooserPanel1.setAlpha(255);
|
242 |
colorChooserPanel1.setColor(Color.blue);
|
243 |
} |
244 |
|
245 |
return colorChooserPanel1;
|
246 |
} |
247 |
|
248 |
/**
|
249 |
* This method initializes chkdefaultvalues
|
250 |
*
|
251 |
* @return javax.swing.JCheckBox
|
252 |
*/
|
253 |
private JCheckBox getChkdefaultvalues() { |
254 |
if (chkdefaultvalues == null) { |
255 |
chkdefaultvalues = new JCheckBox(); |
256 |
chkdefaultvalues.setText(PluginServices.getText(this,
|
257 |
"resto_valores"));
|
258 |
chkdefaultvalues.setBounds(new java.awt.Rectangle(342, 26, 141, 20)); |
259 |
chkdefaultvalues.addActionListener(new java.awt.event.ActionListener() {
|
260 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
261 |
if (auxLegend==null)auxLegend=m_Renderer; |
262 |
if (chkdefaultvalues.isSelected()) {
|
263 |
addDefault(); |
264 |
} else {
|
265 |
delDefault(); |
266 |
} |
267 |
} |
268 |
}); |
269 |
} |
270 |
|
271 |
return chkdefaultvalues;
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* This method initializes jComboBox1
|
276 |
*
|
277 |
* @return javax.swing.JComboBox
|
278 |
*/
|
279 |
private JComboBox getJComboBox1() { |
280 |
if (cmbFieldType == null) { |
281 |
cmbFieldType = new JComboBox(); |
282 |
cmbFieldType.setBounds(new java.awt.Rectangle(124, 26, 212, 20)); |
283 |
cmbFieldType.setActionCommand("INTERVAL_TYPE");
|
284 |
cmbFieldType.addActionListener(listener); |
285 |
cmbFieldType.addItem(PluginServices.getText(this, "equal_intervals")); |
286 |
cmbFieldType.addItem(PluginServices.getText(this,
|
287 |
"natural_intervals"));
|
288 |
cmbFieldType.addItem(PluginServices.getText(this,
|
289 |
"quantile_intervals"));
|
290 |
cmbFieldType.setVisible(true);
|
291 |
} |
292 |
|
293 |
return cmbFieldType;
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* This method initializes panelS
|
298 |
*
|
299 |
* @return javax.swing.JPanel
|
300 |
*/
|
301 |
private JPanel getPanelS() { |
302 |
if (panelS == null) { |
303 |
panelS = new JPanel(); |
304 |
panelS.setPreferredSize(new java.awt.Dimension(417, 32)); |
305 |
panelS.add(getBintervals(), null);
|
306 |
panelS.add(getBInsert(), null);
|
307 |
panelS.add(getBDelAll(), null);
|
308 |
panelS.add(getBDel(), null);
|
309 |
} |
310 |
|
311 |
return panelS;
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* This method initializes bintervals
|
316 |
*
|
317 |
* @return javax.swing.JButton
|
318 |
*/
|
319 |
private JButton getBintervals() { |
320 |
if (bintervals == null) { |
321 |
bintervals = new JButton(); |
322 |
bintervals.setActionCommand("ADD_ALL_VALUES");
|
323 |
bintervals.addActionListener(listener); |
324 |
bintervals.setText(PluginServices.getText(this,
|
325 |
"Calcular_intervalos"));
|
326 |
} |
327 |
|
328 |
return bintervals;
|
329 |
} |
330 |
|
331 |
/**
|
332 |
* This method initializes bInsert
|
333 |
*
|
334 |
* @return javax.swing.JButton
|
335 |
*/
|
336 |
private JButton getBInsert() { |
337 |
if (bInsert == null) { |
338 |
bInsert = new JButton(); |
339 |
bInsert.setActionCommand("ADD_VALUE");
|
340 |
bInsert.addActionListener(listener); |
341 |
bInsert.setText(PluginServices.getText(this, "Anadir")); |
342 |
} |
343 |
|
344 |
return bInsert;
|
345 |
} |
346 |
|
347 |
/**
|
348 |
* This method initializes bDelAll
|
349 |
*
|
350 |
* @return javax.swing.JButton
|
351 |
*/
|
352 |
private JButton getBDelAll() { |
353 |
if (bDelAll == null) { |
354 |
bDelAll = new JButton(); |
355 |
bDelAll.setActionCommand("REMOVE_ALL");
|
356 |
bDelAll.addActionListener(listener); |
357 |
bDelAll.setText(PluginServices.getText(this, "Quitar_todos")); |
358 |
} |
359 |
|
360 |
return bDelAll;
|
361 |
} |
362 |
|
363 |
/**
|
364 |
* This method initializes bDel
|
365 |
*
|
366 |
* @return javax.swing.JButton
|
367 |
*/
|
368 |
private JButton getBDel() { |
369 |
if (bDel == null) { |
370 |
bDel = new JButton(); |
371 |
bDel.setText(PluginServices.getText(this, "Quitar")); |
372 |
bDel.setActionCommand("REMOVE");
|
373 |
bDel.addActionListener(listener); |
374 |
} |
375 |
|
376 |
return bDel;
|
377 |
} |
378 |
|
379 |
/**
|
380 |
* Damos una primera pasada para saber los l?mites inferior y superior y
|
381 |
* rellenar un array con los valores. Luego dividimos ese array en
|
382 |
* intervalos.
|
383 |
*/
|
384 |
private void fillTableValues() { |
385 |
FInterval[] arrayIntervalos = null; |
386 |
DataSource elRs;
|
387 |
m_symbolTable.removeAllItems(); |
388 |
|
389 |
try {
|
390 |
elRs = ((AlphanumericData) m_lyr).getRecordset(); |
391 |
logger.debug("elRs.start()");
|
392 |
elRs.start(); |
393 |
|
394 |
int idField = -1; |
395 |
int numIntervalos = 1; |
396 |
|
397 |
try {
|
398 |
numIntervalos = Integer.parseInt(txtNumIntervals.getText());
|
399 |
} catch (NumberFormatException e) { |
400 |
System.out.println("Foramto de n?mero erroneo"); |
401 |
} |
402 |
|
403 |
String fieldName = (String) cmbField.getSelectedItem(); |
404 |
System.out.println("Nombre del campo de clasificaci?n: " + |
405 |
fieldName); |
406 |
m_Renderer.setFieldName(fieldName); |
407 |
|
408 |
String nomField = m_Renderer.getFieldName();
|
409 |
|
410 |
// Cogemos el tipo de gradaci?n de colores que quiere el usuario y
|
411 |
// Creamos el primer y ?ltimo color.
|
412 |
Color startColor = colorChooserPanel.getColor();
|
413 |
m_Renderer.setStartColor(startColor); |
414 |
|
415 |
Color endColor = colorChooserPanel1.getColor();
|
416 |
m_Renderer.setEndColor(endColor); |
417 |
|
418 |
for (int i = 0; i < elRs.getFieldCount(); i++) { |
419 |
String nomAux = elRs.getFieldName(i).trim();
|
420 |
|
421 |
if (nomField.compareToIgnoreCase(nomAux) == 0) { |
422 |
idField = i; |
423 |
|
424 |
break;
|
425 |
} |
426 |
} |
427 |
|
428 |
if (idField == -1) { |
429 |
System.err.println("Campo no reconocido " + nomField); |
430 |
|
431 |
return;
|
432 |
} |
433 |
|
434 |
///m_symbolTable.removeAllItems();
|
435 |
///m_valuesCache = new Object[m_lyr.getSource().getShapeCount()];
|
436 |
int numSymbols = 0; |
437 |
FSymbol theSymbol; |
438 |
|
439 |
//Date valorDate;
|
440 |
double minValue = Double.MAX_VALUE; |
441 |
double maxValue = Double.MIN_VALUE; |
442 |
|
443 |
//Date minValueDate = null;
|
444 |
//Date maxValueDate = null;
|
445 |
auxLegend = LegendFactory.createVectorialIntervalLegend(m_lyr.getShapeType()); |
446 |
|
447 |
Value clave; |
448 |
|
449 |
//Object resul;
|
450 |
int symbolType = 0; |
451 |
count = 0;
|
452 |
|
453 |
for (int j = 0; j < elRs.getRowCount(); j++) { |
454 |
clave = elRs.getFieldValue(j, idField); |
455 |
|
456 |
IInterval interval = auxLegend.getInterval(clave); |
457 |
|
458 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
|
459 |
if (auxLegend.getSymbolByInterval(interval) == null) { |
460 |
//si no esta creado el simbolo se crea
|
461 |
double valor = 0; |
462 |
symbolType = m_lyr.getShapeType(); |
463 |
|
464 |
if (clave instanceof IntValue) { |
465 |
valor = ((IntValue) clave).getValue(); |
466 |
} else if (clave instanceof DoubleValue) { |
467 |
valor = ((DoubleValue) clave).getValue(); |
468 |
} else if (clave instanceof FloatValue) { |
469 |
valor = ((FloatValue) clave).getValue(); |
470 |
} else if (clave instanceof LongValue) { |
471 |
valor = ((LongValue) clave).getValue(); |
472 |
} else if (clave instanceof DateValue) { |
473 |
//TODO POR IMPLEMENTAR
|
474 |
///valorDate = elRs.getFieldValueAsDate(idField);
|
475 |
///if (valorDate.before(minValueDate)) minValueDate = valorDate;
|
476 |
///if (valorDate.after(maxValueDate)) maxValueDate = valorDate;
|
477 |
} else if (clave instanceof NullValue) { |
478 |
continue;
|
479 |
} |
480 |
|
481 |
if (valor < minValue) {
|
482 |
minValue = (double) valor;
|
483 |
} |
484 |
|
485 |
if (valor > maxValue) {
|
486 |
maxValue = (double) valor;
|
487 |
} |
488 |
} |
489 |
|
490 |
count++; |
491 |
} |
492 |
|
493 |
switch (m_Renderer.getIntervalType()) {
|
494 |
case VectorialIntervalLegend.EQUAL_INTERVALS:
|
495 |
arrayIntervalos = calculateEqualIntervals(numIntervalos, |
496 |
minValue, maxValue, fieldName); |
497 |
|
498 |
break;
|
499 |
|
500 |
case VectorialIntervalLegend.NATURAL_INTERVALS:
|
501 |
arrayIntervalos = calculateNaturalIntervals(numIntervalos, |
502 |
minValue, maxValue, fieldName); |
503 |
|
504 |
break;
|
505 |
|
506 |
case VectorialIntervalLegend.QUANTILE_INTERVALS:
|
507 |
arrayIntervalos = calculateQuantileIntervals(numIntervalos, |
508 |
minValue, maxValue, fieldName); |
509 |
|
510 |
break;
|
511 |
} |
512 |
|
513 |
//intervals = arrayIntervalos;
|
514 |
FInterval elIntervalo; |
515 |
NumberFormat.getInstance().setMaximumFractionDigits(2); |
516 |
m_Renderer.clear(); |
517 |
|
518 |
int r;
|
519 |
int g;
|
520 |
int b;
|
521 |
int stepR;
|
522 |
int stepG;
|
523 |
int stepB;
|
524 |
r = startColor.getRed(); |
525 |
g = startColor.getGreen(); |
526 |
b = startColor.getBlue(); |
527 |
stepR = (endColor.getRed() - r) / arrayIntervalos.length; |
528 |
stepG = (endColor.getGreen() - g) / arrayIntervalos.length; |
529 |
stepB = (endColor.getBlue() - b) / arrayIntervalos.length; |
530 |
|
531 |
if (chkdefaultvalues.isSelected()) {
|
532 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
533 |
auxLegend.addSymbol(new NullIntervalValue(),
|
534 |
auxLegend.getDefaultSymbol()); |
535 |
} |
536 |
|
537 |
for (int k = 0; k < arrayIntervalos.length; k++) { |
538 |
elIntervalo = arrayIntervalos[k]; |
539 |
|
540 |
// clave = elIntervalo; // elIntervalo.getMin() + " - " + elIntervalo.getMax();
|
541 |
// System.out.println("k = " + k + " clave = " + clave);
|
542 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
|
543 |
// if (!m_Renderer.m_symbolList.containsKey(elIntervalo)) {
|
544 |
//si no esta creado el simbolo se crea
|
545 |
theSymbol = new FSymbol(symbolType, new Color(r, g, b)); |
546 |
theSymbol.setDescription(NumberFormat.getInstance().format(elIntervalo.getMin()) +
|
547 |
" - " +
|
548 |
NumberFormat.getInstance().format(elIntervalo.getMax()));
|
549 |
|
550 |
//////////////////////////////////////
|
551 |
// CALCULAMOS UN COLOR APROPIADO
|
552 |
r = r + stepR; |
553 |
g = g + stepG; |
554 |
b = b + stepB; |
555 |
|
556 |
/////////////////////////////////
|
557 |
auxLegend.addSymbol(elIntervalo, theSymbol); |
558 |
System.out.println("addSymbol = " + elIntervalo + |
559 |
" theSymbol = " + theSymbol.getDescription());
|
560 |
numSymbols++; |
561 |
|
562 |
if (numSymbols > 100) { |
563 |
int resp = JOptionPane.showConfirmDialog(this, |
564 |
PluginServices.getText(this, "mas_de_100_simbolos"), |
565 |
PluginServices.getText(this, "quiere_continuar"), |
566 |
JOptionPane.YES_NO_OPTION,
|
567 |
JOptionPane.WARNING_MESSAGE);
|
568 |
|
569 |
if ((resp == JOptionPane.NO_OPTION) || |
570 |
(resp == JOptionPane.DEFAULT_OPTION)) {
|
571 |
return;
|
572 |
} |
573 |
} |
574 |
|
575 |
// }
|
576 |
} // for
|
577 |
|
578 |
System.out.println("Num. Simbolos = " + |
579 |
auxLegend.getValues().length); |
580 |
m_symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
581 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
582 |
elRs.stop(); |
583 |
} catch (DriverException e) {
|
584 |
// TODO Auto-generated catch block
|
585 |
e.printStackTrace(); |
586 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
587 |
e.printStackTrace(); |
588 |
} |
589 |
|
590 |
bDelAll.setEnabled(true);
|
591 |
bDel.setEnabled(true);
|
592 |
} |
593 |
|
594 |
/**
|
595 |
* EQUAL INTERVAL Devuelve un Array con el n?mero de intervalos que se
|
596 |
* quieren crear. Los intervalos se crean con un tama?o igual entre ellos.
|
597 |
*
|
598 |
* @param numIntervals n?mero de intervalos
|
599 |
* @param minValue Valor m?nimo.
|
600 |
* @param maxValue Valor m?ximo.
|
601 |
* @param fieldName Nombre del campo
|
602 |
*
|
603 |
* @return Array con los intervalos.
|
604 |
*/
|
605 |
FInterval[] calculateEqualIntervals(int numIntervals, double minValue, |
606 |
double maxValue, String fieldName) { |
607 |
FInterval[] theIntervalArray = new FInterval[numIntervals]; |
608 |
double step = (maxValue - minValue) / numIntervals;
|
609 |
|
610 |
if (numIntervals > 1) { |
611 |
theIntervalArray[0] = new FInterval(minValue, minValue + step); |
612 |
|
613 |
for (int i = 1; i < (numIntervals - 1); i++) { |
614 |
theIntervalArray[i] = new FInterval(minValue + (i * step) +
|
615 |
0.01, minValue + ((i + 1) * step)); |
616 |
} |
617 |
|
618 |
theIntervalArray[numIntervals - 1] = new FInterval(minValue + |
619 |
((numIntervals - 1) * step) + 0.01, maxValue); |
620 |
} else {
|
621 |
theIntervalArray[0] = new FInterval(minValue, maxValue); |
622 |
} |
623 |
|
624 |
return theIntervalArray;
|
625 |
} |
626 |
|
627 |
/**
|
628 |
* NATURAL INTERVAL Devuelve un Array con el n?mero de intervalos que se
|
629 |
* quieren crear. Los intervalos se distribuyen de forma natural.
|
630 |
*
|
631 |
* @param numIntervals n?mero de intervalos
|
632 |
* @param minValue Valor m?nimo.
|
633 |
* @param maxValue Valor m?ximo.
|
634 |
* @param fieldName Nombre del campo
|
635 |
*
|
636 |
* @return Array con los intervalos.
|
637 |
*/
|
638 |
FInterval[] calculateNaturalIntervals(int numIntervals, double minValue, |
639 |
double maxValue, String fieldName) { |
640 |
NaturalIntervalGenerator intervalGenerator = new NaturalIntervalGenerator(((AlphanumericData) m_lyr),
|
641 |
fieldName, numIntervals); |
642 |
|
643 |
try {
|
644 |
intervalGenerator.generarIntervalos(); |
645 |
} catch (DriverException e) {
|
646 |
e.printStackTrace(); |
647 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
648 |
e.printStackTrace(); |
649 |
} |
650 |
|
651 |
int numIntervalsGen = intervalGenerator.getNumIntervals() - 1; |
652 |
|
653 |
if (numIntervalsGen == -1) { |
654 |
//TODO cuando no puede calcular los intervalos.
|
655 |
numIntervalsGen = 1;
|
656 |
} |
657 |
|
658 |
FInterval[] theIntervalArray = new FInterval[numIntervalsGen]; |
659 |
|
660 |
if (numIntervalsGen > 1) { |
661 |
theIntervalArray[0] = new FInterval(minValue, |
662 |
intervalGenerator.getValorRuptura(0));
|
663 |
|
664 |
for (int i = 1; i < (numIntervalsGen - 1); i++) { |
665 |
theIntervalArray[i] = new FInterval(intervalGenerator.getValInit(i -
|
666 |
1), intervalGenerator.getValorRuptura(i));
|
667 |
} |
668 |
|
669 |
theIntervalArray[numIntervalsGen - 1] = new FInterval(intervalGenerator.getValInit(numIntervalsGen - |
670 |
2), maxValue);
|
671 |
} else {
|
672 |
theIntervalArray[numIntervalsGen - 1] = new FInterval(minValue, |
673 |
maxValue); |
674 |
} |
675 |
|
676 |
return theIntervalArray;
|
677 |
} |
678 |
|
679 |
/**
|
680 |
* QUANTILE INTERVAL Devuelve un Array con el n?mero de intervalos que se
|
681 |
* quieren crear. Los intervalos se distribuyen de forma quantile.
|
682 |
*
|
683 |
* @param numIntervals n?mero de intervalos
|
684 |
* @param minValue Valor m?nimo.
|
685 |
* @param maxValue Valor m?ximo.
|
686 |
* @param fieldName Nombre del campo
|
687 |
*
|
688 |
* @return Array con los intervalos.
|
689 |
*/
|
690 |
FInterval[] calculateQuantileIntervals(int numIntervals, double minValue, |
691 |
double maxValue, String fieldName) { |
692 |
QuantileIntervalGenerator intervalGenerator = new QuantileIntervalGenerator(((AlphanumericData) m_lyr),
|
693 |
fieldName, numIntervals); |
694 |
|
695 |
try {
|
696 |
intervalGenerator.generarIntervalos(); |
697 |
} catch (DriverException e) {
|
698 |
e.printStackTrace(); |
699 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
700 |
e.printStackTrace(); |
701 |
} |
702 |
|
703 |
int numIntervalsGen = intervalGenerator.getNumIntervalGen();
|
704 |
FInterval[] theIntervalArray = new FInterval[numIntervalsGen]; |
705 |
|
706 |
if (intervalGenerator.getNumIntervalGen() > 1) { |
707 |
theIntervalArray[0] = new FInterval(minValue, |
708 |
intervalGenerator.getValRuptura(0));
|
709 |
|
710 |
for (int i = 1; i < (numIntervalsGen - 1); i++) { |
711 |
theIntervalArray[i] = new FInterval(intervalGenerator.getValInit(i -
|
712 |
1), intervalGenerator.getValRuptura(i));
|
713 |
} |
714 |
|
715 |
theIntervalArray[numIntervalsGen - 1] = new FInterval(intervalGenerator.getValInit(numIntervalsGen - |
716 |
2), maxValue);
|
717 |
} else {
|
718 |
theIntervalArray[numIntervalsGen - 1] = new FInterval(minValue, |
719 |
maxValue); |
720 |
} |
721 |
|
722 |
return theIntervalArray;
|
723 |
|
724 |
/* double numQ = count / numIntervals;
|
725 |
for (int i = 0; i < count; i++) {
|
726 |
}
|
727 |
return theIntervalArray;
|
728 |
*/
|
729 |
} |
730 |
|
731 |
/**
|
732 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer,
|
733 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
734 |
*/
|
735 |
public void setLayer(FLayer lyr, Legend r) { |
736 |
// m_TOC = t;
|
737 |
// OJO, COMPROBAR ANTES SI ES DE TIPO VECTORIAL
|
738 |
// m_lyr = (FLyrVect) t.getFirstLyrVectSelected();
|
739 |
m_lyr = (ClassifiableVectorial) lyr; |
740 |
fillFieldNames(); |
741 |
|
742 |
if (r instanceof VectorialIntervalLegend) { |
743 |
m_Renderer = (VectorialIntervalLegend) r; |
744 |
getChkdefaultvalues().setSelected(m_Renderer.isUseDefaultSymbol()); |
745 |
cmbField.getModel().setSelectedItem(m_Renderer.getFieldName()); |
746 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(), |
747 |
m_Renderer.getValues(), m_Renderer.getDescriptions()); |
748 |
colorChooserPanel.setColor(m_Renderer.getStartColor()); |
749 |
colorChooserPanel1.setColor(m_Renderer.getEndColor()); |
750 |
colorChooserPanel.repaint(); |
751 |
colorChooserPanel1.repaint(); |
752 |
} else {
|
753 |
try {
|
754 |
// Si la capa viene con otro tipo de leyenda, creamos
|
755 |
// una nueva del tipo que maneja este panel
|
756 |
m_Renderer = new VectorialIntervalLegend(m_lyr.getShapeType());
|
757 |
} catch (DriverException e) {
|
758 |
// TODO Auto-generated catch block
|
759 |
e.printStackTrace(); |
760 |
} |
761 |
} |
762 |
|
763 |
cmbFieldType.setSelectedIndex(m_Renderer.getIntervalType()); |
764 |
} |
765 |
|
766 |
/**
|
767 |
* DOCUMENT ME!
|
768 |
*/
|
769 |
private void fillFieldNames() { |
770 |
DataSource rs = null; |
771 |
ArrayList nomFields = null; |
772 |
|
773 |
try {
|
774 |
rs = ((AlphanumericData) m_lyr).getRecordset(); |
775 |
logger.debug("rs.start()");
|
776 |
rs.start(); |
777 |
|
778 |
nomFields = new ArrayList(); |
779 |
|
780 |
int type;
|
781 |
for (int i = 0; i < rs.getFieldCount(); i++) { |
782 |
type = rs.getFieldType(i); |
783 |
|
784 |
if (type == Types.NULL) { |
785 |
continue;
|
786 |
} |
787 |
|
788 |
if ((type == Types.INTEGER) || |
789 |
(type == Types.DOUBLE) ||
|
790 |
(type == Types.FLOAT) ||
|
791 |
(type == Types.BIGINT)) {
|
792 |
nomFields.add(rs.getFieldName(i).trim()); |
793 |
} |
794 |
} |
795 |
|
796 |
rs.stop(); |
797 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
798 |
e1.printStackTrace(); |
799 |
} catch (DriverException e) {
|
800 |
e.printStackTrace(); |
801 |
} |
802 |
|
803 |
/* ArrayList nomFields = new ArrayList();
|
804 |
for (int i = 0; i < rs.getFieldsCount(); i++) {
|
805 |
if ((rs.getFieldType(i) == FRecordset.INTEGER) ||
|
806 |
(rs.getFieldType(i) == FRecordset.DECIMAL) ||
|
807 |
(rs.getFieldType(i) == FRecordset.DATE))
|
808 |
{
|
809 |
nomFields.add(rs.getFieldName(i).trim());
|
810 |
}
|
811 |
|
812 |
}
|
813 |
*/
|
814 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray()); |
815 |
cmbField.setModel(cM); |
816 |
|
817 |
// fieldsListValor.setSelectedIndex(0);
|
818 |
m_symbolTable.removeAllItems(); |
819 |
} |
820 |
|
821 |
/**
|
822 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
823 |
*/
|
824 |
public Legend getLegend() {
|
825 |
fillSymbolListFromTable(); |
826 |
|
827 |
if (auxLegend != null) { |
828 |
m_Renderer.setDefaultSymbol(auxLegend.getDefaultSymbol()); |
829 |
m_Renderer.useDefaultSymbol(chkdefaultvalues.isSelected()); |
830 |
} |
831 |
|
832 |
return m_Renderer;
|
833 |
} |
834 |
|
835 |
/**
|
836 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo
|
837 |
* el symbolList, si no tambi?n el arrayKeys y el defaultRenderer
|
838 |
*/
|
839 |
private void fillSymbolListFromTable() { |
840 |
//String clave;
|
841 |
FSymbol theSymbol; |
842 |
IInterval theInterval = null;
|
843 |
|
844 |
// Borramos las anteriores listas:
|
845 |
m_Renderer.clear(); |
846 |
|
847 |
//boolean bRestoValores = false; // PONERLO EN UN CHECKBOX
|
848 |
//double from = 0;
|
849 |
//double to = 0;
|
850 |
//String[] arraySplit = new String[2];
|
851 |
//int hasta;
|
852 |
String fieldName = (String) cmbField.getSelectedItem(); |
853 |
m_Renderer.setFieldName(fieldName); |
854 |
|
855 |
/*if (bRestoValores) {
|
856 |
hasta = m_symbolTable.getRowCount() - 1;
|
857 |
} else {
|
858 |
hasta = m_symbolTable.getRowCount();
|
859 |
}
|
860 |
*/
|
861 |
for (int row = 0; row < m_symbolTable.getRowCount(); row++) { |
862 |
// clave = m_symbolTable.getFieldValue(row,1);
|
863 |
if (!(m_symbolTable.getFieldValue(row, 1) instanceof FInterval)) { |
864 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(row, 0);
|
865 |
theSymbol.setDescription((String) m_symbolTable.getFieldValue(
|
866 |
row, 2));
|
867 |
m_Renderer.addSymbol(new NullIntervalValue(), theSymbol);
|
868 |
} else {
|
869 |
theInterval = (IInterval) m_symbolTable.getFieldValue(row, 1);
|
870 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(row, 0);
|
871 |
theSymbol.setDescription((String) m_symbolTable.getFieldValue(
|
872 |
row, 2));
|
873 |
m_Renderer.addSymbol(theInterval, theSymbol); |
874 |
} |
875 |
|
876 |
///m_Renderer.m_legendIntervals.add(theInterval);
|
877 |
} |
878 |
|
879 |
/* if (bRestoValores) {
|
880 |
//m_Renderer.m_bUseDefaultSymbol = true;
|
881 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(hasta, 0);
|
882 |
m_Renderer.setDefaultSymbol(theSymbol);
|
883 |
}*/
|
884 |
} |
885 |
|
886 |
/**
|
887 |
* This method initializes panelC
|
888 |
*
|
889 |
* @return javax.swing.JPanel
|
890 |
*/
|
891 |
private JPanel getPanelC() { |
892 |
if (panelC == null) { |
893 |
panelC = new JPanel(); |
894 |
panelC.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, |
895 |
0, 0)); |
896 |
panelC.setPreferredSize(new java.awt.Dimension(420, 200)); |
897 |
panelC.add(m_symbolTable); |
898 |
} |
899 |
|
900 |
return panelC;
|
901 |
} |
902 |
|
903 |
/**
|
904 |
* A?ade la fila y el s?mbolo para el resto de valores no representados.
|
905 |
*/
|
906 |
private void addDefault() { |
907 |
|
908 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
909 |
auxLegend.addSymbol(new NullIntervalValue(),
|
910 |
auxLegend.getDefaultSymbol()); |
911 |
m_symbolTable.addTableRecord(auxLegend.getDefaultSymbol(), |
912 |
new NullIntervalValue(),
|
913 |
auxLegend.getDefaultSymbol().getDescription()); |
914 |
m_symbolTable.repaint(); |
915 |
} |
916 |
|
917 |
/**
|
918 |
* Elimina la fila de la tabla y el s?mbolo del resto de valores no
|
919 |
* representados por ning?n valor.
|
920 |
*/
|
921 |
private void delDefault() { |
922 |
auxLegend.delSymbol(new NullIntervalValue());
|
923 |
m_symbolTable.removeRow(new NullIntervalValue());
|
924 |
m_symbolTable.repaint(); |
925 |
} |
926 |
|
927 |
/**
|
928 |
* Listener.
|
929 |
*
|
930 |
* @author Vicente Caballero Navarro
|
931 |
*/
|
932 |
class MyListener implements ActionListener { |
933 |
//private FLyrShp m_layer;
|
934 |
// private FPanelLegendValues m_Parent;
|
935 |
public MyListener() { // FPanelLegendValues p) { |
936 |
|
937 |
// m_Parent = p;
|
938 |
} |
939 |
|
940 |
/**
|
941 |
* DOCUMENT ME!
|
942 |
*
|
943 |
* @param e DOCUMENT ME!
|
944 |
*/
|
945 |
public void actionPerformed(ActionEvent e) { |
946 |
// rellenarValue();
|
947 |
System.out.println("ActionEvent con " + e.getActionCommand()); |
948 |
|
949 |
//modificar el combobox de valor
|
950 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
951 |
JComboBox cb = (JComboBox) e.getSource(); |
952 |
String fieldName = (String) cb.getSelectedItem(); |
953 |
System.out.println("Nombre del campo: " + fieldName); |
954 |
m_symbolTable.removeAllItems(); |
955 |
|
956 |
m_Renderer.setFieldName(fieldName); |
957 |
} else if (e.getActionCommand() == "INTERVAL_TYPE") { |
958 |
JComboBox cb = (JComboBox) e.getSource(); |
959 |
|
960 |
if ((m_Renderer != null) && |
961 |
(cb.getSelectedIndex() != m_Renderer.getIntervalType())) { |
962 |
m_Renderer.setIntervalType(cb.getSelectedIndex()); |
963 |
m_symbolTable.removeAllItems(); |
964 |
} |
965 |
} |
966 |
|
967 |
//A?adir todos los elementos por valor
|
968 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
969 |
fillTableValues(); |
970 |
} |
971 |
|
972 |
//A?adir un ?nico elemento
|
973 |
if (e.getActionCommand() == "ADD_VALUE") { |
974 |
try {
|
975 |
m_symbolTable.addTableRecord(new FSymbol(
|
976 |
m_lyr.getShapeType()), new FInterval(0, 0), "0 - 0"); |
977 |
} catch (DriverException e1) {
|
978 |
e1.printStackTrace(); |
979 |
} |
980 |
|
981 |
/* a?adir("Nuevo_Valor");
|
982 |
aceptar.setEnabled(true);
|
983 |
quitartodo.setEnabled(true);
|
984 |
quitar.setEnabled(true); */
|
985 |
} |
986 |
|
987 |
//Vacia la tabla
|
988 |
if (e.getActionCommand() == "REMOVE_ALL") { |
989 |
m_symbolTable.removeAllItems(); |
990 |
|
991 |
// aceptar.setEnabled(false);
|
992 |
} |
993 |
|
994 |
//Quitar solo el elemento seleccionado
|
995 |
if (e.getActionCommand() == "REMOVE") { |
996 |
m_symbolTable.removeSelectedRows(); |
997 |
} |
998 |
} |
999 |
} |
1000 |
} // @jve:decl-index=0:visual-constraint="10,10"
|