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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Nov 21 18:13:33 CET 2009


Author: alfonx
Date: 2009-11-21 18:13:31 +0100 (Sat, 21 Nov 2009)
New Revision: 544

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/GTUtil.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/JTSUtil.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
Log:
* XMapPane now fine....The repaint timer may stop itself if not needed anymore...

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/GTUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/GTUtil.java	2009-11-21 15:21:41 UTC (rev 543)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/GTUtil.java	2009-11-21 17:13:31 UTC (rev 544)
@@ -356,12 +356,12 @@
 		 * appeared for example in maps that consisted only of layers of DHDN2
 		 * CRS.
 		 */
+		defaultRendererHints.put(
+				StreamingRenderer.SCALE_COMPUTATION_METHOD_KEY,
+				StreamingRenderer.SCALE_OGC);
 //		defaultRendererHints.put(
-//				StreamingRenderer.SCALE_COMPUTATION_METHOD_KEY,
-//				StreamingRenderer.SCALE_OGC);
-		defaultRendererHints.put(
-		StreamingRenderer.SCALE_COMPUTATION_METHOD_KEY,
-		StreamingRenderer.SCALE_ACCURATE);
+//		StreamingRenderer.SCALE_COMPUTATION_METHOD_KEY,
+//		StreamingRenderer.SCALE_ACCURATE);
 		
 
 		defaultRendererHints.put(StreamingRenderer.OPTIMIZE_FTS_RENDERING_KEY,

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/JTSUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/JTSUtil.java	2009-11-21 15:21:41 UTC (rev 543)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/JTSUtil.java	2009-11-21 17:13:31 UTC (rev 544)
@@ -33,6 +33,7 @@
 
 import org.apache.log4j.Logger;
 import org.geotools.geometry.jts.JTS;
+import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.referencing.CRS;
 import org.opengis.referencing.FactoryException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -81,7 +82,23 @@
 		expandedEnv.expandBy(env.getWidth() * pct, env.getHeight() * pct);
 		return expandedEnv;
 	}
+	
 
+	/**
+	 * Expands an {@link Envelope} by percentage.
+	 * 
+	 * @param env
+	 *            the {@link Envelope}
+	 * @param pct
+	 *            percentage (e.g. 0.1 = 10%) to expands the envelope by.
+	 *            Negative values are allowed.
+	 */
+	public static ReferencedEnvelope expandEnvelope(ReferencedEnvelope env, double pct) {
+		final ReferencedEnvelope expandedEnv = new ReferencedEnvelope(env);
+		expandedEnv.expandBy(env.getWidth() * pct, env.getHeight() * pct);
+		return expandedEnv;
+	}
+
 	
   /**
    * Transformiert einen JTS-Envelope von einem CRS in ein anderes. Wenn Bursa-Wolf parameter fehlen, wird lenient gerechnet.
@@ -147,7 +164,7 @@
    *            If <code>true</code>, than the area will be enlarged to match
    *            the aspect ratio. If <code>false</code>, it will only shrink.
    */
-  public static Envelope fixAspectRatio(final Rectangle rect, final Envelope mapArea,
+  public static ReferencedEnvelope fixAspectRatio(final Rectangle rect, final ReferencedEnvelope mapArea,
           boolean grow) {
       // no map area to fix the aspect ratio for
       if (mapArea == null) {
@@ -193,7 +210,7 @@
               mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
                       + (deltaY / 2.0));
 
-      return new Envelope(ll, ur);
+      return new ReferencedEnvelope(new Envelope(ll, ur),mapArea.getCoordinateReferenceSystem());
   }
 
 }

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-21 15:21:41 UTC (rev 543)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java	2009-11-21 17:13:31 UTC (rev 544)
@@ -48,13 +48,16 @@
 	 */
 	public synchronized boolean submit(ReferencedEnvelope envelope,
 			Rectangle paintArea, Graphics2D graphics,
-			final GTRenderer renderer, AffineTransform worldToScreen) {
+			final GTRenderer renderer
+//			, AffineTransform worldToScreen
+			) {
 		if (renderThread == null || !renderThread.isAlive()) {
 			// System.out.println("is vacant... starting thread!");
 			renderThread = null;
 
 			renderThread = new RenderThread(paintArea, graphics, renderer,
-					worldToScreen, envelope);
+//					worldToScreen,
+					envelope);
 			renderThread.start();
 
 			return true;
@@ -76,9 +79,12 @@
 
 		public RenderThread(final Rectangle paintArea,
 				final Graphics2D graphics, GTRenderer renderer,
-				AffineTransform worldToScreen, ReferencedEnvelope mapEnv) {
-			super(new RenderRun(paintArea, graphics, renderer, mapEnv,
-					worldToScreen));
+//				AffineTransform worldToScreen, 
+				ReferencedEnvelope mapEnv) {
+			super(new RenderRun(paintArea, graphics, renderer, 
+					mapEnv
+//					,					worldToScreen
+					));
 			this.renderer = renderer;
 
 			setName("Render" + getName());
@@ -98,18 +104,20 @@
 	class RenderRun implements Runnable, RenderListener {
 		private final Rectangle paintArea;
 		private final Graphics2D graphics;
-		private final AffineTransform worldToScreen;
+//		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
+//				,
+//				AffineTransform worldToScreen
+				) {
 			this.paintArea = paintArea;
 			this.graphics = graphics;
 			this.renderer = renderer;
 			this.mapEnv = mapEnv;
-			this.worldToScreen = worldToScreen;
+//			this.worldToScreen = worldToScreen;
 		}
 
 		@Override
@@ -128,7 +136,7 @@
 				graphics.clearRect(paintArea.x, paintArea.y, paintArea.width,
 						paintArea.height);
 
-				renderer.paint(graphics, paintArea, worldToScreen);
+				renderer.paint(graphics, paintArea, mapEnv);
 
 				// Kill the reference to this Thread so #isRunning will say
 				// false directly

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-21 15:21:41 UTC (rev 543)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java	2009-11-21 17:13:31 UTC (rev 544)
@@ -125,7 +125,7 @@
 	 * regularly and {@link #repaint()}. This {@link Timer} is stopped when all
 	 * renderers have finished.
 	 * 
-	 * @see #INITIAL_REPAINT_DELAYAL
+	 * @see INITIAL_REPAINT_DELAYAL
 	 * @see #REPEATING_REPAINT_DELAY
 	 */
 	final private Timer repaintTimer;
@@ -141,14 +141,18 @@
 	 * the {@link #repaintTimer} is regularly updating the {@link #finalImage}
 	 * with previews.
 	 */
-	public static final long REPEATING_REPAINT_DELAY = 500;
+	public static final int REPEATING_REPAINT_DELAY = 500;
 
 	/**
 	 * Default delay (milliseconds) before the map will be redrawn when resizing
 	 * the pane. This is to avoid flickering while drag-resizing.
+	 * 
+	 * @see #resizeTimer
 	 */
 	public static final int DEFAULT_RESIZING_PAINT_DELAY = 600;
 
+	private final Timer resizeTimer;
+
 	public static final int NONE = -123;
 
 	/**
@@ -186,11 +190,29 @@
 	public static final Cursor WAIT_CURSOR = Cursor
 			.getPredefinedCursor(Cursor.WAIT_CURSOR);
 
+	/**
+	 * {@link Font} used to paint the wait messages into the map
+	 * 
+	 * @see #addGadgets(Graphics2D, boolean)
+	 */
 	final static Font waitFont = new Font("Arial", Font.BOLD, 30);
-	final String waitMsg = SwingUtil.R("WaitMess");
+
+	/**
+	 * {@link Font} used to paint error messages into the map
+	 * 
+	 * @see #addGadgets(Graphics2D, boolean)
+	 */
 	final static Font errorFont = new Font("Arial", Font.BOLD, 13);
 
 	/**
+	 * The wait message painted into the map while rendering is going on on
+	 * another thread.
+	 * 
+	 * @see #addGadgets(Graphics2D, boolean)
+	 */
+	final String waitMsg = SwingUtil.R("WaitMess");
+
+	/**
 	 * Flag fuer Modus "Heran zoomen".
 	 * 
 	 * @see #setState(int)
@@ -249,38 +271,19 @@
 
 		@Override
 		public void layerAdded(final MapLayerListEvent event) {
-
 			MapLayer layer = event.getLayer();
-
 			layer.addMapLayerListener(bgMapLayerListener);
-
-			if (localContext.getLayers().length == 0
-					&& bgContext.getLayers().length == 1) { // the first one and
-				// localContext is
-				// empty
-				if (!setMapArea(localContext.getAreaOfInterest()))
-					requestStartRendering();
-				return;
-			}
-
-			// We need to redraw, even in case that the mapArea didn't change
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 
 		}
 
 		@Override
 		public void layerChanged(final MapLayerListEvent event) {
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 
 		@Override
 		public void layerMoved(final MapLayerListEvent event) {
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 
@@ -288,8 +291,6 @@
 		public void layerRemoved(final MapLayerListEvent event) {
 			if (event.getLayer() != null)
 				event.getLayer().removeMapLayerListener(bgMapLayerListener);
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 	};
@@ -317,7 +318,7 @@
 	 * {@link Image}.
 	 */
 	private BufferedImage bgImage;
-	
+
 	/**
 	 * This {@link Image} is a merge of the {@link #bgImage},
 	 * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
@@ -326,7 +327,6 @@
 	 */
 	private BufferedImage finalImage;
 
-
 	/**
 	 * Optionally a transparent image to paint over the map in the lower right
 	 * corner.
@@ -391,35 +391,18 @@
 			event.getLayer().addMapLayerListener(localMapLayerListener);
 
 			localRenderer.setContext(getContext());
-
-			if (localContext.getLayers().length == 1) { // the first one
-
-				// if the Area of Interest is unset, the LayerBounds are used
-				if (!setMapArea(localContext.getAreaOfInterest()))
-					repaint();
-
-				return;
-			}
-
-			// We need to redraw, even in case that the mapArea didn't change
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 
 		}
 
 		@Override
 		public void layerChanged(final MapLayerListEvent event) {
-			// mapImageInvalid = true;
-			// repaint();
 			localRenderer.setContext(getContext());
 			requestStartRendering();
 		}
 
 		@Override
 		public void layerMoved(final MapLayerListEvent event) {
-			// mapImageInvalid = true;
-			// repaint();
 			localRenderer.setContext(getContext());
 			requestStartRendering();
 		}
@@ -428,8 +411,6 @@
 		public void layerRemoved(final MapLayerListEvent event) {
 			if (event.getLayer() != null)
 				event.getLayer().removeMapLayerListener(localMapLayerListener);
-			// mapImageInvalid = true;
-			// repaint();
 			localRenderer.setContext(getContext());
 			requestStartRendering();
 		}
@@ -444,23 +425,16 @@
 		@Override
 		public void layerChanged(final MapLayerEvent event) {
 			localRenderer.setContext(getContext()); // betters for SLD changes?!
-			// Change of SLD for example
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 
 		@Override
 		public void layerHidden(final MapLayerEvent event) {
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 
 		@Override
 		public void layerShown(final MapLayerEvent event) {
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 	};
@@ -540,14 +514,12 @@
 	private Map<Object, Object> rendererHints = GTUtil
 			.getDefaultGTRendererHints(localRenderer);
 
-	/** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #localImage} **/ 
-	private volatile Boolean requestStartRenderingLocal = false;
-	
-	/** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #bgImage} **/
-	private volatile Boolean requestStartRenderingBg = false;
+	/**
+	 * If set to <code>true</code>, the {@link #startRenderThreadsTimer} will
+	 * start rendering {@link Thread}s
+	 **/
+	private volatile Boolean requestStartRendering = false;
 
-	private final Timer resizeTimer;
-
 	/**
 	 * Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten
 	 * (lat/lon)
@@ -555,7 +527,7 @@
 	protected AffineTransform screenToWorld = null;
 
 	/**
-	 * The flag {@link #requestStartRenderingLocal} can be set to true by events.
+	 * The flag {@link #requestStartRendering} can be set to true by events.
 	 * This {@link Timer} checks the flag regularly and starts one renderer
 	 * thread.
 	 */
@@ -584,6 +556,10 @@
 	/** Is set if a renderer has an error **/
 	protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
 
+	// /** If {@link #getVisibleRect()} of this {@link JPanel} is not yet
+	// defined, but we are **/
+	// private Envelope mapAreaCondidate = null;
+
 	public XMapPane() {
 		this(null, null);
 	}
@@ -629,47 +605,58 @@
 				new ActionListener() {
 
 					public void actionPerformed(final ActionEvent e) {
-						paneResized = true;
-
 						if (!isWellDefined())
 							return;
 
 						final Rectangle bounds = getVisibleRect();
+						//
+						// System.out.println("\n\ntimer performs with bounds = "
+						// + bounds);
 
 						final Envelope geoMapArea = tranformWindowToGeo(
 								bounds.x, bounds.y, bounds.x + bounds.width,
 								bounds.y + bounds.height);
 
-						setMapArea(bestAllowedMapArea(geoMapArea));
+						if (setMapArea(geoMapArea))
+							paneResized = true;
+						// else
+						// syso
 					}
 				});
 		resizeTimer.setRepeats(false);
-		
-//		this.addComponentListener(new ComponentAdapter() {
-//
-//			@Override
-//			public void componentResized(final ComponentEvent e) {
-//				if (bgExecuter != null)
-//					bgExecuter.cancelTask();
-//				if (localExecuter != null)
-//					localExecuter.cancelTask();
-//				resizeTimer.restart();
-//			}
-//
-//		});
 
+		this.addComponentListener(new ComponentAdapter() {
+
+			@Override
+			public void componentResized(final ComponentEvent e) {
+
+				// Already cancel the tasks...
+				if (bgExecuter != null)
+					bgExecuter.cancelTask();
+				if (localExecuter != null)
+					localExecuter.cancelTask();
+
+				resizeTimer.restart();
+			}
+
+		});
+
 		/*
 		 * Setting up the repaintTimer. Not started automatically.
 		 */
-		repaintTimer = new Timer((int) REPEATING_REPAINT_DELAY,
-				new ActionListener() {
+		repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() {
 
-					@Override
-					public void actionPerformed(final ActionEvent e) {
-						updateFinalImage();
-						XMapPane.this.repaint();
-					}
-				});
+			@Override
+			public void actionPerformed(final ActionEvent e) {
+				if ((localExecuter != null && !localExecuter.isRunning())
+						&& (bgExecuter != null && !bgExecuter.isRunning())) {
+					repaintTimer.stop();
+				} else {
+					updateFinalImage();
+					XMapPane.this.repaint(100);
+				}
+			}
+		});
 		repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY);
 		repaintTimer.setRepeats(true);
 
@@ -681,13 +668,16 @@
 
 			@Override
 			public void actionPerformed(final ActionEvent e) {
-				synchronized (requestStartRenderingLocal) {
-					if (requestStartRenderingLocal && isWellDefined()) {
+				synchronized (requestStartRendering) {
+					if (requestStartRendering && isWellDefined()) {
 
 						if (localExecuter.isRunning()) {
 							localExecuter.cancelTask();
 						} else {
-							requestStartRenderingLocal = false;
+
+							// Stupidly, but we have to recheck the
+							setMapArea(getMapArea());
+							requestStartRendering = false;
 							startRendering();
 						}
 					}
@@ -719,10 +709,11 @@
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
 	 */
-	public Envelope bestAllowedMapArea(Envelope env) {
-		// return env;
+	public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) {
+
 		if (getWidth() == 0)
 			return env;
+
 		if (env == null)
 			return null;
 
@@ -801,8 +792,9 @@
 
 					// LOGGER.debug("and fix aspect ratio");
 
-					newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
-							false);
+					newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
+							new ReferencedEnvelope(newArea, env
+									.getCoordinateReferenceSystem()), false);
 				}
 			}
 
@@ -825,8 +817,9 @@
 
 					// LOGGER.debug("and fix aspect ratio");
 
-					newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
-							false);
+					newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
+							new ReferencedEnvelope(newArea, env
+									.getCoordinateReferenceSystem()), false);
 				}
 			}
 
@@ -851,8 +844,9 @@
 
 					// LOGGER.debug("and fix aspect ratio");
 
-					newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
-							false);
+					newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
+							new ReferencedEnvelope(newArea, env
+									.getCoordinateReferenceSystem()), false);
 				}
 			}
 
@@ -877,13 +871,15 @@
 
 					// LOGGER.debug("and fix aspect ratio");
 
-					newArea = JTSUtil.fixAspectRatio(getVisibleRect(), newArea,
-							false);
+					newArea = JTSUtil.fixAspectRatio(getVisibleRect(),
+							new ReferencedEnvelope(newArea, env
+									.getCoordinateReferenceSystem()), false);
 				}
 			}
 		}
 
-		return newArea;
+		return new ReferencedEnvelope(newArea, env
+				.getCoordinateReferenceSystem());
 	}
 
 	/**
@@ -1098,13 +1094,20 @@
 			try {
 				mapArea_ = localContext.getLayerBounds();
 			} catch (final IOException e) {
-				LOGGER.warn("context.getLayerBounds()", e);
+				LOGGER.warn("localContext.getLayerBounds()", e);
 			}
 
+			if (mapArea_ == null && bgContext != null) {
+				try {
+					mapArea_ = bgContext.getLayerBounds();
+				} catch (final IOException e) {
+					LOGGER.warn("bgContext.getLayerBounds()", e);
+				}
+			}
+
 			if (mapArea_ != null) {
-				mapImageInvalid = true; /* note we need to redraw */
-				// setMapArea(mapArea_); // results in a loop
 				mapArea = bestAllowedMapArea(mapArea_);
+				requestStartRendering();
 			}
 		}
 
@@ -1277,19 +1280,17 @@
 	 * {@link XMapPane} is visible and has bounds set.
 	 */
 	public boolean isWellDefined() {
-
 		try {
-
 			if (getContext() == null)
 				return false;
 			if (getContext().getLayerCount() <= 0)
 				return false;
-			if (getMapArea() == null)
+			if (getVisibleRect().getWidth() == 0)
 				return false;
-			if (getBounds().getWidth() == 0)
+			if (getVisibleRect().getHeight() == 0)
 				return false;
-			if (getBounds().getHeight() == 0)
-				return false;
+			// if (getMapArea() == null)
+			// return false;
 		} catch (final Exception e) {
 			return false;
 		}
@@ -1377,8 +1378,8 @@
 	 * Called by the {@link RenderingExecutor} when rendering was cancelled.
 	 */
 	public void onRenderingCancelled() {
-		repaintTimer.stop();
 		LOGGER.debug("Rendering cancelled");
+		repaintTimer.stop();
 	}
 
 	/**
@@ -1422,6 +1423,7 @@
 
 	@Override
 	protected void paintComponent(final Graphics g) {
+
 		if (!acceptsRepaintCalls)
 			return;
 
@@ -1441,7 +1443,7 @@
 			// happening.
 			if (mapAreaChanged && oldMapArea != null
 					&& getMapArea().intersects(oldMapArea)
-					& !getMapArea().equals(oldMapArea)) {
+					& !getMapArea().equals(oldMapArea) && !paneResized) {
 
 				mapAreaChanged = false;
 
@@ -1455,14 +1457,14 @@
 
 			}
 
-			if (paneResized) {
-				paneResized = false;
-				disposeImages();
-			}
+			// if (paneResized) {
+			// paneResized = false;
+			// disposeImages();
+			// }
+			//
+			// // Start the Threads and Timers to render the image
+			// requestStartRendering();
 
-			// Start the Threads and Timers to render the image
-			requestStartRendering();
-
 		}
 
 		if (!paintedSomething) {
@@ -1592,48 +1594,16 @@
 			bgExecuter.cancelTask();
 		if (localExecuter != null)
 			localExecuter.cancelTask();
-		requestStartRenderingLocal = true;
 
+		mapImageInvalid = true;
+		if (paneResized) {
+			paneResized = false;
+			disposeImages();
+		}
+		requestStartRendering = true;
+
 	}
 
-	//
-	// /**
-	// * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten
-	// * neu.
-	// */
-	// protected void resetTransforms() {
-	// if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)
-	// return;
-	//
-	// // We store the last Transform
-	// oldScreenToWorld = screenToWorld;
-	//
-	// this.screenToWorld = new AffineTransform(
-	// // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten
-	// // nach rechts (Osten) hin groesser
-	// // --> positive Verschiebung
-	// getMapArea().getWidth() / getWidth(),
-	// // keine Verzerrung
-	// 0.0, 0.0,
-	// // Waehrend die Fenster-Koordinaten nach unten hin groesser
-	// // werden,
-	// // werden Latitude-Koordinaten nach Sueden hin keiner
-	// // --> negative Verschiebung
-	// -getMapArea().getHeight() / getHeight(),
-	// // Die Longitude-Koordinaten werden nach Osten hin groesser
-	// // --> obere linke Ecke des Fensters hat also den Minimalwert
-	// getMapArea().getMinX(),
-	// // Die Latitude-Koordinaten werden nach Norden hin groesser
-	// // --> obere linke Ecke des Fensters hat also den Maximalwert
-	// getMapArea().getMaxY());
-	//
-	// try {
-	// this.worldToScreen = screenToWorld.createInverse();
-	// } catch (final NoninvertibleTransformException e) {
-	// LOGGER.error(e);
-	// }
-	// }
-
 	/**
 	 * Calculate the affine transforms used to convert between world and pixel
 	 * coordinates. The calculations here are very basic and assume a cartesian
@@ -1651,27 +1621,21 @@
 		ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
 				getContext().getCoordinateReferenceSystem());
 
-		Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!
+		// System.out
+		// .println("paintArea in resetTeansofrms = " + getVisibleRect());
+		if (!isWellDefined())
+			return;
 
-		//        
-		// double xscale = paintArea.getWidth() / refEnv.getWidth();
-		// double yscale = paintArea.getHeight() / refEnv.getHeight();
-		//
-		// double scale = Math.min(xscale, yscale);
-		//
-		// double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();
-		// double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();
-
 		worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
-				paintArea);
+				getVisibleRect());
 
-		// worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff,
-		// yoff);
 		try {
 			screenToWorld = worldToScreen.createInverse();
 
 		} catch (NoninvertibleTransformException ex) {
-			ex.printStackTrace();
+			LOGGER
+					.error("can't invert worldToScreen to get screenToWorld!",
+							ex);
 		}
 	}
 
@@ -1690,7 +1654,7 @@
 		this.bgContext = context;
 
 		if (context != null) {
-			setMapArea(bgContext.getAreaOfInterest());
+			// setMapArea(bgContext.getAreaOfInterest());
 
 			this.bgContext.addMapLayerListListener(bgContextListener);
 
@@ -1699,18 +1663,14 @@
 				mapLayer.addMapLayerListener(bgMapLayerListener);
 			}
 		}
-		mapImageInvalid = true;
-		repaint();
+
+		requestStartRendering();
 	}
 
 	public void setJava2dHints(final RenderingHints java2dHints) {
 		this.java2dHints = java2dHints;
 	}
 
-	/**
-	 * 
-	 * @param context
-	 */
 	public void setLocalContext(final MapContext context) {
 		// Remove the default listener from the old context
 		if (this.localContext != null) {
@@ -1726,7 +1686,7 @@
 
 		if (context != null) {
 
-			setMapArea(localContext.getAreaOfInterest());
+			// setMapArea(localContext.getAreaOfInterest());
 
 			localRenderer.setContext(localContext);
 
@@ -1738,16 +1698,29 @@
 			}
 		}
 
-		mapImageInvalid = true;
-		repaint();
+		requestStartRendering();
+
 	}
 
+	public boolean setMapArea(final Envelope newMapArea) {
+		return setMapArea(new ReferencedEnvelope(newMapArea, getContext()
+				.getCoordinateReferenceSystem()));
+	}
+
 	/**
 	 * @param newMapArea
 	 * @return <code>true</code> if the mapArea has been changed and a repaint
 	 *         has been triggered.
 	 */
-	public boolean setMapArea(final Envelope newMapArea) {
+	public boolean setMapArea(final ReferencedEnvelope newMapArea) {
+		//		
+		// if (getVisibleRect().getWidth() == 0 || (!isVisible()) ||
+		// getVisibleRect().getHeight() == 0) {
+		// // The window is not yet defined.. so we can not really determine the
+		// asepect ratio for the mapPane. We store this as a candidate mappane
+		// and handle it when the component resizes or becomes visible)
+		// mapAreaCondidate = newMapArea;
+		// }
 
 		if (newMapArea == null
 				|| bestAllowedMapArea(newMapArea).equals(mapArea)) {
@@ -1802,11 +1775,13 @@
 			bgContext.setAreaOfInterest(mapArea, localContext
 					.getCoordinateReferenceSystem());
 		}
-		mapImageInvalid = true;
+
 		mapAreaChanged = true;
-		repaint();
 
-		LOGGER.debug("New maparea = " + mapArea);
+		repaint(100);
+
+		requestStartRendering();
+
 		return true;
 	}
 
@@ -1956,8 +1931,10 @@
 	 */
 	private void startRendering() {
 
-		if (!isWellDefined())
+		if (!isWellDefined() || !acceptsRepaintCalls) {
+			requestStartRendering = true;
 			return;
+		}
 
 		if (bgExecuter != null) {
 			// Stop all renderers
@@ -1996,14 +1973,16 @@
 			localRenderer.setJava2DHints(getJava2dHints());
 			localRenderer.setRendererHints(getRendererHints());
 
-			ReferencedEnvelope areaOfInterest = getMapArea();
-			final boolean submitted = localExecuter.submit(areaOfInterest,
+			final boolean submitted = localExecuter.submit(getMapArea(),
 					curPaintArea, (Graphics2D) getLocalImage().getGraphics(),
-					localRenderer, getWorldToScreenTransform());
+					localRenderer
+			// , getWorldToScreenTransform()
+					);
 			if (submitted)
 				repaintTimer.restart();
 			else
-				requestStartRenderingLocal = true; // Try to start rendering again in
+				requestStartRendering = true; // Try to start rendering
+			// again in
 			// a moment
 		}
 
@@ -2079,7 +2058,7 @@
 		} else {
 			// Allow one last rendering
 			if (repaintTimer.isRunning()) {
-				System.out.println("one last rendering....");
+				// System.out.println("one last rendering....");
 				repaintTimer.stop();
 				updateFinalImage();
 				repaint();
@@ -2220,6 +2199,11 @@
 
 				String errStr = ex.getLocalizedMessage();
 
+				if (errStr == null)
+					errStr = ex.getMessage();
+				if (errStr == null)
+					errStr = "unknown error: " + ex.getClass().getSimpleName();
+
 				graphics.setColor(Color.WHITE);
 				graphics.drawString(errStr, 5, y);
 				graphics.setColor(Color.RED);



More information about the Schmitzm-commits mailing list