KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > extensions > ContinuedLabel


1 /*
2  * $Id: ContinuedLabel.java,v 1.1.2.3 2003/04/11 00:24:37 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.extensions;
52
53 import org.apache.fop.apps.FOPException;
54 import org.apache.fop.datatypes.IDReferences;
55 import org.apache.fop.fo.FObj;
56 import org.apache.fop.fo.FONode;
57 import org.apache.fop.fo.PropertyList;
58 import org.apache.fop.fo.Status;
59 import org.apache.fop.layout.Area;
60 import org.apache.fop.layout.AreaTree;
61
62 /**
63  * Implement continued labels for table header/footer.
64  * Content of this element must be an fo:inline.
65  */

66 public class ContinuedLabel extends ExtensionObj {
67
68     private FObj containingTable=null;
69
70     public static class Maker extends FObj.Maker {
71         public FObj make(FObj parent, PropertyList propertyList,
72                          String JavaDoc systemId, int line, int column)
73             throws FOPException {
74             return new ContinuedLabel(parent, propertyList,
75                                       systemId, line, column);
76         }
77
78     }
79
80     public static FObj.Maker maker() {
81         return new ContinuedLabel.Maker();
82     }
83
84     public ContinuedLabel(FObj parent, PropertyList propertyList,
85                           String JavaDoc systemId, int line, int column) {
86         super(parent, propertyList, systemId, line, column);
87
88         // Find ancestor table
89
for (; parent!=null ; parent = parent.getParent()) {
90             if (parent.getName().equals("fo:table")) {
91                 this.containingTable=parent;
92                 break;
93             }
94         }
95     }
96
97
98     public String JavaDoc getName() {
99         return "fop:continued-label";
100     }
101
102
103     /**
104      * If we are within a cell in a table-header or table-footer object
105      * and this is not the first generated area for the table, then generate
106      * an inline area and put the content in it.
107      * @param area The parent area.
108      * @return Value indicating where all, some or none of the content
109      * was placed in the current parent area.
110      */

111     public int layout(Area area) throws FOPException {
112         if (this.marker == START) {
113             this.marker = 0;
114         }
115
116         // See if ancestor table has generated any areas yet.
117
// Note: areasGenerated was already public so I use it, but this
118
// is definitely not very good style!
119
if (containingTable!=null && containingTable.areasGenerated > 0) {
120             int numChildren = this.children.size();
121             for (int i = this.marker; i < numChildren; i++) {
122                 FONode fo = (FONode)children.get(i);
123                 int status;
124                 if (Status.isIncomplete(status = fo.layout(area))) {
125                     this.marker = i;
126                     return status;
127                 }
128             }
129         }
130         return Status.OK;
131     }
132
133     /**
134      * Null implementation.
135      */

136     public void format(AreaTree areaTree) throws FOPException {
137     }
138
139     /**
140      * Removes property id from IDReferences.
141      * This overrides the generic FObj function since ID has no meaning
142      * on a continued-label. However, for now, it propagates to its children
143      * since we don't prevent them from creating IDs. This should probably be
144      * fixed!
145      * @param idReferences the id to remove
146      */

147     public void removeID(IDReferences idReferences) {
148         int numChildren = this.children.size();
149         for (int i = 0; i < numChildren; i++) {
150             FONode child = (FONode)children.get(i);
151             if ((child instanceof FObj)) {
152                 ((FObj)child).removeID(idReferences);
153             }
154         }
155     }
156 }
157
Popular Tags