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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 org.xml.sax.Attributes;
  20. import org.xml.sax.Locator;
  21. import org.apache.fop.apps.FOPException;
  22. import org.apache.fop.datatypes.Length;
  23. import org.apache.fop.fo.FONode;
  24. import org.apache.fop.fo.PropertyList;
  25. import org.apache.fop.fo.ValidationException;
  26. import org.apache.fop.fo.properties.BreakPropertySet;
  27. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  28. import org.apache.fop.fo.properties.KeepProperty;
  29. import org.apache.fop.fo.properties.LengthRangeProperty;
  30. /**
  31. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-row">
  32. * <code>fo:table-row</code></a> object.
  33. */
  34. public class TableRow extends TableCellContainer implements BreakPropertySet {
  35. // The value of properties relevant for fo:table-row.
  36. private LengthRangeProperty blockProgressionDimension;
  37. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  38. private int breakAfter;
  39. private int breakBefore;
  40. private Length height;
  41. private KeepProperty keepTogether;
  42. private KeepProperty keepWithNext;
  43. private KeepProperty keepWithPrevious;
  44. // Unused but valid items, commented out for performance:
  45. // private CommonAccessibility commonAccessibility;
  46. // private CommonAural commonAural;
  47. // private CommonRelativePosition commonRelativePosition;
  48. // private int visibility;
  49. // End of property values
  50. /**
  51. * Create a TableRow instance with the given {@link FONode}
  52. * as parent.
  53. * @param parent {@link FONode} that is the parent of this object
  54. */
  55. public TableRow(FONode parent) {
  56. super(parent);
  57. }
  58. /** {@inheritDoc} */
  59. public void bind(PropertyList pList) throws FOPException {
  60. blockProgressionDimension
  61. = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
  62. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  63. breakAfter = pList.get(PR_BREAK_AFTER).getEnum();
  64. breakBefore = pList.get(PR_BREAK_BEFORE).getEnum();
  65. height = pList.get(PR_HEIGHT).getLength();
  66. keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep();
  67. keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep();
  68. keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep();
  69. super.bind(pList);
  70. }
  71. /** {@inheritDoc} */
  72. public void processNode(String elementName, Locator locator,
  73. Attributes attlist, PropertyList pList) throws FOPException {
  74. super.processNode(elementName, locator, attlist, pList);
  75. if (!inMarker()) {
  76. TablePart part = (TablePart) parent;
  77. pendingSpans = part.pendingSpans;
  78. columnNumberManager = part.columnNumberManager;
  79. }
  80. }
  81. /** {@inheritDoc} */
  82. protected void addChildNode(FONode child) throws FOPException {
  83. if (!inMarker()) {
  84. TableCell cell = (TableCell) child;
  85. TablePart part = (TablePart) getParent();
  86. addTableCellChild(cell, part.isFirst(this));
  87. }
  88. super.addChildNode(child);
  89. }
  90. /** {@inheritDoc} */
  91. protected void startOfNode() throws FOPException {
  92. super.startOfNode();
  93. getFOEventHandler().startRow(this);
  94. }
  95. /** {@inheritDoc} */
  96. protected void endOfNode() throws FOPException {
  97. super.endOfNode();
  98. getFOEventHandler().endRow(this);
  99. }
  100. /** {@inheritDoc} */
  101. public void finalizeNode() throws FOPException {
  102. if (firstChild == null) {
  103. missingChildElementError("(table-cell+)");
  104. }
  105. if (!inMarker()) {
  106. pendingSpans = null;
  107. columnNumberManager = null;
  108. }
  109. }
  110. /**
  111. * {@inheritDoc} String, String)
  112. * <br>XSL Content Model: (table-cell+)
  113. */
  114. protected void validateChildNode(Locator loc, String nsURI,
  115. String localName)
  116. throws ValidationException {
  117. if (FO_URI.equals(nsURI)) {
  118. if (!localName.equals("table-cell")) {
  119. invalidChildError(loc, nsURI, localName);
  120. }
  121. }
  122. }
  123. /** {@inheritDoc} */
  124. TablePart getTablePart() {
  125. return (TablePart) parent;
  126. }
  127. /** {@inheritDoc} */
  128. boolean isTableRow() {
  129. return true;
  130. }
  131. /** @return the "break-after" property. */
  132. public int getBreakAfter() {
  133. return breakAfter;
  134. }
  135. /** @return the "break-before" property. */
  136. public int getBreakBefore() {
  137. return breakBefore;
  138. }
  139. /** @return the "keep-with-previous" property. */
  140. public KeepProperty getKeepWithPrevious() {
  141. return keepWithPrevious;
  142. }
  143. /** @return the "keep-with-next" property. */
  144. public KeepProperty getKeepWithNext() {
  145. return keepWithNext;
  146. }
  147. /** @return the "keep-together" property. */
  148. public KeepProperty getKeepTogether() {
  149. return keepTogether;
  150. }
  151. /**
  152. * Convenience method to check if a keep-together
  153. * constraint is specified.
  154. * @return true if keep-together is active.
  155. */
  156. public boolean mustKeepTogether() {
  157. return !getKeepTogether().getWithinPage().isAuto()
  158. || !getKeepTogether().getWithinColumn().isAuto();
  159. }
  160. /**
  161. * Convenience method to check if a keep-with-next
  162. * constraint is specified.
  163. * @return true if keep-with-next is active.
  164. */
  165. public boolean mustKeepWithNext() {
  166. return !getKeepWithNext().getWithinPage().isAuto()
  167. || !getKeepWithNext().getWithinColumn().isAuto();
  168. }
  169. /**
  170. * Convenience method to check if a keep-with-previous
  171. * constraint is specified.
  172. * @return true if keep-with-previous is active.
  173. */
  174. public boolean mustKeepWithPrevious() {
  175. return !getKeepWithPrevious().getWithinPage().isAuto()
  176. || !getKeepWithPrevious().getWithinColumn().isAuto();
  177. }
  178. /**
  179. * @return the "block-progression-dimension" property.
  180. */
  181. public LengthRangeProperty getBlockProgressionDimension() {
  182. return blockProgressionDimension;
  183. }
  184. /**
  185. * @return the "height" property.
  186. */
  187. public Length getHeight() {
  188. return height;
  189. }
  190. /**
  191. * @return the Common Border, Padding, and Background Properties.
  192. */
  193. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  194. return commonBorderPaddingBackground;
  195. }
  196. /** {@inheritDoc} */
  197. public String getLocalName() {
  198. return "table-row";
  199. }
  200. /**
  201. * {@inheritDoc}
  202. * @return {@link org.apache.fop.fo.Constants#FO_TABLE_ROW}
  203. */
  204. public int getNameId() {
  205. return FO_TABLE_ROW;
  206. }
  207. }