001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.feature.collection;
017:
018: import org.geotools.feature.CollectionEvent;
019: import org.geotools.feature.CollectionListener;
020: import org.geotools.feature.Feature;
021: import org.geotools.feature.FeatureCollection;
022: import org.geotools.feature.FeatureType;
023:
024: import com.vividsolutions.jts.geom.Envelope;
025:
026: /**
027: * This is *not* a Feature - it is a Delegate used by FeatureCollection
028: * implementations as "mix-in", provides implementation of featureCollection
029: * events, featureType, and attribute access backed by an origional
030: * FeatureCollection.
031: * <p>
032: * To use cut&paste the following code exactly:<pre>
033: * <code>
034: * TBA
035: * </code>
036: * </p>
037: * <p>
038: * On the bright side this means we can "fix" all the SubFeatureCollection
039: * implementationsin one fell-swoop.
040: * </p>
041: *
042: * @author Jody Garnett, Refractions Reserach, Inc.
043: * @since GeoTools 2.2
044: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/feature/collection/SubFeatureState.java $
045: */
046: public class SubFeatureState extends FeatureState {
047: final FeatureCollection collection;
048:
049: final CollectionListener listener = new CollectionListener() {
050: public void collectionChanged(CollectionEvent tce) {
051: bounds = null;
052: }
053: };
054:
055: public SubFeatureState(FeatureCollection collection,
056: FeatureCollection sub) {
057: super (sub);
058: this .collection = collection;
059: collection.addListener(listener);
060: }
061:
062: public void close() {
063: if (listener != null) {
064: collection.removeListener(listener);
065: }
066: bounds = null;
067: }
068:
069: //
070: // FeatureCollection Event Support
071: //
072:
073: /**
074: * Adds a listener for collection events.
075: *
076: * @param listener The listener to add
077: */
078: public void addListener(CollectionListener listener) {
079: collection.addListener(listener);
080: }
081:
082: /**
083: * Removes a listener for collection events.
084: *
085: * @param listener The listener to remove
086: */
087: public void removeListener(CollectionListener listener) {
088: collection.removeListener(listener);
089: }
090:
091: protected void fireChange(Feature[] features, int type) {
092: //
093: }
094:
095: //
096: // Feature Methods
097: //
098: public FeatureType getFeatureType() {
099: return collection.getFeatureType();
100: }
101:
102: public FeatureType getChildFeatureType() {
103: return collection.getSchema();
104: }
105:
106: public String getId() {
107: return collection.getID();
108: }
109:
110: }
|