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.

TableCellContainer.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. *
  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. /* $Id$ */
  18. package org.apache.fop.fo.flow.table;
  19. import java.util.List;
  20. import org.apache.fop.apps.FOPException;
  21. import org.apache.fop.datatypes.Length;
  22. import org.apache.fop.fo.FONode;
  23. import org.apache.fop.fo.PropertyList;
  24. import org.apache.fop.fo.properties.CommonAccessibility;
  25. import org.apache.fop.fo.properties.CommonAccessibilityHolder;
  26. /**
  27. * A common class for fo:table-body and fo:table-row which both can contain fo:table-cell.
  28. */
  29. public abstract class TableCellContainer extends TableFObj
  30. implements ColumnNumberManagerHolder, CommonAccessibilityHolder {
  31. private CommonAccessibility commonAccessibility;
  32. /** list of pending spans */
  33. protected List pendingSpans;
  34. /** column number manager */
  35. protected ColumnNumberManager columnNumberManager;
  36. /**
  37. * Construct table cell container.
  38. * @param parent the parent node of the cell container
  39. */
  40. public TableCellContainer(FONode parent) {
  41. super(parent);
  42. }
  43. @Override
  44. public void bind(PropertyList pList) throws FOPException {
  45. super.bind(pList);
  46. commonAccessibility = CommonAccessibility.getInstance(pList);
  47. }
  48. /**
  49. * Add cell to current row.
  50. * @param cell a table cell to add
  51. * @param firstRow true is first row
  52. * @throws FOPException if exception occurs
  53. */
  54. protected void addTableCellChild(TableCell cell, boolean firstRow) throws FOPException {
  55. int colNumber = cell.getColumnNumber();
  56. int colSpan = cell.getNumberColumnsSpanned();
  57. int rowSpan = cell.getNumberRowsSpanned();
  58. Table t = getTable();
  59. if (t.hasExplicitColumns()) {
  60. if (colNumber + colSpan - 1 > t.getNumberOfColumns()) {
  61. TableEventProducer eventProducer = TableEventProducer.Provider.get(
  62. getUserAgent().getEventBroadcaster());
  63. eventProducer.tooManyCells(this, getLocator());
  64. }
  65. } else {
  66. t.ensureColumnNumber(colNumber + colSpan - 1);
  67. // re-cap the size of pendingSpans
  68. while (pendingSpans.size() < colNumber + colSpan - 1) {
  69. pendingSpans.add(null);
  70. }
  71. }
  72. if (firstRow) {
  73. handleCellWidth(cell, colNumber, colSpan);
  74. }
  75. /* if the current cell spans more than one row,
  76. * update pending span list for the next row
  77. */
  78. if (rowSpan > 1) {
  79. for (int i = 0; i < colSpan; i++) {
  80. pendingSpans.set(colNumber - 1 + i, new PendingSpan(rowSpan));
  81. }
  82. }
  83. columnNumberManager.signalUsedColumnNumbers(colNumber, colNumber + colSpan - 1);
  84. t.getRowGroupBuilder().addTableCell(cell);
  85. }
  86. private void handleCellWidth(TableCell cell, int colNumber, int colSpan) throws FOPException {
  87. Table t = getTable();
  88. Length colWidth = null;
  89. if (cell.getWidth().getEnum() != EN_AUTO
  90. && colSpan == 1) {
  91. colWidth = cell.getWidth();
  92. }
  93. for (int i = colNumber; i < colNumber + colSpan; ++i) {
  94. TableColumn col = t.getColumn(i - 1);
  95. if (colWidth != null) {
  96. col.setColumnWidth(colWidth);
  97. }
  98. }
  99. }
  100. /**
  101. * Returns the enclosing table-header/footer/body of this container.
  102. *
  103. * @return <code>this</code> for TablePart, or the parent element for TableRow
  104. */
  105. abstract TablePart getTablePart();
  106. /** {@inheritDoc} */
  107. public ColumnNumberManager getColumnNumberManager() {
  108. return columnNumberManager;
  109. }
  110. /** {@inheritDoc} */
  111. public CommonAccessibility getCommonAccessibility() {
  112. return commonAccessibility;
  113. }
  114. }