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

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

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

revision 322 by alfonx, Wed Aug 26 14:12:17 2009 UTC revision 422 by alfonx, Fri Oct 2 00:47:48 2009 UTC
# Line 31  package skrueger.geotools; Line 31  package skrueger.geotools;
31    
32  import java.io.IOException;  import java.io.IOException;
33  import java.net.URL;  import java.net.URL;
 import java.util.HashMap;  
 import java.util.Map;  
34    
35  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
36    
37  import org.geotools.data.FeatureSource;  import org.geotools.data.FeatureSource;
38  import org.geotools.data.collection.CollectionDataStore;  import org.geotools.data.collection.CollectionDataStore;
 import org.geotools.feature.AttributeType;  
39  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
 import org.opengis.feature.simple.SimpleFeatureType;  
40  import org.geotools.styling.Style;  import org.geotools.styling.Style;
41    import org.opengis.feature.simple.SimpleFeature;
42    import org.opengis.feature.simple.SimpleFeatureType;
43    import org.opengis.feature.type.AttributeDescriptor;
44    
45  import schmitzm.geotools.feature.FeatureUtil;  import schmitzm.geotools.feature.FeatureUtil;
46  import skrueger.AttributeMetaData;  import skrueger.AttributeMetaData;
# Line 58  import skrueger.i8n.Translation; Line 57  import skrueger.i8n.Translation;
57   * @version 1.0   * @version 1.0
58   */   */
59  public class StyledFeatureCollection extends  public class StyledFeatureCollection extends
60                  AbstractStyledLayer<FeatureCollection> implements                  AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature> > implements
61                  StyledFeatureCollectionInterface {                  StyledFeatureCollectionInterface {
62    
63          /** Holds the meta data for displaying a legend. */          /** Holds the meta data for displaying a legend. */
64          protected Map<Integer, AttributeMetaData> attrMetaData = null;          protected AttributeMetadataMap attrMetaData = null;
65    
66          /**          /**
67           * We be filled with a "virtual" {@link FeatureSource} on demand.           * We be filled with a "virtual" {@link FeatureSource} on demand.
68           */           */
69          private FeatureSource featureSource = null;          private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
70    
71          /**          /**
72           * Creates a styled {@link FeatureCollection} with language-specific           * Creates a styled {@link FeatureCollection} with language-specific
# Line 92  public class StyledFeatureCollection ext Line 91  public class StyledFeatureCollection ext
91           * @exception IllegalArgumentException           * @exception IllegalArgumentException
92           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
93           */           */
94          public StyledFeatureCollection(FeatureCollection fc, String id,          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
95                          Translation title, Translation desc, Translation keywords,                          Translation title, Translation desc, Translation keywords,
96                          Style style, Map<Integer, AttributeMetaData> attrMetaData,                          Style style, AttributeMetadataMap attrMetaData,
97                          ImageIcon icon) {                          ImageIcon icon) {
98                  super(fc, fc.getBounds(), fc.getSchema().getDefaultGeometry()                  super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
99                                  .getCoordinateSystem(), id, title, desc, keywords, style, icon);                                  .getCoordinateReferenceSystem(), id, title, desc, keywords, style, icon);
100                  setAttributeMetaData(attrMetaData);                  setAttributeMetaData(attrMetaData);
101          }          }
102    
# Line 122  public class StyledFeatureCollection ext Line 121  public class StyledFeatureCollection ext
121           * @exception IllegalArgumentException           * @exception IllegalArgumentException
122           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
123           */           */
124          public StyledFeatureCollection(FeatureCollection fc, String id,          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
125                          Translation title, Translation desc, Translation keywords,                          Translation title, Translation desc, Translation keywords,
126                          StyledLayerStyle<Map<Integer, AttributeMetaData>> style,                          StyledLayerStyle<AttributeMetadataMap> style,
127                          ImageIcon icon) {                          ImageIcon icon) {
128                  super(fc, fc.getBounds(), fc.getSchema().getDefaultGeometry()                  super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
129                                  .getCoordinateSystem(), id, title, desc, keywords,                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,
130                                  style != null ? style.getGeoObjectStyle() : null, icon);                                  style != null ? style.getGeoObjectStyle() : null, icon);
131                  setAttributeMetaData(style != null ? style.getMetaData() : null);                  setAttributeMetaData(style != null ? style.getMetaData() : null);
132          }          }
# Line 149  public class StyledFeatureCollection ext Line 148  public class StyledFeatureCollection ext
148           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
149           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
150           */           */
151          public StyledFeatureCollection(FeatureCollection fc, String id,          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
152                          Translation title, Style style) {                          Translation title, Style style) {
153                  this(fc, id, title, null, null, style, null, null);                  this(fc, id, title, null, null, style, null, null);
154          }          }
# Line 177  public class StyledFeatureCollection ext Line 176  public class StyledFeatureCollection ext
176           * @exception IllegalArgumentException           * @exception IllegalArgumentException
177           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
178           */           */
179          public StyledFeatureCollection(FeatureCollection fc, String id,          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
180                          String title, String desc, String keywords, Style style,                          String title, String desc, String keywords, Style style,
181                          Map<Integer, AttributeMetaData> attrMetaData, ImageIcon icon) {                          AttributeMetadataMap attrMetaData, ImageIcon icon) {
182                  this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);                  this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);
183                  setTitle(title);                  setTitle(title);
184                  setDesc(desc);                  setDesc(desc);
# Line 207  public class StyledFeatureCollection ext Line 206  public class StyledFeatureCollection ext
206           * @exception IllegalArgumentException           * @exception IllegalArgumentException
207           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
208           */           */
209          public StyledFeatureCollection(FeatureCollection fc, String id,          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
210                          String title, String desc, String keywords,                          String title, String desc, String keywords,
211                          StyledLayerStyle<Map<Integer, AttributeMetaData>> style,                          StyledLayerStyle<AttributeMetadataMap> style,
212                          ImageIcon icon) {                          ImageIcon icon) {
213                  this(fc, id, title, desc, keywords, style != null ? style                  this(fc, id, title, desc, keywords, style != null ? style
214                                  .getGeoObjectStyle() : null, style != null ? style                                  .getGeoObjectStyle() : null, style != null ? style
# Line 233  public class StyledFeatureCollection ext Line 232  public class StyledFeatureCollection ext
232           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
233           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
234           */           */
235          public StyledFeatureCollection(FeatureCollection fc, String id,          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
236                          String title, Style style) {                          String title, Style style) {
237                  this(fc, id, title, null, null, style, null, null);                  this(fc, id, title, null, null, style, null, null);
238          }          }
# Line 255  public class StyledFeatureCollection ext Line 254  public class StyledFeatureCollection ext
254           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
255           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
256           */           */
257          public StyledFeatureCollection(FeatureCollection fc, String id,          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
258                          String title, StyledLayerStyle<Map<Integer, AttributeMetaData>> style) {                          String title, StyledLayerStyle<AttributeMetadataMap> style) {
259                  this(fc, id, title, null, null, style != null ? style                  this(fc, id, title, null, null, style != null ? style
260                                  .getGeoObjectStyle() : null, style != null ? style                                  .getGeoObjectStyle() : null, style != null ? style
261                                  .getMetaData() : null, null);                                  .getMetaData() : null, null);
# Line 274  public class StyledFeatureCollection ext Line 273  public class StyledFeatureCollection ext
273          /**          /**
274           * Returns the meta data needed for displaying a legend.           * Returns the meta data needed for displaying a legend.
275           */           */
276          public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {          public AttributeMetadataMap getAttributeMetaDataMap() {
277                  return attrMetaData;                  return attrMetaData;
278          }          }
279    
# Line 287  public class StyledFeatureCollection ext Line 286  public class StyledFeatureCollection ext
286           *            map of attribute meta data           *            map of attribute meta data
287           */           */
288          public void setAttributeMetaData(          public void setAttributeMetaData(
289                          Map<Integer, AttributeMetaData> attrMetaData) {                          AttributeMetadataMap attrMetaData) {
290                  this.attrMetaData = (attrMetaData != null) ? attrMetaData                  this.attrMetaData = (attrMetaData != null) ? attrMetaData
291                                  : createDefaultAttributeMetaDataMap(geoObject);                                  : createDefaultAttributeMetaDataMap(geoObject);
292          }          }
# Line 299  public class StyledFeatureCollection ext Line 298  public class StyledFeatureCollection ext
298           * @param fc           * @param fc
299           *            a {@link FeatureCollection}           *            a {@link FeatureCollection}
300           */           */
301          public static Map<Integer, AttributeMetaData> createDefaultAttributeMetaDataMap(          public static AttributeMetadataMap createDefaultAttributeMetaDataMap(
302                          FeatureCollection fc) {                          FeatureCollection<SimpleFeatureType,SimpleFeature> fc) {
303                  HashMap<Integer, AttributeMetaData> metaDataMap = new HashMap<Integer, AttributeMetaData>();                  AttributeMetadataMap metaDataMap = new AttributeMetadataMap();
304                  SimpleFeatureType ftype = fc.getSchema();                  SimpleFeatureType ftype = fc.getSchema();
305                  for (int i = 0; i < ftype.getAttributeCount(); i++) {                  for (int i = 0; i < ftype.getAttributeCount(); i++) {
306                          AttributeType aType = ftype.getAttributeType(i);                          AttributeDescriptor aType = ftype.getAttributeDescriptors().get(i);
307                          if (aType != ftype.getDefaultGeometry())                          if (aType != ftype.getGeometryDescriptor())
308                                  metaDataMap.put(i, new AttributeMetaData(i, // Column no.                                  metaDataMap.put(i, new AttributeMetaData(i, // Column no.
309                                                  true, // visible                                                  true, // visible
310                                                  new Translation(aType.getName()), // Column name                                                  new Translation(aType.getLocalName()), // Column name
311                                                  new Translation(), // description                                                  new Translation(), // description
312                                                  "" // Unit                                                  "" // Unit
313                                  ));                                  ));
# Line 361  public class StyledFeatureCollection ext Line 360  public class StyledFeatureCollection ext
360           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
361           */           */
362          @Override          @Override
363          public FeatureCollection getFeatureCollection() {          public FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatureCollection() {
364                  return getGeoObject();                  return getGeoObject();
365          }          }
366    
# Line 372  public class StyledFeatureCollection ext Line 371  public class StyledFeatureCollection ext
371           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
372           */           */
373          @Override          @Override
374          public FeatureSource getFeatureSource() {          public FeatureSource<SimpleFeatureType,SimpleFeature> getFeatureSource() {
375                  if (featureSource == null) {                  if (featureSource == null) {
376                          CollectionDataStore store = new CollectionDataStore(getGeoObject());                          CollectionDataStore store = new CollectionDataStore(getGeoObject());
377                          try {                          try {

Legend:
Removed from v.322  
changed lines
  Added in v.422

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26