001 package com.google.gwt.maps.client.adsense;
002
003 import com.google.gwt.dom.client.Element;
004 import com.google.gwt.event.shared.HandlerRegistration;
005 import com.google.gwt.maps.client.MapWidget;
006 import com.google.gwt.maps.client.controls.ControlPosition;
007 import com.google.gwt.maps.client.events.channelnumber.ChannelNumberChangeMapHandler;
008 import com.google.gwt.maps.client.events.format.FormatChangeMapHandler;
009 import com.google.gwt.maps.client.events.mapchange.MapChangeMapHandler;
010 import com.google.gwt.maps.client.events.position.PositionChangeMapHandler;
011 import com.google.gwt.maps.client.mvc.MVCObjectWidget;
012 import com.google.gwt.user.client.DOM;
013
014 /**
015 * Implements AdSense for Content advertising on an associated map. To use an
016 * AdUnit, you must obtain and specify an AdSense for Content publisher ID
017 * within the AdUnit's constructor options. This class extends MVCObject.
018 * <br><br>
019 * See <a href="https://developers.google.com/maps/documentation/javascript/reference#AdUnit">AdUnit API Doc</a>
020 */
021 public class AdUnitWidget extends MVCObjectWidget<AdUnitImpl> {
022
023 /**
024 * jso
025 */
026 private AdUnitImpl impl;
027
028 /**
029 * create AdUnit widget
030 * @param options
031 */
032 public AdUnitWidget(AdUnitOptions options) {
033 Element div = DOM.createDiv();
034 impl = AdUnitImpl.newInstance(div, options);
035 setElement(div);
036 }
037
038 /**
039 * This event is fired when the AdUnit's channelNumber property changes.
040 * @param handler
041 */
042 public final HandlerRegistration addChannelNumberChangeHandler(ChannelNumberChangeMapHandler handler) {
043 return impl.addChannelNumberChangeHandler(handler);
044 }
045
046 /**
047 * This event is fired when the AdUnit's format property changes.
048 * @param handler
049 */
050 public final HandlerRegistration addFormatChangeHandler(FormatChangeMapHandler handler) {
051 return impl.addFormatChangeHandler(handler);
052 }
053
054 /**
055 * This event is fired when the AdUnit's map property changes.
056 * @param handler
057 */
058 public final HandlerRegistration addMapChangeHandler(MapChangeMapHandler handler) {
059 return impl.addMapChangeHandler(handler);
060 }
061
062 /**
063 * This event is fired when the AdUnit's position property changes.
064 * @param handler
065 */
066 public final HandlerRegistration addPositionChangeHandler(PositionChangeMapHandler handler) {
067 return impl.addPositionChangeHandler(handler);
068 }
069
070 /**
071 * Returns the channel number in use by this AdUnit.
072 */
073 public final String getChannelNumber() {
074 return impl.getChannelNumber();
075 };
076
077 /**
078 * Returns the containing element of the AdUnit.
079 */
080 public final Element getContainer() {
081 return impl.getContainer();
082 };
083
084 /**
085 * Returns the format in use by this AdUnit.
086 */
087 public final AdFormat getFormat() {
088 return impl.getFormat();
089 };
090
091 /**
092 * Returns the map to which this AdUnit's ads are targeted.
093 */
094 public final MapWidget getMap() {
095 return impl.getMap();
096 }
097
098 /**
099 * Returns the ControlPosition at which this AdUnit is displayed on the map.
100 */
101 public final ControlPosition getPosition() {
102 return impl.getPosition();
103 }
104
105 /**
106 * Returns the specified AdSense For Content publisher ID.
107 */
108 public final String getPublisherId() {
109 return impl.getPublisherId();
110 };
111
112 /**
113 * Specifies the channel number for this AdUnit. Channel numbers are optional and can be created for Google AdSense tracking.
114 * @param channelNumber
115 */
116 public final void setChannelNumber(String channelNumber) {
117 impl.setChannelNumber(channelNumber);
118 };
119
120 /**
121 * Specifies the display format for this AdUnit.
122 * @param format
123 */
124 public final void setFormat(AdFormat format) {
125 impl.setFormat(format);
126 };
127
128 /**
129 * Associates this AdUnit with the specified map. Ads will be targeted to the map's viewport. The map must be specified in order to display ads.
130 * @param mapWidget
131 */
132 public final void setMap(MapWidget mapWidget) {
133 impl.setMap(mapWidget);
134 }
135
136 /**
137 * Sets the ControlPosition at which to display the AdUnit on the map. If the position is set to null, the AdUnit is removed from the map.
138 * @param position {@link ControlPosition}
139 */
140 public final void setPosition(ControlPosition position) {
141 impl.setPosition(position);
142 }
143
144 }