Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/jfor/jfor/converter/TableContext.java


1   package org.jfor.jfor.converter;
2   
3   import java.util.*;
4   import org.jfor.jfor.rtflib.rtfdoc.RtfAttributes;
5   import org.xml.sax.Attributes;
6   import org.jfor.jfor.interfaces.ITableColumnsInfo;
7   
8   /*-----------------------------------------------------------------------------
9    * jfor - Open-Source XSL-FO to RTF converter - see www.jfor.org
10   *
11   * ====================================================================
12   * jfor Apache-Style Software License.
13   * Copyright (c) 2002 by the jfor project. All rights reserved.
14   *
15   * Redistribution and use in source and binary forms, with or without
16   * modification, are permitted provided that the following conditions
17   * are met:
18   *
19   * 1. Redistributions of source code must retain the above copyright
20   * notice, this list of conditions and the following disclaimer.
21   *
22   * 2. Redistributions in binary form must reproduce the above copyright
23   * notice, this list of conditions and the following disclaimer in
24   * the documentation and/or other materials provided with the
25   * distribution.
26   *
27   * 3. The end-user documentation included with the redistribution,
28   * if any, must include the following acknowledgment:
29   * "This product includes software developed
30   * by the jfor project (http://www.jfor.org)."
31   * Alternately, this acknowledgment may appear in the software itself,
32   * if and wherever such third-party acknowledgments normally appear.
33   *
34   * 4. The name "jfor" must not be used to endorse
35   * or promote products derived from this software without prior written
36   * permission.  For written permission, please contact info@jfor.org.
37   *
38   * 5. Products derived from this software may not be called "jfor",
39   * nor may "jfor" appear in their name, without prior written
40   * permission of info@jfor.org.
41   *
42   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
43   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45   * DISCLAIMED.  IN NO EVENT SHALL THE JFOR PROJECT OR ITS CONTRIBUTORS BE
46   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
49   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
50   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
51   * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
52   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53   * ====================================================================
54   * Contributor(s):
55  -----------------------------------------------------------------------------*/
56  
57  /**  Used when handling fo:table to hold information common to several builders
58   *  that collaborate to build the table.
59   *  @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
60   */
61  
62  //------------------------------------------------------------------------------
63  // $Id: TableContext.java,v 1.6 2003/06/29 22:31:02 pherweg Exp $
64  // $Log: TableContext.java,v $
65  // Revision 1.6  2003/06/29 22:31:02  pherweg
66  // support for number-rows-spanned added
67  //
68  // Revision 1.5  2002/08/12 09:40:02  bdelacretaz
69  // V0.7.1dev-e, contributions from Boris Poudérous for number-columns-spanned
70  // and vertical merging of tables cells.
71  //
72  // Revision 1.4  2002/07/12 08:08:31  bdelacretaz
73  // License changed to jfor Apache-style license
74  //
75  // Revision 1.3  2002/07/02 16:03:19  bdelacretaz
76  // patch from Trembicki-Guy, Ed <GuyE@DNB.com> to handle undefined table column widths
77  //
78  // Revision 1.2  2001/08/31 07:51:01  bdelacretaz
79  // MPL license text added + javadoc class comments corrected
80  //
81  // Revision 1.1  2001/08/29 13:27:51  bdelacretaz
82  // V0.4.1 - base package name changed to org.jfor.jfor
83  //
84  // Revision 1.1.1.1  2001/08/02 12:53:45  bdelacretaz
85  // initial SourceForge checkin of V0.1 code
86  //
87  //------------------------------------------------------------------------------
88  
89  class TableContext implements ITableColumnsInfo
90  {
91      private final BuilderContext m_context;
92      private final ArrayList m_colWidths = new ArrayList();
93      private int m_colIndex;
94      
95      /**
96       * Added by Peter Herweg on 2002-06-29
97       * This ArrayList contains one element for each column in the table.
98       * value == 0 means there is no row-spanning
99       * value >  0 means there is row-spanning
100      * Each value in the list is decreased by 1 after each finished table-row
101      */
102     private final ArrayList m_colRowSpanningNumber = new ArrayList(); 
103     
104     /**
105      * Added by Peter Herweg on 2002-06-29
106      * If there has a vertical merged cell to be created, its attributes are 
107      * inherited from the corresponding MERGE_START-cell.
108      * For this purpose the attributes of a cell are stored in this array, as soon
109      * as a number-rows-spanned attribute has been found.
110      */
111     private final ArrayList m_colRowSpanningAttrs = new ArrayList();  //Added by Peter Herweg on 2002-06-29
112     
113     TableContext(BuilderContext ctx)
114     {
115         m_context = ctx;
116     }
117 
118     void setNextColumnWidth(String strWidth)
119     throws ValueConversionException
120     {
121         m_colWidths.add(new Float(FoUnitsConverter.getInstance().convertToTwips(strWidth)));
122     }
123     
124     //Added by Peter Herweg on 2002-06-29
125     RtfAttributes getColumnRowSpanningAttrs()
126     {
127         return (RtfAttributes)m_colRowSpanningAttrs.get(m_colIndex);
128     }
129     
130     //Added by Peter Herweg on 2002-06-29
131     Integer getColumnRowSpanningNumber()
132     {
133         return (Integer)m_colRowSpanningNumber.get(m_colIndex);
134     }
135 
136     //Added by Peter Herweg on 2002-06-29
137     void setCurrentColumnRowSpanning(Integer iRowSpanning,  RtfAttributes attrs)
138     throws ValueConversionException
139     {
140         
141         if(m_colIndex<m_colRowSpanningNumber.size())
142         {
143             m_colRowSpanningNumber.set(m_colIndex, iRowSpanning);
144             m_colRowSpanningAttrs.set(m_colIndex, attrs);
145         }
146         else
147         {
148             m_colRowSpanningNumber.add(iRowSpanning);
149             m_colRowSpanningAttrs.add(m_colIndex, attrs);
150         }
151     }
152     
153     //Added by Peter Herweg on 2002-06-29
154     public void setNextColumnRowSpanning(Integer iRowSpanning,  RtfAttributes attrs)
155     {
156         m_colRowSpanningNumber.add(iRowSpanning);
157         m_colRowSpanningAttrs.add(m_colIndex, attrs);
158     }
159     
160     /**
161      * Added by Peter Herweg on 2002-06-29
162      * This function is called after each finished table-row.
163      * It decreases all values in m_colRowSpanningNumber by 1. If a value
164      * reaches 0 row-spanning is finished, and the value won't be decreased anymore.
165      */
166     public void decreaseRowSpannings()
167     {
168         for(int z=0;z<m_colRowSpanningNumber.size();++z)
169         {
170             Integer i=(Integer)m_colRowSpanningNumber.get(z);
171             
172             if(i.intValue()>0)
173                 i=new Integer(i.intValue()-1);
174                 
175             m_colRowSpanningNumber.set(z,i);
176             
177             if(i.intValue()==0)
178                 m_colRowSpanningAttrs.set(z,null);
179         }
180     }
181 
182     /** reset the column iteration index, meant to be called when creating a new row
183      * The 'public' modifier has been added by Boris Poudérous for 'number-columns-spanned' processing
184      */
185     public void selectFirstColumn()
186     {
187         m_colIndex = 0;
188     }
189 
190     /** increment the column iteration index
191      * The 'public' modifier has been added by Boris Poudérous for 'number-columns-spanned' processing
192      */
193     public void selectNextColumn()
194     {
195         m_colIndex++;
196     }
197 
198     /** get current column width according to column iteration index
199      *  @return INVALID_COLUMN_WIDTH if we cannot find the value
200      *  The 'public' modifier has been added by Boris Poudérous for 'number-columns-spanned' processing
201      */
202     public float getColumnWidth()
203     {
204         try {
205             return ((Float)m_colWidths.get(m_colIndex)).floatValue();
206   } catch (IndexOutOfBoundsException ex) {
207             // this code contributed by Trembicki-Guy, Ed <GuyE@DNB.com>
208             m_context.log.logWarning("fo:table-column width not defined,using " + INVALID_COLUM_WIDTH);
209             return INVALID_COLUM_WIDTH;
210         }
211     }
212 
213      /** Added by Boris Poudérous on 07/22/2002 */
214      public int getColumnIndex()
215      {
216        return m_colIndex;
217      }
218      /** - end - */
219 
220      /** Added by Boris Poudérous on 07/22/2002 */
221      public int getNumberOfColumns()
222      {
223        return m_colWidths.size();
224      }
225      /** - end - */
226 }
227