001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hwpf.usermodel;
019:
020: import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
021:
022: public class TableRow extends Paragraph {
023: private final static char TABLE_CELL_MARK = '\u0007';
024:
025: private final static short SPRM_TJC = 0x5400;
026: private final static short SPRM_DXAGAPHALF = (short) 0x9602;
027: private final static short SPRM_FCANTSPLIT = 0x3403;
028: private final static short SPRM_FTABLEHEADER = 0x3404;
029: private final static short SPRM_DYAROWHEIGHT = (short) 0x9407;
030:
031: int _levelNum;
032: private TableProperties _tprops;
033: private TableCell[] _cells;
034:
035: public TableRow(int startIdx, int endIdx, Table parent, int levelNum) {
036: super (startIdx, endIdx, parent);
037:
038: _tprops = TableSprmUncompressor.uncompressTAP(_papx
039: .toByteArray(), 2);
040: _levelNum = levelNum;
041: _cells = new TableCell[_tprops.getItcMac()];
042:
043: int start = 0;
044: int end = 0;
045:
046: for (int cellIndex = 0; cellIndex < _cells.length; cellIndex++) {
047: Paragraph p = getParagraph(start);
048: String s = p.text();
049:
050: while (!((s.charAt(s.length() - 1) == TABLE_CELL_MARK) || p
051: .isEmbeddedCellMark()
052: && p.getTableLevel() == levelNum)) {
053: end++;
054: p = getParagraph(end);
055: s = p.text();
056: }
057: _cells[cellIndex] = new TableCell(start, end, this ,
058: levelNum, _tprops.getRgtc()[cellIndex], _tprops
059: .getRgdxaCenter()[cellIndex], _tprops
060: .getRgdxaCenter()[cellIndex + 1]
061: - _tprops.getRgdxaCenter()[cellIndex]);
062: end++;
063: start = end;
064: }
065: }
066:
067: public int getRowJustification() {
068: return _tprops.getJc();
069: }
070:
071: public void setRowJustification(int jc) {
072: _tprops.setJc(jc);
073: _papx.updateSprm(SPRM_TJC, (short) jc);
074: }
075:
076: public int getGapHalf() {
077: return _tprops.getDxaGapHalf();
078: }
079:
080: public void setGapHalf(int dxaGapHalf) {
081: _tprops.setDxaGapHalf(dxaGapHalf);
082: _papx.updateSprm(SPRM_DXAGAPHALF, (short) dxaGapHalf);
083: }
084:
085: public int getRowHeight() {
086: return _tprops.getDyaRowHeight();
087: }
088:
089: public void setRowHeight(int dyaRowHeight) {
090: _tprops.setDyaRowHeight(dyaRowHeight);
091: _papx.updateSprm(SPRM_DYAROWHEIGHT, (short) dyaRowHeight);
092: }
093:
094: public boolean cantSplit() {
095: return _tprops.getFCantSplit();
096: }
097:
098: public void setCantSplit(boolean cantSplit) {
099: _tprops.setFCantSplit(cantSplit);
100: _papx.updateSprm(SPRM_FCANTSPLIT, (byte) (cantSplit ? 1 : 0));
101: }
102:
103: public boolean isTableHeader() {
104: return _tprops.getFTableHeader();
105: }
106:
107: public void setTableHeader(boolean tableHeader) {
108: _tprops.setFTableHeader(tableHeader);
109: _papx.updateSprm(SPRM_FTABLEHEADER,
110: (byte) (tableHeader ? 1 : 0));
111: }
112:
113: public int numCells() {
114: return _cells.length;
115: }
116:
117: public TableCell getCell(int index) {
118: return _cells[index];
119: }
120: }
|