/[schmitzm]/branches/2.0-RC2/src/skrueger/geotools/StyledFS.java
ViewVC logotype

Annotation of /branches/2.0-RC2/src/skrueger/geotools/StyledFS.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Tue Feb 24 22:43:52 2009 UTC (16 years ago) by mojays
Original Path: trunk/src/skrueger/geotools/StyledFS.java
File size: 4907 byte(s)
First Commit, corresponds to Revision 1008 of Wikisquare-SVN
includes:
- schmitzm.* (except schmitzm.test)
- org.geotools.* (all overridden classes)
- skrueger.geotools
- skrueger.i8n
- skrueger.swing
- appl.data.LateLoadable (dependency in SCHMITZM)
- appl.data.LoadingException (dependency in SCHMITZM)
- appl.util.RasterMetaData (dependency in SCHMITZM)

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     import org.geotools.styling.Style;
19     import org.opengis.referencing.crs.CoordinateReferenceSystem;
20    
21     import schmitzm.geotools.styling.StylingUtil;
22     import skrueger.AttributeMetaData;
23     import skrueger.i8n.Translation;
24    
25     import com.vividsolutions.jts.geom.Envelope;
26    
27     /**
28     * This class enables a non Atlas context to use the Atlas LayerPanel
29     * {@link JPanel} as a {@link MapContextManagerInterface}
30     *
31     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
32     */
33     public class StyledFS implements StyledFeatureSourceInterface {
34     private static final Logger LOGGER = Logger.getLogger(StyledFS.class);
35    
36     private final FeatureSource fs;
37    
38     /**
39     * A unique ID which identifies the Layer in the Atlas. It's more important
40     * than it should be ;-)
41     */
42     private String id;
43    
44     private Style style;
45    
46     private Translation title;
47    
48     private Translation desc;
49    
50     private File sldFile;
51    
52     private HashMap<Integer, AttributeMetaData> map;
53    
54     /**
55     * This class enables a non Atlas context to use the Atlas LayerPanel
56     * {@link JPanel} as a {@link MapContextManagerInterface}
57     *
58     * @param fs
59     * {@link FeatureSource} that is beeing styled.
60     *
61     * @param sldFile
62     * may be <code>null</code>. Otherwise the SLD {@link File} to
63     * import and associate with this {@link StyledFS}
64     */
65     public StyledFS(FeatureSource fs, File sldFile) {
66    
67     super();
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     }
81     }
82    
83     title = new Translation();
84     title.fromOneLine(sldFile.getName());
85    
86     desc = new Translation();
87     desc.fromOneLine(sldFile.getAbsolutePath());
88     }
89    
90     public void dispose() {
91     }
92    
93     /**
94     * Returnes human readable {@link String} of the CRS natively used by this
95     * {@link DpLayer}
96     *
97     * If crs == null, it will call {@link #getGeoObject()}
98     *
99     */
100     public String getCRSString() {
101     if (getCrs() == null)
102     return "CRS?";
103    
104     return getCrs().getName().getCode();
105     }
106    
107     public CoordinateReferenceSystem getCrs() {
108     return fs.getSchema().getDefaultGeometry().getCoordinateSystem();
109     }
110    
111     public Translation getDesc() {
112     return desc;
113     }
114    
115     public Envelope getEnvelope() {
116     try {
117     return fs.getBounds();
118     } catch (IOException e) {
119     e.printStackTrace();
120     return null;
121     }
122     }
123    
124     public FeatureSource getGeoObject() throws Exception {
125     return fs;
126     }
127    
128     public String getId() {
129     return id;
130     }
131    
132     public ImageIcon getImageIcon() {
133     return null;
134     }
135    
136     public URL getInfoURL() {
137     return null;
138     }
139    
140     public Translation getKeywords() {
141     return null;
142     }
143    
144     public Style getStyle() {
145     return style;
146     }
147    
148     public Translation getTitle() {
149     return title;
150     }
151    
152     public boolean isDisposed() {
153     return false;
154     }
155    
156     public boolean isHideInLegend() {
157     return false;
158     }
159    
160     public void setDesc(Translation dec) {
161     this.desc = dec;
162     }
163    
164     public void setImageIcon(ImageIcon icon) {
165     // TODO Auto-generated method stub
166    
167     }
168    
169     public void setKeywords(Translation keywords) {
170     }
171    
172     public void setStyle(Style style) {
173     this.style = style;
174    
175     }
176    
177     public void setTitle(Translation title) {
178     this.title = title;
179    
180     }
181    
182     public void uncache() {
183     }
184    
185     public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {
186     if (map == null) {
187     map = new HashMap<Integer, AttributeMetaData>();
188    
189     // Leaving out the first one, it will be the_geom
190     for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
191     AttributeType att = fs.getSchema().getAttributeType(i);
192    
193     AttributeMetaData attMetaData = new AttributeMetaData(i, att.getLocalName());
194     map.put(i, attMetaData);
195     }
196     }
197     return map;
198     }
199    
200     /**
201     * @return The {@link File} where the SLD was loaded from or
202     * <code>null</code> if there didn't exist a {@link File}. (It
203     * could be a WFS or a PostGIS
204     *
205     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
206     */
207     public File getSldFile() {
208     return sldFile;
209     }
210    
211     public void setSldFile(File sldFile) {
212     this.sldFile = sldFile;
213     }
214    
215     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26