Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.Iterator;
  20. import java.util.List;
  21. import org.apache.fop.layoutmgr.table.TableRowIterator;
  22. import org.apache.fop.traits.MinOptMax;
  23. /**
  24. * This class represents an effective row in a table and holds a list of grid units occupying
  25. * the row as well as some additional values.
  26. */
  27. public class EffRow {
  28. /** Indicates that the row is the first in a table-body */
  29. public static final int FIRST_IN_PART = GridUnit.FIRST_IN_PART;
  30. /** Indicates that the row is the last in a table-body */
  31. public static final int LAST_IN_PART = GridUnit.LAST_IN_PART;
  32. private List gridUnits = new java.util.ArrayList();
  33. private int index;
  34. /** One of HEADER, FOOTER, BODY */
  35. private int bodyType;
  36. private MinOptMax height;
  37. private MinOptMax explicitHeight;
  38. /**
  39. * Creates a new effective row instance.
  40. * @param index index of the row
  41. * @param bodyType type of body (one of HEADER, FOOTER, BODY as found on TableRowIterator)
  42. * @param gridUnits the grid units this row is made of
  43. */
  44. public EffRow(int index, int bodyType, List gridUnits) {
  45. this.index = index;
  46. this.bodyType = bodyType;
  47. this.gridUnits = gridUnits;
  48. // TODO this is ugly, but we may eventually be able to do without that index
  49. for (Iterator guIter = gridUnits.iterator(); guIter.hasNext();) {
  50. Object gu = guIter.next();
  51. if (gu instanceof PrimaryGridUnit) {
  52. ((PrimaryGridUnit) gu).setStartRow(index);
  53. }
  54. }
  55. }
  56. /** @return the index of the EffRow in the sequence of rows */
  57. public int getIndex() {
  58. return this.index;
  59. }
  60. /**
  61. * @return an indicator what type of body this EffRow is in (one of HEADER, FOOTER, BODY
  62. * as found on TableRowIterator)
  63. */
  64. public int getBodyType() {
  65. return this.bodyType;
  66. }
  67. /** @return the table-row FO for this EffRow, or null if there is no table-row. */
  68. public TableRow getTableRow() {
  69. return getGridUnit(0).getRow();
  70. }
  71. /**
  72. * Returns the calculated height for this EffRow, including the cells'
  73. * bpds/paddings/borders, and the table's border-separation.
  74. *
  75. * @return the row's height
  76. */
  77. public MinOptMax getHeight() {
  78. return this.height;
  79. }
  80. /**
  81. * Sets the calculated height for this EffRow, including everything (cells' bpds,
  82. * paddings, borders, and border-separation).
  83. *
  84. * @param mom the calculated height
  85. */
  86. public void setHeight(MinOptMax mom) {
  87. this.height = mom;
  88. }
  89. /** @return the explicit height of the EffRow (as specified through properties) */
  90. public MinOptMax getExplicitHeight() {
  91. return this.explicitHeight;
  92. }
  93. /**
  94. * Sets the height for this row that resulted from the explicit height properties specified
  95. * by the user.
  96. * @param mom the height
  97. */
  98. public void setExplicitHeight(MinOptMax mom) {
  99. this.explicitHeight = mom;
  100. }
  101. /** @return the list of GridUnits for this EffRow */
  102. public List getGridUnits() {
  103. return gridUnits;
  104. }
  105. /**
  106. * Returns the grid unit at a given position.
  107. * @param column index of the grid unit in the row (zero based)
  108. * @return the requested grid unit.
  109. */
  110. public GridUnit getGridUnit(int column) {
  111. return (GridUnit)gridUnits.get(column);
  112. }
  113. /**
  114. * Returns the grid unit at a given position. In contrast to getGridUnit() this
  115. * method returns null if there's no grid unit at the given position. The number of
  116. * grid units for row x can be smaller than the number of grid units for row x-1.
  117. * @param column index of the grid unit in the row (zero based)
  118. * @return the requested grid unit or null if there's no grid unit at this position.
  119. */
  120. public GridUnit safelyGetGridUnit(int column) {
  121. if (column < gridUnits.size()) {
  122. return (GridUnit)gridUnits.get(column);
  123. } else {
  124. return null;
  125. }
  126. }
  127. /**
  128. * Returns a flag for this effective row. Only a subset of the flags on GridUnit is supported.
  129. * The flag is determined by inspecting flags on the EffRow's GridUnits.
  130. * @param which the requested flag (one of {@link EffRow#FIRST_IN_PART} or {@link
  131. * EffRow#LAST_IN_PART})
  132. * @return true if the flag is set
  133. */
  134. public boolean getFlag(int which) {
  135. if (which == FIRST_IN_PART) {
  136. return getGridUnit(0).getFlag(GridUnit.FIRST_IN_PART);
  137. } else if (which == LAST_IN_PART) {
  138. return getGridUnit(0).getFlag(GridUnit.LAST_IN_PART);
  139. } else {
  140. throw new IllegalArgumentException("Illegal flag queried: " + which);
  141. }
  142. }
  143. /** {@inheritDoc} */
  144. public String toString() {
  145. StringBuffer sb = new StringBuffer("EffRow {");
  146. sb.append(index);
  147. if (getBodyType() == TableRowIterator.BODY) {
  148. sb.append(" in body");
  149. } else if (getBodyType() == TableRowIterator.HEADER) {
  150. sb.append(" in header");
  151. } else {
  152. sb.append(" in footer");
  153. }
  154. sb.append(", ").append(height);
  155. sb.append(", ").append(explicitHeight);
  156. sb.append(", ").append(gridUnits.size()).append(" gu");
  157. sb.append("}");
  158. return sb.toString();
  159. }
  160. }