KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > flow > TableColumn


1 /*
2  * $Id: TableColumn.java,v 1.20.2.6 2003/04/11 00:24:39 pietsch Exp $
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.fo.flow;
52
53 // FOP
54
import org.apache.fop.fo.*;
55 import org.apache.fop.fo.properties.*;
56 import org.apache.fop.layout.*;
57 import org.apache.fop.apps.FOPException;
58 import org.apache.fop.datatypes.*;
59
60 public class TableColumn extends FObj {
61
62     Length columnWidthPropVal;
63     int columnWidth;
64     int columnOffset;
65     int numColumnsRepeated;
66     int iColumnNumber;
67
68     boolean setup = false;
69
70     AreaContainer areaContainer;
71
72     public static class Maker extends FObj.Maker {
73         public FObj make(FObj parent, PropertyList propertyList,
74                         String JavaDoc systemId, int line, int column)
75             throws FOPException {
76             return new TableColumn(parent, propertyList,
77                                    systemId, line, column);
78         }
79     }
80
81     public static FObj.Maker maker() {
82         return new TableColumn.Maker();
83     }
84
85     public TableColumn(FObj parent, PropertyList propertyList,
86                         String JavaDoc systemId, int line, int column)
87         throws FOPException {
88         super(parent, propertyList, systemId, line, column);
89         if (!(parent instanceof Table)) {
90             throw new FOPException("A table column must be child of fo:table, not "
91                                    + parent.getName(), systemId, line, column);
92         }
93     }
94
95     public String JavaDoc getName() {
96         return "fo:table-column";
97     }
98
99     public Length getColumnWidthAsLength() {
100         return columnWidthPropVal;
101     }
102
103     public int getColumnWidth() {
104         return columnWidth;
105     }
106
107     /**
108      * Set the column width value in base units which overrides the
109      * value from the column-width Property.
110      */

111     public void setColumnWidth(int columnWidth) {
112         this.columnWidth = columnWidth;
113     }
114
115     public int getColumnNumber() {
116         return iColumnNumber;
117     }
118
119     public int getNumColumnsRepeated() {
120         return numColumnsRepeated;
121     }
122
123     public void doSetup(Area area) throws FOPException {
124
125         // Common Border, Padding, and Background Properties
126
// only background apply, border apply if border-collapse
127
// is collapse.
128
BorderAndPadding bap = propMgr.getBorderAndPadding();
129         BackgroundProps bProps = propMgr.getBackgroundProps();
130
131         // this.properties.get("column-width");
132
// this.properties.get("number-columns-repeated");
133
// this.properties.get("number-columns-spanned");
134
// this.properties.get("visibility");
135

136         this.iColumnNumber =
137         this.properties.get("column-number").getNumber().intValue();
138
139         this.numColumnsRepeated =
140                 this.properties.get("number-columns-repeated").getNumber().intValue();
141
142         this.columnWidthPropVal =
143                 this.properties.get("column-width").getLength();
144         // This won't include resolved table-units or % values yet.
145
this.columnWidth = columnWidthPropVal.mvalue();
146
147         // initialize id
148
String JavaDoc id = this.properties.get("id").getString();
149         try {
150             area.getIDReferences().initializeID(id, area);
151         }
152         catch(FOPException e) {
153             if (!e.isLocationSet()) {
154                 e.setLocation(systemId, line, column);
155             }
156             throw e;
157         }
158
159         setup = true;
160     }
161
162     public int layout(Area area) throws FOPException {
163         if (this.marker == BREAK_AFTER) {
164             return Status.OK;
165         }
166
167         if (this.marker == START) {
168             if (!setup) {
169                 doSetup(area);
170             }
171         }
172         if (columnWidth > 0) {
173             this.areaContainer =
174                     new AreaContainer(propMgr.getFontState(area.getFontInfo()),
175                             columnOffset, 0, columnWidth,
176                             area.getContentHeight(), Position.RELATIVE);
177             areaContainer.foCreator = this; // G Seshadri
178
areaContainer.setPage(area.getPage());
179             areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding());
180             areaContainer.setBackground(propMgr.getBackgroundProps());
181             areaContainer.setHeight(area.getHeight());
182             area.addChild(areaContainer);
183         }
184         return Status.OK;
185     }
186
187     public void setColumnOffset(int columnOffset) {
188         this.columnOffset = columnOffset;
189     }
190
191     public void setHeight(int height) {
192         if (areaContainer != null) {
193             areaContainer.setMaxHeight(height);
194             areaContainer.setHeight(height);
195         }
196     }
197
198 }
199
Popular Tags