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 @ 43171

History | View | Annotate | Download (8.7 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
            PropertyElement p1 = new BasePropertyElementWithGeometrySupport();
127
            p1.labelkey("_upper_left_corner");
128
            p1.value("%+f, %+f", env.getMinimum(DIMENSIONS.X), env.getMaximum(DIMENSIONS.Y));
129
            p1.monospace();
130

    
131
            PropertyElement p2 = new BasePropertyElementWithGeometrySupport();
132
            p2.labelkey("_upper_right_corner");
133
            p2.value("%+f, %+f", env.getMaximum(DIMENSIONS.X), env.getMaximum(DIMENSIONS.Y));
134
            p2.monospace();
135

    
136
            PropertyElement p3 = new BasePropertyElementWithGeometrySupport();
137
            p3.labelkey("_lower_right_corner");
138
            p3.value("%+f, %+f", env.getMaximum(DIMENSIONS.X), env.getMinimum(DIMENSIONS.Y));
139
            p3.monospace();
140

    
141
            PropertyElement p4 = new BasePropertyElementWithGeometrySupport();
142
            p4.labelkey("_lower_left_corner");
143
            p4.value("%+f, %+f", env.getMinimum(DIMENSIONS.X), env.getMinimum(DIMENSIONS.Y));
144
            p4.monospace();
145

    
146
            return p1.build() + p2.build() + p3.build() + p4.build();
147
        }
148

    
149
    }
150

    
151
    public BaseInformationBuilderWithGeometrySupport() {
152
        super();
153
    }
154

    
155
    @Override
156
    public PropertyElementWithGeometrySupport property() {
157
        PropertyElementWithGeometrySupport element = new BasePropertyElementWithGeometrySupport();
158
        this.elements.add(element);
159
        return element;
160
    }
161

    
162
    @Override
163
    public TextElementWithGeometrySupport text() {
164
        TextElementWithGeometrySupport element = new BaseTextElementWithGeometrySupport();
165
        this.elements.add(element);
166
        return element;
167
    }
168

    
169
    @Override
170
    public EnvelopeElement envelope() {
171
        EnvelopeElement element = new DefaultEnvelopeElement();
172
        this.elements.add(element);
173
        return element;
174
    }
175

    
176
    @Override
177
    public RawElementWithGeometrySupport raw() {
178
        RawElementWithGeometrySupport element = new BaseRawElementWithGeometrySupport();
179
        this.elements.add(element);
180
        return element;
181
    }
182

    
183
    @Override
184
    public InformationbuilderWithGeometrySupport backgroundColor(String color) {
185
        return (InformationbuilderWithGeometrySupport) super.backgroundColor(color); 
186
    }
187

    
188
    @Override
189
    public InformationbuilderWithGeometrySupport backgroundColorTitle(String color) {
190
        return (InformationbuilderWithGeometrySupport) super.backgroundColorTitle(color); 
191
    }
192

    
193
    @Override
194
    public InformationbuilderWithGeometrySupport backgroundColorPropertyLabel(String color) {
195
        return (InformationbuilderWithGeometrySupport) super.backgroundColorPropertyLabel(color); 
196
    }
197

    
198
    @Override
199
    public InformationbuilderWithGeometrySupport backgroundColorPropertyValue1(String color) {
200
        return (InformationbuilderWithGeometrySupport) super.backgroundColorPropertyValue1(color); 
201
    }
202
    
203
    @Override
204
    public InformationbuilderWithGeometrySupport backgroundColorPropertyValue2(String color) {
205
        return (InformationbuilderWithGeometrySupport) super.backgroundColorPropertyValue2(color); 
206
    }
207
    
208
    protected Element asAbrev(Element e, IProjection proj) {
209
        if (proj == null) {
210
            return e.value("");
211
        }
212
        return e.value(proj.getAbrev());
213
    }
214

    
215
    protected Element asWKT(Element e, IProjection proj) {
216
        if (proj == null) {
217
            return e.value("");
218
        }
219
        String s = proj.export(ICRSFactory.FORMAT_WKT);
220
        if (s == null) {
221
            s = proj.export(ICRSFactory.FORMAT_WKT_ESRI);
222
        }
223
        if (s == null) {
224
            s = proj.export(ICRSFactory.FORMAT_PROJ4);
225
        }
226
        if (s == null) {
227
            s = proj.getAbrev();
228
        }
229
        if (s != null) {
230
            s = s.replaceAll("\\[", "[\n  ");
231
            s = s.replaceAll("]", "\n]");
232
        }
233
        return e.value(s);
234
    }
235

    
236
    protected Element asWKT(Element e, Envelope env) {
237
        if (env == null) {
238
            return e.value("");
239
        }
240
        return asWKT(e, env.getGeometry());
241
    }
242

    
243
    protected Element asWKT(Element e, Geometry geom) {
244
        String s = "";
245
        try {
246
            s = geom.convertToWKT();
247
        } catch (Exception ex) {
248
        }
249
        return e.value(s);
250
    }
251

    
252
}