root / org.gvsig.legend.proportionalsymbols.app.mainplugin / trunk / org.gvsig.legend.proportionalsymbols.app.mainplugin / src / main / java / org / gvsig / symbology / gui / layerproperties / ProportionalSymbolsPanel.java @ 3573
History | View | Annotate | Download (24.6 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 org.gvsig.symbology.gui.layerproperties; |
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.event.ActionEvent; |
48 |
import java.awt.event.ActionListener; |
49 |
|
50 |
import javax.swing.BorderFactory; |
51 |
import javax.swing.DefaultComboBoxModel; |
52 |
import javax.swing.ImageIcon; |
53 |
import javax.swing.JComboBox; |
54 |
import javax.swing.JLabel; |
55 |
import javax.swing.JOptionPane; |
56 |
import javax.swing.JPanel; |
57 |
|
58 |
import org.slf4j.Logger; |
59 |
import org.slf4j.LoggerFactory; |
60 |
|
61 |
import org.gvsig.andami.IconThemeHelper; |
62 |
import org.gvsig.app.ApplicationLocator; |
63 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
64 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
65 |
import org.gvsig.app.project.documents.view.legend.gui.Quantities; |
66 |
import org.gvsig.fmap.dal.exception.DataException; |
67 |
import org.gvsig.fmap.dal.exception.ReadException; |
68 |
import org.gvsig.fmap.dal.feature.Feature; |
69 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
70 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
71 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
72 |
import org.gvsig.fmap.dal.feature.FeatureType; |
73 |
import org.gvsig.fmap.geom.Geometry; |
74 |
import org.gvsig.fmap.geom.GeometryLocator; |
75 |
import org.gvsig.fmap.geom.GeometryManager; |
76 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
77 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
78 |
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
79 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
80 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
81 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
82 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
83 |
import org.gvsig.gui.beans.swing.JBlank; |
84 |
import org.gvsig.gui.beans.swing.JNumberSpinner; |
85 |
import org.gvsig.i18n.Messages; |
86 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MarkerFillSymbol; |
87 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
88 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol; |
89 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
90 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
91 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle; |
92 |
import org.gvsig.symbology.fmap.rendering.ProportionalSymbolsLegend; |
93 |
import org.gvsig.tools.dispose.DisposableIterator; |
94 |
|
95 |
/**
|
96 |
* Implements the panel for the legend of proportional symbols.In the interface
|
97 |
* will be options to select the value field, the normalization field (if the
|
98 |
* user wants to use it) and options to select the symbol an its minimum and
|
99 |
* maximum size.
|
100 |
*
|
101 |
* Also there will be possible to select a background symbol (only when the
|
102 |
* shapetype of the layer is polygonal).
|
103 |
*
|
104 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
105 |
* @author jldominguez
|
106 |
*/
|
107 |
public class ProportionalSymbolsPanel extends JPanel implements ILegendPanel { |
108 |
|
109 |
private static Logger logger = LoggerFactory.getLogger(ProportionalSymbolsPanel.class); |
110 |
|
111 |
private static final long serialVersionUID = 7394720230276170902L; |
112 |
private JPanel symbolPanel; |
113 |
private JPanel backgroundPanel; |
114 |
private JSymbolPreviewButton tmplateSymbol;
|
115 |
private JSymbolPreviewButton backSymbol;
|
116 |
private JComboBox cmbValue; |
117 |
private JComboBox cmbNormalization; |
118 |
private JNumberSpinner txtMinSize;
|
119 |
private JNumberSpinner txtMaxSize;
|
120 |
private ClassifiableVectorial myLayer;
|
121 |
private ProportionalSymbolsLegend auxLegend;
|
122 |
private String[] fieldNames; |
123 |
private int templateShapeType = 0; |
124 |
|
125 |
private String noNormalization = Messages.getText("none"); |
126 |
|
127 |
private boolean useNormalization = true; |
128 |
|
129 |
/**
|
130 |
* Default constructor
|
131 |
*/
|
132 |
public ProportionalSymbolsPanel() {
|
133 |
initialize(); |
134 |
} |
135 |
|
136 |
/**
|
137 |
* This method initializes this
|
138 |
*/
|
139 |
private void initialize() { |
140 |
|
141 |
setLayout(new BorderLayout()); |
142 |
JPanel aux = new JPanel(new BorderLayout()); |
143 |
|
144 |
JPanel fieldsPanel = new JPanel(new FlowLayout()); |
145 |
fieldsPanel.setBorder(BorderFactory.
|
146 |
createTitledBorder(null,
|
147 |
Messages.getText("fields")
|
148 |
)); |
149 |
fieldsPanel.setPreferredSize(new Dimension(300, 60)); |
150 |
|
151 |
cmbValue = new JComboBox(); |
152 |
cmbValue.setActionCommand("VALUE_SELECTED");
|
153 |
|
154 |
cmbNormalization = new JComboBox(); |
155 |
cmbNormalization.setActionCommand("NORMALIZATION_SELECTED");
|
156 |
|
157 |
fieldsPanel.add(new JLabel( |
158 |
Messages.getText("value")
|
159 |
+ ":"));
|
160 |
fieldsPanel.add(cmbValue); |
161 |
|
162 |
fieldsPanel.add(new JLabel( |
163 |
Messages.getText("normalization")
|
164 |
+ ":"));
|
165 |
fieldsPanel.add(cmbNormalization); |
166 |
|
167 |
symbolPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 3, 2)); |
168 |
symbolPanel.setBorder(BorderFactory.
|
169 |
createTitledBorder(null,
|
170 |
Messages.getText("symbol")
|
171 |
)); |
172 |
|
173 |
GridBagLayoutPanel aux2 = new GridBagLayoutPanel();
|
174 |
aux2.addComponent(new JLabel( |
175 |
Messages.getText("size")
|
176 |
)); |
177 |
aux2.addComponent(new JBlank(10, 10)); |
178 |
aux2.addComponent( |
179 |
Messages.getText("from")
|
180 |
+ ":",
|
181 |
getTxtMinSize()); |
182 |
aux2.addComponent( |
183 |
Messages.getText("to")
|
184 |
+ ":",
|
185 |
getTxtMaxSize()); |
186 |
|
187 |
JPanel templatePanel = new JPanel(); |
188 |
templatePanel.setBorder(BorderFactory.createTitledBorder(null, |
189 |
Messages.getText("template")
|
190 |
)); |
191 |
templatePanel.add(getTemplSymbol()); |
192 |
symbolPanel.add(new JBlank(10, 10)); |
193 |
symbolPanel.add(aux2); |
194 |
symbolPanel.add(new JBlank(10, 10)); |
195 |
symbolPanel.add(templatePanel); |
196 |
|
197 |
aux.add(fieldsPanel, BorderLayout.NORTH);
|
198 |
aux.add(symbolPanel, BorderLayout.CENTER);
|
199 |
|
200 |
this.add(aux, BorderLayout.CENTER); |
201 |
|
202 |
cmbValue.addActionListener(action); |
203 |
cmbNormalization.addActionListener(action); |
204 |
tmplateSymbol.addActionListener(action); |
205 |
} |
206 |
|
207 |
/**
|
208 |
* Creates the panel where the button for the background symbol will be
|
209 |
* placed
|
210 |
*
|
211 |
* @return JPanel panel
|
212 |
*/
|
213 |
private JPanel getBackgroundPanel() { |
214 |
backgroundPanel = new JPanel(); |
215 |
backgroundPanel.setBorder(BorderFactory.createTitledBorder(null, |
216 |
Messages.getText("background")
|
217 |
)); |
218 |
backgroundPanel.add(getBtnBackground()); |
219 |
return backgroundPanel;
|
220 |
} |
221 |
|
222 |
/**
|
223 |
* Creates a JNumberSpinner which is used to select the maximum size for the
|
224 |
* symbol
|
225 |
*
|
226 |
* @return JNumberSpinner
|
227 |
*/
|
228 |
private JNumberSpinner getTxtMaxSize() {
|
229 |
if (txtMaxSize == null) { |
230 |
txtMaxSize = new JNumberSpinner(25.0, 7, 0.0, 100.0, 1.0, 2); |
231 |
txtMaxSize.addActionListener(action); |
232 |
} |
233 |
return txtMaxSize;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* Creates a JNumberSpinner which is used to select the minimum size for the
|
238 |
* symbol
|
239 |
*
|
240 |
* @return JNumberSpinner
|
241 |
*/
|
242 |
private JNumberSpinner getTxtMinSize() {
|
243 |
if (txtMinSize == null) { |
244 |
txtMinSize = new JNumberSpinner(3.0, 7, 0.0, 100.0, 1.0, 2); |
245 |
txtMinSize.addActionListener(action); |
246 |
} |
247 |
return txtMinSize;
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* Creates a JSymbolPreviewButton which is used to select the template
|
252 |
* symbol
|
253 |
*
|
254 |
* @return JSymbolPreviewButton
|
255 |
*/
|
256 |
private JSymbolPreviewButton getTemplSymbol() {
|
257 |
|
258 |
if (tmplateSymbol == null) { |
259 |
int tst = ProportionalSymbolsLegend.isPolygonal(this.templateShapeType) |
260 |
? Geometry.TYPES.POINT |
261 |
: this.templateShapeType;
|
262 |
|
263 |
tmplateSymbol = new JSymbolPreviewButton(tst);
|
264 |
} |
265 |
tmplateSymbol.setPreferredSize(new Dimension(100, 45)); |
266 |
return tmplateSymbol;
|
267 |
} |
268 |
|
269 |
/**
|
270 |
* Creates a JSymbolPreviewButton which is used to select the background
|
271 |
* symbol
|
272 |
*
|
273 |
* @return JSymbolPreviewButton
|
274 |
*/
|
275 |
private JSymbolPreviewButton getBtnBackground() {
|
276 |
if (backSymbol == null) { |
277 |
backSymbol = new JSymbolPreviewButton(Geometry.TYPES.SURFACE);
|
278 |
backSymbol.setPreferredSize(new Dimension(100, 45)); |
279 |
|
280 |
ISymbol fillsym = MapContextLocator.getSymbolManager().createSymbol( |
281 |
Geometry.TYPES.SURFACE, Color.ORANGE);
|
282 |
backSymbol.setSymbol(fillsym); |
283 |
} |
284 |
return backSymbol;
|
285 |
} |
286 |
|
287 |
/**
|
288 |
* Creates a new symbol of an specific shapetype with a concrete size
|
289 |
*
|
290 |
* @param shapeType
|
291 |
* @param size
|
292 |
*
|
293 |
* @return ISymbol symbol created
|
294 |
*/
|
295 |
private ISymbol newSymbol(int shapeType, double size) { |
296 |
if (getTemplSymbol().getSymbol() == null) { |
297 |
ISymbol templateSymbol; |
298 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
299 |
if (geomManager.isSubtype(Geometry.TYPES.POINT, shapeType)
|
300 |
|| geomManager.isSubtype(Geometry.TYPES.MULTIPOINT, shapeType) |
301 |
|| geomManager.isSubtype(Geometry.TYPES.SURFACE, shapeType) |
302 |
|| geomManager.isSubtype(Geometry.TYPES.MULTISURFACE, shapeType)) { |
303 |
templateSymbol = new SimpleMarkerSymbol();
|
304 |
((SimpleMarkerSymbol) templateSymbol).setSize(size); |
305 |
((SimpleMarkerSymbol) templateSymbol).setColor(Color.DARK_GRAY);
|
306 |
|
307 |
} else if (geomManager.isSubtype(Geometry.TYPES.CURVE, shapeType) |
308 |
|| geomManager.isSubtype(Geometry.TYPES.MULTICURVE, shapeType)) { |
309 |
templateSymbol = new SimpleLineSymbol();
|
310 |
((SimpleLineSymbol) templateSymbol).setLineWidth(size); |
311 |
((SimpleLineSymbol) templateSymbol).setLineColor(Color.DARK_GRAY);
|
312 |
|
313 |
} else {
|
314 |
throw new RuntimeException("Unknown symbol type"); |
315 |
|
316 |
} |
317 |
|
318 |
getTemplSymbol().setSymbol(templateSymbol); |
319 |
return newSymbol(shapeType, size);
|
320 |
} else {
|
321 |
// clone symbol
|
322 |
ISymbol mySymbol = getTemplSymbol().getSymbol(); |
323 |
|
324 |
try {
|
325 |
mySymbol = (ISymbol) mySymbol.clone(); |
326 |
} catch (CloneNotSupportedException e) { |
327 |
logger.info("Error while cloning symbol", e);
|
328 |
ApplicationLocator.getManager().messageDialog( |
329 |
Messages.getText("_Unable_to_clone_symbol"),
|
330 |
Messages.getText("error"),
|
331 |
JOptionPane.ERROR_MESSAGE);
|
332 |
} |
333 |
|
334 |
if (mySymbol instanceof ILineSymbol) { |
335 |
ILineSymbol lSym = (ILineSymbol) mySymbol; |
336 |
lSym.setLineWidth(size); |
337 |
|
338 |
} |
339 |
if (mySymbol instanceof IMarkerSymbol) { |
340 |
IMarkerSymbol mSym = (IMarkerSymbol) mySymbol; |
341 |
mSym.setSize(size); |
342 |
|
343 |
if (ProportionalSymbolsLegend.isPolygonal(shapeType)) {
|
344 |
// this is to allow using in Polygon layers
|
345 |
MarkerFillSymbol fillSymbol = new MarkerFillSymbol();
|
346 |
fillSymbol.setOutline(null);
|
347 |
fillSymbol.setFillColor(null);
|
348 |
fillSymbol.getMarkerFillProperties(). |
349 |
setFillStyle(IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL); |
350 |
fillSymbol.setMarker(mSym); |
351 |
} |
352 |
} |
353 |
return mySymbol;
|
354 |
} |
355 |
} |
356 |
|
357 |
/**
|
358 |
* Fills the comboboxes that are placed in the panel with the classifying
|
359 |
* field names of the layer which contain numerical information
|
360 |
*
|
361 |
*/
|
362 |
private void fillFieldNames() { |
363 |
|
364 |
// SelectableDataSource rs;
|
365 |
try {
|
366 |
FeatureStore fsto = (FeatureStore) ((FLyrVect) myLayer).getDataStore(); |
367 |
FeatureType fty = fsto.getDefaultFeatureType(); |
368 |
|
369 |
FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
|
370 |
int cont = 0; |
371 |
for (int i = 0; i < atts.length; i++) { |
372 |
if (atts[i].getDataType().isNumeric()) {
|
373 |
cont++; |
374 |
} |
375 |
} |
376 |
String[] nomFields = new String[cont]; |
377 |
|
378 |
cont = 0;
|
379 |
for (int i = 0; i < atts.length; i++) { |
380 |
if (atts[i].getDataType().isNumeric()) {
|
381 |
nomFields[cont] = atts[i].getName(); |
382 |
cont++; |
383 |
} |
384 |
} |
385 |
this.fieldNames = nomFields;
|
386 |
|
387 |
DefaultComboBoxModel cMValue = new DefaultComboBoxModel(this.fieldNames); |
388 |
DefaultComboBoxModel cMNormalization = new DefaultComboBoxModel(this.fieldNames); |
389 |
cmbValue.setModel(cMValue); |
390 |
cmbNormalization.setModel(cMNormalization); |
391 |
cmbNormalization.addItem(noNormalization); |
392 |
|
393 |
} catch (DataException e) {
|
394 |
|
395 |
logger.info("Error while getting fields", e);
|
396 |
ApplicationLocator.getManager().messageDialog( |
397 |
Messages.getText("_Error_while_getting_fields"),
|
398 |
Messages.getText("error"),
|
399 |
JOptionPane.ERROR_MESSAGE);
|
400 |
|
401 |
// NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
|
402 |
} |
403 |
} |
404 |
|
405 |
public void setData(FLayer lyr, ILegend legend) { |
406 |
|
407 |
this.myLayer = (ClassifiableVectorial) lyr;
|
408 |
|
409 |
fillFieldNames(); |
410 |
|
411 |
int myt = Geometry.TYPES.GEOMETRY;
|
412 |
|
413 |
try {
|
414 |
myt = this.myLayer.getGeometryType().getType();
|
415 |
} catch (ReadException re) {
|
416 |
logger.info("Error while getting geometry type", re);
|
417 |
ApplicationLocator.getManager().message( |
418 |
"Error getting geometry type",
|
419 |
JOptionPane.ERROR_MESSAGE);
|
420 |
} |
421 |
|
422 |
templateShapeType |
423 |
= ProportionalSymbolsLegend.isPolygonal(myt) |
424 |
? Geometry.TYPES.POINT : myt; |
425 |
|
426 |
getTemplSymbol().setShapeType(templateShapeType); |
427 |
|
428 |
if (ProportionalSymbolsLegend.isPolygonal(myt) && backgroundPanel == null) { |
429 |
symbolPanel.add(getBackgroundPanel()); |
430 |
} |
431 |
|
432 |
if (ProportionalSymbolsLegend.class.equals(legend.getClass())) {
|
433 |
|
434 |
auxLegend = (ProportionalSymbolsLegend) legend.cloneLegend(); |
435 |
cmbValue.setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
|
436 |
ISymbol defSymbol = auxLegend.getDefaultSymbol(); |
437 |
|
438 |
if (((ProportionalSymbolsLegend) auxLegend).getUseNormalization()) {
|
439 |
cmbNormalization.setSelectedItem(auxLegend.getClassifyingFieldNames()[1]);
|
440 |
} else {
|
441 |
cmbNormalization.setSelectedItem(noNormalization); |
442 |
} |
443 |
|
444 |
txtMaxSize.setDouble(auxLegend.getMaxSize()); |
445 |
txtMinSize.setDouble(auxLegend.getMinSize()); |
446 |
|
447 |
if (ProportionalSymbolsLegend.isLinear(templateShapeType)) {
|
448 |
((ILineSymbol) defSymbol).setLineWidth(2);
|
449 |
} else {
|
450 |
((IMarkerSymbol) defSymbol).setSize(15);
|
451 |
} |
452 |
|
453 |
getTemplSymbol().setSymbol(defSymbol); |
454 |
|
455 |
if (((ProportionalSymbolsLegend) auxLegend).getBackgroundSymbol() != null) { |
456 |
getBtnBackground().setSymbol(((ProportionalSymbolsLegend) auxLegend).getBackgroundSymbol()); |
457 |
} |
458 |
|
459 |
} else {
|
460 |
|
461 |
auxLegend = new ProportionalSymbolsLegend();
|
462 |
auxLegend.setTemplateShapeType(templateShapeType); |
463 |
|
464 |
if (ProportionalSymbolsLegend.isLinear(templateShapeType)) {
|
465 |
auxLegend.setDefaultSymbol(newSymbol(templateShapeType, 2));
|
466 |
} else {
|
467 |
auxLegend.setDefaultSymbol(newSymbol(templateShapeType, 15));
|
468 |
} |
469 |
|
470 |
getTemplSymbol().setSymbol(auxLegend.getDefaultSymbol()); |
471 |
if (ProportionalSymbolsLegend.isLinear(templateShapeType)) {
|
472 |
txtMinSize.setDouble(3);
|
473 |
txtMaxSize.setDouble(3);
|
474 |
} else {
|
475 |
txtMinSize.setDouble(10);
|
476 |
txtMaxSize.setDouble(10);
|
477 |
} |
478 |
} |
479 |
|
480 |
} |
481 |
|
482 |
public ILegend getLegend() {
|
483 |
ProportionalSymbolsLegend theLegend = new ProportionalSymbolsLegend();
|
484 |
|
485 |
String[] fieldNames = new String[2]; |
486 |
fieldNames[0] = cmbValue.getSelectedItem().toString();
|
487 |
|
488 |
if (!useNormalization) {
|
489 |
fieldNames[1] = fieldNames[0]; |
490 |
} else {
|
491 |
fieldNames[1] = cmbNormalization.getSelectedItem().toString();
|
492 |
} |
493 |
|
494 |
auxLegend.setTemplateShapeType(templateShapeType); |
495 |
auxLegend.setValueField(cmbValue.getSelectedItem().toString()); |
496 |
auxLegend.setNormalizationField(cmbNormalization.getSelectedItem().toString()); |
497 |
auxLegend.setUseNormalization(useNormalization); |
498 |
|
499 |
auxLegend.setMinSize(txtMinSize.getDouble()); |
500 |
auxLegend.setMaxSize(txtMaxSize.getDouble()); |
501 |
|
502 |
auxLegend.clear(); |
503 |
|
504 |
ISymbol symbol = getTemplSymbol().getSymbol(); |
505 |
symbol.setDescription(getSymbolDescription()); |
506 |
auxLegend.setDefaultSymbol(symbol); |
507 |
|
508 |
auxLegend.setClassifyingFieldNames(fieldNames); |
509 |
|
510 |
// ==================================
|
511 |
FLyrVect vect = (FLyrVect) myLayer; |
512 |
FeatureStore fsto = null;
|
513 |
FeatureType fty = null;
|
514 |
FeatureAttributeDescriptor[] atts = null; |
515 |
|
516 |
try {
|
517 |
fsto = (FeatureStore) vect.getDataStore(); |
518 |
fty = fsto.getDefaultFeatureType(); |
519 |
|
520 |
int[] fieldTyp = new int[2]; |
521 |
fieldTyp[0] = fty.getAttributeDescriptor(fieldNames[0]).getType(); |
522 |
fieldTyp[1] = fty.getAttributeDescriptor(fieldNames[1]).getType(); |
523 |
auxLegend.setClassifyingFieldTypes(fieldTyp); |
524 |
|
525 |
FeatureSet fset = fsto.getFeatureSet(); |
526 |
DisposableIterator diter = fset.fastIterator(); |
527 |
Feature fitem = null;
|
528 |
double[] maxs = new double[fieldNames.length]; |
529 |
double[] mins = new double[fieldNames.length]; |
530 |
for (int i = 0; i < fieldNames.length; i++) { |
531 |
// init to worst values
|
532 |
maxs[i] = -Double.MAX_VALUE;
|
533 |
mins[i] = Double.MAX_VALUE;
|
534 |
} |
535 |
double aux_dob = 0; |
536 |
|
537 |
while (diter.hasNext()) {
|
538 |
fitem = (Feature) diter.next(); |
539 |
for (int i = 0; i < fieldNames.length; i++) { |
540 |
aux_dob = fitem.getDouble(fieldNames[i]); |
541 |
if (aux_dob > maxs[i]) {
|
542 |
maxs[i] = aux_dob; |
543 |
} |
544 |
if (aux_dob < mins[i]) {
|
545 |
mins[i] = aux_dob; |
546 |
} |
547 |
} |
548 |
} |
549 |
auxLegend.setMinFeature(mins[0]);
|
550 |
auxLegend.setMaxFeature(maxs[0]);
|
551 |
|
552 |
} catch (DataException e) {
|
553 |
logger.info("Error while creating ProportionalSymbols legend", e);
|
554 |
ApplicationLocator.getManager().message( |
555 |
Messages.getText("_Error_while_creating_legend"),
|
556 |
JOptionPane.ERROR_MESSAGE);
|
557 |
} |
558 |
|
559 |
//Just to avoid empty legend
|
560 |
auxLegend.addSymbol(-Double.MAX_VALUE, symbol);
|
561 |
|
562 |
if (auxLegend.isPolygonal(this.templateShapeType)) { |
563 |
auxLegend.setBackgroundSymbol(getBtnBackground().getSymbol()); |
564 |
} |
565 |
|
566 |
theLegend = (ProportionalSymbolsLegend) auxLegend.cloneLegend(); |
567 |
|
568 |
return theLegend;
|
569 |
} |
570 |
|
571 |
/**
|
572 |
* Creates the String which will be the description of the symbol. If the
|
573 |
* selected normalization field is not "None", then the String created will
|
574 |
* have this structure ValueField/NormalizationField. Else, if the user
|
575 |
* select "None" for the normalization field,the string will show the
|
576 |
* ValueField only.
|
577 |
*
|
578 |
* @return String description for the symbol
|
579 |
*/
|
580 |
private String getSymbolDescription() { |
581 |
String description = ""; |
582 |
|
583 |
if (cmbValue.getSelectedItem() != null) { |
584 |
description += cmbValue.getSelectedItem().toString(); |
585 |
} |
586 |
if (cmbNormalization.getSelectedItem().toString().compareTo(noNormalization) != 0) { |
587 |
description += " / " + cmbNormalization.getSelectedItem().toString();
|
588 |
} |
589 |
|
590 |
return description;
|
591 |
} |
592 |
|
593 |
public String getDescription() { |
594 |
return Messages.getText(
|
595 |
"draw_quantities_using_symbol_size_to_show_exact_values");
|
596 |
} |
597 |
|
598 |
public ImageIcon getIcon() { |
599 |
return IconThemeHelper.getImageIcon(
|
600 |
"legend-overview-proportional-symbols");
|
601 |
} |
602 |
|
603 |
public Class getParentClass() { |
604 |
return Quantities.class;
|
605 |
} |
606 |
|
607 |
public String getTitle() { |
608 |
return Messages.getText("proportional_symbols"); |
609 |
} |
610 |
|
611 |
public Class getLegendClass() { |
612 |
return ProportionalSymbolsLegend.class;
|
613 |
} |
614 |
|
615 |
public boolean isSuitableFor(FLayer layer) { |
616 |
if (layer instanceof FLyrVect) { |
617 |
|
618 |
FLyrVect lyr = (FLyrVect) layer; |
619 |
try {
|
620 |
if (lyr.getShapeType() == Geometry.TYPES.GEOMETRY) {
|
621 |
return false; |
622 |
} |
623 |
|
624 |
FeatureStore fsto = (FeatureStore) lyr.getDataStore(); |
625 |
FeatureType fty = fsto.getDefaultFeatureType(); |
626 |
FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
|
627 |
|
628 |
for (int i = 0; i < atts.length; i++) { |
629 |
if (atts[i].getDataType().isNumeric()) {
|
630 |
return true; |
631 |
} |
632 |
} |
633 |
} catch (DataException e) {
|
634 |
logger.info("Error in isSuitableFor", e);
|
635 |
ApplicationLocator.getManager().message( |
636 |
Messages.getText("_Error_while_checking_suitability"),
|
637 |
JOptionPane.ERROR_MESSAGE);
|
638 |
return false; |
639 |
} |
640 |
} |
641 |
return false; |
642 |
} |
643 |
|
644 |
public JPanel getPanel() { |
645 |
return this; |
646 |
} |
647 |
|
648 |
private ActionListener action = new ActionListener() { |
649 |
|
650 |
public void actionPerformed(ActionEvent e) { |
651 |
|
652 |
if (e.getSource().equals(cmbValue)) {
|
653 |
JComboBox cb = (JComboBox) e.getSource(); |
654 |
auxLegend.setValueField(cb.getSelectedItem().toString()); |
655 |
} |
656 |
if (e.getSource().equals(cmbNormalization)) {
|
657 |
JComboBox cb = (JComboBox) e.getSource(); |
658 |
if (cb.getSelectedItem().toString().compareTo(noNormalization) == 0) { |
659 |
useNormalization = false;
|
660 |
auxLegend.setNormalizationField(cmbValue.getSelectedItem().toString()); |
661 |
} else {
|
662 |
useNormalization = true;
|
663 |
auxLegend.setNormalizationField(cb.getSelectedItem().toString()); |
664 |
} |
665 |
auxLegend.setUseNormalization(useNormalization); |
666 |
} |
667 |
if (e.getSource().equals(txtMinSize)) {
|
668 |
if (txtMaxSize.getDouble() < txtMinSize.getDouble()) {
|
669 |
txtMaxSize.setDouble(txtMinSize.getDouble()); |
670 |
} |
671 |
} |
672 |
if (e.getSource().equals(txtMaxSize)) {
|
673 |
if (txtMaxSize.getDouble() < txtMinSize.getDouble()) {
|
674 |
txtMinSize.setDouble(txtMaxSize.getDouble()); |
675 |
} |
676 |
} |
677 |
} |
678 |
}; |
679 |
|
680 |
} |