KickJava   Java API By Example, From Geeks To Geeks.

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


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  * GoogleMapPolylineTag
11  *
12  * This class represents a <googlemaps;polyline> 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 GoogleMapPolylineTag extends TagSupport JavaDoc implements Serializable JavaDoc, GoogleMapEventListener {
19     
20     private String JavaDoc id = null;
21     private String JavaDoc pointlist = null;
22     private String JavaDoc color = "#ff0000";
23     private int weight = 2;
24     private float opacity = 0.50f;
25     Vector JavaDoc points = null;
26     Vector JavaDoc events = 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()).addPolyline(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 0-1 based opacity of the line. 0 is invisible, 1 is fully opaque.
53      *
54      * @param opacity A float from 0-1.
55      */

56     public void setOpacity(float opacity) {
57         this.opacity = opacity;
58     }
59     /**
60      * Sets the weight (width) of the line in pixels.
61      *
62      * @param weight An int specifying line width in pixels.
63      */

64     public void setWeight(int weight) {
65         this.weight = weight;
66     }
67     /**
68      * Returns the number of points that make up this line or 0 if none are specified.
69      *
70      * @return Number of points in the line, or 0.
71      */

72     public int pointCount() {
73         if (points == null)
74             return 0;
75         else
76             return points.size();
77     }
78     /**
79      * Returns the point located at the given iteration. Points are stored in order
80      * to ensure the line is consistent between renderings.
81      *
82      * @param int The iteration to lookup
83      * @return The point's id
84      */

85     public String JavaDoc getPoint(int p) {
86         if (points == null)
87             return null;
88         else
89             return (String JavaDoc) points.elementAt(p);
90     }
91     /**
92      * Returns this overlays unique id.
93      *
94      * @return The unique id of this overlay.
95      */

96     public String JavaDoc getId() {
97         return id;
98     }
99     /**
100      * Set the unique id for this polyline.
101      *
102      * @param id A unique identifier for this polyline.
103      */

104     public void setId(String JavaDoc id) {
105         this.id = id;
106     }
107     /**
108      * Returns a comma separated list of point ids that generate this line.
109      *
110      * @return A comma separated list of point ids, in order.
111      */

112     public String JavaDoc getPointlist() {
113         return pointlist;
114     }
115     /**
116      * Sets the list of point ids that will makeup this line. The point
117      * ids should be specified in a comma separated list, in the order
118      * the line is to render.<p>
119      * For example: point1, point3, point5, point7
120      *
121      * @param pointlist A comma separated list of point names, in order.
122      */

123     public void setPointlist(String JavaDoc pointlist) {
124         this.pointlist = pointlist;
125         points = new Vector JavaDoc();
126         String JavaDoc[] p = pointlist.split(",");
127         for (int i = 0; i < p.length; i++) {
128             points.add(p[i].trim());
129         }
130     }
131     /**
132      * Returns the color used to draw this line, in hexadecimal format.
133      *
134      * @return A hexadecimal String representing a color.
135      */

136     public String JavaDoc getColor() {
137         return color;
138     }
139     /**
140      * Returns the current opacity level (0-1) of the line.
141      *
142      * @return A float indicating opacity level.
143      */

144     public float getOpacity() {
145         return opacity;
146     }
147     /**
148      * Returns the current width (in pixels) if the line.
149      *
150      * @return An int representing line width (in pixels).
151      */

152     public int getWeight() {
153         return weight;
154     }
155     /**
156      * Adds an event listener to this overlay.
157      *
158      * @param event A GoogleMapEventTag
159      */

160     public void addEvent(GoogleMapEventTag event) {
161         if (events == null)
162             events = new Vector JavaDoc();
163         events.add(event);
164     }
165     /**
166      * Returns the list of currently registered event listeners
167      * for this overlay.
168      *
169      * @return A Vector of GoogleMapEventTags
170      */

171     public Vector JavaDoc getEvents() {
172         return events;
173     }
174 }
175
Popular Tags