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
/**
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
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
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
import org.gvsig.fmap.geom.primitive.Envelope;
38
import org.gvsig.tools.util.impl.BaseInformationBuilder;
39

    
40

    
41
public class BaseInformationBuilderWithGeometrySupport extends BaseInformationBuilder implements InformationbuilderWithGeometrySupport {
42

    
43
    protected class BaseRawElementWithGeometrySupport extends BaseRawElement implements RawElementWithGeometrySupport {
44

    
45
        @Override
46
        public RawElementWithGeometrySupport value(Geometry geom) {
47
            return (RawElementWithGeometrySupport) asWKT(this, geom);
48
        }
49

    
50
        @Override
51
        public RawElementWithGeometrySupport value(IProjection proj) {
52
            return (RawElementWithGeometrySupport) asAbrev(this, proj);
53
        }
54

    
55
        @Override
56
        public RawElementWithGeometrySupport valueAsWKT(IProjection proj) {
57
            return (RawElementWithGeometrySupport) asWKT(this, proj);
58
        }
59

    
60
        @Override
61
        public RawElementWithGeometrySupport value(Envelope env) {
62
            return (RawElementWithGeometrySupport) asWKT(this, env);
63
        }
64
    }
65

    
66
    protected class BaseTextElementWithGeometrySupport extends BaseTextElement implements TextElementWithGeometrySupport {
67

    
68
        @Override
69
        public TextElementWithGeometrySupport value(Geometry geom) {
70
            return (TextElementWithGeometrySupport) asWKT(this, geom);
71
        }
72

    
73
        @Override
74
        public TextElementWithGeometrySupport value(IProjection proj) {
75
            return (TextElementWithGeometrySupport) asAbrev(this, proj);
76
        }
77

    
78
        @Override
79
        public TextElementWithGeometrySupport valueAsWKT(IProjection proj) {
80
            return (TextElementWithGeometrySupport) asWKT(this, proj);
81
        }
82

    
83
        @Override
84
        public TextElementWithGeometrySupport value(Envelope env) {
85
            return (TextElementWithGeometrySupport) asWKT(this, env);
86
        }
87

    
88
    }
89

    
90
    protected class BasePropertyElementWithGeometrySupport extends BasePropertyElement implements PropertyElementWithGeometrySupport {
91
        
92
        @Override
93
        public PropertyElementWithGeometrySupport value(Geometry geom) {
94
            return (PropertyElementWithGeometrySupport) asWKT(this, geom);
95
        }
96

    
97
        @Override
98
        public PropertyElementWithGeometrySupport value(IProjection proj) {
99
            return (PropertyElementWithGeometrySupport) asWKT(this, proj);
100
        }
101

    
102
        @Override
103
        public PropertyElementWithGeometrySupport valueAsWKT(IProjection proj) {
104
            return (PropertyElementWithGeometrySupport) asWKT(this, proj);
105
        }
106

    
107
        @Override
108
        public PropertyElementWithGeometrySupport value(Envelope env) {
109
            return (PropertyElementWithGeometrySupport) asWKT(this, env);
110
        }
111
    }
112

    
113
    private class DefaultEnvelopeElement extends BaseRawElement implements EnvelopeElement {
114

    
115
        private Envelope env;
116

    
117
        @Override
118
        public DefaultEnvelopeElement value(Envelope value) {
119
            this.env = value;
120
            asWKT(this,value);
121
            return this;
122
        }
123

    
124
        @Override
125
        public String build() {
126
            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

    
134
                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

    
139
                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

    
144
                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

    
149
                return p1.build() + p2.build() + p3.build() + p4.build();
150
            }
151
        }
152

    
153
    }
154

    
155
    public BaseInformationBuilderWithGeometrySupport() {
156
        super();
157
    }
158

    
159
    @Override
160
    public PropertyElementWithGeometrySupport property() {
161
        PropertyElementWithGeometrySupport element = new BasePropertyElementWithGeometrySupport();
162
        this.elements.add(element);
163
        return element;
164
    }
165

    
166
    @Override
167
    public TextElementWithGeometrySupport text() {
168
        TextElementWithGeometrySupport element = new BaseTextElementWithGeometrySupport();
169
        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
    public RawElementWithGeometrySupport raw() {
182
        RawElementWithGeometrySupport element = new BaseRawElementWithGeometrySupport();
183
        this.elements.add(element);
184
        return element;
185
    }
186

    
187
    @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
}