001    package com.google.gwt.maps.client.overlays;
002    
003    import com.google.gwt.core.client.JavaScriptObject;
004    import com.google.gwt.dom.client.Element;
005    import com.google.gwt.event.shared.HandlerRegistration;
006    import com.google.gwt.maps.client.MapImpl;
007    import com.google.gwt.maps.client.MapWidget;
008    import com.google.gwt.maps.client.base.LatLng;
009    import com.google.gwt.maps.client.events.MapEventType;
010    import com.google.gwt.maps.client.events.MapHandlerRegistration;
011    import com.google.gwt.maps.client.events.closeclick.CloseClickEventFormatter;
012    import com.google.gwt.maps.client.events.closeclick.CloseClickMapHandler;
013    import com.google.gwt.maps.client.events.content.ContentChangeEventFormatter;
014    import com.google.gwt.maps.client.events.content.ContentChangeMapHandler;
015    import com.google.gwt.maps.client.events.domready.DomReadyEventFormatter;
016    import com.google.gwt.maps.client.events.domready.DomReadyMapHandler;
017    import com.google.gwt.maps.client.events.position.PositionChangeEventFormatter;
018    import com.google.gwt.maps.client.events.position.PositionChangeMapHandler;
019    import com.google.gwt.maps.client.events.zindex.ZindexChangeEventFormatter;
020    import com.google.gwt.maps.client.events.zindex.ZindexChangeMapHandler;
021    import com.google.gwt.maps.client.mvc.MVCObject;
022    import com.google.gwt.maps.client.streetview.StreetViewPanoramaImpl;
023    import com.google.gwt.maps.client.streetview.StreetViewPanoramaWidget;
024    import com.google.gwt.user.client.ui.Widget;
025    
026    /**
027     * An overlay that looks like a bubble and is often connected to a marker.
028     * <br>Extends {@link MVCObject}.
029     * 
030     */
031    public class InfoWindow extends MVCObject<InfoWindow> {
032    
033      /**
034       * use newInstance();
035       * Creates an info window with the given options. An InfoWindow can be placed on a map at a particular position or above a marker, depending on what is specified in the options. Unless auto-pan is disabled, an InfoWindow will pan the map to make itself visible when it is opened. After constructing an InfoWindow, you must call open to display it on the map. The user can click the close button on the InfoWindow to remove it from the map, or the developer can call close() for the same effect.
036       */
037      protected InfoWindow() {}
038      
039      /**
040       * Creates an info window with the given options. An InfoWindow can be placed on a map at a particular position or above a marker, depending on what is specified in the options. Unless auto-pan is disabled, an InfoWindow will pan the map to make itself visible when it is opened. After constructing an InfoWindow, you must call open to display it on the map. The user can click the close button on the InfoWindow to remove it from the map, or the developer can call close() for the same effect.
041       * @param options {@link InfoWindowOptions}
042       */
043      public static final InfoWindow newInstance(InfoWindowOptions options) {
044        return createJso(options).cast();
045      }
046    
047      private static final native JavaScriptObject createJso(InfoWindowOptions options) /*-{
048        return new $wnd.google.maps.InfoWindow(options);
049      }-*/;
050     
051      /**
052       * Closes this InfoWindow by removing it from the DOM structure.
053       */
054      public final native void close() /*-{
055        this.close();
056      }-*/;
057      
058      /**
059       * get content if its a string
060       * @return String
061       */
062      public final native String getContent_String() /*-{
063        return this.getContent();
064      }-*/;
065      
066      /**
067       * get content if its a node
068       * @return {@link Element}
069       */
070      public final native Element getContent_Node() /*-{
071        return this.getContent();
072      }-*/;
073      
074      /**
075       * get Position
076       */
077      public final native LatLng getPosition() /*-{
078        return this.getPosition();
079      }-*/;
080      
081      /**
082       * get Z index
083       */
084      public final native int getZindex() /*-{
085        return this.getZIndex();
086      }-*/;
087      
088      /**
089       * Opens this InfoWindow on the given map. Optionally, an InfoWindow can be associated with an anchor. In the core API, the only anchor is the Marker class. However, an anchor can be any MVCObject that exposes the position property and optionally anchorPoint for calculating the pixelOffset (see InfoWindowOptions). The anchorPoint is the offset from the anchor's position to the tip of the InfoWindow.
090       * @param mapWidget
091       */
092      public final void open(MapWidget mapWidget) {
093        open(mapWidget.getJso(), null);
094      }
095      
096      /**
097       * Opens this InfoWindow on the given map. Optionally, an InfoWindow can be associated with an anchor. In the core API, the only anchor is the Marker class. However, an anchor can be any MVCObject that exposes the position property and optionally anchorPoint for calculating the pixelOffset (see InfoWindowOptions). The anchorPoint is the offset from the anchor's position to the tip of the InfoWindow.
098       * @param mapWidget
099       * @param anchor
100       */
101      public final void open(MapWidget mapWidget, MVCObject<?> anchor) {
102        open(mapWidget.getJso(), anchor);
103      }
104    
105      private final native void open(MapImpl impl) /*-{
106        this.open(impl);
107      }-*/;
108      
109      private final native void open(MapImpl impl, MVCObject<?> anchor) /*-{
110        this.open(impl, anchor);
111      }-*/;
112      
113      private final native void open(MapImpl impl, JavaScriptObject anchor) /*-{
114        this.open(impl, anchor);
115      }-*/;
116      
117      /**
118       * Opens this InfoWindow on the given map. Optionally, an InfoWindow can be associated with an anchor. In the core API, the only anchor is the Marker class. However, an anchor can be any MVCObject that exposes the position property and optionally anchorPoint for calculating the pixelOffset (see InfoWindowOptions). The anchorPoint is the offset from the anchor's position to the tip of the InfoWindow.
119       * @param streetViewPanoRamaWidget
120       */
121      public final void open(StreetViewPanoramaWidget streetViewPanoRamaWidget) {
122        open(streetViewPanoRamaWidget.getJso());
123      }
124      
125      /**
126       * Opens this InfoWindow on the given map. Optionally, an InfoWindow can be associated with an anchor. In the core API, the only anchor is the Marker class. However, an anchor can be any MVCObject that exposes the position property and optionally anchorPoint for calculating the pixelOffset (see InfoWindowOptions). The anchorPoint is the offset from the anchor's position to the tip of the InfoWindow.
127       * @param streetViewPanoRamaWidget
128       * @param anchor
129       */
130      public final void open(StreetViewPanoramaWidget streetViewPanoRamaWidget, MVCObject<?> anchor) {
131        open(streetViewPanoRamaWidget.getJso(), anchor);
132      }
133      
134      private final native void open(StreetViewPanoramaImpl impl) /*-{
135        this.open(impl);
136      }-*/;
137      
138      private final native void open(StreetViewPanoramaImpl impl, MVCObject<?> anchor) /*-{
139        this.open(impl, anchor);
140      }-*/;
141        
142      public final void setContent(Widget widget) {
143        setContent(widget.getElement());
144      }
145      
146      /**
147       * set Content
148       * @param content
149       */
150      public final native void setContent(String content) /*-{
151        this.setContent(content);
152      }-*/;
153      
154      /**
155       * set Content
156       * @param element
157       */
158      public final native void setContent(Element element) /*-{
159        this.setContent(element);
160      }-*/;
161      
162      /**
163       * set Options
164       * @param options
165       */
166      public final native void setOptions(InfoWindowOptions options) /*-{
167        this.setOptions(options);
168      }-*/;
169      
170      /**
171       * set Position
172       * @param position
173       */
174      public final native void setPosition(LatLng position) /*-{
175        this.setPosition(position);
176      }-*/;
177      
178      /**
179       * set Z index
180       * @param index
181       */
182      public final native void setZindex(int index) /*-{
183        this.setZIndex(index);
184      }-*/;
185      
186      /**
187       * This event is fired when the close button was clicked.
188       * @param handler
189       */
190      public final HandlerRegistration addCloseClickHandler(CloseClickMapHandler handler) {
191        return MapHandlerRegistration.addHandler(this, MapEventType.CLOSECLICK, handler, new CloseClickEventFormatter());
192      }
193      
194      /**
195       * This event is fired when the content property changes.
196       * @param handler
197       */
198      public final HandlerRegistration addContentChangeHandler(ContentChangeMapHandler handler) {
199        return MapHandlerRegistration.addHandler(this, MapEventType.CONTENT_CHANGED, handler, new ContentChangeEventFormatter());
200      }
201      
202      /**
203       * This event is fired when the <code>&lt;div&gt;</code> containing the InfoWindow's content is attached to the DOM. You may wish to monitor this event if you are building out your info window content dynamically.
204       * @param handler
205       */
206      public final HandlerRegistration addDomReadyHandler(DomReadyMapHandler handler) {
207        return MapHandlerRegistration.addHandler(this, MapEventType.DOMREADY, handler, new DomReadyEventFormatter());
208      }
209      
210      /**
211       * This event is fired when the position property changes.
212       * @param handler
213       */
214      public final HandlerRegistration addPositionChangeHandler(PositionChangeMapHandler handler) {
215        return MapHandlerRegistration.addHandler(this, MapEventType.POSITION_CHANGED, handler, new PositionChangeEventFormatter());
216      }
217      
218      /**
219       * This event is fired when the InfoWindow's zIndex changes.
220       * @param handler
221       */
222      public final HandlerRegistration addZindexChangedHandler(ZindexChangeMapHandler handler) {
223        return MapHandlerRegistration.addHandler(this, MapEventType.ZINDEX_CHANGED, handler, new ZindexChangeEventFormatter());
224      }
225      
226    }