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