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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 3 17:10:44 CET 2010


Author: alfonx
Date: 2010-02-03 17:10:12 +0100 (Wed, 03 Feb 2010)
New Revision: 660

Modified:
   branches/2.0-RC2/src/skrueger/geotools/XMapPane.java
Log:
XMapPane default maxMapArea now expands as you like it...

Modified: branches/2.0-RC2/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/XMapPane.java	2010-02-03 15:35:20 UTC (rev 659)
+++ branches/2.0-RC2/src/skrueger/geotools/XMapPane.java	2010-02-03 16:10:12 UTC (rev 660)
@@ -13,7 +13,6 @@
 import java.awt.event.ActionListener;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
-import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.geom.AffineTransform;
@@ -100,10 +99,24 @@
  */
 public class XMapPane extends JPanel {
 
+	/**
+	 * If {@link #maxExtend} is <code>null</code> the following rules are used
+	 * to create a default maximum.
+	 * <ul>
+	 * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
+	 * margin</li>
+	 * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
+	 * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
+	 * relative margin</li>
+	 * </ul>
+	 * **/
+	private double defaultMaxMapExtendMode = .05;
+
 	// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB;
 	// private static final int IMAGETYPE_withAlpha =
 	// BufferedImage.TYPE_INT_ARGB;
 	private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR;
+
 	public XMapPaneTool getTool() {
 		return tool;
 	}
@@ -178,29 +191,29 @@
 	 * Flag for no-tool.
 	 */
 	public static final int NONE = -123;
-//
-//	/**
-//	 * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
-//	 * moeglich!
-//	 * 
-//	 * @see #setState(int)
-//	 */
-//	public static final int PAN = 1;
-//
-//	/**
-//	 * Flag fuer Modus "Heran zoomen".
-//	 * 
-//	 * @see #setState(int)
-//	 * @see #setState(int)
-//	 */
-//	public static final int ZOOM_IN = 2;
-//
-//	/**
-//	 * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
-//	 * 
-//	 * @see #setState(int)
-//	 */
-//	public static final int ZOOM_OUT = 3;
+	//
+	// /**
+	// * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl
+	// * moeglich!
+	// *
+	// * @see #setState(int)
+	// */
+	// public static final int PAN = 1;
+	//
+	// /**
+	// * Flag fuer Modus "Heran zoomen".
+	// *
+	// * @see #setState(int)
+	// * @see #setState(int)
+	// */
+	// public static final int ZOOM_IN = 2;
+	//
+	// /**
+	// * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich!
+	// *
+	// * @see #setState(int)
+	// */
+	// public static final int ZOOM_OUT = 3;
 
 	/**
 	 * {@link Font} used to paint the wait messages into the map
@@ -541,18 +554,18 @@
 	 * thread.
 	 */
 	final private Timer startRenderThreadsTimer;
-//
-//	/**
-//	 * The default state is ZOOM_IN, hence by default the
-//	 * {@link #xMapPaneMouseListener} is also enabled.
-//	 **/
-//	private int state = ZOOM_IN;
-//
-//	/**
-//	 * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
-//	 * MapPane-Funktion
-//	 */
-//	protected Cursor staticCursor = null;
+	//
+	// /**
+	// * The default state is ZOOM_IN, hence by default the
+	// * {@link #xMapPaneMouseListener} is also enabled.
+	// **/
+	// private int state = ZOOM_IN;
+	//
+	// /**
+	// * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen
+	// * MapPane-Funktion
+	// */
+	// protected Cursor staticCursor = null;
 
 	private AffineTransform worldToScreen;
 
@@ -611,10 +624,10 @@
 		this.addMouseListener(xMapPaneMouseListener);
 		this.addMouseMotionListener(xMapPaneMouseListener);
 		this.addMouseWheelListener(xMapPaneMouseListener);
-		
+
 		// By default the XMapPAne uses the ZOOM_IN tool.
 		setTool(XMapPaneTool.ZOOM_IN);
-		
+
 		/*
 		 * We use a Timer object to avoid rendering delays and flickering when
 		 * the user is drag-resizing the parent container of this map pane.
@@ -1010,13 +1023,12 @@
 			return;
 
 		graphics.setXORMode(color);
-		
+
 		if (fill) {
 			graphics.fillRect(left, bottom, width, height);
-			graphics.setXORMode(Color.WHITE);	
+			graphics.setXORMode(Color.WHITE);
 		}
-		
-		
+
 		graphics.drawRect(left, bottom, width, height);
 	}
 
@@ -1228,12 +1240,9 @@
 				return null;
 			}
 
-			// Vergrößerung um 10% nochmal rausgenommen
-			// // // Kartenbereich um 10% vergroessern
-			// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil
-			// .expandEnvelope(layerBounds, 0.1), true);
+			return JTSUtil
+					.fixAspectRatio(getVisibleRect(), addDefaultMargin(layerBounds), true);
 
-			return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true);
 		}
 		return maxExtend;
 	}
@@ -1288,20 +1297,21 @@
 		return new AffineTransform(screenToWorld);
 	}
 
-//	public int getState() {
-//		return state;
-//	}
-//
-//	/**
-//	 * Liefert den statisch eingestellten Cursor, der unabhaengig von der
-//	 * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
-//	 * 
-//	 * @return {@code null}, wenn kein statischer Cursor verwendet, sondern der
-//	 *         Cursor automatisch je nach MapPane-Aktion eingestellt wird.
-//	 */
-//	public Cursor getStaticCursor() {
-//		return this.staticCursor;
-//	}
+	// public int getState() {
+	// return state;
+	// }
+	//
+	// /**
+	// * Liefert den statisch eingestellten Cursor, der unabhaengig von der
+	// * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird.
+	// *
+	// * @return {@code null}, wenn kein statischer Cursor verwendet, sondern
+	// der
+	// * Cursor automatisch je nach MapPane-Aktion eingestellt wird.
+	// */
+	// public Cursor getStaticCursor() {
+	// return this.staticCursor;
+	// }
 
 	public AffineTransform getWorldToScreenTransform() {
 		if (worldToScreen == null) {
@@ -1589,38 +1599,40 @@
 		}
 
 	}
-//
-//	/**
-//	 * Performs a {@value #PAN} action. During panning, the displacement is
-//	 * stored in {@link #imageOrigin} object. Calling {@link #performPan()} will
-//	 * reset the offset and call {@link #setMapArea(Envelope)}.
-//	 */
-//	public void performPan() {
-//
-//		final Rectangle winBounds = getVisibleRect();
-//
-//		winBounds.translate(-imageOrigin.x, -imageOrigin.y);
-//		final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
-//				winBounds.y, winBounds.x + winBounds.width, winBounds.y
-//						+ winBounds.height);
-//
-//		imageOrigin.x = 0;
-//		imageOrigin.y = 0;
-//
-//		if (!setMapArea(newMapArea)) {
-//			/**
-//			 * If setMapArea returns true, the finalImage is updated anyways.
-//			 * This if-case exists to ensure that we repaint a correct image
-//			 * even if the new panning area has been denied.
-//			 */
-//			updateFinalImage();
-//			repaint();
-//		}
-//
-//		if (getCursor() == SwingUtil.PANNING_CURSOR)
-//			setCursor(SwingUtil.PAN_CURSOR);
-//	}
 
+	//
+	// /**
+	// * Performs a {@value #PAN} action. During panning, the displacement is
+	// * stored in {@link #imageOrigin} object. Calling {@link #performPan()}
+	// will
+	// * reset the offset and call {@link #setMapArea(Envelope)}.
+	// */
+	// public void performPan() {
+	//
+	// final Rectangle winBounds = getVisibleRect();
+	//
+	// winBounds.translate(-imageOrigin.x, -imageOrigin.y);
+	// final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
+	// winBounds.y, winBounds.x + winBounds.width, winBounds.y
+	// + winBounds.height);
+	//
+	// imageOrigin.x = 0;
+	// imageOrigin.y = 0;
+	//
+	// if (!setMapArea(newMapArea)) {
+	// /**
+	// * If setMapArea returns true, the finalImage is updated anyways.
+	// * This if-case exists to ensure that we repaint a correct image
+	// * even if the new panning area has been denied.
+	// */
+	// updateFinalImage();
+	// repaint();
+	// }
+	//
+	// if (getCursor() == SwingUtil.PANNING_CURSOR)
+	// setCursor(SwingUtil.PAN_CURSOR);
+	// }
+
 	/**
 	 * Entfernt einen Listener von der Map.
 	 * 
@@ -1960,23 +1972,23 @@
 			this.rendererHints = rendererHints;
 	}
 
-//	@Deprecated
-//	public void setState(final int state) {
-//		this.state = state;
-//
-//		// throw new RuntimeException("Old concept.. migrate to new concept!");
-//
-//		// xMapPaneMouseListener.setEnabled((state == ZOOM_IN
-//		// || state == ZOOM_OUT || state == PAN));
-//
-//		// Je nach Aktion den Cursor umsetzen
-//		updateCursor();
-//	}
+	// @Deprecated
+	// public void setState(final int state) {
+	// this.state = state;
+	//
+	// // throw new RuntimeException("Old concept.. migrate to new concept!");
+	//
+	// // xMapPaneMouseListener.setEnabled((state == ZOOM_IN
+	// // || state == ZOOM_OUT || state == PAN));
+	//
+	// // Je nach Aktion den Cursor umsetzen
+	// updateCursor();
+	// }
 
 	public void configureMouse(MouseInputType type, XMapPaneAction action) {
 		xMapPaneMouseListener.actions.put(type, action);
 	}
-	
+
 	/**
 	 * Configure the {@link XMapPaneTool} that active on the map. Passing
 	 * <code>null</code> will set the NO_ACTION tool.
@@ -1989,21 +2001,22 @@
 		setCursor(tool.getCursor());
 	}
 
-//	/**
-//	 * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom,
-//	 * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
-//	 * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
-//	 * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
-//	 * {@code null} als Parameter uebergeben werden
-//	 * 
-//	 * @param cursor
-//	 *            Cursor
-//	 */
-//	public void setStaticCursor(final Cursor cursor) {
-//		this.staticCursor = cursor;
-//		if (cursor != null)
-//			super.setCursor(cursor);
-//	}
+	// /**
+	// * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion
+	// (Zoom,
+	// * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor
+	// * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion
+	// * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann
+	// * {@code null} als Parameter uebergeben werden
+	// *
+	// * @param cursor
+	// * Cursor
+	// */
+	// public void setStaticCursor(final Cursor cursor) {
+	// this.staticCursor = cursor;
+	// if (cursor != null)
+	// super.setCursor(cursor);
+	// }
 
 	/**
 	 * Starts rendering on one or two threads
@@ -2145,43 +2158,44 @@
 				repaint();
 			}
 		}
-//		
-////
-//		// wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig
-//		// von der aktuellen Aktion
-//		if (this.staticCursor != null) {
-//			setCursor(staticCursor);
-//			return;
-//		}
-//		
+		//		
+		// //
+		// // wenn manueller Cursor gesetzt ist, dann diesen verwenden
+		// (unabhaengig
+		// // von der aktuellen Aktion
+		// if (this.staticCursor != null) {
+		// setCursor(staticCursor);
+		// return;
+		// }
+		//		
 		if (getCursor() == SwingUtil.PANNING_CURSOR) {
 			// This cursor will reset itself
 			return;
 		}
-		
+
 		setCursor(tool.getCursor());
-		
-//
-//		// Set the cursor depending on what tool is in use...
-//		switch (state) {
-//		case SELECT_TOP:
-//		case SELECT_ONE_FROM_TOP:
-//		case SELECT_ALL:
-//			setCursor(SwingUtil.CROSSHAIR_CURSOR);
-//			break;
-//		case ZOOM_IN:
-//			setCursor(SwingUtil.ZOOMIN_CURSOR);
-//			break;
-//		case ZOOM_OUT:
-//			setCursor(SwingUtil.ZOOMOUT_CURSOR);
-//			break;
-//		case PAN:
-//			setCursor(SwingUtil.PAN_CURSOR);
-//			break;
-//		default:
-//			setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
-//			break;
-//		}
+
+		//
+		// // Set the cursor depending on what tool is in use...
+		// switch (state) {
+		// case SELECT_TOP:
+		// case SELECT_ONE_FROM_TOP:
+		// case SELECT_ALL:
+		// setCursor(SwingUtil.CROSSHAIR_CURSOR);
+		// break;
+		// case ZOOM_IN:
+		// setCursor(SwingUtil.ZOOMIN_CURSOR);
+		// break;
+		// case ZOOM_OUT:
+		// setCursor(SwingUtil.ZOOMOUT_CURSOR);
+		// break;
+		// case PAN:
+		// setCursor(SwingUtil.PAN_CURSOR);
+		// break;
+		// default:
+		// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+		// break;
+		// }
 	}
 
 	/**
@@ -2211,8 +2225,8 @@
 
 		final Graphics2D finalG = getFinalImage().createGraphics();
 		finalG.setBackground(getMapBackgroundColor());
-		finalG.drawImage(getPreFinalImage(), getImageOrigin().x, getImageOrigin().y,
-				getMapBackgroundColor(), null);
+		finalG.drawImage(getPreFinalImage(), getImageOrigin().x,
+				getImageOrigin().y, getMapBackgroundColor(), null);
 
 		// When panning, we have to clear the area around the image
 		final Rectangle painedArea = new Rectangle(getImageOrigin().x,
@@ -2221,7 +2235,7 @@
 		SwingUtil.clearAround(finalG, painedArea, getVisibleRect(),
 				getMapBackgroundColor());
 
-//		addGadgets(finalG, false);
+		// addGadgets(finalG, false);
 
 		finalG.dispose();
 
@@ -2382,12 +2396,22 @@
 			// BB umrechnen von Layer-CRS in Map-CRS
 
 			// Expand a bit
-			bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.);
+			addDefaultMargin(bounds);
 
 			setMapArea(bounds);
 		}
 	}
 
+	private ReferencedEnvelope addDefaultMargin(ReferencedEnvelope bounds) {
+		return JTSUtil.expandEnvelope(bounds, Math.max(0,
+				defaultMaxMapExtendMode));
+	}
+
+	private Envelope addDefaultMargin(Envelope bounds) {
+		return JTSUtil.expandEnvelope(bounds, Math.max(0,
+				defaultMaxMapExtendMode));
+	}
+
 	/**
 	 * Zooms towards a point.
 	 * 
@@ -2535,8 +2559,8 @@
 			// genau auf dem Rand der angezeigten Flaeche)
 
 			if (mapAreaNew != null) {
-				mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew
-						.getHeight() * 0.1);
+
+				mapAreaNew = addDefaultMargin(mapAreaNew);
 				setMapArea(mapAreaNew);
 			} else {
 				LOGGER
@@ -2618,4 +2642,34 @@
 		return imageOrigin;
 	}
 
+	/**
+	 * If {@link #maxExtend} is <code>null</code> the following rules are used
+	 * to create a default maximum.
+	 * <ul>
+	 * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
+	 * margin</li>
+	 * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
+	 * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
+	 * relative margin</li>
+	 * </ul>
+	 * **/
+	public void setDefaultMaxMapExtendMode(double defaultMaxMapExtendMode) {
+		this.defaultMaxMapExtendMode = defaultMaxMapExtendMode;
+	}
+
+	/**
+	 * If {@link #maxExtend} is <code>null</code> the following rules are used
+	 * to create a default maximum.
+	 * <ul>
+	 * <li>Values &lt; 0 : don't grow to fit the monitors aspect ratio, no
+	 * margin</li>
+	 * <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li>
+	 * <li>Values &gt; 0 : grow to fit the monitors aspect ratio, and add a
+	 * relative margin</li>
+	 * </ul>
+	 * **/
+	public double getDefaultMaxMapExtendMode() {
+		return defaultMaxMapExtendMode;
+	}
+
 }



More information about the Schmitzm-commits mailing list