001: /**
002: * org/ozone-db/xml/dom/html/HTMLTableRowElementImpl.java
003: *
004: * The contents of this file are subject to the OpenXML Public
005: * License Version 1.0; you may not use this file except in compliance
006: * with the License. You may obtain a copy of the License at
007: * http://www.openxml.org/license.html
008: *
009: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
010: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
011: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
012: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
013: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
014: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
015: *
016: * The Initial Developer of this code under the License is Assaf Arkin.
017: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
018: * All Rights Reserved.
019: */package org.ozoneDB.xml.dom.html;
020:
021: import org.ozoneDB.xml.dom.*;
022: import org.w3c.dom.*;
023: import org.w3c.dom.html.*;
024:
025: /**
026: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
027: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
028: * @see org.w3c.dom.html.HTMLTableRowElement
029: * @see ElementImpl
030: */
031: public final class HTMLTableRowElementImpl extends HTMLElementImpl
032: implements HTMLTableRowElement {
033:
034: public int getRowIndex() {
035: Node parent;
036:
037: parent = getParentNode();
038: if (parent instanceof HTMLTableSectionElement) {
039: parent = parent.getParentNode();
040: }
041: if (parent instanceof HTMLTableElement) {
042: return getRowIndex(parent);
043: }
044: ;
045: return -1;
046: }
047:
048: public void setRowIndex(int rowIndex) {
049: Node parent;
050:
051: parent = getParentNode();
052: if (parent instanceof HTMLTableSectionElement) {
053: parent = parent.getParentNode();
054: }
055: if (parent instanceof HTMLTableElement) {
056: ((HTMLTableElementImpl) parent).insertRowX(rowIndex, this );
057: }
058: }
059:
060: public int getSectionRowIndex() {
061: Node parent;
062:
063: parent = getParentNode();
064: if (parent instanceof HTMLTableSectionElement) {
065: return getRowIndex(parent);
066: } else {
067: return -1;
068: }
069: }
070:
071: public void setSectionRowIndex(int sectionRowIndex) {
072: Node parent;
073:
074: parent = getParentNode();
075: if (parent instanceof HTMLTableSectionElement) {
076: ((HTMLTableSectionElementImpl) parent).insertRowX(
077: sectionRowIndex, this );
078: }
079: }
080:
081: int getRowIndex(Node parent) {
082: NodeList rows;
083: int i;
084:
085: // Use getElementsByTagName() which creates a snapshot of all the
086: // TR elements under the TABLE/section. Access to the returned NodeList
087: // is very fast and the snapshot solves many synchronization problems.
088: rows = ((HTMLElement) parent).getElementsByTagName("TR");
089: for (i = 0; i < rows.getLength(); ++i) {
090: if (rows.item(i) == this ) {
091: return i;
092: }
093: }
094: return -1;
095: }
096:
097: public HTMLCollection getCells() {
098: if (_cells == null) {
099: _cells = new HTMLCollectionImpl(this ,
100: HTMLCollectionImpl.CELL);
101: }
102: return _cells;
103: }
104:
105: public void setCells(HTMLCollection cells) {
106: Node child;
107: int i;
108:
109: child = getFirstChild();
110: while (child != null) {
111: removeChild(child);
112: child = child.getNextSibling();
113: }
114: i = 0;
115: child = cells.item(i);
116: while (child != null) {
117: appendChild(child);
118: ++i;
119: child = cells.item(i);
120: }
121: }
122:
123: public HTMLElement insertCell(int index) {
124: Node child;
125: HTMLElement newCell;
126:
127: newCell = new HTMLTableCellElementImpl(
128: (HTMLDocumentImpl) getOwnerDocument(), "TD");
129: child = getFirstChild();
130: while (child != null) {
131: if (child instanceof HTMLTableCellElement) {
132: if (index == 0) {
133: insertBefore(newCell, child);
134: return newCell;
135: }
136: --index;
137: }
138: child = child.getNextSibling();
139: }
140: appendChild(newCell);
141: return newCell;
142: }
143:
144: public void deleteCell(int index) {
145: Node child;
146:
147: child = getFirstChild();
148: while (child != null) {
149: if (child instanceof HTMLTableCellElement) {
150: if (index == 0) {
151: removeChild(child);
152: return;
153: }
154: --index;
155: }
156: child = child.getNextSibling();
157: }
158: }
159:
160: public String getAlign() {
161: return capitalize(getAttribute("align"));
162: }
163:
164: public void setAlign(String align) {
165: setAttribute("align", align);
166: }
167:
168: public String getBgColor() {
169: return getAttribute("bgcolor");
170: }
171:
172: public void setBgColor(String bgColor) {
173: setAttribute("bgcolor", bgColor);
174: }
175:
176: public String getCh() {
177: String ch;
178:
179: // Make sure that the access key is a single character.
180: ch = getAttribute("char");
181: if (ch != null && ch.length() > 1) {
182: ch = ch.substring(0, 1);
183: }
184: return ch;
185: }
186:
187: public void setCh(String ch) {
188: // Make sure that the access key is a single character.
189: if (ch != null && ch.length() > 1) {
190: ch = ch.substring(0, 1);
191: }
192: setAttribute("char", ch);
193: }
194:
195: public String getChOff() {
196: return getAttribute("charoff");
197: }
198:
199: public void setChOff(String chOff) {
200: setAttribute("charoff", chOff);
201: }
202:
203: public String getVAlign() {
204: return capitalize(getAttribute("valign"));
205: }
206:
207: public void setVAlign(String vAlign) {
208: setAttribute("valign", vAlign);
209: }
210:
211: /**
212: * Constructor requires owner document.
213: *
214: * @param owner The owner HTML document
215: */
216: public HTMLTableRowElementImpl(HTMLDocumentImpl owner, String name) {
217: super (owner, "TR");
218: }
219:
220: HTMLCollection _cells;
221:
222: }
|