/[schmitzm]/trunk/src/skrueger/geotools/StyledFS.java
ViewVC logotype

Annotation of /trunk/src/skrueger/geotools/StyledFS.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (hide annotations)
Thu Jul 9 20:51:58 2009 UTC (15 years, 7 months ago) by alfonx
File size: 5466 byte(s)
* SCHMITZ/ISDSS/AV/GP CodeClean: Removed the "throws Exception" from "getGeoObject" and rather let it throw a RuntimeException(e). Now it's our job to remove ny throw/catch leftovers in the outer code.
* Fundamentally introduced AttributeMetaData to AtlasStyler

  
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     this.fs = fs;
68     id = StyledFS.class.getSimpleName()
69     + new Random(new Date().getTime()).nextInt(10000000);
70    
71     this.sldFile = sldFile;
72    
73     if ((sldFile != null) && (sldFile.exists())) {
74     try {
75     style = StylingUtil.loadSLD(sldFile)[0];
76     } catch (FileNotFoundException e) {
77     LOGGER
78     .debug("The SLD file passed was empty. Leaving the Style untouched. (We are in the constructor.. so its null");
79 alfonx 169 } catch (Exception e) {
80     LOGGER.warn("Reading SLD failed: " + sldFile, e);
81 mojays 2 }
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 alfonx 208 public FeatureSource getGeoObject() {
125 mojays 2 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 alfonx 40 /**
157     * If true, this layer will not be shown in the legend. Default = false
158     */
159     /**
160     *
161     * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
162     * verstecken/nicht verstecken gestellt werden können. Das sind
163     * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
164     * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
165     * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
166     * die Funktion genutzt.
167     *
168 alfonx 169 * // public boolean isHideInLegend() { // return false; // }
169 alfonx 40 */
170 mojays 2
171     public void setDesc(Translation dec) {
172     this.desc = dec;
173     }
174    
175     public void setImageIcon(ImageIcon icon) {
176     }
177    
178     public void setKeywords(Translation keywords) {
179     }
180    
181     public void setStyle(Style style) {
182     this.style = style;
183    
184     }
185    
186     public void setTitle(Translation title) {
187     this.title = title;
188    
189     }
190    
191     public void uncache() {
192     }
193    
194 alfonx 93 /**
195     *
196     */
197 mojays 2 public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {
198     if (map == null) {
199 alfonx 169
200 mojays 2 map = new HashMap<Integer, AttributeMetaData>();
201 alfonx 169
202 mojays 2 // Leaving out the first one, it will be the_geom
203     for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
204     AttributeType att = fs.getSchema().getAttributeType(i);
205 alfonx 169
206     AttributeMetaData attMetaData = new AttributeMetaData(i, att
207     .getLocalName());
208 mojays 2 map.put(i, attMetaData);
209     }
210     }
211     return map;
212     }
213    
214     /**
215     * @return The {@link File} where the SLD was loaded from or
216 alfonx 169 * <code>null</code> if there didn't exist a {@link File}. (It could
217     * be a WFS or a PostGIS
218 mojays 2 *
219 alfonx 169 * @author <a href="mailto:[email protected]">Stefan Alfons
220     * Kr&uuml;ger</a>
221 mojays 2 */
222     public File getSldFile() {
223     return sldFile;
224     }
225    
226     public void setSldFile(File sldFile) {
227     this.sldFile = sldFile;
228     }
229    
230     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26