You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TableRow.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* ====================================================================
  2. Copyright 2002-2004 Apache Software Foundation
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ==================================================================== */
  13. package org.apache.poi.hwpf.usermodel;
  14. import org.apache.poi.hwpf.sprm.TableSprmUncompressor;
  15. public class TableRow
  16. extends Paragraph
  17. {
  18. private final static char TABLE_CELL_MARK = '\u0007';
  19. private final static short SPRM_TJC = 0x5400;
  20. private final static short SPRM_DXAGAPHALF = (short)0x9602;
  21. private final static short SPRM_FCANTSPLIT = 0x3403;
  22. private final static short SPRM_FTABLEHEADER = 0x3404;
  23. private final static short SPRM_DYAROWHEIGHT = (short)0x9407;
  24. int _levelNum;
  25. private TableProperties _tprops;
  26. private TableCell[] _cells;
  27. public TableRow(int startIdx, int endIdx, Table parent, int levelNum)
  28. {
  29. super(startIdx, endIdx, parent);
  30. _tprops = TableSprmUncompressor.uncompressTAP(_papx.toByteArray(), 2);
  31. _levelNum = levelNum;
  32. _cells = new TableCell[_tprops.getItcMac()];
  33. int start = 0;
  34. int end = 0;
  35. for (int cellIndex = 0; cellIndex < _cells.length; cellIndex++)
  36. {
  37. Paragraph p = getParagraph(start);
  38. String s = p.text();
  39. while (! ( (s.charAt(s.length() - 1) == TABLE_CELL_MARK) ||
  40. p.isEmbeddedCellMark() && p.getTableLevel() == levelNum))
  41. {
  42. end++;
  43. p = getParagraph(end);
  44. s = p.text();
  45. }
  46. _cells[cellIndex] = new TableCell(start, end, this, levelNum,
  47. _tprops.getRgtc()[cellIndex],
  48. _tprops.getRgdxaCenter()[cellIndex],
  49. _tprops.getRgdxaCenter()[cellIndex+1]-_tprops.getRgdxaCenter()[cellIndex]);
  50. end++;
  51. start = end;
  52. }
  53. }
  54. public int getRowJustification()
  55. {
  56. return _tprops.getJc();
  57. }
  58. public void setRowJustification(int jc)
  59. {
  60. _tprops.setJc(jc);
  61. _papx.updateSprm(SPRM_TJC, (short)jc);
  62. }
  63. public int getGapHalf()
  64. {
  65. return _tprops.getDxaGapHalf();
  66. }
  67. public void setGapHalf(int dxaGapHalf)
  68. {
  69. _tprops.setDxaGapHalf(dxaGapHalf);
  70. _papx.updateSprm(SPRM_DXAGAPHALF, (short)dxaGapHalf);
  71. }
  72. public int getRowHeight()
  73. {
  74. return _tprops.getDyaRowHeight();
  75. }
  76. public void setRowHeight(int dyaRowHeight)
  77. {
  78. _tprops.setDyaRowHeight(dyaRowHeight);
  79. _papx.updateSprm(SPRM_DYAROWHEIGHT, (short)dyaRowHeight);
  80. }
  81. public boolean cantSplit()
  82. {
  83. return _tprops.getFCantSplit();
  84. }
  85. public void setCantSplit(boolean cantSplit)
  86. {
  87. _tprops.setFCantSplit(cantSplit);
  88. _papx.updateSprm(SPRM_FCANTSPLIT, (byte)(cantSplit ? 1 : 0));
  89. }
  90. public boolean isTableHeader()
  91. {
  92. return _tprops.getFTableHeader();
  93. }
  94. public void setTableHeader(boolean tableHeader)
  95. {
  96. _tprops.setFTableHeader(tableHeader);
  97. _papx.updateSprm(SPRM_FTABLEHEADER, (byte)(tableHeader ? 1 : 0));
  98. }
  99. public int numCells()
  100. {
  101. return _cells.length;
  102. }
  103. public TableCell getCell(int index)
  104. {
  105. return _cells[index];
  106. }
  107. }