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 / viewcapturerectangle / ViewCaptureRectangleElement.java @ 44644
History | View | Annotate | Download (3.15 KB)
1 | 44190 | jjdelcerro | package org.gvsig.app.project.documents.view.expressionevaluator.viewcapturerectangle; |
---|---|---|---|
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.GeometryExpressionUtils; |
||
7 | import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
||
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 | @SuppressWarnings("UseSpecificCatch") |
||
21 | public class ViewCaptureRectangleElement |
||
22 | extends AbstractElement
|
||
23 | implements SimpleElement, CalculatedElement
|
||
24 | { |
||
25 | private ViewCaptureRectanglePanel aditionalPanel;
|
||
26 | |||
27 | public ViewCaptureRectangleElement() {
|
||
28 | 44012 | jjdelcerro | super(
|
29 | 44263 | jjdelcerro | "ViewCaptureRectangle",
|
30 | 44012 | jjdelcerro | ToolsLocator.getI18nManager().getTranslation("_Capture_rectangle"),
|
31 | "expressionbuilder-element-view-capture-bbox"
|
||
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 | return builder.geometry(geom).toString();
|
||
50 | 44006 | jjdelcerro | } 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 | return builder.geometry(geom).toString();
|
||
58 | 44006 | jjdelcerro | } 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 ViewCaptureRectanglePanel(); |
||
82 | } |
||
83 | return this.aditionalPanel; |
||
84 | } |
||
85 | 44101 | jjdelcerro | |
86 | 44173 | jjdelcerro | @Override
|
87 | 44101 | jjdelcerro | public boolean isEnabled() { |
88 | 44173 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
89 | return ! application.getUIManager().isModalDialogShowing();
|
||
90 | 44101 | jjdelcerro | } |
91 | |||
92 | 44006 | jjdelcerro | } |