Revision 44263 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

View differences:

ViewTakeProjectionCodeElement.java
1 1
package org.gvsig.app.project.documents.view.expressionevaluator;
2 2

  
3
import java.util.Objects;
3 4
import org.cresques.cts.IProjection;
4 5
import org.gvsig.app.ApplicationLocator;
5 6
import org.gvsig.app.ApplicationManager;
......
7 8
import org.gvsig.app.project.documents.view.ViewManager;
8 9
import org.gvsig.expressionevaluator.swing.Element.SimpleElement;
9 10
import org.gvsig.expressionevaluator.swing.Element.ConstantElement;
11
import org.gvsig.expressionevaluator.swing.impl.Utils;
10 12
import org.gvsig.expressionevaluator.swing.spi.AbstractElement;
11 13
import org.gvsig.tools.ToolsLocator;
14
import org.gvsig.tools.i18n.I18nManager;
12 15

  
13 16
/**
14 17
 *
......
21 24
{
22 25
    public ViewTakeProjectionCodeElement() {
23 26
        super(
27
                "ViewTakeProjectionCode",
24 28
                ToolsLocator.getI18nManager().getTranslation("_Take_projection_code"), 
25 29
                "expressionbuilder-element-view-projection-code"
26 30
        );
27 31
    }
28 32

  
29
    @Override
30
    public Object getValue() {
33
    private IProjection getCurrentProjection() {
31 34
        ApplicationManager application = ApplicationLocator.getManager();
32
        ViewDocument viewDoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
35
        ViewDocument viewDoc = (ViewDocument) application.getActiveDocument(ViewDocument.class);
33 36
        if( viewDoc == null ) {
34 37
            return null;
35 38
        }
36 39
        IProjection proj = viewDoc.getMapContext().getProjection();
40
        return proj;
41
    }
42

  
43
    private Object getProjectionCode(IProjection proj) {
44
        if( proj == null ) {
45
            return 0;
46
        }
37 47
        String[] proj_s = proj.getAbrev().split(":");
38 48
        try {
39 49
            int code = Integer.parseInt(proj_s[1]);
......
43 53
        }
44 54
    }
45 55
    
56
    @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
            Object code = this.getProjectionCode(proj);
80
            html.append("<b>").append(i18n.getTranslation("_Value")).append("</b> ").append(Utils.repr(code)).append("</b>");
81
            html.append(" (").append(proj.getAbrev()).append(")<br>\n");
82
            html.append("<b>").append(i18n.getTranslation("_Type")).append("</b> ").append(code.getClass().getSimpleName()).append("<br>\n");
83
        }
84
        html.append("</html>\n");
85
        return html.toString();
86
    }
87

  
46 88
    
47
    
48 89
}

Also available in: Unified diff