Sorry, forgot to attach the actual patch.
2008/9/5 Eric Ayers <[EMAIL PROTECTED]>:
> Hello Miguel,
>
> I would like for you to review this patch which converts Point and TileIndex
> objects to be sublasses of JavaScriptObject.
>
> M maps/test/com/google/gwt/maps/client/overlay/MarkerTest.java
> M maps/test/com/google/gwt/maps/client/impl/MinimumMapVersionTest.java
> M maps/test/com/google/gwt/maps/client/MapWidgetEventsTest.java
> M maps/test/com/google/gwt/maps/client/geom/ProjectionTest.java
> M maps/src/com/google/gwt/maps/client/overlay/Icon.java
> M maps/src/com/google/gwt/maps/client/geom/TileIndex.java
> M maps/src/com/google/gwt/maps/client/geom/Point.java
> M maps/src/com/google/gwt/maps/client/geom/Bounds.java
> M maps/src/com/google/gwt/maps/client/impl/JsUtil.java
> D maps/src/com/google/gwt/maps/client/impl/PointImpl.java
> M maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java
>
> --
> Eric Z. Ayers - GWT Team - Atlanta, GA USA
> http://code.google.com/webtoolkit/
>
--
Eric Z. Ayers - GWT Team - Atlanta, GA USA
http://code.google.com/webtoolkit/
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---
M maps/test/com/google/gwt/maps/client/overlay/MarkerTest.java
M maps/test/com/google/gwt/maps/client/impl/MinimumMapVersionTest.java
M maps/test/com/google/gwt/maps/client/MapWidgetEventsTest.java
M maps/test/com/google/gwt/maps/client/geom/ProjectionTest.java
M maps/src/com/google/gwt/maps/client/overlay/Icon.java
M maps/src/com/google/gwt/maps/client/geom/TileIndex.java
M maps/src/com/google/gwt/maps/client/geom/Point.java
M maps/src/com/google/gwt/maps/client/geom/Bounds.java
M maps/src/com/google/gwt/maps/client/impl/JsUtil.java
D maps/src/com/google/gwt/maps/client/impl/PointImpl.java
M maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java
Index: maps/test/com/google/gwt/maps/client/overlay/MarkerTest.java
===================================================================
--- maps/test/com/google/gwt/maps/client/overlay/MarkerTest.java (revision 755)
+++ maps/test/com/google/gwt/maps/client/overlay/MarkerTest.java (working copy)
@@ -50,7 +50,7 @@
public void testIconAccessors() {
Icon ic = new Icon();
- Point pointA = new Point(10, 20);
+ Point pointA = Point.getInstance(10, 20);
ic.setDragCrossAnchor(pointA);
assertEquals("DragCrossAnchor", pointA, ic.getDragCrossAnchor());
@@ -62,7 +62,7 @@
ic.setDragCrossSize(size1);
assertEquals("DragCrossSize", size1, ic.getDragCrossSize());
- Point pointB = new Point(20, 30);
+ Point pointB = Point.getInstance(20, 30);
ic.setIconAnchor(pointB);
assertEquals("IconAnchor", pointB, ic.getIconAnchor());
@@ -81,7 +81,7 @@
ic.setImageURL(dummyImage);
assertEquals("ImageURL", dummyImage, ic.getImageURL());
- Point pointC = new Point(100, 20);
+ Point pointC = Point.getInstance(100, 20);
ic.setInfoWindowAnchor(pointC);
assertEquals("InfoWindowAnchor", pointC, ic.getInfoWindowAnchor());
Index: maps/test/com/google/gwt/maps/client/impl/MinimumMapVersionTest.java
===================================================================
--- maps/test/com/google/gwt/maps/client/impl/MinimumMapVersionTest.java (revision 755)
+++ maps/test/com/google/gwt/maps/client/impl/MinimumMapVersionTest.java (working copy)
@@ -183,7 +183,7 @@
@Override
public Point fromLatLngToPixel(LatLng latlng, int zoomLevel) {
- return new Point(0, 0);
+ return Point.getInstance(0, 0);
}
@Override
Index: maps/test/com/google/gwt/maps/client/MapWidgetEventsTest.java
===================================================================
--- maps/test/com/google/gwt/maps/client/MapWidgetEventsTest.java (revision 755)
+++ maps/test/com/google/gwt/maps/client/MapWidgetEventsTest.java (working copy)
@@ -767,7 +767,7 @@
});
RootPanel.get().add(m);
Marker marker = new Marker(new LatLng(12.34, -22.2));
- MapRightClickEvent e = new MapRightClickEvent(m, new Point(101, 222),
+ MapRightClickEvent e = new MapRightClickEvent(m, Point.getInstance(101, 222),
m.getElement(), marker);
delayTestFinish(ASYNC_DELAY_MSEC);
m.trigger(e);
Index: maps/test/com/google/gwt/maps/client/geom/ProjectionTest.java
===================================================================
--- maps/test/com/google/gwt/maps/client/geom/ProjectionTest.java (revision 755)
+++ maps/test/com/google/gwt/maps/client/geom/ProjectionTest.java (working copy)
@@ -84,7 +84,7 @@
map.setCurrentMapType(mapType);
// Now try to call some of the MercatorProjection methods directly
- LatLng lResult = projection.fromPixelToLatLng(new Point(10,10), map.getZoomLevel(), false);
+ LatLng lResult = projection.fromPixelToLatLng(Point.getInstance(10,10), map.getZoomLevel(), false);
assertNotNull("translation from Pixel to LatLng", lResult);
Point pResult = projection.fromLatLngToPixel(map.getCenter(), map.getZoomLevel());
assertNotNull("translation from LatLng to Pixel", pResult);
@@ -123,7 +123,7 @@
public Point fromLatLngToPixel(LatLng latlng, int zoomLevel) {
assertNotNull(latlng);
assertTrue("zoomLevel > 0", zoomLevel > 0);
- return new Point(1, 1);
+ return Point.getInstance(1, 1);
}
@Override
Index: maps/src/com/google/gwt/maps/client/overlay/Icon.java
===================================================================
--- maps/src/com/google/gwt/maps/client/overlay/Icon.java (revision 755)
+++ maps/src/com/google/gwt/maps/client/overlay/Icon.java (working copy)
@@ -49,7 +49,7 @@
public Icon() {
jsoPeer = IconImpl.impl.construct();
// Workaround for problem in the Maps API - issue 124
- setIconAnchor(new Point(0,0));
+ setIconAnchor(Point.getInstance(0,0));
}
/**
@@ -69,7 +69,7 @@
public Icon(String imageUrl) {
jsoPeer = IconImpl.impl.construct(null, imageUrl);
// Workaround for problem in the Maps API - issue 124
- setIconAnchor(new Point(0,0));
+ setIconAnchor(Point.getInstance(0,0));
}
/**
Index: maps/src/com/google/gwt/maps/client/geom/TileIndex.java
===================================================================
--- maps/src/com/google/gwt/maps/client/geom/TileIndex.java (revision 755)
+++ maps/src/com/google/gwt/maps/client/geom/TileIndex.java (working copy)
@@ -16,103 +16,66 @@
package com.google.gwt.maps.client.geom;
import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.maps.client.impl.PointImpl;
-import com.google.gwt.maps.jsio.client.impl.Extractor;
/**
* Specifies the position of a Tile in the map. Used as an argument to
* [EMAIL PROTECTED] Projection#tileCheckRange(TileIndex,int,int)}
*
*/
-public class TileIndex {
+public class TileIndex extends JavaScriptObject {
+ /**
+ * Construct a new TileIndex instance. This is a representation of the Maps API GPoint object used for [EMAIL PROTECTED] TileLayer} operations.
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @return a new instance of a TileIndex option
+ */
+ public static final native Point getInstance(int x, int y) /*-{
+ return new $wnd.Point(x,y);
+ }-*/;
+
/*
* Design Note (zundel): The Maps API re-uses the Point object. I've modeled
* it as a different class in order to allow Point to be immutable and to
* disallow creating a TileIndex by users.
*/
- // TODO: DELETE ME! (needs to function w/o)
- @SuppressWarnings("unused")
- private static final Extractor<TileIndex> __extractor = new Extractor<TileIndex>() {
- public TileIndex fromJS(JavaScriptObject jso) {
- return createPeer(jso);
- }
-
- public JavaScriptObject toJS(TileIndex o) {
- return o.jsoPeer;
- }
- };
-
- /**
- * Create a new TileIndex by wrapping an existing JavaScript GPoint.
- *
- * @param jso the object to wrap.
- * @return a new TileIndex.
- */
- static TileIndex createPeer(JavaScriptObject jso) {
- return new TileIndex(jso);
+ protected TileIndex() {
}
-
- private final JavaScriptObject jsoPeer;
-
- private TileIndex(JavaScriptObject jso) {
- this.jsoPeer = jso;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof TileIndex) {
- return PointImpl.impl.equals(jsoPeer, (TileIndex) obj);
- }
- return false;
- }
-
+
/**
* Returns the X coordinate.
*
* @return the X coordinate.
*/
- public int getX() {
- return PointImpl.impl.getX(jsoPeer);
- }
+ public final native int getX() /*-{
+ return this.x;
+ }-*/;
/**
* Returns the Y coordinate.
*
* @return the Y coordinate.
*/
- public int getY() {
- return PointImpl.impl.getY(jsoPeer);
- }
+ public final native int getY() /*-{
+ return this.y;
+ }-*/;
- @Override
- public int hashCode() {
- // Bias the Y coordinate using a prime number (101) so that inverted
- // coordinates
- // do not hash to the same value.
- return getX() + (101 * getY());
- }
-
/**
* Sets the X coordinate.
*
* @param x the X coordinate.
*/
- public void setX(int x) {
- PointImpl.impl.setX(jsoPeer, x);
- }
+ public final native void setX(int x) /*-{
+ this.x = x;
+ }-*/;
/**
* Sets the Y coordinate.
*
* @param y the Y coordinate.
*/
- public void setY(int y) {
- PointImpl.impl.setY(jsoPeer, y);
- }
+ public final native void setY(int y) /*-{
+ this.y = y;
+ }-*/;
- @Override
- public String toString() {
- return PointImpl.impl.toString(jsoPeer);
- }
}
Index: maps/src/com/google/gwt/maps/client/geom/Point.java
===================================================================
--- maps/src/com/google/gwt/maps/client/geom/Point.java (revision 755)
+++ maps/src/com/google/gwt/maps/client/geom/Point.java (working copy)
@@ -15,78 +15,42 @@
*/
package com.google.gwt.maps.client.geom;
-import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
-import com.google.gwt.maps.client.impl.PointImpl;
-import com.google.gwt.maps.jsio.client.impl.Extractor;
/**
+ * A Point represents a point on the map by its pixel coordinates. It doesn't
+ * represent a point on the earth by its geographical coordinates.
+ * Geographical coordinates are now represented by [EMAIL PROTECTED] LatLng}.
*
+ * In the Google Maps coordinate system, the x coordinate increases to the
+ * right, and the y coordinate increases downwards, though you may use Point
+ * coordinates however you wish.
+ *
*/
-public final class Point {
+public class Point extends JavaScriptObject {
- // TODO: DELETE ME! (needs to function w/o)
- @SuppressWarnings("unused")
- private static final Extractor<Point> __extractor = new Extractor<Point>() {
- public Point fromJS(JavaScriptObject jso) {
- return createPeer(jso);
- }
-
- public JavaScriptObject toJS(Point point) {
- return point.jsoPeer;
- }
- };
-
- private static final PointImpl impl = GWT.create(PointImpl.class);
-
- static Point createPeer(JavaScriptObject jso) {
- return new Point(jso);
+ public static native Point getInstance(int x, int y) /*-{
+ return new $wnd.GPoint(x,y);
+ }-*/;
+
+ protected Point() {
}
- private final JavaScriptObject jsoPeer;
-
- public Point(int x, int y) {
- jsoPeer = impl.construct(x, y);
- }
-
- private Point(JavaScriptObject jso) {
- this.jsoPeer = jso;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof Point) {
- return impl.equals(jsoPeer, (Point) obj);
- }
- return false;
- }
-
/**
* Returns the X coordinate.
+ *
* @return the X coordinate.
*/
- public int getX() {
- return impl.getX(jsoPeer);
- }
+ public final native int getX() /*-{
+ return this.x;
+ }-*/;
/**
* Returns the Y coordinate.
+ *
* @return the Y coordinate.
*/
- public int getY() {
- return impl.getY(jsoPeer);
- }
-
- @Override
- public int hashCode() {
- // Bias the Y coordinate using a prime number (101) so that inverted coordinates
- // do not hash to the same value.
- return getX() + (101 * getY());
- }
-
- @Override
- public String toString() {
- return impl.toString(jsoPeer);
- }
-
+ public final native int getY() /*-{
+ return this.y;
+ }-*/;
}
Index: maps/src/com/google/gwt/maps/client/geom/Bounds.java
===================================================================
--- maps/src/com/google/gwt/maps/client/geom/Bounds.java (revision 755)
+++ maps/src/com/google/gwt/maps/client/geom/Bounds.java (working copy)
@@ -16,8 +16,8 @@
package com.google.gwt.maps.client.geom;
import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
import com.google.gwt.maps.client.impl.BoundsImpl;
-import com.google.gwt.maps.client.impl.JsUtil;
/**
* Represents a rectangular bound. A Bounds is defined by minimum and maximum X
@@ -37,8 +37,8 @@
*
* @param points
*/
- public Bounds(Point[] points) {
- jsoPeer = BoundsImpl.impl.construct(JsUtil.toJsList(points));
+ public Bounds(JsArray<Point> points) {
+ jsoPeer = BoundsImpl.impl.construct(points);
}
/**
@@ -81,8 +81,12 @@
* @return a new bounds object that encloses the previous bounds plus the
* supplied point.
*/
+ @SuppressWarnings("unchecked")
public Bounds extend(Point point) {
- Point pointArgs[] = {this.getUpperLeft(), this.getLowerRight()};
+ JsArray<Point> pointArgs = (JsArray<Point>) JavaScriptObject.createArray();
+ pointArgs.set(0, this.getUpperLeft());
+ pointArgs.set(1, this.getLowerRight());
+
// The JavaScript API enlarges the existing Bounds object. This API creates
// a new object, so we need to clone this Bounds instance first.
Bounds b = new Bounds(pointArgs);
Index: maps/src/com/google/gwt/maps/client/impl/JsUtil.java
===================================================================
--- maps/src/com/google/gwt/maps/client/impl/JsUtil.java (revision 755)
+++ maps/src/com/google/gwt/maps/client/impl/JsUtil.java (working copy)
@@ -21,7 +21,6 @@
import com.google.gwt.maps.client.InfoWindowContent.InfoWindowTab;
import com.google.gwt.maps.client.geocode.Placemark;
import com.google.gwt.maps.client.geom.LatLng;
-import com.google.gwt.maps.client.geom.Point;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.maps.jsio.client.Constructor;
import com.google.gwt.maps.jsio.client.FieldName;
@@ -61,9 +60,6 @@
JSList<Marker> asMarkerList(JavaScriptObject jso);
@FieldName("valueOf")
- JSList<Point> asPointList(JavaScriptObject jso);
-
- @FieldName("valueOf")
JSList<String> asStringList(JavaScriptObject jso);
@FieldName("valueOf")
@@ -121,12 +117,6 @@
return list;
}
- public static JSList<Point> toJsList(Point[] array) {
- JSList<Point> list = lists.asPointList(lists.newArray());
- list.addAll(Arrays.asList(array));
- return list;
- }
-
public static JSList<TileLayer> toJsList(TileLayer[] array) {
JSList<TileLayer> list = lists.asTileLayerList(lists.newArray());
list.addAll(Arrays.asList(array));
Index: maps/src/com/google/gwt/maps/client/impl/PointImpl.java
===================================================================
--- maps/src/com/google/gwt/maps/client/impl/PointImpl.java (revision 755)
+++ maps/src/com/google/gwt/maps/client/impl/PointImpl.java (working copy)
@@ -1,50 +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.client.geom.Point;
-import com.google.gwt.maps.client.geom.TileIndex;
-import com.google.gwt.maps.jsio.client.BeanProperties;
-import com.google.gwt.maps.jsio.client.Constructor;
-import com.google.gwt.maps.jsio.client.JSFlyweightWrapper;
-
-/**
- * Wraps the Maps API GPoint object from the Maps API using JSIO.
- */
[EMAIL PROTECTED]
-public interface PointImpl extends JSFlyweightWrapper {
- PointImpl impl = GWT.create(PointImpl.class);
-
- @Constructor("$wnd.GPoint")
- JavaScriptObject construct(double x, double y);
-
- boolean equals(JavaScriptObject jso, Point other);
-
- boolean equals(JavaScriptObject jso, TileIndex other);
-
- int getX(JavaScriptObject jso);
-
- int getY(JavaScriptObject jso);
-
- void setX(JavaScriptObject o, int x);
-
- void setY(JavaScriptObject o, int y);
-
- String toString(JavaScriptObject jso);
-
-}
Index: maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java
===================================================================
--- maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java (revision 755)
+++ maps/src/com/google/gwt/maps/client/impl/BoundsImpl.java (working copy)
@@ -17,12 +17,12 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
import com.google.gwt.maps.client.geom.Bounds;
import com.google.gwt.maps.client.geom.Point;
import com.google.gwt.maps.jsio.client.BeanProperties;
import com.google.gwt.maps.jsio.client.Constructor;
import com.google.gwt.maps.jsio.client.JSFlyweightWrapper;
-import com.google.gwt.maps.jsio.client.JSList;
/**
* Wraps the GBounds object in the Maps API using JSIO.
@@ -33,7 +33,7 @@
BoundsImpl impl = GWT.create(BoundsImpl.class);
@Constructor("$wnd.GBounds")
- JavaScriptObject construct(JSList<Point> points);
+ JavaScriptObject construct(JsArray<Point> points);
boolean containsBounds(JavaScriptObject jsoPeer, Bounds other);