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