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