[Schmitzm-commits] r412 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/styling schmitzm/jfree/chart/style skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Sep 22 19:46:28 CEST 2009


Author: alfonx
Date: 2009-09-22 19:46:26 +0200 (Tue, 22 Sep 2009)
New Revision: 412

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
   branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartType.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
* AV-Feature: Selected polygons are now marked with hatches, so that the underlying color can still be seen. But there seem to be some zoomIn-problems?!?!


Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-09-22 06:55:30 UTC (rev 411)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-09-22 17:46:26 UTC (rev 412)
@@ -103,6 +103,7 @@
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.filter.Filter;
+import org.opengis.filter.FilterFactory;
 import org.opengis.filter.FilterFactory2;
 import org.opengis.filter.expression.Expression;
 import org.opengis.filter.expression.Literal;
@@ -129,6 +130,7 @@
  * @version 1.1
  */
 public class StylingUtil {
+	private static final FilterFactory FILTER_FACTORY = FeatureUtil.FILTER_FACTORY;
 	private static final Logger LOGGER = Logger.getLogger(StylingUtil.class);
 	/** Transparente Farbe */
 	public static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
@@ -181,25 +183,25 @@
 	static final Stroke SELECTION_STROKE1 = STYLE_FACTORY.createStroke(
 			STYLE_BUILDER.colorExpression(Color.YELLOW.brighter()),
 			FeatureUtil.FILTER_FACTORY2.literal(4), FeatureUtil.FILTER_FACTORY2
-					.literal(1.), FeatureUtil.FILTER_FACTORY.literal("round"),
-			FeatureUtil.FILTER_FACTORY.literal("round"), new float[0],
+					.literal(1.), FILTER_FACTORY.literal("round"),
+			FILTER_FACTORY.literal("round"), new float[0],
 			FeatureUtil.FILTER_FACTORY2.literal(0), null, null);
 
 	static final Stroke SELECTION_STROKE2 = STYLE_FACTORY.createStroke(
 			STYLE_BUILDER.colorExpression(Color.BLACK),
 			FeatureUtil.FILTER_FACTORY2.literal(1.5),
-			FeatureUtil.FILTER_FACTORY2.literal(1.), FeatureUtil.FILTER_FACTORY
-					.literal("round"), FeatureUtil.FILTER_FACTORY
-					.literal("round"), new float[] { 3f, 3f },
-			FeatureUtil.FILTER_FACTORY2.literal(0), null, null);
+			FeatureUtil.FILTER_FACTORY2.literal(1.), FILTER_FACTORY
+					.literal("round"), FILTER_FACTORY.literal("round"),
+			new float[] { 3f, 3f }, FeatureUtil.FILTER_FACTORY2.literal(0),
+			null, null);
 
 	static final Stroke SELECTION_STROKE3 = STYLE_FACTORY.createStroke(
 			STYLE_BUILDER.colorExpression(Color.WHITE),
 			FeatureUtil.FILTER_FACTORY2.literal(1.5),
-			FeatureUtil.FILTER_FACTORY2.literal(1.), FeatureUtil.FILTER_FACTORY
-					.literal("round"), FeatureUtil.FILTER_FACTORY
-					.literal("round"), new float[] { 3f, 3f },
-			FeatureUtil.FILTER_FACTORY2.literal(3), null, null);
+			FeatureUtil.FILTER_FACTORY2.literal(1.), FILTER_FACTORY
+					.literal("round"), FILTER_FACTORY.literal("round"),
+			new float[] { 3f, 3f }, FeatureUtil.FILTER_FACTORY2.literal(3),
+			null, null);
 
 	static final Graphic SELECTION_GRAPHIC1 = STYLE_FACTORY.createGraphic(
 			new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
@@ -224,6 +226,7 @@
 							.colorExpression(Color.YELLOW.brighter())), size3,
 					zeroLit) }, new org.geotools.styling.Symbol[0],
 			FeatureUtil.FILTER_FACTORY2.literal(1), size3, zeroLit);
+
 	static final Fill SELECTION_FILL1 = STYLE_FACTORY.createFill(STYLE_BUILDER
 			.colorExpression(Color.RED), null, FeatureUtil.FILTER_FACTORY2
 			.literal(1), STYLE_FACTORY.createGraphic(new ExternalGraphic[0],
@@ -396,13 +399,16 @@
 	 */
 	public static ColorMap getColorMapFromStyle(final Style style) {
 		final List<ColorMap> colorMapsFromStyle = getColorMapsFromStyle(style);
-		if (colorMapsFromStyle.size()>0) return colorMapsFromStyle.get(0);
-		else return null;
+		if (colorMapsFromStyle.size() > 0)
+			return colorMapsFromStyle.get(0);
+		else
+			return null;
 
 	}
 
 	/**
-	 * Liefert alle Farbpaletten aus einem Style, wenn irgendo {@link RasterSymbolizer} enthalten sind.
+	 * Liefert alle Farbpaletten aus einem Style, wenn irgendo
+	 * {@link RasterSymbolizer} enthalten sind.
 	 * 
 	 * @param style
 	 *            Style Wenn <code>null</code>, dann wird style auf
@@ -1528,13 +1534,13 @@
 	 * @return a {@link Style} that is suitable to identify features of the
 	 *         given type as selected items.
 	 */
-	public static Style createSelectionStyle(Object geoObject) {
+	public static FeatureTypeStyle createSelectionStyle(Object geoObject) {
 
 		if (geoObject instanceof GridCoverage2D
 				|| geoObject instanceof org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) {
 			// Wenn irgendwann mal selection für raster möglich ist, dann hier
 			// einen schöneren style erstellen.
-			return GridUtil.createDefaultStyle();
+			return GridUtil.createDefaultStyle().featureTypeStyles().get(0);
 		}
 
 		// We have vector-data. Now let's determine the type...
@@ -1557,8 +1563,6 @@
 		// if (selectionStyles.containsKey(geometryForm))
 		// return selectionStyles.get(geometryForm);
 
-		Style style = STYLE_FACTORY.createStyle();
-		style.addFeatureTypeStyle(STYLE_FACTORY.createFeatureTypeStyle());
 		Symbolizer[] symbolizers = new Symbolizer[0];
 
 		switch (geometryForm) {
@@ -1578,46 +1582,104 @@
 
 			break;
 		case POLYGON:
+			{ // Black
+				Stroke outline = STYLE_BUILDER.createStroke(
+						Color.red, 3);
+				Mark dots = STYLE_BUILDER.createMark("shape://backslash");
+				dots.setStroke(STYLE_BUILDER.createStroke(Color.red, 3.));
+				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null, dots,
+						null);
+				fillGraphic.setSize(FILTER_FACTORY.literal(9.));
+				Fill fill = STYLE_BUILDER.createFill();
+				fill.setGraphicFill(fillGraphic);
+				PolygonSymbolizer polS0 = STYLE_BUILDER
+				.createPolygonSymbolizer(outline, fill);
+				symbolizers = LangUtil.extendArray(symbolizers, polS0);
+			}
 
-			PolygonSymbolizer polS0 = STYLE_FACTORY.createPolygonSymbolizer();
+			{ // White
+				Stroke outline = STYLE_BUILDER.createStroke(
+						Color.yellow.brighter(), 1);
+				Mark dots = STYLE_BUILDER.createMark("shape://backslash");
+				dots.setStroke(STYLE_BUILDER.createStroke(Color.yellow.brighter(), 1.));
+				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null, dots,
+						null);
+				fillGraphic.setSize(FILTER_FACTORY.literal(9.));
+				Fill fill = STYLE_BUILDER.createFill();
+				fill.setGraphicFill(fillGraphic);
+				PolygonSymbolizer polS0 = STYLE_BUILDER
+						.createPolygonSymbolizer(outline, fill);
+				symbolizers = LangUtil.extendArray(symbolizers, polS0);
+			}
+//			{ // White
+//				Mark dots = STYLE_BUILDER.createMark("shape://slash");
+//				dots.setStroke(STYLE_BUILDER.createStroke(Color.white, 2.));
+//				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null, dots,
+//						null);
+//				fillGraphic.setSize(FILTER_FACTORY.literal(4.));
+//				Fill fill = STYLE_BUILDER.createFill();
+//				fill.setGraphicFill(fillGraphic);
+//				PolygonSymbolizer polS0 = STYLE_BUILDER
+//						.createPolygonSymbolizer(null, fill);
+//				symbolizers = LangUtil.extendArray(symbolizers, polS0);
+//			}
+//			{ // Black
+//				Mark dots = STYLE_BUILDER.createMark("shape://slash");
+//				dots.setStroke(STYLE_BUILDER.createStroke(Color.black, 2.));
+//				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null, dots,
+//						null);
+//				fillGraphic.setSize(FILTER_FACTORY.literal(8.));
+//				Fill fill = STYLE_BUILDER.createFill();
+//				fill.setGraphicFill(fillGraphic);
+//				PolygonSymbolizer polS0 = STYLE_BUILDER
+//				.createPolygonSymbolizer(outline, fill);
+//				symbolizers = LangUtil.extendArray(symbolizers, polS0);
+//			}
+//
+//			{ // Yellow
+//				Mark dots = STYLE_BUILDER.createMark("shape://dot");
+//				dots.setStroke(STYLE_BUILDER.createStroke(Color.yellow.brighter()));
+//				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null, dots,
+//						null);
+//				fillGraphic.setSize(FILTER_FACTORY.literal(5.));
+//				Fill fill = STYLE_BUILDER.createFill();
+//				fill.setGraphicFill(fillGraphic);
+//				PolygonSymbolizer polS0 = STYLE_BUILDER
+//						.createPolygonSymbolizer(null, fill);
+//				symbolizers = LangUtil.extendArray(symbolizers, polS0);
+//			}			
 
-			Fill SELECTION_FILL0 = STYLE_FACTORY.createFill(STYLE_BUILDER
-					.colorExpression(Color.YELLOW.brighter()));
+			break;
 
-			polS0.setFill(SELECTION_FILL0);
-			symbolizers = LangUtil.extendArray(symbolizers, polS0);
+		case LINE:
+			// LineSymbolizer ls = STYLE_FACTORY.createLineSymbolizer();
+			// ls.setStroke(SELECTION_STROKE1);
+			// symbolizers = LangUtil.extendArray(symbolizers, ls);
+			//
+			// LineSymbolizer ls2 = STYLE_FACTORY.createLineSymbolizer();
+			// ls2.setStroke(SELECTION_STROKE2);
+			// symbolizers = LangUtil.extendArray(symbolizers, ls2);
+			//
+			// LineSymbolizer ls3 = STYLE_FACTORY.createLineSymbolizer();
+			// ls3.setStroke(SELECTION_STROKE3);
+			// symbolizers = LangUtil.extendArray(symbolizers, ls3);
 
-			PolygonSymbolizer polS = STYLE_FACTORY.createPolygonSymbolizer();
-			polS.setFill(SELECTION_FILL1);
-			symbolizers = LangUtil.extendArray(symbolizers, polS);
-
-		case LINE:
-			LineSymbolizer ls = STYLE_FACTORY.createLineSymbolizer();
-			ls.setStroke(SELECTION_STROKE1);
+			LineSymbolizer ls = STYLE_BUILDER.createLineSymbolizer(Color.red,
+					3.);
 			symbolizers = LangUtil.extendArray(symbolizers, ls);
 
-			LineSymbolizer ls2 = STYLE_FACTORY.createLineSymbolizer();
-			ls2.setStroke(SELECTION_STROKE2);
+			LineSymbolizer ls2 = STYLE_BUILDER.createLineSymbolizer(
+					Color.white, 1.);
 			symbolizers = LangUtil.extendArray(symbolizers, ls2);
-
-			LineSymbolizer ls3 = STYLE_FACTORY.createLineSymbolizer();
-			ls3.setStroke(SELECTION_STROKE3);
-			symbolizers = LangUtil.extendArray(symbolizers, ls3);
 			break;
 
 		default:
 			throw new IllegalArgumentException("Provide a suitable object.");
 		}
 
-		style.getFeatureTypeStyles()[0].setRules(new Rule[] { STYLE_FACTORY
-				.createRule() });
-		style.getFeatureTypeStyles()[0].getRules()[0]
-				.setSymbolizers(symbolizers);
+		return STYLE_BUILDER.createFeatureTypeStyle(symbolizers, Double.NaN,
+				Double.NaN);
 
-		// selectionStyles.put(geometryForm, style);
-
-		return style;
-
 	}
 
 	public static Style createStyleSimple(Object geoObject, Color color,
@@ -1850,11 +1912,11 @@
 			fill.setColor(STYLE_BUILDER.colorExpression(newColor));
 
 		replaceGraphicColor(fill.getGraphicFill(), oldColor, newColor);
-//
-//		if ((fill.getBackgroundColor() != null)
-//				&& (getColorFromExpression(fill.getBackgroundColor())
-//						.equals(oldColor)))
-//			fill.setBackgroundColor(STYLE_BUILDER.colorExpression(newColor));
+		//
+		// if ((fill.getBackgroundColor() != null)
+		// && (getColorFromExpression(fill.getBackgroundColor())
+		// .equals(oldColor)))
+		// fill.setBackgroundColor(STYLE_BUILDER.colorExpression(newColor));
 	}
 
 	/**
@@ -2052,9 +2114,9 @@
 	public static void copyAllValues(final TextSymbolizer from,
 			final TextSymbolizer to) {
 		to.setLabel(from.getLabel());
-		
-		//TODO Does not copy all that has to be copoied!
 
+		// TODO Does not copy all that has to be copoied!
+
 		final FilterFactory2 ff2 = FeatureUtil.FILTER_FACTORY2;
 
 		to.getFonts()[0].setFontFamily(ff2.literal(from.getFonts()[0]
@@ -2072,29 +2134,28 @@
 	 */
 	public static List<RasterSymbolizer> getRasterSymbolizers(Style style) {
 		final List<RasterSymbolizer> rsList = new ArrayList<RasterSymbolizer>();
-//		
-//		final DuplicatingStyleVisitor collectRSVisitor = new DuplicatingStyleVisitor() {
-//			@Override
-//			public void visit(RasterSymbolizer rs) {
-//				rsList.add(rs);
-//			}; 
-//		};
-//		
-//		collectRSVisitor.visit(symb);
-		
+		//		
+		// final DuplicatingStyleVisitor collectRSVisitor = new
+		// DuplicatingStyleVisitor() {
+		// @Override
+		// public void visit(RasterSymbolizer rs) {
+		// rsList.add(rs);
+		// };
+		// };
+		//		
+		// collectRSVisitor.visit(symb);
+
 		for (FeatureTypeStyle fts : style.featureTypeStyles()) {
 			for (Rule r : fts.rules()) {
-				for (Symbolizer symb : r.getSymbolizers()){
-					if (symb instanceof RasterSymbolizer){
+				for (Symbolizer symb : r.getSymbolizers()) {
+					if (symb instanceof RasterSymbolizer) {
 						rsList.add((RasterSymbolizer) symb);
 					}
 				}
 			}
 		}
-		
+
 		return rsList;
 	}
-	
-	
 
 }

Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartType.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartType.java	2009-09-22 06:55:30 UTC (rev 411)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ChartType.java	2009-09-22 17:46:26 UTC (rev 412)
@@ -75,13 +75,15 @@
 	public ImageIcon getPreviewIcon() {
 		final String fileName = getClass().getSimpleName() + "_" + toString();
 
-		final String imageResPath = "../../resource/images/" + fileName
+		final String imageResPath = "resource/images/" + fileName
 				+ "_preview.png";
 
 		// LOGGER.debug("Looking for image " + imageResPath);
-		final URL imageUrl = ChartStyle.class.getResource(imageResPath);
-
+		final URL imageUrl = JFreeChartUtil.class.getResource(imageResPath);
+		
 		if (imageUrl == null) {
+			LOGGER.warn(imageResPath + "not found!");
+			
 			// Create a default icon
 			final BufferedImage bufferedImage = new BufferedImage(300, 200,
 					BufferedImage.TYPE_INT_RGB);

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-09-22 06:55:30 UTC (rev 411)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-09-22 17:46:26 UTC (rev 412)
@@ -172,13 +172,25 @@
 	 *            A {@link Vector} of SimpleFeature-IDs that are selected.
 	 */
 	private void changeLayerStyle(final Vector<String> newSelection) {
-		Style selectionMapStyle = null;
 		try {
+			Style originalStyle = mapLayer.getStyle();
 			if (newSelection.isEmpty()) {
 
-				selectionMapStyle = styledLayer.getStyle();
-				// LOGGER.debug("NO SELECTION .. set to original style directly");
+				// Check if the Style contains a SELECTION FTS
+				
+				FeatureTypeStyle[] clone = originalStyle.featureTypeStyles().toArray( new FeatureTypeStyle[] {} ).clone();
+				
+				for (FeatureTypeStyle fts : clone) {
+					if (fts.getName() != null
+							&& fts.getName().equals(SELECTION_STYLING)) {
+						originalStyle.featureTypeStyles().remove(fts);
+						
+						mapPane.refresh();
 
+						return;
+					}
+				}
+
 			} else {
 				LOGGER.debug("SELECTION .. change style");
 
@@ -188,17 +200,11 @@
 				// additional styles might be selected.
 				// Taking the style from the mapLayer indicated, that we have to
 				// remove any selection rules first.
-				Style originalStyle = mapLayer.getStyle();
 
-				// TODO The default style is not good here. We need
-				// .createSelectionStyle(normalStyle, geoObj);
-				selectionMapStyle = StylingUtil
+				FeatureTypeStyle selectionFTStyle = StylingUtil
 						.createSelectionStyle(styledLayer.getGeoObject());
-				// selectionMapStyle = StylingUtil
-				// .createDefaultStyle(styledLayer.getGeoObject());
 
-				selectionMapStyle.getFeatureTypeStyles()[0]
-						.setName(SELECTION_STYLING);
+				selectionFTStyle.setName(SELECTION_STYLING);
 
 				/**
 				 * 
@@ -220,32 +226,29 @@
 					fids.add(FilterUtil.FILTER_FAC2.featureId(fid));
 				}
 
-				selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0]
-						.setFilter(FilterUtil.FILTER_FAC2.id(fids));
+				selectionFTStyle.rules().get(0).setFilter(
+						FilterUtil.FILTER_FAC2.id(fids));
 
-				FeatureTypeStyle[] originalFeatureTypeStyles = originalStyle
-						.getFeatureTypeStyles();
-				FeatureTypeStyle[] newFeatureTypes;
-				if (originalFeatureTypeStyles[originalFeatureTypeStyles.length - 1]
-						.getName() != null
-						&& originalFeatureTypeStyles[originalFeatureTypeStyles.length - 1]
-								.getName().equals(SELECTION_STYLING)) {
-					newFeatureTypes = Arrays.copyOf(originalFeatureTypeStyles,
-							originalFeatureTypeStyles.length - 1);
-				} else {
-					newFeatureTypes = originalFeatureTypeStyles;
+				// Maybe there has already been another selection
+				// FeatureTypeStyle... Let's replace it...
+				boolean foundAndReplaced = false;
+				for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
+					if (fts.getName() != null
+							&& fts.getName().equals(SELECTION_STYLING)) {
+						foundAndReplaced = true;
+						fts.rules().clear();
+						fts.rules().addAll(selectionFTStyle.rules());
+						break;
+					}
 				}
+				if (!foundAndReplaced) {
+					originalStyle.featureTypeStyles().add(selectionFTStyle);
+				}
 
-				// The last FTS is the selection FTS
-				newFeatureTypes = LangUtil.extendArray(newFeatureTypes,
-						selectionMapStyle.getFeatureTypeStyles());
-
-				selectionMapStyle.setFeatureTypeStyles(newFeatureTypes);
-
+				// Refresh the map
+				mapPane.refresh();
 			}
 
-			mapLayer.setStyle(selectionMapStyle);
-			mapPane.refresh();
 		} catch (Exception e) {
 			LOGGER.error("Error while trying to create a selection style", e);
 		}



More information about the Schmitzm-commits mailing list