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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Nov 21 16:21:42 CET 2009


Author: alfonx
Date: 2009-11-21 16:21:41 +0100 (Sat, 21 Nov 2009)
New Revision: 543

Modified:
   branches/1.0-gt2-2.6/src/skrueger/geotools/GeomFilterGenerator.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
Log:
* Even better selecting.. BBOX filter was the wrong choice.. INTERSECTS is correct.

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/GeomFilterGenerator.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/GeomFilterGenerator.java	2009-11-21 15:01:05 UTC (rev 542)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/GeomFilterGenerator.java	2009-11-21 15:21:41 UTC (rev 543)
@@ -143,13 +143,9 @@
 			Envelope bbEnv = baseEnv;
 			if (!CRS.equalsIgnoreMetadata(baseCRS, crs))
 				bbEnv = JTSUtil.transformEnvelope(baseEnv, baseCRS, crs);
-			// Filter fuer Envelope zusammenstellen
 			Expression bbox = FilterUtil.FILTER_FAC.createBBoxExpression(bbEnv);
 			GeometryFilterImpl bboxFilter = (GeometryFilterImpl) FilterUtil.FILTER_FAC
-					.createGeometryFilter(AbstractFilter.GEOMETRY_BBOX);
-			// GeometryFilterImpl bboxFilter =
-			// (GeometryFilterImpl)ff.createGeometryFilter(AbstractFilter.
-			// GEOMETRY_WITHIN);
+					.createGeometryFilter(AbstractFilter.GEOMETRY_INTERSECTS);
 			bboxFilter.setExpression2(bbox);
 			return bboxFilter;
 		}

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-21 15:01:05 UTC (rev 542)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java	2009-11-21 15:21:41 UTC (rev 543)
@@ -166,8 +166,6 @@
 	 * @return <code>true</code> if the {@link Thread} is busy rendering.
 	 */
 	public boolean isRunning() {
-		// if (task != null)
-		// System.out.println("is running "+task.getName()+" = true");
 		return (renderThread != null && renderThread.isAlive());
 	}
 

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-21 15:01:05 UTC (rev 542)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java	2009-11-21 15:21:41 UTC (rev 543)
@@ -295,25 +295,38 @@
 	};
 
 	/**
-	 * compass and icon are rendered into this image
+	 * This {@link RenderingExecutor} manages the creation and cancellation of
+	 * up to one {@link Thread} for rendering the {@link #localContext}.
 	 */
-	// protected BufferedImage gadgetsImage;
+	private final RenderingExecutor localExecuter = new RenderingExecutor(this);
 
+	/**
+	 * This {@link RenderingExecutor} manages the creation and cancellation of
+	 * up to one {@link Thread} for rendering the {@link #bgContext}.
+	 */
 	protected RenderingExecutor bgExecuter;
 
 	/**
-	 * The Renderer for the LocalLayers uses this Image. When set to null,
-	 * please dispose this {@link Graphics2D}
+	 * The {@link #localRenderer} for the {@link #localContext} uses this
+	 * {@link Image}.
 	 */
 	private BufferedImage localImage;
 
-	private BufferedImage finalImage;
 	/**
-	 * If # {@link #bgExecuter} is using {@link #bgRenderer} for the Background
-	 * uses this Image. When set to null, please dispose the {@link Graphics2D}
+	 * The {@link #bgRenderer} for the {@link #bgContext} uses this
+	 * {@link Image}.
 	 */
 	private BufferedImage bgImage;
+	
+	/**
+	 * This {@link Image} is a merge of the {@link #bgImage},
+	 * {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is
+	 * updated with {@link #updateFinalImage()} and used for painting in
+	 * {@link #paintComponent(Graphics)}
+	 */
+	private BufferedImage finalImage;
 
+
 	/**
 	 * Optionally a transparent image to paint over the map in the lower right
 	 * corner.
@@ -331,23 +344,16 @@
 
 		@Override
 		public void layerChanged(final MapLayerEvent event) {
-			// Change of SLD for example
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 
 		@Override
 		public void layerHidden(final MapLayerEvent event) {
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 
 		@Override
 		public void layerShown(final MapLayerEvent event) {
-			// mapImageInvalid = true;
-			// repaint();
 			requestStartRendering();
 		}
 	};
@@ -429,8 +435,6 @@
 		}
 	};
 
-	private final RenderingExecutor localExecuter = new RenderingExecutor(this);
-
 	/**
 	 * Listens to each layer in the local {@link MapContext} for changes and
 	 * triggers repaints.
@@ -536,7 +540,11 @@
 	private Map<Object, Object> rendererHints = GTUtil
 			.getDefaultGTRendererHints(localRenderer);
 
-	private volatile Boolean requestStartRendering = false;
+	/** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #localImage} **/ 
+	private volatile Boolean requestStartRenderingLocal = false;
+	
+	/** If set to <code>true</code>, the {@link #startRenderThreadsTimer} will start rendering a new {@link #bgImage} **/
+	private volatile Boolean requestStartRenderingBg = false;
 
 	private final Timer resizeTimer;
 
@@ -547,7 +555,7 @@
 	protected AffineTransform screenToWorld = null;
 
 	/**
-	 * The flag {@link #requestStartRendering} can be set to true by events.
+	 * The flag {@link #requestStartRenderingLocal} can be set to true by events.
 	 * This {@link Timer} checks the flag regularly and starts one renderer
 	 * thread.
 	 */
@@ -576,7 +584,6 @@
 	/** Is set if a renderer has an error **/
 	protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>();
 
-	// TODO doku
 	public XMapPane() {
 		this(null, null);
 	}
@@ -585,15 +592,13 @@
 	 * full constructor extending JPanel
 	 * 
 	 * @param rendererHints
+	 *            may be <code>null</code>. Otherwise a {@link Map<Object,
+	 *            Object>} of {@link RenderingHints} to override the default
+	 *            from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)}
 	 * 
-	 * @param layout
-	 *            - layout (probably shouldn't be set)
-	 * @param isDoubleBuffered
-	 *            - a Swing thing I don't really understand
-	 * @param render
-	 *            - what to draw the map with
 	 * @param localContext
-	 *            - {@link MapContext} of layer to render.
+	 *            The main {@link MapContext} to use. If <code>null</code>, an
+	 *            empty {@link DefaultMapContext} will be created.
 	 */
 	public XMapPane(final MapContext localContext_,
 			final Map<Object, Object> rendererHints) {
@@ -620,37 +625,39 @@
 		 * Using a ComponentListener doesn't work because, unlike a JFrame, the
 		 * pane receives a stream of events during drag-resizing.
 		 */
-		resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, new ActionListener() {
+		resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY,
+				new ActionListener() {
 
-			public void actionPerformed(final ActionEvent e) {
-				paneResized = true;
+					public void actionPerformed(final ActionEvent e) {
+						paneResized = true;
 
-				if (!isWellDefined())
-					return;
+						if (!isWellDefined())
+							return;
 
-				final Rectangle bounds = getVisibleRect();
+						final Rectangle bounds = getVisibleRect();
 
-				final Envelope geoMapArea = tranformWindowToGeo(bounds.x,
-						bounds.y, bounds.x + bounds.width, bounds.y
-								+ bounds.height);
+						final Envelope geoMapArea = tranformWindowToGeo(
+								bounds.x, bounds.y, bounds.x + bounds.width,
+								bounds.y + bounds.height);
 
-				setMapArea(bestAllowedMapArea(geoMapArea));
-			}
-		});
+						setMapArea(bestAllowedMapArea(geoMapArea));
+					}
+				});
 		resizeTimer.setRepeats(false);
-		this.addComponentListener(new ComponentAdapter() {
+		
+//		this.addComponentListener(new ComponentAdapter() {
+//
+//			@Override
+//			public void componentResized(final ComponentEvent e) {
+//				if (bgExecuter != null)
+//					bgExecuter.cancelTask();
+//				if (localExecuter != null)
+//					localExecuter.cancelTask();
+//				resizeTimer.restart();
+//			}
+//
+//		});
 
-			@Override
-			public void componentResized(final ComponentEvent e) {
-				if (bgExecuter != null)
-					bgExecuter.cancelTask();
-				if (localExecuter != null)
-					localExecuter.cancelTask();
-				resizeTimer.restart();
-			}
-
-		});
-
 		/*
 		 * Setting up the repaintTimer. Not started automatically.
 		 */
@@ -674,13 +681,13 @@
 
 			@Override
 			public void actionPerformed(final ActionEvent e) {
-				synchronized (requestStartRendering) {
-					if (requestStartRendering && isWellDefined()) {
+				synchronized (requestStartRenderingLocal) {
+					if (requestStartRenderingLocal && isWellDefined()) {
 
 						if (localExecuter.isRunning()) {
 							localExecuter.cancelTask();
 						} else {
-							requestStartRendering = false;
+							requestStartRenderingLocal = false;
 							startRendering();
 						}
 					}
@@ -909,24 +916,24 @@
 			localExecuter.cancelTask();
 			while (i++ < 10 && localExecuter.isRunning()) {
 				try {
-					Thread.sleep(100);
+					Thread.sleep(200);
 				} catch (final InterruptedException e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
+					LOGGER
+							.warn(
+									"while XMapPane we are waiting for the localExcutor to stop",
+									e);
 				}
 			}
 			if (localExecuter.isRunning()) {
-				System.out
-						.println("BAD BAD BAD... still running the thread....");
+				LOGGER
+						.warn("localExecutor Thread still running after 2s! Continuing anyways...");
 			}
 			localExecuter.dispose();
 		}
 
 		disposeImages();
 
-		// LangUtil.gcTotal();
-
-		// Alle mapPaneListener entfernen
+		// Remove all mapPaneListeners that have registered with us
 		mapPaneListeners.clear();
 
 		removeMouseMotionListener(zoomMapPaneMouseListener);
@@ -979,8 +986,8 @@
 	 */
 	protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) {
 
-//		if (1 == 1)return false;
-		
+		// if (1 == 1)return false;
+
 		if (quickPreviewHint == 0)
 			return false;
 
@@ -1520,7 +1527,7 @@
 	public void performPan() {
 
 		Rectangle winBounds = getVisibleRect();
-		
+
 		winBounds.translate(-imageOrigin.x, -imageOrigin.y);
 		final Envelope newMapArea = tranformWindowToGeo(winBounds.x,
 				winBounds.y, winBounds.x + winBounds.width, winBounds.y
@@ -1585,7 +1592,7 @@
 			bgExecuter.cancelTask();
 		if (localExecuter != null)
 			localExecuter.cancelTask();
-		requestStartRendering = true;
+		requestStartRenderingLocal = true;
 
 	}
 
@@ -1645,7 +1652,7 @@
 				getContext().getCoordinateReferenceSystem());
 
 		Rectangle paintArea = getVisibleRect(); // NOT USE GET BOUNDS!
-		
+
 		//        
 		// double xscale = paintArea.getWidth() / refEnv.getWidth();
 		// double yscale = paintArea.getHeight() / refEnv.getHeight();
@@ -1996,7 +2003,7 @@
 			if (submitted)
 				repaintTimer.restart();
 			else
-				requestStartRendering = true; // Try to start rendering again in
+				requestStartRenderingLocal = true; // Try to start rendering again in
 			// a moment
 		}
 
@@ -2049,10 +2056,12 @@
 		final AffineTransform at = getScreenToWorld();
 		final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null);
 		final Point2D geoP = at.transform(new Point2D.Double(px, py), null);
-		
+
 		// Mmmmm... don't really understand why its x,x,y,y
-//		return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY());
-		return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY()));
+		// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(),
+		// geoP.getY());
+		return new Envelope(new Coordinate(geoO.getX(), geoO.getY()),
+				new Coordinate(geoP.getX(), geoP.getY()));
 	}
 
 	/**
@@ -2349,13 +2358,13 @@
 		newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea
 				.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);
 
+		// TODO we actually want that
+		// // Move the newMapArea above the new center
+		// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter
+		// .getY()
+		// - mapArea.centre().y);
+
 		setMapArea(newMapArea);
 	}
 



More information about the Schmitzm-commits mailing list