KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > usermodel > TableRow


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17
18 package org.apache.poi.hwpf.usermodel;
19
20 import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
21
22 public class TableRow
23   extends Paragraph
24 {
25   private final static char TABLE_CELL_MARK = '\u0007';
26
27   private final static short SPRM_TJC = 0x5400;
28   private final static short SPRM_DXAGAPHALF = (short)0x9602;
29   private final static short SPRM_FCANTSPLIT = 0x3403;
30   private final static short SPRM_FTABLEHEADER = 0x3404;
31   private final static short SPRM_DYAROWHEIGHT = (short)0x9407;
32
33   int _levelNum;
34   private TableProperties _tprops;
35   private TableCell[] _cells;
36
37   public TableRow(int startIdx, int endIdx, Table parent, int levelNum)
38   {
39     super(startIdx, endIdx, parent);
40
41     _tprops = TableSprmUncompressor.uncompressTAP(_papx.toByteArray(), 2);
42     _levelNum = levelNum;
43     _cells = new TableCell[_tprops.getItcMac()];
44
45     int start = 0;
46     int end = 0;
47
48     for (int cellIndex = 0; cellIndex < _cells.length; cellIndex++)
49     {
50       Paragraph p = getParagraph(start);
51       String JavaDoc s = p.text();
52
53       while (! ( (s.charAt(s.length() - 1) == TABLE_CELL_MARK) ||
54                 p.isEmbeddedCellMark() && p.getTableLevel() == levelNum))
55       {
56         end++;
57         p = getParagraph(end);
58         s = p.text();
59       }
60       _cells[cellIndex] = new TableCell(start, end, this, levelNum,
61                                         _tprops.getRgtc()[cellIndex],
62                                         _tprops.getRgdxaCenter()[cellIndex],
63                                         _tprops.getRgdxaCenter()[cellIndex+1]-_tprops.getRgdxaCenter()[cellIndex]);
64       end++;
65       start = end;
66     }
67   }
68
69   public int getRowJustification()
70   {
71     return _tprops.getJc();
72   }
73
74   public void setRowJustification(int jc)
75   {
76     _tprops.setJc(jc);
77     _papx.updateSprm(SPRM_TJC, (short)jc);
78   }
79
80   public int getGapHalf()
81   {
82     return _tprops.getDxaGapHalf();
83   }
84
85   public void setGapHalf(int dxaGapHalf)
86   {
87     _tprops.setDxaGapHalf(dxaGapHalf);
88     _papx.updateSprm(SPRM_DXAGAPHALF, (short)dxaGapHalf);
89   }
90
91   public int getRowHeight()
92   {
93     return _tprops.getDyaRowHeight();
94   }
95
96   public void setRowHeight(int dyaRowHeight)
97   {
98     _tprops.setDyaRowHeight(dyaRowHeight);
99     _papx.updateSprm(SPRM_DYAROWHEIGHT, (short)dyaRowHeight);
100   }
101
102   public boolean cantSplit()
103   {
104     return _tprops.getFCantSplit();
105   }
106
107   public void setCantSplit(boolean cantSplit)
108   {
109     _tprops.setFCantSplit(cantSplit);
110     _papx.updateSprm(SPRM_FCANTSPLIT, (byte)(cantSplit ? 1 : 0));
111   }
112
113   public boolean isTableHeader()
114   {
115     return _tprops.getFTableHeader();
116   }
117
118   public void setTableHeader(boolean tableHeader)
119   {
120     _tprops.setFTableHeader(tableHeader);
121     _papx.updateSprm(SPRM_FTABLEHEADER, (byte)(tableHeader ? 1 : 0));
122   }
123
124   public int numCells()
125   {
126     return _cells.length;
127   }
128
129   public TableCell getCell(int index)
130   {
131     return _cells[index];
132   }
133 }
134
Popular Tags