svn - r34253 - in trunk: demo/example/src/main/java/org/geotools/demo/swing modules/unsupported/swing/src/main/java/org/geotools/swing modules/unsupported/swing/src/main/java/org/geotools/swing/data

1 message Options
Embed this post
Permalink
svn_geotools

svn - r34253 - in trunk: demo/example/src/main/java/org/geotools/demo/swing modules/unsupported/swing/src/main/java/org/geotools/swing modules/unsupported/swing/src/main/java/org/geotools/swing/data

Reply Threaded More More options
Print post
Permalink
Author: mbedward
Date: 2009-10-26 08:46:38 -0400 (Mon, 26 Oct 2009)
New Revision: 34253

Modified:
   trunk/demo/example/src/main/java/org/geotools/demo/swing/ShapefileViewer.java
   trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/JMapPane.java
   trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/RenderingExecutor.java
   trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/data/JFileDataStoreChooser.java
Log:
Tweaked map pane rendering - still needs work. Added JFileDataStoreChooser.showOpenDialog methods with initial dir arg. Fixed working dir in ShapefileViewer example.

Modified: trunk/demo/example/src/main/java/org/geotools/demo/swing/ShapefileViewer.java
===================================================================
--- trunk/demo/example/src/main/java/org/geotools/demo/swing/ShapefileViewer.java 2009-10-26 10:20:26 UTC (rev 34252)
+++ trunk/demo/example/src/main/java/org/geotools/demo/swing/ShapefileViewer.java 2009-10-26 12:46:38 UTC (rev 34253)
@@ -153,7 +153,7 @@
      * argument of the latter method set to {@code true}.
      */
     public void loadShapefile() throws IOException {
-        File file = JFileDataStoreChooser.showOpenFile("shp", null);
+        File file = JFileDataStoreChooser.showOpenFile("shp", cwd, null);
         if (file != null) {
             addShapefile(file.toURL(), true);
             setWorkingDir(file.getParentFile());

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-26 10:20:26 UTC (rev 34252)
+++ trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/JMapPane.java 2009-10-26 12:46:38 UTC (rev 34253)
@@ -820,16 +820,15 @@
                     MapPaneEvent ev = new MapPaneEvent(this, MapPaneEvent.Type.RENDERING_STARTED);
                     publishEvent(ev);
 
-                    clearBaseImage();
-
                 } else {
                     onRenderingRejected();
                 }
 
+            } else {
+                Graphics2D g2 = (Graphics2D) g;
+                g2.drawImage(baseImage, imageOrigin.x, imageOrigin.y, null);
             }
-
-            Graphics2D g2 = (Graphics2D) g;
-            g2.drawImage(baseImage, imageOrigin.x, imageOrigin.y, this);
+            
             redrawBaseImage = true;
         }
     }
@@ -849,7 +848,7 @@
         }
 
         Graphics2D paneGr = (Graphics2D) this.getGraphics();
-        paneGr.drawImage(baseImage, imageOrigin.x, imageOrigin.y, this);
+        paneGr.drawImage(baseImage, imageOrigin.x, imageOrigin.y, null);
 
         MapPaneEvent ev = new MapPaneEvent(this, MapPaneEvent.Type.RENDERING_STOPPED);
         publishEvent(ev);

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-26 10:20:26 UTC (rev 34252)
+++ trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/RenderingExecutor.java 2009-10-26 12:46:38 UTC (rev 34253)
@@ -17,6 +17,8 @@
 
 package org.geotools.swing;
 
+import java.awt.AlphaComposite;
+import java.awt.Composite;
 import java.awt.Graphics2D;
 import java.awt.Rectangle;
 import java.util.concurrent.Callable;
@@ -80,7 +82,7 @@
     /**
      * Constants to indicate the result of a rendering task
      */
-    private enum TaskResult {
+    public enum TaskResult {
         PENDING,
         COMPLETED,
         CANCELLED,
@@ -98,6 +100,13 @@
         private boolean cancelled;
         private boolean failed;
 
+        /**
+         * Constructor. Creates a new rendering task
+         *
+         * @param envelope map area to render (world coordinates)
+         * @param paintArea drawing area (image or display coordinates)
+         * @param graphics graphics object used to draw into the image or display
+         */
         public Task(final ReferencedEnvelope envelope, final Rectangle paintArea, final Graphics2D graphics) {
             this.envelope = envelope;
             this.paintArea = paintArea;
@@ -106,14 +115,30 @@
             failed = false;
         }
 
+        /**
+         * Called by the executor to run this rendering task.
+         *
+         * @return result of the task: completed, cancelled or failed
+         * @throws Exception
+         */
         public TaskResult call() throws Exception {
-            GTRenderer renderer = mapPane.getRenderer();
-            renderer.addRenderListener(this);
+            if (!cancelled) {
+                GTRenderer renderer = mapPane.getRenderer();
+                renderer.addRenderListener(this);
 
-            renderer.paint(graphics, mapPane.getVisibleRect(), envelope, mapPane.getWorldToScreenTransform());
+                /*
+                 * Clear the paint area
+                 */
+                Composite composite = graphics.getComposite();
+                graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
+                graphics.fill(paintArea);
+                graphics.setComposite(composite);
 
-            renderer.removeRenderListener(this);
+                renderer.paint(graphics, mapPane.getVisibleRect(), envelope, mapPane.getWorldToScreenTransform());
 
+                renderer.removeRenderListener(this);
+            }
+
             if (cancelled) {
                 return TaskResult.CANCELLED;
             } else if (failed) {
@@ -123,6 +148,10 @@
             }
         }
 
+        /**
+         * Cancel the rendering task if it is running. If called before
+         * being run the task will be abandoned.
+         */
         public synchronized void cancel() {
             if (isRunning()) {
                 cancelled = true;
@@ -130,13 +159,24 @@
             }
         }
 
+        /**
+         * Called by the renderer when each feature is drawn.
+         *
+         * @param feature the feature just drawn
+         */
         public void featureRenderer(SimpleFeature feature) {
             // @todo update a progress listener
             }
 
+        /**
+         * Called by the renderer on error
+         *
+         * @param e cause of the error
+         */
         public void errorOccurred(Exception e) {
             failed = true;
         }
+
     }
 
     private AtomicBoolean taskRunning;
@@ -145,9 +185,9 @@
     private ScheduledFuture<?> watcher;
 
     /**
-     * Constructor
+     * Constructor. Creates a new executor to service the specified map pane.
      *
-     * @param mapPane the map pane to be serviced by this rendering executor
+     * @param mapPane the map pane to be serviced
      */
     public RenderingExecutor(final JMapPane mapPane) {
         taskRunning = new AtomicBoolean(false);

Modified: trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/data/JFileDataStoreChooser.java
===================================================================
--- trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/data/JFileDataStoreChooser.java 2009-10-26 10:20:26 UTC (rev 34252)
+++ trunk/modules/unsupported/swing/src/main/java/org/geotools/swing/data/JFileDataStoreChooser.java 2009-10-26 12:46:38 UTC (rev 34253)
@@ -198,13 +198,37 @@
      * Show a file open dialog that filters for files with the given extension.
      *
      * @param extension file extension, with or without leading '.'
-     * @param parent parent GUI component (may be null)
+     * @param parent parent GUI component (may be {@code null})
      *
      * @return the selected file or null if the user cancelled the selection
      * @throws java.awt.HeadlessException if run in an unsupported environment
      */
-    public static File showOpenFile(String extension, Component parent) throws HeadlessException {
+    public static File showOpenFile(String extension, Component parent)
+            throws HeadlessException {
+        return showOpenFile(extension, null, parent);
+    }
+
+    /**
+     * Show a file open dialog that filters for files with the given extension.
+     *
+     * @param extension file extension, with or without leading '.'
+     * @param initialDir initial directory to display; if {@code null} the initial directory
+     *        will be the user's default directory
+     * @param parent parent GUI component (may be {@code null})
+     *
+     * @return the selected file or null if the user cancelled the selection
+     * @throws java.awt.HeadlessException if run in an unsupported environment
+     */
+    public static File showOpenFile(String extension, File initialDir, Component parent)
+            throws HeadlessException {
         JFileDataStoreChooser dialog = new JFileDataStoreChooser(extension);
+        if (initialDir != null) {
+            if (initialDir.isDirectory()) {
+                dialog.setCurrentDirectory(initialDir);
+            } else {
+                dialog.setCurrentDirectory(initialDir.getParentFile());
+            }
+        }
         
         if (dialog.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
             return dialog.getSelectedFile();
@@ -222,8 +246,33 @@
      * @return the selected file or null if the user cancelled the selection
      * @throws java.awt.HeadlessException if run in an unsupported environment
      */
-    public static File showOpenFile(String[] extensions, Component parent) throws HeadlessException {
+    public static File showOpenFile(String[] extensions, Component parent)
+            throws HeadlessException {
+        return showOpenFile(extensions, null, parent);
+    }
+
+    /**
+     * Show a file open dialog that filters for files with the given extensions.
+     *
+     * @param extensions array of file extension, with or without leading '.'
+     * @param initialDir initial directory to display; if {@code null} the initial directory
+     *        will be the user's default directory
+     * @param parent parent GUI component (may be null)
+     *
+     * @return the selected file or null if the user cancelled the selection
+     * @throws java.awt.HeadlessException if run in an unsupported environment
+     */
+    public static File showOpenFile(String[] extensions, File initialDir, Component parent)
+            throws HeadlessException {
+
         JFileDataStoreChooser dialog = new JFileDataStoreChooser(extensions);
+        if (initialDir != null) {
+            if (initialDir.isDirectory()) {
+                dialog.setCurrentDirectory(initialDir);
+            } else {
+                dialog.setCurrentDirectory(initialDir.getParentFile());
+            }
+        }
 
         if (dialog.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
             return dialog.getSelectedFile();
@@ -242,9 +291,36 @@
      * @return the selected file or null if the user cancelled the selection
      * @throws java.awt.HeadlessException if run in an unsupported environment
      */
-    public static File showOpenFile(FileDataStoreFactorySpi format, Component parent) throws HeadlessException {
+    public static File showOpenFile(FileDataStoreFactorySpi format, Component parent)
+            throws HeadlessException {
+        return showOpenFile(format, null, parent);
+    }
+
+    /**
+     * Show a file open dialog that filters for files that match a given file
+     * data store format
+     *
+     * @param format the file data store format
+     * @param initialDir initial directory to display; if {@code null} the initial directory
+     *        will be the user's default directory
+     * @param parent parent GUI component (may be null)
+     *
+     * @return the selected file or null if the user cancelled the selection
+     * @throws java.awt.HeadlessException if run in an unsupported environment
+     */
+    public static File showOpenFile(FileDataStoreFactorySpi format, File initialDir, Component parent)
+            throws HeadlessException {
+
         JFileDataStoreChooser dialog = new JFileDataStoreChooser(format);
+        if (initialDir != null) {
+            if (initialDir.isDirectory()) {
+                dialog.setCurrentDirectory(initialDir);
+            } else {
+                dialog.setCurrentDirectory(initialDir.getParentFile());
+            }
+        }
 
+
         if (dialog.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
             return dialog.getSelectedFile();
         }
@@ -252,7 +328,7 @@
     }
 
     /**
-     * Deomonstrates the file data store dialog by prompting for a shapefile
+     * Demonstrates the file data store dialog by prompting for a shapefile
      *
      * @param arg ignored
      */


------------------------------------------------------------------------------
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