Hi Miguel,

These are all good suggestions, especially the one about including all of
the source code. I've updated the patch.

On Thu, Sep 18, 2008 at 9:48 AM, Miguel Méndez <[EMAIL PROTECTED]> wrote:

> Should InfoWindow be included in this patch?
> Shouldn't the Overlay.createPeer method perform the tests on the
> JavaScriptObject and return the correct concrete wrapper class?
>
>
> On Tue, Sep 16, 2008 at 2:19 PM, Eric Ayers <[EMAIL PROTECTED]> wrote:
>
>> Hello Miguel,
>>
>> I would like you to review the attached patch.  This patch addresses issue
>> 170
>>
>>   http://code.google.com/p/gwt-google-apis/issues/detail?id=170
>>
>> This change makes InfoWindow extend the ConcreteOverlay class.  It also
>> adds the methods isInfoWindow(), isPolyline(), isPolygon(), and isMarker()
>> to the Overlay class.
>>
>> M      maps/maps/test/com/google/gwt/maps/client/overlay/OverlayTest.java
>> M      maps/maps/src/com/google/gwt/maps/client/overlay/Overlay.java
>> --
>> Eric Z. Ayers - GWT Team - Atlanta, GA USA
>> http://code.google.com/webtoolkit/
>>
>
>
>
> --
> Miguel
>



-- 
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/src/com/google/gwt/maps/client/InfoWindow.java
M      maps/maps/test/com/google/gwt/maps/client/overlay/OverlayTest.java
M      maps/maps/src/com/google/gwt/maps/client/overlay/Overlay.java

Index: maps/maps/src/com/google/gwt/maps/client/InfoWindow.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/InfoWindow.java	(revision 798)
+++ maps/maps/src/com/google/gwt/maps/client/InfoWindow.java	(working copy)
@@ -15,7 +15,6 @@
  */
 package com.google.gwt.maps.client;
 
-import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.maps.client.event.InfoWindowCloseClickHandler;
 import com.google.gwt.maps.client.event.InfoWindowMaximizeClickHandler;
 import com.google.gwt.maps.client.event.InfoWindowMaximizeEndHandler;
@@ -38,6 +37,7 @@
 import com.google.gwt.maps.client.impl.MarkerImpl;
 import com.google.gwt.maps.client.impl.EventImpl.VoidCallback;
 import com.google.gwt.maps.client.overlay.Marker;
+import com.google.gwt.maps.client.overlay.Overlay.ConcreteOverlay;
 import com.google.gwt.maps.jsio.client.JSList;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.ui.ComplexPanel;
@@ -55,7 +55,7 @@
  * 
  * @see MapWidget#getInfoWindow()
  */
-public final class InfoWindow {
+public final class InfoWindow extends ConcreteOverlay {
 
   private static class VirtualPanel extends ComplexPanel {
 
@@ -100,7 +100,6 @@
   private HandlerCollection<InfoWindowRestoreClickHandler> infoWindowRestoreClickHandlers;
   private HandlerCollection<InfoWindowRestoreEndHandler> infoWindowRestoreEndHandlers;
 
-  private final JavaScriptObject jsoPeer;
   private final MapWidget map;
 
   /**
@@ -117,8 +116,8 @@
    * @param map the map to which this InfoWindow belongs.
    */
   InfoWindow(MapWidget map) {
+    super(MapImpl.impl.getInfoWindow(map));
     this.map = map;
-    jsoPeer = MapImpl.impl.getInfoWindow(map);
   }
 
   /**
Index: maps/maps/test/com/google/gwt/maps/client/overlay/OverlayTest.java
===================================================================
--- maps/maps/test/com/google/gwt/maps/client/overlay/OverlayTest.java	(revision 798)
+++ maps/maps/test/com/google/gwt/maps/client/overlay/OverlayTest.java	(working copy)
@@ -16,6 +16,8 @@
 package com.google.gwt.maps.client.overlay;
 
 import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.maps.client.InfoWindow;
+import com.google.gwt.maps.client.MapWidget;
 import com.google.gwt.maps.client.TestUtilities;
 import com.google.gwt.maps.client.geom.LatLng;
 
@@ -38,6 +40,41 @@
     TestUtilities.cleanDom();
   }
 
+  public void testIsInfoWindow() {
+    MapWidget map = new MapWidget();
+    InfoWindow info = map.getInfoWindow();
+    assertTrue(info.isInfoWindow());
+    assertFalse(info.isMarker());
+    assertFalse(info.isPolyline());
+    assertFalse(info.isPolygon());
+  }
+ 
+  public void testIsMarker() {
+    Marker m = new Marker(LatLng.newInstance(1,1));
+    assertFalse(m.isInfoWindow());
+    assertTrue(m.isMarker());
+    assertFalse(m.isPolyline());
+    assertFalse(m.isPolygon());
+  }
+  
+  public void testIsPolygon() {
+    LatLng points[] = {LatLng.newInstance(0,0), LatLng.newInstance(1,0)};
+    Polygon p = new Polygon(points);
+    assertFalse(p.isInfoWindow());
+    assertFalse(p.isMarker());
+    assertFalse(p.isPolyline());
+    assertTrue(p.isPolygon());
+  }  
+  
+  public void testIsPolyline() {
+    LatLng points[] = {LatLng.newInstance(0,0), LatLng.newInstance(1,0)};
+    Polyline p = new Polyline(points);
+    assertFalse(p.isInfoWindow());
+    assertFalse(p.isMarker());
+    assertTrue(p.isPolyline());
+    assertFalse(p.isPolygon());
+  }  
+  
   public void testOverlayZIndex() {
     LatLng atlanta = LatLng.newInstance(33.7814790, -84.3880580);
     double result1 = Overlay.getZIndex(atlanta.getLatitude());
@@ -45,6 +82,6 @@
     double result2 = Overlay.getZIndex(atlanta.getLatitude() + 1);
     assertTrue("expected non-zero value", result2 != 0.0);
     assertTrue("expected result1 > result2 ", result1 > result2);
-  }
+  }    
   
 }
Index: maps/maps/src/com/google/gwt/maps/client/overlay/Overlay.java
===================================================================
--- maps/maps/src/com/google/gwt/maps/client/overlay/Overlay.java	(revision 798)
+++ maps/maps/src/com/google/gwt/maps/client/overlay/Overlay.java	(working copy)
@@ -21,8 +21,7 @@
 import com.google.gwt.maps.jsio.client.Exported;
 
 /**
- * The base class for adding objects at a specific position on top of
- * the map.
+ * The base class for adding objects at a specific position on top of the map.
  */
 public abstract class Overlay {
 
@@ -82,9 +81,40 @@
    */
   @SuppressWarnings("unused")
   private static Overlay createPeer(JavaScriptObject jsoPeer) {
+    if (nativeIsMarker(jsoPeer)) {
+      return new Marker(jsoPeer);
+    } else if (nativeIsPolyline(jsoPeer)) {
+      return new Polyline(jsoPeer);
+    } else if (nativeIsPolygon(jsoPeer)) {
+      return new Polygon(jsoPeer);
+    } else if (nativeIsInfoWindow(jsoPeer)) {
+      throw new UnsupportedOperationException(
+          "Can't create InfoWindow object from JavaScriptObject.");
+    }
     return new ConcreteOverlay(jsoPeer);
   }
 
+  private static native boolean nativeIsInfoWindow(JavaScriptObject jsoPeer) /*-{
+    // The instanceof test won't work, because $wnd.GInfoWindow has no constructor.
+    // Let's see if it quacks like a duck (has similar member functions)...
+    if (!jsoPeer.selectTab || !jsoPeer.getTabs || !jsoPeer.getPixelOffset) {
+      return false;
+    }  
+    return true;
+  }-*/;
+
+  private static native boolean nativeIsMarker(JavaScriptObject jsoPeer) /*-{
+    return (jsoPeer instanceof $wnd.GMarker);
+  }-*/;
+
+  private static native boolean nativeIsPolygon(JavaScriptObject jsoPeer) /*-{
+    return (jsoPeer instanceof $wnd.GPolygon);
+  }-*/;
+
+  private static native boolean nativeIsPolyline(JavaScriptObject jsoPeer) /*-{
+    return (jsoPeer instanceof $wnd.GPolyline);
+  }-*/;
+
   protected final JavaScriptObject jsoPeer;
 
   public Overlay() {
@@ -97,6 +127,50 @@
   }
 
   /**
+   * Test to see if this overlay is the
+   * [EMAIL PROTECTED] com.google.gwt.maps.client.InfoWindow} for this map.
+   * 
+   * @return <code>true</code> if this overlay is the
+   *         [EMAIL PROTECTED] com.google.gwt.maps.client.InfoWindow} for this map.
+   */
+  public boolean isInfoWindow() {
+    return nativeIsInfoWindow(jsoPeer);
+  }
+
+  /**
+   * Test to see if this overlay is the
+   * [EMAIL PROTECTED] com.google.gwt.maps.client.overlay.Marker} for this map.
+   * 
+   * @return <code>true</code> if this overlay is the
+   *         [EMAIL PROTECTED] com.google.gwt.maps.client.overlay.Marker} for this map.
+   */
+  public boolean isMarker() {
+    return nativeIsMarker(jsoPeer);
+  }
+
+  /**
+   * Test to see if this overlay is the
+   * [EMAIL PROTECTED] com.google.gwt.maps.client.overlay.Polygon} for this map.
+   * 
+   * @return <code>true</code> if this overlay is the
+   *         [EMAIL PROTECTED] com.google.gwt.maps.client.overlay.Polygon} for this map.
+   */
+  public boolean isPolygon() {
+    return nativeIsPolygon(jsoPeer);
+  }
+
+  /**
+   * Test to see if this overlay is the
+   * [EMAIL PROTECTED] com.google.gwt.maps.client.overlay.Polyline} for this map.
+   * 
+   * @return <code>true</code> if this overlay is the
+   *         [EMAIL PROTECTED] com.google.gwt.maps.client.overlay.Polyline} for this map.
+   */
+  public boolean isPolyline() {
+    return nativeIsPolyline(jsoPeer);
+  }
+
+  /**
    * Returns an uninitialized copy of itself that can be added to the map.
    * 
    * @return an uninitialized copy of itself that can be added to the map.
@@ -133,5 +207,4 @@
    */
   @Exported
   protected abstract void remove();
-
 }

Reply via email to