svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / expressionevaluator / viewcapturepoint / ViewCapturePointElement.java @ 44644
History | View | Annotate | Download (3.16 KB)
1 | 44190 | jjdelcerro | package org.gvsig.app.project.documents.view.expressionevaluator.viewcapturepoint; |
---|---|---|---|
2 | 44006 | jjdelcerro | |
3 | 44173 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
4 | import org.gvsig.app.ApplicationManager; |
||
5 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
6 | import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
||
7 | import org.gvsig.expressionevaluator.GeometryExpressionUtils; |
||
8 | 44006 | jjdelcerro | import org.gvsig.expressionevaluator.swing.Element.CalculatedElement; |
9 | import org.gvsig.expressionevaluator.swing.Element.SimpleElement; |
||
10 | 44129 | jjdelcerro | import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
11 | 44006 | jjdelcerro | import org.gvsig.expressionevaluator.swing.spi.AbstractElement; |
12 | import org.gvsig.fmap.geom.Geometry; |
||
13 | 44012 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
14 | 44006 | jjdelcerro | import org.gvsig.tools.swing.api.Component; |
15 | |||
16 | /**
|
||
17 | *
|
||
18 | * @author jjdelcerro
|
||
19 | */
|
||
20 | 44101 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
21 | 44006 | jjdelcerro | public class ViewCapturePointElement |
22 | extends AbstractElement
|
||
23 | 44101 | jjdelcerro | implements SimpleElement, CalculatedElement {
|
24 | |||
25 | 44006 | jjdelcerro | private ViewCapturePointPanel aditionalPanel;
|
26 | |||
27 | public ViewCapturePointElement() {
|
||
28 | 44012 | jjdelcerro | super(
|
29 | 44101 | jjdelcerro | ToolsLocator.getI18nManager().getTranslation("_Capture_point"),
|
30 | 44259 | jjdelcerro | null,
|
31 | 44012 | jjdelcerro | "expressionbuilder-element-view-capture-point"
|
32 | ); |
||
33 | 44006 | jjdelcerro | } |
34 | |||
35 | @Override
|
||
36 | public Object getValue() { |
||
37 | if (this.aditionalPanel == null) { |
||
38 | return null; |
||
39 | } |
||
40 | try {
|
||
41 | Geometry geom = this.aditionalPanel.getGeometry();
|
||
42 | if (geom == null) { |
||
43 | return null; |
||
44 | } |
||
45 | 44644 | jjdelcerro | GeometryExpressionBuilder builder = GeometryExpressionUtils.createExpressionBuilder(); |
46 | 44006 | jjdelcerro | if (this.aditionalPanel.insertAsWKT()) { |
47 | if (this.aditionalPanel.insertAsGeometry()) { |
||
48 | 44198 | jjdelcerro | builder.geometry_support_type(GeometrySupportType.WKT); |
49 | 44006 | jjdelcerro | return builder.geometry(geom, geom.getProjection()).toString();
|
50 | } else {
|
||
51 | String wkt = geom.convertToWKT();
|
||
52 | return "'" + wkt + "'"; |
||
53 | } |
||
54 | } else {
|
||
55 | if (this.aditionalPanel.insertAsGeometry()) { |
||
56 | 44198 | jjdelcerro | builder.geometry_support_type(GeometrySupportType.WKB); |
57 | 44006 | jjdelcerro | return builder.geometry(geom, geom.getProjection()).toString();
|
58 | } else {
|
||
59 | byte[] wkb = geom.convertToWKB(); |
||
60 | return builder.bytearray_hex(wkb);
|
||
61 | } |
||
62 | } |
||
63 | } catch (Exception ex) { |
||
64 | LOGGER.warn("Can't get point value.", ex);
|
||
65 | return null; |
||
66 | } |
||
67 | } |
||
68 | |||
69 | @Override
|
||
70 | 44543 | jjdelcerro | public String getRenderedValue() { |
71 | Object v = this.getValue(); |
||
72 | if( v == null ) { |
||
73 | return super.getRenderedValue(); |
||
74 | } |
||
75 | return v.toString();
|
||
76 | } |
||
77 | |||
78 | @Override
|
||
79 | 44129 | jjdelcerro | public Component getAditionalPanel(JExpressionBuilder expressionBuilder) { |
80 | 44006 | jjdelcerro | if (aditionalPanel == null) { |
81 | this.aditionalPanel = new ViewCapturePointPanel(); |
||
82 | } |
||
83 | return this.aditionalPanel; |
||
84 | } |
||
85 | 44543 | jjdelcerro | |
86 | 44101 | jjdelcerro | @Override
|
87 | public boolean isEnabled() { |
||
88 | 44173 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
89 | return ! application.getUIManager().isModalDialogShowing();
|
||
90 | 44101 | jjdelcerro | } |
91 | 44006 | jjdelcerro | } |