001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057: package org.apache.html.dom;
058:
059: import org.w3c.dom.*;
060: import org.w3c.dom.html.*;
061:
062: /**
063: * @version $Revision: 1.4 $ $Date: 2001/01/30 23:58:05 $
064: * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
065: * @see org.w3c.dom.html.HTMLTableRowElement
066: * @see ElementImpl
067: */
068: public class HTMLTableRowElementImpl extends HTMLElementImpl implements
069: HTMLTableRowElement {
070:
071: public int getRowIndex() {
072: Node parent;
073:
074: parent = getParentNode();
075: if (parent instanceof HTMLTableSectionElement)
076: parent = parent.getParentNode();
077: if (parent instanceof HTMLTableElement)
078: return getRowIndex(parent);
079: ;
080: return -1;
081: }
082:
083: public void setRowIndex(int rowIndex) {
084: Node parent;
085:
086: parent = getParentNode();
087: if (parent instanceof HTMLTableSectionElement)
088: parent = parent.getParentNode();
089: if (parent instanceof HTMLTableElement)
090: ((HTMLTableElementImpl) parent).insertRowX(rowIndex, this );
091: }
092:
093: public int getSectionRowIndex() {
094: Node parent;
095:
096: parent = getParentNode();
097: if (parent instanceof HTMLTableSectionElement)
098: return getRowIndex(parent);
099: else
100: return -1;
101: }
102:
103: public void setSectionRowIndex(int sectionRowIndex) {
104: Node parent;
105:
106: parent = getParentNode();
107: if (parent instanceof HTMLTableSectionElement)
108: ((HTMLTableSectionElementImpl) parent).insertRowX(
109: sectionRowIndex, this );
110: }
111:
112: int getRowIndex(Node parent) {
113: NodeList rows;
114: int i;
115:
116: // Use getElementsByTagName() which creates a snapshot of all the
117: // TR elements under the TABLE/section. Access to the returned NodeList
118: // is very fast and the snapshot solves many synchronization problems.
119: rows = ((HTMLElement) parent).getElementsByTagName("TR");
120: for (i = 0; i < rows.getLength(); ++i)
121: if (rows.item(i) == this )
122: return i;
123: return -1;
124: }
125:
126: public HTMLCollection getCells() {
127: if (_cells == null)
128: _cells = new HTMLCollectionImpl(this ,
129: HTMLCollectionImpl.CELL);
130: return _cells;
131: }
132:
133: public void setCells(HTMLCollection cells) {
134: Node child;
135: int i;
136:
137: child = getFirstChild();
138: while (child != null) {
139: removeChild(child);
140: child = child.getNextSibling();
141: }
142: i = 0;
143: child = cells.item(i);
144: while (child != null) {
145: appendChild(child);
146: ++i;
147: child = cells.item(i);
148: }
149: }
150:
151: public HTMLElement insertCell(int index) {
152: Node child;
153: HTMLElement newCell;
154:
155: newCell = new HTMLTableCellElementImpl(
156: (HTMLDocumentImpl) getOwnerDocument(), "TD");
157: child = getFirstChild();
158: while (child != null) {
159: if (child instanceof HTMLTableCellElement) {
160: if (index == 0) {
161: insertBefore(newCell, child);
162: return newCell;
163: }
164: --index;
165: }
166: child = child.getNextSibling();
167: }
168: appendChild(newCell);
169: return newCell;
170: }
171:
172: public void deleteCell(int index) {
173: Node child;
174:
175: child = getFirstChild();
176: while (child != null) {
177: if (child instanceof HTMLTableCellElement) {
178: if (index == 0) {
179: removeChild(child);
180: return;
181: }
182: --index;
183: }
184: child = child.getNextSibling();
185: }
186: }
187:
188: public String getAlign() {
189: return capitalize(getAttribute("align"));
190: }
191:
192: public void setAlign(String align) {
193: setAttribute("align", align);
194: }
195:
196: public String getBgColor() {
197: return getAttribute("bgcolor");
198: }
199:
200: public void setBgColor(String bgColor) {
201: setAttribute("bgcolor", bgColor);
202: }
203:
204: public String getCh() {
205: String ch;
206:
207: // Make sure that the access key is a single character.
208: ch = getAttribute("char");
209: if (ch != null && ch.length() > 1)
210: ch = ch.substring(0, 1);
211: return ch;
212: }
213:
214: public void setCh(String ch) {
215: // Make sure that the access key is a single character.
216: if (ch != null && ch.length() > 1)
217: ch = ch.substring(0, 1);
218: setAttribute("char", ch);
219: }
220:
221: public String getChOff() {
222: return getAttribute("charoff");
223: }
224:
225: public void setChOff(String chOff) {
226: setAttribute("charoff", chOff);
227: }
228:
229: public String getVAlign() {
230: return capitalize(getAttribute("valign"));
231: }
232:
233: public void setVAlign(String vAlign) {
234: setAttribute("valign", vAlign);
235: }
236:
237: /**
238: * Constructor requires owner document.
239: *
240: * @param owner The owner HTML document
241: */
242: public HTMLTableRowElementImpl(HTMLDocumentImpl owner, String name) {
243: super (owner, name);
244: }
245:
246: HTMLCollection _cells;
247:
248: }
|