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.BeginEvent;
35  import org.vectomatic.dom.svg.events.BeginHandler;
36  import org.vectomatic.dom.svg.events.EndEvent;
37  import org.vectomatic.dom.svg.events.EndHandler;
38  import org.vectomatic.dom.svg.events.FocusInEvent;
39  import org.vectomatic.dom.svg.events.FocusInHandler;
40  import org.vectomatic.dom.svg.events.FocusOutEvent;
41  import org.vectomatic.dom.svg.events.FocusOutHandler;
42  import org.vectomatic.dom.svg.events.HasAnimationHandlers;
43  import org.vectomatic.dom.svg.events.HasGraphicalHandlers;
44  import org.vectomatic.dom.svg.events.RepeatEvent;
45  import org.vectomatic.dom.svg.events.RepeatHandler;
46  import org.vectomatic.dom.svg.impl.SVGAnimationElement;
47  import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired;
48  import org.vectomatic.dom.svg.itf.ISVGTests;
49  
50  import com.google.gwt.core.client.JavaScriptException;
51  import com.google.gwt.event.dom.client.ClickEvent;
52  import com.google.gwt.event.dom.client.ClickHandler;
53  import com.google.gwt.event.dom.client.DragEndEvent;
54  import com.google.gwt.event.dom.client.DragEndHandler;
55  import com.google.gwt.event.dom.client.DragEnterEvent;
56  import com.google.gwt.event.dom.client.DragEnterHandler;
57  import com.google.gwt.event.dom.client.DragEvent;
58  import com.google.gwt.event.dom.client.DragHandler;
59  import com.google.gwt.event.dom.client.DragLeaveEvent;
60  import com.google.gwt.event.dom.client.DragLeaveHandler;
61  import com.google.gwt.event.dom.client.DragOverEvent;
62  import com.google.gwt.event.dom.client.DragOverHandler;
63  import com.google.gwt.event.dom.client.DragStartEvent;
64  import com.google.gwt.event.dom.client.DragStartHandler;
65  import com.google.gwt.event.dom.client.DropEvent;
66  import com.google.gwt.event.dom.client.DropHandler;
67  import com.google.gwt.event.dom.client.LoadEvent;
68  import com.google.gwt.event.dom.client.LoadHandler;
69  import com.google.gwt.event.dom.client.MouseDownEvent;
70  import com.google.gwt.event.dom.client.MouseDownHandler;
71  import com.google.gwt.event.dom.client.MouseMoveEvent;
72  import com.google.gwt.event.dom.client.MouseMoveHandler;
73  import com.google.gwt.event.dom.client.MouseOutEvent;
74  import com.google.gwt.event.dom.client.MouseOutHandler;
75  import com.google.gwt.event.dom.client.MouseOverEvent;
76  import com.google.gwt.event.dom.client.MouseOverHandler;
77  import com.google.gwt.event.dom.client.MouseUpEvent;
78  import com.google.gwt.event.dom.client.MouseUpHandler;
79  import com.google.gwt.event.dom.client.TouchCancelEvent;
80  import com.google.gwt.event.dom.client.TouchCancelHandler;
81  import com.google.gwt.event.dom.client.TouchEndEvent;
82  import com.google.gwt.event.dom.client.TouchEndHandler;
83  import com.google.gwt.event.dom.client.TouchMoveEvent;
84  import com.google.gwt.event.dom.client.TouchMoveHandler;
85  import com.google.gwt.event.dom.client.TouchStartEvent;
86  import com.google.gwt.event.dom.client.TouchStartHandler;
87  import com.google.gwt.event.shared.HandlerRegistration;
88  
89  /**
90   * <p>The {@link org.vectomatic.dom.svg.OMSVGAnimationElement} interface is
91   * the base interface for all of the animation element interfaces: {@link
92   * org.vectomatic.dom.svg.OMSVGAnimateElement}, {@link org.vectomatic.dom.svg.OMSVGSetElement},
93   * {@link org.vectomatic.dom.svg.OMSVGAnimateColorElement}, {@link org.vectomatic.dom.svg.OMSVGAnimateMotionElement}
94   * and {@link org.vectomatic.dom.svg.OMSVGAnimateTransformElement}.</p> <p>Unlike
95   * other SVG DOM interfaces, the SVG DOM does not specify convenience DOM
96   * properties corresponding to the various language attributes on SVG's animation
97   * elements. Specification of these convenience properties in a way that will
98   * be compatible with future versions of SMIL Animation is expected in a future
99   * version of SVG. The current method for accessing and modifying the attributes
100  * on the animation elements is to use the standard <code>getAttribute</code>,
101  * <code>setAttribute</code>, <code>getAttributeNS</code> and <code>setAttributeNS</code>
102  * defined in <a href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/">DOM
103  * Level 2 Core</a> [<a href="refs.html#ref-DOM2">DOM2</a>].</p>
104  */
105 public abstract class OMSVGAnimationElement extends OMSVGElement implements HasGraphicalHandlers, HasAnimationHandlers, ISVGTests, ISVGExternalResourcesRequired {
106   protected OMSVGAnimationElement(SVGAnimationElement ot) {
107     super(ot);
108   }
109 
110   // Implementation of the svg::SVGAnimationElement W3C IDL interface
111   /**
112    * The element which is being animated.
113    */
114   public final OMSVGElement getTargetElement() {
115     return (OMSVGElement)convert(((SVGAnimationElement)ot).getTargetElement());
116   }
117   /**
118    * Returns the begin time, in seconds, for this animation element's current
119    * interval, if it exists, regardless of whether the interval has begun yet.
120    * If there is no current interval, then a DOMException with code INVALID_STATE_ERR
121    * is thrown.
122    * @return The start time, in seconds, of this animation element's current
123    * interval.
124    * @throws DOMException(INVALID_STATE_ERR) The animation element does not
125    * have a current interval.
126    */
127   public final float getStartTime() throws JavaScriptException {
128     return ((SVGAnimationElement)ot).getStartTime();
129   }
130   /**
131    * Returns the current time in seconds relative to time zero for the given
132    * time container.
133    * @return The current time in seconds relative to time zero for the given
134    * time container.
135    */
136   public final float getCurrentTime() {
137     return ((SVGAnimationElement)ot).getCurrentTime();
138   }
139   /**
140    * Returns the number of seconds for the simple duration for this animation.
141    * If the simple duration is undefined (e.g., the end time is indefinite),
142    * then an exception is raised.
143    * @return number of seconds for the simple duration for this animation.
144    * @throws DOMException(NOT_SUPPORTED_ERR) The simple duration is not   determined
145    * on the given element.
146    */
147   public final float getSimpleDuration() throws JavaScriptException {
148     return ((SVGAnimationElement)ot).getSimpleDuration();
149   }
150 
151   // Implementation of the smil::ElementTimeControl W3C IDL interface
152   /**
153    * Creates a begin instance time for the current time. The new instance time
154    * is added to the <a href="http://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-BeginEnd-InstanceTimesLists"><em>begin
155    * instance times list</em></a>. The behavior of this method is equivalent
156    * to <code>beginElementAt(0)</code>.
157    */
158   public final void beginElement() {
159     ((SVGAnimationElement)ot).beginElement();
160   }
161   /**
162    * Creates a begin instance time for the current time plus the specified offset.
163    * The new instance time is added to the <a href="http://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-BeginEnd-InstanceTimesLists"><em>begin
164    * instance times list</em></a>.
165    * @param offset The offset from the current document time, in seconds, at
166    * which to begin the element.
167    */
168   public final void beginElementAt(float offset) {
169     ((SVGAnimationElement)ot).beginElementAt(offset);
170   }
171   /**
172    * Creates an end instance time for the current time. The new instance time
173    * is added to the <a href="http://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-BeginEnd-InstanceTimesLists"><em>end
174    * instance times list</em></a>. The behavior of this method is equivalent
175    * to <code>endElementAt(0)</code>.
176    */
177   public final void endElement() {
178     ((SVGAnimationElement)ot).endElement();
179   }
180   /**
181    * Creates a end instance time for the current time plus the specified offset.
182    * The new instance time is added to the <a href="http://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-BeginEnd-InstanceTimesLists"><em>end
183    * instance times list</em></a>.
184    * @param offset offset from the current document time, in seconds, at   which
185    * to end the element.
186    */
187   public final void endElementAt(float offset) {
188     ((SVGAnimationElement)ot).endElementAt(offset);
189   }
190 
191   // Implementation of the svg::SVGExternalResourcesRequired W3C IDL interface
192   /**
193    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
194    * on the given element. Note that the SVG DOM defines the attribute {@link
195    * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
196    * as being of type {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean}, whereas
197    * the SVG language definition says that {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
198    * is not animated. Because the SVG language definition states that {@link
199    * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
200    * cannot be animated, the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getAnimVal()}
201    * will always be the same as the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getBaseVal()}.
202    */
203   public final OMSVGAnimatedBoolean getExternalResourcesRequired() {
204     return ((SVGAnimationElement)ot).getExternalResourcesRequired();
205   }
206 
207   // Implementation of the svg::SVGTests W3C IDL interface
208   /**
209    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredFeatures()}
210    * on the given element.
211    */
212   public final OMSVGStringList getRequiredFeatures() {
213     return ((SVGAnimationElement)ot).getRequiredFeatures();
214   }
215   /**
216    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredExtensions()}
217    * on the given element.
218    */
219   public final OMSVGStringList getRequiredExtensions() {
220     return ((SVGAnimationElement)ot).getRequiredExtensions();
221   }
222   /**
223    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getSystemLanguage()}
224    * on the given element.
225    */
226   public final OMSVGStringList getSystemLanguage() {
227     return ((SVGAnimationElement)ot).getSystemLanguage();
228   }
229   /**
230    * Returns true if the user agent supports the given extension, specified
231    * by a URI.
232    * @param extension The name of the extension, expressed as a URI.
233    * @return True or false, depending on whether the given extension is   supported.
234    */
235   public final boolean hasExtension(String extension) {
236     return ((SVGAnimationElement)ot).hasExtension(extension);
237   }
238 
239   @Override
240   public final HandlerRegistration addClickHandler(ClickHandler handler) {
241     return addDomHandler(handler, ClickEvent.getType());
242   }
243   @Override
244   public final HandlerRegistration addDragEndHandler(DragEndHandler handler) {
245     return addDomHandler(handler, DragEndEvent.getType());
246   }
247   @Override
248   public final HandlerRegistration addDragEnterHandler(DragEnterHandler handler) {
249     return addDomHandler(handler, DragEnterEvent.getType());
250   }
251   @Override
252   public final HandlerRegistration addDragHandler(DragHandler handler) {
253     return addDomHandler(handler, DragEvent.getType());
254   }
255   @Override
256   public final HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) {
257     return addDomHandler(handler, DragLeaveEvent.getType());
258   }
259   @Override
260   public final HandlerRegistration addDragOverHandler(DragOverHandler handler) {
261     return addDomHandler(handler, DragOverEvent.getType());
262   }
263   @Override
264   public final HandlerRegistration addDragStartHandler(DragStartHandler handler) {
265     return addDomHandler(handler, DragStartEvent.getType());
266   }
267   @Override
268   public final HandlerRegistration addDropHandler(DropHandler handler) {
269     return addDomHandler(handler, DropEvent.getType());
270   }
271   @Override
272   public final HandlerRegistration addLoadHandler(LoadHandler handler) {
273     return addDomHandler(handler, LoadEvent.getType());
274   }
275   @Override
276   public final HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
277     return addDomHandler(handler, MouseDownEvent.getType());
278   }
279   @Override
280   public final HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
281     return addDomHandler(handler, MouseMoveEvent.getType());
282   }
283   @Override
284   public final HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
285     return addDomHandler(handler, MouseOutEvent.getType());
286   }
287   @Override
288   public final HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
289     return addDomHandler(handler, MouseOverEvent.getType());
290   }
291   @Override
292   public final HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
293     return addDomHandler(handler, MouseUpEvent.getType());
294   }
295   @Override
296   public final HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
297     return addDomHandler(handler, TouchCancelEvent.getType());
298   }
299   @Override
300   public final HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
301     return addDomHandler(handler, TouchEndEvent.getType());
302   }
303   @Override
304   public final HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
305     return addDomHandler(handler, TouchMoveEvent.getType());
306   }
307   @Override
308   public final HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
309     return addDomHandler(handler, TouchStartEvent.getType());
310   }
311   @Override
312   public final HandlerRegistration addActivateHandler(ActivateHandler handler) {
313     return addDomHandler(handler, ActivateEvent.getType());
314   }
315   @Override
316   public final HandlerRegistration addBeginHandler(BeginHandler handler) {
317     return addDomHandler(handler, BeginEvent.getType());
318   }
319   @Override
320   public final HandlerRegistration addEndHandler(EndHandler handler) {
321     return addDomHandler(handler, EndEvent.getType());
322   }
323   @Override
324   public final HandlerRegistration addFocusInHandler(FocusInHandler handler) {
325     return addDomHandler(handler, FocusInEvent.getType());
326   }
327   @Override
328   public final HandlerRegistration addFocusOutHandler(FocusOutHandler handler) {
329     return addDomHandler(handler, FocusOutEvent.getType());
330   }
331   @Override
332   public final HandlerRegistration addRepeatHandler(RepeatHandler handler) {
333     return addDomHandler(handler, RepeatEvent.getType());
334   }
335 }