[Schmitzm-commits] r581 - branches/1.0-gt2-2.6/src/skrueger/geotools

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


Author: alfonx
Date: 2009-11-26 10:18:18 +0100 (Thu, 26 Nov 2009)
New Revision: 581

Modified:
   branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java
Log:
Fixed a bug that lead to a blink when zooming out with the right mouse button


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-25 20:30:02 UTC (rev 580)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java	2009-11-26 09:18:18 UTC (rev 581)
@@ -136,7 +136,7 @@
 				// Kill the reference to this Thread so #isRunning will say
 				// false directly
 				renderThread = null;
-				mapPane.onRenderingCompleted(startT-System.currentTimeMillis());
+				mapPane.onRenderingCompleted(System.currentTimeMillis()-startT);
 			} catch (Exception e) {
 				mapPane.onRenderingFailed(e);
 			} finally {

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-25 20:30:02 UTC (rev 580)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java	2009-11-26 09:18:18 UTC (rev 581)
@@ -232,7 +232,7 @@
 	 * If last average last two renderings took more than that many ms, show the
 	 * user a scaled preview
 	 **/
-	private static final long PRESCALE_MINTIME = 1000;
+	private static final long PRESCALE_MINTIME = 230;
 
 	/**
 	 * The wait message painted into the map while rendering is going on on
@@ -286,7 +286,7 @@
 
 		@Override
 		public void layerAdded(final MapLayerListEvent event) {
-			MapLayer layer = event.getLayer();
+			final MapLayer layer = event.getLayer();
 			layer.addMapLayerListener(bgMapLayerListener);
 			requestStartRendering();
 
@@ -521,12 +521,12 @@
 	 * A flag indicating, that the image size has changed and the buffered
 	 * images are not big enough any more
 	 **/
-	protected boolean paneResized = false;
+	protected boolean paneResized = true;
 
 	private BufferedImage preFinalImage;
 
 	// ** if 0, no quick preview will be shown **/
-	private int quickPreviewHint = 0;
+//	private int quickPreviewHint = 0;
 
 	private Map<Object, Object> rendererHints = GTUtil
 			.getDefaultGTRendererHints(getLocalRenderer());
@@ -639,9 +639,7 @@
 						// bounds.y + bounds.height);
 
 						paneResized = true;
-
 						if (setMapArea(getMapArea())) {
-
 						}
 					}
 				});
@@ -1005,26 +1003,18 @@
 	 * 
 	 * @param g
 	 *            Graphics2D to paint the preview into
-	 * 
-	 * @param state
-	 *            Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT}
 	 */
 	protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
 
 		// if (1 == 1)return false;
+//		if (quickPreviewHint == 0)
+//			return false;
 
-		if (quickPreviewHint == 0)
-			return false;
-
-		graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
-				RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
-		graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-				RenderingHints.VALUE_ANTIALIAS_OFF);
-		graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
-				RenderingHints.VALUE_RENDER_SPEED);
-
 		if (oldMapArea == null)
 			return false;
+		
+		if (getPreFinalImage() == null)
+			return false;
 
 		final Rectangle visibleArea = getVisibleRect();
 
@@ -1038,6 +1028,13 @@
 		final int xx2 = (int) Math.round(oldMapWindow.getMaxX());
 		final int yy2 = (int) Math.round(oldMapWindow.getMaxY());
 
+		graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+				RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
+		graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+				RenderingHints.VALUE_ANTIALIAS_OFF);
+		graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
+				RenderingHints.VALUE_RENDER_SPEED);
+
 		graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2,
 				(int) visibleArea.getMinX(), (int) visibleArea.getMinY(),
 				(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(),
@@ -1051,7 +1048,7 @@
 
 		addGadgets(graphics, true);
 
-		quickPreviewHint = 0;
+//		quickPreviewHint = 0;
 
 		repaintTimer.restart();
 
@@ -1091,7 +1088,7 @@
 					getVisibleRect().height, IMAGETYPE);
 			SwingUtil.clearImage(finalImage, getMapBackgroundColor());
 
-			requestStartRendering();
+//			requestStartRendering();
 		}
 		return finalImage;
 	}
@@ -1150,7 +1147,7 @@
 			try {
 				localContext.setCoordinateReferenceSystem(GeoImportUtil
 						.getDefaultCRS());
-			} catch (Exception e) {
+			} catch (final Exception e) {
 				throw new RuntimeException("setting context CRS:", e);
 			}
 
@@ -1243,16 +1240,6 @@
 	}
 
 	private Image getPreFinalImage() {
-		// if (preFinalImage == null) {
-		//			
-		// // Rectangle curPaintArea = getVisibleRect();
-		// // preFinalImage = new BufferedImage(curPaintArea.width,
-		// // curPaintArea.height, BufferedImage.TYPE_INT_RGB);
-		//			
-		// preFinalImage = createImage(getBounds().width, getBounds().height);
-		//
-		// requestStartRendering();
-		// }
 		return preFinalImage;
 	}
 
@@ -1444,9 +1431,9 @@
 	 * @param l
 	 *            long ms the rendering took
 	 */
-	public void onRenderingCompleted(long l) {
-		// LOGGER.debug("complete");
-		lastRenderingDuration = lastRenderingDuration + l / 2;
+	public void onRenderingCompleted(final long l) {
+		lastRenderingDuration = (lastRenderingDuration + l) / 2;
+		LOGGER.debug("complete rendering after "+lastRenderingDuration+"ms");
 
 		repaintTimer.stop();
 
@@ -1498,13 +1485,13 @@
 
 		if (!isWellDefined())
 			return;
+//
+//		if (paneResized) {
+////			((Graphics2D) g).setBackground(getMapBackgroundColor());
+////			g.clearRect(0, 0, getVisibleRect().width, getVisibleRect().height);
+//			return;
+//		}
 
-		if (paneResized) {
-			((Graphics2D) g).setBackground(getMapBackgroundColor());
-			g.clearRect(0, 0, getVisibleRect().width, getVisibleRect().height);
-			return;
-		}
-
 		// super.paintComponent(g); // candidate for removal
 
 		boolean paintedSomething = false;
@@ -1519,17 +1506,17 @@
 			if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged
 					&& oldMapArea != null
 					&& getMapArea().intersects(oldMapArea)
-					& !getMapArea().equals(oldMapArea) && !paneResized) {
+					&& !getMapArea().equals(oldMapArea) && !paneResized) {
 
 				mapAreaChanged = false;
 
-				if (getMapArea().covers(oldMapArea)) {
-					quickPreviewHint = ZOOM_OUT;
+//				if (getMapArea().covers(oldMapArea)) {
+////					quickPreviewHint = ZOOM_OUT;
+//					paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
+//				} else if (oldMapArea.covers(getMapArea())) {
+//					quickPreviewHint = ZOOM_IN;
 					paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
-				} else if (oldMapArea.covers(getMapArea())) {
-					quickPreviewHint = ZOOM_IN;
-					paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g);
-				}
+//				}
 			}
 		}
 
@@ -1592,7 +1579,7 @@
 	 */
 	public void performPan() {
 
-		Rectangle winBounds = getVisibleRect();
+		final Rectangle winBounds = getVisibleRect();
 
 		winBounds.translate(-imageOrigin.x, -imageOrigin.y);
 		final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
@@ -1660,7 +1647,7 @@
 	 *            the current map pane extent (screen units)
 	 */
 	private void resetTransforms() {
-		ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
+		final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
 				getMapContext().getCoordinateReferenceSystem());
 
 		// System.out
@@ -1674,7 +1661,7 @@
 		try {
 			screenToWorld = worldToScreen.createInverse();
 
-		} catch (NoninvertibleTransformException ex) {
+		} catch (final NoninvertibleTransformException ex) {
 			LOGGER
 					.error("can't invert worldToScreen to get screenToWorld!",
 							ex);
@@ -1744,7 +1731,7 @@
 
 	}
 
-	public void setBorder(Border b) {
+	public void setBorder(final Border b) {
 		super.setBorder(b);
 	}
 
@@ -1861,7 +1848,7 @@
 	 * 
 	 * @param if <code>null</code>, white is used.
 	 */
-	public void setMapBackgroundColor(Color bgColor) {
+	public void setMapBackgroundColor(final Color bgColor) {
 		this.mapBackgroundColor = bgColor;
 	}
 
@@ -2208,11 +2195,11 @@
 	 *            <code>false</code>, it will only depend on
 	 *            {@link #localExecuter.isRunning} and #bgExecuter.isRunning
 	 */
-	private void addGadgets(final Graphics2D graphics, boolean forceWait) {
+	private void addGadgets(final Graphics2D graphics, final boolean forceWait) {
 
 		// Paint a logo to the bottom right if available
 		if (mapImage != null) {
-			Rectangle visibleRect = getVisibleRect();
+			final Rectangle visibleRect = getVisibleRect();
 			graphics.drawImage(mapImage, visibleRect.width
 					- mapImage.getWidth() - 10, getVisibleRect().height
 					- mapImage.getHeight() - 10, null);
@@ -2246,7 +2233,7 @@
 			final Color c = graphics.getColor();
 			graphics.setFont(errorFont);
 
-			for (Exception ex : renderingErrors) {
+			for (final Exception ex : renderingErrors) {
 
 				String errStr = ex.getLocalizedMessage();
 
@@ -2414,7 +2401,7 @@
 	 * Shall non-fatal rendering exceptions be reported in the mappane or be
 	 * dropped quitely.
 	 */
-	public void setShowExceptions(boolean showExceptions) {
+	public void setShowExceptions(final boolean showExceptions) {
 		this.showExceptions = showExceptions;
 	}
 

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java	2009-11-25 20:30:02 UTC (rev 580)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java	2009-11-26 09:18:18 UTC (rev 581)
@@ -90,7 +90,7 @@
 				+ mapArea.getMinY();
 
 		if ((xMapPane.getState() == XMapPane.PAN)
-				|| (e.getButton() == MouseEvent.BUTTON3)) {
+				|| (e.getButton() == MouseEvent.BUTTON3 && xMapPane.getState() == XMapPane.ZOOM_IN)) {
 			xMapPane.performPan();
 
 		} else if (xMapPane.getState() == XMapPane.ZOOM_IN) {



More information about the Schmitzm-commits mailing list