svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / VectorialInterval.java @ 25074
History | View | Annotate | Download (27.8 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.feature.FeatureAttributeDescriptor; |
67 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
68 |
import org.gvsig.fmap.dal.feature.FeatureType; |
69 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
70 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
71 |
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
72 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
73 |
import org.gvsig.fmap.mapcontext.rendering.legend.FInterval; |
74 |
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval; |
75 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
76 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory; |
77 |
import org.gvsig.fmap.mapcontext.rendering.legend.NullIntervalValue; |
78 |
import org.gvsig.fmap.mapcontext.rendering.legend.VectorialIntervalLegend; |
79 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
80 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
81 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
82 |
import org.gvsig.gui.beans.swing.JButton; |
83 |
|
84 |
import com.iver.andami.PluginServices; |
85 |
import com.iver.andami.messages.NotificationManager; |
86 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
87 |
import com.iver.utiles.XMLException; |
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 |
int symbolType = layer.getShapeType();
|
438 |
int numSymbols = 0; |
439 |
|
440 |
for (int k = 0; k < arrayIntervalos.length; k++) { |
441 |
interval = arrayIntervalos[k]; |
442 |
|
443 |
ISymbol theSymbol = SymbologyFactory.createDefaultSymbolByShapeType( |
444 |
symbolType, |
445 |
new Color(r, g, b)); |
446 |
theSymbol.setDescription(NumberFormat.getInstance().format(interval.getMin()) +
|
447 |
" - " +
|
448 |
NumberFormat.getInstance().format(interval.getMax()));
|
449 |
|
450 |
//////////////////////////////////////
|
451 |
// CALCULAMOS UN COLOR APROPIADO
|
452 |
r = r + stepR; |
453 |
g = g + stepG; |
454 |
b = b + stepB; |
455 |
|
456 |
/////////////////////////////////
|
457 |
auxLegend.addSymbol(interval, theSymbol); |
458 |
System.out.println("addSymbol = " + interval + |
459 |
" theSymbol = " + theSymbol.getDescription());
|
460 |
numSymbols++; |
461 |
|
462 |
if (numSymbols > 100) { |
463 |
int resp = JOptionPane.showConfirmDialog(this, |
464 |
PluginServices.getText(this, "mas_de_100_simbolos"), |
465 |
PluginServices.getText(this, "quiere_continuar"), |
466 |
JOptionPane.YES_NO_OPTION,
|
467 |
JOptionPane.WARNING_MESSAGE);
|
468 |
|
469 |
if ((resp == JOptionPane.NO_OPTION) || |
470 |
(resp == JOptionPane.DEFAULT_OPTION)) {
|
471 |
return;
|
472 |
} |
473 |
} |
474 |
|
475 |
// }
|
476 |
} // for
|
477 |
|
478 |
System.out.println("Num. Simbolos = " + |
479 |
auxLegend.getValues().length); |
480 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
481 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
482 |
|
483 |
} catch (DataException e) {
|
484 |
NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e); |
485 |
} catch (LegendLayerException e) {
|
486 |
NotificationManager.addError(PluginServices.getText(this, "failed_computing_intervals"), e); |
487 |
} |
488 |
|
489 |
bDelAll.setEnabled(true);
|
490 |
bDel.setEnabled(true);
|
491 |
} |
492 |
|
493 |
protected FInterval[] calculateIntervals() throws LegendLayerException { |
494 |
int intervalCount = 1; |
495 |
// ensure the interval value is an integer greather than 0
|
496 |
try {
|
497 |
intervalCount = (int) Double. |
498 |
parseDouble(txtNumIntervals.getText()); |
499 |
if (intervalCount<1) { |
500 |
throw new Exception(); |
501 |
} |
502 |
} catch (Exception e) { |
503 |
JOptionPane.showMessageDialog(this, |
504 |
PluginServices.getText(this, "invalid_interval_count_value")); |
505 |
return null; |
506 |
} |
507 |
|
508 |
try {
|
509 |
|
510 |
return auxLegend.calculateIntervals(
|
511 |
//return theLegend.calculateIntervals(
|
512 |
((FLyrVect) layer).getFeatureStore(), |
513 |
(String) cmbField.getSelectedItem(),
|
514 |
intervalCount, |
515 |
layer.getShapeType() |
516 |
); |
517 |
} catch (DataException e) {
|
518 |
return null; |
519 |
} |
520 |
} |
521 |
|
522 |
public void setData(FLayer layer, ILegend legend) { |
523 |
this.layer = (ClassifiableVectorial) layer;
|
524 |
int shapeType = 0; |
525 |
try {
|
526 |
shapeType = this.layer.getShapeType();
|
527 |
} catch (DataException e) {
|
528 |
NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e); |
529 |
} |
530 |
|
531 |
if (symbolTable != null) { |
532 |
pnlCenter.remove(symbolTable); |
533 |
} |
534 |
|
535 |
getDefaultSymbolPrev(shapeType); |
536 |
|
537 |
symbolTable = new SymbolTable(this, SymbolTable.INTERVALS_TYPE, shapeType); |
538 |
pnlCenter.add(symbolTable); |
539 |
fillFieldNames(); |
540 |
|
541 |
/* if (legend instanceof VectorialIntervalLegend) {
|
542 |
theLegend = (VectorialIntervalLegend) legend;
|
543 |
getChkDefaultvalues().setSelected(theLegend.isUseDefaultSymbol());
|
544 |
cmbField.getModel().setSelectedItem(theLegend.getClassifyingFieldNames()[0]);
|
545 |
symbolTable.fillTableFromSymbolList(theLegend.getSymbols(),
|
546 |
theLegend.getValues(), theLegend.getDescriptions());
|
547 |
colorChooserPanel.setColor(theLegend.getStartColor());
|
548 |
colorChooserPanel1.setColor(theLegend.getEndColor());
|
549 |
colorChooserPanel.repaint();
|
550 |
colorChooserPanel1.repaint();
|
551 |
} else {
|
552 |
// Si la capa viene con otro tipo de leyenda, creamos
|
553 |
// una nueva del tipo que maneja este panel
|
554 |
theLegend = new VectorialIntervalLegend();
|
555 |
theLegend.setShapeType(shapeType);
|
556 |
}
|
557 |
|
558 |
|
559 |
cmbFieldType.setSelectedIndex(theLegend.getIntervalType());
|
560 |
*/
|
561 |
if (VectorialIntervalLegend.class.equals(legend.getClass())) {
|
562 |
try {
|
563 |
auxLegend = (VectorialIntervalLegend) legend.cloneLegend(); |
564 |
} catch (XMLException e) {
|
565 |
NotificationManager.addError(e); |
566 |
} |
567 |
chkdefaultvalues.setSelected(auxLegend.isUseDefaultSymbol()); |
568 |
cmbField.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
|
569 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
570 |
auxLegend.getValues(), auxLegend.getDescriptions()); |
571 |
colorChooserPanel.setColor(auxLegend.getStartColor()); |
572 |
colorChooserPanel1.setColor(auxLegend.getEndColor()); |
573 |
colorChooserPanel.repaint(); |
574 |
colorChooserPanel1.repaint(); |
575 |
if(auxLegend.isUseDefaultSymbol()) {
|
576 |
txtNumIntervals.setText(String.valueOf(auxLegend.getSymbols().length - 1)); |
577 |
} else {
|
578 |
txtNumIntervals.setText(String.valueOf(auxLegend.getSymbols().length));
|
579 |
} |
580 |
} else {
|
581 |
// Si la capa viene con otro tipo de leyenda, creamos
|
582 |
// una nueva del tipo que maneja este panel
|
583 |
auxLegend = new VectorialIntervalLegend();
|
584 |
auxLegend.setShapeType(shapeType); |
585 |
auxLegend.useDefaultSymbol(false);
|
586 |
} |
587 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
588 |
cmbFieldType.setSelectedIndex(auxLegend.getIntervalType()); |
589 |
} |
590 |
|
591 |
|
592 |
public void getDefaultSymbolPrev(int shapeType) { |
593 |
if(defaultSymbolPrev == null){ |
594 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
|
595 |
defaultSymbolPrev.setPreferredSize(new Dimension(110,20)); |
596 |
defaultSymbolPanel.add(defaultSymbolPrev,null);
|
597 |
} |
598 |
} |
599 |
|
600 |
protected void fillFieldNames() { |
601 |
FeatureStore rs = null;
|
602 |
ArrayList<String> nomFields = null; |
603 |
|
604 |
try {
|
605 |
rs = ((FLyrVect) layer).getFeatureStore(); |
606 |
// logger.debug("rs.start()");
|
607 |
// rs.start();
|
608 |
|
609 |
nomFields = new ArrayList<String>(); |
610 |
|
611 |
int type;
|
612 |
Iterator<FeatureAttributeDescriptor> iterator=rs.getDefaultFeatureType().iterator();
|
613 |
while (iterator.hasNext()) {
|
614 |
FeatureAttributeDescriptor descriptor = iterator.next(); |
615 |
|
616 |
// }
|
617 |
// for (int i = 0; i < rs.getFieldCount(); i++) {
|
618 |
type = descriptor.getDataType();//rs.getFieldType(i);
|
619 |
|
620 |
// if (type.equals(FeatureAttributeDescriptor.) == Types.NULL) {
|
621 |
// continue;
|
622 |
// }
|
623 |
|
624 |
if (type == DataTypes.INT ||
|
625 |
type == DataTypes.DOUBLE || |
626 |
type == DataTypes.FLOAT || |
627 |
type == DataTypes.LONG) |
628 |
{ |
629 |
nomFields.add(descriptor.getName()); |
630 |
} |
631 |
} |
632 |
|
633 |
// rs.stop();
|
634 |
} catch (DataException e) {
|
635 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
636 |
} |
637 |
|
638 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray()); |
639 |
cmbField.setModel(cM); |
640 |
|
641 |
symbolTable.removeAllItems(); |
642 |
} |
643 |
|
644 |
/**
|
645 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
646 |
*/
|
647 |
public ILegend getLegend() {
|
648 |
fillSymbolListFromTable(); |
649 |
if(defaultSymbolPrev.getSymbol() != null) { |
650 |
auxLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol()); |
651 |
} |
652 |
|
653 |
auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected()); |
654 |
|
655 |
try {
|
656 |
theLegend = (VectorialIntervalLegend) auxLegend.cloneLegend(); |
657 |
} catch (XMLException e) {
|
658 |
// TODO Auto-generated catch block
|
659 |
e.printStackTrace(); |
660 |
} |
661 |
return theLegend;
|
662 |
} |
663 |
|
664 |
/**
|
665 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo
|
666 |
* el symbolList, si no tambi�n el arrayKeys y el defaultRenderer
|
667 |
*/
|
668 |
|
669 |
private void fillSymbolListFromTable() { |
670 |
ISymbol theSymbol; |
671 |
IInterval theInterval = null;
|
672 |
|
673 |
// Borramos las anteriores listas:
|
674 |
auxLegend.clear(); |
675 |
|
676 |
String fieldName = (String) cmbField.getSelectedItem(); |
677 |
auxLegend.setClassifyingFieldNames(new String[] {fieldName}); |
678 |
|
679 |
auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected()); |
680 |
|
681 |
FeatureStore rs; |
682 |
try {
|
683 |
|
684 |
rs = ((FLyrVect) layer).getFeatureStore(); |
685 |
// rs.start();
|
686 |
FeatureType featureType=rs.getDefaultFeatureType(); |
687 |
auxLegend |
688 |
.setClassifyingFieldTypes(new int[] { new Integer( |
689 |
featureType.getAttributeDescriptor(fieldName) |
690 |
.getDataType()) }); |
691 |
logger.debug("rs.start()");
|
692 |
// rs.stop();
|
693 |
|
694 |
} catch (DataException e) {
|
695 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
696 |
} |
697 |
|
698 |
|
699 |
|
700 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
701 |
if (!(symbolTable.getFieldValue(row, 1) instanceof FInterval)) { |
702 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
703 |
theSymbol.setDescription((String) symbolTable.getFieldValue(
|
704 |
row, 2));
|
705 |
auxLegend.addSymbol(new NullIntervalValue(), theSymbol);
|
706 |
} else {
|
707 |
theInterval = (IInterval) symbolTable.getFieldValue(row, 1);
|
708 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
709 |
theSymbol.setDescription((String) symbolTable.getFieldValue(
|
710 |
row, 2));
|
711 |
auxLegend.addSymbol(theInterval, theSymbol); |
712 |
} |
713 |
} |
714 |
if(chkdefaultvalues.isSelected()){
|
715 |
if(defaultSymbolPrev.getSymbol() != null){ |
716 |
String description = PluginServices.getText(this,"default"); |
717 |
defaultSymbolPrev.getSymbol().setDescription(description); |
718 |
auxLegend.addSymbol(new NullIntervalValue(), defaultSymbolPrev.getSymbol());
|
719 |
} |
720 |
} |
721 |
} |
722 |
|
723 |
/**
|
724 |
* This method initializes panelC
|
725 |
*
|
726 |
* @return javax.swing.JPanel
|
727 |
*/
|
728 |
private JPanel getPnlCenter() { |
729 |
if (pnlCenter == null) { |
730 |
pnlCenter = new JPanel(); |
731 |
} |
732 |
|
733 |
return pnlCenter;
|
734 |
} |
735 |
|
736 |
/**
|
737 |
* Listener.
|
738 |
*
|
739 |
* @author Vicente Caballero Navarro
|
740 |
*/
|
741 |
class MyListener implements ActionListener { |
742 |
|
743 |
public void actionPerformed(ActionEvent e) { |
744 |
System.out.println("ActionEvent con " + e.getActionCommand()); |
745 |
|
746 |
//modificar el combobox de valor
|
747 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
748 |
JComboBox cb = (JComboBox) e.getSource(); |
749 |
String fieldName = (String) cb.getSelectedItem(); |
750 |
System.out.println("Nombre del campo: " + fieldName); |
751 |
symbolTable.removeAllItems(); |
752 |
|
753 |
//theLegend.setClassifyingFieldNames(new String[] {fieldName});
|
754 |
auxLegend.setClassifyingFieldNames(new String[] {fieldName}); |
755 |
} else if (e.getActionCommand() == "INTERVAL_TYPE") { |
756 |
JComboBox cb = (JComboBox) e.getSource(); |
757 |
|
758 |
//if ((theLegend != null) &&
|
759 |
if ((auxLegend != null) && |
760 |
// (cb.getSelectedIndex() != theLegend.getIntervalType())) {
|
761 |
(cb.getSelectedIndex() != auxLegend.getIntervalType())) { |
762 |
//theLegend.setIntervalType(cb.getSelectedIndex());
|
763 |
auxLegend.setIntervalType(cb.getSelectedIndex()); |
764 |
symbolTable.removeAllItems(); |
765 |
} |
766 |
} |
767 |
|
768 |
//A�adir todos los elementos por valor
|
769 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
770 |
fillTableValues(); |
771 |
} |
772 |
|
773 |
//A�adir un �nico elemento
|
774 |
if (e.getActionCommand() == "ADD_VALUE") { |
775 |
try {
|
776 |
symbolTable.addTableRecord( |
777 |
SymbologyFactory.createDefaultSymbolByShapeType(layer.getShapeType()), |
778 |
new FInterval(0, 0), |
779 |
"0 - 0");
|
780 |
} catch (DataException e1) {
|
781 |
NotificationManager.addError(PluginServices.getText(this, "could_not_get_shape_type"), e1); |
782 |
} |
783 |
|
784 |
} |
785 |
|
786 |
//Vacia la tabla
|
787 |
if (e.getActionCommand() == "REMOVE_ALL") { |
788 |
symbolTable.removeAllItems(); |
789 |
|
790 |
} |
791 |
|
792 |
//Quitar solo el elemento seleccionado
|
793 |
if (e.getActionCommand() == "REMOVE") { |
794 |
symbolTable.removeSelectedRows(); |
795 |
} |
796 |
} |
797 |
} |
798 |
|
799 |
public String getDescription() { |
800 |
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") + "."; |
801 |
} |
802 |
|
803 |
public ImageIcon getIcon() { |
804 |
return new ImageIcon(this.getClass().getClassLoader(). |
805 |
getResource("images/Intervalos.png"));
|
806 |
} |
807 |
|
808 |
public Class getParentClass() { |
809 |
return Quantities.class;
|
810 |
} |
811 |
|
812 |
public String getTitle() { |
813 |
return PluginServices.getText(this,"Intervalos"); |
814 |
} |
815 |
|
816 |
public JPanel getPanel() { |
817 |
return this; |
818 |
} |
819 |
|
820 |
public Class getLegendClass() { |
821 |
return VectorialIntervalLegend.class;
|
822 |
} |
823 |
|
824 |
private boolean isNumericField(int fieldType) { |
825 |
if (fieldType == DataTypes.DOUBLE || fieldType == DataTypes.FLOAT
|
826 |
|| fieldType == DataTypes.LONG || fieldType == DataTypes.INT) { |
827 |
return true; |
828 |
}else{
|
829 |
return false; |
830 |
} |
831 |
// switch (fieldType) {
|
832 |
// case Types.BIGINT:
|
833 |
// case Types.DECIMAL:
|
834 |
// case Types.DOUBLE:
|
835 |
// case Types.FLOAT:
|
836 |
// case Types.INTEGER:
|
837 |
// case Types.NUMERIC:
|
838 |
// case Types.REAL:
|
839 |
// case Types.SMALLINT:
|
840 |
// case Types.TINYINT:
|
841 |
// return true;
|
842 |
// default:
|
843 |
// return false;
|
844 |
// }
|
845 |
|
846 |
} |
847 |
public boolean isSuitableFor(FLayer layer) { |
848 |
if (layer instanceof FLyrVect) { |
849 |
FeatureStore sds; |
850 |
try {
|
851 |
sds = ((FLyrVect) layer).getFeatureStore(); |
852 |
FeatureType featureType=sds.getDefaultFeatureType(); |
853 |
Iterator iterator=featureType.iterator();
|
854 |
while (iterator.hasNext()) {
|
855 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next(); |
856 |
|
857 |
// }
|
858 |
// String[] fNames = sds.getFieldNames();
|
859 |
// for (int i = 0; i < fNames.length; i++) {
|
860 |
if (isNumericField(descriptor.getDataType())) {
|
861 |
return true; |
862 |
} |
863 |
} |
864 |
} catch (DataException e) {
|
865 |
return false; |
866 |
} |
867 |
} |
868 |
return false; |
869 |
} |
870 |
} |