|
|
|
svn_geotools
|
Author: mbedward
Date: 2009-10-27 09:28:39 -0400 (Tue, 27 Oct 2009) New Revision: 34265 Modified: trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/JMapPane.java trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/RenderingExecutor.java Log: Tidied up StatusBar code; added popup menu for CRS options. Improved JTextReporter sizing and added extra listener method. Modified: trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/JMapPane.java =================================================================== --- trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/JMapPane.java 2009-10-27 10:48:10 UTC (rev 34264) +++ trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/JMapPane.java 2009-10-27 13:28:39 UTC (rev 34265) @@ -182,7 +182,7 @@ private boolean redrawBaseImage; private boolean needNewBaseImage; private boolean baseImageMoved; - private boolean displayAreaChanged; + private boolean clearLabelCache; /** @@ -207,7 +207,7 @@ needNewBaseImage = true; redrawBaseImage = true; baseImageMoved = false; - displayAreaChanged = false; + clearLabelCache = false; /* * We use a Timer object to avoid rendering delays and @@ -269,7 +269,6 @@ resizeTimer.restart(); } }); - } /** @@ -306,6 +305,7 @@ MapPaneEvent ev = new MapPaneEvent(this, MapPaneEvent.Type.PANE_RESIZED); publishEvent(ev); } + } /** @@ -541,7 +541,7 @@ pendingDisplayArea = new ReferencedEnvelope(envelope); } else { doSetDisplayArea(envelope); - displayAreaChanged = true; + clearLabelCache = true; repaint(); } @@ -785,14 +785,14 @@ if (acceptRepaintRequests) { - if (context == null || renderer == null) { + if (curPaintArea == null || + context == null || + context.getLayerCount() == 0 || + renderer == null) { + return; } - if (curPaintArea == null ) { - return; - } - if (needNewBaseImage) { baseImage = new BufferedImage(curPaintArea.width + 1, curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB); if (baseImageGraphics != null) { @@ -801,7 +801,7 @@ baseImageGraphics = baseImage.createGraphics(); needNewBaseImage = false; redrawBaseImage = true; - labelCache.clear(); + clearLabelCache = true; } final ReferencedEnvelope mapAOI = context.getAreaOfInterest(); @@ -813,7 +813,7 @@ if (baseImageMoved) { afterImageMove(mapAOI, curPaintArea); baseImageMoved = false; - labelCache.clear(); + clearLabelCache = true; } if (renderingExecutor.submit(mapAOI, curPaintArea, baseImageGraphics)) { @@ -821,6 +821,7 @@ publishEvent(ev); } else { + System.out.println("task rejected"); onRenderingRejected(); } @@ -843,9 +844,10 @@ public void onRenderingCompleted() { System.out.println("onRenderingCompleted"); - if (displayAreaChanged) { + if (clearLabelCache) { labelCache.clear(); } + clearLabelCache = false; Graphics2D paneGr = (Graphics2D) this.getGraphics(); paneGr.drawImage(baseImage, imageOrigin.x, imageOrigin.y, null); Modified: trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/RenderingExecutor.java =================================================================== --- trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/RenderingExecutor.java 2009-10-27 10:48:10 UTC (rev 34264) +++ trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/RenderingExecutor.java 2009-10-27 13:28:39 UTC (rev 34265) @@ -25,6 +25,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -79,6 +80,12 @@ private long pollingInterval; + /* + * This latch is used to avoid a race between the cancellation of + * a current task and the submittal of a new task + */ + private CountDownLatch cancelLatch; + /** * Constants to indicate the result of a rendering task */ @@ -89,6 +96,8 @@ FAILED; } + private long numFeatures; + /** * A rendering task */ @@ -97,6 +106,7 @@ private final ReferencedEnvelope envelope; private final Rectangle paintArea; private final Graphics2D graphics; + private boolean cancelled; private boolean failed; @@ -111,7 +121,7 @@ this.envelope = envelope; this.paintArea = paintArea; this.graphics = graphics; - cancelled = false; + this.cancelled = false; failed = false; } @@ -124,19 +134,23 @@ public TaskResult call() throws Exception { if (!cancelled) { GTRenderer renderer = mapPane.getRenderer(); - renderer.addRenderListener(this); + try { + renderer.addRenderListener(this); - /* - * Clear the paint area - */ - Composite composite = graphics.getComposite(); - graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f)); - graphics.fill(paintArea); - graphics.setComposite(composite); + /* + * Clear the paint area + */ + Composite composite = graphics.getComposite(); + graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f)); + graphics.fill(paintArea); + graphics.setComposite(composite); - renderer.paint(graphics, mapPane.getVisibleRect(), envelope, mapPane.getWorldToScreenTransform()); - - renderer.removeRenderListener(this); + numFeatures = 0; + renderer.paint(graphics, mapPane.getVisibleRect(), envelope, mapPane.getWorldToScreenTransform()); + + } finally { + renderer.removeRenderListener(this); + } } if (cancelled) { @@ -166,7 +180,8 @@ */ public void featureRenderer(SimpleFeature feature) { // @todo update a progress listener - } + numFeatures++ ; + } /** * Called by the renderer on error @@ -195,6 +210,7 @@ taskExecutor = Executors.newSingleThreadExecutor(); watchExecutor = Executors.newSingleThreadScheduledExecutor(); pollingInterval = DEFAULT_POLLING_INTERVAL; + cancelLatch = new CountDownLatch(0); } /** @@ -229,7 +245,14 @@ * rejected */ public synchronized boolean submit(ReferencedEnvelope envelope, Rectangle paintArea, Graphics2D graphics) { - if (!isRunning()) { + if (!isRunning() || cancelLatch.getCount() > 0) { + try { + // wait for any cancelled task to finish its shutdown + cancelLatch.await(); + } catch (InterruptedException ex) { + return false; + } + task = new Task(envelope, paintArea, graphics); taskRunning.set(true); taskResult = taskExecutor.submit(task); @@ -249,17 +272,25 @@ /** * Cancel the current rendering task if one is running */ - public void cancelTask() { + public synchronized void cancelTask() { if (isRunning()) { task.cancel(); + cancelLatch = new CountDownLatch(1); } } private void pollTaskResult() { + System.out.println("polling"); + System.out.flush(); + if (!taskResult.isDone()) { return; } + System.out.println("task finished"); + System.out.println("num features: " + numFeatures); + System.out.flush(); + TaskResult result = TaskResult.PENDING; try { @@ -273,16 +304,23 @@ switch (result) { case CANCELLED: + cancelLatch.countDown(); + System.out.println("cancelled"); mapPane.onRenderingCancelled(); break; case COMPLETED: + System.out.println("completed"); mapPane.onRenderingCompleted(); break; case FAILED: + System.out.println("failed"); mapPane.onRenderingFailed(); break; + + default: + System.out.println("undefined result"); } } ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ GeoTools-commits mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-commits |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |