001/********************************************** 002 * Copyright (C) 2010 Lukas Laag 003 * This file is part of lib-gwt-svg. 004 * 005 * libgwtsvg is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * libgwtsvg is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/ 017 **********************************************/ 018/* 019 * Copyright (c) 2004 World Wide Web Consortium, 020 * 021 * (Massachusetts Institute of Technology, European Research Consortium for 022 * Informatics and Mathematics, Keio University). All Rights Reserved. This 023 * work is distributed under the W3C(r) Software License [1] in the hope that 024 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 025 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 026 * 027 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 028 */ 029 030package org.vectomatic.dom.svg; 031 032import java.util.Iterator; 033 034import com.google.gwt.core.client.JavaScriptException; 035import com.google.gwt.core.client.JavaScriptObject; 036 037/** 038 * <p>This interface defines a list of SVGPathSeg objects.</p> <p>{@link org.vectomatic.dom.svg.OMSVGPathSegList} 039 * has the same attributes and methods as other SVGxxxList interfaces. Implementers 040 * may consider using a single base class to implement the various SVGxxxList 041 * interfaces.</p> 042 */ 043public class OMSVGPathSegList implements Iterable<OMSVGPathSeg> { 044 private JavaScriptObject ot; 045 protected OMSVGPathSegList(JavaScriptObject ot) { 046 this.ot = ot; 047 } 048 049 // Implementation of the svg::SVGPathSegList W3C IDL interface 050 /** 051 * The number of items in the list. 052 */ 053 public final native int getNumberOfItems() /*-{ 054 return this.@org.vectomatic.dom.svg.OMSVGPathSegList::ot.numberOfItems; 055 }-*/; 056 /** 057 * Clears all existing current items from the list, with the result being 058 * an empty list. 059 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list 060 * cannot be modified. 061 */ 062 public final native void clear() throws JavaScriptException /*-{ 063 this.@org.vectomatic.dom.svg.OMSVGPathSegList::ot.clear(); 064 }-*/; 065 /** 066 * Clears all existing current items from the list and re-initializes the 067 * list to hold the single item specified by the parameter. If the inserted 068 * item is already in a list, it is removed from its previous list before 069 * it is inserted into this list. The inserted item is the item itself and 070 * not a copy. 071 * @param newItem The item which should become the only member of the list. 072 * @return The item being inserted into the list. 073 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised when the list 074 * cannot be modified. 075 */ 076 public final native OMSVGPathSeg initialize(OMSVGPathSeg newItem) throws JavaScriptException /*-{ 077 return this.@org.vectomatic.dom.svg.OMSVGPathSegList::ot.initialize(newItem); 078 }-*/; 079 /** 080 * Returns the specified item from the list. The returned item is the item 081 * itself and not a copy. Any changes made to the item are immediately reflected 082 * in the list. 083 * @param index The index of the item from the list which is to be returned. 084 * The first item is number 0. 085 * @return The selected item. 086 * @throws DOMException(INDEX_SIZE_ERR) Raised if the index number is greater 087 * than or equal to {@link org.vectomatic.dom.svg.OMSVGPathSegList#getNumberOfItems()}. 088 */ 089 public final native OMSVGPathSeg getItem(int index) throws JavaScriptException /*-{ 090 return this.@org.vectomatic.dom.svg.OMSVGPathSegList::ot.getItem(index); 091 }-*/; 092 /** 093 * Inserts a new item into the list at the specified position. The first item 094 * is number 0. If <var>newItem</var> is already in a list, it is removed 095 * from its previous list before it is inserted into this list. The inserted 096 * item is the item itself and not a copy. If the item is already in this 097 * list, note that the index of the item to insert before is <i>before</i> 098 * the removal of the item. 099 * @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.OMSVGPathSegList#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 OMSVGPathSeg insertItemBefore(OMSVGPathSeg newItem, int index) throws JavaScriptException /*-{ 110 return this.@org.vectomatic.dom.svg.OMSVGPathSegList::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.OMSVGPathSegList#getNumberOfItems()}. 126 */ 127 public final native OMSVGPathSeg replaceItem(OMSVGPathSeg newItem, int index) throws JavaScriptException /*-{ 128 return this.@org.vectomatic.dom.svg.OMSVGPathSegList::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.OMSVGPathSegList#getNumberOfItems()}. 139 */ 140 public final native OMSVGPathSeg removeItem(int index) throws JavaScriptException /*-{ 141 return this.@org.vectomatic.dom.svg.OMSVGPathSegList::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 OMSVGPathSeg appendItem(OMSVGPathSeg newItem) throws JavaScriptException /*-{ 154 return this.@org.vectomatic.dom.svg.OMSVGPathSegList::ot.appendItem(newItem); 155 }-*/; 156 157 /** 158 * Returns an iterator over the {@link org.vectomatic.dom.svg.OMSVGPathSeg} 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.OMSVGPathSeg} 170 * elements in this list in proper sequence 171 */ 172 @Override 173 public final Iterator<OMSVGPathSeg> iterator() { 174 return new Iterator<OMSVGPathSeg>() { 175 private int index; 176 @Override 177 public boolean hasNext() { 178 return index < getNumberOfItems(); 179 } 180 181 @Override 182 public OMSVGPathSeg next() { 183 return getItem(index++); 184 } 185 186 @Override 187 public void remove() { 188 throw new UnsupportedOperationException(); 189 } 190 }; 191 } 192}