[Schmitzm-commits] r301 - in trunk/src/schmitzm: geotools/styling jfree/chart/style

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Aug 15 19:28:40 CEST 2009


Author: alfonx
Date: 2009-08-15 19:28:39 +0200 (Sat, 15 Aug 2009)
New Revision: 301

Modified:
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
Log:
* Added some DEBUG output for "renderSeriesShapes"

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-08-15 10:33:43 UTC (rev 300)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-08-15 17:28:39 UTC (rev 301)
@@ -844,7 +844,8 @@
 	public static Style[] loadSLD(URL url) {
 		// LOGGER.debug("Loading styles from URL...");
 		try {
-			return loadSLD(url.openStream());
+			final InputStream openStream = url.openStream();
+			return loadSLD(openStream);
 		} catch (IOException e) {
 			return null;
 		}
@@ -868,7 +869,7 @@
 			return null;
 		}
 
-//		LOGGER.debug("Loading styles from inputStream...");
+		// LOGGER.debug("Loading styles from inputStream...");
 
 		SLDParser stylereader;
 		stylereader = new SLDParser(StylingUtil.STYLE_FACTORY);
@@ -879,9 +880,9 @@
 			LOGGER
 					.warn(" ... no Styles recognized in inputStream. Will return empty styles[] array!");
 		} else {
-//			LOGGER.debug(" ... loaded " + styles.length
-//					+ " styles from inputStream, first style's name= "
-//					+ styles[0].getName());
+			// LOGGER.debug(" ... loaded " + styles.length
+			// + " styles from inputStream, first style's name= "
+			// + styles[0].getName());
 		}
 
 		// This is the main successful exit form loadSLD
@@ -970,16 +971,20 @@
 	public static final void saveStyleToSLD(Style style, File exportFile,
 			Charset charset) throws TransformerException, IOException {
 		Writer w = null;
+
 		if (charset != null) {
+			LOGGER
+					.warn("Explicitly setting the Chartset to "
+							+ charset
+							+ "! Steve thinks that this is a bad idea, because it doesn't"
+							+ " transform the content but just declares the header.");
 			SLDTRANSFORMER.setEncoding(charset);
 		}
 		SLDTRANSFORMER.setIndentation(2);
-		final String xml = SLDTRANSFORMER.transform(style);
-		w = new FileWriter(exportFile);
-		w.write(xml);
-		w.close();
-		LOGGER.info("Saved a Style to " + exportFile + " with charset "
-				+ SLDTRANSFORMER.getEncoding().name());
+		SLDTRANSFORMER.transform(style, new FileWriter(exportFile));
+
+		LOGGER.info("Saved a Style with charset "
+				+ SLDTRANSFORMER.getEncoding().name() + " to " + exportFile);
 	}
 
 	/**
@@ -1119,7 +1124,7 @@
 				}
 			}
 		} catch (final java.lang.IllegalStateException e) {
-			LOGGER.error("Iterating over the features",e);
+			LOGGER.error("Iterating over the features", e);
 			/**
 			 * SK: 14.Apri 2009. It happened a few time to that fcIt.hasNext
 			 * suddenly threw an exception for the "africa countries.shp":
@@ -1189,7 +1194,7 @@
 			}
 
 		} catch (final Exception e) {
-			LOGGER.error("error - filter API stuff?",e);
+			LOGGER.error("error - filter API stuff?", e);
 			return null;
 		}
 		return null;
@@ -1220,7 +1225,7 @@
 			}
 
 		} catch (final Exception e) {
-			LOGGER.error("error - filter API stuff?",e);
+			LOGGER.error("error - filter API stuff?", e);
 			return results;
 		}
 		return results;
@@ -1252,7 +1257,7 @@
 			}
 
 		} catch (final Exception e) {
-			LOGGER.error("error - filter API stuff?",e);
+			LOGGER.error("error - filter API stuff?", e);
 			return results;
 		}
 		return results;
@@ -1359,12 +1364,12 @@
 			PointSymbolizer ps = (PointSymbolizer) sym;
 			Graphic graphic = ps.getGraphic();
 
-// That bugfix was needed in 2.4.5 before we patched the StyleFactoryImpl			
+			// That bugfix was needed in 2.4.5 before we patched the
+			// StyleFactoryImpl
 			if (graphic.getSize() instanceof NilExpression) {
 				graphic.setSize(FilterUtil.FILTER_FAC.literal(10.));
 			}
-			
-			
+
 			try {
 				SLDTRANSFORMER.transform(graphic);
 			} catch (TransformerException e) {
@@ -1570,8 +1575,9 @@
 		return style;
 
 	}
-	
-	public static Style createStyleSimple(Object geoObject, Color color, Color color2) {
+
+	public static Style createStyleSimple(Object geoObject, Color color,
+			Color color2) {
 		if (geoObject instanceof GridCoverage2D
 				|| geoObject instanceof org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) {
 			// Wenn irgendwann mal selection für raster möglich ist, dann hier
@@ -1606,20 +1612,28 @@
 		switch (geometryForm) {
 
 		case POINT:
-			PointSymbolizer ps = STYLE_BUILDER.createPointSymbolizer(STYLE_BUILDER.createGraphic(null, STYLE_BUILDER.createMark("circle"), null));
-			ps.getGraphic().getMarks()[0].setFill(STYLE_BUILDER.createFill(color, 0.5));
-			ps.getGraphic().getMarks()[0].setSize(STYLE_BUILDER.literalExpression(8.));
+			PointSymbolizer ps = STYLE_BUILDER
+					.createPointSymbolizer(STYLE_BUILDER.createGraphic(null,
+							STYLE_BUILDER.createMark("circle"), null));
+			ps.getGraphic().getMarks()[0].setFill(STYLE_BUILDER.createFill(
+					color, 0.5));
+			ps.getGraphic().getMarks()[0].setSize(STYLE_BUILDER
+					.literalExpression(8.));
 			ps.getGraphic().setSize(STYLE_BUILDER.literalExpression(8.));
-			ps.getGraphic().getMarks()[0].setStroke(STYLE_BUILDER.createStroke(color2));
+			ps.getGraphic().getMarks()[0].setStroke(STYLE_BUILDER
+					.createStroke(color2));
 			symbolizers = LangUtil.extendArray(symbolizers, ps);
 
 			break;
 		case POLYGON:
-			PolygonSymbolizer polS = STYLE_BUILDER.createPolygonSymbolizer(STYLE_BUILDER.createStroke(color2), STYLE_BUILDER.createFill(color));
+			PolygonSymbolizer polS = STYLE_BUILDER.createPolygonSymbolizer(
+					STYLE_BUILDER.createStroke(color2), STYLE_BUILDER
+							.createFill(color));
 			symbolizers = LangUtil.extendArray(symbolizers, polS);
 
 		case LINE:
-			LineSymbolizer ls = STYLE_BUILDER.createLineSymbolizer(STYLE_BUILDER.createStroke(color));
+			LineSymbolizer ls = STYLE_BUILDER
+					.createLineSymbolizer(STYLE_BUILDER.createStroke(color));
 			symbolizers = LangUtil.extendArray(symbolizers, ls);
 			break;
 
@@ -1634,26 +1648,28 @@
 
 		return style;
 	}
-	
 
 	/**
 	 * Creates a {@link Box} that shows a legend for a list of
 	 * {@link FeatureTypeStyle}s and a targeted featureType
 	 * 
-	 * @param featureType If this a legend for Point, Polygon or Line?
-	 * @param featureTypeStyles The Styles to presen in this legend
+	 * @param featureType
+	 *            If this a legend for Point, Polygon or Line?
+	 * @param featureTypeStyles
+	 *            The Styles to presen in this legend
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
 	 */
-	public static Box createLegendPanel(
-			FeatureTypeStyle[] featureTypeStyles, FeatureType featureType) {
+	public static Box createLegendPanel(FeatureTypeStyle[] featureTypeStyles,
+			FeatureType featureType) {
 
-		Box box = new Box(BoxLayout.Y_AXIS){
+		Box box = new Box(BoxLayout.Y_AXIS) {
 
 			/**
-			 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
-			 * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
+			 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot
+			 * gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS
+			 * gesetzt.
 			 * 
 			 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 			 *         Kr&uuml;ger</a>
@@ -1685,20 +1701,22 @@
 						.size() == rule.getSymbolizers().length)
 					continue;
 
-				Box hbox = new Box( BoxLayout.X_AXIS){
+				Box hbox = new Box(BoxLayout.X_AXIS) {
 
 					/**
-					 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot gemacht
-					 * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt.
+					 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein
+					 * Screenshot gemacht wird) wird. Dann werden wird der
+					 * Hintergrund auf WEISS gesetzt.
 					 * 
-					 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
-					 *         Kr&uuml;ger</a>
+					 * @author <a href="mailto:skpublic at wikisquare.de">Stefan
+					 *         Alfons Kr&uuml;ger</a>
 					 */
 					@Override
 					public void print(Graphics g) {
 						final Color orig = getBackground();
 						setBackground(Color.WHITE);
-						// wrap in try/finally so that we always restore the state
+						// wrap in try/finally so that we always restore the
+						// state
 						try {
 							super.print(g);
 						} finally {
@@ -1708,12 +1726,14 @@
 				};
 
 				/**
-				 * The size of the legend Symbol is dependent on the size of the font.
+				 * The size of the legend Symbol is dependent on the size of the
+				 * font.
 				 */
-				final int fontHeight = new JLabel().getFontMetrics(new JLabel().getFont()).getHeight();
-				final Dimension ICON_SIZE = new Dimension(23, fontHeight > 5 ? fontHeight : 5);
+				final int fontHeight = new JLabel().getFontMetrics(
+						new JLabel().getFont()).getHeight();
+				final Dimension ICON_SIZE = new Dimension(23,
+						fontHeight > 5 ? fontHeight : 5);
 
-
 				// ****************************************************************************
 				// Create the actual icon
 				// ****************************************************************************
@@ -1742,7 +1762,8 @@
 
 				final JLabel classTitleLabel = new JLabel(labelT.toString());
 				hbox.add(classTitleLabel);
-				classTitleLabel.setLabelFor(iconLabel); // Whatever it is good for
+				classTitleLabel.setLabelFor(iconLabel); // Whatever it is good
+				// for
 
 				box.add(hbox);
 
@@ -1752,7 +1773,6 @@
 		return box;
 	}
 
-
 	//
 	// /**
 	// * Doubles the number of palettes by adding the reverse palette to every
@@ -1796,8 +1816,6 @@
 	//
 	// return newPalettes;
 	// }
-	
-	
 
 	/**
 	 * Replaces the "main" color in a given {@link Symbolizer} element
@@ -1841,7 +1859,6 @@
 		replaceStrokeColor(ps.getStroke(), oldColor, newColor);
 	}
 
-	
 	/**
 	 * Replaces the "main" color in a given {@link PointSymbolizer} element
 	 * 
@@ -1856,7 +1873,6 @@
 		replaceGraphicColor(ps.getGraphic(), oldColor, newColor);
 	}
 
-
 	/**
 	 * Replaces the "main" color in a given {@link PolygonSymbolizer} element
 	 * 
@@ -1874,7 +1890,8 @@
 
 	/**
 	 * Replaces the "main" color in a given {@link Stroke} element
-	 * @param stroke 
+	 * 
+	 * @param stroke
 	 * @param oldColor
 	 * @param newColor
 	 */
@@ -1884,8 +1901,11 @@
 			return;
 
 		if ((stroke.getColor() != null)
-				&& (StylingUtil.getColorFromExpression(stroke.getColor()).equals(oldColor)))
-			stroke.setColor(StylingUtil.STYLE_BUILDER.colorExpression(newColor));
+				&& (StylingUtil.getColorFromExpression(stroke.getColor())
+						.equals(oldColor)))
+			stroke
+					.setColor(StylingUtil.STYLE_BUILDER
+							.colorExpression(newColor));
 
 		replaceGraphicColor(stroke.getGraphicFill(), oldColor, newColor);
 
@@ -1895,6 +1915,7 @@
 
 	/**
 	 * Replaces the "main" color in a given {@link Fill} element
+	 * 
 	 * @param fill
 	 * @param oldColor
 	 * @param newColor
@@ -1940,7 +1961,6 @@
 		}
 	}
 
-
 	/**
 	 * @return the {@link Color} used in the {@link Graphic} or null, if an
 	 *         {@link ExternalGraphic} is used.
@@ -2019,7 +2039,7 @@
 
 		return foundColor;
 	}
-	
+
 	/**
 	 * @return the first {@link Color} used in a {@link Symbolizer}.
 	 * 
@@ -2048,7 +2068,6 @@
 		return null;
 	}
 
-	
 	/**
 	 * @return the first {@link Color} used in a {@link LineSymbolizer}.
 	 * 
@@ -2067,7 +2086,6 @@
 		return foundColor;
 	}
 
-
 	/**
 	 * @return the first {@link Color} used in a {@link PolygonSymbolizer}.
 	 * 
@@ -2089,7 +2107,6 @@
 		return foundColor;
 	}
 
-
 	/**
 	 * @return the first {@link Color} used in a {@link PointSymbolizer}.
 	 * 
@@ -2103,13 +2120,14 @@
 		return getGraphicColor(ps.getGraphic());
 	}
 
-
 	/***************************************************************************
 	 * Copies all Values from one {@link TextSymbolizer} to another
 	 * {@link TextSymbolizer}
 	 * 
-	 * @param from {@link TextSymbolizer} source
-	 * @param to {@link TextSymbolizer} target. May not be <code>null</code>.
+	 * @param from
+	 *            {@link TextSymbolizer} source
+	 * @param to
+	 *            {@link TextSymbolizer} target. May not be <code>null</code>.
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
@@ -2117,9 +2135,9 @@
 	public static void copyAllValues(final TextSymbolizer from,
 			final TextSymbolizer to) {
 		to.setLabel(from.getLabel());
-		
+
 		final FilterFactory2 ff2 = FeatureUtil.FILTER_FACTORY2;
-		
+
 		to.getFonts()[0].setFontFamily(ff2.literal(from.getFonts()[0]
 				.getFontFamily().toString()));
 		to.getFonts()[0].setFontSize(ff2.literal(from.getFonts()[0]
@@ -2130,5 +2148,4 @@
 				.getFontStyle().toString()));
 	}
 
-
 }

Modified: trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java	2009-08-15 10:33:43 UTC (rev 300)
+++ trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java	2009-08-15 17:28:39 UTC (rev 301)
@@ -30,6 +30,7 @@
 package schmitzm.jfree.chart.style;
 
 import java.awt.Color;
+import java.awt.Shape;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -305,8 +306,16 @@
     // Apply shape visibility
     for (int series : seriesShapesVisible.keySet())
       try {
-        if ( isSeriesShapesVisible(series) != null )
-          renderer.setSeriesShape(series, isSeriesShapesVisible(series) ? AbstractRenderer.DEFAULT_SHAPE : null, false);
+        if ( isSeriesShapesVisible(series) != null ) {
+			final Shape shape = isSeriesShapesVisible(series) ? 
+			  AbstractRenderer.DEFAULT_SHAPE
+			  : null;
+			renderer.setSeriesShape(series,
+					  shape,
+					  false);
+			LOGGER.debug("Setting shape = "+shape +" for series "+series);
+		}
+        
       } catch (Exception err) {
         LOGGER.warn("Renderer contains not series "+series+". Shapes visibility can not be applied.");
       }



More information about the Schmitzm-commits mailing list