/** * Notifies the parent list that this item has changed. This also * discards the cached representation of the item. */ protected void resetAttribute() { if (parent != null) { itemStringValue = null; parent.itemChanged(); } }
/** * Removes all items from the list. * @exception DOMException NO_MODIFICATION_ALLOWED_ERR: * Raised when the list cannot be modified. */ public void clear() throws DOMException { revalidate(); if (itemList != null) { // Remove all the items. clear(itemList); // Set the DOM attribute. resetAttribute(); } }
/** * Appends the string representation of the given {@link SVGItem} to * the DOM attribute. This is called in response to an append to * the list. */ protected void resetAttribute(SVGItem item) { String newValue = getValueAsString() + getItemSeparator() + item.getValueAsString(); setAttributeValue( newValue ); valid = true; }
/** * Inserts a new item at the end of the list. * If newItem is already in a list, it is removed from its previous list * before it is inserted into this list. * * @param newItem The item which is to be inserted into the list. The * first item is number 0. * @return The inserted item. * @exception DOMException NO_MODIFICATION_ALLOWED_ERR: * Raised when the list cannot be modified. * @exception SVGException SVG_WRONG_TYPE_ERR: * Raised if parameter newItem is the wrong type of object for the given * list. */ protected SVGItem appendItemImpl(Object newItem) throws DOMException, SVGException { checkItemType(newItem); revalidate(); SVGItem item = removeIfNeeded(newItem); itemList.add(item); // Set the item's parent. item.setParent(this); if (itemList.size() <= 1) { resetAttribute(); } else { resetAttribute(item); } return item; }
/** * Removes all items from the list and adds the specified item to * the list. * * @param newItem the item which should become the only member of the list. * @return the item being inserted into the list. * @exception DOMException NO_MODIFICATION_ALLOWED_ERR: * Raised when the list cannot be modified. * @exception SVGException SVG_WRONG_TYPE_ERR: * Raised if parameter newItem is the wrong type of object for the given * list. */ protected SVGItem initializeImpl(Object newItem) throws DOMException, SVGException { checkItemType(newItem); // Clear the list, creating it if it doesn't exist yet. if (itemList == null) { itemList = new ArrayList(1); } else { clear(itemList); } SVGItem item = removeIfNeeded(newItem); // Add the item. itemList.add(item); // Set the item's parent. item.setParent(this); // Update the DOM attribute. resetAttribute(); return item; }
/** * Initializes the list, if needed. */ protected void revalidate() { if (valid) { return; } try { ListBuilder builder = new ListBuilder(this); doParse(getValueAsString(), builder); List parsedList = builder.getList(); if (parsedList != null) { clear(itemList); } itemList = parsedList; } catch (ParseException e) { itemList = null; } valid = true; }
/** * Removes an existing item from the list. * * @param index The index of the item which * is to be removed. The first item is number 0. * @return The removed item. * @exception DOMException NO_MODIFICATION_ALLOWED_ERR: * Raised when the list cannot be modified. * @exception DOMException INDEX_SIZE_ERR: * Raised if the index number is negative or greater * than or equal to <code>numberOfItems</code>. */ protected SVGItem removeItemImpl(int index) throws DOMException { revalidate(); if (index < 0 || index >= itemList.size()) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", new Object[] { new Integer(index) } ); } SVGItem item = (SVGItem)itemList.remove(index); // Set the item to have no parent list. item.setParent(null); // Reset the DOM attribute. resetAttribute(); return item; }
/** * Returns the item from the list at the specified index. * * @param index The index of the item from the list which is to be returned. * The first item is number 0. * @return The selected item. * @exception DOMException INDEX_SIZE_ERR: * Raised if the index number is negative or greater than or equal to * <code>numberOfItems</code>. */ protected SVGItem getItemImpl(int index) throws DOMException { revalidate(); if (index < 0 || itemList == null || index >= itemList.size()) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", new Object[] {index} ); } return (SVGItem)itemList.get(index); }
/** * Sets the DOM attribute value to be the string representation of the * given list. */ protected void setValueAsString(List value) throws DOMException { String finalValue = null; Iterator it = value.iterator(); if (it.hasNext()) { SVGItem item = (SVGItem) it.next(); StringBuffer buf = new StringBuffer( value.size() * 8 ); buf.append( item.getValueAsString() ); while (it.hasNext()) { item = (SVGItem) it.next(); buf.append(getItemSeparator()); buf.append(item.getValueAsString()); } finalValue = buf.toString(); } setAttributeValue(finalValue); valid = true; }
/** * Removes the specified object from its parent list if it is an item, or * creates a new item if the specified object is not an item. * * @param newItem an instance of {@link SVGItem} to remove from its parent * list, or an SVG object for which a new {@link SVGItem} should be * created * @return item the {@link SVGItem} just removed from its parent list, or * the newly created {@link SVGItem} */ protected SVGItem removeIfNeeded(Object newItem) { SVGItem item; if (newItem instanceof SVGItem) { // This is an existing item, so remove it from its parent list. item = (SVGItem)newItem; if (item.getParent() != null) { item.getParent().removeItem(item); } } else { // This must be an SVG object, so create a new SVGItem from it. item = createSVGItem(newItem); } return item; }
/** * Inserts a new item at the end of the list. * If newItem is already in a list, it is removed from its previous list * before it is inserted into this list. * * @param newItem The item which is to be inserted into the list. The * first item is number 0. * @return The inserted item. * @exception DOMException NO_MODIFICATION_ALLOWED_ERR: * Raised when the list cannot be modified. * @exception SVGException SVG_WRONG_TYPE_ERR: * Raised if parameter newItem is the wrong type of object for the given * list. */ protected SVGItem appendItemImpl(Object newItem) throws DOMException, SVGException { checkItemType(newItem); revalidate(); SVGItem item = removeIfNeeded(newItem); itemList.add(item); // Set the item's parent. item.setParent(this); if (itemList.size() <= 1) { resetAttribute(); } else { resetAttribute(item); } return item; }
/** * Removes all items from the list and adds the specified item to * the list. * * @param newItem the item which should become the only member of the list. * @return the item being inserted into the list. * @exception DOMException NO_MODIFICATION_ALLOWED_ERR: * Raised when the list cannot be modified. * @exception SVGException SVG_WRONG_TYPE_ERR: * Raised if parameter newItem is the wrong type of object for the given * list. */ protected SVGItem initializeImpl(Object newItem) throws DOMException, SVGException { checkItemType(newItem); // Clear the list, creating it if it doesn't exist yet. if (itemList == null) { itemList = new ArrayList(1); } else { clear(itemList); } SVGItem item = removeIfNeeded(newItem); // Add the item. itemList.add(item); // Set the item's parent. item.setParent(this); // Update the DOM attribute. resetAttribute(); return item; }
/** * Initializes the list, if needed. */ protected void revalidate() { if (valid) { return; } try { ListBuilder builder = new ListBuilder(this); doParse(getValueAsString(), builder); List parsedList = builder.getList(); if (parsedList != null) { clear(itemList); } itemList = parsedList; } catch (ParseException e) { itemList = null; } valid = true; }
/** * Removes an existing item from the list. * * @param index The index of the item which * is to be removed. The first item is number 0. * @return The removed item. * @exception DOMException NO_MODIFICATION_ALLOWED_ERR: * Raised when the list cannot be modified. * @exception DOMException INDEX_SIZE_ERR: * Raised if the index number is negative or greater * than or equal to <code>numberOfItems</code>. */ protected SVGItem removeItemImpl(int index) throws DOMException { revalidate(); if (index < 0 || index >= itemList.size()) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", new Object[] {index} ); } SVGItem item = (SVGItem)itemList.remove(index); // Set the item to have no parent list. item.setParent(null); // Reset the DOM attribute. resetAttribute(); return item; }
/** * Returns the item from the list at the specified index. * * @param index The index of the item from the list which is to be returned. * The first item is number 0. * @return The selected item. * @exception DOMException INDEX_SIZE_ERR: * Raised if the index number is negative or greater than or equal to * <code>numberOfItems</code>. */ protected SVGItem getItemImpl(int index) throws DOMException { revalidate(); if (index < 0 || itemList == null || index >= itemList.size()) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", new Object[] { new Integer(index) } ); } return (SVGItem)itemList.get(index); }
/** * Sets the DOM attribute value to be the string representation of the * given list. */ protected void setValueAsString(List value) throws DOMException { String finalValue = null; Iterator it = value.iterator(); if (it.hasNext()) { SVGItem item = (SVGItem) it.next(); StringBuffer buf = new StringBuffer( value.size() * 8 ); buf.append( item.getValueAsString() ); while (it.hasNext()) { item = (SVGItem) it.next(); buf.append(getItemSeparator()); buf.append(item.getValueAsString()); } finalValue = buf.toString(); } setAttributeValue(finalValue); valid = true; }
/** * Removes the specified object from its parent list if it is an item, or * creates a new item if the specified object is not an item. * * @param newItem an instance of {@link SVGItem} to remove from its parent * list, or an SVG object for which a new {@link SVGItem} should be * created * @return item the {@link SVGItem} just removed from its parent list, or * the newly created {@link SVGItem} */ protected SVGItem removeIfNeeded(Object newItem) { SVGItem item; if (newItem instanceof SVGItem) { // This is an existing item, so remove it from its parent list. item = (SVGItem)newItem; if (item.getParent() != null) { item.getParent().removeItem(item); } } else { // This must be an SVG object, so create a new SVGItem from it. item = createSVGItem(newItem); } return item; }
throws DOMException, SVGException { checkItemType(newItem); revalidate(); if (index < 0 || index >= itemList.size()) { throw createDOMException (DOMException.INDEX_SIZE_ERR, "index.out.of.bounds", new Object[] {index} ); SVGItem item = removeIfNeeded(newItem); resetAttribute();
/** * Notifies the parent list that this item has changed. */ protected void reset() { if (parentList != null) { parentList.itemChanged(); } } }
/** * Appends the string representation of the given {@link SVGItem} to * the DOM attribute. This is called in response to an append to * the list. */ protected void resetAttribute(SVGItem item) { String newValue = getValueAsString() + getItemSeparator() + item.getValueAsString(); setAttributeValue( newValue ); valid = true; }