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