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