[Schmitzm-commits] r500 - branches/1.0-gt2-2.6/src/skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Oct 25 17:56:22 CET 2009


Author: alfonx
Date: 2009-10-25 17:56:21 +0100 (Sun, 25 Oct 2009)
New Revision: 500

Modified:
   branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
Der Style wird nur erneuert, wenn die selection sich ge?\195?\164ndert hat. Sollte man denken, dass das sowieso nur passiert? Ja, aber bei einzelnen clicks auf punkte im chart, wurde das styling zweimal gesetzt...



Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-10-25 13:26:54 UTC (rev 499)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-10-25 16:56:21 UTC (rev 500)
@@ -58,6 +58,7 @@
 
 import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.FeatureIterator;
+import org.geotools.filter.FidFilterImpl;
 import org.geotools.map.MapLayer;
 import org.geotools.renderer.GTRenderer;
 import org.geotools.renderer.label.LabelCacheImpl;
@@ -67,6 +68,8 @@
 import org.geotools.styling.visitor.DuplicatingStyleVisitor;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.filter.Filter;
+import org.opengis.filter.Not;
 import org.opengis.filter.identity.FeatureId;
 
 import schmitzm.geotools.FilterUtil;
@@ -78,7 +81,6 @@
 import schmitzm.geotools.styling.StylingUtil;
 import skrueger.geotools.MapPaneToolBar;
 import skrueger.geotools.StyledFeaturesInterface;
-import skrueger.geotools.StyledLayerInterface;
 
 /**
  * This class keeps the selection of a (feature) {@link JTable} synchronized
@@ -189,6 +191,7 @@
 		try {
 
 			Style originalStyle = mapLayer.getStyle();
+
 			if (newSelection.isEmpty()) {
 
 				// Check if the Style contains a SELECTION FTS
@@ -209,8 +212,14 @@
 				}
 
 			} else {
+
 				LOGGER.debug("SELECTION .. change style");
 
+				// Saving a repaint if the selection didn't change
+				if (!selectionChanged(newSelection, originalStyle)) {
+					return;
+				}
+
 				// We take Style from the MapLayer that is displayed at the
 				// moment. We do not use the styledLayer.getStyle, because in
 				// the atlas, this always return the default style, but
@@ -232,7 +241,6 @@
 				 * inverted to be shorter.
 				 * 
 				 */
-
 				final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollectionFiltered = styledLayer
 						.getFeatureCollectionFiltered();
 				if (newSelection.size() > featureCollectionFiltered.size() / 2) {
@@ -288,13 +296,13 @@
 				dsv.visit(originalStyle);
 				Style newStyle = (Style) dsv.getCopy();
 
-//SK-Debug
-//				try {
-////					
-////				StylingUtil.saveStyleToSLD(newStyle, new File(
-////						"/home/stefan/Desktop/selection.sld"));
-//				} catch (Exception e) {
-//				}
+				// SK-Debug
+				try {
+					//
+					StylingUtil.saveStyleToSLD(newStyle, new File(
+							"/home/stefan/Desktop/selection.sld"));
+				} catch (Exception e) {
+				}
 
 				// DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();
 				// dsv.visit(originalStyle);
@@ -312,6 +320,91 @@
 		}
 	}
 
+	/**
+	 * Analyses whether the selection has changed in comparison to the selection
+	 * stored in the mapLayer.Style
+	 * 
+	 * @param newSelection
+	 * @param originalStyle
+	 * @return
+	 */
+	private boolean selectionChanged(Vector<String> newSelection,
+			Style originalStyle) {
+
+		boolean SELECTION_STYLING_foundInMapStyle = false;
+
+		/**
+		 * testing, whether the selection really changed. If not, we can save
+		 * one paint!
+		 */
+		for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
+
+			if (fts.getName() != null
+					&& fts.getName().equals(SELECTION_STYLING)) {
+
+				SELECTION_STYLING_foundInMapStyle = true;
+
+				Filter filter = fts.rules().get(0).getFilter();
+				if (filter instanceof Not) {
+					FidFilterImpl antiOrigFidsFilter = (FidFilterImpl) ((Not) filter)
+							.getFilter();
+
+					// Check one way
+					final Set<String> antiFids = antiOrigFidsFilter
+							.getFidsSet();
+
+					if (antiFids.isEmpty() && !newSelection.isEmpty())
+						return true;
+
+					for (String fid : antiFids) {
+						if (newSelection.contains(fid)) {
+							return true;
+						}
+					}
+
+					// Check the other way
+					for (String fid : newSelection) {
+						if (antiFids.contains(fid)) {
+							return true;
+						}
+					}
+
+				} else {
+					FidFilterImpl origFidsFilter = (FidFilterImpl) filter;
+
+					// Check one way
+					final Set<String> fids = origFidsFilter.getFidsSet();
+
+					if (fids.isEmpty() && newSelection.isEmpty())
+						return false;
+					if (fids.size() != newSelection.size())
+						return true;
+
+					for (String fid : fids) {
+						if (!newSelection.contains(fid)) {
+							return true;
+						}
+					}
+
+					// Check the other way
+					for (String fid : newSelection) {
+						if (!fids.contains(fid)) {
+							return true;
+						}
+					}
+
+				}
+
+				break;
+			}
+		}
+
+		if (!SELECTION_STYLING_foundInMapStyle && !newSelection.isEmpty())
+			return true;
+
+		return false;
+	}
+
 	private void replaceRenderer() {
 		//
 		// // Has to be done before we apply the new Renderer
@@ -382,7 +475,6 @@
 		if (e.getSourceObject() != this.mapPane)
 			return;
 
-
 		/**
 		 * Checking, that the FeatureSelectedEvent actually contains features
 		 * from this layer



More information about the Schmitzm-commits mailing list