KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lamatek > tags > google > GoogleMapInsertTag


1 package com.lamatek.tags.google;
2
3 import java.util.StringTokenizer JavaDoc;
4 import java.util.Vector JavaDoc;
5
6 import javax.servlet.jsp.tagext.Tag JavaDoc;
7 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
8
9 /**
10  * GoogleMapInsertTag
11  *
12  * Represents a <googlemaps:insert> tag, which attaches a pannable, zoomable image
13  * to the map. Developers should now extend this class or override it's methods.
14  *
15  * @author Tom Cole
16  * @version 0.96
17  */

18 public class GoogleMapInsertTag extends TagSupport JavaDoc {
19
20     String JavaDoc id;
21     String JavaDoc point;
22     String JavaDoc url;
23     int baseZoom;
24     int width;
25     int height;
26     Vector JavaDoc maps = null;
27     String JavaDoc mapTypes = null;
28     /**
29      * Sets a map unique id for this insert.
30      *
31      * @param id A unique identifier for this insert.
32      */

33     public void setId(String JavaDoc id) {
34         this.id = id;
35     }
36     /**
37      * Returns the unique id for this insert.
38      *
39      * @return The inserts id.
40      */

41     public String JavaDoc getId() {
42         return id;
43     }
44     /**
45      * Returns the zoom level at which this image should be displayed at
46      * fullscale. The image will be scaled smaller/larger as the zoom
47      * level goes above/below this value.
48      *
49      * @return The base zoom level for this image.
50      */

51     public int getBaseZoom() {
52         return baseZoom;
53     }
54     /**
55      * Sets the base zoom level where the image should be displayed
56      * at full scale.
57      *
58      * @param baseZoom The zoom level this image is displayed at full scale.
59      */

60     public void setBaseZoom(int baseZoom) {
61         this.baseZoom = baseZoom;
62     }
63     /**
64      * Returns the full scale height (in pixels) of this image.
65      *
66      * @return The height of the image in pixels.
67      */

68     public int getHeight() {
69         return height;
70     }
71     /**
72      * Sets the full scale height (in pixels) of this image.
73      *
74      * @param height The height of the image, in pixels.
75      */

76     public void setHeight(int height) {
77         this.height = height;
78     }
79     /**
80      * Returns the id of the point tag that points to the centerpoint of this image.
81      *
82      * @return The id of a point tag in this map.
83      */

84     public String JavaDoc getPoint() {
85         return point;
86     }
87     /**
88      * Sets the id of the point tag that points to the centerpoing of this image.
89      * The image will be placed on the map based on the longitude/latitude of this point.
90      *
91      * @param point The id of a point that is part of this map.
92      */

93     public void setPoint(String JavaDoc point) {
94         this.point = point;
95     }
96     /**
97      * Returns the url to the image to attach to the map.
98      *
99      * @return A relative or absolute url.
100      */

101     public String JavaDoc getUrl() {
102         return url;
103     }
104     /**
105      * Sets the url to the image that is to be attached to the map. This may be
106      * either a relative or absolute url.
107      *
108      * @param url A relative or asolute url to a valid image file.
109      */

110     public void setUrl(String JavaDoc url) {
111         this.url = url;
112     }
113     /**
114      * Returns the full scale width (in pixels) of this image.
115      *
116      * @return The width of the image, in pixels.
117      */

118     public int getWidth() {
119         return width;
120     }
121     /**
122      * Sets the full scale width (in pixels) of this image.
123      *
124      * @param width The full-scale width of the image, in pixels.
125      */

126     public void setWidth(int width) {
127         this.width = width;
128     }
129     /**
130      * Overrides doStartTag() in TagSupport. Developers should not override this method.
131      * If they do, they must call super.doStartTag() to ensure the tag get added to the
132      * tree properly.
133      */

134     public int doStartTag() {
135         Tag JavaDoc tag = this;
136         while (tag.getParent() != null) {
137             if (tag.getParent() instanceof GoogleMapTag) {
138                 ((GoogleMapTag) tag.getParent()).addInsert(this);
139                 return SKIP_BODY;
140             }
141             tag = tag.getParent();
142         }
143         return SKIP_BODY;
144     }
145     /**
146      * Adds a map type to the allowed list. The mapType parameter should correspond to
147      * the labels on the map type control buttons, and these are <em>case sensitive</em>.
148      * For example, use "Map", "Hybrid" or "Satellite" for the default map types.
149      *
150      * @param mapType A map type that should display this image insert.
151      */

152     public void addMapType(String JavaDoc mapType) {
153         if (maps == null)
154             maps = new Vector JavaDoc();
155         maps.addElement(mapType);
156     }
157     /**
158      * Sets the map types that should display this image insert. The mapTypes attribute
159      * must be a comma separated list of map type names, as denoted by the map type control
160      * buttons. For example, to display this image insert on all the standard map types you could
161      * specify "Map, Hybrid, Satellite". The map type names are <em>case sensitive</em>.
162      * <p>
163      * If you specify no names (by not setting this or passing it 'null') then all
164      * registered map types will display the image insert.
165      *
166      * @param mapTypes A comma separated list of valid map type names.
167      */

168     public void setMapTypes(String JavaDoc mapTypes) {
169         this.mapTypes = mapTypes;
170         StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(mapTypes, ",");
171         while (t.hasMoreTokens()) {
172             if (this.maps == null)
173                 this.maps = new Vector JavaDoc();
174             String JavaDoc mapType = t.nextToken().trim();
175             this.maps.addElement(mapType);
176         }
177     }
178     /**
179      * Returns the comma separated list of map type names that display this image insert.
180      * This method only returns a value if map types were set using setMapTypes(), otherwise
181      * it returns null.
182      *
183      * @return The comma separated list of included map type names.
184      */

185     public String JavaDoc getMapTypes() {
186        return mapTypes;
187     }
188     /**
189      * Returns the number of map type names that are to display this image insert, or 0 if there are none.
190      *
191      * @return The number of map type names included.
192      */

193     public int getMapTypeCount() {
194         if (maps == null)
195             return 0;
196         else
197             return maps.size();
198     }
199     /**
200      * Returns the map type name at the given interation, or null if none exists.
201      *
202      * @return The registered map type name at the given iterator, or null of none is defined.
203      */

204     public String JavaDoc getMapType(int i) {
205         if (maps == null)
206             return null;
207         else
208             return (String JavaDoc) maps.elementAt(i);
209     }
210 }
211
Popular Tags