Hello Miguel,

I would like for you to review the attached patch.  It is another
straightforward JS overlay conversion - this time of PolyEditingOptions.
 - Updated some of the javadoc.
 - Added to the Polyline unit test
 - In the process of writing the unit test, I discovered that
Polyline.setEditingEnabled() must be called after the polyline was added to
the map, so I documented it in the javadoc.

M      maps/maps/test/com/google/gwt/maps/client/overlay/PolylineTest.java
M
maps/maps/src/com/google/gwt/maps/client/overlay/PolyEditingOptions.java
M      maps/maps/src/com/google/gwt/maps/client/overlay/Polygon.java
M      maps/maps/src/com/google/gwt/maps/client/overlay/Polyline.java
D
maps/maps/src/com/google/gwt/maps/client/impl/PolyEditingOptionsImpl.java
M
maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DrawingOverlayDemo.java

-- 
Eric Z. Ayers - GWT Team - Atlanta, GA USA
http://code.google.com/webtoolkit/

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

M      maps/maps/test/com/google/gwt/maps/client/overlay/PolylineTest.java
M      maps/maps/src/com/google/gwt/maps/client/overlay/PolyEditingOptions.java
M      maps/maps/src/com/google/gwt/maps/client/overlay/Polygon.java
M      maps/maps/src/com/google/gwt/maps/client/overlay/Polyline.java
D      maps/maps/src/com/google/gwt/maps/client/impl/PolyEditingOptionsImpl.java
M      maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DrawingOverlayDemo.java

Index: maps/maps/test/com/google/gwt/maps/client/overlay/PolylineTest.java
===================================================================
--- maps/maps/test/com/google/gwt/maps/client/overlay/PolylineTest.java	(revision 782)
+++ maps/maps/test/com/google/gwt/maps/client/overlay/PolylineTest.java	(working copy)
@@ -74,6 +74,18 @@
     RootPanel.get().add(map);
   }
 
+  public void testPolylineEditingOptions() {
+    PolyEditingOptions opts;
+    opts = PolyEditingOptions.newInstance();
+    assertNotNull(opts);
+    opts = PolyEditingOptions.newInstance(true);
+    assertNotNull(opts);
+    opts = PolyEditingOptions.newInstance(100);
+    assertNotNull(opts);
+    opts = PolyEditingOptions.newInstance(100, true);
+    assertNotNull(opts);
+  }
+
   /**
    * Tests the fromEncoded() methods.
    */
@@ -156,6 +168,49 @@
   }
 
   /**
+   * Test the setEditngEnabled() method.
+   */
+  public void testPolylineSetEditingOptions() {
+    MapWidget map = new MapWidget(new LatLng(0, 0), 3);
+    map.setSize("500px", "400px");
+
+    LatLng[] points = { // 
+    new LatLng(45, 45), //
+        new LatLng(45, -45), //
+        new LatLng(0, 0)};
+
+    Polyline p = new Polyline(points);
+    map.addOverlay(p);
+    p.setEditingEnabled(true);
+    
+    p = new Polyline(points);
+    map.addOverlay(p);
+    p.setEditingEnabled(false);
+
+    p = new Polyline(points);
+    map.addOverlay(p);
+    p.setEditingEnabled(PolyEditingOptions.newInstance(false));
+
+    p = new Polyline(points);
+    map.addOverlay(p);
+    p.setEditingEnabled(PolyEditingOptions.newInstance(true));
+
+    p = new Polyline(points);
+    map.addOverlay(p);
+    p.setEditingEnabled(PolyEditingOptions.newInstance(100));
+
+    p = new Polyline(points);
+    map.addOverlay(p);
+    p.setEditingEnabled(PolyEditingOptions.newInstance(5, true));
+
+    p = new Polyline(points);
+    map.addOverlay(p);
+    p.setEditingEnabled(PolyEditingOptions.newInstance(7, false));
+
+    RootPanel.get().add(map);
+  }
+
+  /**
    * Test the getVertexCount() method.
    */
   public void testPolylineVertexCount() {
Index: maps/maps/src/com/google/gwt/maps/client/overlay/PolyEditingOptions.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/overlay/PolyEditingOptions.java	(revision 782)
+++ maps/maps/src/com/google/gwt/maps/client/overlay/PolyEditingOptions.java	(working copy)
@@ -16,20 +16,18 @@
 package com.google.gwt.maps.client.overlay;
 
 import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.maps.client.impl.PolyEditingOptionsImpl;
 
 /**
- * Options to pass to the [EMAIL PROTECTED] Polyline} editing routines.
+ * Options to pass to the [EMAIL PROTECTED] Polyline#setDrawingEnabled()} editing routines.
  */
-public class PolyEditingOptions {
+public class PolyEditingOptions extends JavaScriptObject {
 
-  private final JavaScriptObject jsoPeer;
-
   /**
-   * Create a [EMAIL PROTECTED] PolyEditingOptions} object using defaults.
+   * Create a new [EMAIL PROTECTED] PolyEditingOptions} object. 
+   * @return a new [EMAIL PROTECTED] PolyEditingOptions} object.
    */
-  public PolyEditingOptions() {
-    jsoPeer = PolyEditingOptionsImpl.impl.construct();
+  public static PolyEditingOptions newInstance() {
+    return (PolyEditingOptions) createObject();
   }
 
   /**
@@ -38,38 +36,51 @@
    * @param fromStart specifies whether [EMAIL PROTECTED] Polyline#setDrawingEnabled()}
    *          should add points from the start rather than from the end, which
    *          is the default.
+   * @return a new [EMAIL PROTECTED] PolyEditingOptions} object.
    */
-  public PolyEditingOptions(boolean fromStart) {
-    this();
-    setFromStart(fromStart);
-  }
+  public static native PolyEditingOptions newInstance(boolean fromStart) /*-{
+    return {"fromStart":fromStart};
+  }-*/;
 
   /**
    * Create a [EMAIL PROTECTED] PolyEditingOptions} object.
    * 
-   * @param maxVerticies specifies the maximum number of vertices permitted for
+   * @param maxVertices specifies the maximum number of vertices permitted for
    *          this polyline. Once this number is reached, no more may be added
+   * @return a new [EMAIL PROTECTED] PolyEditingOptions} object.
    */
-  public PolyEditingOptions(int maxVerticies) {
-    this();
-    setMaxVertices(maxVerticies);
-  }
+  public static native PolyEditingOptions newInstance(int maxVertices) /*-{
+    return {"maxVertices":maxVertices};
+  }-*/;
+  
+  /**
+   * Create a [EMAIL PROTECTED] PolyEditingOptions} object.
+   * 
+   * @param fromStart specifies whether [EMAIL PROTECTED] Polyline#setDrawingEnabled()}
+   *          should add points from the start rather than from the end, which
+   *          is the default.
+   * @param maxVertices specifies the maximum number of vertices permitted for
+   *          this polyline. Once this number is reached, no more may be added
+   * @return a new [EMAIL PROTECTED] PolyEditingOptions} object.
+   */
+  public static native PolyEditingOptions newInstance(int maxVertices, boolean fromStart) /*-{
+    return {"fromStart":fromStart, "maxVertices":maxVertices};
+  }-*/;
 
-  public PolyEditingOptions(int maxVerticies, boolean fromStart) {
-    this();
-    setMaxVertices(maxVerticies);
-    setFromStart(fromStart);
+  protected PolyEditingOptions() {
+    // Protected constructor required for JavaScript overlays.
   }
-
   /**
    * This property specifies whether enableDrawing should add points from the
    * start rather than from the end, which is the default.
    * 
-   * @param fromStart
+   * @param fromStart specifies whether [EMAIL PROTECTED] Polyline#setDrawingEnabled()}
+   *          should add points from the start rather than from the end, which
+   *          is the default.
    */
-  public void setFromStart(boolean fromStart) {
-    PolyEditingOptionsImpl.impl.setFromStart(jsoPeer, fromStart);
-  }
+  public final native void setFromStart(boolean fromStart) /*-{
+    this.fromStart = fromStart;
+  }-*/;
 
   /**
    * This property specifies the maximum number of vertices permitted for this
@@ -77,7 +88,7 @@
    * 
    * @param maxVertices the maximum number of vertices permitted.
    */
-  public void setMaxVertices(int maxVertices) {
-    PolyEditingOptionsImpl.impl.setMaxVertices(jsoPeer, maxVertices);
-  }
+  public final native void setMaxVertices(int maxVertices) /*-{
+    this.maxVertices = maxVertices;
+  }-*/;
 }
Index: maps/maps/src/com/google/gwt/maps/client/overlay/Polygon.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/overlay/Polygon.java	(revision 782)
+++ maps/maps/src/com/google/gwt/maps/client/overlay/Polygon.java	(working copy)
@@ -283,9 +283,10 @@
   }
 
   /**
-   * This event is fired when the polygon is clicked. Note that this event also+   * subsequently triggers a "click" event on the map, where the polygon is
+   * This event is fired when the polygon is clicked. Note that this event also+
+   * * subsequently triggers a "click" event on the map, where the polygon is
    * passed as the overlay argument within that event
-   *
+   * 
    * @param handler the handler to call when this event fires.
    */
   public void addPolygonVisibilityChangedHandler(
@@ -420,11 +421,12 @@
       polygonRemoveHandlers.removeHandler(handler);
     }
   }
-  
+
   /**
    * Removes a single handler of this map previously added with
-   * [EMAIL PROTECTED] Polygon#addPolygonVisibilityChangedHandler(PolygonVisibilityChangedHandler)}.
-   *
+   * [EMAIL PROTECTED] Polygon#addPolygonVisibilityChangedHandler(PolygonVisibilityChangedHandler)}
+   * .
+   * 
    * @param handler the handler to remove
    */
   public void removePolygonVisibilityChangedHandler(
@@ -468,11 +470,15 @@
    * Allows modification of an existing [EMAIL PROTECTED] Polygon} chain of points. When
    * enabled, users may select and drag existing vertices. Unless a vertex limit
    * less than current number of vertices is specified by
-   * [EMAIL PROTECTED] PolyEditingOptions#setMaxVertices(int)}, "ghost" points will also
-   * be added at the midpoints of polyline sections, allowing users to
-   * interpolate new vertices by clicking and dragging these additional
-   * vertices. A [EMAIL PROTECTED] PolygonLineUpdatedEvent} event will be triggered
-   * whenever vertex is added or moved.
+   * [EMAIL PROTECTED] PolyEditingOptions#setMaxVertices(int)}, "ghost" points will also be
+   * added at the midpoints of polyline sections, allowing users to interpolate
+   * new vertices by clicking and dragging these additional vertices. A
+   * [EMAIL PROTECTED] PolygonLineUpdatedEvent} event will be triggered whenever vertex is
+   * added or moved.
+   * 
+   * Note, you must add the polyline to the map before enabling editing.
+   * 
+   * @param enabled <code>true</code> to turn on editing of this polyline.
    */
   public void setEditingEnabled(boolean enabled) {
     if (enabled) {
@@ -486,6 +492,8 @@
    * Enable editing as in [EMAIL PROTECTED] Polygon#setEditingEnabled(boolean)}, but with
    * control over the drawing parameters.
    * 
+   * Note, you must add the polyline to the map before enabling editing.
+   *  
    * @param opts parameters for the editing session.
    */
   public void setEditingEnabled(PolyEditingOptions opts) {
@@ -493,7 +501,7 @@
   }
 
   /**
-   * Changes the style of the polylgon fill. The [EMAIL PROTECTED] Polygon} must already be
+   * Changes the style of the polygon fill. The [EMAIL PROTECTED] Polygon} must already be
    * added to the map via
    * [EMAIL PROTECTED] com.google.gwt.maps.client.MapWidget#addOverlay(Overlay)}
    * 
@@ -516,14 +524,14 @@
 
   /**
    * Show or hide the polygon.
-   *
+   * 
    * @param visible true to show the polygon.
    */
   public void setVisible(boolean visible) {
     if (visible) {
       PolygonImpl.impl.show(jsoPeer);
     } else {
-       PolygonImpl.impl.hide(jsoPeer);
+      PolygonImpl.impl.hide(jsoPeer);
     }
   }
 
@@ -534,7 +542,7 @@
    * @return true if setVisible(<code>false</code>) is supported.
    */
   public boolean supportsHide() {
-   return PolygonImpl.impl.supportsHide(jsoPeer);
+    return PolygonImpl.impl.supportsHide(jsoPeer);
   }
 
   /**
@@ -596,12 +604,12 @@
     maybeInitPolygonLineUpdatedHandlers();
     polygonLineUpdatedHandlers.trigger();
   }
-  
+
   /**
    * Manually trigger the specified event on this object.
-   *
+   * 
    * Note: The trigger() methods are provided for unit testing purposes only.
-   *
+   * 
    * @param event an event to deliver to the handler.
    */
   void trigger(PolygonVisibilityChangedEvent event) {
@@ -655,7 +663,7 @@
           jsoPeer, MapEvent.REMOVE);
     }
   }
-  
+
   private void maybeInitPolygonVisibilityChangedHandlers() {
     if (polygonVisibilityChangedHandlers == null) {
       polygonVisibilityChangedHandlers = new HandlerCollection<PolygonVisibilityChangedHandler>(
Index: maps/maps/src/com/google/gwt/maps/client/overlay/Polyline.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/overlay/Polyline.java	(revision 782)
+++ maps/maps/src/com/google/gwt/maps/client/overlay/Polyline.java	(working copy)
@@ -489,11 +489,15 @@
    * Allows modification of an existing [EMAIL PROTECTED] Polyline} chain of points. When
    * enabled, users may select and drag existing vertices. Unless a vertex limit
    * less than current number of vertices is specified by
-   * [EMAIL PROTECTED] PolyEditingOptions#setMaxVertices(int)}, "ghost" points will also
-   * be added at the midpoints of polyline sections, allowing users to
-   * interpolate new vertices by clicking and dragging these additional
-   * vertices. A [EMAIL PROTECTED] PolylineLineUpdatedEvent} event will be triggered
-   * whenever vertex is added or moved.
+   * [EMAIL PROTECTED] PolyEditingOptions#setMaxVertices(int)}, "ghost" points will also be
+   * added at the midpoints of polyline sections, allowing users to interpolate
+   * new vertices by clicking and dragging these additional vertices. A
+   * [EMAIL PROTECTED] PolylineLineUpdatedEvent} event will be triggered whenever vertex is
+   * added or moved.
+   * 
+   * Note, you must add the polyline to the map before enabling editing.
+   * 
+   * @param enabled <code>true</code> to turn on editing of this polyline.
    */
   public void setEditingEnabled(boolean enabled) {
     if (enabled) {
@@ -507,6 +511,8 @@
    * Enable editing as in [EMAIL PROTECTED] Polyline#setEditingEnabled(boolean)}, but with
    * control over the polyline drawing parameters.
    * 
+   * Note, you must add the polyline to the map before enabling editing.
+   * 
    * @param opts parameters for the polyline editing session.
    */
   public void setEditingEnabled(PolyEditingOptions opts) {
Index: maps/maps/src/com/google/gwt/maps/client/impl/PolyEditingOptionsImpl.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/impl/PolyEditingOptionsImpl.java	(revision 782)
+++ maps/maps/src/com/google/gwt/maps/client/impl/PolyEditingOptionsImpl.java	(working copy)
@@ -1,40 +0,0 @@
-/*
- * Copyright 2008 Google Inc.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.maps.client.impl;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.maps.jsio.client.BeanProperties;
-import com.google.gwt.maps.jsio.client.Constructor;
-import com.google.gwt.maps.jsio.client.JSFlyweightWrapper;
-
-/**
- * Wrapper for the GPolyEditingOptions object from the Maps API using JSIO. The Maps
- * API does not provide a constructor for this object. Instead, it is
- * constructed from a JavaScript Object literal.
- */
[EMAIL PROTECTED]
-public interface PolyEditingOptionsImpl extends JSFlyweightWrapper {
-
-  PolyEditingOptionsImpl impl = GWT.create(PolyEditingOptionsImpl.class);
-
-  @Constructor("Object")
-  JavaScriptObject construct();
-
-  void setFromStart(JavaScriptObject jsoPeer, boolean fromStart);
-
-  void setMaxVertices(JavaScriptObject jsoPeer, int maxVerticies);
-}
Index: maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DrawingOverlayDemo.java
===================================================================
--- maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DrawingOverlayDemo.java	(revision 782)
+++ maps/samples/hellomaps/src/com/google/gwt/maps/sample/hellomaps/client/DrawingOverlayDemo.java	(working copy)
@@ -175,16 +175,16 @@
     if (lastPolygon == null) {
       return;
     }
-    // allow up to 10 verticies to exist in the polygon.
-    lastPolygon.setEditingEnabled(new PolyEditingOptions(10));
+    // allow up to 10 vertices to exist in the polygon.
+    lastPolygon.setEditingEnabled(PolyEditingOptions.newInstance(10));
   }
 
   private void editPolyline() {
     if (lastPolyline == null) {
       return;
     }
-    // allow up to 10 verticies to exist in the line.
-    lastPolyline.setEditingEnabled(new PolyEditingOptions(10));
+    // allow up to 10 vertices to exist in the line.
+    lastPolyline.setEditingEnabled(PolyEditingOptions.newInstance(10));
   }
 
   /**

Reply via email to