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