[Schmitzm-commits] r158 - in trunk/src/skrueger/geotools: . selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jun 22 15:45:33 CEST 2009


Author: alfonx
Date: 2009-06-22 15:45:32 +0200 (Mon, 22 Jun 2009)
New Revision: 158

Modified:
   trunk/src/skrueger/geotools/MapView.java
   trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
* Changed the Selection-Stlying-Filter: It's now based on GeoTools Filters! The new Filter() { .. } approach is not recommended in GeoTools and will probably produce other problems also. Because the ShapeFileRenderer is optimizing the filters (thats why it's 10 times faster), its doing some stuff that only works on GeoTools Filters:

Which leads to a problem: Any "Martin-Filter" from Schmitzm does not work when using the ShapefileRenderer

Modified: trunk/src/skrueger/geotools/MapView.java
===================================================================
--- trunk/src/skrueger/geotools/MapView.java	2009-06-22 13:01:08 UTC (rev 157)
+++ trunk/src/skrueger/geotools/MapView.java	2009-06-22 13:45:32 UTC (rev 158)
@@ -9,6 +9,7 @@
 import javax.swing.JSplitPane;
 
 import org.apache.log4j.Logger;
+import org.geotools.renderer.lite.StreamingRenderer;
 import org.geotools.renderer.shape.ShapefileRenderer;
 
 import schmitzm.geotools.gui.GeoMapPane;

Modified: trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-06-22 13:01:08 UTC (rev 157)
+++ trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-06-22 13:45:32 UTC (rev 158)
@@ -17,6 +17,8 @@
 import java.beans.PropertyChangeListener;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.JTable;
@@ -24,12 +26,16 @@
 import javax.swing.event.ListSelectionListener;
 
 import org.geotools.feature.Feature;
+import org.geotools.filter.FidFilter;
+import org.geotools.filter.FidFilterImpl;
 import org.geotools.map.MapLayer;
 import org.geotools.styling.FeatureTypeStyle;
 import org.geotools.styling.Style;
 import org.opengis.filter.Filter;
 import org.opengis.filter.FilterVisitor;
+import org.opengis.filter.identity.FeatureId;
 
+import schmitzm.geotools.FilterUtil;
 import schmitzm.geotools.gui.JMapPane;
 import schmitzm.geotools.map.event.FeatureSelectedEvent;
 import schmitzm.geotools.map.event.JMapPaneEvent;
@@ -167,34 +173,28 @@
 				selectionMapStyle.getFeatureTypeStyles()[0]
 						.setName(SELECTION_STYLING);
 
-				// Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule();
-				selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0]
-						.setFilter(new Filter() {
+				/**
+				 * 
+				 * Add a Filter to the selectionMapStyle, so that it is only
+				 * used on objects that are selected. <br/>
+				 * 
+				 * Note 1:<br/>
+				 * It is NEVER allowed to GeoTools extend Filter () { .. } (and write
+				 * tests into the evaluate block). Especially for the
+				 * ShapeFileRenderer, we may only use a geotools Filter.<br/>
+				 * 
+				 * Note 2:<br/>
+				 * The FilterUtil.FILTER_FAC2.id(fids) wants a set of FeatureId-Objects!
+				 */
 
-							@Override
-							public Object accept(FilterVisitor visitor,
-									Object extraData) {
-								return null;
-							}
+				Set<FeatureId> fids = new HashSet<FeatureId>();
+				for (String fid : newSelection) {
+					fids.add(FilterUtil.FILTER_FAC2.featureId(fid));
+				}
 
-							@Override
-							public boolean evaluate(Object obj) {
-								if (obj instanceof Feature) {
-									Feature f = (Feature) obj;
-									// TODO BAD CODE! says Martin.. i am fine
-									// with it.. well.. not great...
-									for (String ffID : newSelection) {
-										if (ffID.equals(f.getID()))
-											return true;
-									}
-									return false;
+				selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0]
+						.setFilter(FilterUtil.FILTER_FAC2.id(fids));
 
-								}
-								return false;
-							}
-
-						});
-
 				FeatureTypeStyle[] originalFeatureTypeStyles = originalStyle
 						.getFeatureTypeStyles();
 				FeatureTypeStyle[] newFeatureTypes;
@@ -258,16 +258,16 @@
 		FeatureSelectedEvent fse = (FeatureSelectedEvent) e;
 
 		/**
-		 * Checking, that the FeatureSelectedEvent actually contains features from this layer 
+		 * Checking, that the FeatureSelectedEvent actually contains features
+		 * from this layer
 		 */
 		final String sourceID = fse.getSourceLayer().getTitle();
 		final String syncForID = mapLayer.getTitle();
 		if (sourceID != null && syncForID != null
-				&& !sourceID.equals(syncForID)){
-			LOGGER.debug("Ignoring a FeatureSelectedEvent from "+sourceID);
+				&& !sourceID.equals(syncForID)) {
+			LOGGER.debug("Ignoring a FeatureSelectedEvent from " + sourceID);
 			return;
 		}
-		
 
 		LOGGER.debug("do event " + fse);
 



More information about the Schmitzm-commits mailing list