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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. /**
  24. * A common class for fo:table-body and fo:table-row which both can contain fo:table-cell.
  25. */
  26. public abstract class TableCellContainer extends TableFObj implements ColumnNumberManagerHolder {
  27. protected List pendingSpans;
  28. protected ColumnNumberManager columnNumberManager;
  29. public TableCellContainer(FONode parent) {
  30. super(parent);
  31. }
  32. protected void addTableCellChild(TableCell cell, boolean firstRow) throws FOPException {
  33. int colNumber = cell.getColumnNumber();
  34. int colSpan = cell.getNumberColumnsSpanned();
  35. int rowSpan = cell.getNumberRowsSpanned();
  36. Table t = getTable();
  37. if (t.hasExplicitColumns()) {
  38. if (colNumber + colSpan - 1 > t.getNumberOfColumns()) {
  39. TableEventProducer eventProducer = TableEventProducer.Provider.get(
  40. getUserAgent().getEventBroadcaster());
  41. eventProducer.tooManyCells(this, getLocator());
  42. }
  43. } else {
  44. t.ensureColumnNumber(colNumber + colSpan - 1);
  45. // re-cap the size of pendingSpans
  46. while (pendingSpans.size() < colNumber + colSpan - 1) {
  47. pendingSpans.add(null);
  48. }
  49. }
  50. if (firstRow) {
  51. handleCellWidth(cell, colNumber, colSpan);
  52. }
  53. /* if the current cell spans more than one row,
  54. * update pending span list for the next row
  55. */
  56. if (rowSpan > 1) {
  57. for (int i = 0; i < colSpan; i++) {
  58. pendingSpans.set(colNumber - 1 + i, new PendingSpan(rowSpan));
  59. }
  60. }
  61. columnNumberManager.signalUsedColumnNumbers(colNumber, colNumber + colSpan - 1);
  62. t.getRowGroupBuilder().addTableCell(cell);
  63. }
  64. private void handleCellWidth(TableCell cell, int colNumber, int colSpan) throws FOPException {
  65. Table t = getTable();
  66. Length colWidth = null;
  67. if (cell.getWidth().getEnum() != EN_AUTO
  68. && colSpan == 1) {
  69. colWidth = cell.getWidth();
  70. }
  71. for (int i = colNumber; i < colNumber + colSpan; ++i) {
  72. TableColumn col = t.getColumn(i - 1);
  73. if (colWidth != null) {
  74. col.setColumnWidth(colWidth);
  75. }
  76. }
  77. }
  78. /**
  79. * Returns the enclosing table-header/footer/body of this container.
  80. *
  81. * @return <code>this</code> for TablePart, or the parent element for TableRow
  82. */
  83. abstract TablePart getTablePart();
  84. /** {@inheritDoc} */
  85. public ColumnNumberManager getColumnNumberManager() {
  86. return columnNumberManager;
  87. }
  88. }