[Schmitzm-commits] r1145 - in trunk: src/schmitzm/geotools/gui src/schmitzm/geotools/styling src/schmitzm/lang src/skrueger/geotools src_junit/schmitzm/geotools/gui

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Oct 18 01:56:08 CEST 2010


Author: alfonx
Date: 2010-10-18 01:56:07 +0200 (Mon, 18 Oct 2010)
New Revision: 1145

Modified:
   trunk/src/schmitzm/geotools/gui/XMapPane.java
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/schmitzm/lang/LangUtil.java
   trunk/src/skrueger/geotools/RenderingExecutor.java
   trunk/src_junit/schmitzm/geotools/gui/XMapPaneTest.java
Log:
AtlasStyler now allows to configure textclasses per language... still a bit experimental

Modified: trunk/src/schmitzm/geotools/gui/XMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/XMapPane.java	2010-10-17 00:53:34 UTC (rev 1144)
+++ trunk/src/schmitzm/geotools/gui/XMapPane.java	2010-10-17 23:56:07 UTC (rev 1145)
@@ -19,6 +19,8 @@
 import java.awt.geom.NoninvertibleTransformException;
 import java.awt.geom.Point2D;
 import java.awt.image.BufferedImage;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -30,10 +32,10 @@
 import javax.swing.border.Border;
 
 import org.apache.log4j.Logger;
-import org.geotools.data.FeatureSource;
 import org.geotools.data.memory.MemoryFeatureCollection;
 import org.geotools.factory.GeoTools;
 import org.geotools.feature.FeatureCollection;
+import org.geotools.filter.function.EnvFunction;
 import org.geotools.geometry.DirectPosition2D;
 import org.geotools.geometry.jts.JTS;
 import org.geotools.geometry.jts.ReferencedEnvelope;
@@ -75,6 +77,7 @@
 import schmitzm.swing.SwingUtil;
 import schmitzm.swing.event.MouseInputType;
 import skrueger.geotools.RenderingExecutor;
+import skrueger.i8n.Translation;
 
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
@@ -275,10 +278,9 @@
 			try {
 				return ((MapMouseEvent) e).getMapPosition();
 			} catch (final Exception err) {
-				LOGGER
-						.error(
-								"return ((GeoMouseEvent) e).getMapCoordinate(null).toPoint2D();",
-								err);
+				LOGGER.error(
+						"return ((GeoMouseEvent) e).getMapCoordinate(null).toPoint2D();",
+						err);
 			}
 
 		// aktuelle Geo-Position ueber Transformation des JMapPane berechnen
@@ -591,6 +593,19 @@
 	 **/
 	private boolean showExceptions = false;
 
+	/**
+	 * Change the render language of this XMapPane when the translation is
+	 * changed.
+	 */
+	private PropertyChangeListener activeLanguageChangeListener = new PropertyChangeListener() {
+
+		@Override
+		public void propertyChange(PropertyChangeEvent evt) {
+			setRenderLanguage((String) evt.getNewValue());
+			refresh();
+		}
+	};
+
 	public XMapPane() {
 		this(null, null);
 	}
@@ -612,6 +627,9 @@
 
 		super(true);
 
+		setRenderLanguage(Translation.getActiveLang());
+		Translation.addActiveLangChangeListener(activeLanguageChangeListener);
+
 		stopBlinkTimer = initBlinkTimer();
 
 		// A default setting
@@ -866,19 +884,20 @@
 				// LOGGER.debug("Moving area down by " + divY);
 
 				newArea = new Envelope(new Coordinate(newArea.getMinX(),
-						newArea.getMinY() - divY), new Coordinate(newArea
-						.getMaxX(), newArea.getMaxY() - divY));
+						newArea.getMinY() - divY), new Coordinate(
+						newArea.getMaxX(), newArea.getMaxY() - divY));
 
 				if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
 					// LOGGER.debug("Now it exeeds the bottom border.. cut!");
 					// And cut the bottom if it moved out of the area
 					newArea = new Envelope(new Coordinate(newArea.getMinX(),
-							maxAllowedExtend.getMinY()), new Coordinate(newArea
-							.getMaxX(), newArea.getMaxY()));
+							maxAllowedExtend.getMinY()), new Coordinate(
+							newArea.getMaxX(), newArea.getMaxY()));
 
 					// LOGGER.debug("and fix aspect ratio");
 
-					newArea = JTSUtil.fixAspectRatio(getMapPaneSize(),
+					newArea = JTSUtil.fixAspectRatio(
+							getMapPaneSize(),
 							new ReferencedEnvelope(newArea, env
 									.getCoordinateReferenceSystem()), false);
 				}
@@ -891,19 +910,20 @@
 				// LOGGER.debug("Moving area up by " + divY);
 
 				newArea = new Envelope(new Coordinate(newArea.getMinX(),
-						newArea.getMinY() - divY), new Coordinate(newArea
-						.getMaxX(), newArea.getMaxY() - divY));
+						newArea.getMinY() - divY), new Coordinate(
+						newArea.getMaxX(), newArea.getMaxY() - divY));
 
 				if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
 					// LOGGER.debug("Now it exeeds the top border.. cut!");
 					// And cut the bottom if it moved out of the area
 					newArea = new Envelope(new Coordinate(newArea.getMinX(),
-							newArea.getMinY()), new Coordinate(newArea
-							.getMaxX(), maxAllowedExtend.getMaxY()));
+							newArea.getMinY()), new Coordinate(
+							newArea.getMaxX(), maxAllowedExtend.getMaxY()));
 
 					// LOGGER.debug("and fix aspect ratio");
 
-					newArea = JTSUtil.fixAspectRatio(getMapPaneSize(),
+					newArea = JTSUtil.fixAspectRatio(
+							getMapPaneSize(),
 							new ReferencedEnvelope(newArea, env
 									.getCoordinateReferenceSystem()), false);
 				}
@@ -924,13 +944,15 @@
 				if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
 					// LOGGER.debug("Now it exeeds the left border.. cut!");
 					// And cut the left if it moved out of the area
-					newArea = new Envelope(new Coordinate(maxAllowedExtend
-							.getMinX(), newArea.getMinY()), new Coordinate(
-							newArea.getMaxX(), newArea.getMaxY()));
+					newArea = new Envelope(
+							new Coordinate(maxAllowedExtend.getMinX(),
+									newArea.getMinY()),
+							new Coordinate(newArea.getMaxX(), newArea.getMaxY()));
 
 					// LOGGER.debug("and fix aspect ratio");
 
-					newArea = JTSUtil.fixAspectRatio(getMapPaneSize(),
+					newArea = JTSUtil.fixAspectRatio(
+							getMapPaneSize(),
 							new ReferencedEnvelope(newArea, env
 									.getCoordinateReferenceSystem()), false);
 				}
@@ -952,12 +974,13 @@
 					// LOGGER.debug("Now it exeeds the right border.. cut!");
 					// And cut the left if it moved out of the area
 					newArea = new Envelope(new Coordinate(newArea.getMinX(),
-							newArea.getMinY()), new Coordinate(maxAllowedExtend
-							.getMaxX(), newArea.getMaxY()));
+							newArea.getMinY()), new Coordinate(
+							maxAllowedExtend.getMaxX(), newArea.getMaxY()));
 
 					// LOGGER.debug("and fix aspect ratio");
 
-					newArea = JTSUtil.fixAspectRatio(getMapPaneSize(),
+					newArea = JTSUtil.fixAspectRatio(
+							getMapPaneSize(),
 							new ReferencedEnvelope(newArea, env
 									.getCoordinateReferenceSystem()), false);
 				}
@@ -965,8 +988,8 @@
 
 		}
 
-		return new ReferencedEnvelope(newArea, env
-				.getCoordinateReferenceSystem());
+		return new ReferencedEnvelope(newArea,
+				env.getCoordinateReferenceSystem());
 	}
 
 	/**
@@ -1000,15 +1023,13 @@
 				try {
 					Thread.sleep(200);
 				} catch (final InterruptedException e) {
-					LOGGER
-							.warn(
-									"while XMapPane we are waiting for the localExcutor to stop",
-									e);
+					LOGGER.warn(
+							"while XMapPane we are waiting for the localExcutor to stop",
+							e);
 				}
 			}
 			if (localExecuter.isRunning()) {
-				LOGGER
-						.warn("localExecutor Thread still running after 2s! Continuing anyways...");
+				LOGGER.warn("localExecutor Thread still running after 2s! Continuing anyways...");
 			}
 			localExecuter.dispose();
 		}
@@ -1095,9 +1116,9 @@
 			final Rectangle visibleArea = getMapPaneSize();
 
 			// Calculate the oldMapArea in the current WindowCoordinates:
-			final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea
-					.getMinX(), oldMapArea.getMinY(), oldMapArea.getMaxX(),
-					oldMapArea.getMaxY());
+			final Envelope oldMapWindow = tranformGeoToWindow(
+					oldMapArea.getMinX(), oldMapArea.getMinY(),
+					oldMapArea.getMaxX(), oldMapArea.getMaxY());
 
 			final int xx1 = (int) Math.round(oldMapWindow.getMinX());
 			final int yy1 = (int) Math.round(oldMapWindow.getMinY());
@@ -1147,7 +1168,7 @@
 	private Image getBgImage() {
 		if (bgImage == null) {
 			bgImage = new BufferedImage(getMapPaneSize().width,
-			    getMapPaneSize().height, IMAGETYPE);
+					getMapPaneSize().height, IMAGETYPE);
 			SwingUtil.clearImage(finalImage, getMapBackgroundColor());
 		}
 
@@ -1166,7 +1187,7 @@
 		if (finalImage == null) {
 			// Rectangle curPaintArea = getMapPaneSize();
 			finalImage = new BufferedImage(getMapPaneSize().width,
-			    getMapPaneSize().height, IMAGETYPE);
+					getMapPaneSize().height, IMAGETYPE);
 			SwingUtil.clearImage(finalImage, getMapBackgroundColor());
 
 			// requestStartRendering();
@@ -1181,7 +1202,7 @@
 
 		if (localImage == null) {
 			localImage = new BufferedImage(getMapPaneSize().width,
-			    getMapPaneSize().height, IMAGETYPE_withAlpha);
+					getMapPaneSize().height, IMAGETYPE_withAlpha);
 			SwingUtil.clearImage(localImage, getMapBackgroundColor());
 		}
 
@@ -1228,8 +1249,8 @@
 				throw new RuntimeException("setting context CRS:", e);
 			}
 
-		return new ReferencedEnvelope(mapArea, localContext
-				.getCoordinateReferenceSystem());
+		return new ReferencedEnvelope(mapArea,
+				localContext.getCoordinateReferenceSystem());
 	}
 
 	/**
@@ -1274,10 +1295,10 @@
 			// The next command may take long time!
 			// long start = System.currentTimeMillis();
 			final ReferencedEnvelope layerBounds = getVisibleLayoutBounds(localContext);
-			//			
+			//
 			// LOGGER.info(
 			// (System.currentTimeMillis()-start)+"m to get maxExtend");
-			//			
+			//
 			if (layerBounds == null) {
 				// // TODO Last fallback could be the CRS valid area
 				return null;
@@ -1302,7 +1323,6 @@
 
 		final int length = context.getLayerCount();
 		MapLayer layer;
-		FeatureSource<SimpleFeatureType, SimpleFeature> fs;
 		ReferencedEnvelope env;
 		CoordinateReferenceSystem sourceCrs;
 
@@ -1332,15 +1352,13 @@
 					}
 
 				} catch (FactoryException e) {
-					LOGGER
-							.warn(
-									"Data source and map context coordinate system differ, yet it was not possible to get a projected bounds estimate...",
-									e);
+					LOGGER.warn(
+							"Data source and map context coordinate system differ, yet it was not possible to get a projected bounds estimate...",
+							e);
 				} catch (TransformException e) {
-					LOGGER
-							.warn(
-									"Data source and map context coordinate system differ, yet it was not possible to get a projected bounds estimate...",
-									e);
+					LOGGER.warn(
+							"Data source and map context coordinate system differ, yet it was not possible to get a projected bounds estimate...",
+							e);
 				}
 
 				if (result == null) {
@@ -1491,8 +1509,8 @@
 		// winBounds.x, winBounds.y, winBounds.x
 		// + winBounds.width, winBounds.y
 		// + winBounds.height);
-		//					
 		//
+		//
 		// winBounds = xMapPane.getBounds();
 		// Point testIng = new Point(xMapPane.imageOrigin);
 		// testIng.translate(dx, dy);
@@ -1576,8 +1594,8 @@
 
 	/**
 	 * Called by the {@linkplain XMapPane.RenderingTask} when rendering failed.
-	 * Publishes a {@linkplain XMapPaneEvent} of type {@code
-	 * MapPaneEvent.Type.RENDERING_STOPPED} to listeners.
+	 * Publishes a {@linkplain XMapPaneEvent} of type
+	 * {@code MapPaneEvent.Type.RENDERING_STOPPED} to listeners.
 	 * 
 	 * @param renderingError
 	 *            The error that occured during rendering
@@ -1808,10 +1826,8 @@
 		final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
 				getMapContext().getCoordinateReferenceSystem());
 
-		// TODO Die
-
 		worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
-		    getMapPaneSize());
+				getMapPaneSize());
 
 		try {
 			if (worldToScreen != null)
@@ -1820,9 +1836,7 @@
 				screenToWorld = null;
 
 		} catch (final NoninvertibleTransformException ex) {
-			LOGGER
-					.error("can't invert worldToScreen to get screenToWorld!",
-							ex);
+			LOGGER.error("can't invert worldToScreen to get screenToWorld!", ex);
 		}
 	}
 
@@ -1901,7 +1915,6 @@
 		repaint();
 	}
 
-
 	/**
 	 * Set the new map area.
 	 * 
@@ -1973,12 +1986,12 @@
 		resetTransforms();
 
 		if (localContext != null) {
-			localContext.setAreaOfInterest(mapArea, localContext
-					.getCoordinateReferenceSystem());
+			localContext.setAreaOfInterest(mapArea,
+					localContext.getCoordinateReferenceSystem());
 		}
 		if (bgContext != null) {
-			bgContext.setAreaOfInterest(mapArea, localContext
-					.getCoordinateReferenceSystem());
+			bgContext.setAreaOfInterest(mapArea,
+					localContext.getCoordinateReferenceSystem());
 		}
 
 		mapAreaChanged = true;
@@ -2045,7 +2058,8 @@
 	 * mean there is no restriction.
 	 */
 	public void setMaxZoomScale(final Double maxZoomScale) {
-		this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE : maxZoomScale;
+		this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE
+				: maxZoomScale;
 	}
 
 	// /** Stored the time used for the last real rendering in ms. **/
@@ -2100,18 +2114,18 @@
 		xMapPaneMouseListener.configure(tool);
 		setCursor(tool.getCursor());
 	}
-	
+
 	/**
-	 * Returns a {@code new Rectangle(getWidth(),getHeight()}, because
-	 * the complete map should be rendered, even a part of the map is
-     * currently not visible due to an scrollpane.<br>
-	 * This method is used instead of {@link #getMapPaneSize()}, because
-	 * of rendering problems when the map pane is hidden partly by a
-	 * scroll pane (in ISDSS).
+	 * Returns a {@code new Rectangle(getWidth(),getHeight()}, because the
+	 * complete map should be rendered, even a part of the map is currently not
+	 * visible due to an scrollpane.<br>
+	 * This method is used instead of {@link #getMapPaneSize()}, because of
+	 * rendering problems when the map pane is hidden partly by a scroll pane
+	 * (in ISDSS).
 	 */
 	protected Rectangle getMapPaneSize() {
-	  //return getMapPaneSize();
-	  return new Rectangle(getWidth(),getHeight());
+		// return getMapPaneSize();
+		return new Rectangle(getWidth(), getHeight());
 	}
 
 	/**
@@ -2323,9 +2337,9 @@
 		// Paint a logo to the bottom right if available
 		if (mapImage != null) {
 			final Rectangle visibleRect = getMapPaneSize();
-			graphics.drawImage(mapImage, visibleRect.width
-					- mapImage.getWidth() - 10, getMapPaneSize().height
-					- mapImage.getHeight() - 10, null);
+			graphics.drawImage(mapImage,
+					visibleRect.width - mapImage.getWidth() - 10,
+					getMapPaneSize().height - mapImage.getHeight() - 10, null);
 		}
 
 		int y = 17;
@@ -2472,13 +2486,13 @@
 	}
 
 	private ReferencedEnvelope addDefaultMargin(ReferencedEnvelope bounds) {
-		return JTSUtil.expandEnvelope(bounds, Math.max(0,
-				defaultMaxMapExtendMode));
+		return JTSUtil.expandEnvelope(bounds,
+				Math.max(0, defaultMaxMapExtendMode));
 	}
 
 	private Envelope addDefaultMargin(Envelope bounds) {
-		return JTSUtil.expandEnvelope(bounds, Math.max(0,
-				defaultMaxMapExtendMode));
+		return JTSUtil.expandEnvelope(bounds,
+				Math.max(0, defaultMaxMapExtendMode));
 	}
 
 	/**
@@ -2522,14 +2536,13 @@
 		final Envelope mapArea = getMapArea();
 
 		final Envelope newMapArea = new Envelope(mapArea);
-		newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
-				.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
-				.getHeight()) / 2.);
+		newMapArea.expandBy(
+				(mapArea.getWidth() * zoomFaktor - mapArea.getWidth()) / 2.,
+				(mapArea.getHeight() * zoomFaktor - mapArea.getHeight()) / 2.);
 
 		// // Move the newMapArea above the new center if we zoom in:
-		newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
-				.getY()
-				- mapArea.centre().y);
+		newMapArea.translate(gcenter.getX() - mapArea.centre().x,
+				gcenter.getY() - mapArea.centre().y);
 
 		return setMapArea(newMapArea);
 	}
@@ -2544,7 +2557,7 @@
 	 */
 	public boolean zoomTowards(Point point, Double zFactor) {
 		// int units = wheelEvt.getUnitsToScroll();
-		// 
+		//
 		// Negativer Wert --> Zoom out --> Faktir > 1
 
 		// SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
@@ -2568,9 +2581,9 @@
 				- getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
 				- getMapArea().getHeight() * relY * zFactor);
 		Coordinate ur = new Coordinate(mapCoord.getX()
-				+ getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
-				.getY()
-				+ getMapArea().getHeight() * (1 - relY) * zFactor);
+				+ getMapArea().getWidth() * (1 - relX) * zFactor,
+				mapCoord.getY() + getMapArea().getHeight() * (1 - relY)
+						* zFactor);
 
 		return setMapArea(new Envelope(ll, ur));
 	}
@@ -2617,11 +2630,10 @@
 			if (sourceCRS == null) {
 				sourceCRS = layer.getFeatureSource().getSchema()
 						.getGeometryDescriptor().getCoordinateReferenceSystem();
-				LOGGER
-						.info("CRS for "
-								+ layer.getTitle()
-								+ " could not be determined from schema, trying GeometryDescriptor results: "
-								+ sourceCRS);
+				LOGGER.info("CRS for "
+						+ layer.getTitle()
+						+ " could not be determined from schema, trying GeometryDescriptor results: "
+						+ sourceCRS);
 			}
 
 			Envelope mapAreaNew;
@@ -2684,8 +2696,7 @@
 				mapAreaNew = addDefaultMargin(mapAreaNew);
 				setMapArea(mapAreaNew);
 			} else {
-				LOGGER
-						.warn("Couldn't transformEnvelope when zooming to the layer");
+				LOGGER.warn("Couldn't transformEnvelope when zooming to the layer");
 			}
 		} catch (Exception err) {
 			LOGGER.error("Zoom to layer did not terminate correctly", err);
@@ -2792,6 +2803,12 @@
 
 	final static int BLINK_TIMER_DEPLAY = 800;
 
+	/** Key for the environment variable storing the render language **/
+	public static final String ENV_LANG = "LANG";
+	public static final String ENV_LANG_DEFAULT = "XX";
+
+	private String renderLanguage;
+
 	/**
 	 * The job of the BlinkTimer is to remove the features painted in BLINK
 	 * style again.
@@ -2853,7 +2870,32 @@
 			stopBlinkTimer.start();
 
 		}
+	}
 
+	/**
+	 * Set a specific language for rendering. The value will be inserted into a
+	 * {@link EnvFunction} variable before rendering.
+	 * 
+	 * @param e
+	 *            .g. "de" or <code>null</code> (default) if no specific
+	 *            langauge should be set.
+	 * 
+	 */
+	public void setRenderLanguage(String renderLanguage) {
+		this.renderLanguage = renderLanguage;
 	}
 
+	/**
+	 * Return any a specific language set for rendering. The value will be
+	 * inserted into a {@link EnvFunction} variable before rendering.
+	 * 
+	 * @param e
+	 *            .g. "de" or <code>null</code> (default) if no specific
+	 *            langauge should be set.
+	 * 
+	 */
+	public String getRenderLanguage() {
+		return renderLanguage;
+	}
+
 }

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-10-17 00:53:34 UTC (rev 1144)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-10-17 23:56:07 UTC (rev 1145)
@@ -237,7 +237,8 @@
 	 *            oder {@link FeatureCollection}
 	 * @return {@code null} falls kein Style generiert werden kann
 	 * 
-	 * @Deprectated Use FeatureUtil.createDefaultStyle and FeatureUtil.getGeometryForm
+	 * @Deprectated Use FeatureUtil.createDefaultStyle and
+	 *              FeatureUtil.getGeometryForm
 	 */
 	public static Style createDefaultStyle(Object object) {
 		Style style = STYLE_BUILDER.createStyle(); // SK.. nicer default than
@@ -289,8 +290,8 @@
 	 *            Geo-Wert, der NoData repraesentiert
 	 */
 	public static Category createNoDataCategory(int value, double geoValue) {
-		return new Category(Vocabulary
-				.formatInternational(VocabularyKeys.NODATA),
+		return new Category(
+				Vocabulary.formatInternational(VocabularyKeys.NODATA),
 				new Color[] { new Color(0, 0, 0, 0) }, new NumberRange(value,
 						value), new NumberRange(geoValue, geoValue));
 	}
@@ -896,11 +897,11 @@
 	public static Style createStyleFromSLD(Element element) {
 		String xmlDefinition = new XMLOutputter().outputString(element);
 		// TODO: Workaround, because gt2-2.6.x has problems when the
-        //       ColorMapEntries are not in the ascending order according to
-        //       their values
+		// ColorMapEntries are not in the ascending order according to
+		// their values
 		// --> maybe we can bring the XML-Elements to an ascending order
-		//     prior to interprete the XML
-		
+		// prior to interprete the XML
+
 		ByteArrayInputStream inputStream = null;
 		try {
 			inputStream = new ByteArrayInputStream(xmlDefinition.getBytes());
@@ -948,9 +949,10 @@
 		RasterSymbolizerImpl rasterSymbolizerImpl = new RasterSymbolizerImpl();
 
 		// MS: In GT-2.6.1 the attribute for the raster style is "grid",
-        //     not "raster". Setting the geometry to NULL causes that
-        //     the grid attribute is determined dynamically during rendering
-        rasterSymbolizerImpl.setGeometry(null);//new AttributeExpressionImpl("grid"));
+		// not "raster". Setting the geometry to NULL causes that
+		// the grid attribute is determined dynamically during rendering
+		rasterSymbolizerImpl.setGeometry(null);// new
+												// AttributeExpressionImpl("grid"));
 
 		// Entferne alle label informationen
 		clearColorMapLabels(colorMap);
@@ -1048,10 +1050,9 @@
 			styles = stylereader.readXML();
 			return styles;
 		} catch (Exception e) {
-			LOGGER
-					.warn(
-							" ... no styles recognized. Return 'new Style[] { null }' ",
-							e);
+			LOGGER.warn(
+					" ... no styles recognized. Return 'new Style[] { null }' ",
+					e);
 			return new Style[] { null };
 		}
 
@@ -1154,10 +1155,8 @@
 			FeatureTypeStyle fts = style.featureTypeStyles().get(ii);
 
 			if (fts.getName() != null
-					&& fts
-							.getName()
-							.equals(
-									FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
+					&& fts.getName()
+							.equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
 				cleanStyle.featureTypeStyles().remove(ii);
 				break;
 			}
@@ -1184,10 +1183,8 @@
 			FeatureTypeStyle fts = style.featureTypeStyles().get(ii);
 
 			if (fts.getName() != null
-					&& fts
-							.getName()
-							.equals(
-									FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
+					&& fts.getName()
+							.equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
 				return style.featureTypeStyles().get(ii);
 			}
 		}
@@ -1309,10 +1306,8 @@
 
 					// Leave out FTSs that are selection related
 					if (fts.getName() != null
-							&& fts
-									.getName()
-									.equals(
-											FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
+							&& fts.getName()
+									.equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
 						continue;
 
 					final List<Rule> rules = fts.rules();
@@ -1381,8 +1376,7 @@
 									break;
 								}
 							} else {
-								LOGGER
-										.warn("Unbekannter geom Typ! Gehe von sichbar aus!");
+								LOGGER.warn("Unbekannter geom Typ! Gehe von sichbar aus!");
 								passt = true;
 							}
 						}
@@ -1529,10 +1523,9 @@
 									}
 								}
 							} catch (Exception e) {
-								LOGGER
-										.debug(
-												"Checking for textSymbolizer allwaysFalseFilter",
-												e);
+								LOGGER.debug(
+										"Checking for textSymbolizer allwaysFalseFilter",
+										e);
 							}
 						}
 
@@ -1896,15 +1889,15 @@
 			}
 
 			{ // White
-				Stroke outline = STYLE_BUILDER.createStroke(Color.yellow
-						.brighter(), 1);
+				Stroke outline = STYLE_BUILDER.createStroke(
+						Color.yellow.brighter(), 1);
 
 				Fill fill = null;
 
 				if (type != SelectionStylesTypes.Outline_only) {
 					Mark fillMark = STYLE_BUILDER.createMark(markShapeName);
-					fillMark.setStroke(STYLE_BUILDER.createStroke(Color.yellow
-							.brighter(), 1.));
+					fillMark.setStroke(STYLE_BUILDER.createStroke(
+							Color.yellow.brighter(), 1.));
 					Graphic fillGraphic = STYLE_BUILDER.createGraphic(null,
 							fillMark, null);
 					fillGraphic.setSize(FILTER_FACTORY.literal(size));
@@ -1987,8 +1980,8 @@
 			break;
 		case POLYGON:
 			PolygonSymbolizer polS = STYLE_BUILDER.createPolygonSymbolizer(
-					STYLE_BUILDER.createStroke(color2), STYLE_BUILDER
-							.createFill(color));
+					STYLE_BUILDER.createStroke(color2),
+					STYLE_BUILDER.createFill(color));
 			symbolizers = LangUtil.extendArray(symbolizers, polS);
 
 		case LINE:
@@ -2135,9 +2128,7 @@
 		if ((stroke.getColor() != null)
 				&& (StylingUtil.getColorFromExpression(stroke.getColor())
 						.equals(oldColor)))
-			stroke
-					.setColor(StylingUtil.STYLE_BUILDER
-							.colorExpression(newColor));
+			stroke.setColor(StylingUtil.STYLE_BUILDER.colorExpression(newColor));
 
 		replaceGraphicColor(stroke.getGraphicFill(), oldColor, newColor);
 
@@ -2382,10 +2373,8 @@
 
 			// Leave out FTSs that are selection related
 			if (fts.getName() != null
-					&& fts
-							.getName()
-							.equals(
-									FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
+					&& fts.getName()
+							.equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
 				continue;
 
 			for (Rule r : fts.rules()) {
@@ -2490,38 +2479,40 @@
 
 		return filterSLDVisibleOnly(fc, style, scaleDenominator);
 	}
-	
-    /**
-     * Since GT2.6, the AttributeNames are case sensitive. Also the raster
-     * Styles need GeometryProperty set to "geom" to work. This method checks
-     * all referenced AttributeNames.
-     * 
-     * @param Schema may be <code>null</code>, e.g. for raster layers
-     * 
-     *        TODO Rename to correctStye
-     */
-    public static Style correctPropertyNames(Style style) {
-      return correctPropertyNames(style,null);
-    }
-    
-    /**
+
+	/**
 	 * Since GT2.6, the AttributeNames are case sensitive. Also the raster
 	 * Styles need GeometryProperty set to "geom" to work. This method checks
+	 * all referenced AttributeNames.
+	 * 
+	 * @param Schema
+	 *            may be <code>null</code>, e.g. for raster layers
+	 * 
+	 *            TODO Rename to correctStye
+	 */
+	public static Style correctPropertyNames(Style style) {
+		return correctPropertyNames(style, null);
+	}
+
+	/**
+	 * Since GT2.6, the AttributeNames are case sensitive. Also the raster
+	 * Styles need GeometryProperty set to "geom" to work. This method checks
 	 * all referenced AttributeNames and checks them against the schema.
 	 * 
-	 * @param Schema may be <code>null</code>, e.g. for raster layers
+	 * @param Schema
+	 *            may be <code>null</code>, e.g. for raster layers
 	 * 
-	 *        TODO Rename to correctStye
+	 *            TODO Rename to correctStye
 	 */
 	public static Style correctPropertyNames(Style style,
 			final SimpleFeatureType schema) {
 
 		DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor() {
 			public void visit(RasterSymbolizer sym) {
-					sym.setGeometryPropertyName("geom");
+				sym.setGeometryPropertyName("geom");
 				super.visit(sym);
 			};
-			
+
 			@Override
 			public void visit(ColorMap cm) {
 				super.visit(sortColorMap(cm));
@@ -2727,6 +2718,10 @@
 				attExVid.visit(filterExpression, null);
 
 				final String[] attributeNames = attExVid.getAttributeNames();
+
+				if (attributeNames.length == 0)
+					return null;
+
 				String prop1 = null;
 				if (attributeNames.length == 1) {
 					// Easy
@@ -2851,8 +2846,8 @@
 			symbolizers = LangUtil.extendArray(symbolizers, pol1);
 
 			PolygonSymbolizer pol2 = STYLE_BUILDER.createPolygonSymbolizer(
-					STYLE_BUILDER.createStroke(Color.black, 2), STYLE_BUILDER
-							.createFill(Color.WHITE, .5));
+					STYLE_BUILDER.createStroke(Color.black, 2),
+					STYLE_BUILDER.createFill(Color.WHITE, .5));
 			symbolizers = LangUtil.extendArray(symbolizers, pol2);
 
 			break;
@@ -2888,10 +2883,9 @@
 			sld = stylereader.parseSLD();
 			return sld;
 		} catch (Exception e) {
-			LOGGER
-					.warn(
-							" ... no StyledLayerDescriptor recognized. Returning null ",
-							e);
+			LOGGER.warn(
+					" ... no StyledLayerDescriptor recognized. Returning null ",
+					e);
 			return sld;
 		}
 	}
@@ -2905,10 +2899,9 @@
 			sld = stylereader.parseSLD();
 			return sld;
 		} catch (Exception e) {
-			LOGGER
-					.warn(
-							" ... no StyledLayerDescriptor recognized. Returning null ",
-							e);
+			LOGGER.warn(
+					" ... no StyledLayerDescriptor recognized. Returning null ",
+					e);
 			return sld;
 		}
 	}
@@ -2920,6 +2913,7 @@
 	 * @throws TransformerException
 	 */
 	public static String toXMLString(Object sld) throws TransformerException {
+		SLDTRANSFORMER.setIndentation(1);
 		return SLDTRANSFORMER.transform(sld);
 	}
 

Modified: trunk/src/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/src/schmitzm/lang/LangUtil.java	2010-10-17 00:53:34 UTC (rev 1144)
+++ trunk/src/schmitzm/lang/LangUtil.java	2010-10-17 23:56:07 UTC (rev 1145)
@@ -57,22 +57,22 @@
  * @version 1.0
  */
 public class LangUtil {
-    /** Eine Sekunde in Millisekunden. */
-    public static final long SEC_MILLIS = 1000;
-    /** Eine Minute in Millisekunden. */
-    public static final long MIN_MILLIS = 60 * SEC_MILLIS;
-    /** Eine Stunde in Millisekunden. */
-    public static final long HOUR_MILLIS = 60 * MIN_MILLIS; 
-    /** Ein Tag in Millisekunden. */
-    public static final long DAY_MILLIS = 24 * HOUR_MILLIS; 
-    /** Eine Woche in Millisekunden. */
-    public static final long WEEK_MILLIS = 7 * DAY_MILLIS; 
+	/** Eine Sekunde in Millisekunden. */
+	public static final long SEC_MILLIS = 1000;
+	/** Eine Minute in Millisekunden. */
+	public static final long MIN_MILLIS = 60 * SEC_MILLIS;
+	/** Eine Stunde in Millisekunden. */
+	public static final long HOUR_MILLIS = 60 * MIN_MILLIS;
+	/** Ein Tag in Millisekunden. */
+	public static final long DAY_MILLIS = 24 * HOUR_MILLIS;
+	/** Eine Woche in Millisekunden. */
+	public static final long WEEK_MILLIS = 7 * DAY_MILLIS;
 
 	final static Pattern onlyZerosRegEx = Pattern.compile("^([\\s0.,]*)$");
 
 	/**
-	 * Liefert <code>true</code> wenn der String nur Nullen, Leerzeichen, Kommata und/oder
-	 * Punkte enthält.
+	 * Liefert <code>true</code> wenn der String nur Nullen, Leerzeichen,
+	 * Kommata und/oder Punkte enthält.
 	 */
 	public static boolean onlyZero(String numerString) {
 		return onlyZerosRegEx.matcher(numerString).find();
@@ -255,6 +255,19 @@
 	 * @param sep
 	 *            Trenner
 	 * @param str
+	 *            aneinanderzuhaengende Stings als Liste
+	 */
+	public static String stringConcatWithSep(String sep, Collection<Object> list) {
+		return stringConcatWithSep(sep, null, list.toArray());
+	}
+
+	/**
+	 * Haengt eine beliebige Anzahl von Strings hintereinander und fuegt
+	 * zwischen den Strings einen Trenner ein.
+	 * 
+	 * @param sep
+	 *            Trenner
+	 * @param str
 	 *            aneinanderzuhaengende Stings
 	 */
 	public static String stringConcatWithSep(String sep, Object... str) {

Modified: trunk/src/skrueger/geotools/RenderingExecutor.java
===================================================================
--- trunk/src/skrueger/geotools/RenderingExecutor.java	2010-10-17 00:53:34 UTC (rev 1144)
+++ trunk/src/skrueger/geotools/RenderingExecutor.java	2010-10-17 23:56:07 UTC (rev 1145)
@@ -5,6 +5,7 @@
 import java.awt.geom.AffineTransform;
 
 import org.apache.log4j.Logger;
+import org.geotools.filter.function.EnvFunction;
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.renderer.GTRenderer;
 import org.geotools.renderer.RenderListener;
@@ -17,7 +18,8 @@
  * {@link Thread} for rendering.
  */
 public class RenderingExecutor {
-	private final static Logger LOGGER = Logger.getLogger(RenderingExecutor.class);
+	private final static Logger LOGGER = Logger
+			.getLogger(RenderingExecutor.class);
 	/**
 	 * Instance to a {@link RenderThread} doing any work. It's volatile so the
 	 * correct value will always be visible to any {@link Thread}
@@ -50,21 +52,17 @@
 	 * @return true if the rendering task was accepted; false if it was rejected
 	 */
 	public synchronized boolean submit(ReferencedEnvelope envelope,
-			Rectangle paintArea, Graphics2D graphics, final GTRenderer renderer
-	// , AffineTransform worldToScreen
-	) {
+			Rectangle paintArea, Graphics2D graphics, final GTRenderer renderer) {
 		if (renderThread == null || !renderThread.isAlive()) {
 			// System.out.println("is vacant... starting thread!");
 			renderThread = null;
 
 			renderThread = new RenderThread(paintArea, graphics, renderer,
-			// worldToScreen,
 					envelope);
 			renderThread.start();
 
 			return true;
 		} else {
-			// System.out.println("is busy... requesting stop!");
 			renderThread.getRenderer().stopRendering();
 			return false;
 		}
@@ -81,16 +79,12 @@
 
 		public RenderThread(final Rectangle paintArea,
 				final Graphics2D graphics, GTRenderer renderer,
-				// AffineTransform worldToScreen,
 				ReferencedEnvelope mapEnv) {
-			super(new RenderRun(paintArea, graphics, renderer, mapEnv
-			// , worldToScreen
-					));
+			super(new RenderRun(paintArea, graphics, renderer, mapEnv));
 			this.renderer = renderer;
 
 			setName("Render" + getName());
 
-			// System.out.println("starting render thread " + getName());
 		}
 
 		public GTRenderer getRenderer() {
@@ -105,20 +99,15 @@
 	class RenderRun implements Runnable, RenderListener {
 		private final Rectangle paintArea;
 		private final Graphics2D graphics;
-		// private final AffineTransform worldToScreen;
 		private final GTRenderer renderer;
 		private final ReferencedEnvelope mapEnv;
 
 		public RenderRun(Rectangle paintArea, Graphics2D graphics,
-				GTRenderer renderer, ReferencedEnvelope mapEnv
-		// ,
-		// AffineTransform worldToScreen
-		) {
+				GTRenderer renderer, ReferencedEnvelope mapEnv) {
 			this.paintArea = paintArea;
 			this.graphics = graphics;
 			this.renderer = renderer;
 			this.mapEnv = mapEnv;
-			// this.worldToScreen = worldToScreen;
 		}
 
 		@Override
@@ -126,19 +115,29 @@
 			long startT = System.currentTimeMillis();
 			try {
 				renderer.addRenderListener(this);
-//				LOGGER.debug("start rendering...");
+				// LOGGER.debug("start rendering...");
 
 				// Clear the graphics context
 				graphics.setBackground(mapPane.getMapBackgroundColor());
 				graphics.clearRect(paintArea.x, paintArea.y, paintArea.width,
 						paintArea.height);
 
+				// TODO It should be enough to set only the Local Value, but it isn't 
+				EnvFunction.setGlobalValue(XMapPane.ENV_LANG,
+						mapPane.getRenderLanguage());
+				EnvFunction.setLocalValue(XMapPane.ENV_LANG,
+						mapPane.getRenderLanguage());
+
+//				LOGGER.debug("Renderer language set to "
+//						+ mapPane.getRenderLanguage());
+
 				renderer.paint(graphics, paintArea, mapEnv);
 
 				// Kill the reference to this Thread so #isRunning will say
 				// false directly
 				renderThread = null;
-				mapPane.onRenderingCompleted(System.currentTimeMillis()-startT);
+				mapPane.onRenderingCompleted(System.currentTimeMillis()
+						- startT);
 			} catch (Exception e) {
 				mapPane.onRenderingFailed(e);
 			} finally {

Modified: trunk/src_junit/schmitzm/geotools/gui/XMapPaneTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/gui/XMapPaneTest.java	2010-10-17 00:53:34 UTC (rev 1144)
+++ trunk/src_junit/schmitzm/geotools/gui/XMapPaneTest.java	2010-10-17 23:56:07 UTC (rev 1145)
@@ -3,40 +3,75 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import org.geotools.filter.function.EnvFunction;
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.junit.Test;
+import org.opengis.filter.FilterFactory2;
+import org.opengis.filter.expression.Function;
 
 import schmitzm.geotools.GTUtil;
+import schmitzm.geotools.feature.FeatureUtil;
+import skrueger.i8n.Translation;
 
 public class XMapPaneTest {
 
 	@Test
 	public void testBestAllowedMapArea() {
-		
+
 		XMapPane xMapPane = new XMapPane();
-		
-		ReferencedEnvelope zeroWidthBBOx = new ReferencedEnvelope(1,1,2,2,GTUtil.WGS84);
+
+		ReferencedEnvelope zeroWidthBBOx = new ReferencedEnvelope(1, 1, 2, 2,
+				GTUtil.WGS84);
 		assertEquals(0., zeroWidthBBOx.getWidth(), 0.);
 		assertEquals(0., zeroWidthBBOx.getHeight(), 0.);
-		ReferencedEnvelope corrected = xMapPane.bestAllowedMapArea(zeroWidthBBOx);
-		
+		ReferencedEnvelope corrected = xMapPane
+				.bestAllowedMapArea(zeroWidthBBOx);
+
 		assertTrue(corrected.getWidth() > 0.);
 		assertTrue(corrected.getHeight() > 0.);
-		
+
 	}
-	
 
 	@Test
 	public void testBestAllowedMapArea2() {
-		
+
 		XMapPane xMapPane = new XMapPane();
-		
+
 		xMapPane.setMaxZoomScale(null);
 
 		assertTrue(xMapPane.getMaxZoomScale() != 1.);
 		assertTrue(xMapPane.getMaxZoomScale() < 1.);
 		assertTrue(xMapPane.getMaxZoomScale() == Double.MIN_VALUE);
+	}
+
+	@Test
+	public void testSetRenderLanguage() {
+		EnvFunction.setLocalValue(XMapPane.ENV_LANG, "de");
+		FilterFactory2 ff = FeatureUtil.FILTER_FACTORY2;
+
+		Function function = ff.function("env", ff.literal(XMapPane.ENV_LANG),
+				ff.literal("xx"));
+
+		System.out.println(function);
+
+		Object evaluated = function.evaluate(null);
+
+		System.out.println(evaluated);
+	}
+
+	/**
+	 * WHen the active language is change in {@link Translation}, it shoudl
+	 * automatically change in any {@link XMapPane}.
+	 */
+	@Test
+	public void testChangeRenderLanguageListener() {
+		XMapPane mapPane = new XMapPane();
 		
+		mapPane.setRenderLanguage("de");
+		assertEquals("de", mapPane.getRenderLanguage());
+		
+		Translation.setActiveLang("ru");
+		assertEquals("ru", mapPane.getRenderLanguage());
 	}
 
 }



More information about the Schmitzm-commits mailing list