001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: EffRow.java 478928 2006-11-24 17:32:48Z vhennebert $ */
019:
020: package org.apache.fop.layoutmgr.table;
021:
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.apache.fop.fo.flow.TableRow;
026: import org.apache.fop.traits.MinOptMax;
027:
028: /**
029: * This class represents an effective row in a table and holds a list of grid units occupying
030: * the row as well as some additional values.
031: */
032: class EffRow {
033:
034: /** Indicates that the row is the first in a table-body */
035: public static final int FIRST_IN_PART = GridUnit.FIRST_IN_PART;
036: /** Indicates that the row is the last in a table-body */
037: public static final int LAST_IN_PART = GridUnit.LAST_IN_PART;
038:
039: private List gridUnits = new java.util.ArrayList();
040: private int index;
041: /** One of HEADER, FOOTER, BODY */
042: private int bodyType;
043: private MinOptMax height;
044: private MinOptMax explicitHeight;
045:
046: /**
047: * Creates a new effective row instance.
048: * @param index index of the row
049: * @param bodyType type of body (one of HEADER, FOOTER, BODY as found on TableRowIterator)
050: */
051: public EffRow(int index, int bodyType) {
052: this .index = index;
053: this .bodyType = bodyType;
054: }
055:
056: /** @return the index of the EffRow in the sequence of rows */
057: public int getIndex() {
058: return this .index;
059: }
060:
061: /**
062: * @return an indicator what type of body this EffRow is in (one of HEADER, FOOTER, BODY
063: * as found on TableRowIterator)
064: */
065: public int getBodyType() {
066: return this .bodyType;
067: }
068:
069: /** @return the table-row FO for this EffRow, or null if there is no table-row. */
070: public TableRow getTableRow() {
071: return getGridUnit(0).getRow();
072: }
073:
074: /** @return the calculated height for this EffRow. */
075: public MinOptMax getHeight() {
076: return this .height;
077: }
078:
079: /**
080: * Sets the calculated height for this EffRow.
081: * @param mom the calculated height
082: */
083: public void setHeight(MinOptMax mom) {
084: this .height = mom;
085: }
086:
087: /** @return the explicit height of the EffRow (as specified through properties) */
088: public MinOptMax getExplicitHeight() {
089: return this .explicitHeight;
090: }
091:
092: /**
093: * Sets the height for this row that resulted from the explicit height properties specified
094: * by the user.
095: * @param mom the height
096: */
097: public void setExplicitHeight(MinOptMax mom) {
098: this .explicitHeight = mom;
099: }
100:
101: /** @return the list of GridUnits for this EffRow */
102: public List 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 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("Illegal flag queried: "
157: + which);
158: }
159: }
160:
161: /** @see java.lang.Object#toString() */
162: public String toString() {
163: StringBuffer sb = new StringBuffer("EffRow {");
164: sb.append(index);
165: if (getBodyType() == TableRowIterator.BODY) {
166: sb.append(" in body");
167: } else if (getBodyType() == TableRowIterator.HEADER) {
168: sb.append(" in header");
169: } else {
170: sb.append(" in footer");
171: }
172: sb.append(", ").append(height);
173: sb.append(", ").append(explicitHeight);
174: sb.append(", ").append(gridUnits.size()).append(" gu");
175: sb.append("}");
176: return sb.toString();
177: }
178: }
|