[Schmitzm-commits] r418 - in branches/1.0-gt2-2.6/src: gtmig/org/geotools/swing skrueger/geotools/labelsearch

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Sep 28 17:36:12 CEST 2009


Author: alfonx
Date: 2009-09-28 17:36:11 +0200 (Mon, 28 Sep 2009)
New Revision: 418

Modified:
   branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/SearchMapDialog.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/labelsearch.properties
   branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/labelsearch_de.properties
Log:
* AV-Feature: The Search button only appears if there is anything to search
* GP-Features: Layers that will not show in the atlas legend are marked in the GP MapComposer in gray.


Modified: branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java	2009-09-25 16:34:10 UTC (rev 417)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/JMapPane.java	2009-09-28 15:36:11 UTC (rev 418)
@@ -333,7 +333,7 @@
 				reset = false; /* forget about the reset */
 				oldRect = r; /* store what the current size is */
 
-				mapArea = fixAspectRatio(r, mapArea);
+				mapArea = fixAspectRatio(r, mapArea, false);
 			}
 		}
 
@@ -369,7 +369,14 @@
 		((Graphics2D) g).drawImage(baseImage, 0, 0, this);
 	}
 
-	private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea) {
+	/**
+	 * Returns an {@link Envelope} that has the same aspect ratio as the given rectangle
+	 * @param grow
+	 *            If <code>true</code>, than the area will be enlarged to match
+	 *            the aspect ratio. If <code>false</code>, it will only shrink.
+	 */
+	private Envelope fixAspectRatio(final Rectangle r, final Envelope mapArea,
+			boolean grow) {
 
 		final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
 		final double mapHeight = mapArea.getHeight();
@@ -381,7 +388,7 @@
 		final double scaleY = r.getHeight() / mapArea.getHeight();
 		double scale = 1.0; // stupid compiler!
 
-		if (scaleX > scaleY) { /* pick the smaller scale */
+		if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {
 			scale = scaleX;
 		} else {
 			scale = scaleY;
@@ -665,7 +672,7 @@
 			final Coordinate ur = new Coordinate(right, top);
 			// xulu.sc
 			// mapArea = fixAspectRatio(this.getBounds(), new Envelope(ll, ur));
-			setMapArea(fixAspectRatio(this.getBounds(), new Envelope(ll, ur)));
+			setMapArea(bestAllowedMapArea(new Envelope(ll, ur)));
 			// xulu.ec
 		} else if (state == JMapPane.ZoomIn) {
 
@@ -911,7 +918,7 @@
 		 * Correct the aspect Ratio before we check the rest. Otherwise we might
 		 * easily fail.
 		 */
-		env = fixAspectRatio(this.getBounds(), env);
+		env = fixAspectRatio(this.getBounds(), env, false);
 
 		final double scale = env.getWidth() / getWidth();
 		final double centerX = env.getMinX() + env.getWidth() / 2.;
@@ -947,110 +954,102 @@
 			newArea = new Envelope(ll, ur);
 		}
 
-		if (getMaxExtend() != null) {
+		Envelope maxAllowedExtend = getMaxExtend();
+		while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)) {
+			/*
+			 * If a maxExtend is set, we have to honour that...
+			 */
 
-			while (!getMaxExtend().contains(newArea)) {
-				/*
-				 * If a maxExtend is set, we have to honour that...
-				 */
+			// Exceeds top? Move down and maybe cut
+			if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
+				double divY = newArea.getMaxY() - maxAllowedExtend.getMaxY();
+				LOGGER.debug("Moving area down by " + divY);
 
-				// Exceeds top? Move down and maybe cut
-				if (newArea.getMaxY() > maxExtend.getMaxY()) {
-					double divY = newArea.getMaxY() - maxExtend.getMaxY();
-					LOGGER.debug("Moving area down by " + divY);
+				newArea = new Envelope(new Coordinate(newArea.getMinX(),
+						newArea.getMinY() - divY), new Coordinate(newArea
+						.getMaxX(), newArea.getMaxY() - divY));
 
+				if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
+					LOGGER.debug("Now it exeeds the bottom border.. cut!");
+					// And cut the bottom if it moved out of the area
 					newArea = new Envelope(new Coordinate(newArea.getMinX(),
-							newArea.getMinY() - divY), new Coordinate(newArea
-							.getMaxX(), newArea.getMaxY() - divY));
+							maxAllowedExtend.getMinY()), new Coordinate(newArea
+							.getMaxX(), newArea.getMaxY()));
 
-					if (newArea.getMinY() < maxExtend.getMinY()) {
-						LOGGER.debug("Now it exeeds the bottom border.. cut!");
-						// And cut the bottom if it moved out of the area
-						newArea = new Envelope(new Coordinate(
-								newArea.getMinX(), maxExtend.getMinY()),
-								new Coordinate(newArea.getMaxX(), newArea
-										.getMaxY()));
+					LOGGER.debug("and fix aspect ratio");
 
-						LOGGER.debug("and fix aspect ratio");
-
-						newArea = fixAspectRatio(this.getBounds(), newArea);
-					}
+					newArea = fixAspectRatio(this.getBounds(), newArea, false);
 				}
+			}
 
-				// Exceeds bottom? Move up and maybe cut
-				if (newArea.getMinY() < maxExtend.getMinY()) {
-					double divY = newArea.getMinY() - maxExtend.getMinY();
-					LOGGER.debug("Moving area up by " + divY);
+			// Exceeds bottom? Move up and maybe cut
+			if (newArea.getMinY() < maxAllowedExtend.getMinY()) {
+				double divY = newArea.getMinY() - maxAllowedExtend.getMinY();
+				LOGGER.debug("Moving area up by " + divY);
 
+				newArea = new Envelope(new Coordinate(newArea.getMinX(),
+						newArea.getMinY() - divY), new Coordinate(newArea
+						.getMaxX(), newArea.getMaxY() - divY));
+
+				if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
+					LOGGER.debug("Now it exeeds the top border.. cut!");
+					// And cut the bottom if it moved out of the area
 					newArea = new Envelope(new Coordinate(newArea.getMinX(),
-							newArea.getMinY() - divY), new Coordinate(newArea
-							.getMaxX(), newArea.getMaxY() - divY));
+							newArea.getMinY()), new Coordinate(newArea
+							.getMaxX(), maxAllowedExtend.getMaxY()));
 
-					if (newArea.getMaxY() > maxExtend.getMaxY()) {
-						LOGGER.debug("Now it exeeds the top border.. cut!");
-						// And cut the bottom if it moved out of the area
-						newArea = new Envelope(new Coordinate(
-								newArea.getMinX(), newArea.getMinY()),
-								new Coordinate(newArea.getMaxX(), maxExtend
-										.getMaxY()));
+					LOGGER.debug("and fix aspect ratio");
 
-						LOGGER.debug("and fix aspect ratio");
-
-						newArea = fixAspectRatio(this.getBounds(), newArea);
-					}
+					newArea = fixAspectRatio(this.getBounds(), newArea, false);
 				}
+			}
 
-				// Exceeds to the right? move and maybe cut
-				if (newArea.getMaxX() > maxExtend.getMaxX()) {
+			// Exceeds to the right? move and maybe cut
+			if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
 
-					// Move left..
-					double divX = newArea.getMaxX() - maxExtend.getMaxX();
-					LOGGER.debug("Moving area left by " + divX);
+				// Move left..
+				double divX = newArea.getMaxX() - maxAllowedExtend.getMaxX();
+				LOGGER.debug("Moving area left by " + divX);
 
-					newArea = new Envelope(new Coordinate(newArea.getMinX()
-							- divX, newArea.getMinY()), new Coordinate(newArea
-							.getMaxX()
-							- divX, newArea.getMaxY()));
+				newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
+						newArea.getMinY()), new Coordinate(newArea.getMaxX()
+						- divX, newArea.getMaxY()));
 
-					if (newArea.getMinX() < maxExtend.getMinX()) {
-						LOGGER.debug("Now it exeeds the left border.. cut!");
-						// And cut the left if it moved out of the area
-						newArea = new Envelope(new Coordinate(maxExtend
-								.getMinX(), newArea.getMinY()), new Coordinate(
-								newArea.getMaxX(), newArea.getMaxY()));
+				if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
+					LOGGER.debug("Now it exeeds the left border.. cut!");
+					// And cut the left if it moved out of the area
+					newArea = new Envelope(new Coordinate(maxExtend.getMinX(),
+							newArea.getMinY()), new Coordinate(newArea
+							.getMaxX(), newArea.getMaxY()));
 
-						LOGGER.debug("and fix aspect ratio");
+					LOGGER.debug("and fix aspect ratio");
 
-						newArea = fixAspectRatio(this.getBounds(), newArea);
-					}
+					newArea = fixAspectRatio(this.getBounds(), newArea, false);
 				}
+			}
 
-				// Exceeds to the left? move and maybe cut
-				if (newArea.getMinX() < maxExtend.getMinX()) {
+			// Exceeds to the left? move and maybe cut
+			if (newArea.getMinX() < maxAllowedExtend.getMinX()) {
 
-					// Move right..
-					double divX = newArea.getMinX() - maxExtend.getMinX();
-					LOGGER.debug("Moving area right by " + divX);
+				// Move right..
+				double divX = newArea.getMinX() - maxAllowedExtend.getMinX();
+				LOGGER.debug("Moving area right by " + divX);
 
-					newArea = new Envelope(new Coordinate(newArea.getMinX()
-							- divX, newArea.getMinY()), new Coordinate(newArea
-							.getMaxX()
-							- divX, newArea.getMaxY()));
+				newArea = new Envelope(new Coordinate(newArea.getMinX() - divX,
+						newArea.getMinY()), new Coordinate(newArea.getMaxX()
+						- divX, newArea.getMaxY()));
 
-					if (newArea.getMaxX() > maxExtend.getMaxX()) {
-						LOGGER.debug("Now it exeeds the right border.. cut!");
-						// And cut the left if it moved out of the area
-						newArea = new Envelope(new Coordinate(
-								newArea.getMinX(), newArea.getMinY()),
-								new Coordinate(maxExtend.getMaxX(), newArea
-										.getMaxY()));
+				if (newArea.getMaxX() > maxAllowedExtend.getMaxX()) {
+					LOGGER.debug("Now it exeeds the right border.. cut!");
+					// And cut the left if it moved out of the area
+					newArea = new Envelope(new Coordinate(newArea.getMinX(),
+							newArea.getMinY()), new Coordinate(maxAllowedExtend
+							.getMaxX(), newArea.getMaxY()));
 
-						LOGGER.debug("and fix aspect ratio");
+					LOGGER.debug("and fix aspect ratio");
 
-						newArea = fixAspectRatio(this.getBounds(), newArea);
-					}
+					newArea = fixAspectRatio(this.getBounds(), newArea, false);
 				}
-
 			}
 
 		}
@@ -1115,13 +1114,26 @@
 
 	/**
 	 * Returns the evelope of the viewable area. The JMapPane will never show
-	 * anything outside of this extend.
+	 * anything outside of this extend. If this has been set to
+	 * <code>null</code> via {@link #setMaxExtend(Envelope)}, it tries to return
+	 * quickly the context's bounds. It it takes to long to determine the
+	 * context bounds, <code>null</code> is returned.
 	 * 
 	 * @param maxExtend
 	 *            <code>null</code> to not have this restriction.
 	 */
 
 	public Envelope getMaxExtend() {
+		if (maxExtend == null) {
+			try {
+				return fixAspectRatio(this.getBounds(), context.getLayerBounds(), true);
+			} catch (IOException e) {
+				LOGGER
+						.warn(
+								"maxExtend == null; faild to getLayerBounds of context",
+								e);
+			}
+		}
 		return maxExtend;
 	}
 

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/SearchMapDialog.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/SearchMapDialog.java	2009-09-25 16:34:10 UTC (rev 417)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/SearchMapDialog.java	2009-09-28 15:36:11 UTC (rev 418)
@@ -37,7 +37,6 @@
 
 import java.awt.BorderLayout;
 import java.awt.Cursor;
-import java.awt.FlowLayout;
 import java.awt.Point;
 import java.awt.Window;
 import java.awt.event.KeyAdapter;
@@ -55,6 +54,8 @@
 import javax.swing.ListSelectionModel;
 import javax.swing.SwingWorker;
 
+import net.miginfocom.swing.MigLayout;
+
 import org.apache.log4j.Logger;
 import org.geotools.swing.ExceptionMonitor;
 
@@ -125,25 +126,21 @@
 
 	private void initialize() {
 
-		JPanel cp = new JPanel(new BorderLayout());
+		JPanel cp = new JPanel(new MigLayout("wrap 1","[grow]","[][][grow]"));
 
 		JLabel label = new JLabel(LabelSearch.R("SearchMapDialog.searchString.Label"));
 		label.setLabelFor(searchTextField);
 		searchTextField.setToolTipText(LabelSearch.R("SearchMapDialog.searchString.tt"));
-
 		searchTextField.addKeyListener(keyListenerStartSearch);
-
 		// Pressing ESC disposes the Dialog
 		searchTextField.addKeyListener(keyEscDispose);
+		cp.add(label, "split 2");
+		cp.add(searchTextField);
+		
+		cp.add(new JLabel(LabelSearch.R("SearchMapDialog.Explanation")));
+		
+		cp.add(scrollPane);
 
-		JPanel upper = new JPanel(new FlowLayout(FlowLayout.LEFT));
-		upper.add(label);
-		upper.add(searchTextField);
-
-		cp.add(upper, BorderLayout.NORTH);
-
-		SwingUtil.setPreferredHeight(scrollPane, 0);
-		SwingUtil.setMaximumHeight(scrollPane, 0);
 		cp.add(scrollPane, BorderLayout.SOUTH);
 
 		cp.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/labelsearch.properties
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/labelsearch.properties	2009-09-25 16:34:10 UTC (rev 417)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/labelsearch.properties	2009-09-28 15:36:11 UTC (rev 418)
@@ -60,3 +60,4 @@
 SearchMapDialog.searchString.tt=Enter text and press [Enter or Return].
 SearchMapDialog.title=Search labels in map\: ${0}
 
+SearchMapDialog.Explanation=<html>Here you can search all of the map's <b>labels</b>.</html>  

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/labelsearch_de.properties
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/labelsearch_de.properties	2009-09-25 16:34:10 UTC (rev 417)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/labelsearch_de.properties	2009-09-28 15:36:11 UTC (rev 418)
@@ -59,3 +59,5 @@
 SearchMapDialog.searchString.Label=Suchbegriff eingeben:
 SearchMapDialog.searchString.tt=Geben Sie den Suchbegriff ein und drücken Sie [Enter]
 SearchMapDialog.title=Durchsuche Karte: ${0}
+
+SearchMapDialog.Explanation=<html>Es werden alle <b>Beschriftungen</b> dieser Karte durchsucht.</html> 



More information about the Schmitzm-commits mailing list