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