View Javadoc

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