/[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 40 - (hide annotations)
Mon Apr 6 19:31:02 2009 UTC (15 years, 10 months ago) by alfonx
Original Path: trunk/src/skrueger/geotools/StyledFS.java
File size: 5419 byte(s)
* Layers can be marked as "hide In Legend" in the GP and will be hidden in the AV's legend

Das Interface StyledMapInterface.java hatte bisher eine abstrakte Methode isHideInLegend, die nie benutzt wurde. Ich habe die Idee jetzt im Atlas implementiert, und dann gemekert, dass nicht unbedingt eine Eigenschaft dieses Interfaces sein sollte.
Ein Layer soll nicht generell auf verstecken/nicht verstecken gestellt werden können. Das sind Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer. Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer nicht in der Legende auftauchen sollen.  

Meines Wissens hat keiner bisher die Funktion genutzt.

Ich habe in allen allen Klassen welche StyledMapInterface implementieren die Funktion auskommentiert.

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 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     // public boolean isHideInLegend() {
169     // return false;
170     // }
171     */
172 mojays 2
173     public void setDesc(Translation dec) {
174     this.desc = dec;
175     }
176    
177     public void setImageIcon(ImageIcon icon) {
178     // TODO Auto-generated method stub
179    
180     }
181    
182     public void setKeywords(Translation keywords) {
183     }
184    
185     public void setStyle(Style style) {
186     this.style = style;
187    
188     }
189    
190     public void setTitle(Translation title) {
191     this.title = title;
192    
193     }
194    
195     public void uncache() {
196     }
197    
198     public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {
199     if (map == null) {
200     map = new HashMap<Integer, AttributeMetaData>();
201    
202     // 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    
206     AttributeMetaData attMetaData = new AttributeMetaData(i, att.getLocalName());
207     map.put(i, attMetaData);
208     }
209     }
210     return map;
211     }
212    
213     /**
214     * @return The {@link File} where the SLD was loaded from or
215     * <code>null</code> if there didn't exist a {@link File}. (It
216     * could be a WFS or a PostGIS
217     *
218     * @author <a href="mailto:[email protected]">Stefan Alfons Kr&uuml;ger</a>
219     */
220     public File getSldFile() {
221     return sldFile;
222     }
223    
224     public void setSldFile(File sldFile) {
225     this.sldFile = sldFile;
226     }
227    
228     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26