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