/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java
ViewVC logotype

Annotation of /branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 223 - (hide annotations)
Tue Jul 14 15:01:57 2009 UTC (15 years, 7 months ago) by alfonx
Original Path: trunk/src/skrueger/geotools/StyledFS.java
File size: 6180 byte(s)
* Last commit before refactoring StyledMapInterface to StyledLayerInterface
1 mojays 2 package skrueger.geotools;
2    
3     import java.io.File;
4     import java.io.FileNotFoundException;
5     import java.io.IOException;
6     import java.net.URL;
7     import java.util.Date;
8     import java.util.HashMap;
9     import java.util.Map;
10     import java.util.Random;
11    
12     import javax.swing.ImageIcon;
13     import javax.swing.JPanel;
14    
15     import org.apache.log4j.Logger;
16     import org.geotools.data.FeatureSource;
17     import org.geotools.feature.AttributeType;
18 alfonx 221 import org.geotools.feature.FeatureCollection;
19 mojays 2 import org.geotools.styling.Style;
20     import org.opengis.referencing.crs.CoordinateReferenceSystem;
21    
22     import schmitzm.geotools.styling.StylingUtil;
23     import skrueger.AttributeMetaData;
24     import skrueger.i8n.Translation;
25    
26     import com.vividsolutions.jts.geom.Envelope;
27    
28     /**
29     * This class enables a non Atlas context to use the Atlas LayerPanel
30     * {@link JPanel} as a {@link MapContextManagerInterface}
31     *
32     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
33     */
34     public class StyledFS implements StyledFeatureSourceInterface {
35     private static final Logger LOGGER = Logger.getLogger(StyledFS.class);
36    
37     private final FeatureSource fs;
38    
39     /**
40     * A unique ID which identifies the Layer in the Atlas. It's more important
41     * than it should be ;-)
42     */
43     private String id;
44    
45     private Style style;
46    
47     private Translation title;
48    
49     private Translation desc;
50    
51     private File sldFile;
52    
53     private HashMap<Integer, AttributeMetaData> map;
54    
55     /**
56     * This class enables a non Atlas context to use the Atlas LayerPanel
57     * {@link JPanel} as a {@link MapContextManagerInterface}
58     *
59     * @param fs
60     * {@link FeatureSource} that is beeing styled.
61     *
62     * @param sldFile
63     * may be <code>null</code>. Otherwise the SLD {@link File} to
64     * import and associate with this {@link StyledFS}
65     */
66     public StyledFS(FeatureSource fs, File sldFile) {
67    
68     this.fs = fs;
69     id = StyledFS.class.getSimpleName()
70     + new Random(new Date().getTime()).nextInt(10000000);
71    
72     this.sldFile = sldFile;
73    
74     if ((sldFile != null) && (sldFile.exists())) {
75     try {
76     style = StylingUtil.loadSLD(sldFile)[0];
77     } catch (FileNotFoundException e) {
78     LOGGER
79     .debug("The SLD file passed was empty. Leaving the Style untouched. (We are in the constructor.. so its null");
80 alfonx 169 } catch (Exception e) {
81     LOGGER.warn("Reading SLD failed: " + sldFile, e);
82 mojays 2 }
83     }
84     title = new Translation();
85     title.fromOneLine(sldFile.getName());
86    
87     desc = new Translation();
88     desc.fromOneLine(sldFile.getAbsolutePath());
89     }
90    
91     public void dispose() {
92     }
93    
94     /**
95     * Returnes human readable {@link String} of the CRS natively used by this
96     * {@link DpLayer}
97     *
98     * If crs == null, it will call {@link #getGeoObject()}
99     *
100     */
101     public String getCRSString() {
102     if (getCrs() == null)
103     return "CRS?";
104    
105     return getCrs().getName().getCode();
106     }
107    
108     public CoordinateReferenceSystem getCrs() {
109     return fs.getSchema().getDefaultGeometry().getCoordinateSystem();
110     }
111    
112     public Translation getDesc() {
113     return desc;
114     }
115    
116     public Envelope getEnvelope() {
117     try {
118     return fs.getBounds();
119     } catch (IOException e) {
120     e.printStackTrace();
121     return null;
122     }
123     }
124    
125 alfonx 208 public FeatureSource getGeoObject() {
126 mojays 2 return fs;
127     }
128    
129     public String getId() {
130     return id;
131     }
132    
133     public ImageIcon getImageIcon() {
134     return null;
135     }
136    
137     public URL getInfoURL() {
138     return null;
139     }
140    
141     public Translation getKeywords() {
142     return null;
143     }
144    
145     public Style getStyle() {
146     return style;
147     }
148    
149     public Translation getTitle() {
150     return title;
151     }
152    
153     public boolean isDisposed() {
154     return false;
155     }
156    
157 alfonx 40 /**
158     * If true, this layer will not be shown in the legend. Default = false
159     */
160     /**
161     *
162     * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
163     * verstecken/nicht verstecken gestellt werden können. Das sind
164     * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
165     * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
166     * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
167     * die Funktion genutzt.
168     *
169 alfonx 169 * // public boolean isHideInLegend() { // return false; // }
170 alfonx 40 */
171 mojays 2
172     public void setDesc(Translation dec) {
173     this.desc = dec;
174     }
175    
176     public void setImageIcon(ImageIcon icon) {
177     }
178    
179     public void setKeywords(Translation keywords) {
180     }
181    
182     public void setStyle(Style style) {
183     this.style = style;
184    
185     }
186    
187     public void setTitle(Translation title) {
188     this.title = title;
189    
190     }
191    
192     public void uncache() {
193     }
194    
195 alfonx 93 /**
196     *
197     */
198 mojays 2 public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {
199     if (map == null) {
200 alfonx 169
201 mojays 2 map = new HashMap<Integer, AttributeMetaData>();
202 alfonx 169
203 mojays 2 // Leaving out the first one, it will be the_geom
204     for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
205     AttributeType att = fs.getSchema().getAttributeType(i);
206 alfonx 169
207     AttributeMetaData attMetaData = new AttributeMetaData(i, att
208     .getLocalName());
209 mojays 2 map.put(i, attMetaData);
210     }
211     }
212     return map;
213     }
214    
215     /**
216     * @return The {@link File} where the SLD was loaded from or
217 alfonx 169 * <code>null</code> if there didn't exist a {@link File}. (It could
218     * be a WFS or a PostGIS
219 mojays 2 *
220 alfonx 169 * @author <a href="mailto:[email protected]">Stefan Alfons
221     * Kr&uuml;ger</a>
222 mojays 2 */
223     public File getSldFile() {
224     return sldFile;
225     }
226    
227     public void setSldFile(File sldFile) {
228     this.sldFile = sldFile;
229     }
230    
231 alfonx 221 /**
232     * Returns the features of the {@link FeatureSource}.
233     *
234 alfonx 222 * @see {@link StyledFeaturesInterface}
235 alfonx 221 */
236     @Override
237     public FeatureCollection getFeatureCollection() {
238     FeatureCollection features;
239     try {
240     features = getGeoObject().getFeatures();
241     } catch (IOException e) {
242     throw new RuntimeException(
243     "Error getting the features of the FeatureSource");
244     }
245     return features;
246     }
247    
248     /**
249     * Same as {@link #getGeoObject()} method, but complies to the
250 alfonx 222 * {@link StyledFeaturesInterface}
251 alfonx 221 *
252 alfonx 222 * @see {@link StyledFeaturesInterface}
253 alfonx 221 */
254     @Override
255     public FeatureSource getFeatureSource() {
256     return getGeoObject();
257     }
258    
259 mojays 2 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26