Revision 44129
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/ProjectSymbolTable.java | ||
---|---|---|
1 |
package org.gvsig.app.project; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Iterator; |
|
7 |
import java.util.Map; |
|
8 |
import java.util.Properties; |
|
9 |
import org.apache.commons.io.IOUtils; |
|
10 |
import org.apache.commons.lang3.Range; |
|
11 |
import org.cresques.cts.IProjection; |
|
12 |
import org.gvsig.app.ApplicationLocator; |
|
13 |
import org.gvsig.app.ApplicationManager; |
|
14 |
import org.gvsig.app.project.documents.Document; |
|
15 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
16 |
import org.gvsig.app.project.documents.view.ViewManager; |
|
17 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
18 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
19 |
import org.gvsig.expressionevaluator.Interpreter; |
|
20 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
21 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
|
22 |
import org.gvsig.fmap.crs.CRSFactory; |
|
23 |
import org.gvsig.fmap.dal.feature.Feature; |
|
24 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
25 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
26 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
27 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
28 |
import org.gvsig.fmap.geom.Geometry; |
|
29 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
30 |
import org.gvsig.fmap.geom.primitive.Point; |
|
31 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
32 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
33 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
34 |
import org.gvsig.fmap.mapcontrol.AreaAndPerimeterCalculator; |
|
35 |
import org.gvsig.temporarystorage.TemporaryStorageGroup; |
|
36 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
|
37 |
import org.gvsig.temporarystorage.TemporaryStorageManager; |
|
38 |
|
|
39 |
/** |
|
40 |
* |
|
41 |
* @author jjdelcerro |
|
42 |
*/ |
|
43 |
@SuppressWarnings("UseSpecificCatch") |
|
44 |
public class ProjectSymbolTable extends AbstractSymbolTable { |
|
45 |
|
|
46 |
private abstract class CachedValue<T> { |
|
47 |
|
|
48 |
T value = null; |
|
49 |
long lastAccess = 0; |
|
50 |
|
|
51 |
protected abstract void reload(); |
|
52 |
|
|
53 |
public boolean isExpired() { |
|
54 |
long now = System.currentTimeMillis(); |
|
55 |
return now - lastAccess > 3000; |
|
56 |
} |
|
57 |
|
|
58 |
public T get() { |
|
59 |
if (isExpired()) { |
|
60 |
reload(); |
|
61 |
} |
|
62 |
lastAccess = System.currentTimeMillis(); |
|
63 |
return value; |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
private class ProjectValue extends CachedValue<Project> { |
|
68 |
|
|
69 |
@Override |
|
70 |
protected void reload() { |
|
71 |
value = ProjectManager.getInstance().getCurrentProject(); |
|
72 |
} |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
private class CurrentViewValue extends CachedValue<ViewDocument> { |
|
77 |
|
|
78 |
@Override |
|
79 |
protected void reload() { |
|
80 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
81 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
|
82 |
value = viewdoc; |
|
83 |
} |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
private class CurrentViewEnvelopeValue extends CachedValue<Geometry> { |
|
88 |
|
|
89 |
@Override |
|
90 |
protected void reload() { |
|
91 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
92 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
|
93 |
if( viewdoc == null ) { |
|
94 |
value = null; |
|
95 |
return; |
|
96 |
} |
|
97 |
value = viewdoc.getMapContext().getViewPort().getEnvelope().getGeometry(); |
|
98 |
} |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
private class PropertiesValue extends CachedValue<Map<File, Properties>> { |
|
103 |
|
|
104 |
@Override |
|
105 |
protected void reload() { |
|
106 |
value = new HashMap<>(); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
private class CurrentProjectFunction extends AbstractFunction { |
|
111 |
|
|
112 |
public CurrentProjectFunction() { |
|
113 |
super( |
|
114 |
"Project", |
|
115 |
"project", |
|
116 |
Range.is(0), |
|
117 |
"Access to the current project loaded in gvSIG desktop.\n", |
|
118 |
"project()", |
|
119 |
null, |
|
120 |
"Project" |
|
121 |
); |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
126 |
return currentProject.get(); |
|
127 |
} |
|
128 |
|
|
129 |
} |
|
130 |
|
|
131 |
private class FirstSelectedFeatureFunction extends AbstractFunction { |
|
132 |
|
|
133 |
public FirstSelectedFeatureFunction() { |
|
134 |
super( |
|
135 |
"Project", |
|
136 |
"firstSelectedFeature", |
|
137 |
Range.between(3, 4), |
|
138 |
"Access to the first selected feature of the layer, and " |
|
139 |
+ "return the value of the attribute.", |
|
140 |
"firstSelectedFeature({{view}}, layer, attribute, defaulValue)", |
|
141 |
new String[]{ |
|
142 |
"view - String value with the name of a view", |
|
143 |
"layer - String value with the name of a layer in the indicated view", |
|
144 |
"attribute - String value with the name of the attribute in the indicated layer", |
|
145 |
"defaultValue - Optional. Value to use if the indicated " |
|
146 |
+ "attribute can not be accessed. For example, if the " |
|
147 |
+ "view or layer does not exist, or it does not have " |
|
148 |
+ "selected elements." |
|
149 |
}, |
|
150 |
"Object" |
|
151 |
); |
|
152 |
} |
|
153 |
|
|
154 |
@Override |
|
155 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
156 |
Object defaultValue = null; |
|
157 |
String viewName = getStr(args, 0); |
|
158 |
String layerName = getStr(args, 1); |
|
159 |
String attrName = getStr(args, 2); |
|
160 |
if (args.length == 4) { |
|
161 |
defaultValue = getObject(args, 3); |
|
162 |
} |
|
163 |
try { |
|
164 |
Project project = currentProject.get(); |
|
165 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
166 |
if (view == null) { |
|
167 |
return defaultValue; |
|
168 |
} |
|
169 |
FLayer layer = view.getLayer(layerName); |
|
170 |
if (!(layer instanceof FLyrVect)) { |
|
171 |
return defaultValue; |
|
172 |
} |
|
173 |
FeatureSelection selection = ((FLyrVect) layer).getFeatureStore().getFeatureSelection(); |
|
174 |
if (selection == null || selection.isEmpty()) { |
|
175 |
return defaultValue; |
|
176 |
} |
|
177 |
Feature feature = selection.first(); |
|
178 |
if (feature == null) { |
|
179 |
return defaultValue; |
|
180 |
} |
|
181 |
return feature.get(attrName); |
|
182 |
} catch (Exception ex) { |
|
183 |
return defaultValue; |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
} |
|
188 |
|
|
189 |
private class FirstFeatureFunction extends AbstractFunction { |
|
190 |
|
|
191 |
public FirstFeatureFunction() { |
|
192 |
super( |
|
193 |
"Project", |
|
194 |
"firstFeature", |
|
195 |
Range.between(3, 6), |
|
196 |
"Access to the first feature of the layer, and " |
|
197 |
+ "return the value of the attribute.", |
|
198 |
"firstFeature({{view}}, layer, attribute, filter, order, defaulValue)", |
|
199 |
new String[]{ |
|
200 |
"view - String value with the name of a view", |
|
201 |
"layer - String value with the name of a layer in the indicated view", |
|
202 |
"attribute - String value with the name of the attribute in the indicated layer", |
|
203 |
"filter - Optional. String value with a filter expression", |
|
204 |
"order - Optional. String value with the order. must be a string with the names of separate fields with commas", |
|
205 |
"defaultValue - Optional. Value to use if the indicated " |
|
206 |
+ "attribute can not be accessed. For example, if the " |
|
207 |
+ "view or layer does not exist." |
|
208 |
}, |
|
209 |
"Object" |
|
210 |
); |
|
211 |
} |
|
212 |
|
|
213 |
@Override |
|
214 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
215 |
Object defaultValue = null; |
|
216 |
String filter = null; |
|
217 |
String order = null; |
|
218 |
String viewName = getStr(args, 0); |
|
219 |
String layerName = getStr(args, 1); |
|
220 |
String attrName = getStr(args, 2); |
|
221 |
switch (args.length) { |
|
222 |
case 4: |
|
223 |
filter = getStr(args, 3); |
|
224 |
break; |
|
225 |
case 5: |
|
226 |
filter = getStr(args, 3); |
|
227 |
order = getStr(args, 4); |
|
228 |
break; |
|
229 |
case 6: |
|
230 |
filter = getStr(args, 3); |
|
231 |
order = getStr(args, 4); |
|
232 |
defaultValue = getObject(args, 6); |
|
233 |
break; |
|
234 |
} |
|
235 |
try { |
|
236 |
Project project = currentProject.get(); |
|
237 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
238 |
if (view == null) { |
|
239 |
return defaultValue; |
|
240 |
} |
|
241 |
FLayer layer = view.getLayer(layerName); |
|
242 |
if (!(layer instanceof FLyrVect)) { |
|
243 |
return defaultValue; |
|
244 |
} |
|
245 |
FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
|
246 |
FeatureSet set; |
|
247 |
if (filter == null && order == null) { |
|
248 |
set = store.getFeatureSet(); |
|
249 |
} else { |
|
250 |
FeatureQuery query = store.createFeatureQuery(); |
|
251 |
if (filter != null) { |
|
252 |
query.addFilter(filter); |
|
253 |
} |
|
254 |
if (order != null) { |
|
255 |
query.getOrder().add(order); |
|
256 |
} |
|
257 |
set = store.getFeatureSet(query); |
|
258 |
} |
|
259 |
Feature feature = set.first(); |
|
260 |
if (feature == null) { |
|
261 |
return defaultValue; |
|
262 |
} |
|
263 |
return feature.get(attrName); |
|
264 |
} catch (Exception ex) { |
|
265 |
return defaultValue; |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
269 |
} |
|
270 |
|
|
271 |
private class ViewFunction extends AbstractFunction { |
|
272 |
|
|
273 |
public ViewFunction() { |
|
274 |
super( |
|
275 |
"Project", |
|
276 |
"view", |
|
277 |
Range.is(1), |
|
278 |
"Access to the indicated view", |
|
279 |
"view({{viewName}})", |
|
280 |
new String[]{ |
|
281 |
"view - String value with the name of a view" |
|
282 |
}, |
|
283 |
"DocumentView" |
|
284 |
); |
|
285 |
} |
|
286 |
|
|
287 |
@Override |
|
288 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
289 |
String viewName = getStr(args, 0); |
|
290 |
Project project = currentProject.get(); |
|
291 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
292 |
return view; |
|
293 |
} |
|
294 |
|
|
295 |
} |
|
296 |
|
|
297 |
private class ViewBBoxFunction extends AbstractFunction { |
|
298 |
|
|
299 |
public ViewBBoxFunction() { |
|
300 |
super( |
|
301 |
"Project", |
|
302 |
"viewbbox", |
|
303 |
Range.is(0), |
|
304 |
"Return the BBox of the active view.", |
|
305 |
"viewbbox()", |
|
306 |
null, |
|
307 |
"Geometry" |
|
308 |
); |
|
309 |
} |
|
310 |
|
|
311 |
@Override |
|
312 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
313 |
return currentViewEnvelope.get(); |
|
314 |
} |
|
315 |
|
|
316 |
} |
|
317 |
|
|
318 |
|
|
319 |
private class SavedPointFunction extends AbstractFunction { |
|
320 |
|
|
321 |
public SavedPointFunction() { |
|
322 |
super( |
|
323 |
"Project", |
|
324 |
"savedpoint", |
|
325 |
Range.is(1), |
|
326 |
"Return the value of the saved point with the name indicated.\n" |
|
327 |
+ "If the named point do not exists return null.", |
|
328 |
"savedpoint({{name}})", |
|
329 |
new String[]{ |
|
330 |
"name - String value with the name of the point" |
|
331 |
}, |
|
332 |
"Geometry" |
|
333 |
); |
|
334 |
} |
|
335 |
|
|
336 |
@Override |
|
337 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
338 |
TemporaryStorageManager manager = TemporaryStorageLocator.getTemporaryStorageManager(); |
|
339 |
TemporaryStorageGroup storage = manager.create("Points",Point.class); |
|
340 |
Geometry value = (Geometry) storage.get(getStr(args, 0)); |
|
341 |
return value; |
|
342 |
} |
|
343 |
|
|
344 |
} |
|
345 |
|
|
346 |
private class AreaFunction extends AbstractFunction { |
|
347 |
|
|
348 |
public AreaFunction() { |
|
349 |
super( |
|
350 |
"Project", |
|
351 |
"Area", |
|
352 |
Range.between(2,3), |
|
353 |
"Calculate the area of the geometry in the indicated units", |
|
354 |
"Area({{geometry}}, \"m\")", |
|
355 |
new String[]{ |
|
356 |
"geometry - Geometry", |
|
357 |
"Projection - Optional. Projection of the geometry or a string with the projection name", |
|
358 |
"units - String value with the name the units to use" |
|
359 |
}, |
|
360 |
"Double" |
|
361 |
); |
|
362 |
} |
|
363 |
|
|
364 |
@Override |
|
365 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
366 |
int units = 0; |
|
367 |
IProjection proj = null; |
|
368 |
Geometry geom = getGeom(args, 0); |
|
369 |
switch( args.length ) { |
|
370 |
case 2: |
|
371 |
units = getUnits(args, 1); |
|
372 |
break; |
|
373 |
case 3: |
|
374 |
proj = getProjection(args, 1); |
|
375 |
units = getUnits(args, 2); |
|
376 |
break; |
|
377 |
} |
|
378 |
if (proj == null) { |
|
379 |
proj = geom.getProjection(); |
|
380 |
} |
|
381 |
AreaAndPerimeterCalculator calculator = new AreaAndPerimeterCalculator(); |
|
382 |
double area = calculator.area(geom, proj, units); |
|
383 |
return area; |
|
384 |
} |
|
385 |
} |
|
386 |
|
|
387 |
private class PerimeterFunction extends AbstractFunction { |
|
388 |
|
|
389 |
public PerimeterFunction() { |
|
390 |
super( |
|
391 |
"Project", |
|
392 |
"Perimeter", |
|
393 |
Range.between(2,3), |
|
394 |
"Calculate the perimeter of the geometry in the indicated units", |
|
395 |
"Perimeter({{geometry}}, \"m\")", |
|
396 |
new String[]{ |
|
397 |
"geometry - Geometry", |
|
398 |
"Projection - Optional. Projection of the geometry or a string with the projection name", |
|
399 |
"units - String value with the name the units to use" |
|
400 |
}, |
|
401 |
"Double" |
|
402 |
); |
|
403 |
} |
|
404 |
|
|
405 |
@Override |
|
406 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
407 |
int units = 0; |
|
408 |
IProjection proj = null; |
|
409 |
Geometry geom = getGeom(args, 0); |
|
410 |
switch( args.length ) { |
|
411 |
case 2: |
|
412 |
units = getUnits(args, 1); |
|
413 |
break; |
|
414 |
case 3: |
|
415 |
proj = getProjection(args, 1); |
|
416 |
units = getUnits(args, 2); |
|
417 |
break; |
|
418 |
} |
|
419 |
if (proj == null) { |
|
420 |
proj = geom.getProjection(); |
|
421 |
} |
|
422 |
AreaAndPerimeterCalculator calculator = new AreaAndPerimeterCalculator(); |
|
423 |
double area = calculator.perimeter(geom, proj, units); |
|
424 |
return area; |
|
425 |
} |
|
426 |
} |
|
427 |
|
|
428 |
private class PropertyFunction extends AbstractFunction { |
|
429 |
|
|
430 |
public PropertyFunction() { |
|
431 |
super( |
|
432 |
"Project", |
|
433 |
"property", |
|
434 |
Range.between(2, 3), |
|
435 |
"Access to a property value in a properties file. If the" |
|
436 |
+ "indicated filename is not absolute, access it relative" |
|
437 |
+ "to the project.", |
|
438 |
"property({{filename}}, name, defaultValue)", |
|
439 |
new String[]{ |
|
440 |
"filename - String value with the name of the properties file", |
|
441 |
"name - String value with the name of the property to retrieve from the file", |
|
442 |
"defaultValue - Optional. Default value if can't access the file or the property",}, |
|
443 |
"String" |
|
444 |
); |
|
445 |
} |
|
446 |
|
|
447 |
@Override |
|
448 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
449 |
String filename = getStr(args, 0); |
|
450 |
String name = getStr(args, 1); |
|
451 |
String defaultValue = null; |
|
452 |
if (args.length == 3) { |
|
453 |
defaultValue = getStr(args, 2); |
|
454 |
} |
|
455 |
|
|
456 |
File file = new File(filename); |
|
457 |
if (!file.isAbsolute()) { |
|
458 |
Project project = currentProject.get(); |
|
459 |
if (project.getFile() == null) { |
|
460 |
return defaultValue; |
|
461 |
} |
|
462 |
file = new File(project.getFile().getParent(), filename); |
|
463 |
} |
|
464 |
Map<File, Properties> x = propertiesFiles.get(); |
|
465 |
Properties properties = x.get(file); |
|
466 |
if (properties == null) { |
|
467 |
properties = new Properties(); |
|
468 |
FileInputStream in = null; |
|
469 |
try { |
|
470 |
in = new FileInputStream(file); |
|
471 |
properties.load(in); |
|
472 |
} catch (Exception ex) { |
|
473 |
return defaultValue; |
|
474 |
} finally { |
|
475 |
IOUtils.closeQuietly(in); |
|
476 |
} |
|
477 |
x.put(file, properties); |
|
478 |
} |
|
479 |
String value = properties.getProperty(name, defaultValue); |
|
480 |
return value; |
|
481 |
} |
|
482 |
|
|
483 |
} |
|
484 |
|
|
485 |
ProjectValue currentProject = new ProjectValue(); |
|
486 |
CurrentViewValue currentView = new CurrentViewValue(); |
|
487 |
CurrentViewEnvelopeValue currentViewEnvelope = new CurrentViewEnvelopeValue(); |
|
488 |
PropertiesValue propertiesFiles = new PropertiesValue(); |
|
489 |
|
|
490 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
491 |
public ProjectSymbolTable() { |
|
492 |
super("Project"); |
|
493 |
this.addFunction(new CurrentProjectFunction()); |
|
494 |
this.addFunction(new FirstSelectedFeatureFunction()); |
|
495 |
this.addFunction(new FirstFeatureFunction()); |
|
496 |
this.addFunction(new ViewFunction()); |
|
497 |
this.addFunction(new ViewBBoxFunction()); |
|
498 |
this.addFunction(new PropertyFunction()); |
|
499 |
this.addFunction(new AreaFunction()); |
|
500 |
this.addFunction(new PerimeterFunction()); |
|
501 |
this.addFunction(new SavedPointFunction()); |
|
502 |
} |
|
503 |
|
|
504 |
private MapContext getMapContext(Feature feature) { |
|
505 |
FeatureStore store = feature.getStore(); |
|
506 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
|
507 |
project.getDocuments(ViewManager.TYPENAME); |
|
508 |
for (Document document : project.getDocuments(ViewManager.TYPENAME)) { |
|
509 |
ViewDocument view = (ViewDocument) document; |
|
510 |
MapContext mapContext = view.getMapContext(); |
|
511 |
FLayer layer = getLayer(mapContext, store); |
|
512 |
if (layer != null) { |
|
513 |
return mapContext; |
|
514 |
} |
|
515 |
} |
|
516 |
return null; |
|
517 |
} |
|
518 |
|
|
519 |
private FLayer getLayer(MapContext mapContext, FeatureStore store) { |
|
520 |
Iterator<FLayer> it = mapContext.deepiterator(); |
|
521 |
while (it.hasNext()) { |
|
522 |
FLayer layer = it.next(); |
|
523 |
if (layer instanceof FLyrVect) { |
|
524 |
FeatureStore layer_store = ((FLyrVect) layer).getFeatureStore(); |
|
525 |
if (layer_store == store) { |
|
526 |
return layer; |
|
527 |
} |
|
528 |
} |
|
529 |
} |
|
530 |
return null; |
|
531 |
} |
|
532 |
|
|
533 |
private IProjection getProjection(Object[] args, int i) { |
|
534 |
Object value = args[i]; |
|
535 |
if (value == null) { |
|
536 |
return null; |
|
537 |
} |
|
538 |
if (value instanceof IProjection) { |
|
539 |
return (IProjection) value; |
|
540 |
} |
|
541 |
String code = value.toString(); |
|
542 |
return CRSFactory.getCRS(code); |
|
543 |
} |
|
544 |
|
|
545 |
private int getUnits(Object[] args, int i) { |
|
546 |
Object value = args[i]; |
|
547 |
if (value == null) { |
|
548 |
throw new IllegalArgumentException("Illegal unit value 'null'"); |
|
549 |
} |
|
550 |
if (value instanceof Number) { |
|
551 |
return ((Number) value).intValue(); |
|
552 |
} |
|
553 |
String name = value.toString(); |
|
554 |
String[] names = MapContext.getAreaAbbr(); |
|
555 |
for (int j = 0; j < names.length; j++) { |
|
556 |
if (name.equalsIgnoreCase(names[j])) { |
|
557 |
return j; |
|
558 |
} |
|
559 |
} |
|
560 |
names = MapContext.getAreaNames(); |
|
561 |
for (int j = 0; j < names.length; j++) { |
|
562 |
if (name.equalsIgnoreCase(names[j])) { |
|
563 |
return j; |
|
564 |
} |
|
565 |
} |
|
566 |
throw new IllegalArgumentException("Illegal unit name '" + name + "'"); |
|
567 |
} |
|
568 |
|
|
569 |
public static void selfRegister() { |
|
570 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
571 |
manager.registerSymbolTable(new ProjectSymbolTable(), true); |
|
572 |
} |
|
573 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/symboltables/ProjectSymbolTable.java | ||
---|---|---|
1 |
package org.gvsig.app.project.symboltables; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.Iterator; |
|
7 |
import java.util.Map; |
|
8 |
import java.util.Properties; |
|
9 |
import org.apache.commons.io.IOUtils; |
|
10 |
import org.apache.commons.lang3.Range; |
|
11 |
import org.cresques.cts.IProjection; |
|
12 |
import org.gvsig.app.ApplicationLocator; |
|
13 |
import org.gvsig.app.ApplicationManager; |
|
14 |
import org.gvsig.app.project.Project; |
|
15 |
import org.gvsig.app.project.ProjectManager; |
|
16 |
import org.gvsig.app.project.documents.Document; |
|
17 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
18 |
import org.gvsig.app.project.documents.view.ViewManager; |
|
19 |
import org.gvsig.expressionevaluator.Interpreter; |
|
20 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
21 |
import org.gvsig.expressionevaluator.spi.AbstractSymbolTable; |
|
22 |
import org.gvsig.fmap.crs.CRSFactory; |
|
23 |
import org.gvsig.fmap.dal.feature.Feature; |
|
24 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
25 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
26 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
27 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
28 |
import org.gvsig.fmap.geom.Geometry; |
|
29 |
import org.gvsig.fmap.geom.primitive.Point; |
|
30 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
31 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
32 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
33 |
import org.gvsig.fmap.mapcontrol.AreaAndPerimeterCalculator; |
|
34 |
import org.gvsig.temporarystorage.TemporaryStorageGroup; |
|
35 |
import org.gvsig.temporarystorage.TemporaryStorageLocator; |
|
36 |
import org.gvsig.temporarystorage.TemporaryStorageManager; |
|
37 |
|
|
38 |
/** |
|
39 |
* |
|
40 |
* @author jjdelcerro |
|
41 |
*/ |
|
42 |
@SuppressWarnings("UseSpecificCatch") |
|
43 |
public class ProjectSymbolTable extends AbstractSymbolTable { |
|
44 |
|
|
45 |
public static final String AREA_NAME = "AREA"; |
|
46 |
public static final String PERIMETER_NAME = "PERIMETER"; |
|
47 |
public static final String FIRSTLAYERFEATURE_NAME = "FirstLayerFeature"; |
|
48 |
|
|
49 |
static final String NAME = "Project"; |
|
50 |
|
|
51 |
private abstract class CachedValue<T> { |
|
52 |
|
|
53 |
T value = null; |
|
54 |
long lastAccess = 0; |
|
55 |
|
|
56 |
protected abstract void reload(); |
|
57 |
|
|
58 |
public boolean isExpired() { |
|
59 |
long now = System.currentTimeMillis(); |
|
60 |
return now - lastAccess > 3000; |
|
61 |
} |
|
62 |
|
|
63 |
public T get() { |
|
64 |
if (isExpired()) { |
|
65 |
reload(); |
|
66 |
} |
|
67 |
lastAccess = System.currentTimeMillis(); |
|
68 |
return value; |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
private class ProjectValue extends CachedValue<Project> { |
|
73 |
|
|
74 |
@Override |
|
75 |
protected void reload() { |
|
76 |
value = ProjectManager.getInstance().getCurrentProject(); |
|
77 |
} |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
private class CurrentViewValue extends CachedValue<ViewDocument> { |
|
82 |
|
|
83 |
@Override |
|
84 |
protected void reload() { |
|
85 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
86 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
|
87 |
value = viewdoc; |
|
88 |
} |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
private class CurrentViewEnvelopeValue extends CachedValue<Geometry> { |
|
93 |
|
|
94 |
@Override |
|
95 |
protected void reload() { |
|
96 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
97 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
|
98 |
if( viewdoc == null ) { |
|
99 |
value = null; |
|
100 |
return; |
|
101 |
} |
|
102 |
value = viewdoc.getMapContext().getViewPort().getEnvelope().getGeometry(); |
|
103 |
} |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
private class PropertiesValue extends CachedValue<Map<File, Properties>> { |
|
108 |
|
|
109 |
@Override |
|
110 |
protected void reload() { |
|
111 |
value = new HashMap<>(); |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
private class CurrentProjectFunction extends AbstractFunction { |
|
116 |
|
|
117 |
public CurrentProjectFunction() { |
|
118 |
super( |
|
119 |
"Project", |
|
120 |
"project", |
|
121 |
Range.is(0), |
|
122 |
"Access to the current project loaded in gvSIG desktop.\n", |
|
123 |
"project()", |
|
124 |
null, |
|
125 |
"Project" |
|
126 |
); |
|
127 |
} |
|
128 |
|
|
129 |
@Override |
|
130 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
131 |
return currentProject.get(); |
|
132 |
} |
|
133 |
|
|
134 |
} |
|
135 |
|
|
136 |
private class FirstSelectedFeatureFunction extends AbstractFunction { |
|
137 |
|
|
138 |
public FirstSelectedFeatureFunction() { |
|
139 |
super( |
|
140 |
"Project", |
|
141 |
"firstSelectedFeature", |
|
142 |
Range.between(3, 4), |
|
143 |
"Access to the first selected feature of the layer, and " |
|
144 |
+ "return the value of the attribute.", |
|
145 |
"firstSelectedFeature({{view}}, layer, attribute, defaulValue)", |
|
146 |
new String[]{ |
|
147 |
"view - String value with the name of a view", |
|
148 |
"layer - String value with the name of a layer in the indicated view", |
|
149 |
"attribute - String value with the name of the attribute in the indicated layer", |
|
150 |
"defaultValue - Optional. Value to use if the indicated " |
|
151 |
+ "attribute can not be accessed. For example, if the " |
|
152 |
+ "view or layer does not exist, or it does not have " |
|
153 |
+ "selected elements." |
|
154 |
}, |
|
155 |
"Object" |
|
156 |
); |
|
157 |
} |
|
158 |
|
|
159 |
@Override |
|
160 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
161 |
Object defaultValue = null; |
|
162 |
String viewName = getStr(args, 0); |
|
163 |
String layerName = getStr(args, 1); |
|
164 |
String attrName = getStr(args, 2); |
|
165 |
if (args.length == 4) { |
|
166 |
defaultValue = getObject(args, 3); |
|
167 |
} |
|
168 |
try { |
|
169 |
Project project = currentProject.get(); |
|
170 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
171 |
if (view == null) { |
|
172 |
return defaultValue; |
|
173 |
} |
|
174 |
FLayer layer = view.getLayer(layerName); |
|
175 |
if (!(layer instanceof FLyrVect)) { |
|
176 |
return defaultValue; |
|
177 |
} |
|
178 |
FeatureSelection selection = ((FLyrVect) layer).getFeatureStore().getFeatureSelection(); |
|
179 |
if (selection == null || selection.isEmpty()) { |
|
180 |
return defaultValue; |
|
181 |
} |
|
182 |
Feature feature = selection.first(); |
|
183 |
if (feature == null) { |
|
184 |
return defaultValue; |
|
185 |
} |
|
186 |
return feature.get(attrName); |
|
187 |
} catch (Exception ex) { |
|
188 |
return defaultValue; |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
} |
|
193 |
|
|
194 |
private class FirstLayerFeatureFunction extends AbstractFunction { |
|
195 |
|
|
196 |
public FirstLayerFeatureFunction() { |
|
197 |
super( |
|
198 |
"Project", |
|
199 |
FIRSTLAYERFEATURE_NAME, |
|
200 |
Range.between(3, 6), |
|
201 |
"Access to the first feature of the layer, and " |
|
202 |
+ "return the value of the attribute.", |
|
203 |
FIRSTLAYERFEATURE_NAME+"({{view}}, layer, attribute, filter, order, defaulValue)", |
|
204 |
new String[]{ |
|
205 |
"view - String value with the name of a view", |
|
206 |
"layer - String value with the name of a layer in the indicated view", |
|
207 |
"attribute - String value with the name of the attribute in the indicated layer", |
|
208 |
"filter - Optional. String value with a filter expression", |
|
209 |
"order - Optional. String value with the order. must be a string with the names of separate fields with commas", |
|
210 |
"defaultValue - Optional. Value to use if the indicated " |
|
211 |
+ "attribute can not be accessed. For example, if the " |
|
212 |
+ "view or layer does not exist." |
|
213 |
}, |
|
214 |
"Object" |
|
215 |
); |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
220 |
Object defaultValue = null; |
|
221 |
String filter = null; |
|
222 |
String order = null; |
|
223 |
String viewName = getStr(args, 0); |
|
224 |
String layerName = getStr(args, 1); |
|
225 |
String attrName = getStr(args, 2); |
|
226 |
switch (args.length) { |
|
227 |
case 4: |
|
228 |
filter = getStr(args, 3); |
|
229 |
break; |
|
230 |
case 5: |
|
231 |
filter = getStr(args, 3); |
|
232 |
order = getStr(args, 4); |
|
233 |
break; |
|
234 |
case 6: |
|
235 |
filter = getStr(args, 3); |
|
236 |
order = getStr(args, 4); |
|
237 |
defaultValue = getObject(args, 6); |
|
238 |
break; |
|
239 |
} |
|
240 |
try { |
|
241 |
Project project = currentProject.get(); |
|
242 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
243 |
if (view == null) { |
|
244 |
return defaultValue; |
|
245 |
} |
|
246 |
FLayer layer = view.getLayer(layerName); |
|
247 |
if (!(layer instanceof FLyrVect)) { |
|
248 |
return defaultValue; |
|
249 |
} |
|
250 |
FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
|
251 |
FeatureSet set; |
|
252 |
if (filter == null && order == null) { |
|
253 |
set = store.getFeatureSet(); |
|
254 |
} else { |
|
255 |
FeatureQuery query = store.createFeatureQuery(); |
|
256 |
if (filter != null) { |
|
257 |
query.addFilter(filter); |
|
258 |
} |
|
259 |
if (order != null) { |
|
260 |
query.getOrder().add(order); |
|
261 |
} |
|
262 |
query.retrievesAllAttributes(); |
|
263 |
set = store.getFeatureSet(query); |
|
264 |
} |
|
265 |
Feature feature = set.first(); |
|
266 |
if (feature == null) { |
|
267 |
return defaultValue; |
|
268 |
} |
|
269 |
return feature.get(attrName); |
|
270 |
} catch (Exception ex) { |
|
271 |
return defaultValue; |
|
272 |
} |
|
273 |
} |
|
274 |
|
|
275 |
} |
|
276 |
|
|
277 |
private class ViewFunction extends AbstractFunction { |
|
278 |
|
|
279 |
public ViewFunction() { |
|
280 |
super( |
|
281 |
"Project", |
|
282 |
"view", |
|
283 |
Range.is(1), |
|
284 |
"Access to the indicated view", |
|
285 |
"view({{viewName}})", |
|
286 |
new String[]{ |
|
287 |
"view - String value with the name of a view" |
|
288 |
}, |
|
289 |
"DocumentView" |
|
290 |
); |
|
291 |
} |
|
292 |
|
|
293 |
@Override |
|
294 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
295 |
String viewName = getStr(args, 0); |
|
296 |
Project project = currentProject.get(); |
|
297 |
ViewDocument view = (ViewDocument) project.getDocument(viewName, ViewManager.TYPENAME); |
|
298 |
return view; |
|
299 |
} |
|
300 |
|
|
301 |
} |
|
302 |
|
|
303 |
private class ViewBBoxFunction extends AbstractFunction { |
|
304 |
|
|
305 |
public ViewBBoxFunction() { |
|
306 |
super( |
|
307 |
"Project", |
|
308 |
"viewbbox", |
|
309 |
Range.is(0), |
|
310 |
"Return the BBox of the active view.", |
|
311 |
"viewbbox()", |
|
312 |
null, |
|
313 |
"Geometry" |
|
314 |
); |
|
315 |
} |
|
316 |
|
|
317 |
@Override |
|
318 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
319 |
return currentViewEnvelope.get(); |
|
320 |
} |
|
321 |
|
|
322 |
} |
|
323 |
|
|
324 |
|
|
325 |
private class SavedPointFunction extends AbstractFunction { |
|
326 |
|
|
327 |
public SavedPointFunction() { |
|
328 |
super( |
|
329 |
"Project", |
|
330 |
"savedpoint", |
|
331 |
Range.is(1), |
|
332 |
"Return the value of the saved point with the name indicated.\n" |
|
333 |
+ "If the named point do not exists return null.", |
|
334 |
"savedpoint({{name}})", |
|
335 |
new String[]{ |
|
336 |
"name - String value with the name of the point" |
|
337 |
}, |
|
338 |
"Geometry" |
|
339 |
); |
|
340 |
} |
|
341 |
|
|
342 |
@Override |
|
343 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
344 |
TemporaryStorageManager manager = TemporaryStorageLocator.getTemporaryStorageManager(); |
|
345 |
TemporaryStorageGroup storage = manager.create("Points",Point.class); |
|
346 |
Geometry value = (Geometry) storage.get(getStr(args, 0)); |
|
347 |
return value; |
|
348 |
} |
|
349 |
|
|
350 |
} |
|
351 |
|
|
352 |
private class AreaFunction extends AbstractFunction { |
|
353 |
|
|
354 |
public AreaFunction() { |
|
355 |
super( |
|
356 |
"Project", |
|
357 |
AREA_NAME, |
|
358 |
Range.between(2,3), |
|
359 |
"Calculate the area of the geometry in the indicated units", |
|
360 |
AREA_NAME+"({{geometry}}, 'm?')", |
|
361 |
new String[]{ |
|
362 |
"geometry - Geometry", |
|
363 |
"Projection - Optional. Projection of the geometry or a string with the projection name", |
|
364 |
"units - String value with the name the units to use" |
|
365 |
}, |
|
366 |
"Double" |
|
367 |
); |
|
368 |
} |
|
369 |
|
|
370 |
@Override |
|
371 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
372 |
int units = 0; |
|
373 |
IProjection proj = null; |
|
374 |
Geometry geom = getGeom(args, 0); |
|
375 |
switch( args.length ) { |
|
376 |
case 2: |
|
377 |
units = getUnits(args, 1); |
|
378 |
break; |
|
379 |
case 3: |
|
380 |
proj = getProjection(args, 1); |
|
381 |
units = getUnits(args, 2); |
|
382 |
break; |
|
383 |
} |
|
384 |
if (proj == null) { |
|
385 |
proj = geom.getProjection(); |
|
386 |
} |
|
387 |
AreaAndPerimeterCalculator calculator = new AreaAndPerimeterCalculator(); |
|
388 |
double area = calculator.area(geom, proj, units); |
|
389 |
return area; |
|
390 |
} |
|
391 |
} |
|
392 |
|
|
393 |
private class PerimeterFunction extends AbstractFunction { |
|
394 |
|
|
395 |
public PerimeterFunction() { |
|
396 |
super( |
|
397 |
"Project", |
|
398 |
PERIMETER_NAME, |
|
399 |
Range.between(2,3), |
|
400 |
"Calculate the perimeter of the geometry in the indicated units", |
|
401 |
PERIMETER_NAME+"({{geometry}}, 'm')", |
|
402 |
new String[]{ |
|
403 |
"geometry - Geometry", |
|
404 |
"Projection - Optional. Projection of the geometry or a string with the projection name", |
|
405 |
"units - String value with the name the units to use" |
|
406 |
}, |
|
407 |
"Double" |
|
408 |
); |
|
409 |
} |
|
410 |
|
|
411 |
@Override |
|
412 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
413 |
int units = 0; |
|
414 |
IProjection proj = null; |
|
415 |
Geometry geom = getGeom(args, 0); |
|
416 |
switch( args.length ) { |
|
417 |
case 2: |
|
418 |
units = getUnits(args, 1); |
|
419 |
break; |
|
420 |
case 3: |
|
421 |
proj = getProjection(args, 1); |
|
422 |
units = getUnits(args, 2); |
|
423 |
break; |
|
424 |
} |
|
425 |
if (proj == null) { |
|
426 |
proj = geom.getProjection(); |
|
427 |
} |
|
428 |
AreaAndPerimeterCalculator calculator = new AreaAndPerimeterCalculator(); |
|
429 |
double area = calculator.perimeter(geom, proj, units); |
|
430 |
return area; |
|
431 |
} |
|
432 |
} |
|
433 |
|
|
434 |
private class PropertyFunction extends AbstractFunction { |
|
435 |
|
|
436 |
public PropertyFunction() { |
|
437 |
super( |
|
438 |
"Project", |
|
439 |
"property", |
|
440 |
Range.between(2, 3), |
|
441 |
"Access to a property value in a properties file. If the" |
|
442 |
+ "indicated filename is not absolute, access it relative" |
|
443 |
+ "to the project.", |
|
444 |
"property({{filename}}, name, defaultValue)", |
|
445 |
new String[]{ |
|
446 |
"filename - String value with the name of the properties file", |
|
447 |
"name - String value with the name of the property to retrieve from the file", |
|
448 |
"defaultValue - Optional. Default value if can't access the file or the property",}, |
|
449 |
"String" |
|
450 |
); |
|
451 |
} |
|
452 |
|
|
453 |
@Override |
|
454 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
455 |
String filename = getStr(args, 0); |
|
456 |
String name = getStr(args, 1); |
|
457 |
String defaultValue = null; |
|
458 |
if (args.length == 3) { |
|
459 |
defaultValue = getStr(args, 2); |
|
460 |
} |
|
461 |
|
|
462 |
File file = new File(filename); |
|
463 |
if (!file.isAbsolute()) { |
|
464 |
Project project = currentProject.get(); |
|
465 |
if (project.getFile() == null) { |
|
466 |
return defaultValue; |
|
467 |
} |
|
468 |
file = new File(project.getFile().getParent(), filename); |
|
469 |
} |
|
470 |
Map<File, Properties> x = propertiesFiles.get(); |
|
471 |
Properties properties = x.get(file); |
|
472 |
if (properties == null) { |
|
473 |
properties = new Properties(); |
|
474 |
FileInputStream in = null; |
|
475 |
try { |
|
476 |
in = new FileInputStream(file); |
|
477 |
properties.load(in); |
|
478 |
} catch (Exception ex) { |
|
479 |
return defaultValue; |
|
480 |
} finally { |
|
481 |
IOUtils.closeQuietly(in); |
|
482 |
} |
|
483 |
x.put(file, properties); |
|
484 |
} |
|
485 |
String value = properties.getProperty(name, defaultValue); |
|
486 |
return value; |
|
487 |
} |
|
488 |
|
|
489 |
} |
|
490 |
|
|
491 |
ProjectValue currentProject = new ProjectValue(); |
|
492 |
CurrentViewValue currentView = new CurrentViewValue(); |
|
493 |
CurrentViewEnvelopeValue currentViewEnvelope = new CurrentViewEnvelopeValue(); |
|
494 |
PropertiesValue propertiesFiles = new PropertiesValue(); |
|
495 |
|
|
496 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
|
497 |
public ProjectSymbolTable() { |
|
498 |
super(NAME); |
|
499 |
this.addFunction(new CurrentProjectFunction()); |
|
500 |
this.addFunction(new FirstSelectedFeatureFunction()); |
|
501 |
this.addFunction(new FirstLayerFeatureFunction()); |
|
502 |
this.addFunction(new ViewFunction()); |
|
503 |
this.addFunction(new ViewBBoxFunction()); |
|
504 |
this.addFunction(new PropertyFunction()); |
|
505 |
this.addFunction(new AreaFunction()); |
|
506 |
this.addFunction(new PerimeterFunction()); |
|
507 |
this.addFunction(new SavedPointFunction()); |
|
508 |
} |
|
509 |
|
|
510 |
private MapContext getMapContext(Feature feature) { |
|
511 |
FeatureStore store = feature.getStore(); |
|
512 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
|
513 |
project.getDocuments(ViewManager.TYPENAME); |
|
514 |
for (Document document : project.getDocuments(ViewManager.TYPENAME)) { |
|
515 |
ViewDocument view = (ViewDocument) document; |
|
516 |
MapContext mapContext = view.getMapContext(); |
|
517 |
FLayer layer = getLayer(mapContext, store); |
|
518 |
if (layer != null) { |
|
519 |
return mapContext; |
|
520 |
} |
|
521 |
} |
|
522 |
return null; |
|
523 |
} |
|
524 |
|
|
525 |
private FLayer getLayer(MapContext mapContext, FeatureStore store) { |
|
526 |
Iterator<FLayer> it = mapContext.deepiterator(); |
|
527 |
while (it.hasNext()) { |
|
528 |
FLayer layer = it.next(); |
|
529 |
if (layer instanceof FLyrVect) { |
|
530 |
FeatureStore layer_store = ((FLyrVect) layer).getFeatureStore(); |
|
531 |
if (layer_store == store) { |
|
532 |
return layer; |
|
533 |
} |
|
534 |
} |
|
535 |
} |
|
536 |
return null; |
|
537 |
} |
|
538 |
|
|
539 |
private IProjection getProjection(Object[] args, int i) { |
|
540 |
Object value = args[i]; |
|
541 |
if (value == null) { |
|
542 |
return null; |
|
543 |
} |
|
544 |
if (value instanceof IProjection) { |
|
545 |
return (IProjection) value; |
|
546 |
} |
|
547 |
String code = value.toString(); |
|
548 |
return CRSFactory.getCRS(code); |
|
549 |
} |
|
550 |
|
|
551 |
private int getUnits(Object[] args, int i) { |
|
552 |
Object value = args[i]; |
|
553 |
if (value == null) { |
|
554 |
throw new IllegalArgumentException("Illegal unit value 'null'"); |
|
555 |
} |
|
556 |
if (value instanceof Number) { |
|
557 |
return ((Number) value).intValue(); |
|
558 |
} |
|
559 |
String name = value.toString(); |
|
560 |
String[] names = MapContext.getAreaAbbr(); |
|
561 |
for (int j = 0; j < names.length; j++) { |
|
562 |
if (name.equalsIgnoreCase(names[j])) { |
|
563 |
return j; |
|
564 |
} |
|
565 |
} |
|
566 |
names = MapContext.getAreaNames(); |
|
567 |
for (int j = 0; j < names.length; j++) { |
|
568 |
if (name.equalsIgnoreCase(names[j])) { |
|
569 |
return j; |
|
570 |
} |
|
571 |
} |
|
572 |
throw new IllegalArgumentException("Illegal unit name '" + name + "'"); |
|
573 |
} |
|
574 |
|
|
575 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/symboltables/functionPanels/perimeter/PerimeterAditionalPanelView.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<object classname="com.jeta.forms.store.memento.FormPackage"> |
|
4 |
<at name="fileversion"> |
|
5 |
<object classname="com.jeta.forms.store.memento.FormsVersion2"> |
|
6 |
<at name="major">2</at> |
|
7 |
<at name="minor">0</at> |
|
8 |
<at name="sub">0</at> |
|
9 |
</object> |
|
10 |
</at> |
|
11 |
<at name="form"> |
|
12 |
<object classname="com.jeta.forms.store.memento.FormMemento"> |
|
13 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
14 |
<at name="cellconstraints"> |
|
15 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
16 |
<at name="column">1</at> |
|
17 |
<at name="row">1</at> |
|
18 |
<at name="colspan">1</at> |
|
19 |
<at name="rowspan">1</at> |
|
20 |
<at name="halign">default</at> |
|
21 |
<at name="valign">default</at> |
|
22 |
<at name="insets" object="insets">0,0,0,0</at> |
|
23 |
</object> |
|
24 |
</at> |
|
25 |
<at name="componentclass">com.jeta.forms.gui.form.FormComponent</at> |
|
26 |
</super> |
|
27 |
<at name="id">/home/jjdelcerro/datos/devel/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/symboltables/functionPanels/perimeter/PerimeterAditionalPanelView.xml</at> |
|
28 |
<at name="path">datos/devel/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/symboltables/functionPanels/perimeter/PerimeterAditionalPanelView.xml</at> |
|
29 |
<at name="rowspecs">CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE</at> |
|
30 |
<at name="colspecs">FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE</at> |
|
31 |
<at name="components"> |
|
32 |
<object classname="java.util.LinkedList"> |
|
33 |
<item > |
|
34 |
<at name="value"> |
|
35 |
<object classname="com.jeta.forms.store.memento.BeanMemento"> |
|
36 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
37 |
<at name="cellconstraints"> |
|
38 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
39 |
<at name="column">2</at> |
|
40 |
<at name="row">2</at> |
|
41 |
<at name="colspan">1</at> |
|
42 |
<at name="rowspan">1</at> |
|
43 |
<at name="halign">default</at> |
|
44 |
<at name="valign">default</at> |
|
45 |
<at name="insets" object="insets">0,0,0,0</at> |
|
46 |
</object> |
|
47 |
</at> |
|
48 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
|
49 |
</super> |
|
50 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
|
51 |
<at name="beanclass">com.jeta.forms.components.label.JETALabel</at> |
|
52 |
<at name="beanproperties"> |
|
53 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
|
54 |
<at name="classname">com.jeta.forms.components.label.JETALabel</at> |
|
55 |
<at name="properties"> |
|
56 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
|
57 |
<at name="border"> |
|
58 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
59 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
60 |
<at name="name">border</at> |
|
61 |
</super> |
|
62 |
<at name="borders"> |
|
63 |
<object classname="java.util.LinkedList"> |
|
64 |
<item > |
|
65 |
<at name="value"> |
|
66 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
67 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
68 |
<at name="name">border</at> |
|
69 |
</super> |
|
70 |
</object> |
|
71 |
</at> |
|
72 |
</item> |
|
73 |
</object> |
|
74 |
</at> |
|
75 |
</object> |
|
76 |
</at> |
|
77 |
<at name="name">lblTitle</at> |
|
78 |
<at name="width">997</at> |
|
79 |
<at name="text">_Perimeter</at> |
|
80 |
<at name="fill"> |
|
81 |
<object classname="com.jeta.forms.store.properties.effects.PaintProperty"> |
|
82 |
<at name="name">fill</at> |
|
83 |
</object> |
|
84 |
</at> |
|
85 |
<at name="font"> |
|
86 |
<object classname="com.jeta.forms.store.properties.FontProperty"> |
|
87 |
<at name="family">Dialog</at> |
|
88 |
<at name="style">1</at> |
|
89 |
<at name="size">11</at> |
|
90 |
</object> |
|
91 |
</at> |
|
92 |
<at name="height">14</at> |
|
93 |
</object> |
|
94 |
</at> |
|
95 |
</object> |
|
96 |
</at> |
|
97 |
</object> |
|
98 |
</at> |
|
99 |
</item> |
|
100 |
<item > |
|
101 |
<at name="value"> |
|
102 |
<object classname="com.jeta.forms.store.memento.BeanMemento"> |
|
103 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
104 |
<at name="cellconstraints"> |
|
105 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
106 |
<at name="column">2</at> |
|
107 |
<at name="row">8</at> |
|
108 |
<at name="colspan">1</at> |
|
109 |
<at name="rowspan">1</at> |
|
110 |
<at name="halign">default</at> |
|
111 |
<at name="valign">default</at> |
|
112 |
<at name="insets" object="insets">0,0,0,0</at> |
|
113 |
</object> |
|
114 |
</at> |
|
115 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
|
116 |
</super> |
|
117 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
|
118 |
<at name="beanclass">com.jeta.forms.components.label.JETALabel</at> |
|
119 |
<at name="beanproperties"> |
|
120 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
|
121 |
<at name="classname">com.jeta.forms.components.label.JETALabel</at> |
|
122 |
<at name="properties"> |
|
123 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
|
124 |
<at name="border"> |
|
125 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
126 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
127 |
<at name="name">border</at> |
|
128 |
</super> |
|
129 |
<at name="borders"> |
|
130 |
<object classname="java.util.LinkedList"> |
|
131 |
<item > |
|
132 |
<at name="value"> |
|
133 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
134 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
135 |
<at name="name">border</at> |
|
136 |
</super> |
|
137 |
</object> |
|
138 |
</at> |
|
139 |
</item> |
|
140 |
</object> |
|
141 |
</at> |
|
142 |
</object> |
|
143 |
</at> |
|
144 |
<at name="name">lblSelectUnits</at> |
|
145 |
<at name="width">997</at> |
|
146 |
<at name="text">_Select_units</at> |
|
147 |
<at name="fill"> |
|
148 |
<object classname="com.jeta.forms.store.properties.effects.PaintProperty"> |
|
149 |
<at name="name">fill</at> |
|
150 |
</object> |
|
151 |
</at> |
|
152 |
<at name="height">14</at> |
|
153 |
</object> |
|
154 |
</at> |
|
155 |
</object> |
|
156 |
</at> |
|
157 |
</object> |
|
158 |
</at> |
|
159 |
</item> |
|
160 |
<item > |
|
161 |
<at name="value"> |
|
162 |
<object classname="com.jeta.forms.store.memento.BeanMemento"> |
|
163 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
164 |
<at name="cellconstraints"> |
|
165 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
166 |
<at name="column">2</at> |
|
167 |
<at name="row">10</at> |
|
168 |
<at name="colspan">1</at> |
|
169 |
<at name="rowspan">1</at> |
|
170 |
<at name="halign">default</at> |
|
171 |
<at name="valign">default</at> |
|
172 |
<at name="insets" object="insets">0,0,0,0</at> |
|
173 |
</object> |
|
174 |
</at> |
|
175 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
|
176 |
</super> |
|
177 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
|
178 |
<at name="beanclass">javax.swing.JList</at> |
|
179 |
<at name="beanproperties"> |
|
180 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
|
181 |
<at name="classname">javax.swing.JList</at> |
|
182 |
<at name="properties"> |
|
183 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
|
184 |
<at name="border"> |
|
185 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
186 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
187 |
<at name="name">border</at> |
|
188 |
</super> |
|
189 |
<at name="borders"> |
|
190 |
<object classname="java.util.LinkedList"> |
|
191 |
<item > |
|
192 |
<at name="value"> |
|
193 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
194 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
195 |
<at name="name">border</at> |
|
196 |
</super> |
|
197 |
</object> |
|
198 |
</at> |
|
199 |
</item> |
|
200 |
</object> |
|
201 |
</at> |
|
202 |
</object> |
|
203 |
</at> |
|
204 |
<at name="scrollableTracksViewportHeight">true</at> |
|
205 |
<at name="scrollableTracksViewportWidth">true</at> |
|
206 |
<at name="name">lstUnits</at> |
|
207 |
<at name="width">995</at> |
|
208 |
<at name="items"> |
|
209 |
<object classname="com.jeta.forms.store.properties.ItemsProperty"> |
|
210 |
<at name="name">items</at> |
|
211 |
</object> |
|
212 |
</at> |
|
213 |
<at name="scollBars"> |
|
214 |
<object classname="com.jeta.forms.store.properties.ScrollBarsProperty"> |
|
215 |
<at name="name">scollBars</at> |
|
216 |
<at name="verticalpolicy">20</at> |
|
217 |
<at name="horizontalpolicy">30</at> |
|
218 |
<at name="border"> |
|
219 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
220 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
221 |
<at name="name">border</at> |
|
222 |
</super> |
|
223 |
<at name="borders"> |
|
224 |
<object classname="java.util.LinkedList"> |
|
225 |
<item > |
|
226 |
<at name="value"> |
|
227 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
228 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
229 |
<at name="name">border</at> |
|
230 |
</super> |
|
231 |
</object> |
|
232 |
</at> |
|
233 |
</item> |
|
234 |
</object> |
|
235 |
</at> |
|
236 |
</object> |
|
237 |
</at> |
|
238 |
</object> |
|
239 |
</at> |
|
240 |
<at name="height">363</at> |
|
241 |
</object> |
|
242 |
</at> |
|
243 |
</object> |
|
244 |
</at> |
|
245 |
</object> |
|
246 |
</at> |
|
247 |
</item> |
|
248 |
<item > |
|
249 |
<at name="value"> |
|
250 |
<object classname="com.jeta.forms.store.memento.BeanMemento"> |
|
251 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
252 |
<at name="cellconstraints"> |
|
253 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
254 |
<at name="column">2</at> |
|
255 |
<at name="row">4</at> |
|
256 |
<at name="colspan">1</at> |
|
257 |
<at name="rowspan">1</at> |
|
258 |
<at name="halign">default</at> |
|
259 |
<at name="valign">default</at> |
|
260 |
<at name="insets" object="insets">0,0,0,0</at> |
|
261 |
</object> |
|
262 |
</at> |
|
263 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
|
264 |
</super> |
|
265 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
|
266 |
<at name="beanclass">com.jeta.forms.components.label.JETALabel</at> |
|
267 |
<at name="beanproperties"> |
|
268 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
|
269 |
<at name="classname">com.jeta.forms.components.label.JETALabel</at> |
|
270 |
<at name="properties"> |
|
271 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
|
272 |
<at name="border"> |
|
273 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
274 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
275 |
<at name="name">border</at> |
|
276 |
</super> |
|
277 |
<at name="borders"> |
|
278 |
<object classname="java.util.LinkedList"> |
|
279 |
<item > |
|
280 |
<at name="value"> |
|
281 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
282 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
283 |
<at name="name">border</at> |
|
284 |
</super> |
|
285 |
</object> |
|
286 |
</at> |
|
287 |
</item> |
|
288 |
</object> |
|
289 |
</at> |
|
290 |
</object> |
|
291 |
</at> |
|
292 |
<at name="name">lblSelectField</at> |
|
293 |
<at name="width">997</at> |
|
294 |
<at name="text">_Select_field</at> |
|
295 |
<at name="fill"> |
|
296 |
<object classname="com.jeta.forms.store.properties.effects.PaintProperty"> |
|
297 |
<at name="name">fill</at> |
|
298 |
</object> |
|
299 |
</at> |
|
300 |
<at name="height">14</at> |
|
301 |
</object> |
|
302 |
</at> |
|
303 |
</object> |
|
304 |
</at> |
|
305 |
</object> |
|
306 |
</at> |
|
307 |
</item> |
|
308 |
<item > |
|
309 |
<at name="value"> |
|
310 |
<object classname="com.jeta.forms.store.memento.BeanMemento"> |
|
311 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
312 |
<at name="cellconstraints"> |
|
313 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
314 |
<at name="column">2</at> |
|
315 |
<at name="row">6</at> |
|
316 |
<at name="colspan">1</at> |
|
317 |
<at name="rowspan">1</at> |
|
318 |
<at name="halign">default</at> |
|
319 |
<at name="valign">default</at> |
|
320 |
<at name="insets" object="insets">0,0,0,0</at> |
|
321 |
</object> |
|
322 |
</at> |
|
323 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
|
324 |
</super> |
|
325 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
|
326 |
<at name="beanclass">javax.swing.JComboBox</at> |
|
327 |
<at name="beanproperties"> |
|
328 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
|
329 |
<at name="classname">javax.swing.JComboBox</at> |
|
330 |
<at name="properties"> |
|
331 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
|
332 |
<at name="border"> |
|
333 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
334 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
335 |
<at name="name">border</at> |
|
336 |
</super> |
|
337 |
<at name="borders"> |
|
338 |
<object classname="java.util.LinkedList"> |
Also available in: Unified diff