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

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

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

branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java revision 336 by alfonx, Thu Aug 27 09:10:10 2009 UTC branches/2.0-RC1/src/skrueger/geotools/StyledFS.java revision 607 by alfonx, Wed Dec 9 15:13:42 2009 UTC
# 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 48  import org.geotools.styling.Style; Line 46  import org.geotools.styling.Style;
46  import org.opengis.feature.simple.SimpleFeature;  import org.opengis.feature.simple.SimpleFeature;
47  import org.opengis.feature.simple.SimpleFeatureType;  import org.opengis.feature.simple.SimpleFeatureType;
48  import org.opengis.feature.type.AttributeDescriptor;  import org.opengis.feature.type.AttributeDescriptor;
49    import org.opengis.filter.Filter;
50  import org.opengis.referencing.crs.CoordinateReferenceSystem;  import org.opengis.referencing.crs.CoordinateReferenceSystem;
51    
52    import schmitzm.geotools.io.GeoImportUtil;
53  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
54  import skrueger.AttributeMetaData;  import skrueger.AttributeMetadata;
55  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
56    
57  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
# Line 81  public class StyledFS implements StyledF Line 81  public class StyledFS implements StyledF
81    
82          private File sldFile;          private File sldFile;
83    
84          private HashMap<Integer, AttributeMetaData> map;          private AttributeMetadataMap map;
85    
86            private Filter filter = Filter.INCLUDE;
87    
88          /**          /**
89           * 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 94  public class StyledFS implements StyledF Line 96  public class StyledFS implements StyledF
96           *            may be <code>null</code>. Otherwise the SLD {@link File} to           *            may be <code>null</code>. Otherwise the SLD {@link File} to
97           *            import and associate with this {@link StyledFS}           *            import and associate with this {@link StyledFS}
98           */           */
99          public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs, File sldFile) {          public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
100                            File sldFile) {
101    
102                  this.fs = fs;                  this.fs = fs;
103                  id = StyledFS.class.getSimpleName()                  id = StyledFS.class.getSimpleName()
# Line 113  public class StyledFS implements StyledF Line 116  public class StyledFS implements StyledF
116                          }                          }
117                  }                  }
118                  title = new Translation();                  title = new Translation();
                 title.fromOneLine(sldFile.getName());  
   
119                  desc = new Translation();                  desc = new Translation();
120                  desc.fromOneLine(sldFile.getAbsolutePath());  
121                    if (sldFile != null) {
122                            title.fromOneLine(sldFile.getName());
123                            desc.fromOneLine(sldFile.getAbsolutePath());
124                    }
125    
126            }
127    
128            public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) {
129                    this(fs, null);
130          }          }
131    
132          public void dispose() {          public void dispose() {
# Line 137  public class StyledFS implements StyledF Line 147  public class StyledFS implements StyledF
147          }          }
148    
149          public CoordinateReferenceSystem getCrs() {          public CoordinateReferenceSystem getCrs() {
150                  return fs.getSchema().getCoordinateReferenceSystem();                  CoordinateReferenceSystem crs = fs.getSchema().getCoordinateReferenceSystem();
151                    if (fs.getSchema().getCoordinateReferenceSystem() == null) {
152                            LOGGER.warn("Could not determine the CRS of "+getTitle()+". Using default "+GeoImportUtil.getDefaultCRS());
153                            crs = GeoImportUtil.getDefaultCRS();
154                    }
155                    return crs;
156          }          }
157    
158          public Translation getDesc() {          public Translation getDesc() {
# Line 226  public class StyledFS implements StyledF Line 241  public class StyledFS implements StyledF
241          /**          /**
242           *           *
243           */           */
244          public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {          public AttributeMetadataMap getAttributeMetaDataMap() {
245                  if (map == null) {                  if (map == null) {
246    
247                          map = new HashMap<Integer, AttributeMetaData>();                          map = new AttributeMetadataMap(new String[] {Translation.getActiveLang()});
248    
249                          // Leaving out the first one, it will be the_geom                          // Leaving out the first one, it will be the_geom
250                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {                          for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
251                                  AttributeDescriptor att = fs.getSchema().getDescriptor(i);                                  AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
252    
253                                  AttributeMetaData attMetaData = new AttributeMetaData(i, att                                  AttributeMetadata attMetaData = new AttributeMetadata(attDesc.getName(), map.getLanguages());
254                                                  .getLocalName());                                  map.put(attDesc.getName(), attMetaData);
                                 map.put(i, attMetaData);  
255                          }                          }
256                  }                  }
257                  return map;                  return map;
# Line 245  public class StyledFS implements StyledF Line 259  public class StyledFS implements StyledF
259    
260          /**          /**
261           * @return The {@link File} where the SLD was loaded from or           * @return The {@link File} where the SLD was loaded from or
262           *         <code>null</code> if there didn't exist a {@link File}.           *         <code>null</code> if there didn't exist a {@link File}.
263           *           *
264           * @author <a href="mailto:[email protected]">Stefan Alfons           * @author <a href="mailto:[email protected]">Stefan Alfons
265           *         Kr&uuml;ger</a>           *         Kr&uuml;ger</a>
# Line 264  public class StyledFS implements StyledF Line 278  public class StyledFS implements StyledF
278           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
279           */           */
280          @Override          @Override
281          public FeatureCollection getFeatureCollection() {          public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
282                  FeatureCollection features;                  FeatureCollection<SimpleFeatureType, SimpleFeature> features;
283                  try {                  try {
284                          features = getGeoObject().getFeatures();                          features = getGeoObject().getFeatures();
285                  } catch (IOException e) {                  } catch (IOException e) {
# Line 282  public class StyledFS implements StyledF Line 296  public class StyledFS implements StyledF
296           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
297           */           */
298          @Override          @Override
299          public FeatureSource getFeatureSource() {          public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
300                  return getGeoObject();                  return getGeoObject();
301          }          }
302    
303            @Override
304            public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
305    //              final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
306    //              if (filter == Filter.EXCLUDE)
307    //                      return new EmptyFeatureCollection(fc.getSchema());
308    //              if (filter == Filter.INCLUDE)
309    //                      return fc;
310    //              return fc.subCollection(filter);
311                    
312                    try {
313                            return getFeatureSource().getFeatures(filter);
314                    } catch (IOException e) {
315                            throw new RuntimeException(e);
316                    }
317            }
318    
319            @Override
320            public Filter getFilter() {
321                    return filter;
322            }
323    
324            @Override
325            public void setFilter(Filter filter) {
326                    this.filter = filter;
327            }
328    
329            @Override
330            public SimpleFeatureType getSchema() {
331                    return getGeoObject().getSchema();
332            }
333    
334  }  }

Legend:
Removed from v.336  
changed lines
  Added in v.607

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26