root / branches / gvSIG_GisPlanet / applications / appgvSIG / src / com / iver / cit / gvsig / gui / legendmanager / panels / FPanelLegendBreaks.java @ 2247
History | View | Annotate | Download (20 KB)
1 |
/*
|
---|---|
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.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 |
import java.util.TreeMap; |
60 |
|
61 |
import javax.swing.DefaultComboBoxModel; |
62 |
import javax.swing.JButton; |
63 |
import javax.swing.JComboBox; |
64 |
import javax.swing.JLabel; |
65 |
import javax.swing.JOptionPane; |
66 |
import javax.swing.JPanel; |
67 |
import javax.swing.JTextField; |
68 |
|
69 |
import org.apache.log4j.Logger; |
70 |
|
71 |
import com.hardcode.driverManager.DriverLoadException; |
72 |
import com.hardcode.gdbms.engine.data.DataSource; |
73 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
74 |
import com.hardcode.gdbms.engine.values.FloatValue; |
75 |
import com.hardcode.gdbms.engine.values.IntValue; |
76 |
import com.hardcode.gdbms.engine.values.LongValue; |
77 |
import com.hardcode.gdbms.engine.values.NullValue; |
78 |
import com.hardcode.gdbms.engine.values.Value; |
79 |
import com.iver.andami.PluginServices; |
80 |
import com.iver.andami.Utilities; |
81 |
import com.iver.cit.gvsig.fmap.DriverException; |
82 |
import com.iver.cit.gvsig.fmap.core.FShape; |
83 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
84 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
85 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
86 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
87 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
88 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
89 |
import com.iver.cit.gvsig.fmap.rendering.FInterval; |
90 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
91 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
92 |
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
93 |
import com.iver.cit.gvsig.gui.Panels.ColorChooserPanel; |
94 |
|
95 |
|
96 |
/**
|
97 |
* DOCUMENT ME!
|
98 |
*
|
99 |
* @author fjp To change the template for this generated type comment go to
|
100 |
* Window>Preferences>Java>Code Generation>Code and
|
101 |
* Comments
|
102 |
*/
|
103 |
public class FPanelLegendBreaks extends JPanel implements ILegendPanel { |
104 |
private static Logger logger = Logger.getLogger(FPanelLegendBreaks.class.getName()); |
105 |
final static int EQUAL_INTERVALS = 0; |
106 |
final static int NATURAL_INTERVALS = 1; |
107 |
final static int QUANTILE_INTERVALS = 2; |
108 |
private MyListener listener = new MyListener(); |
109 |
|
110 |
// private TOC m_TOC;
|
111 |
private VectorialIntervalLegend m_Renderer;
|
112 |
private ClassifiableVectorial m_lyr;
|
113 |
private FSymbolTable m_symbolTable = new FSymbolTable(); |
114 |
private JComboBox m_cboFields; |
115 |
private JTextField m_txtNumIntervals; |
116 |
private ColorChooserPanel m_colorChooser1;
|
117 |
private ColorChooserPanel m_colorChooser2;
|
118 |
private JButton m_btnDeleteAll; |
119 |
private JButton m_btnDelete; |
120 |
private FInterval[] intervals; |
121 |
|
122 |
/**
|
123 |
*
|
124 |
*/
|
125 |
public FPanelLegendBreaks() {
|
126 |
super();
|
127 |
initComponents(); |
128 |
} |
129 |
|
130 |
/**
|
131 |
* DOCUMENT ME!
|
132 |
*
|
133 |
* @param numIntervals DOCUMENT ME!
|
134 |
* @param minValue DOCUMENT ME!
|
135 |
* @param maxValue DOCUMENT ME!
|
136 |
*
|
137 |
* @return DOCUMENT ME!
|
138 |
*/
|
139 |
static FInterval[] calculateEqualIntervals(int numIntervals, |
140 |
double minValue, double maxValue) { |
141 |
FInterval[] theIntervalArray = new FInterval[numIntervals]; |
142 |
double step = (maxValue - minValue) / numIntervals;
|
143 |
|
144 |
for (int i = 0; i < numIntervals; i++) { |
145 |
theIntervalArray[i] = new FInterval(minValue + (i * step),
|
146 |
minValue + ((i + 1) * step));
|
147 |
} |
148 |
|
149 |
return theIntervalArray;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* DOCUMENT ME!
|
154 |
*/
|
155 |
protected void initComponents() { |
156 |
/* JLabel label = new JLabel();
|
157 |
label.setIcon(new javax.swing.ImageIcon(Abrir.class.getClassLoader()
|
158 |
.getResource("images/ValoresUnicos.png")));
|
159 |
limagen[1] = new JLabel();
|
160 |
limagen[1] = label; */
|
161 |
JPanel botonestabla = new JPanel(); |
162 |
|
163 |
JButton btnAddAll = new JButton(PluginServices.getText(this, |
164 |
"Calcular_intervalos"));
|
165 |
btnAddAll.setActionCommand("ADD_ALL_VALUES");
|
166 |
botonestabla.add(btnAddAll); |
167 |
|
168 |
JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir")); |
169 |
btnAdd.setActionCommand("ADD_VALUE");
|
170 |
btnAdd.addActionListener(listener); |
171 |
botonestabla.add(btnAdd); |
172 |
|
173 |
m_btnDeleteAll = new JButton(PluginServices.getText(this, "Quitar_todos")); |
174 |
m_btnDeleteAll.setActionCommand("REMOVE_ALL");
|
175 |
m_btnDeleteAll.addActionListener(listener); |
176 |
botonestabla.add(m_btnDeleteAll); |
177 |
|
178 |
m_btnDelete = new JButton(PluginServices.getText(this, "Quitar")); |
179 |
m_btnDelete.setActionCommand("REMOVE");
|
180 |
m_btnDelete.addActionListener(listener); |
181 |
botonestabla.add(m_btnDelete); |
182 |
|
183 |
m_btnDeleteAll.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
|
184 |
public void propertyChange(java.beans.PropertyChangeEvent e) { |
185 |
if ((e.getPropertyName().equals("enabled"))) { |
186 |
System.out.println("propertyChange(enabled)"); // TODO Auto-generated property Event stub "enabled" |
187 |
} |
188 |
} |
189 |
}); |
190 |
m_btnDelete.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
|
191 |
public void propertyChange(java.beans.PropertyChangeEvent e) { |
192 |
if ((e.getPropertyName().equals("enabled"))) { |
193 |
System.out.println("propertyChange(enabled)"); // TODO Auto-generated property Event stub "enabled" |
194 |
} |
195 |
} |
196 |
}); |
197 |
btnAddAll.addActionListener(listener); |
198 |
|
199 |
JPanel ptabla = new JPanel(); |
200 |
ptabla.setLayout(new BorderLayout()); |
201 |
|
202 |
m_cboFields = new JComboBox(); |
203 |
m_cboFields.setActionCommand("FIELD_SELECTED");
|
204 |
m_cboFields.addActionListener(listener); |
205 |
m_cboFields.setVisible(true);
|
206 |
|
207 |
JPanel pAux1 = new JPanel(); |
208 |
|
209 |
/* pAux1.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
210 |
"Campo de clasificaci?n",
|
211 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
|
212 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); */
|
213 |
|
214 |
// pAux1.setPreferredSize(new Dimension(300,50));
|
215 |
GridBagLayout gridBag = new GridBagLayout(); |
216 |
pAux1.setLayout(gridBag); |
217 |
|
218 |
GridBagConstraints c = new GridBagConstraints(); |
219 |
|
220 |
c.anchor = GridBagConstraints.WEST;
|
221 |
|
222 |
JLabel lblFieldClassification = new JLabel(PluginServices.getText(this, |
223 |
"Campo_de_clasificacion"));
|
224 |
c.gridx = 0;
|
225 |
c.gridy = 0;
|
226 |
c.insets = new Insets(5, 5, 2, 2); |
227 |
c.gridwidth = 1;
|
228 |
gridBag.setConstraints(lblFieldClassification, c); |
229 |
pAux1.add(lblFieldClassification); |
230 |
|
231 |
c.gridx = 1;
|
232 |
c.gridy = 0;
|
233 |
gridBag.setConstraints(m_cboFields, c); |
234 |
pAux1.add(m_cboFields); |
235 |
|
236 |
JLabel lblNumIntervals = new JLabel(PluginServices.getText(this, |
237 |
"No_de_intervalos") + ":"); |
238 |
c.gridx = 3;
|
239 |
c.gridy = 0;
|
240 |
gridBag.setConstraints(lblNumIntervals, c); |
241 |
pAux1.add(lblNumIntervals); |
242 |
|
243 |
m_txtNumIntervals = new JTextField(4); |
244 |
c.gridx = 4;
|
245 |
c.gridy = 0;
|
246 |
gridBag.setConstraints(m_txtNumIntervals, c); |
247 |
m_txtNumIntervals.setText("5");
|
248 |
pAux1.add(m_txtNumIntervals); |
249 |
|
250 |
c.insets = new Insets(2, 2, 2, 2); |
251 |
|
252 |
JLabel lblColor1 = new JLabel(PluginServices.getText(this, "Color_inicio") + |
253 |
":");
|
254 |
c.gridx = 0;
|
255 |
c.gridy = 1;
|
256 |
gridBag.setConstraints(lblColor1, c); |
257 |
pAux1.add(lblColor1); |
258 |
|
259 |
m_colorChooser1 = new ColorChooserPanel();
|
260 |
m_colorChooser1.setColor(Color.red);
|
261 |
m_colorChooser1.setAlpha(255);
|
262 |
c.gridx = 1;
|
263 |
c.gridy = 1;
|
264 |
gridBag.setConstraints(m_colorChooser1, c); |
265 |
pAux1.add(m_colorChooser1); |
266 |
|
267 |
JLabel lblColor2 = new JLabel(PluginServices.getText(this, "Color_final") + |
268 |
":");
|
269 |
c.gridx = 3;
|
270 |
c.gridy = 1;
|
271 |
gridBag.setConstraints(lblColor2, c); |
272 |
pAux1.add(lblColor2); |
273 |
|
274 |
m_colorChooser2 = new ColorChooserPanel();
|
275 |
m_colorChooser2.setColor(Color.blue);
|
276 |
m_colorChooser2.setAlpha(255);
|
277 |
c.gridx = 4;
|
278 |
c.gridy = 1;
|
279 |
gridBag.setConstraints(m_colorChooser2, c); |
280 |
pAux1.add(m_colorChooser2); |
281 |
|
282 |
ptabla.add(m_symbolTable, BorderLayout.CENTER);
|
283 |
this.setLayout(new BorderLayout()); |
284 |
this.add(pAux1, BorderLayout.NORTH); |
285 |
this.add(ptabla, BorderLayout.CENTER); |
286 |
this.add(botonestabla, BorderLayout.SOUTH); |
287 |
} |
288 |
|
289 |
/**
|
290 |
* Damos una primera pasada para saber los l?mites inferior y superior y
|
291 |
* rellenar un array con los valores. Luego dividimos ese array en
|
292 |
* intervalos.
|
293 |
*/
|
294 |
private void fillTableValues() { |
295 |
FInterval[] arrayIntervalos = null; |
296 |
DataSource elRs;
|
297 |
m_symbolTable.removeAllItems(); |
298 |
|
299 |
try {
|
300 |
elRs = ((AlphanumericData) m_lyr).getRecordset(); |
301 |
logger.debug("elRs.start()");
|
302 |
elRs.start(); |
303 |
|
304 |
int idField = -1; |
305 |
|
306 |
int numIntervalos = Integer.parseInt(m_txtNumIntervals.getText()); |
307 |
int tipoClasificacion = EQUAL_INTERVALS;
|
308 |
|
309 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
310 |
System.out.println("Nombre del campo de clasificaci?n: " + |
311 |
fieldName); |
312 |
m_Renderer.setFieldName(fieldName); |
313 |
|
314 |
String nomField = m_Renderer.getFieldName();
|
315 |
|
316 |
// Cogemos el tipo de gradaci?n de colores que quiere el usuario y
|
317 |
// Creamos el primer y ?ltimo color.
|
318 |
Color startColor = m_colorChooser1.getColor();
|
319 |
m_Renderer.setStartColor(startColor); |
320 |
Color endColor = m_colorChooser2.getColor();
|
321 |
m_Renderer.setEndColor(endColor); |
322 |
int r;
|
323 |
int g;
|
324 |
int b;
|
325 |
int stepR;
|
326 |
int stepG;
|
327 |
int stepB;
|
328 |
r = startColor.getRed(); |
329 |
g = startColor.getGreen(); |
330 |
b = startColor.getBlue(); |
331 |
stepR = (endColor.getRed() - r) / numIntervalos; |
332 |
stepG = (endColor.getGreen() - g) / numIntervalos; |
333 |
stepB = (endColor.getBlue() - b) / numIntervalos; |
334 |
|
335 |
for (int i = 0; i < elRs.getFieldCount(); i++) { |
336 |
String nomAux = elRs.getFieldName(i).trim();
|
337 |
|
338 |
if (nomField.compareToIgnoreCase(nomAux) == 0) { |
339 |
idField = i; |
340 |
|
341 |
break;
|
342 |
} |
343 |
} |
344 |
|
345 |
if (idField == -1) { |
346 |
System.err.println("Campo no reconocido " + nomField); |
347 |
|
348 |
return;
|
349 |
} |
350 |
|
351 |
///m_symbolTable.removeAllItems();
|
352 |
///m_valuesCache = new Object[m_lyr.getSource().getShapeCount()];
|
353 |
|
354 |
int numSymbols = 0; |
355 |
FSymbol theSymbol; |
356 |
Date valorDate;
|
357 |
double minValue = Double.MAX_VALUE; |
358 |
double maxValue = Double.MIN_VALUE; |
359 |
Date minValueDate = null; |
360 |
Date maxValueDate = null; |
361 |
|
362 |
VectorialIntervalLegend auxLegend; |
363 |
auxLegend = LegendFactory.createVectorialIntervalLegend(m_lyr.getShapeType()); |
364 |
|
365 |
Value clave; |
366 |
Object resul;
|
367 |
int symbolType = 0; |
368 |
|
369 |
|
370 |
for (int j = 0; j < elRs.getRowCount(); j++) { |
371 |
clave = elRs.getFieldValue(j, idField); |
372 |
|
373 |
FInterval interval = auxLegend.getInterval(clave); |
374 |
|
375 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
|
376 |
if (auxLegend.getSymbolByInterval(interval) == null) { |
377 |
//si no esta creado el simbolo se crea
|
378 |
double valor=0; |
379 |
symbolType = m_lyr.getShapeType(); |
380 |
|
381 |
if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.IntValue") { |
382 |
valor = ((IntValue) clave).getValue(); |
383 |
} else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.DoubleValue") { |
384 |
valor = ((DoubleValue) clave).getValue(); |
385 |
} else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.FloatValue") { |
386 |
valor = ((FloatValue) clave).getValue(); |
387 |
} else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.LongValue") { |
388 |
valor = ((LongValue) clave).getValue(); |
389 |
} else if (clave.getClass().getName() == "com.hardcode.gdbms.engine.values.DateValue") { |
390 |
//TODO POR IMPLEMENTAR
|
391 |
///valorDate = elRs.getFieldValueAsDate(idField);
|
392 |
///if (valorDate.before(minValueDate)) minValueDate = valorDate;
|
393 |
///if (valorDate.after(maxValueDate)) maxValueDate = valorDate;
|
394 |
} |
395 |
if (valor < minValue) {
|
396 |
minValue = (double) valor;
|
397 |
} |
398 |
if (valor > maxValue) {
|
399 |
maxValue = (double) valor;
|
400 |
} |
401 |
} |
402 |
} |
403 |
|
404 |
switch (tipoClasificacion) {
|
405 |
case EQUAL_INTERVALS:
|
406 |
arrayIntervalos = calculateEqualIntervals(numIntervalos, |
407 |
minValue, maxValue); |
408 |
|
409 |
break;
|
410 |
|
411 |
case NATURAL_INTERVALS:
|
412 |
|
413 |
// POR HACER
|
414 |
break;
|
415 |
} |
416 |
|
417 |
intervals = arrayIntervalos; |
418 |
|
419 |
FInterval elIntervalo; |
420 |
NumberFormat.getInstance().setMaximumFractionDigits(2); |
421 |
m_Renderer.clear(); |
422 |
for (int k = 0; k < arrayIntervalos.length; k++) { |
423 |
elIntervalo = arrayIntervalos[k]; |
424 |
|
425 |
// clave = elIntervalo; // elIntervalo.getMin() + " - " + elIntervalo.getMax();
|
426 |
// System.out.println("k = " + k + " clave = " + clave);
|
427 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
|
428 |
// if (!m_Renderer.m_symbolList.containsKey(elIntervalo)) {
|
429 |
//si no esta creado el simbolo se crea
|
430 |
theSymbol = new FSymbol(symbolType, new Color(r, g, b)); |
431 |
theSymbol.setDescription(NumberFormat.getInstance().format(elIntervalo.getMin()) +
|
432 |
" - " +
|
433 |
NumberFormat.getInstance().format(elIntervalo.getMax()));
|
434 |
|
435 |
//////////////////////////////////////
|
436 |
// CALCULAMOS UN COLOR APROPIADO
|
437 |
r = r + stepR; |
438 |
g = g + stepG; |
439 |
b = b + stepB; |
440 |
|
441 |
/////////////////////////////////
|
442 |
m_Renderer.addSymbol(elIntervalo, theSymbol); |
443 |
System.out.println("addSymbol = "+elIntervalo+" theSymbol = "+theSymbol.getDescription()); |
444 |
numSymbols++; |
445 |
|
446 |
if (numSymbols > 100) { |
447 |
JOptionPane.showMessageDialog(this, |
448 |
"M?s 100 de s?mbolos no aportan informaci?n en un plano. Por favor, revise el campo seleccionado.");
|
449 |
|
450 |
break;
|
451 |
} |
452 |
|
453 |
// }
|
454 |
} // for
|
455 |
|
456 |
System.out.println("Num. Simbolos = " + |
457 |
m_Renderer.getValues().length); |
458 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(), |
459 |
m_Renderer.getValues(), m_Renderer.getDescriptions()); |
460 |
elRs.stop(); |
461 |
} catch (DriverException e) {
|
462 |
// TODO Auto-generated catch block
|
463 |
e.printStackTrace(); |
464 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
465 |
e.printStackTrace(); |
466 |
} |
467 |
|
468 |
m_btnDeleteAll.setEnabled(true);
|
469 |
m_btnDelete.setEnabled(true);
|
470 |
} |
471 |
|
472 |
/**
|
473 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo
|
474 |
* el symbolList, si no tambi?n el arrayKeys y el defaultRenderer
|
475 |
*/
|
476 |
private void fillSymbolListFromTable() { |
477 |
String clave;
|
478 |
FSymbol theSymbol; |
479 |
FInterval theInterval = null;
|
480 |
|
481 |
// Borramos las anteriores listas:
|
482 |
m_Renderer.clear(); |
483 |
|
484 |
boolean bRestoValores = false; // PONERLO EN UN CHECKBOX |
485 |
double from = 0; |
486 |
double to = 0; |
487 |
String[] arraySplit = new String[2]; |
488 |
int hasta;
|
489 |
String fieldName = (String) m_cboFields.getSelectedItem(); |
490 |
m_Renderer.setFieldName(fieldName); |
491 |
|
492 |
if (bRestoValores) {
|
493 |
hasta = m_symbolTable.getRowCount() - 1;
|
494 |
} else {
|
495 |
hasta = m_symbolTable.getRowCount(); |
496 |
} |
497 |
|
498 |
for (int row = 0; row < m_symbolTable.getRowCount(); row++) { |
499 |
// clave = m_symbolTable.getFieldValue(row,1);
|
500 |
theInterval = (FInterval) m_symbolTable.getFieldValue(row, 1);
|
501 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(row, 0);
|
502 |
theSymbol.setDescription((String) m_symbolTable.getFieldValue(row, 2)); |
503 |
m_Renderer.addSymbol(theInterval, theSymbol); |
504 |
|
505 |
///m_Renderer.m_legendIntervals.add(theInterval);
|
506 |
} |
507 |
|
508 |
if (bRestoValores) {
|
509 |
//m_Renderer.m_bUseDefaultSymbol = true;
|
510 |
theSymbol = (FSymbol) m_symbolTable.getFieldValue(hasta, 0);
|
511 |
m_Renderer.setDefaultSymbol(theSymbol); |
512 |
} |
513 |
} |
514 |
|
515 |
|
516 |
/**
|
517 |
* DOCUMENT ME!
|
518 |
*/
|
519 |
private void fillFieldNames() { |
520 |
DataSource rs = null; |
521 |
ArrayList nomFields = null; |
522 |
|
523 |
try {
|
524 |
rs = ((AlphanumericData) m_lyr).getRecordset(); |
525 |
logger.debug("rs.start()");
|
526 |
rs.start(); |
527 |
|
528 |
nomFields = new ArrayList(); |
529 |
Value val; |
530 |
|
531 |
for (int i = 0; i < rs.getFieldCount(); i++) { |
532 |
//TODO deber?a de existir un getFieldType
|
533 |
val = rs.getFieldValue(0,i);
|
534 |
if (val==null || val.getClass() == NullValue.class ) continue; |
535 |
if ((val.getClass() == IntValue.class) ||
|
536 |
(val.getClass() == DoubleValue.class) || |
537 |
(val.getClass() == FloatValue.class) || |
538 |
(val.getClass() == LongValue.class)) { |
539 |
nomFields.add(rs.getFieldName(i).trim()); |
540 |
} |
541 |
} |
542 |
|
543 |
rs.stop(); |
544 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
545 |
e1.printStackTrace(); |
546 |
} catch (DriverException e) {
|
547 |
e.printStackTrace(); |
548 |
} |
549 |
|
550 |
/* ArrayList nomFields = new ArrayList();
|
551 |
for (int i = 0; i < rs.getFieldsCount(); i++) {
|
552 |
if ((rs.getFieldType(i) == FRecordset.INTEGER) ||
|
553 |
(rs.getFieldType(i) == FRecordset.DECIMAL) ||
|
554 |
(rs.getFieldType(i) == FRecordset.DATE))
|
555 |
{
|
556 |
nomFields.add(rs.getFieldName(i).trim());
|
557 |
}
|
558 |
|
559 |
}
|
560 |
*/
|
561 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray()); |
562 |
m_cboFields.setModel(cM); |
563 |
|
564 |
// fieldsListValor.setSelectedIndex(0);
|
565 |
m_symbolTable.removeAllItems(); |
566 |
} |
567 |
|
568 |
/**
|
569 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer,
|
570 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
571 |
*/
|
572 |
public void setLayer(FLayer lyr, Legend r) { |
573 |
// m_TOC = t;
|
574 |
// OJO, COMPROBAR ANTES SI ES DE TIPO VECTORIAL
|
575 |
// m_lyr = (FLyrVect) t.getFirstLyrVectSelected();
|
576 |
m_lyr = (ClassifiableVectorial) lyr; |
577 |
fillFieldNames(); |
578 |
|
579 |
if (r instanceof VectorialIntervalLegend) { |
580 |
m_Renderer = (VectorialIntervalLegend) r; |
581 |
m_cboFields.getModel().setSelectedItem(m_Renderer.getFieldName()); |
582 |
m_symbolTable.fillTableFromSymbolList(m_Renderer.getSymbols(), |
583 |
m_Renderer.getValues(), m_Renderer.getDescriptions()); |
584 |
m_colorChooser1.setColor(m_Renderer.getStartColor()); |
585 |
m_colorChooser2.setColor(m_Renderer.getEndColor()); |
586 |
m_colorChooser1.repaint(); |
587 |
m_colorChooser2.repaint(); |
588 |
} else {
|
589 |
try {
|
590 |
// Si la capa viene con otro tipo de leyenda, creamos
|
591 |
// una nueva del tipo que maneja este panel
|
592 |
m_Renderer = new VectorialIntervalLegend(m_lyr.getShapeType());
|
593 |
} catch (DriverException e) {
|
594 |
// TODO Auto-generated catch block
|
595 |
e.printStackTrace(); |
596 |
} |
597 |
} |
598 |
} |
599 |
|
600 |
/**
|
601 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
602 |
*/
|
603 |
public Legend getLegend() {
|
604 |
fillSymbolListFromTable(); |
605 |
|
606 |
return m_Renderer;
|
607 |
} |
608 |
|
609 |
/**
|
610 |
* DOCUMENT ME!
|
611 |
*
|
612 |
* @author Vicente Caballero Navarro
|
613 |
*/
|
614 |
class MyListener implements ActionListener { |
615 |
//private FLyrShp m_layer;
|
616 |
// private FPanelLegendValues m_Parent;
|
617 |
public MyListener() { // FPanelLegendValues p) { |
618 |
|
619 |
// m_Parent = p;
|
620 |
} |
621 |
|
622 |
/**
|
623 |
* DOCUMENT ME!
|
624 |
*
|
625 |
* @param e DOCUMENT ME!
|
626 |
*/
|
627 |
public void actionPerformed(ActionEvent e) { |
628 |
// rellenarValue();
|
629 |
System.out.println("ActionEvent con " + e.getActionCommand()); |
630 |
|
631 |
//modificar el combobox de valor
|
632 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
633 |
JComboBox cb = (JComboBox) e.getSource(); |
634 |
String fieldName = (String) cb.getSelectedItem(); |
635 |
System.out.println("Nombre del campo: " + fieldName); |
636 |
m_symbolTable.removeAllItems(); |
637 |
|
638 |
m_Renderer.setFieldName(fieldName); |
639 |
} |
640 |
|
641 |
//A?adir todos los elementos por valor
|
642 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
643 |
fillTableValues(); |
644 |
} |
645 |
|
646 |
//A?adir un ?nico elemento
|
647 |
if (e.getActionCommand() == "ADD_VALUE") { |
648 |
/* a?adir("Nuevo_Valor");
|
649 |
aceptar.setEnabled(true);
|
650 |
quitartodo.setEnabled(true);
|
651 |
quitar.setEnabled(true); */
|
652 |
} |
653 |
|
654 |
//Vacia la tabla
|
655 |
if (e.getActionCommand() == "REMOVE_ALL") { |
656 |
m_symbolTable.removeAllItems(); |
657 |
|
658 |
// aceptar.setEnabled(false);
|
659 |
} |
660 |
|
661 |
//Quitar solo el elemento seleccionado
|
662 |
if (e.getActionCommand() == "REMOVE") { |
663 |
m_symbolTable.removeSelectedRows(); |
664 |
} |
665 |
} |
666 |
} |
667 |
} |