root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / VectorialInterval.java @ 20779
History | View | Annotate | Download (28.2 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.FlowLayout; |
46 |
import java.awt.GridLayout; |
47 |
import java.awt.event.ActionEvent; |
48 |
import java.awt.event.ActionListener; |
49 |
import java.io.File; |
50 |
import java.io.IOException; |
51 |
import java.sql.Types; |
52 |
import java.text.NumberFormat; |
53 |
import java.util.ArrayList; |
54 |
|
55 |
import javax.swing.BorderFactory; |
56 |
import javax.swing.DefaultComboBoxModel; |
57 |
import javax.swing.ImageIcon; |
58 |
import javax.swing.JCheckBox; |
59 |
import javax.swing.JComboBox; |
60 |
import javax.swing.JOptionPane; |
61 |
import javax.swing.JPanel; |
62 |
import javax.swing.JTextField; |
63 |
|
64 |
import org.apache.log4j.Logger; |
65 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
66 |
import org.gvsig.gui.beans.swing.JButton; |
67 |
|
68 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
69 |
import com.hardcode.gdbms.engine.data.DataSource; |
70 |
import com.iver.andami.PluginServices; |
71 |
import com.iver.andami.messages.NotificationManager; |
72 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
73 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
74 |
import com.iver.cit.gvsig.fmap.core.styles.IMarkerFillPropertiesStyle; |
75 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
76 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
77 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
78 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
79 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
80 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
81 |
import com.iver.cit.gvsig.fmap.rendering.FInterval; |
82 |
import com.iver.cit.gvsig.fmap.rendering.IInterval; |
83 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
84 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
85 |
import com.iver.cit.gvsig.fmap.rendering.NullIntervalValue; |
86 |
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
87 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
88 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
89 |
|
90 |
|
91 |
/**
|
92 |
* DOCUMENT ME!
|
93 |
*
|
94 |
* @author Vicente Caballero Navarro
|
95 |
*/
|
96 |
public class VectorialInterval extends JPanel implements ILegendPanel{ |
97 |
private static Logger logger = Logger.getLogger(VectorialInterval.class.getName()); |
98 |
private GridBagLayoutPanel pnlGeneral = null; |
99 |
protected JComboBox cmbField = null; |
100 |
protected JTextField txtNumIntervals = null; |
101 |
private ColorChooserPanel colorChooserPanel = null; |
102 |
private ColorChooserPanel colorChooserPanel1 = null; |
103 |
protected JCheckBox chkdefaultvalues = null; |
104 |
protected JComboBox cmbFieldType = null; |
105 |
private JPanel panelS = null; |
106 |
private JButton bintervals = null; |
107 |
private JButton bInsert = null; |
108 |
protected JButton bDelAll = null; |
109 |
protected JButton bDel = null; |
110 |
private int count = 0; |
111 |
protected ClassifiableVectorial layer;
|
112 |
protected VectorialIntervalLegend theLegend;
|
113 |
protected VectorialIntervalLegend auxLegend = null; |
114 |
protected SymbolTable symbolTable;
|
115 |
private MyListener listener = new MyListener(); |
116 |
protected JPanel pnlCenter = null; |
117 |
protected JPanel optionPanel; |
118 |
private JPanel pnlNorth; |
119 |
|
120 |
/**
|
121 |
* This is the default constructor
|
122 |
*/
|
123 |
public VectorialInterval() {
|
124 |
super();
|
125 |
initialize(); |
126 |
} |
127 |
|
128 |
/**
|
129 |
* This method initializes this
|
130 |
*/
|
131 |
private void initialize() { |
132 |
this.setLayout(new BorderLayout()); |
133 |
this.setSize(700, 350); |
134 |
this.add(getPnlNorth(), BorderLayout.NORTH); |
135 |
|
136 |
this.add(getPnlButtons(), BorderLayout.SOUTH); |
137 |
this.add(getPnlCenter(), BorderLayout.CENTER); |
138 |
setOptionPanel(getOptionPanel()); |
139 |
} |
140 |
|
141 |
private JPanel getPnlNorth() { |
142 |
if (pnlNorth == null) { |
143 |
pnlNorth = new JPanel(new GridLayout(1, 2)); |
144 |
pnlNorth.add(getGeneralPanel()); |
145 |
} |
146 |
return pnlNorth;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* This method initializes panelN
|
151 |
*
|
152 |
* @return javax.swing.JPanel
|
153 |
*/
|
154 |
private JPanel getGeneralPanel() { |
155 |
if (pnlGeneral == null) { |
156 |
pnlGeneral = new GridBagLayoutPanel();
|
157 |
pnlGeneral.setBorder(BorderFactory.
|
158 |
createTitledBorder(null,
|
159 |
PluginServices.getText(this, "fields"))); |
160 |
pnlGeneral.addComponent(PluginServices.getText(this, "Campo_de_clasificacion"), |
161 |
getCmbFields()); |
162 |
pnlGeneral.addComponent(PluginServices.getText(this, "tipo_de_intervalo"), |
163 |
getCmbIntervalTypes()); |
164 |
|
165 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); |
166 |
aux.add(getTxtNumIntervals()); |
167 |
pnlGeneral.addComponent(PluginServices.getText(this, "No_de_intervalos"), |
168 |
aux); |
169 |
pnlGeneral.addComponent("", getChkDefaultvalues());
|
170 |
|
171 |
} |
172 |
return pnlGeneral;
|
173 |
} |
174 |
|
175 |
public JPanel getOptionPanel() { |
176 |
if (optionPanel == null) { |
177 |
optionPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
178 |
optionPanel.setBorder(BorderFactory.
|
179 |
createTitledBorder(null,
|
180 |
PluginServices.getText(this, "color_ramp"))); |
181 |
|
182 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
183 |
aux.addComponent(PluginServices.getText(this, "Color_final"), |
184 |
getColorChooserPanel()); |
185 |
aux.addComponent(PluginServices.getText(this, "Color_inicio"), |
186 |
getColorChooserPanel1()); |
187 |
optionPanel.add(aux); |
188 |
} |
189 |
return optionPanel;
|
190 |
} |
191 |
|
192 |
private void setOptionPanel(JPanel p) { |
193 |
getPnlNorth().remove(getOptionPanel()); |
194 |
getPnlNorth().add(p, BorderLayout.NORTH);
|
195 |
} |
196 |
/**
|
197 |
* This method initializes jComboBox
|
198 |
*
|
199 |
* @return javax.swing.JComboBox
|
200 |
*/
|
201 |
private JComboBox getCmbFields() { |
202 |
if (cmbField == null) { |
203 |
cmbField = new JComboBox(); |
204 |
cmbField.setActionCommand("FIELD_SELECTED");
|
205 |
cmbField.addActionListener(listener); |
206 |
cmbField.setVisible(true);
|
207 |
} |
208 |
|
209 |
return cmbField;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* This method initializes txtNumIntervals
|
214 |
*
|
215 |
* @return javax.swing.JTextField
|
216 |
*/
|
217 |
private JTextField getTxtNumIntervals() { |
218 |
if (txtNumIntervals == null) { |
219 |
txtNumIntervals = new JTextField(5); |
220 |
txtNumIntervals.setText("5");
|
221 |
} |
222 |
|
223 |
return txtNumIntervals;
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* This method initializes colorChooserPanel
|
228 |
*
|
229 |
* @return com.iver.cit.gvsig.gui.Panels.ColorChooserPanel
|
230 |
*/
|
231 |
private ColorChooserPanel getColorChooserPanel() {
|
232 |
if (colorChooserPanel == null) { |
233 |
colorChooserPanel = new ColorChooserPanel();
|
234 |
colorChooserPanel.setBounds(new java.awt.Rectangle(108, 49, 54, 20)); |
235 |
colorChooserPanel.setAlpha(255);
|
236 |
colorChooserPanel.setColor(Color.red);
|
237 |
} |
238 |
|
239 |
return colorChooserPanel;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* This method initializes colorChooserPanel1
|
244 |
*
|
245 |
* @return com.iver.cit.gvsig.gui.Panels.ColorChooserPanel
|
246 |
*/
|
247 |
private ColorChooserPanel getColorChooserPanel1() {
|
248 |
if (colorChooserPanel1 == null) { |
249 |
colorChooserPanel1 = new ColorChooserPanel();
|
250 |
colorChooserPanel1.setBounds(new java.awt.Rectangle(251, 49, 54, 20)); |
251 |
colorChooserPanel1.setAlpha(255);
|
252 |
colorChooserPanel1.setColor(Color.blue);
|
253 |
} |
254 |
|
255 |
return colorChooserPanel1;
|
256 |
} |
257 |
|
258 |
/**
|
259 |
* This method initializes chkdefaultvalues
|
260 |
*
|
261 |
* @return javax.swing.JCheckBox
|
262 |
*/
|
263 |
protected JCheckBox getChkDefaultvalues() { |
264 |
if (chkdefaultvalues == null) { |
265 |
chkdefaultvalues = new JCheckBox(); |
266 |
chkdefaultvalues.setText(PluginServices.getText(this,
|
267 |
"resto_valores"));
|
268 |
chkdefaultvalues.setBounds(new java.awt.Rectangle(342, 26, 141, 20)); |
269 |
chkdefaultvalues.addActionListener(new java.awt.event.ActionListener() {
|
270 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
271 |
if (auxLegend==null)auxLegend=theLegend; |
272 |
if (chkdefaultvalues.isSelected()) {
|
273 |
addDefault(); |
274 |
} else {
|
275 |
delDefault(); |
276 |
} |
277 |
} |
278 |
}); |
279 |
} |
280 |
|
281 |
return chkdefaultvalues;
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* This method initializes jComboBox1
|
286 |
*
|
287 |
* @return javax.swing.JComboBox
|
288 |
*/
|
289 |
private JComboBox getCmbIntervalTypes() { |
290 |
if (cmbFieldType == null) { |
291 |
cmbFieldType = new JComboBox(); |
292 |
cmbFieldType.setActionCommand("INTERVAL_TYPE");
|
293 |
cmbFieldType.addActionListener(listener); |
294 |
cmbFieldType.addItem(PluginServices.getText(this, "equal_intervals")); |
295 |
cmbFieldType.addItem(PluginServices.getText(this,
|
296 |
"natural_intervals"));
|
297 |
cmbFieldType.addItem(PluginServices.getText(this,
|
298 |
"quantile_intervals"));
|
299 |
cmbFieldType.setVisible(true);
|
300 |
} |
301 |
|
302 |
return cmbFieldType;
|
303 |
} |
304 |
|
305 |
/**
|
306 |
* This method initializes panelS
|
307 |
*
|
308 |
* @return javax.swing.JPanel
|
309 |
*/
|
310 |
protected JPanel getPnlButtons() { |
311 |
if (panelS == null) { |
312 |
panelS = new JPanel(); |
313 |
panelS.setPreferredSize(new java.awt.Dimension(417, 32)); |
314 |
panelS.add(getBintervals(), null);
|
315 |
panelS.add(getBInsert(), null);
|
316 |
panelS.add(getBDelAll(), null);
|
317 |
panelS.add(getBDel(), null);
|
318 |
} |
319 |
|
320 |
return panelS;
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* This method initializes bintervals
|
325 |
*
|
326 |
* @return javax.swing.JButton
|
327 |
*/
|
328 |
private JButton getBintervals() { |
329 |
if (bintervals == null) { |
330 |
bintervals = new JButton(); |
331 |
bintervals.setActionCommand("ADD_ALL_VALUES");
|
332 |
bintervals.addActionListener(listener); |
333 |
bintervals.setText(PluginServices.getText(this,
|
334 |
"Calcular_intervalos"));
|
335 |
} |
336 |
|
337 |
return bintervals;
|
338 |
} |
339 |
|
340 |
/**
|
341 |
* This method initializes bInsert
|
342 |
*
|
343 |
* @return javax.swing.JButton
|
344 |
*/
|
345 |
private JButton getBInsert() { |
346 |
if (bInsert == null) { |
347 |
bInsert = new JButton(); |
348 |
bInsert.setActionCommand("ADD_VALUE");
|
349 |
bInsert.addActionListener(listener); |
350 |
bInsert.setText(PluginServices.getText(this, "Anadir")); |
351 |
} |
352 |
|
353 |
return bInsert;
|
354 |
} |
355 |
|
356 |
/**
|
357 |
* This method initializes bDelAll
|
358 |
*
|
359 |
* @return javax.swing.JButton
|
360 |
*/
|
361 |
private JButton getBDelAll() { |
362 |
if (bDelAll == null) { |
363 |
bDelAll = new JButton(); |
364 |
bDelAll.setActionCommand("REMOVE_ALL");
|
365 |
bDelAll.addActionListener(listener); |
366 |
bDelAll.setText(PluginServices.getText(this, "Quitar_todos")); |
367 |
} |
368 |
|
369 |
return bDelAll;
|
370 |
} |
371 |
|
372 |
/**
|
373 |
* This method initializes bDel
|
374 |
*
|
375 |
* @return javax.swing.JButton
|
376 |
*/
|
377 |
private JButton getBDel() { |
378 |
if (bDel == null) { |
379 |
bDel = new JButton(); |
380 |
bDel.setText(PluginServices.getText(this, "Quitar")); |
381 |
bDel.setActionCommand("REMOVE");
|
382 |
bDel.addActionListener(listener); |
383 |
} |
384 |
|
385 |
return bDel;
|
386 |
} |
387 |
|
388 |
|
389 |
/**
|
390 |
* Damos una primera pasada para saber los l�mites inferior y superior y
|
391 |
* rellenar un array con los valores. Luego dividimos ese array en
|
392 |
* intervalos.
|
393 |
*/
|
394 |
protected void fillTableValues() { |
395 |
|
396 |
symbolTable.removeAllItems(); |
397 |
|
398 |
try {
|
399 |
FInterval[] arrayIntervalos = calculateIntervals();
|
400 |
if (arrayIntervalos == null) |
401 |
return;
|
402 |
|
403 |
FInterval interval; |
404 |
NumberFormat.getInstance().setMaximumFractionDigits(2); |
405 |
//theLegend.clear();
|
406 |
auxLegend.clear(); |
407 |
|
408 |
int r;
|
409 |
int g;
|
410 |
int b;
|
411 |
int stepR;
|
412 |
int stepG;
|
413 |
int stepB;
|
414 |
|
415 |
// Cogemos el tipo de gradaci�n de colores que quiere el usuario y
|
416 |
// Creamos el primer y �ltimo color.
|
417 |
Color startColor = colorChooserPanel.getColor();
|
418 |
//theLegend.setStartColor(startColor);
|
419 |
auxLegend.setStartColor(startColor); |
420 |
|
421 |
Color endColor = colorChooserPanel1.getColor();
|
422 |
//theLegend.setEndColor(endColor);
|
423 |
auxLegend.setEndColor(endColor); |
424 |
|
425 |
r = startColor.getRed(); |
426 |
g = startColor.getGreen(); |
427 |
b = startColor.getBlue(); |
428 |
stepR = (endColor.getRed() - r) / arrayIntervalos.length; |
429 |
stepG = (endColor.getGreen() - g) / arrayIntervalos.length; |
430 |
stepB = (endColor.getBlue() - b) / arrayIntervalos.length; |
431 |
|
432 |
auxLegend = LegendFactory.createVectorialIntervalLegend(layer.getShapeType()); |
433 |
|
434 |
if (chkdefaultvalues.isSelected()) {
|
435 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
436 |
auxLegend.addSymbol(new NullIntervalValue(),
|
437 |
auxLegend.getDefaultSymbol()); |
438 |
} |
439 |
|
440 |
int symbolType = layer.getShapeType();
|
441 |
int numSymbols = 0; |
442 |
|
443 |
for (int k = 0; k < arrayIntervalos.length; k++) { |
444 |
interval = arrayIntervalos[k]; |
445 |
|
446 |
ISymbol theSymbol = SymbologyFactory.createDefaultSymbolByShapeType( |
447 |
symbolType, |
448 |
new Color(r, g, b)); |
449 |
theSymbol.setDescription(NumberFormat.getInstance().format(interval.getMin()) +
|
450 |
" - " +
|
451 |
NumberFormat.getInstance().format(interval.getMax()));
|
452 |
|
453 |
//////////////////////////////////////
|
454 |
// CALCULAMOS UN COLOR APROPIADO
|
455 |
r = r + stepR; |
456 |
g = g + stepG; |
457 |
b = b + stepB; |
458 |
|
459 |
/////////////////////////////////
|
460 |
auxLegend.addSymbol(interval, theSymbol); |
461 |
System.out.println("addSymbol = " + interval + |
462 |
" theSymbol = " + theSymbol.getDescription());
|
463 |
numSymbols++; |
464 |
|
465 |
if (numSymbols > 100) { |
466 |
int resp = JOptionPane.showConfirmDialog(this, |
467 |
PluginServices.getText(this, "mas_de_100_simbolos"), |
468 |
PluginServices.getText(this, "quiere_continuar"), |
469 |
JOptionPane.YES_NO_OPTION,
|
470 |
JOptionPane.WARNING_MESSAGE);
|
471 |
|
472 |
if ((resp == JOptionPane.NO_OPTION) || |
473 |
(resp == JOptionPane.DEFAULT_OPTION)) {
|
474 |
return;
|
475 |
} |
476 |
} |
477 |
|
478 |
// }
|
479 |
} // for
|
480 |
|
481 |
System.out.println("Num. Simbolos = " + |
482 |
auxLegend.getValues().length); |
483 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
484 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
485 |
|
486 |
} catch (ReadDriverException e) {
|
487 |
NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e); |
488 |
} catch (LegendLayerException e) {
|
489 |
NotificationManager.addError(PluginServices.getText(this, "failed_computing_intervals"), e); |
490 |
} |
491 |
|
492 |
bDelAll.setEnabled(true);
|
493 |
bDel.setEnabled(true);
|
494 |
} |
495 |
|
496 |
protected FInterval[] calculateIntervals() throws LegendLayerException { |
497 |
int intervalCount = 1; |
498 |
// ensure the interval value is an integer greather than 0
|
499 |
try {
|
500 |
intervalCount = (int) Double. |
501 |
parseDouble(txtNumIntervals.getText()); |
502 |
if (intervalCount<1) { |
503 |
throw new Exception(); |
504 |
} |
505 |
} catch (Exception e) { |
506 |
JOptionPane.showMessageDialog(this, |
507 |
PluginServices.getText(this, "invalid_interval_count_value")); |
508 |
return null; |
509 |
} |
510 |
|
511 |
try {
|
512 |
|
513 |
return auxLegend.calculateIntervals(
|
514 |
//return theLegend.calculateIntervals(
|
515 |
((AlphanumericData) layer).getRecordset(), |
516 |
(String) cmbField.getSelectedItem(),
|
517 |
intervalCount, |
518 |
layer.getShapeType() |
519 |
); |
520 |
} catch (ReadDriverException e) {
|
521 |
return null; |
522 |
} |
523 |
} |
524 |
|
525 |
public void setData(FLayer layer, ILegend legend) { |
526 |
this.layer = (ClassifiableVectorial) layer;
|
527 |
int shapeType = 0; |
528 |
try {
|
529 |
shapeType = this.layer.getShapeType();
|
530 |
} catch (ReadDriverException e) {
|
531 |
NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e); |
532 |
} |
533 |
|
534 |
if (symbolTable != null) |
535 |
pnlCenter.remove(symbolTable); |
536 |
|
537 |
|
538 |
symbolTable = new SymbolTable(this, SymbolTable.INTERVALS_TYPE, shapeType); |
539 |
pnlCenter.add(symbolTable); |
540 |
fillFieldNames(); |
541 |
|
542 |
/* if (legend instanceof VectorialIntervalLegend) {
|
543 |
theLegend = (VectorialIntervalLegend) legend;
|
544 |
getChkDefaultvalues().setSelected(theLegend.isUseDefaultSymbol());
|
545 |
cmbField.getModel().setSelectedItem(theLegend.getClassifyingFieldNames()[0]);
|
546 |
symbolTable.fillTableFromSymbolList(theLegend.getSymbols(),
|
547 |
theLegend.getValues(), theLegend.getDescriptions());
|
548 |
colorChooserPanel.setColor(theLegend.getStartColor());
|
549 |
colorChooserPanel1.setColor(theLegend.getEndColor());
|
550 |
colorChooserPanel.repaint();
|
551 |
colorChooserPanel1.repaint();
|
552 |
} else {
|
553 |
// Si la capa viene con otro tipo de leyenda, creamos
|
554 |
// una nueva del tipo que maneja este panel
|
555 |
theLegend = new VectorialIntervalLegend();
|
556 |
theLegend.setShapeType(shapeType);
|
557 |
}
|
558 |
|
559 |
|
560 |
cmbFieldType.setSelectedIndex(theLegend.getIntervalType());
|
561 |
*/
|
562 |
if (VectorialIntervalLegend.class.equals(legend.getClass())) {
|
563 |
auxLegend = (VectorialIntervalLegend) legend; |
564 |
getChkDefaultvalues().setSelected(auxLegend.isUseDefaultSymbol()); |
565 |
cmbField.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
|
566 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
567 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
568 |
colorChooserPanel.setColor(auxLegend.getStartColor()); |
569 |
colorChooserPanel1.setColor(auxLegend.getEndColor()); |
570 |
colorChooserPanel.repaint(); |
571 |
colorChooserPanel1.repaint(); |
572 |
} else {
|
573 |
// Si la capa viene con otro tipo de leyenda, creamos
|
574 |
// una nueva del tipo que maneja este panel
|
575 |
auxLegend = new VectorialIntervalLegend();
|
576 |
auxLegend.setShapeType(shapeType); |
577 |
} |
578 |
|
579 |
cmbFieldType.setSelectedIndex(auxLegend.getIntervalType()); |
580 |
} |
581 |
|
582 |
|
583 |
protected void fillFieldNames() { |
584 |
DataSource rs = null; |
585 |
ArrayList nomFields = null; |
586 |
|
587 |
try {
|
588 |
rs = ((AlphanumericData) layer).getRecordset(); |
589 |
logger.debug("rs.start()");
|
590 |
rs.start(); |
591 |
|
592 |
nomFields = new ArrayList(); |
593 |
|
594 |
int type;
|
595 |
for (int i = 0; i < rs.getFieldCount(); i++) { |
596 |
type = rs.getFieldType(i); |
597 |
|
598 |
if (type == Types.NULL) { |
599 |
continue;
|
600 |
} |
601 |
|
602 |
if ((type == Types.INTEGER) || |
603 |
(type == Types.DOUBLE) ||
|
604 |
(type == Types.FLOAT) ||
|
605 |
(type == Types.BIGINT)) {
|
606 |
nomFields.add(rs.getFieldName(i).trim()); |
607 |
} |
608 |
} |
609 |
|
610 |
rs.stop(); |
611 |
} catch (ReadDriverException e) {
|
612 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
613 |
} |
614 |
|
615 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray()); |
616 |
cmbField.setModel(cM); |
617 |
|
618 |
symbolTable.removeAllItems(); |
619 |
} |
620 |
|
621 |
/**
|
622 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
623 |
*/
|
624 |
public ILegend getLegend() {
|
625 |
fillSymbolListFromTable(); |
626 |
theLegend = auxLegend; |
627 |
return theLegend;
|
628 |
} |
629 |
/*
|
630 |
public ILegend getLegend() {
|
631 |
fillSymbolListFromTable();
|
632 |
|
633 |
if (auxLegend != null) {
|
634 |
// your settings that are not the set of symbols must be located here
|
635 |
auxLegend.setClassifyingFieldNames(
|
636 |
new String[] {(String) getCmbFields().getSelectedItem()});
|
637 |
|
638 |
|
639 |
|
640 |
theLegend = auxLegend;
|
641 |
}
|
642 |
|
643 |
return theLegend;
|
644 |
}*/
|
645 |
|
646 |
/**
|
647 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo
|
648 |
* el symbolList, si no tambi�n el arrayKeys y el defaultRenderer
|
649 |
*/
|
650 |
/*private void fillSymbolListFromTable() {
|
651 |
ISymbol theSymbol;
|
652 |
IInterval theInterval = null;
|
653 |
|
654 |
// Borramos las anteriores listas:
|
655 |
theLegend.clear();
|
656 |
|
657 |
String fieldName = (String) cmbField.getSelectedItem();
|
658 |
theLegend.setClassifyingFieldNames(new String[] {fieldName});
|
659 |
|
660 |
for (int row = 0; row < symbolTable.getRowCount(); row++) {
|
661 |
if (!(symbolTable.getFieldValue(row, 1) instanceof FInterval)) {
|
662 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
663 |
theSymbol.setDescription((String) symbolTable.getFieldValue(
|
664 |
row, 2));
|
665 |
theLegend.addSymbol(new NullIntervalValue(), theSymbol);
|
666 |
} else {
|
667 |
theInterval = (IInterval) symbolTable.getFieldValue(row, 1);
|
668 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
669 |
theSymbol.setDescription((String) symbolTable.getFieldValue(
|
670 |
row, 2));
|
671 |
theLegend.addSymbol(theInterval, theSymbol);
|
672 |
}
|
673 |
|
674 |
}
|
675 |
}*/
|
676 |
private void fillSymbolListFromTable() { |
677 |
ISymbol theSymbol; |
678 |
IInterval theInterval = null;
|
679 |
|
680 |
// Borramos las anteriores listas:
|
681 |
auxLegend.clear(); |
682 |
|
683 |
String fieldName = (String) cmbField.getSelectedItem(); |
684 |
auxLegend.setClassifyingFieldNames(new String[] {fieldName}); |
685 |
|
686 |
DataSource rs;
|
687 |
try {
|
688 |
|
689 |
rs = ((AlphanumericData) layer).getRecordset(); |
690 |
rs.start(); |
691 |
auxLegend.setClassifyingFieldTypes(new int[] {rs.getFieldType(rs.getFieldIndexByName(fieldName))}); |
692 |
logger.debug("rs.start()");
|
693 |
rs.stop(); |
694 |
|
695 |
} catch (ReadDriverException e) {
|
696 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
697 |
} |
698 |
|
699 |
|
700 |
|
701 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
702 |
if (!(symbolTable.getFieldValue(row, 1) instanceof FInterval)) { |
703 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
704 |
theSymbol.setDescription((String) symbolTable.getFieldValue(
|
705 |
row, 2));
|
706 |
auxLegend.addSymbol(new NullIntervalValue(), theSymbol);
|
707 |
} else {
|
708 |
theInterval = (IInterval) symbolTable.getFieldValue(row, 1);
|
709 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
710 |
theSymbol.setDescription((String) symbolTable.getFieldValue(
|
711 |
row, 2));
|
712 |
auxLegend.addSymbol(theInterval, theSymbol); |
713 |
} |
714 |
|
715 |
} |
716 |
} |
717 |
|
718 |
/**
|
719 |
* This method initializes panelC
|
720 |
*
|
721 |
* @return javax.swing.JPanel
|
722 |
*/
|
723 |
private JPanel getPnlCenter() { |
724 |
if (pnlCenter == null) { |
725 |
pnlCenter = new JPanel(); |
726 |
} |
727 |
|
728 |
return pnlCenter;
|
729 |
} |
730 |
|
731 |
/**
|
732 |
* A�ade la fila y el s�mbolo para el resto de valores no representados.
|
733 |
*/
|
734 |
private void addDefault() { |
735 |
|
736 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
737 |
auxLegend.addSymbol(new NullIntervalValue(),
|
738 |
auxLegend.getDefaultSymbol()); |
739 |
symbolTable.addTableRecord(auxLegend.getDefaultSymbol(), |
740 |
new NullIntervalValue(),
|
741 |
auxLegend.getDefaultSymbol().getDescription()); |
742 |
symbolTable.repaint(); |
743 |
} |
744 |
|
745 |
/**
|
746 |
* Elimina la fila de la tabla y el s�mbolo del resto de valores no
|
747 |
* representados por ning�n valor.
|
748 |
*/
|
749 |
private void delDefault() { |
750 |
auxLegend.delSymbol(new NullIntervalValue());
|
751 |
symbolTable.removeRow(new NullIntervalValue());
|
752 |
symbolTable.repaint(); |
753 |
} |
754 |
|
755 |
/**
|
756 |
* Listener.
|
757 |
*
|
758 |
* @author Vicente Caballero Navarro
|
759 |
*/
|
760 |
class MyListener implements ActionListener { |
761 |
|
762 |
public void actionPerformed(ActionEvent e) { |
763 |
System.out.println("ActionEvent con " + e.getActionCommand()); |
764 |
|
765 |
//modificar el combobox de valor
|
766 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
767 |
JComboBox cb = (JComboBox) e.getSource(); |
768 |
String fieldName = (String) cb.getSelectedItem(); |
769 |
System.out.println("Nombre del campo: " + fieldName); |
770 |
symbolTable.removeAllItems(); |
771 |
|
772 |
//theLegend.setClassifyingFieldNames(new String[] {fieldName});
|
773 |
auxLegend.setClassifyingFieldNames(new String[] {fieldName}); |
774 |
} else if (e.getActionCommand() == "INTERVAL_TYPE") { |
775 |
JComboBox cb = (JComboBox) e.getSource(); |
776 |
|
777 |
//if ((theLegend != null) &&
|
778 |
if ((auxLegend != null) && |
779 |
// (cb.getSelectedIndex() != theLegend.getIntervalType())) {
|
780 |
(cb.getSelectedIndex() != auxLegend.getIntervalType())) { |
781 |
//theLegend.setIntervalType(cb.getSelectedIndex());
|
782 |
auxLegend.setIntervalType(cb.getSelectedIndex()); |
783 |
symbolTable.removeAllItems(); |
784 |
} |
785 |
} |
786 |
|
787 |
//A�adir todos los elementos por valor
|
788 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
789 |
fillTableValues(); |
790 |
} |
791 |
|
792 |
//A�adir un �nico elemento
|
793 |
if (e.getActionCommand() == "ADD_VALUE") { |
794 |
try {
|
795 |
symbolTable.addTableRecord( |
796 |
SymbologyFactory.createDefaultSymbolByShapeType(layer.getShapeType()), |
797 |
new FInterval(0, 0), |
798 |
"0 - 0");
|
799 |
} catch (ReadDriverException e1) {
|
800 |
NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e1); |
801 |
} |
802 |
|
803 |
} |
804 |
|
805 |
//Vacia la tabla
|
806 |
if (e.getActionCommand() == "REMOVE_ALL") { |
807 |
symbolTable.removeAllItems(); |
808 |
|
809 |
} |
810 |
|
811 |
//Quitar solo el elemento seleccionado
|
812 |
if (e.getActionCommand() == "REMOVE") { |
813 |
symbolTable.removeSelectedRows(); |
814 |
} |
815 |
} |
816 |
} |
817 |
|
818 |
public String getDescription() { |
819 |
return PluginServices.getText(this,"Muestra_los_elementos_de_la_capa_usando_una_gama_de_colores_en_funcion_del_valor_de_un_determinado_campo_de_atributos") + "."; |
820 |
} |
821 |
|
822 |
public ImageIcon getIcon() { |
823 |
return new ImageIcon(this.getClass().getClassLoader(). |
824 |
getResource("images/Intervalos.png"));
|
825 |
} |
826 |
|
827 |
public Class getParentClass() { |
828 |
return Quantities.class;
|
829 |
} |
830 |
|
831 |
public String getTitle() { |
832 |
return PluginServices.getText(this,"Intervalos"); |
833 |
} |
834 |
|
835 |
public JPanel getPanel() { |
836 |
return this; |
837 |
} |
838 |
|
839 |
public Class getLegendClass() { |
840 |
return VectorialIntervalLegend.class;
|
841 |
} |
842 |
|
843 |
private boolean isNumericField(int fieldType) { |
844 |
switch (fieldType) {
|
845 |
case Types.BIGINT: |
846 |
case Types.DECIMAL: |
847 |
case Types.DOUBLE: |
848 |
case Types.FLOAT: |
849 |
case Types.INTEGER: |
850 |
case Types.NUMERIC: |
851 |
case Types.REAL: |
852 |
case Types.SMALLINT: |
853 |
case Types.TINYINT: |
854 |
return true; |
855 |
default:
|
856 |
return false; |
857 |
} |
858 |
|
859 |
} |
860 |
public boolean isSuitableFor(FLayer layer) { |
861 |
if (layer instanceof FLyrVect) { |
862 |
SelectableDataSource sds; |
863 |
try {
|
864 |
sds = ((FLyrVect) layer).getRecordset(); |
865 |
String[] fNames = sds.getFieldNames(); |
866 |
for (int i = 0; i < fNames.length; i++) { |
867 |
if (isNumericField(sds.getFieldType(i))) {
|
868 |
return true; |
869 |
} |
870 |
} |
871 |
} catch (ReadDriverException e) {
|
872 |
return false; |
873 |
} |
874 |
} |
875 |
return false; |
876 |
} |
877 |
} |