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 4.1KB

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