Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TableCell.java 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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.Locator;
  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.ValidationException;
  25. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  26. import org.apache.fop.fo.properties.LengthRangeProperty;
  27. /**
  28. * Class modelling the fo:table-cell object.
  29. */
  30. public class TableCell extends TableFObj {
  31. // The value of properties relevant for fo:table-cell.
  32. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  33. private LengthRangeProperty blockProgressionDimension;
  34. private int columnNumber;
  35. private int displayAlign;
  36. private int emptyCells;
  37. private int endsRow;
  38. private int numberColumnsSpanned;
  39. private int numberRowsSpanned;
  40. private int startsRow;
  41. private Length width;
  42. // Unused but valid items, commented out for performance:
  43. // private CommonAccessibility commonAccessibility;
  44. // private CommonAural commonAural;
  45. // private CommonRelativePosition commonRelativePosition;
  46. // private int relativeAlign;
  47. // private Length height;
  48. // private LengthRangeProperty inlineProgressionDimension;
  49. // private KeepProperty keepTogether;
  50. // private KeepProperty keepWithNext;
  51. // private KeepProperty keepWithPrevious;
  52. // End of property values
  53. /** used for FO validation */
  54. private boolean blockItemFound = false;
  55. /**
  56. * @param parent FONode that is the parent of this object
  57. */
  58. public TableCell(FONode parent) {
  59. super(parent);
  60. }
  61. /**
  62. * {@inheritDoc}
  63. */
  64. public void bind(PropertyList pList) throws FOPException {
  65. super.bind(pList);
  66. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  67. blockProgressionDimension = pList.get(PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange();
  68. displayAlign = pList.get(PR_DISPLAY_ALIGN).getEnum();
  69. emptyCells = pList.get(PR_EMPTY_CELLS).getEnum();
  70. startsRow = pList.get(PR_STARTS_ROW).getEnum();
  71. // For properly computing columnNumber
  72. if (startsRow() && getParent().getNameId() != FO_TABLE_ROW) {
  73. ((TableBody) getParent()).signalNewRow();
  74. }
  75. endsRow = pList.get(PR_ENDS_ROW).getEnum();
  76. columnNumber = pList.get(PR_COLUMN_NUMBER).getNumeric().getValue();
  77. numberColumnsSpanned = pList.get(PR_NUMBER_COLUMNS_SPANNED).getNumeric().getValue();
  78. numberRowsSpanned = pList.get(PR_NUMBER_ROWS_SPANNED).getNumeric().getValue();
  79. width = pList.get(PR_WIDTH).getLength();
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. public void startOfNode() throws FOPException {
  85. super.startOfNode();
  86. getFOEventHandler().startCell(this);
  87. }
  88. /**
  89. * Make sure content model satisfied, if so then tell the
  90. * FOEventHandler that we are at the end of the flow.
  91. * {@inheritDoc}
  92. */
  93. public void endOfNode() throws FOPException {
  94. if (!blockItemFound) {
  95. missingChildElementError("marker* (%block;)+", true);
  96. }
  97. if ((startsRow() || endsRow())
  98. && getParent().getNameId() == FO_TABLE_ROW ) {
  99. TableEventProducer eventProducer = TableEventProducer.Provider.get(
  100. getUserAgent().getEventBroadcaster());
  101. eventProducer.startEndRowUnderTableRowWarning(this, getLocator());
  102. }
  103. getFOEventHandler().endCell(this);
  104. }
  105. /**
  106. * {@inheritDoc}
  107. * XSL Content Model: marker* (%block;)+
  108. */
  109. protected void validateChildNode(Locator loc, String nsURI, String localName)
  110. throws ValidationException {
  111. if (FO_URI.equals(nsURI)) {
  112. if (localName.equals("marker")) {
  113. if (blockItemFound) {
  114. nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
  115. }
  116. } else if (!isBlockItem(nsURI, localName)) {
  117. invalidChildError(loc, nsURI, localName);
  118. } else {
  119. blockItemFound = true;
  120. }
  121. }
  122. }
  123. /** {@inheritDoc} */
  124. protected void setCollapsedBorders() {
  125. createBorder(CommonBorderPaddingBackground.BEFORE);
  126. createBorder(CommonBorderPaddingBackground.AFTER);
  127. createBorder(CommonBorderPaddingBackground.START);
  128. createBorder(CommonBorderPaddingBackground.END);
  129. }
  130. /** {@inheritDoc} */
  131. public boolean generatesReferenceAreas() {
  132. return true;
  133. }
  134. /**
  135. * @return the Common Border, Padding, and Background Properties.
  136. */
  137. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  138. return this.commonBorderPaddingBackground;
  139. }
  140. /**
  141. * @return the "column-number" property.
  142. */
  143. public int getColumnNumber() {
  144. return columnNumber;
  145. }
  146. /** @return true if "empty-cells" is "show" */
  147. public boolean showEmptyCells() {
  148. return (this.emptyCells == EN_SHOW);
  149. }
  150. /**
  151. * @return the "number-columns-spanned" property.
  152. */
  153. public int getNumberColumnsSpanned() {
  154. return Math.max(numberColumnsSpanned, 1);
  155. }
  156. /**
  157. * @return the "number-rows-spanned" property.
  158. */
  159. public int getNumberRowsSpanned() {
  160. return Math.max(numberRowsSpanned, 1);
  161. }
  162. /**
  163. * @return the "block-progression-dimension" property.
  164. */
  165. public LengthRangeProperty getBlockProgressionDimension() {
  166. return blockProgressionDimension;
  167. }
  168. /** @return the display-align property. */
  169. public int getDisplayAlign() {
  170. return displayAlign;
  171. }
  172. /**
  173. * @return the "width" property.
  174. */
  175. public Length getWidth() {
  176. return width;
  177. }
  178. /** @return true if the cell starts a row. */
  179. public boolean startsRow() {
  180. return (startsRow == EN_TRUE);
  181. }
  182. /** @return true if the cell ends a row. */
  183. public boolean endsRow() {
  184. return (endsRow == EN_TRUE);
  185. }
  186. /** {@inheritDoc} */
  187. public String getLocalName() {
  188. return "table-cell";
  189. }
  190. /**
  191. * {@inheritDoc}
  192. */
  193. public final int getNameId() {
  194. return FO_TABLE_CELL;
  195. }
  196. }