KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.lamatek.tags.google;
2
3 import java.io.Serializable 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  * GoogleMapPolygonTag
11  *
12  * This class represents a <googlemaps;polygon> tag. Developers should not subclass or override this
13  * class or it's methods.
14  *
15  * @author Tom Cole
16  * @version 0.40
17  */

18 public class GoogleMapPolygonTag extends TagSupport JavaDoc implements Serializable JavaDoc, GoogleMapEventListener {
19
20     String JavaDoc color = "#ff0000";
21     int weight = 2;
22     float opacity = 0.50f;
23     String JavaDoc pointlist = null;
24     Vector JavaDoc points = null;
25     Vector JavaDoc events = null;
26     String JavaDoc id = null;
27     /**
28      * Overrides doStartTag() in TagSupport. Developers should not override this method.
29      * If they do, they must call super.doStartTag() to ensure the tag get added to the
30      * tree properly.
31      */

32     public int doStartTag() {
33         Tag JavaDoc tag = this;
34         while (tag.getParent() != null) {
35             if (tag.getParent() instanceof GoogleMapTag) {
36                 ((GoogleMapTag) tag.getParent()).addPolygon(this);
37                 return SKIP_BODY;
38             }
39             tag = tag.getParent();
40         }
41         return SKIP_BODY;
42     }
43     /**
44      * Sets the color used to draw this overlay. Default is #ff0000.
45      *
46      * @param color The color code in hexadecimal format.
47      */

48     public void setColor(String JavaDoc color) {
49         this.color = color;
50     }
51     /**
52      * Sets the weight (width) of the line in pixels.
53      *
54      * @param weight An int specifying line width in pixels.
55      */

56     public void setWeight(int weight) {
57         this.weight = weight;
58     }
59     /**
60      * Returns the current opacity level (0-1) of the line.
61      *
62      * @return A float indicating opacity level.
63      */

64     public float getOpacity() {
65         return opacity;
66     }
67     /**
68      * Sets the 0-1 based opacity of the line. 0 is invisible, 1 is fully opaque.
69      *
70      * @param opacity A float from 0-1.
71      */

72     public void setOpacity(float opacity) {
73         this.opacity = opacity;
74     }
75     /**
76      * Returns a comma separated list of point ids that generate this line.
77      *
78      * @return A comma separated list of point ids, in order.
79      */

80     public String JavaDoc getPointlist() {
81         return pointlist;
82     }
83     /**
84      * Sets the list of point ids that will makeup this line. The point
85      * ids should be specified in a comma separated list, in the order
86      * the line is to render.<p>
87      * For example: point1, point3, point5, point7
88      *
89      * @param pointlist A comma separated list of point names, in order.
90      */

91     public void setPointlist(String JavaDoc pointlist) {
92         this.pointlist = pointlist;
93         points = new Vector JavaDoc();
94         String JavaDoc[] p = pointlist.split(",");
95         for (int i = 0; i < p.length; i++) {
96             points.add(p[i].trim());
97         }
98     }
99     /**
100      * Returns the number of points that make up this line or 0 if none are specified.
101      *
102      * @return Number of points in the line, or 0.
103      */

104     public int pointCount() {
105         if (points == null)
106             return 0;
107         else
108             return points.size();
109     }
110     /**
111      * Returns the point located at the given iteration. Points are stored in order
112      * to ensure the line is consistent between renderings.
113      *
114      * @param int The iteration to lookup
115      * @return The point's id
116      */

117     public String JavaDoc getPoint(int p) {
118         if (points == null)
119             return null;
120         else
121             return (String JavaDoc) points.elementAt(p);
122     }
123     /**
124      * Returns the color used to draw this line, in hexadecimal format.
125      *
126      * @return A hexadecimal String representing a color.
127      */

128     public String JavaDoc getColor() {
129         return color;
130     }
131     /**
132      * Returns the current width (in pixels) if the line.
133      *
134      * @return An int representing line width (in pixels).
135      */

136     public int getWeight() {
137         return weight;
138     }
139     /**
140      * Adds an event listener to this overlay.
141      *
142      * @param event A GoogleMapEventTag
143      */

144     public void addEvent(GoogleMapEventTag event) {
145         if (events == null)
146             events = new Vector JavaDoc();
147         events.add(event);
148     }
149     /**
150      * Returns the list of currently registered event listeners
151      * for this overlay.
152      *
153      * @return A Vector of GoogleMapEventTags
154      */

155     public Vector JavaDoc getEvents() {
156         return events;
157     }
158     /**
159      * Returns this overlays unique id.
160      *
161      * @return The unique id of this overlay.
162      */

163     public String JavaDoc getId() {
164         return id;
165     }
166     /**
167      * Set the unique id for this polygon.
168      *
169      * @param id A unique identifier for this polygon.
170      */

171     public void setId(String JavaDoc id) {
172         this.id = id;
173     }
174 }
175
Popular Tags