KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > layoutmgr > table > EffRow


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: EffRow.java 478928 2006-11-24 17:32:48Z vhennebert $ */
19
20 package org.apache.fop.layoutmgr.table;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.apache.fop.fo.flow.TableRow;
26 import org.apache.fop.traits.MinOptMax;
27
28 /**
29  * This class represents an effective row in a table and holds a list of grid units occupying
30  * the row as well as some additional values.
31  */

32 class EffRow {
33     
34     /** Indicates that the row is the first in a table-body */
35     public static final int FIRST_IN_PART = GridUnit.FIRST_IN_PART;
36     /** Indicates that the row is the last in a table-body */
37     public static final int LAST_IN_PART = GridUnit.LAST_IN_PART;
38     
39     private List JavaDoc gridUnits = new java.util.ArrayList JavaDoc();
40     private int index;
41     /** One of HEADER, FOOTER, BODY */
42     private int bodyType;
43     private MinOptMax height;
44     private MinOptMax explicitHeight;
45     
46     /**
47      * Creates a new effective row instance.
48      * @param index index of the row
49      * @param bodyType type of body (one of HEADER, FOOTER, BODY as found on TableRowIterator)
50      */

51     public EffRow(int index, int bodyType) {
52         this.index = index;
53         this.bodyType = bodyType;
54     }
55     
56     /** @return the index of the EffRow in the sequence of rows */
57     public int getIndex() {
58         return this.index;
59     }
60     
61     /**
62      * @return an indicator what type of body this EffRow is in (one of HEADER, FOOTER, BODY
63      * as found on TableRowIterator)
64      */

65     public int getBodyType() {
66         return this.bodyType;
67     }
68     
69     /** @return the table-row FO for this EffRow, or null if there is no table-row. */
70     public TableRow getTableRow() {
71         return getGridUnit(0).getRow();
72     }
73     
74     /** @return the calculated height for this EffRow. */
75     public MinOptMax getHeight() {
76         return this.height;
77     }
78     
79     /**
80      * Sets the calculated height for this EffRow.
81      * @param mom the calculated height
82      */

83     public void setHeight(MinOptMax mom) {
84         this.height = mom;
85     }
86     
87     /** @return the explicit height of the EffRow (as specified through properties) */
88     public MinOptMax getExplicitHeight() {
89         return this.explicitHeight;
90     }
91     
92     /**
93      * Sets the height for this row that resulted from the explicit height properties specified
94      * by the user.
95      * @param mom the height
96      */

97     public void setExplicitHeight(MinOptMax mom) {
98         this.explicitHeight = mom;
99     }
100     
101     /** @return the list of GridUnits for this EffRow */
102     public List JavaDoc getGridUnits() {
103         return gridUnits;
104     }
105     
106     /**
107      * Returns the grid unit at a given position.
108      * @param column index of the grid unit in the row (zero based)
109      * @return the requested grid unit.
110      */

111     public GridUnit getGridUnit(int column) {
112         return (GridUnit)gridUnits.get(column);
113     }
114     
115     /**
116      * Returns the grid unit at a given position. In contrast to getGridUnit() this
117      * method returns null if there's no grid unit at the given position. The number of
118      * grid units for row x can be smaller than the number of grid units for row x-1.
119      * @param column index of the grid unit in the row (zero based)
120      * @return the requested grid unit or null if there's no grid unit at this position.
121      */

122     public GridUnit safelyGetGridUnit(int column) {
123         if (column < gridUnits.size()) {
124             return (GridUnit)gridUnits.get(column);
125         } else {
126             return null;
127         }
128     }
129     
130     /**
131      * Sets a flag on all grid units of this effective row.
132      * @param flag which flag to set (on of the GridUnit.* constants)
133      * @param value new value for the flag
134      */

135     public void setFlagForAllGridUnits(int flag, boolean value) {
136         Iterator JavaDoc iter = gridUnits.iterator();
137         while (iter.hasNext()) {
138             GridUnit gu = (GridUnit)iter.next();
139             gu.setFlag(flag, value);
140         }
141     }
142
143     /**
144      * Returns a flag for this effective row. Only a subset of the flags on GridUnit is supported.
145      * The flag is determined by inspecting flags on the EffRow's GridUnits.
146      * @param which the requested flag (one of {@link EffRow#FIRST_IN_PART} or {@link
147      * EffRow#LAST_IN_PART})
148      * @return true if the flag is set
149      */

150     public boolean getFlag(int which) {
151         if (which == FIRST_IN_PART) {
152             return getGridUnit(0).getFlag(GridUnit.FIRST_IN_PART);
153         } else if (which == LAST_IN_PART) {
154             return getGridUnit(0).getFlag(GridUnit.LAST_IN_PART);
155         } else {
156             throw new IllegalArgumentException JavaDoc("Illegal flag queried: " + which);
157         }
158     }
159     
160     /** @see java.lang.Object#toString() */
161     public String JavaDoc toString() {
162         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("EffRow {");
163         sb.append(index);
164         if (getBodyType() == TableRowIterator.BODY) {
165             sb.append(" in body");
166         } else if (getBodyType() == TableRowIterator.HEADER) {
167             sb.append(" in header");
168         } else {
169             sb.append(" in footer");
170         }
171         sb.append(", ").append(height);
172         sb.append(", ").append(explicitHeight);
173         sb.append(", ").append(gridUnits.size()).append(" gu");
174         sb.append("}");
175         return sb.toString();
176     }
177 }
178
Popular Tags