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