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.SVGGElement;
41 import org.vectomatic.dom.svg.itf.ISVGContainerElement;
42 import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired;
43 import org.vectomatic.dom.svg.itf.ISVGLangSpace;
44 import org.vectomatic.dom.svg.itf.ISVGStylable;
45 import org.vectomatic.dom.svg.itf.ISVGTests;
46 import org.vectomatic.dom.svg.itf.ISVGTransformable;
47 import org.vectomatic.dom.svg.utils.DOMHelper;
48 import org.vectomatic.dom.svg.utils.SVGConstants;
49
50 import com.google.gwt.core.client.JavaScriptException;
51 import com.google.gwt.dom.client.TagName;
52 import com.google.gwt.event.dom.client.ClickEvent;
53 import com.google.gwt.event.dom.client.ClickHandler;
54 import com.google.gwt.event.dom.client.LoadEvent;
55 import com.google.gwt.event.dom.client.LoadHandler;
56 import com.google.gwt.event.dom.client.MouseDownEvent;
57 import com.google.gwt.event.dom.client.MouseDownHandler;
58 import com.google.gwt.event.dom.client.MouseMoveEvent;
59 import com.google.gwt.event.dom.client.MouseMoveHandler;
60 import com.google.gwt.event.dom.client.MouseOutEvent;
61 import com.google.gwt.event.dom.client.MouseOutHandler;
62 import com.google.gwt.event.dom.client.MouseOverEvent;
63 import com.google.gwt.event.dom.client.MouseOverHandler;
64 import com.google.gwt.event.dom.client.MouseUpEvent;
65 import com.google.gwt.event.dom.client.MouseUpHandler;
66 import com.google.gwt.event.dom.client.TouchCancelEvent;
67 import com.google.gwt.event.dom.client.TouchCancelHandler;
68 import com.google.gwt.event.dom.client.TouchEndEvent;
69 import com.google.gwt.event.dom.client.TouchEndHandler;
70 import com.google.gwt.event.dom.client.TouchMoveEvent;
71 import com.google.gwt.event.dom.client.TouchMoveHandler;
72 import com.google.gwt.event.dom.client.TouchStartEvent;
73 import com.google.gwt.event.dom.client.TouchStartHandler;
74 import com.google.gwt.event.shared.HandlerRegistration;
75
76 /**
77 * The {@link org.vectomatic.dom.svg.OMSVGSVGElement} interface corresponds
78 * to the <a href='http://www.w3.org/TR/SVG11/struct.html#GElement' title='g
79 * element specification'>g</a> element.
80 */
81 @TagName("g")
82 public class OMSVGGElement extends OMSVGElement implements HasGraphicalHandlers, ISVGTests, ISVGLangSpace, ISVGExternalResourcesRequired, ISVGStylable, ISVGTransformable, ISVGContainerElement {
83 public OMSVGGElement() {
84 this((SVGGElement)DOMHelper.createElementNS(DOMHelper.getCurrentDocument(), SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_G_TAG).cast());
85 }
86
87 protected OMSVGGElement(SVGGElement ot) {
88 super(ot);
89 }
90
91 // Implementation of the svg::SVGGElement W3C IDL interface
92
93 // Implementation of the svg::SVGExternalResourcesRequired W3C IDL interface
94 /**
95 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
96 * on the given element. Note that the SVG DOM defines the attribute {@link
97 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
98 * as being of type {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean}, whereas
99 * the SVG language definition says that {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
100 * is not animated. Because the SVG language definition states that {@link
101 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
102 * cannot be animated, the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getAnimVal()}
103 * will always be the same as the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getBaseVal()}.
104 */
105 public final OMSVGAnimatedBoolean getExternalResourcesRequired() {
106 return ((SVGGElement)ot).getExternalResourcesRequired();
107 }
108
109 // Implementation of the svg::SVGLangSpace W3C IDL interface
110 /**
111 * Corresponds to attribute <code>xml:lang</code> on the given element.
112 */
113 public final String getXmllang() {
114 return ((SVGGElement)ot).getXmllang();
115 }
116 /**
117 * Corresponds to attribute <code>xml:lang</code> on the given element.
118 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt
119 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
120 * attribute</a>.
121 */
122 public final void setXmllang(java.lang.String value) throws JavaScriptException {
123 ((SVGGElement)ot).setXmllang(value);
124 }
125 /**
126 * Corresponds to attribute <code>xml:space</code> on the given element.
127 */
128 public final String getXmlspace() {
129 return ((SVGGElement)ot).getXmlspace();
130 }
131 /**
132 * Corresponds to attribute <code>xml:space</code> on the given element.
133 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt
134 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
135 * attribute</a>.
136 */
137 public final void setXmlspace(java.lang.String value) throws JavaScriptException {
138 ((SVGGElement)ot).setXmlspace(value);
139 }
140
141 // Implementation of the svg::SVGLocatable W3C IDL interface
142 /**
143 * The element which established the current viewport. Often, the nearest
144 * ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' title='svg
145 * element specification'>svg</a> element. Null if the current element is
146 * the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
147 * title='svg element specification'>svg</a> element.
148 */
149 public final OMSVGElement getNearestViewportElement() {
150 return (OMSVGElement)convert(((SVGGElement)ot).getNearestViewportElement());
151 }
152 /**
153 * The farthest ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
154 * title='svg element specification'>svg</a> element. Null if the current
155 * element is the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
156 * title='svg element specification'>svg</a> element.
157 */
158 public final OMSVGElement getFarthestViewportElement() {
159 return (OMSVGElement)convert(((SVGGElement)ot).getFarthestViewportElement());
160 }
161 /**
162 * Returns the tight bounding box in current user space (i.e., after application
163 * of the <code>transform</code> attribute, if any) on the geometry of all
164 * contained graphics elements, exclusive of stroking, clipping, masking and
165 * filter effects). Note that getBBox must return the actual bounding box
166 * at the time the method was called, even in case the element has not yet
167 * been rendered.
168 * @return An {@link org.vectomatic.dom.svg.OMSVGRect} object that defines
169 * the bounding box.
170 */
171 public final OMSVGRect getBBox() {
172 return ((SVGGElement)ot).getBBox();
173 }
174 /**
175 * Returns the transformation matrix from current user units (i.e., after
176 * application of the <code>transform</code> attribute, if any) to the viewport
177 * coordinate system for the {@link org.vectomatic.dom.svg.itf.ISVGLocatable#getNearestViewportElement()}.
178 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
179 * the CTM.
180 */
181 public final OMSVGMatrix getCTM() {
182 return ((SVGGElement)ot).getCTM();
183 }
184 /**
185 * Returns the transformation matrix from current user units (i.e., after
186 * application of the <code>transform</code> attribute, if any) to the parent
187 * user agent's notice of a "pixel". For display devices, ideally this represents
188 * a physical screen pixel. For other devices or environments where physical
189 * pixel sizes are not known, then an algorithm similar to the CSS2 definition
190 * of a "pixel" can be used instead. Note that null is returned if this element
191 * is not hooked into the document tree. This method would have been more
192 * aptly named as <code>getClientCTM</code>, but the name <code>getScreenCTM</code>
193 * is kept for historical reasons.
194 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
195 * the given transformation matrix.
196 */
197 public final OMSVGMatrix getScreenCTM() {
198 return ((SVGGElement)ot).getScreenCTM();
199 }
200 /**
201 * Returns the transformation matrix from the user coordinate system on the
202 * current element (after application of the <code>transform</code> attribute,
203 * if any) to the user coordinate system on parameter <var>element</var> (after
204 * application of its <code>transform</code> attribute, if any).
205 * @param element The target element.
206 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
207 * the transformation.
208 * @throws SVGException(SVG_MATRIX_NOT_INVERTABLE) Raised if the currently
209 * defined transformation matrices make it impossible to compute the given
210 * matrix (e.g., because one of the transformations is singular).
211 */
212 public final OMSVGMatrix getTransformToElement(OMSVGElement element) throws JavaScriptException {
213 return ((SVGGElement)ot).getTransformToElement(((SVGElement)element.ot));
214 }
215
216 // Implementation of the svg::SVGTests W3C IDL interface
217 /**
218 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredFeatures()}
219 * on the given element.
220 */
221 public final OMSVGStringList getRequiredFeatures() {
222 return ((SVGGElement)ot).getRequiredFeatures();
223 }
224 /**
225 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredExtensions()}
226 * on the given element.
227 */
228 public final OMSVGStringList getRequiredExtensions() {
229 return ((SVGGElement)ot).getRequiredExtensions();
230 }
231 /**
232 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getSystemLanguage()}
233 * on the given element.
234 */
235 public final OMSVGStringList getSystemLanguage() {
236 return ((SVGGElement)ot).getSystemLanguage();
237 }
238 /**
239 * Returns true if the user agent supports the given extension, specified
240 * by a URI.
241 * @param extension The name of the extension, expressed as a URI.
242 * @return True or false, depending on whether the given extension is supported.
243 */
244 public final boolean hasExtension(String extension) {
245 return ((SVGGElement)ot).hasExtension(extension);
246 }
247
248 // Implementation of the svg::SVGTransformable W3C IDL interface
249 /**
250 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTransformable#getTransform()}
251 * on the given element.
252 */
253 public final OMSVGAnimatedTransformList getTransform() {
254 return ((SVGGElement)ot).getTransform();
255 }
256
257 @Override
258 public final HandlerRegistration addClickHandler(ClickHandler handler) {
259 return addDomHandler(handler, ClickEvent.getType());
260 }
261 @Override
262 public final HandlerRegistration addLoadHandler(LoadHandler handler) {
263 return addDomHandler(handler, LoadEvent.getType());
264 }
265 @Override
266 public final HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
267 return addDomHandler(handler, MouseDownEvent.getType());
268 }
269 @Override
270 public final HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
271 return addDomHandler(handler, MouseMoveEvent.getType());
272 }
273 @Override
274 public final HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
275 return addDomHandler(handler, MouseOutEvent.getType());
276 }
277 @Override
278 public final HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
279 return addDomHandler(handler, MouseOverEvent.getType());
280 }
281 @Override
282 public final HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
283 return addDomHandler(handler, MouseUpEvent.getType());
284 }
285 @Override
286 public final HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
287 return addDomHandler(handler, TouchCancelEvent.getType());
288 }
289 @Override
290 public final HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
291 return addDomHandler(handler, TouchEndEvent.getType());
292 }
293 @Override
294 public final HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
295 return addDomHandler(handler, TouchMoveEvent.getType());
296 }
297 @Override
298 public final HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
299 return addDomHandler(handler, TouchStartEvent.getType());
300 }
301 @Override
302 public final HandlerRegistration addActivateHandler(ActivateHandler handler) {
303 return addDomHandler(handler, ActivateEvent.getType());
304 }
305 @Override
306 public final HandlerRegistration addFocusInHandler(FocusInHandler handler) {
307 return addDomHandler(handler, FocusInEvent.getType());
308 }
309 @Override
310 public final HandlerRegistration addFocusOutHandler(FocusOutHandler handler) {
311 return addDomHandler(handler, FocusOutEvent.getType());
312 }
313 }