View Javadoc

1   /**********************************************
2    * Copyright (C) 2010 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 java.util.Iterator;
33  
34  import com.google.gwt.core.client.JavaScriptException;
35  import com.google.gwt.core.client.JavaScriptObject;
36  
37  /**
38   * <p>This interface defines a list of SVGLength objects.</p> <p>{@link org.vectomatic.dom.svg.OMSVGLengthList}
39   * has the same attributes and methods as other SVGxxxList interfaces. Implementers
40   * may consider using a single base class to implement the various SVGxxxList
41   * interfaces.</p> <p id="ReadOnlyLengthList">An {@link org.vectomatic.dom.svg.OMSVGLengthList}
42   * object can be designated as <em>read only</em>, which means that attempts
43   * to modify the object will result in an exception being thrown, as described
44   * below.</p>
45   */
46  public class OMSVGLengthList implements Iterable<OMSVGLength> {
47    private JavaScriptObject ot;
48    protected OMSVGLengthList(JavaScriptObject ot) {
49      this.ot = ot;
50    }
51  
52    // Implementation of the svg::SVGLengthList W3C IDL interface
53    /**
54     * The number of items in the list.
55     */
56    public final native int getNumberOfItems() /*-{
57      return this.@org.vectomatic.dom.svg.OMSVGLengthList::ot.numberOfItems;
58    }-*/;
59    /**
60     * Clears all existing current items from the list, with the result being
61     * an empty list.
62     * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list
63     * corresponds to a <a href="svgdom.html#ReadOnlyNodes">read only attribute</a>
64     * or when the object itself is   <a href="#ReadOnlyLengthList">read only</a>.
65     */
66    public final native void clear() throws JavaScriptException /*-{
67      this.@org.vectomatic.dom.svg.OMSVGLengthList::ot.clear();
68    }-*/;
69    /**
70     * Clears all existing current items from the list and re-initializes the
71     * list to hold the single item specified by the parameter.  If the inserted
72     * item is already in a list, it is removed from its previous list before
73     * it is inserted into this list.  The inserted item is the item itself and
74     * not a copy.
75     * @param newItem The item which should become the only member of the list.
76     * @return The item being inserted into the list.
77     * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list
78     * corresponds to a <a href="svgdom.html#ReadOnlyNodes">read only attribute</a>
79     * or when the object itself is   <a href="#ReadOnlyLengthList">read only</a>.
80     */
81    public final native OMSVGLength initialize(OMSVGLength newItem) throws JavaScriptException /*-{
82      return this.@org.vectomatic.dom.svg.OMSVGLengthList::ot.initialize(newItem);
83    }-*/;
84    /**
85     * Returns the specified item from the list.  The returned item is the item
86     * itself and not a copy.  Any changes made to the item are immediately reflected
87     * in the list.
88     * @param index The index of the item from the list which is to be   returned.
89     * The first item is number 0.
90     * @return The selected item.
91     * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list
92     * corresponds to a <a href="svgdom.html#ReadOnlyNodes">read only attribute</a>
93     * or when the object itself is   <a href="#ReadOnlyLengthList">read only</a>.
94     */
95    public final native OMSVGLength getItem(int index) throws JavaScriptException /*-{
96      return this.@org.vectomatic.dom.svg.OMSVGLengthList::ot.getItem(index);
97    }-*/;
98    /**
99     * Inserts a new item into the list at the specified position. The first item
100    * is number 0. If <var>newItem</var> is already in a list, it is removed
101    * from its previous list before it is inserted into this list. The inserted
102    * item is the item itself and not a copy. If the item is already in this
103    * list, note that the index of the item to insert before is <i>before</i>
104    * the removal of the item.
105    * @param newItem The item which is to be inserted into the list.
106    * @param index The index of the item before which the new item is to be 
107    * inserted. The first item is number 0.  If the index is equal to 0,   then
108    * the new item is inserted at the front of the list. If the index   is greater
109    * than or equal to {@link org.vectomatic.dom.svg.OMSVGLengthList#getNumberOfItems()},
110    * then the new item is   appended to the end of the list.
111    * @return The inserted item.
112    * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list
113    * corresponds to a <a href="svgdom.html#ReadOnlyNodes">read only attribute</a>
114    * or when the object itself is   <a href="#ReadOnlyLengthList">read only</a>.
115    */
116   public final native OMSVGLength insertItemBefore(OMSVGLength newItem, int index) throws JavaScriptException /*-{
117     return this.@org.vectomatic.dom.svg.OMSVGLengthList::ot.insertItemBefore(newItem, index);
118   }-*/;
119   /**
120    * Replaces an existing item in the list with a new item. If <var>newItem</var>
121    * is already in a list, it is removed from its previous list before it is
122    * inserted into this list.  The inserted item is the item itself and not
123    * a copy.  If the item is already in this list, note that the index of the
124    * item to replace is <i>before</i> the removal of the item.
125    * @param newItem The item which is to be inserted into the list.
126    * @param index The index of the item which is to be replaced. The first 
127    * item is number 0.
128    * @return The inserted item.
129    * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list
130    * corresponds to a <a href="svgdom.html#ReadOnlyNodes">read only attribute</a>
131    * or when the object itself is   <a href="#ReadOnlyLengthList">read only</a>.
132    * @throws DOMException(INDEX_SIZE_ERR) Raised if the index number is   greater
133    * than or equal to {@link org.vectomatic.dom.svg.OMSVGLengthList#getNumberOfItems()}.
134    */
135   public final native OMSVGLength replaceItem(OMSVGLength newItem, int index) throws JavaScriptException /*-{
136     return this.@org.vectomatic.dom.svg.OMSVGLengthList::ot.replaceItem(newItem, index);
137   }-*/;
138   /**
139    * Removes an existing item from the list.
140    * @param index The index of the item which is to be removed. The first  
141    * item is number 0.
142    * @return The removed item.
143    * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list
144    * corresponds to a <a href="svgdom.html#ReadOnlyNodes">read only attribute</a>
145    * or when the object itself is   <a href="#ReadOnlyLengthList">read only</a>.
146    * @throws DOMException(INDEX_SIZE_ERR) Raised if the index number is   greater
147    * than or equal to {@link org.vectomatic.dom.svg.OMSVGLengthList#getNumberOfItems()}.
148    */
149   public final native OMSVGLength removeItem(int index) /*-{
150     return this.@org.vectomatic.dom.svg.OMSVGLengthList::ot.removeItem(index);
151   }-*/;
152   /**
153    * Inserts a new item at the end of the list. If <var>newItem</var> is already
154    * in a list, it is removed from its previous list before it is inserted into
155    * this list.  The inserted item is the item itself and not a copy.
156    * @param newItem The item which is to be inserted. The first item is   number
157    * 0.
158    * @return The inserted item.
159    * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list
160    * corresponds to a <a href="svgdom.html#ReadOnlyNodes">read only attribute</a>
161    * or when the object itself is   <a href="#ReadOnlyLengthList">read only</a>.
162    */
163    public final native OMSVGLength appendItem(OMSVGLength newItem) throws JavaScriptException /*-{
164     return this.@org.vectomatic.dom.svg.OMSVGLengthList::ot.appendItem(newItem);
165   }-*/;
166 
167   /**
168    * Returns an iterator over the {@link org.vectomatic.dom.svg.OMSVGLength}
169    * elements in this list in proper sequence.
170    *
171    * <p>This implementation returns a straightforward implementation of the
172    * iterator interface, relying on the backing list's {@code getNumberOfItems()},
173    * and {@code getItem(int)} methods.
174    *
175    * <p>Note that the iterator returned by this method will throw an
176    * {@code UnsupportedOperationException} in response to its
177    * {@code remove} method.
178    *
179    * @return an iterator over the {@link org.vectomatic.dom.svg.OMSVGLength}
180    * elements in this list in proper sequence
181    */
182   @Override
183   public final Iterator<OMSVGLength> iterator() {
184 	return new Iterator<OMSVGLength>() {
185 		private int index;
186 		@Override
187 		public boolean hasNext() {
188 			return index < getNumberOfItems();
189 		}
190 
191 		@Override
192 		public OMSVGLength next() {
193 			return getItem(index++);
194 		}
195 
196 		@Override
197 		public void remove() {
198 			throw new UnsupportedOperationException();
199 		}
200 	};
201   }
202 }