[Schmitzm-commits] r648 - branches/2.0-RC2/src/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 28 17:51:57 CET 2010


Author: alfonx
Date: 2010-01-28 17:51:55 +0100 (Thu, 28 Jan 2010)
New Revision: 648

Modified:
   branches/2.0-RC2/src/skrueger/geotools/XMapPane.java
   branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction.java
   branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java
Log:


Modified: branches/2.0-RC2/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/XMapPane.java	2010-01-28 16:50:51 UTC (rev 647)
+++ branches/2.0-RC2/src/skrueger/geotools/XMapPane.java	2010-01-28 16:51:55 UTC (rev 648)
@@ -630,6 +630,10 @@
 		this.addMouseWheelListener(xMapPaneMouseListener);
 		xMapPaneMouseListener.actions.put(MouseInputType.RClick, XMapPaneAction.ZOOM_IN);
 		xMapPaneMouseListener.actions.put(MouseInputType.RDrag, XMapPaneAction.ZOOM_IN);
+		
+		xMapPaneMouseListener.actions.put(MouseInputType.LClick, XMapPaneAction.ZOOM_OUT);
+		xMapPaneMouseListener.actions.put(MouseInputType.LDrag, XMapPaneAction.ZOOM_OUT);
+		
 
 		/*
 		 * We use a Timer object to avoid rendering delays and flickering when

Modified: branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction.java	2010-01-28 16:50:51 UTC (rev 647)
+++ branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction.java	2010-01-28 16:51:55 UTC (rev 648)
@@ -88,5 +88,6 @@
   public void performWheel(XMapPane mapPane, MouseWheelEvent ev, DirectPosition coord);
   
   public static XMapPaneAction_Zoom ZOOM_IN = new XMapPaneAction_Zoom.In();
+  public static XMapPaneAction_Zoom ZOOM_OUT = new XMapPaneAction_Zoom.Out();
 
 }

Modified: branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java	2010-01-28 16:50:51 UTC (rev 647)
+++ branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java	2010-01-28 16:51:55 UTC (rev 648)
@@ -12,82 +12,174 @@
 
 public abstract class XMapPaneAction_Zoom implements XMapPaneAction {
 
-public static class In extends XMapPaneAction_Zoom {
+	public static class In extends XMapPaneAction_Zoom {
 
-	@Override
-	public void performClick(XMapPane mapPane, MouseEvent ev,
-			DirectPosition coord) {
+		@Override
+		public void performClick(XMapPane mapPane, MouseEvent ev,
+				DirectPosition coord) {
 
-		mapPane.zoomTo(ev.getPoint(), 1 / 2.);
-	}
+			mapPane.zoomTo(ev.getPoint(), 1 / 2.);
+		}
 
-	@Override
-	public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
-			DirectPosition coord) {
+		@Override
+		public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
+				DirectPosition coord) {
 
-		final int units = wheelEvt.getUnitsToScroll();
-		if (units > 0)
-			mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);
-		else
-			mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);
-	}
+			final int units = wheelEvt.getUnitsToScroll();
+			if (units > 0)
+				mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);
+			else
+				mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);
+		}
 
-	@Override
-	public void performDragging(XMapPane mapPane, MouseEvent ev,
-			Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
-			DirectPosition endCoord) {
+		@Override
+		public void performDragging(XMapPane mapPane, MouseEvent ev,
+				Point dragStartPos, Point dragLastPos,
+				DirectPosition startCoord, DirectPosition endCoord) {
 
-		if (dragLastPos != null)
-			mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, dragLastPos);
+			if (dragLastPos != null)
+				mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
+						dragLastPos);
 
-		mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
-				.getPoint());
+			mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
+					.getPoint());
+		}
+
+		@Override
+		public void performDragged(XMapPane mapPane, MouseEvent ev,
+				Point dragStartPos, Point dragLastPos,
+				DirectPosition startCoord, DirectPosition endCoord) {
+
+			if (dragLastPos != null)
+				mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
+						dragLastPos);
+
+			// If this is similar to a click, let mouseClicked handle it!
+			if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
+					.getPoint().y
+					- dragStartPos.y)) < 160) {
+				// performClick(mapPane, ev, coord)
+				return;
+			}
+
+			final Rectangle bounds = mapPane.getBounds();
+
+			Envelope mapArea = mapPane.getMapArea();
+
+			// Replace with transform and translate
+			final double mapWidth = mapArea.getWidth();
+			final double mapHeight = mapArea.getHeight();
+
+			final double startX = ((dragStartPos.x * mapWidth) / (double) bounds.width)
+					+ mapArea.getMinX();
+			final double startY = (((bounds.getHeight() - dragStartPos.y) * mapHeight) / (double) bounds.height)
+					+ mapArea.getMinY();
+			final double endX = ((ev.getPoint().x * mapWidth) / (double) bounds.width)
+					+ mapArea.getMinX();
+			final double endY = (((bounds.getHeight() - ev.getPoint().y) * mapHeight) / (double) bounds.height)
+					+ mapArea.getMinY();
+
+			final double left = Math.min(startX, endX);
+			final double right = Math.max(startX, endX);
+			final double bottom = Math.min(startY, endY);
+			final double top = Math.max(startY, endY);
+			final Coordinate ll = new Coordinate(left, bottom);
+			final Coordinate ur = new Coordinate(right, top);
+
+			mapPane.setMapArea(new Envelope(ll, ur));
+
+		}
 	}
 
-	@Override
-	public void performDragged(XMapPane mapPane, MouseEvent ev,
-			Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
-			DirectPosition endCoord) {
+	public static class Out extends XMapPaneAction_Zoom {
 
-		if (dragLastPos != null)
-			mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, dragLastPos );
+		@Override
+		public void performClick(XMapPane mapPane, MouseEvent ev,
+				DirectPosition coord) {
 
-		// If this is similar to a click, let mouseClicked handle it!
-		if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
-				.getPoint().y
-				- dragStartPos.y)) < 160) {
-			// performClick(mapPane, ev, coord)
-			return;
+			mapPane.zoomTo(ev.getPoint(), 2.);
 		}
 
-		final Rectangle bounds = mapPane.getBounds();
+		@Override
+		public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
+				DirectPosition coord) {
 
-		Envelope mapArea = mapPane.getMapArea();
+			final int units = wheelEvt.getUnitsToScroll();
+			if (units <= 0)
+				mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);
+			else
+				mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);
+		}
 
-		// Replace with transform and translate
-		final double mapWidth = mapArea.getWidth();
-		final double mapHeight = mapArea.getHeight();
+		@Override
+		public void performDragging(XMapPane mapPane, MouseEvent ev,
+				Point dragStartPos, Point dragLastPos,
+				DirectPosition startCoord, DirectPosition endCoord) {
 
-		final double startX = ((dragStartPos.x * mapWidth) / (double) bounds.width)
-				+ mapArea.getMinX();
-		final double startY = (((bounds.getHeight() - dragStartPos.y) * mapHeight) / (double) bounds.height)
-				+ mapArea.getMinY();
-		final double endX = ((ev.getPoint().x * mapWidth) / (double) bounds.width)
-				+ mapArea.getMinX();
-		final double endY = (((bounds.getHeight() - ev.getPoint().y) * mapHeight) / (double) bounds.height)
-				+ mapArea.getMinY();
+			if (dragLastPos != null)
+				mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
+						dragLastPos);
 
-		final double left = Math.min(startX, endX);
-		final double right = Math.max(startX, endX);
-		final double bottom = Math.min(startY, endY);
-		final double top = Math.max(startY, endY);
-		final Coordinate ll = new Coordinate(left, bottom);
-		final Coordinate ur = new Coordinate(right, top);
+			mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
+					.getPoint());
+		}
 
-		mapPane.setMapArea(new Envelope(ll, ur));
+		@Override
+		public void performDragged(XMapPane mapPane, MouseEvent ev,
+				Point dragStartPos, Point dragLastPos,
+				DirectPosition startCoord, DirectPosition endCoord) {
 
-	}
+			if (dragLastPos != null)
+				mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
+						dragLastPos);
 
-}
+			// If this is similar to a click, let mouseClicked handle it!
+			if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
+					.getPoint().y
+					- dragStartPos.y)) < 160) {
+				// performClick(mapPane, ev, coord)
+				return;
+			}
 
+			final Rectangle bounds = mapPane.getBounds();
+
+			Envelope mapArea = mapPane.getMapArea();
+
+			// Replace with transform and translate
+			final double mapWidth = mapArea.getWidth();
+			final double mapHeight = mapArea.getHeight();
+
+			final double startX = ((dragStartPos.x * mapWidth) / (double) bounds.width)
+					+ mapArea.getMinX();
+			final double startY = (((bounds.getHeight() - dragStartPos.y) * mapHeight) / (double) bounds.height)
+					+ mapArea.getMinY();
+			final double endX = ((ev.getPoint().x * mapWidth) / (double) bounds.width)
+					+ mapArea.getMinX();
+			final double endY = (((bounds.getHeight() - ev.getPoint().y) * mapHeight) / (double) bounds.height)
+					+ mapArea.getMinY();
+
+			// 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);
+			final double bottom = Math.min(startY, endY);
+			final double top = Math.max(startY, endY);
+			final double nWidth = (mapWidth * mapWidth) / (right - left);
+			final double nHeight = (mapHeight * mapHeight) / (top - bottom);
+			final double deltaX1 = left - mapArea.getMinX();
+			final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
+			final double deltaY1 = bottom - mapArea.getMinY();
+			final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
+			final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
+					mapArea.getMinY() - nDeltaY1);
+			final double deltaX2 = mapArea.getMaxX() - right;
+			final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
+			final double deltaY2 = mapArea.getMaxY() - top;
+			final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
+			final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
+					mapArea.getMaxY() + nDeltaY2);
+
+			mapPane.setMapArea(new Envelope(ll, ur));
+
+		}
+	}
 }
\ No newline at end of file



More information about the Schmitzm-commits mailing list