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