Revision 9675
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.231/buildNumber.properties | ||
---|---|---|
1 |
#Sat Oct 14 19:23:34 CEST 2023 |
|
2 |
buildNumber=235 |
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.231/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.symbology.library.ProportionalSymbolsLibrary |
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.231/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<!-- |
|
2 |
|
|
3 |
gvSIG. Desktop Geographic Information System. |
|
4 |
|
|
5 |
Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
|
8 |
modify it under the terms of the GNU General Public License |
|
9 |
as published by the Free Software Foundation; either version 3 |
|
10 |
of the License, or (at your option) any later version. |
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
GNU General Public License for more details. |
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
|
18 |
along with this program; if not, write to the Free Software |
|
19 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
MA 02110-1301, USA. |
|
21 |
|
|
22 |
For any additional information, do not hesitate to contact us |
|
23 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
|
|
25 |
--> |
|
26 |
<assembly> |
|
27 |
<id>gvsig-plugin-package</id> |
|
28 |
<formats> |
|
29 |
<format>zip</format> |
|
30 |
</formats> |
|
31 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
32 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
33 |
<files> |
|
34 |
<file> |
|
35 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
36 |
<outputDirectory>lib</outputDirectory> |
|
37 |
</file> |
|
38 |
<file> |
|
39 |
<source>target/package.info</source> |
|
40 |
</file> |
|
41 |
</files> |
|
42 |
|
|
43 |
<fileSets> |
|
44 |
<fileSet> |
|
45 |
<directory>src/main/resources-plugin</directory> |
|
46 |
<outputDirectory>.</outputDirectory> |
|
47 |
</fileSet> |
|
48 |
</fileSets> |
|
49 |
|
|
50 |
<!-- No dependencies |
|
51 |
<dependencySets> |
|
52 |
<dependencySet> |
|
53 |
<useProjectArtifact>false</useProjectArtifact> |
|
54 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
55 |
<outputDirectory>lib</outputDirectory> |
|
56 |
<includes> |
|
57 |
<include>...</include> |
|
58 |
</includes> |
|
59 |
</dependencySet> |
|
60 |
</dependencySets> |
|
61 |
--> |
|
62 |
|
|
63 |
</assembly> |
|
64 |
|
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.231/src/main/java/org/gvsig/symbology/fmap/rendering/ProportionalSymbolsLegend.java | ||
---|---|---|
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.fmap.rendering; |
|
42 |
|
|
43 |
import org.slf4j.Logger; |
|
44 |
import org.slf4j.LoggerFactory; |
|
45 |
|
|
46 |
import org.gvsig.fmap.dal.feature.Feature; |
|
47 |
import org.gvsig.fmap.geom.Geometry; |
|
48 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
49 |
import org.gvsig.fmap.geom.GeometryManager; |
|
50 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
51 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
52 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
|
54 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.IntervalLegendEvent; |
|
55 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LabelLegendEvent; |
|
56 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
|
57 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
|
58 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
59 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.ValueLegendEvent; |
|
60 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
|
61 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
62 |
import org.gvsig.i18n.Messages; |
|
63 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend; |
|
64 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MarkerFillSymbol; |
|
65 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol; |
|
66 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
67 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
68 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleMarkerFillPropertiesStyle; |
|
69 |
import org.gvsig.tools.ToolsLocator; |
|
70 |
import org.gvsig.tools.dynobject.DynStruct; |
|
71 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
72 |
import org.gvsig.tools.persistence.PersistentState; |
|
73 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
74 |
import org.gvsig.tools.util.Callable; |
|
75 |
|
|
76 |
|
|
77 |
/** |
|
78 |
* Implements a legend which represents the quantitative information |
|
79 |
* (numeric values). This representation is possible thanks to a symbol |
|
80 |
* whose size is different each time (depending on the numeric values |
|
81 |
* and if we want to use normalization or not). |
|
82 |
* |
|
83 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
84 |
* @author jldominguez |
|
85 |
*/ |
|
86 |
public class ProportionalSymbolsLegend extends VectorialUniqueValueLegend { |
|
87 |
|
|
88 |
private static Logger logger = LoggerFactory.getLogger(ProportionalSymbolsLegend.class); |
|
89 |
public static final String |
|
90 |
PROPORTIONAL_SYMBOL_LEGEND_NAME = |
|
91 |
"PROPORTIONAL_SYMBOL_LEGEND"; |
|
92 |
public static final String |
|
93 |
PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME = |
|
94 |
"PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION"; |
|
95 |
|
|
96 |
public void setClassifyingFieldNames(String[] fNames) { |
|
97 |
super.setClassifyingFieldNames(fNames); |
|
98 |
valueField = fNames[0]; |
|
99 |
normalizationField = fNames[1]; |
|
100 |
} |
|
101 |
|
|
102 |
private ISymbol backgroundSymbol; |
|
103 |
private String valueField; |
|
104 |
private String normalizationField; |
|
105 |
private double minSize; |
|
106 |
private double maxSize; |
|
107 |
private int templateShapeType; |
|
108 |
private boolean useNormalization; |
|
109 |
private double maxFeature, minFeature; |
|
110 |
private ZSort zSort = null; |
|
111 |
|
|
112 |
|
|
113 |
public ISymbol getSymbolByValue(Object key) { |
|
114 |
return null; |
|
115 |
} |
|
116 |
|
|
117 |
public ISymbol getSymbolByFeature(Feature feat) { |
|
118 |
|
|
119 |
ISymbol theSymbol = getDefaultSymbol(); |
|
120 |
ISymbol auxSymbol; |
|
121 |
|
|
122 |
double value = 0; |
|
123 |
double normValue = 0; |
|
124 |
double size; |
|
125 |
double separation = maxSize-minSize; |
|
126 |
|
|
127 |
if (separation == 0) { |
|
128 |
separation = 1; |
|
129 |
} |
|
130 |
|
|
131 |
try { |
|
132 |
|
|
133 |
value = feat.getDouble(this.valueField); |
|
134 |
if (useNormalization) { |
|
135 |
|
|
136 |
normValue = feat.getDouble(this.normalizationField); |
|
137 |
if (normValue == 0) { |
|
138 |
size = (value >= 0) ? |
|
139 |
Double.POSITIVE_INFINITY : |
|
140 |
Double.NEGATIVE_INFINITY; |
|
141 |
} else { |
|
142 |
value = value / normValue; |
|
143 |
size = minSize + (value * separation) ; |
|
144 |
} |
|
145 |
|
|
146 |
} else { |
|
147 |
double difFeat = maxFeature - minFeature; |
|
148 |
double step = difFeat/separation; |
|
149 |
size = minSize + ((value - minFeature)/step); |
|
150 |
} |
|
151 |
|
|
152 |
} catch (Exception e) { |
|
153 |
logger.info("Error while getting value in ProportionalSymbolsLegend.", e); |
|
154 |
return null; |
|
155 |
} |
|
156 |
|
|
157 |
if (size == Double.NaN || size == Double.POSITIVE_INFINITY |
|
158 |
|| size == Double.NEGATIVE_INFINITY) { |
|
159 |
|
|
160 |
// logger.info("The symbol size is NaN or INFINITE."); |
|
161 |
return null; |
|
162 |
} |
|
163 |
|
|
164 |
Geometry defgeom = feat.getDefaultGeometry(); |
|
165 |
int def_geom_type = defgeom.getGeometryType().getType(); |
|
166 |
|
|
167 |
if (isPolygonal(def_geom_type) && theSymbol instanceof IMarkerSymbol) { |
|
168 |
|
|
169 |
MarkerFillSymbol aux = new MarkerFillSymbol(); |
|
170 |
((IMarkerSymbol) theSymbol).setSize(size); |
|
171 |
aux.setMarker((IMarkerSymbol) theSymbol); |
|
172 |
SimpleMarkerFillPropertiesStyle p = new SimpleMarkerFillPropertiesStyle(); |
|
173 |
p.setFillStyle(SimpleMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL); |
|
174 |
aux.setMarkerFillProperties(p); |
|
175 |
theSymbol = aux; |
|
176 |
} |
|
177 |
else if (isLinear(def_geom_type)) { |
|
178 |
|
|
179 |
ILineSymbol line = (ILineSymbol) theSymbol; |
|
180 |
line.setLineWidth(size); |
|
181 |
theSymbol = line; |
|
182 |
} |
|
183 |
else if (isPoint(def_geom_type)) { |
|
184 |
IMarkerSymbol marker = (IMarkerSymbol) theSymbol; |
|
185 |
marker.setSize(size); |
|
186 |
theSymbol = marker; |
|
187 |
} |
|
188 |
|
|
189 |
if (backgroundSymbol != null) { |
|
190 |
MultiLayerFillSymbol multi = new MultiLayerFillSymbol() ; |
|
191 |
multi.addLayer(backgroundSymbol); |
|
192 |
multi.addLayer(theSymbol); |
|
193 |
return multi; |
|
194 |
} |
|
195 |
auxSymbol = theSymbol; |
|
196 |
|
|
197 |
return auxSymbol; |
|
198 |
|
|
199 |
} |
|
200 |
|
|
201 |
public static boolean isPolygonal(int ty) { |
|
202 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
203 |
return geomManager.isSubtype(Geometry.TYPES.MULTISURFACE, ty) || |
|
204 |
geomManager.isSubtype(Geometry.TYPES.SURFACE, ty); |
|
205 |
} |
|
206 |
|
|
207 |
public static boolean isLinear(int ty) { |
|
208 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
209 |
return geomManager.isSubtype(Geometry.TYPES.MULTICURVE, ty) || |
|
210 |
geomManager.isSubtype(Geometry.TYPES.CURVE, ty); |
|
211 |
} |
|
212 |
|
|
213 |
public static boolean isPoint(int ty) { |
|
214 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
215 |
return geomManager.isSubtype(Geometry.TYPES.MULTIPOINT, ty) || |
|
216 |
geomManager.isSubtype(Geometry.TYPES.POINT, ty); |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* Gets the background symbol which only can appear when the shapetype of the layer |
|
221 |
* is polygonal |
|
222 |
* |
|
223 |
* @return ISymbol the symbol for the background |
|
224 |
*/ |
|
225 |
public ISymbol getBackgroundSymbol() {return backgroundSymbol;} |
|
226 |
/** |
|
227 |
* Sets the background symbol which is used only when the shapetype of the layer is polygonal |
|
228 |
* |
|
229 |
* @param backgroundSymbol the symbol for the background |
|
230 |
*/ |
|
231 |
public void setBackgroundSymbol(ISymbol backgroundSymbol) {this.backgroundSymbol = backgroundSymbol;} |
|
232 |
/** |
|
233 |
* Obtains the classifying field name to be used to calculate the size of the symbol |
|
234 |
* |
|
235 |
* @return String the name of the field |
|
236 |
* @throws ReadDriverException |
|
237 |
*/ |
|
238 |
public String getValueField() { |
|
239 |
// try { |
|
240 |
// // TODO: |
|
241 |
// // Por los alias, al guardar un proyecto no podemos |
|
242 |
// // permitir que se guarde con campos que luego |
|
243 |
// // no van a existir. |
|
244 |
//// int id = dataSource.getFieldIndexByName(valueField); |
|
245 |
//// valueField = dataSource.getFieldName(id); |
|
246 |
// } catch (ReadDriverException e) { |
|
247 |
// e.printStackTrace(); |
|
248 |
// throw new RuntimeException(e); |
|
249 |
// } |
|
250 |
return valueField; |
|
251 |
} |
|
252 |
/** |
|
253 |
* Sets the classifying field name to be used to calculate the size of the symbol |
|
254 |
* |
|
255 |
* @param String the name of the field |
|
256 |
*/ |
|
257 |
public void setValueField(String valueField) {this.valueField = valueField;} |
|
258 |
/** |
|
259 |
* Obtains the classifying field name to be used to calculate the size of the symbol when the |
|
260 |
* user is doing it with a normalization value. |
|
261 |
* |
|
262 |
* @return String the name of the field |
|
263 |
*/ |
|
264 |
public String getNormalizationField() { |
|
265 |
return normalizationField; |
|
266 |
} |
|
267 |
/** |
|
268 |
* Sets the classifying field name to be used to calculate the size of the symbol when the |
|
269 |
* user is doing it with a normalization value. |
|
270 |
* |
|
271 |
* @param String the name of the field |
|
272 |
*/ |
|
273 |
public void setNormalizationField(String normalizationField) {this.normalizationField = normalizationField;} |
|
274 |
/** |
|
275 |
* Obtains the minimum size for the symbol |
|
276 |
* |
|
277 |
* @return double the minimum size for the symbol |
|
278 |
*/ |
|
279 |
public double getMinSize() {return minSize;} |
|
280 |
/** |
|
281 |
* Sets the minimum size for the symbol |
|
282 |
* |
|
283 |
* @param minSize the minimum size for the symbol |
|
284 |
*/ |
|
285 |
public void setMinSize(double minSize) {this.minSize = minSize;} |
|
286 |
/** |
|
287 |
* Obtains the maximum size for the symbol |
|
288 |
* |
|
289 |
* @return double the minimum size for the symbol |
|
290 |
*/ |
|
291 |
public double getMaxSize() {return maxSize;} |
|
292 |
/** |
|
293 |
* Sets the maximum size for the symbol |
|
294 |
* |
|
295 |
* @param maxSize the minimum size for the symbol |
|
296 |
*/ |
|
297 |
public void setMaxSize(double maxSize) {this.maxSize = maxSize;} |
|
298 |
/** |
|
299 |
* Obtains the shapetype of the template symbol |
|
300 |
* |
|
301 |
* @return int shape type for the template symbol |
|
302 |
*/ |
|
303 |
public int getTemplateShapeType() {return templateShapeType;} |
|
304 |
/** |
|
305 |
* Sets the shapetype of the template symbol |
|
306 |
* |
|
307 |
* @param templateShapeType shape type for the template symbol |
|
308 |
*/ |
|
309 |
public void setTemplateShapeType(int tst) { |
|
310 |
|
|
311 |
if (isPolygonal(getShapeType())) { |
|
312 |
if (isPoint(tst) || isPolygonal(tst)) { |
|
313 |
this.templateShapeType = tst; |
|
314 |
} |
|
315 |
} else { |
|
316 |
|
|
317 |
if ((isPoint(tst) && isPoint(getShapeType())) |
|
318 |
|| (isLinear(tst) && isLinear(getShapeType()))) { |
|
319 |
// || (getShapeType() == Geometry.TYPES.NULL)) { |
|
320 |
|
|
321 |
this.templateShapeType = tst; |
|
322 |
} |
|
323 |
} |
|
324 |
} |
|
325 |
|
|
326 |
/** |
|
327 |
* Obtains the boolean which is true if the user wants to calculate the size of the |
|
328 |
* symbol using a normalization field. |
|
329 |
* |
|
330 |
* @return boolean true if the user wants normalization.Otherwise, false. |
|
331 |
*/ |
|
332 |
public boolean getUseNormalization() {return useNormalization;} |
|
333 |
/** |
|
334 |
* Sets the boolean which is true if the user wants to calculate the size of the |
|
335 |
* symbol using a normalization field. |
|
336 |
* |
|
337 |
* @param useNormalization true if the user wants normalization.Otherwise, false. |
|
338 |
*/ |
|
339 |
public void setUseNormalization(boolean useNormalization) {this.useNormalization = useNormalization;} |
|
340 |
/** |
|
341 |
* Obtains the variable which represents the maximum value of the classifying field that is used |
|
342 |
* to calculate the size of the symbol |
|
343 |
* |
|
344 |
* @return double the maximum value of the classifying field |
|
345 |
*/ |
|
346 |
public double getMaxFeature() {return maxFeature;} |
|
347 |
/** |
|
348 |
* Sets the variable which represents the maximum value of the classifying field that is used |
|
349 |
* to calculate the size of the symbol |
|
350 |
* |
|
351 |
* @param maxFeature |
|
352 |
*/ |
|
353 |
public void setMaxFeature(double maxFeature) {this.maxFeature = maxFeature;} |
|
354 |
/** |
|
355 |
* Obtains the variable which represents the minimum value of the classifying field that is used |
|
356 |
* to calculate the size of the symbol |
|
357 |
* |
|
358 |
* @return double the minimum value of the classifying field |
|
359 |
*/ |
|
360 |
public double getMinFeature() {return minFeature;} |
|
361 |
/** |
|
362 |
* Sets the variable which represents the minimum value of the classifying field that is used |
|
363 |
* to calculate the size of the symbol |
|
364 |
* |
|
365 |
* @param minFeature |
|
366 |
*/ |
|
367 |
public void setMinFeature(double minFeature) {this.minFeature = minFeature;} |
|
368 |
|
|
369 |
|
|
370 |
public ISymbol[] getSymbols() { |
|
371 |
ISymbol[] auxSymbols=super.getSymbols(); |
|
372 |
if(backgroundSymbol != null){ |
|
373 |
ISymbol[] symbols=new ISymbol[auxSymbols.length+1]; |
|
374 |
for (int i = 0; i < auxSymbols.length; i++) { |
|
375 |
symbols[i]=auxSymbols[i]; |
|
376 |
} |
|
377 |
symbols[symbols.length-1]=backgroundSymbol; |
|
378 |
return symbols; |
|
379 |
} else { |
|
380 |
return auxSymbols; |
|
381 |
} |
|
382 |
} |
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
public ZSort getZSort() { |
|
387 |
if (zSort == null){ |
|
388 |
zSort = new MyZSort(this); |
|
389 |
} |
|
390 |
return zSort; |
|
391 |
} |
|
392 |
|
|
393 |
public void setZSort(ZSort zSort){ |
|
394 |
return; |
|
395 |
} |
|
396 |
|
|
397 |
private class MyZSort extends ZSort { |
|
398 |
|
|
399 |
public MyZSort(ILegend legend) { |
|
400 |
super(legend); |
|
401 |
} |
|
402 |
|
|
403 |
public void legendChanged(LegendChangedEvent e) { |
|
404 |
} |
|
405 |
|
|
406 |
public String getClassName() { |
|
407 |
return getClass().getName(); |
|
408 |
} |
|
409 |
|
|
410 |
public int getLevelCount() { |
|
411 |
int levels = 0; |
|
412 |
if (backgroundSymbol!=null){ |
|
413 |
if(backgroundSymbol instanceof IMultiLayerSymbol){ |
|
414 |
levels += ((IMultiLayerSymbol)backgroundSymbol).getLayerCount(); |
|
415 |
} else { |
|
416 |
levels += 1; |
|
417 |
} |
|
418 |
} |
|
419 |
ISymbol sym = getDefaultSymbol(); |
|
420 |
if(getDefaultSymbol() instanceof IMultiLayerSymbol){ |
|
421 |
levels += ((IMultiLayerSymbol)sym).getLayerCount(); |
|
422 |
} else { |
|
423 |
levels += 1; |
|
424 |
} |
|
425 |
return levels+1; |
|
426 |
} |
|
427 |
|
|
428 |
|
|
429 |
public void setUsingZSort(boolean usingZSort) { |
|
430 |
} |
|
431 |
|
|
432 |
public void setLevels(ISymbol sym, int[] values) { |
|
433 |
} |
|
434 |
|
|
435 |
|
|
436 |
public void setLevels(int row, int[] values) { |
|
437 |
} |
|
438 |
|
|
439 |
public int[] getLevels(ISymbol sym) { |
|
440 |
return getLevels(0); |
|
441 |
} |
|
442 |
|
|
443 |
public int[] getLevels(int row) { |
|
444 |
int levelsCount = getLevelCount(); |
|
445 |
int[] levels = new int[levelsCount]; |
|
446 |
int bgLevels = 1; |
|
447 |
if (backgroundSymbol!=null){ |
|
448 |
if(backgroundSymbol instanceof IMultiLayerSymbol){ |
|
449 |
bgLevels = ((IMultiLayerSymbol)backgroundSymbol).getLayerCount(); |
|
450 |
} |
|
451 |
for (int i=0; i<bgLevels; i++) { |
|
452 |
levels[i]=i; |
|
453 |
} |
|
454 |
} |
|
455 |
|
|
456 |
ISymbol sym = getDefaultSymbol(); |
|
457 |
int frLevels = 1; |
|
458 |
if(getDefaultSymbol() instanceof IMultiLayerSymbol){ |
|
459 |
frLevels = ((IMultiLayerSymbol)sym).getLayerCount(); |
|
460 |
} |
|
461 |
for (int i=0; i<frLevels; i++) { |
|
462 |
levels[i+bgLevels]=i+bgLevels; |
|
463 |
} |
|
464 |
levels[frLevels+bgLevels]=frLevels+bgLevels; |
|
465 |
return levels; |
|
466 |
} |
|
467 |
|
|
468 |
|
|
469 |
public boolean isUsingZSort() { |
|
470 |
return backgroundSymbol!=null; |
|
471 |
} |
|
472 |
|
|
473 |
|
|
474 |
public ISymbol[] getSymbols() { |
|
475 |
return getSymbols(); |
|
476 |
} |
|
477 |
|
|
478 |
public String[] getDescriptions() { |
|
479 |
return getDescriptions(); |
|
480 |
} |
|
481 |
|
|
482 |
public int getTopLevelIndexAllowed() { |
|
483 |
return getLevelCount(); |
|
484 |
} |
|
485 |
|
|
486 |
@Override |
|
487 |
public String toString() { |
|
488 |
String out = "ZSort for ProportionalSymbolLegend"; |
|
489 |
return out; |
|
490 |
} |
|
491 |
|
|
492 |
public boolean symbolChanged(SymbolLegendEvent e) { |
|
493 |
return true; |
|
494 |
} |
|
495 |
|
|
496 |
public boolean classifiedSymbolChange(SymbolLegendEvent e) { |
|
497 |
return true; |
|
498 |
} |
|
499 |
|
|
500 |
public boolean intervalChange(IntervalLegendEvent e) { |
|
501 |
return false; |
|
502 |
} |
|
503 |
|
|
504 |
public boolean valueChange(ValueLegendEvent e) { |
|
505 |
return false; |
|
506 |
} |
|
507 |
|
|
508 |
// TODO should not exist here |
|
509 |
public boolean labelFieldChange(LabelLegendEvent e) { |
|
510 |
return false; |
|
511 |
} |
|
512 |
|
|
513 |
public void legendCleared(LegendClearEvent event) { |
|
514 |
} |
|
515 |
} |
|
516 |
|
|
517 |
|
|
518 |
public void loadFromState(PersistentState state) |
|
519 |
throws PersistenceException { |
|
520 |
|
|
521 |
int[] ft = state.getIntArray("fieldTypes"); |
|
522 |
this.setClassifyingFieldTypes(ft); |
|
523 |
|
|
524 |
this.valueField = state.getString("valueField"); |
|
525 |
this.normalizationField = state.getString("normalizationField"); |
|
526 |
this.templateShapeType = state.getInt("templateShapeType"); |
|
527 |
this.maxSize = state.getDouble("maxSize"); |
|
528 |
this.minSize = state.getDouble("minSize"); |
|
529 |
this.maxFeature = state.getDouble("maxFeature"); |
|
530 |
this.minFeature = state.getDouble("minFeature"); |
|
531 |
this.useNormalization = state.getBoolean("useNormalization"); |
|
532 |
|
|
533 |
ISymbol sym = (ISymbol) state.get("defaultSymbol"); |
|
534 |
this.setDefaultSymbol(sym); |
|
535 |
|
|
536 |
sym = (ISymbol) state.get("backgroundSymbol"); |
|
537 |
this.setBackgroundSymbol(sym); |
|
538 |
|
|
539 |
String[] fieldNames = new String[2]; |
|
540 |
fieldNames[0]= valueField; |
|
541 |
if (normalizationField.compareTo(Messages.getText("none")) == 0) { |
|
542 |
fieldNames[1]= fieldNames[0]; |
|
543 |
} else { |
|
544 |
fieldNames[1] = normalizationField; |
|
545 |
} |
|
546 |
setClassifyingFieldNames(fieldNames); |
|
547 |
} |
|
548 |
|
|
549 |
|
|
550 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
551 |
|
|
552 |
int[] ft = this.getClassifyingFieldTypes(); |
|
553 |
state.set("fieldTypes", ft); |
|
554 |
|
|
555 |
state.set("valueField", this.valueField); |
|
556 |
state.set("normalizationField", this.normalizationField); |
|
557 |
state.set("templateShapeType", this.templateShapeType); |
|
558 |
state.set("maxSize", this.maxSize); |
|
559 |
state.set("minSize", this.minSize); |
|
560 |
state.set("maxFeature", this.maxFeature); |
|
561 |
state.set("minFeature", this.minFeature); |
|
562 |
state.set("useNormalization", this.useNormalization); |
|
563 |
state.set("defaultSymbol", this.getDefaultSymbol()); |
|
564 |
state.set("backgroundSymbol", this.backgroundSymbol); |
|
565 |
} |
|
566 |
|
|
567 |
|
|
568 |
public static class RegisterPersistence implements Callable { |
|
569 |
|
|
570 |
public Object call() throws Exception { |
|
571 |
|
|
572 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
573 |
if (manager |
|
574 |
.getDefinition(PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) { |
|
575 |
DynStruct definition = |
|
576 |
manager |
|
577 |
.addDefinition( |
|
578 |
ProportionalSymbolsLegend.class, |
|
579 |
PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME, |
|
580 |
PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME |
|
581 |
+ " Persistence definition", null, null); |
|
582 |
|
|
583 |
definition.addDynFieldString("valueField").setMandatory(true); |
|
584 |
definition.addDynFieldString("normalizationField").setMandatory(true); |
|
585 |
definition.addDynFieldInt("templateShapeType").setMandatory(true); |
|
586 |
definition.addDynFieldArray("fieldTypes").setClassOfItems(Integer.class).setMandatory(true); |
|
587 |
definition.addDynFieldDouble("maxSize").setMandatory(true); |
|
588 |
definition.addDynFieldDouble("minSize").setMandatory(true); |
|
589 |
definition.addDynFieldDouble("maxFeature").setMandatory(true); |
|
590 |
definition.addDynFieldDouble("minFeature").setMandatory(true); |
|
591 |
definition.addDynFieldBoolean("useNormalization").setMandatory(true); |
|
592 |
|
|
593 |
definition.addDynFieldObject("defaultSymbol") |
|
594 |
.setClassOfValue(ISymbol.class).setMandatory(true); |
|
595 |
definition.addDynFieldObject("backgroundSymbol") |
|
596 |
.setClassOfValue(ISymbol.class).setMandatory(true); |
|
597 |
} |
|
598 |
return Boolean.TRUE; |
|
599 |
} |
|
600 |
|
|
601 |
} |
|
602 |
|
|
603 |
public static class RegisterLegend implements Callable { |
|
604 |
|
|
605 |
public Object call() throws Exception { |
|
606 |
MapContextManager manager = |
|
607 |
MapContextLocator.getMapContextManager(); |
|
608 |
|
|
609 |
manager.registerLegend( |
|
610 |
PROPORTIONAL_SYMBOL_LEGEND_NAME, |
|
611 |
ProportionalSymbolsLegend.class); |
|
612 |
|
|
613 |
return Boolean.TRUE; |
|
614 |
} |
|
615 |
|
|
616 |
} |
|
617 |
|
|
618 |
} |
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.231/src/main/java/org/gvsig/symbology/gui/layerproperties/ProportionalSymbolsPanel.java | ||
---|---|---|
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 |
} |
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.231/src/main/java/org/gvsig/symbology/library/ProportionalSymbolsLibrary.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2013 gvSIG Association |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.symbology.library; |
|
24 |
|
|
25 |
import org.gvsig.andami.IconThemeHelper; |
|
26 |
import org.gvsig.app.project.documents.view.legend.gui.LegendManager; |
|
27 |
import org.gvsig.symbology.SymbologyLibrary; |
|
28 |
import org.gvsig.symbology.fmap.rendering.ProportionalSymbolsLegend; |
|
29 |
import org.gvsig.symbology.gui.layerproperties.ProportionalSymbolsPanel; |
|
30 |
import org.gvsig.tools.library.AbstractLibrary; |
|
31 |
import org.gvsig.tools.library.LibraryException; |
|
32 |
import org.gvsig.tools.persistence.xml.XMLPersistenceLibrary; |
|
33 |
import org.gvsig.tools.util.Caller; |
|
34 |
import org.gvsig.tools.util.impl.DefaultCaller; |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* Simple library to register proportional symbols legend |
|
39 |
* |
|
40 |
* @author jldominguez |
|
41 |
* |
|
42 |
*/ |
|
43 |
public class ProportionalSymbolsLibrary extends AbstractLibrary { |
|
44 |
|
|
45 |
|
|
46 |
public void doRegistration() { |
|
47 |
registerAsImplementationOf(ProportionalSymbolsLibrary.class); |
|
48 |
/* |
|
49 |
* This checks map context library registration |
|
50 |
*/ |
|
51 |
require(SymbologyLibrary.class); |
|
52 |
/* |
|
53 |
* This is because we need to use persistence manager |
|
54 |
*/ |
|
55 |
require(XMLPersistenceLibrary.class); |
|
56 |
} |
|
57 |
|
|
58 |
protected void doInitialize() throws LibraryException { |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
protected void doPostInitialize() throws LibraryException { |
|
64 |
|
|
65 |
IconThemeHelper.registerIcon( |
|
66 |
"legend", "legend-overview-proportional-symbols", this); |
|
67 |
|
|
68 |
Caller caller = new DefaultCaller(); |
|
69 |
|
|
70 |
caller.add(new ProportionalSymbolsLegend.RegisterLegend()); |
|
71 |
caller.add(new ProportionalSymbolsLegend.RegisterPersistence()); |
|
72 |
|
|
73 |
/* |
|
74 |
* Do register of all |
|
75 |
*/ |
|
76 |
if( !caller.call() ) { |
|
77 |
throw new LibraryException( |
|
78 |
ProportionalSymbolsLibrary.class, |
|
79 |
caller.getExceptions()); |
|
80 |
} |
|
81 |
|
|
82 |
LegendManager.addLegendPage(ProportionalSymbolsPanel.class); |
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
} |
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.231/src/main/resources-plugin/i18n/text.properties | ||
---|---|---|
1 |
#Translations for language [es] |
|
2 |
#Mon Sep 21 10:02:12 CEST 2009 |
|
3 |
a_default_symbol_will_be_used=Ser\u00e1 utilizado un s\u00edmbolo por defecto |
|
4 |
above=Arriba |
|
5 |
accept=Aceptar |
|
6 |
accessing_file_structure=Accediendo a la estructura del fichero |
|
7 |
add=A\u00f1adir |
|
8 |
add_class=A\u00f1adir clase |
|
9 |
add_expression=A\u00f1adir Expresi\u00f3n |
|
10 |
add_field=A\u00f1adir campo |
|
11 |
add_operator=A\u00f1adir Operador |
Also available in: Unified diff