1 /**********************************************
2 * Copyright (C) 2010-2011 Lukas Laag
3 * This file is part of lib-gwt-svg.
4 *
5 * libgwtsvg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * libgwtsvg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/
17 **********************************************/
18 /*
19 * Copyright (c) 2004 World Wide Web Consortium,
20 *
21 * (Massachusetts Institute of Technology, European Research Consortium for
22 * Informatics and Mathematics, Keio University). All Rights Reserved. This
23 * work is distributed under the W3C(r) Software License [1] in the hope that
24 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 *
27 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
28 */
29
30 package org.vectomatic.dom.svg;
31
32 import org.vectomatic.dom.svg.events.ActivateEvent;
33 import org.vectomatic.dom.svg.events.ActivateHandler;
34 import org.vectomatic.dom.svg.events.FocusInEvent;
35 import org.vectomatic.dom.svg.events.FocusInHandler;
36 import org.vectomatic.dom.svg.events.FocusOutEvent;
37 import org.vectomatic.dom.svg.events.FocusOutHandler;
38 import org.vectomatic.dom.svg.events.HasGraphicalHandlers;
39 import org.vectomatic.dom.svg.impl.SVGElement;
40 import org.vectomatic.dom.svg.impl.SVGPolylineElement;
41 import org.vectomatic.dom.svg.itf.ISVGAnimatedPoints;
42 import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired;
43 import org.vectomatic.dom.svg.itf.ISVGGraphicsElement;
44 import org.vectomatic.dom.svg.itf.ISVGLangSpace;
45 import org.vectomatic.dom.svg.itf.ISVGStylable;
46 import org.vectomatic.dom.svg.itf.ISVGTests;
47 import org.vectomatic.dom.svg.itf.ISVGTransformable;
48 import org.vectomatic.dom.svg.utils.DOMHelper;
49 import org.vectomatic.dom.svg.utils.SVGConstants;
50
51 import com.google.gwt.core.client.JavaScriptException;
52 import com.google.gwt.dom.client.TagName;
53 import com.google.gwt.event.dom.client.ClickEvent;
54 import com.google.gwt.event.dom.client.ClickHandler;
55 import com.google.gwt.event.dom.client.LoadEvent;
56 import com.google.gwt.event.dom.client.LoadHandler;
57 import com.google.gwt.event.dom.client.MouseDownEvent;
58 import com.google.gwt.event.dom.client.MouseDownHandler;
59 import com.google.gwt.event.dom.client.MouseMoveEvent;
60 import com.google.gwt.event.dom.client.MouseMoveHandler;
61 import com.google.gwt.event.dom.client.MouseOutEvent;
62 import com.google.gwt.event.dom.client.MouseOutHandler;
63 import com.google.gwt.event.dom.client.MouseOverEvent;
64 import com.google.gwt.event.dom.client.MouseOverHandler;
65 import com.google.gwt.event.dom.client.MouseUpEvent;
66 import com.google.gwt.event.dom.client.MouseUpHandler;
67 import com.google.gwt.event.dom.client.TouchCancelEvent;
68 import com.google.gwt.event.dom.client.TouchCancelHandler;
69 import com.google.gwt.event.dom.client.TouchEndEvent;
70 import com.google.gwt.event.dom.client.TouchEndHandler;
71 import com.google.gwt.event.dom.client.TouchMoveEvent;
72 import com.google.gwt.event.dom.client.TouchMoveHandler;
73 import com.google.gwt.event.dom.client.TouchStartEvent;
74 import com.google.gwt.event.dom.client.TouchStartHandler;
75 import com.google.gwt.event.shared.HandlerRegistration;
76
77 /**
78 * The {@link org.vectomatic.dom.svg.OMSVGPolylineElement} interface corresponds
79 * to the <a href='http://www.w3.org/TR/SVG11/shapes.html#PolylineElement'
80 * title='polyline element specification'>polyline</a> element.
81 */
82 @TagName("polyline")
83 public class OMSVGPolylineElement extends OMSVGElement implements HasGraphicalHandlers, ISVGTests, ISVGLangSpace, ISVGExternalResourcesRequired, ISVGStylable, ISVGTransformable, ISVGAnimatedPoints, ISVGGraphicsElement {
84 public OMSVGPolylineElement() {
85 this((SVGPolylineElement)DOMHelper.createElementNS(DOMHelper.getCurrentDocument(), SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_POLYLINE_TAG).cast());
86 }
87
88 protected OMSVGPolylineElement(SVGPolylineElement ot) {
89 super(ot);
90 }
91
92 // Implementation of the svg::SVGPolylineElement W3C IDL interface
93
94 // Implementation of the svg::SVGAnimatedPoints W3C IDL interface
95 /**
96 * Provides access to the base (i.e., static) contents of the <span class='attr-name'>'points'</span>
97 * attribute.
98 */
99 public final OMSVGPointList getPoints() {
100 return ((SVGPolylineElement)ot).getPoints();
101 }
102 /**
103 * Provides access to the current animated contents of the <span class='attr-name'>'points'</span>
104 * attribute. If the given attribute or property is being animated, contains
105 * the current animated value of the attribute or property. If the given attribute
106 * or property is not currently being animated, contains the same value as
107 * {@link org.vectomatic.dom.svg.itf.ISVGAnimatedPoints#getPoints()}.
108 */
109 public final OMSVGPointList getAnimatedPoints() {
110 return ((SVGPolylineElement)ot).getAnimatedPoints();
111 }
112
113 // Implementation of the svg::SVGExternalResourcesRequired W3C IDL interface
114 /**
115 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
116 * on the given element. Note that the SVG DOM defines the attribute {@link
117 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
118 * as being of type {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean}, whereas
119 * the SVG language definition says that {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
120 * is not animated. Because the SVG language definition states that {@link
121 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
122 * cannot be animated, the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getAnimVal()}
123 * will always be the same as the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getBaseVal()}.
124 */
125 public final OMSVGAnimatedBoolean getExternalResourcesRequired() {
126 return ((SVGPolylineElement)ot).getExternalResourcesRequired();
127 }
128
129 // Implementation of the svg::SVGLangSpace W3C IDL interface
130 /**
131 * Corresponds to attribute <code>xml:lang</code> on the given element.
132 */
133 public final String getXmllang() {
134 return ((SVGPolylineElement)ot).getXmllang();
135 }
136 /**
137 * Corresponds to attribute <code>xml:lang</code> on the given element.
138 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt
139 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
140 * attribute</a>.
141 */
142 public final void setXmllang(java.lang.String value) throws JavaScriptException {
143 ((SVGPolylineElement)ot).setXmllang(value);
144 }
145 /**
146 * Corresponds to attribute <code>xml:space</code> on the given element.
147 */
148 public final String getXmlspace() {
149 return ((SVGPolylineElement)ot).getXmlspace();
150 }
151 /**
152 * Corresponds to attribute <code>xml:space</code> on the given element.
153 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt
154 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
155 * attribute</a>.
156 */
157 public final void setXmlspace(java.lang.String value) throws JavaScriptException {
158 ((SVGPolylineElement)ot).setXmlspace(value);
159 }
160
161 // Implementation of the svg::SVGLocatable W3C IDL interface
162 /**
163 * The element which established the current viewport. Often, the nearest
164 * ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' title='svg
165 * element specification'>svg</a> element. Null if the current element is
166 * the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
167 * title='svg element specification'>svg</a> element.
168 */
169 public final OMSVGElement getNearestViewportElement() {
170 return (OMSVGElement)convert(((SVGPolylineElement)ot).getNearestViewportElement());
171 }
172 /**
173 * The farthest ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
174 * title='svg element specification'>svg</a> element. Null if the current
175 * element is the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
176 * title='svg element specification'>svg</a> element.
177 */
178 public final OMSVGElement getFarthestViewportElement() {
179 return (OMSVGElement)convert(((SVGPolylineElement)ot).getFarthestViewportElement());
180 }
181 /**
182 * Returns the tight bounding box in current user space (i.e., after application
183 * of the <code>transform</code> attribute, if any) on the geometry of all
184 * contained graphics elements, exclusive of stroking, clipping, masking and
185 * filter effects). Note that getBBox must return the actual bounding box
186 * at the time the method was called, even in case the element has not yet
187 * been rendered.
188 * @return An {@link org.vectomatic.dom.svg.OMSVGRect} object that defines
189 * the bounding box.
190 */
191 public final OMSVGRect getBBox() {
192 return ((SVGPolylineElement)ot).getBBox();
193 }
194 /**
195 * Returns the transformation matrix from current user units (i.e., after
196 * application of the <code>transform</code> attribute, if any) to the viewport
197 * coordinate system for the {@link org.vectomatic.dom.svg.itf.ISVGLocatable#getNearestViewportElement()}.
198 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
199 * the CTM.
200 */
201 public final OMSVGMatrix getCTM() {
202 return ((SVGPolylineElement)ot).getCTM();
203 }
204 /**
205 * Returns the transformation matrix from current user units (i.e., after
206 * application of the <code>transform</code> attribute, if any) to the parent
207 * user agent's notice of a "pixel". For display devices, ideally this represents
208 * a physical screen pixel. For other devices or environments where physical
209 * pixel sizes are not known, then an algorithm similar to the CSS2 definition
210 * of a "pixel" can be used instead. Note that null is returned if this element
211 * is not hooked into the document tree. This method would have been more
212 * aptly named as <code>getClientCTM</code>, but the name <code>getScreenCTM</code>
213 * is kept for historical reasons.
214 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
215 * the given transformation matrix.
216 */
217 public final OMSVGMatrix getScreenCTM() {
218 return ((SVGPolylineElement)ot).getScreenCTM();
219 }
220 /**
221 * Returns the transformation matrix from the user coordinate system on the
222 * current element (after application of the <code>transform</code> attribute,
223 * if any) to the user coordinate system on parameter <var>element</var> (after
224 * application of its <code>transform</code> attribute, if any).
225 * @param element The target element.
226 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
227 * the transformation.
228 * @throws SVGException(SVG_MATRIX_NOT_INVERTABLE) Raised if the currently
229 * defined transformation matrices make it impossible to compute the given
230 * matrix (e.g., because one of the transformations is singular).
231 */
232 public final OMSVGMatrix getTransformToElement(OMSVGElement element) throws JavaScriptException {
233 return ((SVGPolylineElement)ot).getTransformToElement(((SVGElement)element.ot));
234 }
235
236 // Implementation of the svg::SVGTests W3C IDL interface
237 /**
238 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredFeatures()}
239 * on the given element.
240 */
241 public final OMSVGStringList getRequiredFeatures() {
242 return ((SVGPolylineElement)ot).getRequiredFeatures();
243 }
244 /**
245 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredExtensions()}
246 * on the given element.
247 */
248 public final OMSVGStringList getRequiredExtensions() {
249 return ((SVGPolylineElement)ot).getRequiredExtensions();
250 }
251 /**
252 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getSystemLanguage()}
253 * on the given element.
254 */
255 public final OMSVGStringList getSystemLanguage() {
256 return ((SVGPolylineElement)ot).getSystemLanguage();
257 }
258 /**
259 * Returns true if the user agent supports the given extension, specified
260 * by a URI.
261 * @param extension The name of the extension, expressed as a URI.
262 * @return True or false, depending on whether the given extension is supported.
263 */
264 public final boolean hasExtension(String extension) {
265 return ((SVGPolylineElement)ot).hasExtension(extension);
266 }
267
268 // Implementation of the svg::SVGTransformable W3C IDL interface
269 /**
270 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTransformable#getTransform()}
271 * on the given element.
272 */
273 public final OMSVGAnimatedTransformList getTransform() {
274 return ((SVGPolylineElement)ot).getTransform();
275 }
276
277 @Override
278 public final HandlerRegistration addClickHandler(ClickHandler handler) {
279 return addDomHandler(handler, ClickEvent.getType());
280 }
281 @Override
282 public final HandlerRegistration addLoadHandler(LoadHandler handler) {
283 return addDomHandler(handler, LoadEvent.getType());
284 }
285 @Override
286 public final HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
287 return addDomHandler(handler, MouseDownEvent.getType());
288 }
289 @Override
290 public final HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
291 return addDomHandler(handler, MouseMoveEvent.getType());
292 }
293 @Override
294 public final HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
295 return addDomHandler(handler, MouseOutEvent.getType());
296 }
297 @Override
298 public final HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
299 return addDomHandler(handler, MouseOverEvent.getType());
300 }
301 @Override
302 public final HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
303 return addDomHandler(handler, MouseUpEvent.getType());
304 }
305 @Override
306 public final HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
307 return addDomHandler(handler, TouchCancelEvent.getType());
308 }
309 @Override
310 public final HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
311 return addDomHandler(handler, TouchEndEvent.getType());
312 }
313 @Override
314 public final HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
315 return addDomHandler(handler, TouchMoveEvent.getType());
316 }
317 @Override
318 public final HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
319 return addDomHandler(handler, TouchStartEvent.getType());
320 }
321 @Override
322 public final HandlerRegistration addActivateHandler(ActivateHandler handler) {
323 return addDomHandler(handler, ActivateEvent.getType());
324 }
325 @Override
326 public final HandlerRegistration addFocusInHandler(FocusInHandler handler) {
327 return addDomHandler(handler, FocusInEvent.getType());
328 }
329 @Override
330 public final HandlerRegistration addFocusOutHandler(FocusOutHandler handler) {
331 return addDomHandler(handler, FocusOutEvent.getType());
332 }
333 }