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