Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / BaseInformationBuilderWithGeometrySupport.java @ 43215

History | View | Annotate | Download (8.92 KB)

1 43171 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
25 43170 fdiaz
package org.gvsig.fmap.geom.jts;
26
27
import org.cresques.cts.ICRSFactory;
28
import org.cresques.cts.IProjection;
29
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.Geometry.DIMENSIONS;
32 43171 jjdelcerro
import org.gvsig.fmap.geom.InformationbuilderWithGeometrySupport;
33
import org.gvsig.fmap.geom.InformationbuilderWithGeometrySupport.EnvelopeElement;
34
import org.gvsig.fmap.geom.InformationbuilderWithGeometrySupport.PropertyElementWithGeometrySupport;
35
import org.gvsig.fmap.geom.InformationbuilderWithGeometrySupport.RawElementWithGeometrySupport;
36
import org.gvsig.fmap.geom.InformationbuilderWithGeometrySupport.TextElementWithGeometrySupport;
37 43170 fdiaz
import org.gvsig.fmap.geom.primitive.Envelope;
38 43171 jjdelcerro
import org.gvsig.tools.util.impl.BaseInformationBuilder;
39 43170 fdiaz
40
41 43171 jjdelcerro
public class BaseInformationBuilderWithGeometrySupport extends BaseInformationBuilder implements InformationbuilderWithGeometrySupport {
42 43170 fdiaz
43 43171 jjdelcerro
    protected class BaseRawElementWithGeometrySupport extends BaseRawElement implements RawElementWithGeometrySupport {
44 43170 fdiaz
45
        @Override
46 43171 jjdelcerro
        public RawElementWithGeometrySupport value(Geometry geom) {
47
            return (RawElementWithGeometrySupport) asWKT(this, geom);
48 43170 fdiaz
        }
49
50
        @Override
51 43171 jjdelcerro
        public RawElementWithGeometrySupport value(IProjection proj) {
52
            return (RawElementWithGeometrySupport) asAbrev(this, proj);
53 43170 fdiaz
        }
54
55
        @Override
56 43171 jjdelcerro
        public RawElementWithGeometrySupport valueAsWKT(IProjection proj) {
57
            return (RawElementWithGeometrySupport) asWKT(this, proj);
58 43170 fdiaz
        }
59
60
        @Override
61 43171 jjdelcerro
        public RawElementWithGeometrySupport value(Envelope env) {
62
            return (RawElementWithGeometrySupport) asWKT(this, env);
63 43170 fdiaz
        }
64
    }
65
66 43171 jjdelcerro
    protected class BaseTextElementWithGeometrySupport extends BaseTextElement implements TextElementWithGeometrySupport {
67 43170 fdiaz
68
        @Override
69 43171 jjdelcerro
        public TextElementWithGeometrySupport value(Geometry geom) {
70
            return (TextElementWithGeometrySupport) asWKT(this, geom);
71 43170 fdiaz
        }
72
73
        @Override
74 43171 jjdelcerro
        public TextElementWithGeometrySupport value(IProjection proj) {
75
            return (TextElementWithGeometrySupport) asAbrev(this, proj);
76 43170 fdiaz
        }
77
78
        @Override
79 43171 jjdelcerro
        public TextElementWithGeometrySupport valueAsWKT(IProjection proj) {
80
            return (TextElementWithGeometrySupport) asWKT(this, proj);
81 43170 fdiaz
        }
82
83
        @Override
84 43171 jjdelcerro
        public TextElementWithGeometrySupport value(Envelope env) {
85
            return (TextElementWithGeometrySupport) asWKT(this, env);
86 43170 fdiaz
        }
87
88
    }
89
90 43171 jjdelcerro
    protected class BasePropertyElementWithGeometrySupport extends BasePropertyElement implements PropertyElementWithGeometrySupport {
91
92 43170 fdiaz
        @Override
93 43171 jjdelcerro
        public PropertyElementWithGeometrySupport value(Geometry geom) {
94
            return (PropertyElementWithGeometrySupport) asWKT(this, geom);
95 43170 fdiaz
        }
96
97
        @Override
98 43171 jjdelcerro
        public PropertyElementWithGeometrySupport value(IProjection proj) {
99
            return (PropertyElementWithGeometrySupport) asWKT(this, proj);
100 43170 fdiaz
        }
101
102
        @Override
103 43171 jjdelcerro
        public PropertyElementWithGeometrySupport valueAsWKT(IProjection proj) {
104
            return (PropertyElementWithGeometrySupport) asWKT(this, proj);
105 43170 fdiaz
        }
106
107
        @Override
108 43171 jjdelcerro
        public PropertyElementWithGeometrySupport value(Envelope env) {
109
            return (PropertyElementWithGeometrySupport) asWKT(this, env);
110 43170 fdiaz
        }
111
    }
112
113 43171 jjdelcerro
    private class DefaultEnvelopeElement extends BaseRawElement implements EnvelopeElement {
114 43170 fdiaz
115 43171 jjdelcerro
        private Envelope env;
116 43170 fdiaz
117
        @Override
118
        public DefaultEnvelopeElement value(Envelope value) {
119 43171 jjdelcerro
            this.env = value;
120
            asWKT(this,value);
121 43170 fdiaz
            return this;
122
        }
123
124
        @Override
125
        public String build() {
126 43215 jjdelcerro
            if( env == null ) {
127
                return new BaseTextElementWithGeometrySupport().value("None").build();
128
            } else {
129
                PropertyElement p1 = new BasePropertyElementWithGeometrySupport();
130
                p1.labelkey("_upper_left_corner");
131
                p1.value("%+f, %+f", env.getMinimum(DIMENSIONS.X), env.getMaximum(DIMENSIONS.Y));
132
                p1.monospace();
133 43170 fdiaz
134 43215 jjdelcerro
                PropertyElement p2 = new BasePropertyElementWithGeometrySupport();
135
                p2.labelkey("_upper_right_corner");
136
                p2.value("%+f, %+f", env.getMaximum(DIMENSIONS.X), env.getMaximum(DIMENSIONS.Y));
137
                p2.monospace();
138 43170 fdiaz
139 43215 jjdelcerro
                PropertyElement p3 = new BasePropertyElementWithGeometrySupport();
140
                p3.labelkey("_lower_right_corner");
141
                p3.value("%+f, %+f", env.getMaximum(DIMENSIONS.X), env.getMinimum(DIMENSIONS.Y));
142
                p3.monospace();
143 43170 fdiaz
144 43215 jjdelcerro
                PropertyElement p4 = new BasePropertyElementWithGeometrySupport();
145
                p4.labelkey("_lower_left_corner");
146
                p4.value("%+f, %+f", env.getMinimum(DIMENSIONS.X), env.getMinimum(DIMENSIONS.Y));
147
                p4.monospace();
148 43170 fdiaz
149 43215 jjdelcerro
                return p1.build() + p2.build() + p3.build() + p4.build();
150
            }
151 43170 fdiaz
        }
152
153
    }
154
155 43171 jjdelcerro
    public BaseInformationBuilderWithGeometrySupport() {
156 43170 fdiaz
        super();
157
    }
158
159
    @Override
160 43171 jjdelcerro
    public PropertyElementWithGeometrySupport property() {
161
        PropertyElementWithGeometrySupport element = new BasePropertyElementWithGeometrySupport();
162 43170 fdiaz
        this.elements.add(element);
163
        return element;
164
    }
165
166
    @Override
167 43171 jjdelcerro
    public TextElementWithGeometrySupport text() {
168
        TextElementWithGeometrySupport element = new BaseTextElementWithGeometrySupport();
169 43170 fdiaz
        this.elements.add(element);
170
        return element;
171
    }
172
173
    @Override
174
    public EnvelopeElement envelope() {
175
        EnvelopeElement element = new DefaultEnvelopeElement();
176
        this.elements.add(element);
177
        return element;
178
    }
179
180
    @Override
181 43171 jjdelcerro
    public RawElementWithGeometrySupport raw() {
182
        RawElementWithGeometrySupport element = new BaseRawElementWithGeometrySupport();
183 43170 fdiaz
        this.elements.add(element);
184
        return element;
185
    }
186
187 43171 jjdelcerro
    @Override
188
    public InformationbuilderWithGeometrySupport backgroundColor(String color) {
189
        return (InformationbuilderWithGeometrySupport) super.backgroundColor(color);
190
    }
191
192
    @Override
193
    public InformationbuilderWithGeometrySupport backgroundColorTitle(String color) {
194
        return (InformationbuilderWithGeometrySupport) super.backgroundColorTitle(color);
195
    }
196
197
    @Override
198
    public InformationbuilderWithGeometrySupport backgroundColorPropertyLabel(String color) {
199
        return (InformationbuilderWithGeometrySupport) super.backgroundColorPropertyLabel(color);
200
    }
201
202
    @Override
203
    public InformationbuilderWithGeometrySupport backgroundColorPropertyValue1(String color) {
204
        return (InformationbuilderWithGeometrySupport) super.backgroundColorPropertyValue1(color);
205
    }
206
207
    @Override
208
    public InformationbuilderWithGeometrySupport backgroundColorPropertyValue2(String color) {
209
        return (InformationbuilderWithGeometrySupport) super.backgroundColorPropertyValue2(color);
210
    }
211
212
    protected Element asAbrev(Element e, IProjection proj) {
213
        if (proj == null) {
214
            return e.value("");
215
        }
216
        return e.value(proj.getAbrev());
217
    }
218
219
    protected Element asWKT(Element e, IProjection proj) {
220
        if (proj == null) {
221
            return e.value("");
222
        }
223
        String s = proj.export(ICRSFactory.FORMAT_WKT);
224
        if (s == null) {
225
            s = proj.export(ICRSFactory.FORMAT_WKT_ESRI);
226
        }
227
        if (s == null) {
228
            s = proj.export(ICRSFactory.FORMAT_PROJ4);
229
        }
230
        if (s == null) {
231
            s = proj.getAbrev();
232
        }
233
        if (s != null) {
234
            s = s.replaceAll("\\[", "[\n  ");
235
            s = s.replaceAll("]", "\n]");
236
        }
237
        return e.value(s);
238
    }
239
240
    protected Element asWKT(Element e, Envelope env) {
241
        if (env == null) {
242
            return e.value("");
243
        }
244
        return asWKT(e, env.getGeometry());
245
    }
246
247
    protected Element asWKT(Element e, Geometry geom) {
248
        String s = "";
249
        try {
250
            s = geom.convertToWKT();
251
        } catch (Exception ex) {
252
        }
253
        return e.value(s);
254
    }
255
256 43170 fdiaz
}