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.

TableContext.java 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * $Id$
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.render.rtf;
  52. import java.util.ArrayList;
  53. import org.apache.avalon.framework.logger.ConsoleLogger;
  54. import org.apache.avalon.framework.logger.Logger;
  55. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
  56. import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
  57. /** Used when handling fo:table to hold information to build the table.
  58. *
  59. * Contributor(s):
  60. * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
  61. * @author Trembicki-Guy, Ed <GuyE@DNB.com>
  62. * @author Boris Poudérous <boris.pouderous@eads-telecom.com>
  63. * @author Peter Herweg <pherweg@web.de>
  64. *
  65. * This class was originally developed for the JFOR project and
  66. * is now integrated into FOP.
  67. */
  68. class TableContext implements ITableColumnsInfo {
  69. private final Logger log = new ConsoleLogger();
  70. private final BuilderContext m_context;
  71. private final ArrayList m_colWidths = new ArrayList();
  72. private int m_colIndex;
  73. /**
  74. * Added by Peter Herweg on 2002-06-29
  75. * This ArrayList contains one element for each column in the table.
  76. * value == 0 means there is no row-spanning
  77. * value > 0 means there is row-spanning
  78. * Each value in the list is decreased by 1 after each finished table-row
  79. */
  80. private final ArrayList m_colRowSpanningNumber = new ArrayList();
  81. /**
  82. * Added by Peter Herweg on 2002-06-29
  83. * If there has a vertical merged cell to be created, its attributes are
  84. * inherited from the corresponding MERGE_START-cell.
  85. * For this purpose the attributes of a cell are stored in this array, as soon
  86. * as a number-rows-spanned attribute has been found.
  87. */
  88. private final ArrayList m_colRowSpanningAttrs = new ArrayList();
  89. private boolean m_bNextRowBelongsToHeader = false;
  90. public void setNextRowBelongsToHeader(boolean bNextRowBelongsToHeader) {
  91. m_bNextRowBelongsToHeader = bNextRowBelongsToHeader;
  92. }
  93. public boolean getNextRowBelongsToHeader() {
  94. return m_bNextRowBelongsToHeader;
  95. }
  96. TableContext(BuilderContext ctx) {
  97. m_context = ctx;
  98. }
  99. void setNextColumnWidth(String strWidth)
  100. throws Exception {
  101. m_colWidths.add(new Float(FoUnitsConverter.getInstance().convertToTwips(strWidth)));
  102. }
  103. //Added by Peter Herweg on 2002-06-29
  104. RtfAttributes getColumnRowSpanningAttrs() {
  105. return (RtfAttributes)m_colRowSpanningAttrs.get(m_colIndex);
  106. }
  107. //Added by Peter Herweg on 2002-06-29
  108. Integer getColumnRowSpanningNumber() {
  109. return (Integer)m_colRowSpanningNumber.get(m_colIndex);
  110. }
  111. //Added by Peter Herweg on 2002-06-29
  112. void setCurrentColumnRowSpanning(Integer iRowSpanning, RtfAttributes attrs)
  113. throws Exception {
  114. if (m_colIndex < m_colRowSpanningNumber.size()) {
  115. m_colRowSpanningNumber.set(m_colIndex, iRowSpanning);
  116. m_colRowSpanningAttrs.set(m_colIndex, attrs);
  117. } else {
  118. m_colRowSpanningNumber.add(iRowSpanning);
  119. m_colRowSpanningAttrs.add(m_colIndex, attrs);
  120. }
  121. }
  122. //Added by Peter Herweg on 2002-06-29
  123. public void setNextColumnRowSpanning(Integer iRowSpanning,
  124. RtfAttributes attrs) {
  125. m_colRowSpanningNumber.add(iRowSpanning);
  126. m_colRowSpanningAttrs.add(m_colIndex, attrs);
  127. }
  128. /**
  129. * Added by Peter Herweg on 2002-06-29
  130. * This function is called after each finished table-row.
  131. * It decreases all values in m_colRowSpanningNumber by 1. If a value
  132. * reaches 0 row-spanning is finished, and the value won't be decreased anymore.
  133. */
  134. public void decreaseRowSpannings() {
  135. for (int z = 0; z < m_colRowSpanningNumber.size(); ++z) {
  136. Integer i = (Integer)m_colRowSpanningNumber.get(z);
  137. if (i.intValue() > 0) {
  138. i = new Integer(i.intValue() - 1);
  139. }
  140. m_colRowSpanningNumber.set(z, i);
  141. if (i.intValue() == 0) {
  142. m_colRowSpanningAttrs.set(z, null);
  143. }
  144. }
  145. }
  146. /**
  147. * Reset the column iteration index, meant to be called when creating a new row
  148. * The 'public' modifier has been added by Boris Poudérous for
  149. * 'number-columns-spanned' processing
  150. */
  151. public void selectFirstColumn() {
  152. m_colIndex = 0;
  153. }
  154. /**
  155. * Increment the column iteration index
  156. * The 'public' modifier has been added by Boris Poudérous for
  157. * 'number-columns-spanned' processing
  158. */
  159. public void selectNextColumn() {
  160. m_colIndex++;
  161. }
  162. /**
  163. * Get current column width according to column iteration index
  164. * @return INVALID_COLUMN_WIDTH if we cannot find the value
  165. * The 'public' modifier has been added by Boris Poudérous for
  166. * 'number-columns-spanned' processing
  167. */
  168. public float getColumnWidth() {
  169. try {
  170. return ((Float)m_colWidths.get(m_colIndex)).floatValue();
  171. } catch (IndexOutOfBoundsException ex) {
  172. // this code contributed by Trembicki-Guy, Ed <GuyE@DNB.com>
  173. log.warn("fo:table-column width not defined, using " + INVALID_COLUM_WIDTH);
  174. return INVALID_COLUM_WIDTH;
  175. }
  176. }
  177. /** Added by Boris Poudérous on 07/22/2002 */
  178. public int getColumnIndex() {
  179. return m_colIndex;
  180. }
  181. /** - end - */
  182. /** Added by Boris Poudérous on 07/22/2002 */
  183. public int getNumberOfColumns() {
  184. return m_colWidths.size();
  185. }
  186. /** - end - */
  187. }