[Schmitzm-commits] r533 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/styling skrueger skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 19 18:27:05 CET 2009


Author: alfonx
Date: 2009-11-19 18:27:01 +0100 (Thu, 19 Nov 2009)
New Revision: 533

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
   branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
Log:
* XMapPane now prints erros nicely

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-11-19 10:39:48 UTC (rev 532)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-11-19 17:27:01 UTC (rev 533)
@@ -2457,7 +2457,7 @@
 								.getLocalPart());
 				super.visit(sym);
 			}
-
+			@Override
 			public void visit(TextSymbolizer sym) {
 				sym
 						.setGeometryPropertyName(FeatureUtil.findBestMatchingAttributeFallBackFirst(
@@ -2481,6 +2481,7 @@
 
 				super.visit(sym);
 			}
+			
 
 		};
 

Modified: branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java	2009-11-19 10:39:48 UTC (rev 532)
+++ branches/1.0-gt2-2.6/src/skrueger/AttributeMetadata.java	2009-11-19 17:27:01 UTC (rev 533)
@@ -196,43 +196,43 @@
 	/**
 	 * Creates a new visible {@link AttributeMetadata} with default (no) values.
 	 */
-	public AttributeMetadata(final String localName, final String defaultTitle) {
-		this(localName, true, new Translation(defaultTitle), new Translation(),
+	public AttributeMetadata(final String localName, final String defaultTitle, List<String> langs) {
+		this(localName, true, new Translation(langs, defaultTitle), new Translation(),
 				"");
 	}
 
 	/**
 	 * Creates a new visible {@link AttributeMetadata} with default (no) values.
 	 */
-	public AttributeMetadata(final Name name, final String defaultTitle) {
-		this(name, true, new Translation(defaultTitle), new Translation(), "");
+	public AttributeMetadata(final Name name, final String defaultTitle, List<String> langs) {
+		this(name, true, new Translation(langs, defaultTitle), new Translation(), "");
 	}
 
 	/**
 	 * Creates a new visible {@link AttributeMetadata} with default (no) values.
 	 */
-	public AttributeMetadata(final Name name) {
-		this(name, true, new Translation(name.getLocalPart()),
+	public AttributeMetadata(final Name name, List<String> langs) {
+		this(name, true, new Translation(langs, name.getLocalPart()),
 				new Translation(), "");
 	}
 
 	/**
 	 * Creates a new visible {@link AttributeMetadata} with default (no) values.
 	 */
-	public AttributeMetadata(final String localName) {
-		this(localName, true, new Translation(localName), new Translation(), "");
+	public AttributeMetadata(final String localName, List<String> langs) {
+		this(localName, true, new Translation(langs, localName), new Translation(), "");
 	}
 
 	/** Only used for {@link Copyable<AttributeMetaData>#copy()} **/
 	private AttributeMetadata() {
 	}
 
-	public AttributeMetadata(AttributeDescriptor attDesc) {
-		this(attDesc.getName());
+	public AttributeMetadata(AttributeDescriptor attDesc, List<String> langs) {
+		this(attDesc.getName(), langs);
 	}
 
-	public AttributeMetadata(AttributeDescriptor attDesc, int weight) {
-		this(attDesc.getName());
+	public AttributeMetadata(AttributeDescriptor attDesc, int weight, List<String> langs) {
+		this(attDesc.getName(), langs);
 		setWeight(weight);
 	}
 

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java	2009-11-19 10:39:48 UTC (rev 532)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/AttributeMetadataMap.java	2009-11-19 17:27:01 UTC (rev 533)
@@ -1,6 +1,7 @@
 package skrueger.geotools;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.TreeMap;
 
@@ -8,8 +9,11 @@
 import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.Name;
 
+import cern.colt.Arrays;
+
 import skrueger.AttributeMetadata;
 import skrueger.i8n.I8NUtil;
+import skrueger.i8n.Translation;
 
 /**
  * An extension of TreeMap, that is copyable in the sense of the {@link Copyable} interface
@@ -17,8 +21,23 @@
 public class AttributeMetadataMap extends TreeMap<Name, AttributeMetadata>
 		implements Copyable<AttributeMetadataMap> {
 	static private final Logger LOGGER = Logger.getLogger(AttributeMetadataMap.class);
+	private List<String> langs;
 	
+	public AttributeMetadataMap(List<String> defLanguages) {
+		langs = defLanguages;
+	}
 	
+	@Deprecated 
+	public AttributeMetadataMap() {
+		langs = new ArrayList<String>();
+		langs.add(Translation.getActiveLang());
+	}
+	
+	
+	public AttributeMetadataMap(String[] strings) {
+		langs = new ArrayList<String>(java.util.Arrays.asList(strings));
+	}
+
 	/**
 	 * @Deprecated use get(Name name) or get(String localName)
 	 */
@@ -33,7 +52,7 @@
 	public AttributeMetadata get(Name name) {
 		final AttributeMetadata attributeMetadata = super.get(name);
 		if (attributeMetadata == null && name != null && !name.getLocalPart().trim().isEmpty()) {
-			put(name,new AttributeMetadata(name));
+			put(name,new AttributeMetadata(name, langs));
 			return super.get(name);
 		}
 		return attributeMetadata;
@@ -57,7 +76,7 @@
 
 	@Override
 	public AttributeMetadataMap copy() {
-		AttributeMetadataMap copy = new AttributeMetadataMap();
+		AttributeMetadataMap copy = new AttributeMetadataMap(langs);
 		return copyTo(copy);
 	}
 
@@ -87,4 +106,8 @@
 			return 1.;
 
 	}
+
+	public List<String> getLanguages() {
+		return langs;
+	}
 }

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java	2009-11-19 10:39:48 UTC (rev 532)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java	2009-11-19 17:27:01 UTC (rev 533)
@@ -4,15 +4,11 @@
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 
-import javax.swing.SwingUtilities;
-
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.renderer.GTRenderer;
 import org.geotools.renderer.RenderListener;
 import org.opengis.feature.simple.SimpleFeature;
 
-import schmitzm.swing.SwingUtil;
-
 /**
  * This class is used by {@link XMapPane} to start and stop the rendering a
  * {@link Thread} for rendering.
@@ -58,7 +54,7 @@
 			renderThread = null;
 
 			renderThread = new RenderThread(paintArea, graphics, renderer,
-					worldToScreen);
+					worldToScreen, envelope);
 			renderThread.start();
 
 			return true;
@@ -80,8 +76,8 @@
 
 		public RenderThread(final Rectangle paintArea,
 				final Graphics2D graphics, GTRenderer renderer,
-				AffineTransform worldToScreen) {
-			super(new RenderRun(paintArea, graphics, renderer, worldToScreen));
+				AffineTransform worldToScreen, ReferencedEnvelope mapEnv) {
+			super(new RenderRun(paintArea, graphics, renderer, mapEnv, worldToScreen));
 			this.renderer = renderer;
 
 			setName("Render" + getName());
@@ -103,12 +99,14 @@
 		private final Graphics2D graphics;
 		private final AffineTransform worldToScreen;
 		private final GTRenderer renderer;
+		private final ReferencedEnvelope mapEnv;
 
 		public RenderRun(Rectangle paintArea, Graphics2D graphics,
-				GTRenderer renderer, AffineTransform worldToScreen) {
+				GTRenderer renderer, ReferencedEnvelope mapEnv, AffineTransform worldToScreen) {
 			this.paintArea = paintArea;
 			this.graphics = graphics;
 			this.renderer = renderer;
+			this.mapEnv = mapEnv;
 			this.worldToScreen = worldToScreen;
 		}
 
@@ -128,15 +126,12 @@
 				graphics.clearRect(paintArea.x, paintArea.y, paintArea.width,
 						paintArea.height);
 
-				renderer.paint(graphics, paintArea, worldToScreen);
+				renderer.paint(graphics, paintArea, mapEnv, worldToScreen);
 
-				// Invoked later, so when onRenderingCompleted is called, the Thread is not running anymore (#isRunning = false)
-				SwingUtilities.invokeLater(new Runnable() {
-					@Override
-					public void run() {
-						mapPane.onRenderingCompleted();
-					};
-				});
+				// Kill the reference to this Thread to #isRunning will def. say false
+				renderThread = null;
+				mapPane.onRenderingCompleted();
+				
 			} finally {
 				renderer.removeRenderListener(this);
 			}
@@ -144,7 +139,6 @@
 
 		@Override
 		public void errorOccurred(Exception e) {
-			// System.out.println("rendering error");
 			mapPane.onRenderingFailed(e);
 		}
 

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java	2009-11-19 10:39:48 UTC (rev 532)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java	2009-11-19 17:27:01 UTC (rev 533)
@@ -245,13 +245,13 @@
 	public AttributeMetadataMap getAttributeMetaDataMap() {
 		if (map == null) {
 
-			map = new AttributeMetadataMap();
+			map = new AttributeMetadataMap(new String[] {Translation.getActiveLang()});
 
 			// Leaving out the first one, it will be the_geom
 			for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
 				AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
 
-				AttributeMetadata attMetaData = new AttributeMetadata(attDesc.getName());
+				AttributeMetadata attMetaData = new AttributeMetadata(attDesc.getName(), map.getLanguages());
 				map.put(attDesc.getName(), attMetaData);
 			}
 		}

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-11-19 10:39:48 UTC (rev 532)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-11-19 17:27:01 UTC (rev 533)
@@ -249,7 +249,7 @@
 	public static AttributeMetadataMap getVisibleAttributeMetaData(
 			final AttributeMetadataMap amdMap, final boolean visible) {
 
-		final AttributeMetadataMap filteredMap = new AttributeMetadataMap();
+		final AttributeMetadataMap filteredMap = new AttributeMetadataMap(amdMap.getLanguages());
 		for (final AttributeMetadata amd : amdMap.values())
 			if (amd.isVisible() == visible)
 				filteredMap.put(amd.getName(), amd);

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java	2009-11-19 10:39:48 UTC (rev 532)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java	2009-11-19 17:27:01 UTC (rev 533)
@@ -21,6 +21,7 @@
 import java.awt.geom.Point2D;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Vector;
@@ -57,6 +58,7 @@
 import schmitzm.geotools.GTUtil;
 import schmitzm.geotools.JTSUtil;
 import schmitzm.geotools.gui.SelectableXMapPane;
+import schmitzm.geotools.io.GeoImportUtil;
 import schmitzm.geotools.map.event.JMapPaneListener;
 import schmitzm.geotools.map.event.MapLayerAdapter;
 import schmitzm.lang.LangUtil;
@@ -183,6 +185,8 @@
 			.getPredefinedCursor(Cursor.WAIT_CURSOR);
 
 	final static Font waitFont = new Font("Arial", Font.BOLD, 30);
+	final String waitMsg = SwingUtil.R("WaitMess");
+	final static Font errorFont = new Font("Arial", Font.BOLD, 13);
 
 	/**
 	 * Flag fuer Modus "Heran zoomen".
@@ -243,8 +247,11 @@
 
 		@Override
 		public void layerAdded(final MapLayerListEvent event) {
-			event.getLayer().addMapLayerListener(bgMapLayerListener);
 
+			MapLayer layer = event.getLayer();
+
+			layer.addMapLayerListener(bgMapLayerListener);
+
 			if (localContext.getLayers().length == 0
 					&& bgContext.getLayers().length == 1) { // the first one and
 				// localContext is
@@ -452,7 +459,7 @@
 	};
 
 	private final GTRenderer localRenderer = GTUtil.createGTRenderer();
-	
+
 	private final GTRenderer bgRenderer = GTUtil.createGTRenderer();
 
 	/**
@@ -523,7 +530,8 @@
 	// if null, no quick preview will be shown
 	private int quickPreviewHint = 0;
 
-	private Map<Object, Object> rendererHints;
+	private Map<Object, Object> rendererHints = GTUtil
+			.getDefaultGTRendererHints(localRenderer);
 
 	private volatile Boolean requestStartRendering = false;
 
@@ -564,6 +572,9 @@
 	public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener(
 			this);
 
+	/** Is set if a renderer has an error **/
+	protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
+
 	// TODO doku
 	public XMapPane() {
 		this(null, null);
@@ -591,8 +602,6 @@
 
 		setOpaque(true);
 
-		localRenderer.setJava2DHints(getJava2dHints());
-
 		if (localContext_ != null)
 			setLocalContext(localContext_);
 
@@ -899,7 +908,7 @@
 			localExecuter.cancelTask();
 			while (i++ < 10 && localExecuter.isRunning()) {
 				try {
-					Thread.sleep(200);
+					Thread.sleep(100);
 				} catch (final InterruptedException e) {
 					// TODO Auto-generated catch block
 					e.printStackTrace();
@@ -1026,10 +1035,12 @@
 
 		SwingUtil.clearAround(graphics, painedArea, visibleArea);
 
-		addGadgets(graphics);
+		addGadgets(graphics, true);
 
 		quickPreviewHint = 0;
 
+		repaintTimer.restart();
+
 		graphics.dispose();
 
 		// Something has been drawn
@@ -1093,7 +1104,7 @@
 	 * 
 	 * @return
 	 */
-	public Envelope getMapArea() {
+	public ReferencedEnvelope getMapArea() {
 		if (mapArea == null) {
 			ReferencedEnvelope mapArea_ = null;
 			try {
@@ -1104,7 +1115,7 @@
 
 			if (mapArea_ != null) {
 				mapImageInvalid = true; /* note we need to redraw */
-//				setMapArea(mapArea_); // results in a loop
+				// setMapArea(mapArea_); // results in a loop
 				mapArea = bestAllowedMapArea(mapArea_);
 			}
 		}
@@ -1112,7 +1123,20 @@
 		if (mapArea == null)
 			return null;
 
-		return new Envelope(mapArea);
+		if (localContext.getCoordinateReferenceSystem() == null)
+			try {
+				localContext.setCoordinateReferenceSystem(GeoImportUtil
+						.getDefaultCRS());
+			} catch (TransformException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			} catch (FactoryException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+
+		return new ReferencedEnvelope(mapArea, localContext
+				.getCoordinateReferenceSystem());
 	}
 
 	/**
@@ -1196,6 +1220,10 @@
 	}
 
 	public Map<Object, Object> getRendererHints() {
+		// Clear label cache
+		labelCache.clear();
+		rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
+
 		return rendererHints;
 	}
 
@@ -1376,6 +1404,8 @@
 		repaintTimer.stop();
 		updateFinalImage();
 		repaint();
+		if (renderingErrors.size() > 0)
+			renderingErrors.remove(0);
 	}
 
 	/**
@@ -1389,6 +1419,9 @@
 	 * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
 	 */
 	public void onRenderingFailed(final Exception renderingError) {
+		this.renderingErrors.add(renderingError);
+		if (renderingErrors.size() > 3)
+			renderingErrors.remove(0);
 		repaintTimer.stop();
 		LOGGER.warn("Rendering failed", renderingError);
 		updateFinalImage();
@@ -1410,7 +1443,7 @@
 		// Maybe update the cursor and maybe stop the repainting timer
 		updateCursor();
 
-		super.paintComponent(g); // candidate for removal
+		// super.paintComponent(g); // candidate for removal
 
 		boolean paintedSomething = false;
 
@@ -1853,7 +1886,8 @@
 	}
 
 	private void setRendererHints(final Map<Object, Object> rendererHints) {
-		this.rendererHints = rendererHints;
+		if (rendererHints != null)
+			this.rendererHints = rendererHints;
 	}
 
 	/**
@@ -1912,6 +1946,9 @@
 		 */
 
 		if (getBgContext() != null) {
+			bgRenderer.setJava2DHints(getJava2dHints());
+			bgRenderer.setRendererHints(getRendererHints());
+
 			// bgExecuter = new RenderingExecutor();
 			// LOGGER.debug("starting bg renderer:");
 			// // /* System.out.println("rendering"); */
@@ -1927,16 +1964,13 @@
 			// localExecuter = new RenderingExecutor(this, 150l);
 			// LOGGER.debug("starting local renderer:");
 
-			// Clear label cache
-			labelCache.clear();
-			final Map<Object, Object> rh = localRenderer.getRendererHints();
-			rh.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
-			localRenderer.setRendererHints(rh);
+			localRenderer.setJava2DHints(getJava2dHints());
+			localRenderer.setRendererHints(getRendererHints());
 
-			final boolean submitted = localExecuter.submit(getContext()
-					.getAreaOfInterest(), curPaintArea,
-					(Graphics2D) getLocalImage().getGraphics(), localRenderer,
-					getWorldToScreenTransform());
+			ReferencedEnvelope areaOfInterest = getMapArea();
+			final boolean submitted = localExecuter.submit(areaOfInterest,
+					curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
+					localRenderer, getWorldToScreenTransform());
 			if (submitted)
 				repaintTimer.restart();
 			else
@@ -2015,6 +2049,7 @@
 		} else {
 			// Allow one last rendering
 			if (repaintTimer.isRunning()) {
+				System.out.println("one last rendering....");
 				repaintTimer.stop();
 				updateFinalImage();
 				repaint();
@@ -2091,7 +2126,7 @@
 				imageOrigin.y, finalImageWidth, finalImageHeight);
 		SwingUtil.clearAround(finalG, painedArea, getVisibleRect());
 
-		addGadgets(finalG);
+		addGadgets(finalG, false);
 
 		finalG.dispose();
 
@@ -2101,8 +2136,14 @@
 	/**
 	 * Paints some optional stuff into the given {@link Graphics2D}. Usually
 	 * called as the last layer when {@link #updateFinalImage()}
+	 * 
+	 * @param forceWait
+	 *            if <code>true</code>, a Wait-message will be painted even
+	 *            though the rendering threads may not yet have started. If
+	 *            <code>false</code>, it will only depend on
+	 *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning
 	 */
-	private void addGadgets(final Graphics2D graphics) {
+	private void addGadgets(final Graphics2D graphics, boolean forceWait) {
 
 		// Paint a logo to the bottom right if available
 		if (mapImage != null) {
@@ -2110,28 +2151,62 @@
 					- mapImage.getWidth() - 10, getBounds().height
 					- mapImage.getHeight() - 10, null);
 		}
+		
+		
+		int y = 17;
 
 		// If the rendering process is still running, indicate this is the image
-		if (bgExecuter != null && bgExecuter.isRunning()
+		if (forceWait || bgExecuter != null && bgExecuter.isRunning()
 				|| localExecuter != null && localExecuter.isRunning()) {
+			
+			y+=8;
 
 			final Color c = graphics.getColor();
 			graphics.setFont(waitFont);
-			String waitStr = "Wait..."; //i8n
-			
-			graphics.setColor(Color.WHITE);
-			graphics.drawString(waitStr, 39, 69); 
+//			String waitStr = "Wait..."; // i8n
+
+			graphics.setColor(getMapBackgroundColor());
+			graphics.drawString(waitMsg, 5, y);
+			graphics.setColor(getMapBackgroundColor());
+			graphics.drawString(waitMsg, 7, y+2);
 			graphics.setColor(Color.BLACK);
-			graphics.drawString(waitStr, 40, 70); 
+			graphics.drawString(waitMsg, 6, y+1);
 
 			graphics.setColor(c);
+			
+			y += 24;
 		}
 
+		if (renderingErrors != null) {
+
+			final Color c = graphics.getColor();
+			graphics.setFont(errorFont);
+
+			for (Exception ex : renderingErrors) {
+
+				if (ex instanceof java.lang.IllegalArgumentException
+						&& ex.getMessage().equals(
+								"Argument \"sourceCRS\" should not be null."))
+					continue;
+
+				String errStr = ex.getLocalizedMessage();
+
+				graphics.setColor(Color.WHITE);
+				graphics.drawString(errStr, 5, y);
+				graphics.setColor(Color.RED);
+				graphics.drawString(errStr, 6, y + 1);
+
+				y += 19;
+			}
+
+			graphics.setColor(c);
+		}
+
 	}
 
 	/**
-	 * Sets the {@link #mapArea} to best possibly present the given features. If only one
-	 * single point is given, the window is moved over the point.
+	 * Sets the {@link #mapArea} to best possibly present the given features. If
+	 * only one single point is given, the window is moved over the point.
 	 * 
 	 * @param features
 	 *            if <code>null</code> or size==0, the function doesn nothing.



More information about the Schmitzm-commits mailing list