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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Nov 28 03:25:08 CET 2009


Author: alfonx
Date: 2009-11-28 03:25:08 +0100 (Sat, 28 Nov 2009)
New Revision: 596

Modified:
   branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java
Log:
* Removed a bug in ZoomXMapPaneMouseListener.. one flicker less when zooming out with right mouse button

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-28 01:12:42 UTC (rev 595)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java	2009-11-28 02:25:08 UTC (rev 596)
@@ -2392,11 +2392,10 @@
 				.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea
 				.getHeight()) / 2.);
 
-		// TODO we actually want that
 		// // Move the newMapArea above the new center
-		// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
-		// .getY()
-		// - mapArea.centre().y);
+		newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
+				.getY()
+				- mapArea.centre().y);
 
 		setMapArea(newMapArea);
 	}

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-28 01:12:42 UTC (rev 595)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/ZoomXMapPaneMouseListener.java	2009-11-28 02:25:08 UTC (rev 596)
@@ -4,15 +4,12 @@
 import java.awt.Graphics;
 import java.awt.Point;
 import java.awt.Rectangle;
-import java.awt.event.InputEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseWheelEvent;
 
 import org.apache.log4j.Logger;
 
-import schmitzm.swing.SwingUtil;
-
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
 
@@ -21,13 +18,13 @@
 	private static Logger LOGGER = Logger
 			.getLogger(ZoomXMapPaneMouseListener.class);
 
-
 	protected final XMapPane xMapPane;
 
 	protected boolean enabled = true;
 
 	public ZoomXMapPaneMouseListener(XMapPane xMapPane) {
-		if (xMapPane == null) throw new IllegalArgumentException("xMapPane may not be null");
+		if (xMapPane == null)
+			throw new IllegalArgumentException("xMapPane may not be null");
 		this.xMapPane = xMapPane;
 	}
 
@@ -35,11 +32,11 @@
 	 * Stores beginning of a drag event in window coordinates
 	 */
 	protected Point startPos;
-	
+
 	/**
 	 * Stores last position of a drag event in window coordinates
 	 */
-	protected  Point lastPos;
+	protected Point lastPos;
 
 	/**
 	 * Draws a rectangle in XOR mode from the origin at {@link #startPos} to the
@@ -72,6 +69,21 @@
 		if (!isEnabled())
 			return;
 
+		if ((xMapPane.getState() == XMapPane.PAN)
+		// || (e.getButton() == MouseEvent.BUTTON3 && xMapPane.getState() ==
+		// XMapPane.ZOOM_IN)
+		) {
+			xMapPane.performPan();
+			return;
+		}
+
+		// If this is a click, let mouseClicked handle it!
+		if ((Math.abs(startPos.x - e.getPoint().x) * Math.abs(e.getPoint().y
+				- startPos.y)) < 160) {
+			// xMapPane.zoomTo(e.getPoint(), .5);
+			return;
+		}
+
 		final Rectangle bounds = xMapPane.getBounds();
 
 		Envelope mapArea = xMapPane.getMapArea();
@@ -89,20 +101,10 @@
 		final double endY = (((bounds.getHeight() - e.getPoint().y) * mapHeight) / (double) bounds.height)
 				+ mapArea.getMinY();
 
-		if ((xMapPane.getState() == XMapPane.PAN)
-				|| (e.getButton() == MouseEvent.BUTTON3 && xMapPane.getState() == XMapPane.ZOOM_IN)) {
-			xMapPane.performPan();
+		if (xMapPane.getState() == XMapPane.ZOOM_IN) {
 
-		} else if (xMapPane.getState() == XMapPane.ZOOM_IN) {
-
 			drawRectangle(xMapPane.getGraphics(), e.getPoint());
 
-			// Don't zoom too small areas. Handle it like a click then
-			if ((Math.abs(startPos.x - e.getPoint().x) * Math.abs(e.getPoint().y - startPos.y)) < 160) {
-				xMapPane.zoomTo(e.getPoint(), .5);
-				return;
-			}
-
 			final double left = Math.min(startX, endX);
 			final double right = Math.max(startX, endX);
 			final double bottom = Math.min(startY, endY);
@@ -116,15 +118,14 @@
 
 			// Remove the rectangle
 			drawRectangle(xMapPane.getGraphics(), e.getPoint());
-			
-			
+			//
+			// // Don't zoom too small areas
+			// if ((Math.abs(startPos.x - e.getPoint().x) * Math
+			// .abs(e.getPoint().y - startPos.y)) < 100) {
+			// xMapPane.zoomTo(e.getPoint(), 2.);
+			// return;
+			// }
 
-			// Don't zoom too small areas
-			if ((Math.abs(startPos.x - e.getPoint().x) * Math.abs(e.getPoint().y - startPos.y)) < 100) {
-				xMapPane.zoomTo(e.getPoint(), 2.);
-				return;
-			}
-
 			// make the dragged rectangle in screen coords the new map size?
 			final double left = Math.min(startX, endX);
 			final double right = Math.max(startX, endX);
@@ -148,10 +149,8 @@
 			xMapPane.setMapArea(new Envelope(ll, ur));
 		}
 
-
 	}
 
-
 	public void setEnabled(boolean enabled) {
 		this.enabled = enabled;
 	}
@@ -163,7 +162,7 @@
 	public boolean isEnabled() {
 		return enabled && xMapPane.isWellDefined();
 	}
-	
+
 	/**
 	 * Verarbeitet die Mausrad-Aktion, indem gezoomed wird.
 	 * 
@@ -171,7 +170,8 @@
 	 *            Mausrad-Event
 	 */
 	public void mouseWheelMoved(MouseWheelEvent wheelEvt) {
-		if (!isEnabled()) return;
+		if (!isEnabled())
+			return;
 
 		final int units = wheelEvt.getUnitsToScroll();
 		if (units > 0)
@@ -239,12 +239,10 @@
 	public void mouseDragged(final MouseEvent event) {
 		if (!isEnabled())
 			return;
-		
+
 		xMapPane.mouseDragged(startPos, lastPos, event);
 
-
 		lastPos = event.getPoint();
 	}
 
-
 }



More information about the Schmitzm-commits mailing list