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 / ViewTakeProjectionCodeElement.java @ 44644
History | View | Annotate | Download (3.2 KB)
1 | 44006 | jjdelcerro | package org.gvsig.app.project.documents.view.expressionevaluator; |
---|---|---|---|
2 | |||
3 | 44263 | jjdelcerro | import java.util.Objects; |
4 | 44006 | jjdelcerro | import org.cresques.cts.IProjection; |
5 | import org.gvsig.app.ApplicationLocator; |
||
6 | import org.gvsig.app.ApplicationManager; |
||
7 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
8 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
9 | import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
||
10 | 44006 | jjdelcerro | import org.gvsig.expressionevaluator.swing.Element.SimpleElement; |
11 | import org.gvsig.expressionevaluator.swing.Element.ConstantElement; |
||
12 | import org.gvsig.expressionevaluator.swing.spi.AbstractElement; |
||
13 | 44012 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
14 | 44263 | jjdelcerro | import org.gvsig.tools.i18n.I18nManager; |
15 | 44006 | jjdelcerro | |
16 | /**
|
||
17 | *
|
||
18 | * @author jjdelcerro
|
||
19 | */
|
||
20 | @SuppressWarnings("UseSpecificCatch") |
||
21 | public class ViewTakeProjectionCodeElement |
||
22 | extends AbstractElement
|
||
23 | implements SimpleElement, ConstantElement
|
||
24 | { |
||
25 | public ViewTakeProjectionCodeElement() {
|
||
26 | 44012 | jjdelcerro | super(
|
27 | 44263 | jjdelcerro | "ViewTakeProjectionCode",
|
28 | 44012 | jjdelcerro | ToolsLocator.getI18nManager().getTranslation("_Take_projection_code"),
|
29 | "expressionbuilder-element-view-projection-code"
|
||
30 | ); |
||
31 | 44006 | jjdelcerro | } |
32 | |||
33 | 44263 | jjdelcerro | private IProjection getCurrentProjection() {
|
34 | 44006 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
35 | 44263 | jjdelcerro | ViewDocument viewDoc = (ViewDocument) application.getActiveDocument(ViewDocument.class); |
36 | 44006 | jjdelcerro | if( viewDoc == null ) { |
37 | return null; |
||
38 | } |
||
39 | IProjection proj = viewDoc.getMapContext().getProjection(); |
||
40 | 44263 | jjdelcerro | return proj;
|
41 | } |
||
42 | |||
43 | private Object getProjectionCode(IProjection proj) { |
||
44 | if( proj == null ) { |
||
45 | return 0; |
||
46 | } |
||
47 | 44006 | jjdelcerro | String[] proj_s = proj.getAbrev().split(":"); |
48 | try {
|
||
49 | int code = Integer.parseInt(proj_s[1]); |
||
50 | return code;
|
||
51 | } catch(Exception ex) { |
||
52 | return proj_s[1]; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | 44263 | jjdelcerro | @Override
|
57 | public Object getValue() { |
||
58 | IProjection proj = this.getCurrentProjection();
|
||
59 | return this.getProjectionCode(proj); |
||
60 | } |
||
61 | |||
62 | @Override
|
||
63 | public String getRenderedValue() { |
||
64 | return Objects.toString(this.getValue(), "0"); |
||
65 | } |
||
66 | |||
67 | @Override
|
||
68 | public String getDescription() { |
||
69 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
70 | |||
71 | IProjection proj = this.getCurrentProjection();
|
||
72 | |||
73 | StringBuilder html = new StringBuilder(); |
||
74 | html.append("<html>\n");
|
||
75 | html.append("<b>").append(i18n.getTranslation("_Constant")).append("</b><br>\n<br>\n"); |
||
76 | if( proj == null ) { |
||
77 | html.append("<b>").append(i18n.getTranslation("_Value")).append("</b> NULL<br>\n"); |
||
78 | } else {
|
||
79 | 44644 | jjdelcerro | ExpressionEvaluatorManager expressionManager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager(); |
80 | 44263 | jjdelcerro | Object code = this.getProjectionCode(proj); |
81 | 44644 | jjdelcerro | html.append("<b>").append(i18n.getTranslation("_Value")).append("</b> ").append(expressionManager.getReprMethod(proj).repr(proj)).append("</b>"); |
82 | 44263 | jjdelcerro | html.append(" (").append(proj.getAbrev()).append(")<br>\n"); |
83 | html.append("<b>").append(i18n.getTranslation("_Type")).append("</b> ").append(code.getClass().getSimpleName()).append("<br>\n"); |
||
84 | } |
||
85 | html.append("</html>\n");
|
||
86 | return html.toString();
|
||
87 | } |
||
88 | |||
89 | 44006 | jjdelcerro | |
90 | } |