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

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