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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/skrueger/geotools/StyledFS.java revision 244 by alfonx, Wed Jul 29 09:33:33 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java revision 454 by alfonx, Sun Oct 11 16:12:05 2009 UTC
# Line 2  Line 2 
2   * Copyright (c) 2009 Martin O. J. Schmitz.   * Copyright (c) 2009 Martin O. J. Schmitz.
3   *   *
4   * This file is part of the SCHMITZM library - a collection of utility   * This file is part of the SCHMITZM library - a collection of utility
5   * classes based on Java 1.6, focussing (not only) on Java Swing   * classes based on Java 1.6, focusing (not only) on Java Swing
6   * and the Geotools library.   * and the Geotools library.
7   *   *
8   * The SCHMITZM project is hosted at:   * The SCHMITZM project is hosted at:
# Line 34  import java.io.FileNotFoundException; Line 34  import java.io.FileNotFoundException;
34  import java.io.IOException;  import java.io.IOException;
35  import java.net.URL;  import java.net.URL;
36  import java.util.Date;  import java.util.Date;
 import java.util.HashMap;  
 import java.util.Map;  
37  import java.util.Random;  import java.util.Random;
38    
39  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
# Line 43  import javax.swing.JPanel; Line 41  import javax.swing.JPanel;
41    
42  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
43  import org.geotools.data.FeatureSource;  import org.geotools.data.FeatureSource;
44  import org.geotools.feature.AttributeType;  import org.geotools.data.store.EmptyFeatureCollection;
45  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
46  import org.geotools.styling.Style;  import org.geotools.styling.Style;
47    import org.opengis.feature.simple.SimpleFeature;
48    import org.opengis.feature.simple.SimpleFeatureType;
49    import org.opengis.feature.type.AttributeDescriptor;
50    import org.opengis.filter.Filter;
51  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
52    
53    import schmitzm.geotools.io.GeoImportUtil;
54  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
55  import skrueger.AttributeMetaData;  import skrueger.AttributeMetaData;
56  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
# Line 63  import com.vividsolutions.jts.geom.Envel Line 66  import com.vividsolutions.jts.geom.Envel
66  public class StyledFS implements StyledFeatureSourceInterface {  public class StyledFS implements StyledFeatureSourceInterface {
67          private static final Logger LOGGER = Logger.getLogger(StyledFS.class);          private static final Logger LOGGER = Logger.getLogger(StyledFS.class);
68    
69          private final FeatureSource fs;          private final FeatureSource<SimpleFeatureType, SimpleFeature> fs;
70    
71          /**          /**
72           * A unique ID which identifies the Layer in the Atlas. It's more important           * A unique ID which identifies the Layer in the Atlas. It's more important
# Line 79  public class StyledFS implements StyledF Line 82  public class StyledFS implements StyledF
82    
83          private File sldFile;          private File sldFile;
84    
85          private HashMap<Integer, AttributeMetaData> map;          private AttributeMetadataMap map;
86    
87            private Filter filter = Filter.INCLUDE;
88    
89          /**          /**
90           * This class enables a non Atlas context to use the Atlas LayerPanel           * This class enables a non Atlas context to use the Atlas LayerPanel
# Line 92  public class StyledFS implements StyledF Line 97  public class StyledFS implements StyledF
97           *            may be <code>null</code>. Otherwise the SLD {@link File} to           *            may be <code>null</code>. Otherwise the SLD {@link File} to
98           *            import and associate with this {@link StyledFS}           *            import and associate with this {@link StyledFS}
99           */           */
100          public StyledFS(FeatureSource fs, File sldFile) {          public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
101                            File sldFile) {
102    
103                  this.fs = fs;                  this.fs = fs;
104                  id = StyledFS.class.getSimpleName()                  id = StyledFS.class.getSimpleName()
# Line 100  public class StyledFS implements StyledF Line 106  public class StyledFS implements StyledF
106    
107                  this.sldFile = sldFile;                  this.sldFile = sldFile;
108    
109                  if ((sldFile != null) && (sldFile.exists())) {                  if (sldFile != null && sldFile.exists()) {
110                          try {                          try {
111                                  style = StylingUtil.loadSLD(sldFile)[0];                                  style = StylingUtil.loadSLD(sldFile)[0];
112                          } catch (FileNotFoundException e) {                          } catch (FileNotFoundException e) {
# Line 111  public class StyledFS implements StyledF Line 117  public class StyledFS implements StyledF
117                          }                          }
118                  }                  }
119                  title = new Translation();                  title = new Translation();
                 title.fromOneLine(sldFile.getName());  
   
120                  desc = new Translation();                  desc = new Translation();
121                  desc.fromOneLine(sldFile.getAbsolutePath());  
122                    if (sldFile != null) {
123                            title.fromOneLine(sldFile.getName());
124                            desc.fromOneLine(sldFile.getAbsolutePath());
125                    }
126    
127            }
128    
129            public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) {
130                    this(fs, null);
131          }          }
132    
133          public void dispose() {          public void dispose() {
134          }          }
135    
136          /**          /**
137           * Returnes human readable {@link String} of the CRS natively used by this           * Returns human readable {@link String} of the CRS natively used by this
138           * {@link DpLayer}           * {@link DpLayer}
139           *           *
140           * If crs == null, it will call {@link #getGeoObject()}           * If CRS == null, it will call {@link #getGeoObject()}
141           *           *
142           */           */
143          public String getCRSString() {          public String getCRSString() {
# Line 135  public class StyledFS implements StyledF Line 148  public class StyledFS implements StyledF
148          }          }
149    
150          public CoordinateReferenceSystem getCrs() {          public CoordinateReferenceSystem getCrs() {
151                  return fs.getSchema().getDefaultGeometry().getCoordinateSystem();                  CoordinateReferenceSystem crs = fs.getSchema().getCoordinateReferenceSystem();
152                    if (fs.getSchema().getCoordinateReferenceSystem() == null) {
153                            LOGGER.warn("Could not determine the CRS of "+getTitle()+". Using default "+GeoImportUtil.getDefaultCRS());
154                            crs = GeoImportUtil.getDefaultCRS();
155                    }
156                    return crs;
157          }          }
158    
159          public Translation getDesc() {          public Translation getDesc() {
# Line 151  public class StyledFS implements StyledF Line 169  public class StyledFS implements StyledF
169                  }                  }
170          }          }
171    
172          public FeatureSource getGeoObject() {          public FeatureSource<SimpleFeatureType, SimpleFeature> getGeoObject() {
173                  return fs;                  return fs;
174          }          }
175    
# Line 224  public class StyledFS implements StyledF Line 242  public class StyledFS implements StyledF
242          /**          /**
243           *           *
244           */           */
245          public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {          public AttributeMetadataMap getAttributeMetaDataMap() {
246                  if (map == null) {                  if (map == null) {
247    
248                          map = new HashMap<Integer, AttributeMetaData>();                          map = new AttributeMetadataMap();
249    
250                          // Leaving out the first one, it will be the_geom                          // Leaving out the first one, it will be the_geom
251                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
252                                  AttributeType att = fs.getSchema().getAttributeType(i);                                  AttributeDescriptor att = fs.getSchema().getDescriptor(i);
253    
254                                  AttributeMetaData attMetaData = new AttributeMetaData(i, att                                  AttributeMetaData attMetaData = new AttributeMetaData(i, att
255                                                  .getLocalName());                                                  .getLocalName());
# Line 243  public class StyledFS implements StyledF Line 261  public class StyledFS implements StyledF
261    
262          /**          /**
263           * @return The {@link File} where the SLD was loaded from or           * @return The {@link File} where the SLD was loaded from or
264           *         <code>null</code> if there didn't exist a {@link File}.           *         <code>null</code> if there didn't exist a {@link File}.
265           *           *
266           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
267           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
# Line 262  public class StyledFS implements StyledF Line 280  public class StyledFS implements StyledF
280           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
281           */           */
282          @Override          @Override
283          public FeatureCollection getFeatureCollection() {          public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
284                  FeatureCollection features;                  FeatureCollection<SimpleFeatureType, SimpleFeature> features;
285                  try {                  try {
286                          features = getGeoObject().getFeatures();                          features = getGeoObject().getFeatures();
287                  } catch (IOException e) {                  } catch (IOException e) {
# Line 280  public class StyledFS implements StyledF Line 298  public class StyledFS implements StyledF
298           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
299           */           */
300          @Override          @Override
301          public FeatureSource getFeatureSource() {          public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
302                  return getGeoObject();                  return getGeoObject();
303          }          }
304    
305            @Override
306            public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
307                    final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
308                    if (filter == Filter.EXCLUDE)
309                            return new EmptyFeatureCollection(fc.getSchema());
310                    if (filter == Filter.INCLUDE)
311                            return fc;
312                    return fc.subCollection(filter);
313            }
314    
315            @Override
316            public Filter getFilter() {
317                    return filter;
318            }
319    
320            @Override
321            public void setFilter(Filter filter) {
322                    this.filter = filter;
323            }
324    
325            @Override
326            public SimpleFeatureType getSchema() {
327                    return getGeoObject().getSchema();
328            }
329    
330  }  }

Legend:
Removed from v.244  
changed lines
  Added in v.454

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26