Revision 2521
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.72/buildNumber.properties | ||
---|---|---|
1 |
#Mon Jan 28 18:04:41 CET 2019 |
|
2 |
buildNumber=75 |
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.72/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.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.72/src/main/java/org/gvsig/symbology/fmap/rendering/filterexpression/EvaluatorCreator.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.fmap.rendering.filterexpression; |
|
24 |
|
|
25 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
|
26 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
|
27 |
|
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* Utility class to centralize the creation of an |
|
32 |
* @link {@link EvaluatorWithDescriptions} |
|
33 |
* |
|
34 |
* TODO Perhaps create a manager in Tools to perform this operation |
|
35 |
* |
|
36 |
* @author jldominguez |
|
37 |
* |
|
38 |
*/ |
|
39 |
public class EvaluatorCreator { |
|
40 |
|
|
41 |
/** |
|
42 |
* Create an {@link EvaluatorWithDescriptions} that uses |
|
43 |
* the string expression provided |
|
44 |
* |
|
45 |
* @param expr |
|
46 |
* @return |
|
47 |
*/ |
|
48 |
public static EvaluatorWithDescriptions getEvaluator(String expr) { |
|
49 |
return new SQLJEPEvaluator(expr); |
|
50 |
} |
|
51 |
|
|
52 |
} |
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.72/src/main/java/org/gvsig/symbology/fmap/rendering/VectorFilterExpressionLegend.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib��ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.fmap.rendering; |
|
42 |
|
|
43 |
|
|
44 |
import java.util.ArrayList; |
|
45 |
|
|
46 |
import org.slf4j.Logger; |
|
47 |
import org.slf4j.LoggerFactory; |
|
48 |
|
|
49 |
import org.gvsig.fmap.dal.feature.Feature; |
|
50 |
import org.gvsig.fmap.geom.Geometry; |
|
51 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
52 |
import org.gvsig.fmap.geom.GeometryManager; |
|
53 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
54 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
55 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
56 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
57 |
import org.gvsig.i18n.Messages; |
|
58 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend; |
|
59 |
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator; |
|
60 |
import org.gvsig.tools.ToolsLocator; |
|
61 |
import org.gvsig.tools.dynobject.DynStruct; |
|
62 |
import org.gvsig.tools.evaluator.Evaluator; |
|
63 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
64 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
|
65 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
66 |
import org.gvsig.tools.persistence.PersistentState; |
|
67 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
68 |
import org.gvsig.tools.util.Callable; |
|
69 |
|
|
70 |
|
|
71 |
/** |
|
72 |
* |
|
73 |
* Implements a vector legend which represents the elements of a layer |
|
74 |
* depending on the value of an expression. That is, if the expression is |
|
75 |
* evaluated to true, then the symbol associated to the expression is painted. |
|
76 |
* In other case it is not showed. |
|
77 |
* |
|
78 |
* If the expression result is a string, it is considered false if |
|
79 |
* it is the empty string "", true otherwise. |
|
80 |
* |
|
81 |
* If the expression result is numeric, it is considered false |
|
82 |
* if it is zero, and true otherwise. |
|
83 |
* |
|
84 |
* In other cases, it is considered false if the result is null and true |
|
85 |
* otherwise. |
|
86 |
* |
|
87 |
* @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es |
|
88 |
* @author jldominguez |
|
89 |
*/ |
|
90 |
public class VectorFilterExpressionLegend |
|
91 |
extends AbstractClassifiedVectorLegend { |
|
92 |
|
|
93 |
private static final Logger logger = LoggerFactory.getLogger( |
|
94 |
VectorFilterExpressionLegend.class); |
|
95 |
|
|
96 |
public static final String |
|
97 |
FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME = |
|
98 |
"FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME"; |
|
99 |
|
|
100 |
public static final String |
|
101 |
FILTER_EXPRESSION_LEGEND_NAME = "FILTER_EXPRESSION_LEGEND_NAME"; |
|
102 |
|
|
103 |
public static final String I18N_DEFAULT = Messages.getText("default_value"); |
|
104 |
public static final String NON_I18N_DEFAULT = Messages.getText("Default"); |
|
105 |
|
|
106 |
private int shapeType; |
|
107 |
private ISymbol defaultSymbol; |
|
108 |
|
|
109 |
private boolean useDefaultSymbol = false; |
|
110 |
|
|
111 |
private long error_msg_count = 0; |
|
112 |
|
|
113 |
private ArrayList<Item> newSymbols = new ArrayList<Item>() { |
|
114 |
private static final long serialVersionUID = 1L; |
|
115 |
|
|
116 |
public int indexOf(String expr) { |
|
117 |
return super.indexOf(new Item(expr, null)); |
|
118 |
} |
|
119 |
}; |
|
120 |
|
|
121 |
|
|
122 |
private class Item implements Cloneable { |
|
123 |
|
|
124 |
private ISymbol sym; |
|
125 |
// get it with getSql() |
|
126 |
// private String expression; |
|
127 |
private EvaluatorWithDescriptions evaluator; |
|
128 |
|
|
129 |
public Item(String expression, ISymbol sym) { |
|
130 |
this.sym = sym; |
|
131 |
evaluator = EvaluatorCreator.getEvaluator(expression); |
|
132 |
} |
|
133 |
|
|
134 |
public boolean equals(Object obj) { |
|
135 |
if (obj == null) return false; |
|
136 |
if (!obj.getClass().equals(Item.class)) return false; |
|
137 |
return this.evaluator.getSQL().equals( |
|
138 |
((Item) obj).evaluator.getSQL() |
|
139 |
); |
|
140 |
} |
|
141 |
|
|
142 |
public String getStringExpression() { |
|
143 |
return evaluator.getSQL(); |
|
144 |
} |
|
145 |
|
|
146 |
public Evaluator getEvaluator() { |
|
147 |
return evaluator; |
|
148 |
} |
|
149 |
|
|
150 |
public Object clone() { |
|
151 |
|
|
152 |
ISymbol clonesym = null; |
|
153 |
try { |
|
154 |
clonesym = (ISymbol) this.sym.clone(); |
|
155 |
} catch (CloneNotSupportedException e) { |
|
156 |
logger.info("Error: unable to clone symbol.", e); |
|
157 |
clonesym = this.sym; |
|
158 |
} |
|
159 |
return new Item(getStringExpression(), clonesym); |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
public VectorFilterExpressionLegend() { |
|
164 |
this.setClassifyingFieldNames(new String[0]); |
|
165 |
this.setClassifyingFieldTypes(new int[0]); |
|
166 |
} |
|
167 |
|
|
168 |
public ISymbol getSymbolByFeature(Feature featu) { |
|
169 |
|
|
170 |
EvaluatorData evda = featu.getEvaluatorData(); |
|
171 |
|
|
172 |
ISymbol returnSymbol = null; |
|
173 |
Object result = null; |
|
174 |
String expr = null; |
|
175 |
|
|
176 |
try { |
|
177 |
|
|
178 |
for (int i = 0; i < newSymbols.size(); i++) { |
|
179 |
|
|
180 |
Evaluator eval = newSymbols.get(i).getEvaluator(); |
|
181 |
expr = eval.getSQL(); |
|
182 |
|
|
183 |
if (expr.equalsIgnoreCase(VectorFilterExpressionLegend.I18N_DEFAULT)){ |
|
184 |
/* |
|
185 |
* Skip default item |
|
186 |
*/ |
|
187 |
continue; |
|
188 |
} |
|
189 |
|
|
190 |
result = eval.evaluate(evda); |
|
191 |
if (isConsideredTrue(result)) { |
|
192 |
returnSymbol = newSymbols.get(i).sym; |
|
193 |
if (returnSymbol != null) { |
|
194 |
return returnSymbol; |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
} catch (Exception e) { |
|
199 |
|
|
200 |
if (error_msg_count % 1000 == 0) { |
|
201 |
logger.info("Error (msg every 1000 occurrences) while getting symbol in VectorFilterExpressionLegend", e); |
|
202 |
error_msg_count = 0; |
|
203 |
} |
|
204 |
error_msg_count++; |
|
205 |
} |
|
206 |
|
|
207 |
if (useDefaultSymbol) |
|
208 |
return getDefaultSymbol(); |
|
209 |
|
|
210 |
return null; |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Tells whether the input object is considered true. |
|
215 |
* Basically, it is false if it has an empty value |
|
216 |
* (FALSE, null, 0, "") |
|
217 |
* |
|
218 |
* @param result |
|
219 |
* @return |
|
220 |
*/ |
|
221 |
private boolean isConsideredTrue(Object res) { |
|
222 |
|
|
223 |
if (res == null) { |
|
224 |
return false; |
|
225 |
} |
|
226 |
|
|
227 |
if (res instanceof Boolean) { |
|
228 |
return ((Boolean) res).booleanValue(); |
|
229 |
} |
|
230 |
|
|
231 |
if (res instanceof Number) { |
|
232 |
return ((Number) res).doubleValue() != 0d; |
|
233 |
} |
|
234 |
|
|
235 |
if (res instanceof String) { |
|
236 |
return ((String) res).length() > 0; |
|
237 |
} |
|
238 |
|
|
239 |
// Because it is not null |
|
240 |
return true; |
|
241 |
} |
|
242 |
|
|
243 |
public void addSymbol(Object key, ISymbol symbol) { |
|
244 |
newSymbols.add(new Item((String)key.toString(), |
|
245 |
symbol)); |
|
246 |
} |
|
247 |
|
|
248 |
public void clear() { |
|
249 |
newSymbols.clear(); |
|
250 |
} |
|
251 |
|
|
252 |
public void resetItems() { |
|
253 |
newSymbols = new ArrayList<Item>() { |
|
254 |
private static final long serialVersionUID = 1L; |
|
255 |
|
|
256 |
public int indexOf(String expr) { |
|
257 |
return super.indexOf(new Item(expr, null)); |
|
258 |
} |
|
259 |
}; |
|
260 |
} |
|
261 |
|
|
262 |
public void delSymbol(Object key) { |
|
263 |
ISymbol mySymbol = null; |
|
264 |
for (int i = 0; i < newSymbols.size(); i++) { |
|
265 |
if (newSymbols.get(i).evaluator.getSQL().equals(key)) |
|
266 |
newSymbols.remove(i); |
|
267 |
} |
|
268 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(mySymbol,null)); |
|
269 |
} |
|
270 |
|
|
271 |
|
|
272 |
public void replace(ISymbol oldSymbol, ISymbol newSymbol) { |
|
273 |
|
|
274 |
for (int i = 0; i < newSymbols.size(); i++) { |
|
275 |
if (newSymbols.get(i).sym.equals(oldSymbol)) |
|
276 |
newSymbols.get(i).sym = newSymbol; |
|
277 |
} |
|
278 |
|
|
279 |
fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(oldSymbol,newSymbol)); |
|
280 |
} |
|
281 |
|
|
282 |
|
|
283 |
public String[] getDescriptions() { |
|
284 |
String[] descriptions = new String[newSymbols.size()]; |
|
285 |
ISymbol[] auxSym = getSymbols(); |
|
286 |
|
|
287 |
for (int i = 0; i < descriptions.length; i++) |
|
288 |
descriptions[i] = auxSym[i].getDescription(); |
|
289 |
|
|
290 |
return descriptions; |
|
291 |
} |
|
292 |
|
|
293 |
public ISymbol[] getSymbols() { |
|
294 |
|
|
295 |
if (newSymbols != null) { |
|
296 |
ISymbol[] mySymbols = new ISymbol[newSymbols.size()]; |
|
297 |
for (int i = 0; i < newSymbols.size(); i++) { |
|
298 |
mySymbols[i] = newSymbols.get(i).sym; |
|
299 |
} |
|
300 |
return mySymbols; |
|
301 |
} |
|
302 |
return null; |
|
303 |
} |
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
public ISymbol getDefaultSymbol() { |
|
308 |
if(defaultSymbol==null) { |
|
309 |
|
|
310 |
defaultSymbol = MapContextLocator.getSymbolManager( |
|
311 |
).createSymbol(shapeType); |
|
312 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null, defaultSymbol)); |
|
313 |
} |
|
314 |
return defaultSymbol; |
|
315 |
} |
|
316 |
|
|
317 |
|
|
318 |
public String getClassName() { |
|
319 |
return getClass().getName(); |
|
320 |
} |
|
321 |
|
|
322 |
|
|
323 |
public int getShapeType() { |
|
324 |
return shapeType; |
|
325 |
} |
|
326 |
|
|
327 |
public boolean isUseDefaultSymbol() { |
|
328 |
return useDefaultSymbol; |
|
329 |
} |
|
330 |
|
|
331 |
public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException { |
|
332 |
if (s == null) throw new NullPointerException("Default symbol cannot be null"); |
|
333 |
ISymbol old = defaultSymbol; |
|
334 |
defaultSymbol = s; |
|
335 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol)); |
|
336 |
} |
|
337 |
|
|
338 |
public void setShapeType(int shapeType) { |
|
339 |
if (this.shapeType != shapeType) { |
|
340 |
|
|
341 |
ISymbol sym = MapContextLocator.getSymbolManager( |
|
342 |
).createSymbol(shapeType); |
|
343 |
setDefaultSymbol(sym); |
|
344 |
this.shapeType = shapeType; |
|
345 |
} |
|
346 |
} |
|
347 |
|
|
348 |
public void useDefaultSymbol(boolean b) { |
|
349 |
useDefaultSymbol = b; |
|
350 |
} |
|
351 |
|
|
352 |
public Object[] getValues() { |
|
353 |
if (newSymbols != null) { |
|
354 |
Object[] myObjects = new Object[newSymbols.size()]; |
|
355 |
for (int i = 0; i < newSymbols.size(); i++) { |
|
356 |
myObjects[i] = newSymbols.get(i).getStringExpression(); |
|
357 |
} |
|
358 |
return myObjects; |
|
359 |
} |
|
360 |
return null; |
|
361 |
} |
|
362 |
|
|
363 |
public static boolean isPolygonal(int ty) { |
|
364 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
365 |
return geomManager.isSubtype(Geometry.TYPES.MULTISURFACE, ty) || |
|
366 |
geomManager.isSubtype(Geometry.TYPES.SURFACE, ty); |
|
367 |
} |
|
368 |
|
|
369 |
|
|
370 |
public static boolean isLinear(int ty) { |
|
371 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
372 |
return geomManager.isSubtype(Geometry.TYPES.MULTICURVE, ty) || |
|
373 |
geomManager.isSubtype(Geometry.TYPES.CURVE, ty); |
|
374 |
} |
|
375 |
|
|
376 |
public static boolean isPoint(int ty) { |
|
377 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
378 |
return geomManager.isSubtype(Geometry.TYPES.MULTIPOINT, ty) || |
|
379 |
geomManager.isSubtype(Geometry.TYPES.POINT, ty); |
|
380 |
} |
|
381 |
|
|
382 |
public void removeDefaultSymbol() { |
|
383 |
|
|
384 |
} |
|
385 |
|
|
386 |
// ============================= |
|
387 |
|
|
388 |
public static class RegisterPersistence implements Callable { |
|
389 |
|
|
390 |
public Object call() throws Exception { |
|
391 |
|
|
392 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
393 |
if (manager.getDefinition( |
|
394 |
FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) { |
|
395 |
DynStruct definition = manager |
|
396 |
.addDefinition(VectorFilterExpressionLegend.class, |
|
397 |
FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME, |
|
398 |
FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME |
|
399 |
+ " Persistence definition", null, null); |
|
400 |
|
|
401 |
definition.extend(manager.getDefinition( |
|
402 |
AbstractClassifiedVectorLegend |
|
403 |
.CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
|
404 |
|
|
405 |
definition.addDynFieldBoolean("useDefaultSymbol") |
|
406 |
.setMandatory(true); |
|
407 |
definition.addDynFieldObject("defaultSymbol") |
|
408 |
.setClassOfValue(ISymbol.class).setMandatory(true); |
|
409 |
definition.addDynFieldInt("shapeType") |
|
410 |
.setMandatory(true); |
|
411 |
|
|
412 |
definition.addDynFieldArray("itemSymbolArray") |
|
413 |
.setClassOfItems(ISymbol.class); |
|
414 |
definition.addDynFieldArray("itemStringArray") |
|
415 |
.setClassOfItems(String.class); |
|
416 |
|
|
417 |
} |
|
418 |
return Boolean.TRUE; |
|
419 |
} |
|
420 |
|
|
421 |
} |
|
422 |
|
|
423 |
public static class RegisterLegend implements Callable { |
|
424 |
|
|
425 |
public Object call() throws Exception { |
|
426 |
MapContextManager manager = |
|
427 |
MapContextLocator.getMapContextManager(); |
|
428 |
|
|
429 |
manager.registerLegend( |
|
430 |
FILTER_EXPRESSION_LEGEND_NAME, |
|
431 |
VectorFilterExpressionLegend.class); |
|
432 |
|
|
433 |
return Boolean.TRUE; |
|
434 |
} |
|
435 |
|
|
436 |
} |
|
437 |
|
|
438 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
439 |
|
|
440 |
super.saveToState(state); |
|
441 |
state.set("useDefaultSymbol", this.isUseDefaultSymbol()); |
|
442 |
state.set("defaultSymbol", this.getDefaultSymbol()); |
|
443 |
state.set("shapeType", this.getShapeType()); |
|
444 |
|
|
445 |
ISymbol[] syms = this.getSymbols(); |
|
446 |
if (syms == null) { |
|
447 |
syms = new ISymbol[0]; |
|
448 |
} |
|
449 |
Object[] vals = this.getValues(); |
|
450 |
String[] vals_str = null; |
|
451 |
if (vals == null) { |
|
452 |
vals_str = new String[0]; |
|
453 |
} else { |
|
454 |
vals_str = new String[vals.length]; |
|
455 |
for (int i=0; i<vals.length; i++) { |
|
456 |
String aux = ((vals[i] == null) ? null : vals[i].toString()); |
|
457 |
// Prevents saving localized version of 'Default' |
|
458 |
aux = translateDefault(aux, false); |
|
459 |
vals_str[i] = aux; |
|
460 |
} |
|
461 |
} |
|
462 |
|
|
463 |
state.set("itemSymbolArray", syms); |
|
464 |
state.set("itemStringArray", vals_str); |
|
465 |
|
|
466 |
} |
|
467 |
|
|
468 |
public void loadFromState(PersistentState state) |
|
469 |
throws PersistenceException { |
|
470 |
|
|
471 |
super.loadFromState(state); |
|
472 |
|
|
473 |
this.setShapeType(state.getInt("shapeType")); |
|
474 |
Boolean b = state.getBoolean("useDefaultSymbol"); |
|
475 |
this.useDefaultSymbol(b); |
|
476 |
ISymbol defsym = (ISymbol) state.get("defaultSymbol"); |
|
477 |
this.setDefaultSymbol(defsym); |
|
478 |
|
|
479 |
String[] strs = state.getStringArray("itemStringArray"); |
|
480 |
ISymbol[] syms = (ISymbol[]) state.getArray("itemSymbolArray", |
|
481 |
ISymbol.class); |
|
482 |
|
|
483 |
if (strs.length != syms.length) { |
|
484 |
logger.info("VectorFilterExpressionLegend - load state - Different size in arrays: " + strs.length + ", " + syms.length); |
|
485 |
} |
|
486 |
int nmin = Math.min(strs.length, syms.length); |
|
487 |
for (int i=0; i<nmin; i++) { |
|
488 |
String aux = strs[i]; |
|
489 |
aux = translateDefault(aux, true); |
|
490 |
this.addSymbol(aux, syms[i]); |
|
491 |
} |
|
492 |
} |
|
493 |
|
|
494 |
/** |
|
495 |
* Utility method to (un)translate the word 'Default' |
|
496 |
* @param aux |
|
497 |
* @param forward |
|
498 |
* If TRUE, then translate (Default -> Por defecto) |
|
499 |
* If FALSE then untranslate (Por defecto -> Default) |
|
500 |
* @return |
|
501 |
*/ |
|
502 |
private String translateDefault(String aux, boolean forward) { |
|
503 |
|
|
504 |
if (aux == null) { |
|
505 |
return null; |
|
506 |
} |
|
507 |
if (forward && aux.compareTo(NON_I18N_DEFAULT) == 0) { |
|
508 |
return I18N_DEFAULT; |
|
509 |
} |
|
510 |
if (!forward && aux.compareTo(I18N_DEFAULT) == 0) { |
|
511 |
return NON_I18N_DEFAULT; |
|
512 |
} |
|
513 |
return aux; |
|
514 |
} |
|
515 |
|
|
516 |
|
|
517 |
public Object clone() throws CloneNotSupportedException { |
|
518 |
|
|
519 |
VectorFilterExpressionLegend resp = |
|
520 |
(VectorFilterExpressionLegend) super.clone(); |
|
521 |
|
|
522 |
Object[] vals = this.getValues(); |
|
523 |
ISymbol[] syms = this.getSymbols(); |
|
524 |
if (vals != null && syms != null) { |
|
525 |
|
|
526 |
resp.resetItems(); |
|
527 |
|
|
528 |
int n = Math.min(vals.length, syms.length); |
|
529 |
for (int i=0; i<n; i++) { |
|
530 |
resp.addSymbol( |
|
531 |
vals[i], |
|
532 |
(ISymbol) syms[i].clone()); |
|
533 |
} |
|
534 |
} |
|
535 |
ISymbol sym = this.getDefaultSymbol(); |
|
536 |
sym = (ISymbol) sym.clone(); |
|
537 |
resp.setDefaultSymbol(sym); |
|
538 |
return resp; |
|
539 |
} |
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
} |
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.72/src/main/java/org/gvsig/symbology/gui/layerproperties/ExpressionSymbolPanel.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.gui.layerproperties; |
|
24 |
|
|
25 |
import java.awt.Dimension; |
|
26 |
import java.awt.GridBagConstraints; |
|
27 |
import java.awt.GridBagLayout; |
|
28 |
import java.awt.Insets; |
|
29 |
import java.awt.event.ActionEvent; |
|
30 |
import java.awt.event.ActionListener; |
|
31 |
|
|
32 |
import javax.swing.BorderFactory; |
|
33 |
import javax.swing.JOptionPane; |
|
34 |
import javax.swing.JPanel; |
|
35 |
import javax.swing.JScrollPane; |
|
36 |
import javax.swing.JTextArea; |
|
37 |
import javax.swing.ScrollPaneConstants; |
|
38 |
|
|
39 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
40 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
|
41 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
42 |
import org.gvsig.app.ApplicationLocator; |
|
43 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
|
44 |
import org.gvsig.fmap.dal.feature.Feature; |
|
45 |
import org.gvsig.fmap.geom.Geometry; |
|
46 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
47 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
48 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
|
49 |
import org.gvsig.i18n.Messages; |
|
50 |
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator; |
|
51 |
import org.gvsig.tools.evaluator.EvaluatorException; |
|
52 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
|
53 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
54 |
import org.gvsig.tools.swing.api.evaluator.ComponentSwingManager; |
|
55 |
import org.gvsig.tools.swing.api.evaluator.EvaluatorPanel; |
|
56 |
|
|
57 |
|
|
58 |
/** |
|
59 |
* This panel shows an expression creation panel (from the Tools |
|
60 |
* library) and shows a symbol preview panel with a description |
|
61 |
* so the user can associate a symbol to the expression (symbol |
|
62 |
* will be used if expression evaluates to TRUE) |
|
63 |
* |
|
64 |
* @see EvaluatorPanel |
|
65 |
* |
|
66 |
* |
|
67 |
* @author jldominguez |
|
68 |
* |
|
69 |
*/ |
|
70 |
public class ExpressionSymbolPanel extends JPanel |
|
71 |
implements ActionListener, IWindow { |
|
72 |
|
|
73 |
/** |
|
74 |
* |
|
75 |
*/ |
|
76 |
private static final long serialVersionUID = 6299256060002740452L; |
|
77 |
private Feature dummyFeature = null; |
|
78 |
private EvaluatorWithDescriptions evald = null; |
|
79 |
private int shptype = Geometry.TYPES.GEOMETRY; |
|
80 |
|
|
81 |
private JPanel symPanel = null; |
|
82 |
private JSymbolPreviewButton templateButton = null; |
|
83 |
private JTextArea descArea = null; |
|
84 |
private AcceptCancelPanel acPanel; |
|
85 |
private boolean okPressed = false; |
|
86 |
private WindowInfo winfo = null; |
|
87 |
|
|
88 |
private EvaluatorPanel evapa = null; |
|
89 |
|
|
90 |
public ExpressionSymbolPanel( |
|
91 |
Feature dummy_feat, EvaluatorWithDescriptions ed, int st, ISymbol sym) { |
|
92 |
|
|
93 |
dummyFeature = dummy_feat; |
|
94 |
evald = ed; |
|
95 |
shptype = st; |
|
96 |
|
|
97 |
initialize(sym); |
|
98 |
} |
|
99 |
|
|
100 |
private EvaluatorPanel getEvaluatorPanel() { |
|
101 |
if (evapa == null) { |
|
102 |
ComponentSwingManager esm = |
|
103 |
ToolsSwingLocator.getComponentSwingManager(); |
|
104 |
evapa = esm.getEvaluatorPanel( |
|
105 |
dummyFeature.getType(), |
|
106 |
evald); |
|
107 |
} |
|
108 |
return evapa; |
|
109 |
} |
|
110 |
|
|
111 |
public String getExpression() { |
|
112 |
return getEvaluatorPanel().getExpression(); |
|
113 |
} |
|
114 |
|
|
115 |
public ISymbol getSymbol() { |
|
116 |
ISymbol resp = getTemplateButton(null).getSymbol(); |
|
117 |
resp.setDescription(this.getDescArea(null).getText()); |
|
118 |
return resp; |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* |
|
123 |
*/ |
|
124 |
private void initialize(ISymbol sym) { |
|
125 |
|
|
126 |
this.setLayout(new GridBagLayout()); |
|
127 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
128 |
|
|
129 |
gbc.gridx = 0; |
|
130 |
gbc.gridy = 0; |
|
131 |
gbc.anchor = GridBagConstraints.CENTER; |
|
132 |
gbc.fill = GridBagConstraints.BOTH; |
|
133 |
gbc.weightx = 1; |
|
134 |
gbc.weighty = 1; |
|
135 |
this.add(getEvaluatorPanel(), gbc); |
|
136 |
gbc.gridy = 1; |
|
137 |
gbc.weighty = 0; |
|
138 |
this.add(getSymbolPanel(sym), gbc); |
|
139 |
gbc.gridy = 2; |
|
140 |
this.add(getAcceptCancel(), gbc); |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* @return |
|
145 |
*/ |
|
146 |
private JPanel getAcceptCancel() { |
|
147 |
|
|
148 |
if (acPanel == null) { |
|
149 |
acPanel = new AcceptCancelPanel(this, this); |
|
150 |
} |
|
151 |
return acPanel; |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* @return |
|
156 |
*/ |
|
157 |
private JPanel getSymbolPanel(ISymbol sym) { |
|
158 |
|
|
159 |
if (symPanel == null) { |
|
160 |
|
|
161 |
symPanel = new JPanel(); |
|
162 |
symPanel.setLayout(new GridBagLayout()); |
|
163 |
symPanel.setBorder(BorderFactory.createTitledBorder( |
|
164 |
Messages.getText("_Symbol_and_description"))); |
|
165 |
|
|
166 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
167 |
|
|
168 |
gbc.fill = GridBagConstraints.BOTH; |
|
169 |
gbc.anchor = GridBagConstraints.NORTHWEST; |
|
170 |
gbc.gridx = 0; |
|
171 |
gbc.gridy = 0; |
|
172 |
gbc.weightx = 0.2; |
|
173 |
gbc.weighty = 0; |
|
174 |
gbc.insets = new Insets(7, 7, 7, 7); |
|
175 |
symPanel.add(getTemplateButton(sym), gbc); |
|
176 |
|
|
177 |
gbc.gridx = 1; |
|
178 |
gbc.weightx = 0.8; |
|
179 |
|
|
180 |
JScrollPane scroll = new JScrollPane(getDescArea(sym)); |
|
181 |
scroll.setHorizontalScrollBarPolicy( |
|
182 |
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
183 |
scroll.setVerticalScrollBarPolicy( |
|
184 |
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); |
|
185 |
symPanel.add(scroll, gbc); |
|
186 |
} |
|
187 |
return symPanel; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* @return |
|
192 |
*/ |
|
193 |
private JTextArea getDescArea(ISymbol sym) { |
|
194 |
if (descArea == null) { |
|
195 |
|
|
196 |
descArea = new JTextArea(); |
|
197 |
descArea.setWrapStyleWord(true); |
|
198 |
descArea.setLineWrap(true); |
|
199 |
if (sym != null) { |
|
200 |
descArea.setText(sym.getDescription()); |
|
201 |
} |
|
202 |
} |
|
203 |
return descArea; |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* @return |
|
208 |
*/ |
|
209 |
private JSymbolPreviewButton getTemplateButton(ISymbol sym) { |
|
210 |
if (templateButton == null) { |
|
211 |
ISymbol inisym = sym; |
|
212 |
if (inisym == null) { |
|
213 |
inisym = MapContextLocator.getSymbolManager(). |
|
214 |
createSymbol(shptype); |
|
215 |
} |
|
216 |
templateButton = new JSymbolPreviewButton(inisym, shptype); |
|
217 |
templateButton.setPreferredSize(new Dimension(100, 35)); |
|
218 |
templateButton.setMinimumSize(new Dimension(100, 35)); |
|
219 |
} |
|
220 |
return templateButton; |
|
221 |
} |
|
222 |
|
|
223 |
/* (non-Javadoc) |
|
224 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) |
|
225 |
*/ |
|
226 |
public void actionPerformed(ActionEvent e) { |
|
227 |
|
|
228 |
if (e.getActionCommand().compareToIgnoreCase("ok") == 0) { |
|
229 |
|
|
230 |
Class<?> return_class = null; |
|
231 |
try { |
|
232 |
return_class = validateExpression(); |
|
233 |
} catch (EvaluatorException epe) { |
|
234 |
|
|
235 |
if (epe.getCause() instanceof ArithmeticException) { |
|
236 |
|
|
237 |
if (!userTolerates(epe)) { |
|
238 |
okPressed = false; |
|
239 |
return; |
|
240 |
} else { |
|
241 |
// User said ok |
|
242 |
okPressed = true; |
|
243 |
closeThis(); |
|
244 |
return; |
|
245 |
} |
|
246 |
|
|
247 |
} else { |
|
248 |
String detail = epe.getMessageStack(); |
|
249 |
ApplicationLocator.getManager().messageDialog( |
|
250 |
Messages.getText("incorrect_expression") |
|
251 |
+ "\n\n" + detail, |
|
252 |
Messages.getText("error"), |
|
253 |
JOptionPane.ERROR_MESSAGE); |
|
254 |
okPressed = false; |
|
255 |
return; |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
if (return_class != Boolean.class) { |
|
260 |
int usr_opt = JOptionPane.showConfirmDialog( |
|
261 |
this, |
|
262 |
Messages.getText("_Result_not_boolean_so_zero_empty_string_null_are_false_Continue_question"), |
|
263 |
Messages.getText("confirmation_dialog"), |
|
264 |
JOptionPane.YES_NO_OPTION); |
|
265 |
if (usr_opt == JOptionPane.NO_OPTION) { |
|
266 |
okPressed = false; |
|
267 |
return; |
|
268 |
} |
|
269 |
} |
|
270 |
okPressed = true; |
|
271 |
closeThis(); |
|
272 |
|
|
273 |
} else { |
|
274 |
if (e.getActionCommand().compareToIgnoreCase("cancel") == 0) { |
|
275 |
okPressed = false; |
|
276 |
closeThis(); |
|
277 |
} |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
|
|
282 |
/** |
|
283 |
* @param epe |
|
284 |
* @return |
|
285 |
*/ |
|
286 |
private boolean userTolerates(EvaluatorException epe) { |
|
287 |
|
|
288 |
String detail = Messages.getText( |
|
289 |
"_Expression_can_cause_arithmetic_issues_Continue_question"); |
|
290 |
detail = detail + "\n\nMessage: "; |
|
291 |
detail = detail + epe.getMessageStack(); |
|
292 |
|
|
293 |
int usr_opt = JOptionPane.showConfirmDialog( |
|
294 |
this, |
|
295 |
detail, |
|
296 |
Messages.getText("confirmation_dialog"), |
|
297 |
JOptionPane.YES_NO_OPTION); |
|
298 |
|
|
299 |
return usr_opt == JOptionPane.YES_OPTION; |
|
300 |
} |
|
301 |
|
|
302 |
/** |
|
303 |
* @return class of the return value |
|
304 |
*/ |
|
305 |
private Class<? extends Object> validateExpression() throws EvaluatorException { |
|
306 |
|
|
307 |
String expr = this.getExpression(); |
|
308 |
EvaluatorWithDescriptions evde = EvaluatorCreator.getEvaluator(expr); |
|
309 |
Object resp_class = null; |
|
310 |
|
|
311 |
try { |
|
312 |
/* |
|
313 |
* Try evaluate feature with default values |
|
314 |
*/ |
|
315 |
resp_class = evde.evaluate(dummyFeature.getEvaluatorData()); |
|
316 |
} catch (EvaluatorException e) { |
|
317 |
/* |
|
318 |
* Parse exception or field not found or |
|
319 |
* divison by zero, etc. |
|
320 |
* Malformed expression, not valid |
|
321 |
*/ |
|
322 |
throw e; |
|
323 |
} catch (Exception e) { |
|
324 |
/* |
|
325 |
* All other exceptions. |
|
326 |
* Should not happen often. |
|
327 |
* We assume a strange |
|
328 |
* exception (NPE, etc) and decide it's not a valid |
|
329 |
* expression |
|
330 |
* |
|
331 |
*/ |
|
332 |
throw new EvaluatorException(e); |
|
333 |
} |
|
334 |
|
|
335 |
if (resp_class == null) { |
|
336 |
return null; |
|
337 |
} else { |
|
338 |
return resp_class.getClass(); |
|
339 |
} |
|
340 |
} |
|
341 |
|
|
342 |
private void closeThis() { |
|
343 |
MDIManager mm = ApplicationLocator.getManager().getUIManager(); |
|
344 |
mm.closeWindow(this); |
|
345 |
} |
|
346 |
|
|
347 |
public boolean isOkPressed() { |
|
348 |
return okPressed; |
|
349 |
} |
|
350 |
|
|
351 |
/* (non-Javadoc) |
|
352 |
* @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowInfo() |
|
353 |
*/ |
|
354 |
public WindowInfo getWindowInfo() { |
|
355 |
if (winfo == null) { |
|
356 |
winfo = new WindowInfo( |
|
357 |
WindowInfo.MODALDIALOG | |
|
358 |
WindowInfo.RESIZABLE); |
|
359 |
|
|
360 |
winfo.setTitle(Messages.getText("expression_creator")); |
|
361 |
winfo.setWidth(675); |
|
362 |
winfo.setHeight(400); |
|
363 |
} |
|
364 |
return winfo; |
|
365 |
} |
|
366 |
|
|
367 |
/* (non-Javadoc) |
|
368 |
* @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowProfile() |
|
369 |
*/ |
|
370 |
public Object getWindowProfile() { |
|
371 |
return WindowInfo.DIALOG_PROFILE; |
|
372 |
} |
|
373 |
|
|
374 |
} |
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.72/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanel.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib��ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
package org.gvsig.symbology.gui.layerproperties; |
|
42 |
|
|
43 |
import java.awt.BorderLayout; |
|
44 |
import java.awt.Dimension; |
|
45 |
import java.awt.event.ActionEvent; |
|
46 |
import java.awt.event.ActionListener; |
|
47 |
import java.io.File; |
|
48 |
import java.io.IOException; |
|
49 |
import java.util.ArrayList; |
|
50 |
import java.util.List; |
|
51 |
|
|
52 |
import javax.swing.BoxLayout; |
|
53 |
import javax.swing.ImageIcon; |
|
54 |
import javax.swing.JButton; |
|
55 |
import javax.swing.JCheckBox; |
|
56 |
import javax.swing.JOptionPane; |
|
57 |
import javax.swing.JPanel; |
|
58 |
|
|
59 |
import org.slf4j.Logger; |
|
60 |
import org.slf4j.LoggerFactory; |
|
61 |
|
|
62 |
import org.gvsig.andami.IconThemeHelper; |
|
63 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
|
64 |
import org.gvsig.app.ApplicationLocator; |
|
65 |
import org.gvsig.app.project.documents.view.legend.gui.Categories; |
|
66 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
|
67 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
|
68 |
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable; |
|
69 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
70 |
import org.gvsig.fmap.dal.feature.Feature; |
|
71 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
72 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
73 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
74 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
75 |
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
|
76 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
77 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
78 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
79 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
|
80 |
import org.gvsig.gui.beans.swing.JBlank; |
|
81 |
import org.gvsig.i18n.Messages; |
|
82 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol; |
|
83 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle; |
|
84 |
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend; |
|
85 |
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator; |
|
86 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
|
87 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
88 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
|
89 |
|
|
90 |
/** |
|
91 |
* Implements the JPanel that shows the properties of a |
|
92 |
* VectorialFilterExpressionLegend |
|
93 |
* in order to allows the user to modify its characteristics |
|
94 |
* |
|
95 |
* @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es |
|
96 |
* |
|
97 |
*/ |
|
98 |
public class VectorFilterExpressionPanel extends JPanel |
|
99 |
implements ILegendPanel, ActionListener { |
|
100 |
|
|
101 |
private static final Logger logger = LoggerFactory.getLogger( |
|
102 |
VectorFilterExpressionPanel.class); |
|
103 |
|
|
104 |
private static final long serialVersionUID = -7187473609965942511L; |
|
105 |
private VectorFilterExpressionLegend theLegend; |
|
106 |
private VectorFilterExpressionLegend auxLegend; |
|
107 |
private ClassifiableVectorial layer; |
|
108 |
private PictureFillSymbol previewSymbol; |
|
109 |
private JPanel pnlCenter; |
|
110 |
private JPanel pnlMovBut; |
|
111 |
private SymbolTable symbolTable; |
|
112 |
private JButton btnAddExpression; |
|
113 |
private JButton btnModExpression; |
|
114 |
private JButton btnRemoveExpression; |
|
115 |
private JButton moveUp; |
|
116 |
private JButton moveDown; |
|
117 |
private int shapeType; |
|
118 |
protected JCheckBox chkdefaultvalues = null; |
|
119 |
protected JSymbolPreviewButton defaultSymbolPrev; |
|
120 |
private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel(); |
|
121 |
private UsabilitySwingManager usabilitySwingManager = ToolsSwingLocator.getUsabilitySwingManager(); |
|
122 |
|
|
123 |
/** |
|
124 |
* This is the default constructor |
|
125 |
*/ |
|
126 |
public VectorFilterExpressionPanel() { |
|
127 |
super(); |
|
128 |
initialize(); |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
/** |
|
133 |
* This method initializes this |
|
134 |
*/ |
|
135 |
private void initialize() { |
|
136 |
|
|
137 |
pnlCenter = new JPanel(); |
|
138 |
pnlCenter.setLayout(new BorderLayout()); |
|
139 |
|
|
140 |
JPanel pnlButtons = new JPanel(); |
|
141 |
btnAddExpression = usabilitySwingManager.createJButton( |
|
142 |
Messages.getText("new_filter_expression")); |
|
143 |
btnAddExpression.setActionCommand("NEW_EXPRESSION"); |
|
144 |
btnAddExpression.addActionListener(this); |
|
145 |
pnlButtons.add(btnAddExpression); |
|
146 |
|
|
147 |
btnModExpression = usabilitySwingManager.createJButton( |
|
148 |
Messages.getText("modify_filter_expression")); |
|
149 |
btnModExpression.setActionCommand("MODIFY_EXPRESSION"); |
|
150 |
btnModExpression.addActionListener(this); |
|
151 |
pnlButtons.add(btnModExpression); |
|
152 |
|
|
153 |
btnRemoveExpression = usabilitySwingManager.createJButton( |
|
154 |
Messages.getText("delete_filter_expression")); |
|
155 |
btnRemoveExpression.setActionCommand("REMOVE"); |
|
156 |
btnRemoveExpression.addActionListener(this); |
|
157 |
pnlButtons.add(btnRemoveExpression); |
|
158 |
defaultSymbolPanel.add(getChkDefaultvalues()); |
|
159 |
pnlCenter.add(defaultSymbolPanel,BorderLayout.NORTH); |
|
160 |
|
|
161 |
this.setLayout(new BorderLayout()); |
|
162 |
this.add(pnlCenter, BorderLayout.CENTER); |
|
163 |
this.add(pnlButtons, BorderLayout.SOUTH); |
|
164 |
|
|
165 |
|
|
166 |
} |
|
167 |
public void getDefaultSymbolPrev(int shapeType) { |
|
168 |
if(defaultSymbolPrev == null){ |
|
169 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType); |
|
170 |
defaultSymbolPrev.setPreferredSize(new Dimension(110,20)); |
|
171 |
defaultSymbolPanel.add(defaultSymbolPrev,null); |
|
172 |
} |
|
173 |
} |
|
174 |
|
|
175 |
public String getDescription() { |
|
176 |
return Messages.getText( |
|
177 |
"shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + "."; |
|
178 |
} |
|
179 |
|
|
180 |
public ISymbol getIconSymbol() { |
|
181 |
if (previewSymbol == null) { |
|
182 |
try { |
|
183 |
previewSymbol = new PictureFillSymbol(); |
|
184 |
previewSymbol.setImage( new File( |
|
185 |
this.getClass().getClassLoader(). |
|
186 |
getResource("images" + File.separator |
|
187 |
+ "legend" + File.separator |
|
188 |
+ "legend-overview-vectorial-unique-value.png"). |
|
189 |
getFile()).toURI().toURL()); |
|
190 |
previewSymbol.getMarkerFillProperties(). |
|
191 |
setFillStyle( |
|
192 |
IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL); |
|
193 |
} catch (IOException e) { |
|
194 |
return null; |
|
195 |
} |
|
196 |
} |
|
197 |
return previewSymbol; |
|
198 |
} |
|
199 |
|
|
200 |
public ILegend getLegend() { |
|
201 |
auxLegend.clear(); |
|
202 |
fillSymbolListFromTable(); |
|
203 |
|
|
204 |
theLegend = (VectorFilterExpressionLegend) auxLegend.cloneLegend(); |
|
205 |
if(defaultSymbolPrev.getSymbol() != null) |
|
206 |
theLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol()); |
|
207 |
|
|
208 |
theLegend.useDefaultSymbol(chkdefaultvalues.isSelected()); |
|
209 |
return theLegend; |
|
210 |
} |
|
211 |
/** |
|
212 |
* Fills the list of symbols of the legend |
|
213 |
* |
|
214 |
*/ |
|
215 |
private void fillSymbolListFromTable() { |
|
216 |
Object clave; |
|
217 |
ISymbol theSymbol; |
|
218 |
|
|
219 |
FLyrVect m = (FLyrVect) layer; |
|
220 |
try { |
|
221 |
|
|
222 |
if(auxLegend.getClassifyingFieldNames() != null) { |
|
223 |
String[] fNames= auxLegend.getClassifyingFieldNames(); |
|
224 |
int[] fieldTypes = new int[auxLegend.getClassifyingFieldNames().length]; |
|
225 |
|
|
226 |
FeatureStore fsto = (FeatureStore) m.getDataStore(); |
|
227 |
FeatureType fty = fsto.getDefaultFeatureType(); |
|
228 |
|
|
229 |
for (int i = 0; i < fNames.length; i++) { |
|
230 |
fieldTypes[i] = fty.getAttributeDescriptor(fNames[i]).getType(); |
|
231 |
} |
|
232 |
|
|
233 |
auxLegend.setClassifyingFieldTypes(fieldTypes); |
|
234 |
} |
|
235 |
} catch (Exception e) { |
|
236 |
|
|
237 |
} |
|
238 |
|
|
239 |
auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected()); |
|
240 |
|
|
241 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
|
242 |
clave = symbolTable.getFieldValue(row, 1); |
|
243 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0); |
|
244 |
theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2)); |
|
245 |
auxLegend.addSymbol(clave, theSymbol); |
|
246 |
} |
|
247 |
if(chkdefaultvalues.isSelected()){ |
|
248 |
if(defaultSymbolPrev.getSymbol() != null){ |
|
249 |
String description = VectorFilterExpressionLegend.I18N_DEFAULT; |
|
250 |
defaultSymbolPrev.getSymbol().setDescription(description); |
|
251 |
auxLegend.addSymbol( |
|
252 |
description, defaultSymbolPrev.getSymbol()); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
} |
|
257 |
|
|
258 |
public Class<VectorFilterExpressionLegend> getLegendClass() { |
|
259 |
return VectorFilterExpressionLegend.class; |
|
260 |
} |
|
261 |
|
|
262 |
public JPanel getPanel() { |
|
263 |
return this; |
|
264 |
} |
|
265 |
|
|
266 |
public Class<Categories> getParentClass() { |
|
267 |
return Categories.class; |
|
268 |
} |
|
269 |
|
|
270 |
public String getTitle() { |
|
271 |
return Messages.getText("expressions"); |
|
272 |
} |
|
273 |
|
|
274 |
public boolean isSuitableFor(FLayer layer) { |
|
275 |
FLyrVect lVect = (FLyrVect) layer; |
|
276 |
try { |
|
277 |
return |
|
278 |
VectorFilterExpressionLegend.isPoint(lVect.getShapeType()) |
|
279 |
|| |
|
280 |
VectorFilterExpressionLegend.isLinear(lVect.getShapeType()) |
|
281 |
|| |
|
282 |
VectorFilterExpressionLegend.isPolygonal(lVect.getShapeType()); |
|
283 |
} catch (Exception e) { |
|
284 |
return false; |
|
285 |
} |
|
286 |
|
|
287 |
} |
|
288 |
|
|
289 |
public void setData(FLayer lyr, ILegend legend) { |
|
290 |
this.layer = (ClassifiableVectorial) lyr; |
|
291 |
shapeType = 0; |
|
292 |
|
|
293 |
try { |
|
294 |
shapeType = this.layer.getGeometryType().getType(); |
|
295 |
} catch (ReadException e) { |
|
296 |
logger.info("Error while getting layer shp type", e); |
|
297 |
ApplicationLocator.getManager().message( |
|
298 |
Messages.getText("generating_intervals"), |
|
299 |
JOptionPane.ERROR_MESSAGE); |
|
300 |
} |
|
301 |
|
|
302 |
if (symbolTable != null) |
|
303 |
pnlCenter.remove(symbolTable); |
|
304 |
if (pnlMovBut != null) |
|
305 |
pnlCenter.remove(pnlMovBut); |
|
306 |
|
|
307 |
getDefaultSymbolPrev(shapeType); |
|
308 |
|
|
309 |
symbolTable = new SymbolTable(this, "expressions", shapeType); |
|
310 |
pnlCenter.add(symbolTable, BorderLayout.CENTER); |
|
311 |
pnlCenter.add(getPnlMovBut(),BorderLayout.EAST); |
|
312 |
|
|
313 |
|
|
314 |
if (legend instanceof VectorFilterExpressionLegend) { |
|
315 |
|
|
316 |
auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend(); |
|
317 |
if (auxLegend.isUseDefaultSymbol()) { |
|
318 |
// Default must not be in table |
|
319 |
fillTableSkipDefault(auxLegend); |
|
320 |
} else { |
|
321 |
symbolTable.fillTableFromSymbolList( |
|
322 |
auxLegend.getSymbols(), |
|
323 |
auxLegend.getValues(), |
|
324 |
auxLegend.getDescriptions()); |
|
325 |
} |
|
326 |
|
|
327 |
|
|
328 |
} else { |
|
329 |
auxLegend = new VectorFilterExpressionLegend(); |
|
330 |
auxLegend.setShapeType(shapeType); |
|
331 |
} |
|
332 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
|
333 |
getChkDefaultvalues().setSelected(auxLegend.isUseDefaultSymbol()); |
|
334 |
} |
|
335 |
|
|
336 |
private JPanel getPnlMovBut() { |
|
337 |
if(pnlMovBut == null){ |
|
338 |
pnlMovBut = new JPanel(); |
|
339 |
pnlMovBut.setLayout(new BoxLayout(pnlMovBut, BoxLayout.Y_AXIS)); |
|
340 |
pnlMovBut.add(new JBlank(1, 70)); |
|
341 |
ImageIcon ico = IconThemeHelper.getImageIcon( |
|
342 |
"symbol-layer-move-up"); |
|
343 |
moveUp = usabilitySwingManager.createJButton(ico); |
|
344 |
pnlMovBut.add(moveUp); |
|
345 |
moveUp.setSize(new Dimension(15,15)); |
|
346 |
pnlMovBut.add(new JBlank(1,10)); |
|
347 |
ico = IconThemeHelper.getImageIcon( |
|
348 |
"symbol-layer-move-down"); |
|
349 |
moveDown = usabilitySwingManager.createJButton(ico); |
|
350 |
pnlMovBut.add(moveDown); |
|
351 |
pnlMovBut.add(new JBlank(1, 70)); |
|
352 |
moveDown.setActionCommand("MOVE-DOWN"); |
|
353 |
moveUp.setActionCommand("MOVE-UP"); |
|
354 |
moveDown.addActionListener(this); |
|
355 |
moveUp.addActionListener(this); |
|
356 |
} |
|
357 |
return pnlMovBut; |
|
358 |
} |
|
359 |
|
|
360 |
public void actionPerformed(ActionEvent e) { |
|
361 |
|
|
362 |
int[] indices = null; |
|
363 |
Feature dummyFeat = null; |
|
364 |
|
|
365 |
if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){ |
|
366 |
indices = symbolTable.getSelectedRows(); |
|
367 |
} |
|
368 |
|
|
369 |
if(e.getActionCommand() == "MOVE-UP"){ |
|
370 |
if (indices.length>0) { |
|
371 |
int classIndex = indices[0]; |
|
372 |
int targetPos = Math.max(0, classIndex-1); |
|
373 |
symbolTable.moveUpRows(classIndex, targetPos,indices.length); |
|
374 |
} |
|
375 |
} |
|
376 |
|
|
377 |
if(e.getActionCommand() == "MOVE-DOWN"){ |
|
378 |
if (indices.length>0) { |
|
379 |
int classIndex = indices[indices.length-1]; |
|
380 |
int targetPos = Math.min(symbolTable.getRowCount()-1, classIndex+1); |
|
381 |
symbolTable.moveDownRows(classIndex, targetPos,indices.length); |
|
382 |
} |
|
383 |
} |
|
384 |
|
|
385 |
if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){ |
|
386 |
ArrayList<String> orders = new ArrayList<String>(); |
|
387 |
|
|
388 |
for (int i = 0; i < symbolTable.getRowCount(); i++) { |
|
389 |
orders.add(symbolTable.getFieldValue(i,1).toString()); |
|
390 |
} |
|
391 |
} |
|
392 |
if (e.getActionCommand() == "NEW_EXPRESSION") { |
|
393 |
|
|
394 |
FLyrVect vect = (FLyrVect) layer; |
|
395 |
FeatureStore fsto = (FeatureStore) vect.getDataStore(); |
|
396 |
FeatureType fty = null; |
|
397 |
int shptype = 0; |
|
398 |
|
|
399 |
try { |
|
400 |
fty = fsto.getDefaultFeatureType(); |
|
401 |
shptype = vect.getGeometryType().getType(); |
|
402 |
dummyFeat = fsto.createNewFeature(true); |
|
403 |
} catch (Exception exc) { |
|
404 |
logger.error(Messages.getText( |
|
405 |
"error_trying_to_access_to_the_layer"), exc); |
|
406 |
return; |
|
407 |
} |
|
408 |
|
|
409 |
EvaluatorWithDescriptions evalu = EvaluatorCreator.getEvaluator(""); |
|
410 |
MDIManager mm = ApplicationLocator.getManager().getUIManager(); |
|
411 |
|
|
412 |
ExpressionSymbolPanel esp = new ExpressionSymbolPanel( |
|
413 |
dummyFeat, evalu, shptype, null); |
|
414 |
mm.addCentredWindow(esp); |
|
415 |
|
|
416 |
/* |
|
417 |
* esp is modal |
|
418 |
*/ |
|
419 |
if (!esp.isOkPressed()) { |
|
420 |
return; |
|
421 |
} |
|
422 |
|
|
423 |
String expr = esp.getExpression(); |
|
424 |
if (expr == null || expr.length() == 0) { |
|
425 |
ApplicationLocator.getManager().messageDialog( |
|
426 |
Messages.getText("error_validating_filter_query"), |
|
427 |
Messages.getText("error"), |
|
428 |
JOptionPane.ERROR_MESSAGE); |
|
429 |
return; |
|
430 |
} |
|
431 |
|
|
432 |
ISymbol sym = esp.getSymbol(); |
|
433 |
// evalu = EvaluatorCreator.getEvaluator(expr); |
|
434 |
// Add all fields in the feature type |
|
435 |
this.addClassFieldNames(fty); |
|
436 |
|
Also available in: Unified diff