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.

TableColumn.java 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. // XML
  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.Constants;
  24. import org.apache.fop.fo.FONode;
  25. import org.apache.fop.fo.PropertyList;
  26. import org.apache.fop.fo.ValidationException;
  27. import org.apache.fop.fo.expr.PropertyException;
  28. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  29. import org.apache.fop.fo.properties.Property;
  30. import org.apache.fop.fo.properties.TableColLength;
  31. import org.apache.fop.layoutmgr.table.CollapsingBorderModel;
  32. /**
  33. * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-column">
  34. * <code>fo:table-column</code></a> object.
  35. */
  36. public class TableColumn extends TableFObj {
  37. // The value of properties relevant for fo:table-column.
  38. private CommonBorderPaddingBackground commonBorderPaddingBackground;
  39. private int columnNumber;
  40. private Length columnWidth;
  41. private int numberColumnsRepeated;
  42. private int numberColumnsSpanned;
  43. private boolean isHeader;
  44. // Unused but valid items, commented out for performance:
  45. // private int visibility;
  46. // End of property values
  47. private boolean implicitColumn;
  48. private PropertyList pList = null;
  49. /**
  50. * Create a TableColumn instance with the given {@link FONode}
  51. * as parent.
  52. *
  53. * @param parent {@link FONode} that is the parent of this object
  54. */
  55. public TableColumn(FONode parent) {
  56. this(parent, false);
  57. }
  58. /**
  59. * Create a TableColumn instance with the given {@link FONode}
  60. * as parent
  61. *
  62. * @param parent FONode that is the parent of this object
  63. * @param implicit true if this table-column has automatically been created (does not
  64. * correspond to an explicit fo:table-column in the input document)
  65. */
  66. public TableColumn(FONode parent, boolean implicit) {
  67. super(parent);
  68. this.implicitColumn = implicit;
  69. }
  70. /** {@inheritDoc} */
  71. public void bind(PropertyList pList) throws FOPException {
  72. commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
  73. columnNumber = pList.get(PR_COLUMN_NUMBER).getNumeric().getValue();
  74. columnWidth = pList.get(PR_COLUMN_WIDTH).getLength();
  75. numberColumnsRepeated = pList.get(PR_NUMBER_COLUMNS_REPEATED)
  76. .getNumeric().getValue();
  77. numberColumnsSpanned = pList.get(PR_NUMBER_COLUMNS_SPANNED)
  78. .getNumeric().getValue();
  79. super.bind(pList);
  80. if (numberColumnsRepeated <= 0) {
  81. TableEventProducer eventProducer = TableEventProducer.Provider.get(
  82. getUserAgent().getEventBroadcaster());
  83. eventProducer.valueMustBeBiggerGtEqOne(this,
  84. "number-columns-repeated", numberColumnsRepeated, getLocator());
  85. }
  86. if (numberColumnsSpanned <= 0) {
  87. TableEventProducer eventProducer = TableEventProducer.Provider.get(
  88. getUserAgent().getEventBroadcaster());
  89. eventProducer.valueMustBeBiggerGtEqOne(this,
  90. "number-columns-spanned", numberColumnsSpanned, getLocator());
  91. }
  92. /* check for unspecified width and replace with default of
  93. * proportional-column-width(1), in case of fixed table-layout
  94. * warn only for explicit columns
  95. */
  96. if (columnWidth.getEnum() == EN_AUTO) {
  97. if (!this.implicitColumn && !getTable().isAutoLayout()) {
  98. TableEventProducer eventProducer = TableEventProducer.Provider.get(
  99. getUserAgent().getEventBroadcaster());
  100. eventProducer.warnImplicitColumns(this, getLocator());
  101. }
  102. columnWidth = new TableColLength(1.0, this);
  103. }
  104. /* in case of explicit columns, from-table-column()
  105. * can be used on descendants of the table-cells, so
  106. * we need a reference to the column's property list
  107. * (cleared in Table.endOfNode())
  108. */
  109. if (!this.implicitColumn) {
  110. this.pList = pList;
  111. }
  112. isHeader = (pList.get(Constants.PR_X_HEADER_COLUMN).getEnum() == Constants.EN_TRUE);
  113. }
  114. /** {@inheritDoc} */
  115. public void startOfNode() throws FOPException {
  116. super.startOfNode();
  117. getFOEventHandler().startColumn(this);
  118. }
  119. void setCollapsedBorders(CollapsingBorderModel collapsingBorderModel) {
  120. this.collapsingBorderModel = collapsingBorderModel;
  121. setCollapsedBorders();
  122. }
  123. /** {@inheritDoc} */
  124. public void endOfNode() throws FOPException {
  125. getFOEventHandler().endColumn(this);
  126. }
  127. /**
  128. * {@inheritDoc}
  129. * <br>XSL Content Model: empty
  130. */
  131. protected void validateChildNode(Locator loc,
  132. String nsURI, String localName)
  133. throws ValidationException {
  134. if (FO_URI.equals(nsURI)) {
  135. invalidChildError(loc, nsURI, localName);
  136. }
  137. }
  138. /**
  139. * Get the {@link CommonBorderPaddingBackground} instance
  140. * attached to this TableColumn.
  141. * @return the {@link CommonBorderPaddingBackground} instance
  142. */
  143. public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
  144. return commonBorderPaddingBackground;
  145. }
  146. /**
  147. * Get a {@link Length} instance corresponding to the
  148. * <code>column-width</code> property.
  149. * @return the "column-width" property.
  150. */
  151. public Length getColumnWidth() {
  152. return columnWidth;
  153. }
  154. /**
  155. * Sets the column width.
  156. * @param columnWidth the column width
  157. */
  158. public void setColumnWidth(Length columnWidth) {
  159. this.columnWidth = columnWidth;
  160. }
  161. /**
  162. * Get the value of the <code>column-number</code> property
  163. * @return the "column-number" property.
  164. */
  165. public int getColumnNumber() {
  166. return columnNumber;
  167. }
  168. /**
  169. * Used for setting the column-number for an implicit column
  170. * @param columnNumber the number to set
  171. */
  172. protected void setColumnNumber(int columnNumber) {
  173. this.columnNumber = columnNumber;
  174. }
  175. /** @return value for number-columns-repeated. */
  176. public int getNumberColumnsRepeated() {
  177. return numberColumnsRepeated;
  178. }
  179. /** @return value for number-columns-spanned. */
  180. public int getNumberColumnsSpanned() {
  181. return numberColumnsSpanned;
  182. }
  183. /** {@inheritDoc} */
  184. public String getLocalName() {
  185. return "table-column";
  186. }
  187. /**
  188. * {@inheritDoc}
  189. * @return {@link org.apache.fop.fo.Constants#FO_TABLE_COLUMN}
  190. */
  191. public int getNameId() {
  192. return FO_TABLE_COLUMN;
  193. }
  194. /**
  195. * Indicates whether this table-column has been created as
  196. * default column for this table in case no table-columns
  197. * have been defined.
  198. * Note that this only used to provide better
  199. * user feedback (see ColumnSetup).
  200. * @return true if this table-column has been created as default column
  201. */
  202. public boolean isImplicitColumn() {
  203. return implicitColumn;
  204. }
  205. /** {@inheritDoc} */
  206. public String toString() {
  207. StringBuffer sb = new StringBuffer("fo:table-column");
  208. sb.append(" column-number=").append(getColumnNumber());
  209. if (getNumberColumnsRepeated() > 1) {
  210. sb.append(" number-columns-repeated=")
  211. .append(getNumberColumnsRepeated());
  212. }
  213. if (getNumberColumnsSpanned() > 1) {
  214. sb.append(" number-columns-spanned=")
  215. .append(getNumberColumnsSpanned());
  216. }
  217. sb.append(" column-width=").append(((Property)getColumnWidth()).getString());
  218. return sb.toString();
  219. }
  220. /**
  221. * Retrieve a property value through its Id; used by
  222. * from-table-column() function
  223. *
  224. * @param propId the id for the property to retrieve
  225. * @return the requested Property
  226. * @throws PropertyException if there is a problem evaluating the property
  227. */
  228. public Property getProperty(int propId) throws PropertyException {
  229. return this.pList.get(propId);
  230. }
  231. /**
  232. * Clear the reference to the PropertyList (retained for
  233. * from-table-column())
  234. */
  235. protected void releasePropertyList() {
  236. this.pList = null;
  237. }
  238. /**
  239. * Returns {@code true} if this column is made of header cells.
  240. *
  241. * @return {@code true} if cells in this column are like TH cells in HTML
  242. */
  243. public boolean isHeader() {
  244. return isHeader;
  245. }
  246. }