[Schmitzm-commits] r867 - in trunk/src: schmitzm/geotools/styling skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 27 00:42:09 CEST 2010


Author: alfonx
Date: 2010-05-27 00:42:07 +0200 (Thu, 27 May 2010)
New Revision: 867

Modified:
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
Added some more methods to create rules and symbolizers to mark selections.

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-05-25 14:10:41 UTC (rev 866)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-05-26 22:42:07 UTC (rev 867)
@@ -43,6 +43,7 @@
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.SortedMap;
@@ -121,11 +122,13 @@
 import org.opengis.filter.Filter;
 import org.opengis.filter.FilterFactory;
 import org.opengis.filter.FilterFactory2;
+import org.opengis.filter.Or;
 import org.opengis.filter.PropertyIsEqualTo;
 import org.opengis.filter.expression.Expression;
 import org.opengis.filter.expression.Function;
 import org.opengis.filter.expression.Literal;
 import org.opengis.filter.expression.PropertyName;
+import org.opengis.filter.spatial.Equals;
 
 import schmitzm.geotools.FilterUtil;
 import schmitzm.geotools.feature.FeatureUtil;
@@ -225,6 +228,8 @@
 							.colorExpression(Color.YELLOW.brighter())), size3,
 					zeroLit) }, new org.geotools.styling.Symbol[0],
 			FeatureUtil.FILTER_FACTORY2.literal(1), size3, zeroLit);
+	
+	public static final String SELECTION_RULE_ID = "SelectionRule marking selected features";
 
 	/**
 	 * Erstellt einen Default-Style fuer die Klassen/Interfaces:
@@ -1090,10 +1095,11 @@
 	 * @return <code>true</code> if the file was really written.
 	 *         <code>false</code> means, that the existing file already was
 	 *         equals.
-	 * @throws IOException 
-	 * @throws TransformerException 
+	 * @throws IOException
+	 * @throws TransformerException
 	 */
-	public static final boolean saveStyleToSLD(Style origStyle, File exportFile) throws TransformerException, IOException {
+	public static final boolean saveStyleToSLD(Style origStyle, File exportFile)
+			throws TransformerException, IOException {
 
 		// Wenn Datei nicht mit .sld endet, die Dateierweiterung
 		// anhängen
@@ -1786,12 +1792,77 @@
 					.getGeometryForm((FeatureSource<SimpleFeatureType, SimpleFeature>) geoObject);
 		}
 
+		return createSelectionStyle(geometryForm);
+
+	}
+
+	/**
+	 * @param geoObject
+	 *            the {@link GeometryForm} the selection style shall be created
+	 *            for.
+	 * 
+	 * @return a {@link Style} that is suitable to identify features of the
+	 *         given type as selected items.
+	 */
+	public static FeatureTypeStyle createSelectionStyle(
+			GeometryForm geometryForm) {
 		// /**
 		// * Let's see if we have a cached version of the requested style.
 		// */
 		// if (selectionStyles.containsKey(geometryForm))
 		// return selectionStyles.get(geometryForm);
 
+		Symbolizer[] symbolizers = createSelectionSymbolizers(geometryForm);
+
+		return STYLE_BUILDER.createFeatureTypeStyle(symbolizers,0.0,
+				Double.POSITIVE_INFINITY);
+	}
+
+	/**
+	 * Creates a rule which paints features as selected.
+	 * 
+	 * @param geometryForm
+	 * @param idPropertyName
+	 * @param selectionIds
+	 * @return
+	 */
+	public static Rule createSelectionRule(GeometryForm geometryForm,
+			String idPropertyName, List<String> selectionIds) {
+
+		if (idPropertyName == null)
+			throw new IllegalArgumentException();
+		if (selectionIds == null)
+			throw new IllegalArgumentException();
+		if (geometryForm == null)
+			throw new IllegalArgumentException();
+
+		Rule rule = STYLE_FACTORY.createRule();
+		rule.setName(SELECTION_RULE_ID);
+
+		// Filter: Eine OR Filter Verknüpfung für jede Selektions EQUALS
+		List<Filter> equals = new ArrayList<Filter>();
+		if (selectionIds.size() > 0) {
+			for (String id : selectionIds) {
+				Equals equal = FilterUtil.FILTER_FAC2.equal(
+						FilterUtil.FILTER_FAC2.literal(id),
+						FilterUtil.FILTER_FAC2.property(idPropertyName));
+				equals.add(equal);
+			}
+			rule.setFilter(FilterUtil.FILTER_FAC2.or(equals));
+		} else {
+			// if nothing is selected, return an empty rule without symbolizers. 
+			return rule;
+		}
+
+		// Symboizers
+		Symbolizer[] symbolizers = createSelectionSymbolizers(geometryForm);
+		rule.symbolizers().addAll(Arrays.asList(symbolizers));
+
+		return rule;
+	}
+
+	public static Symbolizer[] createSelectionSymbolizers(
+			GeometryForm geometryForm) {
 		Symbolizer[] symbolizers = new Symbolizer[0];
 
 		switch (geometryForm) {
@@ -1869,10 +1940,7 @@
 		default:
 			throw new IllegalArgumentException("Provide a suitable object.");
 		}
-
-		return STYLE_BUILDER.createFeatureTypeStyle(symbolizers, Double.NaN,
-				Double.NaN);
-
+		return symbolizers;
 	}
 
 	public static Style createStyleSimple(Object geoObject, Color color,

Modified: trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2010-05-25 14:10:41 UTC (rev 866)
+++ trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2010-05-26 22:42:07 UTC (rev 867)
@@ -220,7 +220,7 @@
 				// moment. We do not use the styledLayer.getStyle, because in
 				// the atlas, this always return the default style, but
 				// additional styles might be selected.
-				// Taking the style from the mapLayer indicated, that we have to
+				// Taking the style from the mapLayer indicates, that we have to
 				// remove any selection rules first.
 
 				FeatureTypeStyle selectionFTStyle = StylingUtil



More information about the Schmitzm-commits mailing list