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