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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 18 10:56:49 CET 2009


Author: alfonx
Date: 2009-11-18 10:56:47 +0100 (Wed, 18 Nov 2009)
New Revision: 524

Modified:
   branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java
Log:
* XMapPane is now only using one RenderingExecutor, and its now properly disposed, not leaving any threads in the ThreadPool
* Locks are not happening, memory leak still happens :-/
* Corrected isValid() against is WellDefined() in XMapPane

Modified: branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java	2009-11-18 09:54:52 UTC (rev 523)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java	2009-11-18 09:56:47 UTC (rev 524)
@@ -174,26 +174,26 @@
 	 * @see #setState(int)
 	 */
 	public static final int SELECT_ONE_FROM_TOP = 104;
-//
-//	/**
-//	 * While threads are working, we call {@link XMapPane#updateFinalImage()}
-//	 * regularly and repaint(). This {@link Timer} is stopped when all renderers
-//	 * have finished.
-//	 */
-//	final private Timer repainterTimer;
-//
-//	/**
-//	 * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
-//	 * the {@link #repainterTimer} is regularly updating the {@link #finalImage}
-//	 * with previews.
-//	 */
-//	public static final long REPEATING_REPAINT_DELAY = 500;
-//	
-//	/**
-//	 * The initial delay in milliseconds until the {@link #finalImage} is updated the first time.  
-//	 */
-//	public static final long INITIAL_REPAINT_DELAY = 333;
 
+	/**
+	 * While threads are working, we call {@link XMapPane#updateFinalImage()}
+	 * regularly and repaint(). This {@link Timer} is stopped when all renderers
+	 * have finished.
+	 */
+	final private Timer repainterTimer;
+
+	/**
+	 * While the {@link #bgExecuter} and {@link #localExecuter} are rendering,
+	 * the {@link #repainterTimer} is regularly updating the {@link #finalImage}
+	 * with previews.
+	 */
+	public static final long REPEATING_REPAINT_DELAY = 500;
+	
+	/**
+	 * The initial delay in milliseconds until the {@link #finalImage} is updated the first time.  
+	 */
+	public static final long INITIAL_REPAINT_DELAY = 1000;
+
 	protected RenderingExecutor bgExecuter;
 
 	/**
@@ -415,26 +415,32 @@
 
 		});
 
-//		repainterTimer = new Timer((int) REPEATING_REPAINT_DELAY,
-//				new ActionListener() {
-//
-//					@Override
-//					public void actionPerformed(ActionEvent e) {
-//						updateFinalImage();
-//						XMapPane.this.repaint();
-//					}
-//				});
-//		repainterTimer.setInitialDelay(300);
-//		repainterTimer.setRepeats(true);
+		repainterTimer = new Timer((int) REPEATING_REPAINT_DELAY,
+				new ActionListener() {
 
-		startRenderThreadsTimer = new Timer(200, new ActionListener() {
+					@Override
+					public void actionPerformed(ActionEvent e) {
+						updateFinalImage();
+						XMapPane.this.repaint();
+					}
+				});
+		repainterTimer.setInitialDelay(300);
+		repainterTimer.setRepeats(true);
 
+		startRenderThreadsTimer = new Timer(100, new ActionListener() {
+
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				synchronized (requestStartRendering) {
-					if (requestStartRendering && isValid())
-						startRendering();
-					requestStartRendering = false;
+					if (requestStartRendering && isWellDefined()) {
+						
+						if (localExecuter.isRunning()){
+							localExecuter.cancelTask();
+						} else {
+							requestStartRendering = false;
+							startRendering();
+						}
+					}
 				}
 			}
 		});
@@ -620,12 +626,12 @@
 			setCursor(WAIT_CURSOR);
 			return;
 		} else {
-//			// Allow one last rendering
-//			if (repainterTimer.isRunning()) {
-//				repainterTimer.stop();
-//				updateFinalImage();
-//				repaint();
-//			}
+			// Allow one last rendering
+			if (repainterTimer.isRunning()) {
+				repainterTimer.stop();
+				updateFinalImage();
+				repaint();
+			}
 		}
 
 		// wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig
@@ -1109,7 +1115,7 @@
 
 	public static final int NONE = -123;
 
-	private RenderingExecutor localExecuter;
+	private RenderingExecutor localExecuter = new RenderingExecutor(this, 150l);
 
 	private BufferedImage finalImage;
 
@@ -1196,6 +1202,7 @@
 		if (localExecuter != null)
 			localExecuter.cancelTask();
 		requestStartRendering = true;
+		
 	}
 
 	/**
@@ -1346,6 +1353,7 @@
 		finalG.setBackground(getMapBackgroundColor());
 
 		// Render the two map images first, into the preFinalImage
+		if (bgExecuter != null)
 		{
 			final Graphics2D preFinalG = (Graphics2D) getPreFinalImage()
 					.getGraphics();
@@ -1357,6 +1365,8 @@
 			// // Draw the local layers image
 			preFinalG.drawImage(getLocalImage(), 0, 0, null);
 			preFinalG.dispose();
+		} else {
+			preFinalImage = getLocalImage();
 		}
 
 		finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y,
@@ -1416,12 +1426,14 @@
 		if (!isWellDefined())
 			return;
 
-		if (bgExecuter != null)
+		if (bgExecuter != null){
 			// Stop all renderers
 			bgExecuter.cancelTask();
+		}
 
-		if (localExecuter != null)
+		if (localExecuter != null){
 			localExecuter.cancelTask();
+		}
 	
 		Rectangle curPaintArea = getVisibleRect();
 
@@ -1436,14 +1448,14 @@
 			LOGGER.debug("starting bg renderer:");
 			// /* System.out.println("rendering"); */
 			final GTRenderer createGTRenderer = GTUtil.createGTRenderer(
-					localContext, getRendererHints());
+					bgContext, getRendererHints());
 			createGTRenderer.setJava2DHints(getJava2dHints());
 			bgExecuter.submit(getBgContext().getAreaOfInterest(), curPaintArea,
 					(Graphics2D) getBgImage().getGraphics(), createGTRenderer);
 		}
 
 		if (getContext() != null) {
-			localExecuter = new RenderingExecutor(this, 150l);
+//			localExecuter = new RenderingExecutor(this, 150l);
 			LOGGER.debug("starting local renderer:");
 			final GTRenderer createGTRenderer = GTUtil.createGTRenderer(
 					localContext, getRendererHints());
@@ -1522,6 +1534,7 @@
 	 * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
 	 */
 	public void onRenderingCompleted() {
+		repainterTimer.stop();
 		updateFinalImage();
 		repaint();
 	}
@@ -1534,6 +1547,7 @@
 	 * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
 	 */
 	public void onRenderingCancelled() {
+		repainterTimer.stop();
 		LOGGER.debug("Rendering cancelled");
 	}
 
@@ -1548,22 +1562,13 @@
 	 * @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
 	 */
 	public void onRenderingFailed(Exception renderingError) {
+		repainterTimer.stop();
 		LOGGER.warn("Rendering failed", renderingError);
 		updateFinalImage();
 		repaint();
 
 	}
 
-	/**
-	 * Called when a rendering request has been rejected. This will be common,
-	 * such as when the user pauses during drag-resizing fo the map pane. The
-	 * base implementation does nothing. It is provided for sub-classes to
-	 * override if required.
-	 */
-	public void onRenderingRejected() {
-		LOGGER.warn("Rendering rejected");
-		repaint();
-	}
 
 	@Override
 	public void propertyChange(final PropertyChangeEvent evt) {
@@ -1930,16 +1935,19 @@
 		if (isDisposed())
 			return;
 		
+		
 		setPainting(false);
 
 		disposed = true;
 
 		if (bgExecuter != null) {
 			bgExecuter.cancelTask();
+			bgExecuter.dispose();
 		}
 
 		if (localExecuter != null) {
 			localExecuter.cancelTask();
+			localExecuter.dispose();
 		}
 
 		startRenderThreadsTimer.stop();

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-18 09:54:52 UTC (rev 523)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/RenderingExecutor.java	2009-11-18 09:56:47 UTC (rev 524)
@@ -261,13 +261,13 @@
      *         rejected
      */
     public synchronized boolean submit(ReferencedEnvelope envelope, Rectangle paintArea, Graphics2D graphics, final GTRenderer renderer) {
-        if (!isRunning() || cancelLatch.getCount() > 0) {
-            try {
-                // wait for any cancelled task to finish its shutdown
-                cancelLatch.await();
-            } catch (InterruptedException ex) {
-                return false;
-            }
+        if (!isRunning()) {
+//            try {
+//                // wait for any cancelled task to finish its shutdown
+//                cancelLatch.await();
+//            } catch (InterruptedException ex) {
+//                return false;
+//            }
 
             task = new Task(envelope, paintArea, graphics, renderer);
             taskRunning.set(true);
@@ -291,7 +291,11 @@
     public synchronized void cancelTask() {
         if (isRunning()) {
             task.cancel();
-            cancelLatch = new CountDownLatch(1);
+            
+            // Cancelling to often... can that be the reason?
+            if (cancelLatch.getCount() < 1) {
+            	cancelLatch = new CountDownLatch(1);
+            }
         }
     }
 
@@ -343,5 +347,10 @@
             watchExecutor.shutdownNow();
         }
     }
+    
+    public void dispose() {
+    	taskExecutor.shutdownNow();
+        watchExecutor.shutdownNow();
+    }
 }
 



More information about the Schmitzm-commits mailing list