KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ListItem.java,v 1.16.2.8 2003/04/11 00:24:38 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.layout.*;
56 import org.apache.fop.layout.BlockArea;
57 import org.apache.fop.apps.FOPException;
58
59 public class ListItem extends FObj {
60
61     public static class Maker extends FObj.Maker {
62         public FObj make(FObj parent, PropertyList propertyList,
63                          String JavaDoc systemId, int line, int column)
64             throws FOPException {
65             return new ListItem(parent, propertyList, systemId, line, column);
66         }
67
68     }
69
70     public static FObj.Maker maker() {
71         return new ListItem.Maker();
72     }
73
74     int align;
75     int alignLast;
76     int breakBefore;
77     int breakAfter;
78     int lineHeight;
79     int startIndent;
80     int endIndent;
81     int spaceBefore;
82     int spaceAfter;
83     String JavaDoc id;
84     BlockArea blockArea;
85
86     public ListItem(FObj parent, PropertyList propertyList,
87                     String JavaDoc systemId, int line, int column) {
88         super(parent, propertyList, systemId, line, column);
89     }
90
91     public String JavaDoc getName() {
92         return "fo:list-item";
93     }
94
95     public int layout(Area area) throws FOPException {
96         if (this.marker == START) {
97
98             // Common Accessibility Properties
99
AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
100
101             // Common Aural Properties
102
AuralProps mAurProps = propMgr.getAuralProps();
103
104             // Common Border, Padding, and Background Properties
105
BorderAndPadding bap = propMgr.getBorderAndPadding();
106             BackgroundProps bProps = propMgr.getBackgroundProps();
107
108             // Common Margin Properties-Block
109
MarginProps mProps = propMgr.getMarginProps();
110
111             // Common Relative Position Properties
112
RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
113
114             // this.properties.get("break-after");
115
// this.properties.get("break-before");
116
// this.properties.get("id");
117
// this.properties.get("keep-together");
118
// this.properties.get("keep-with-next");
119
// this.properties.get("keep-with-previous");
120
// this.properties.get("relative-align");
121

122             this.align = this.properties.get("text-align").getEnum();
123             this.alignLast = this.properties.get("text-align-last").getEnum();
124             this.lineHeight =
125                 this.properties.get("line-height").getLength().mvalue();
126             this.spaceBefore =
127                 this.properties.get("space-before.optimum").getLength().mvalue();
128             this.spaceAfter =
129                 this.properties.get("space-after.optimum").getLength().mvalue();
130             this.id = this.properties.get("id").getString();
131
132             try {
133                 area.getIDReferences().createID(id);
134             }
135             catch(FOPException e) {
136                 if (!e.isLocationSet()) {
137                     e.setLocation(systemId, line, column);
138                 }
139                 throw e;
140             }
141
142             this.marker = 0;
143         }
144
145         /* not sure this is needed given we know area is from list block */
146         if (area instanceof BlockArea) {
147             area.end();
148         }
149
150         if (spaceBefore != 0) {
151             area.addDisplaySpace(spaceBefore);
152         }
153
154         this.blockArea =
155             new BlockArea(propMgr.getFontState(area.getFontInfo()),
156                           area.getAllocationWidth(), area.spaceLeft(), 0, 0,
157                           0, align, alignLast, lineHeight);
158
159         // Fix links in lists in tables problem
160
blockArea.setTableCellXOffset(area.getTableCellXOffset());
161
162         this.blockArea.setGeneratedBy(this);
163         this.areasGenerated++;
164         if (this.areasGenerated == 1)
165             this.blockArea.isFirst(true);
166             // for normal areas this should be the only pair
167
// this.blockArea.addLineagePair(this, this.areasGenerated);
168

169         // markers
170
// if (this.hasMarkers())
171
// this.blockArea.addMarkers(this.getMarkers());
172

173         blockArea.setParent(area);
174         blockArea.setPage(area.getPage());
175         blockArea.start();
176
177         blockArea.setAbsoluteHeight(area.getAbsoluteHeight());
178         blockArea.setIDReferences(area.getIDReferences());
179
180         int numChildren = this.children.size();
181         if (numChildren != 2) {
182             throw new FOPException("list-item must have exactly two children",
183                                    systemId, line, column);
184         }
185         ListItemLabel label = (ListItemLabel)children.get(0);
186         ListItemBody body = (ListItemBody)children.get(1);
187
188         int status;
189
190         // what follows doesn't yet take into account whether the
191
// body failed completely or only got some text in
192

193         if (this.marker == 0) {
194             // configure id
195
area.getIDReferences().configureID(id, area);
196
197             status = label.layout(blockArea);
198             if (Status.isIncomplete(status)) {
199                 return status;
200             }
201         }
202
203         status = body.layout(blockArea);
204         if (Status.isIncomplete(status)) {
205             blockArea.end();
206             area.addChild(blockArea);
207             area.increaseHeight(blockArea.getHeight());
208             this.marker = 1;
209             return status;
210         }
211
212         blockArea.end();
213         area.addChild(blockArea);
214         area.increaseHeight(blockArea.getHeight());
215
216         if (spaceAfter != 0) {
217             area.addDisplaySpace(spaceAfter);
218         }
219
220         /* not sure this is needed given we know area is from list block */
221         if (area instanceof BlockArea) {
222             area.start();
223         }
224         this.blockArea.isLast(true);
225         return Status.OK;
226     }
227
228     /**
229      * Return the content width of the boxes generated by this FO.
230      */

231     public int getContentWidth() {
232         if (blockArea != null)
233             return blockArea.getContentWidth(); // getAllocationWidth()??
234
else
235             return 0; // not laid out yet
236
}
237
238 }
239
Popular Tags