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: TableColumn.java 488960 2006-12-20 08:34:28Z spepping $ */
019:
020: package org.apache.fop.fo.flow;
021:
022: // XML
023: import org.xml.sax.Locator;
024:
025: import org.apache.fop.apps.FOPException;
026: import org.apache.fop.datatypes.Length;
027: import org.apache.fop.fo.FONode;
028: import org.apache.fop.fo.PropertyList;
029: import org.apache.fop.fo.ValidationException;
030: import org.apache.fop.fo.expr.PropertyException;
031: import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
032: import org.apache.fop.fo.properties.Property;
033: import org.apache.fop.fo.properties.TableColLength;
034:
035: /**
036: * Class modelling the fo:table-column object.
037: */
038: public class TableColumn extends TableFObj {
039: // The value of properties relevant for fo:table-column.
040: private CommonBorderPaddingBackground commonBorderPaddingBackground;
041: private int columnNumber;
042: private Length columnWidth;
043: private int numberColumnsRepeated;
044: private int numberColumnsSpanned;
045: // Unused but valid items, commented out for performance:
046: // private int visibility;
047: // End of property values
048:
049: private boolean defaultColumn;
050: private PropertyList pList = null;
051:
052: /**
053: * @param parent FONode that is the parent of this object
054: */
055: public TableColumn(FONode parent) {
056: this (parent, false);
057: }
058:
059: /**
060: * @param parent FONode that is the parent of this object
061: * @param defaultColumn true if this table-column has been manually created as a default column
062: */
063: public TableColumn(FONode parent, boolean defaultColumn) {
064: super (parent);
065: this .defaultColumn = defaultColumn;
066: }
067:
068: /**
069: * @see org.apache.fop.fo.FObj#bind(PropertyList)
070: */
071: public void bind(PropertyList pList) throws FOPException {
072: commonBorderPaddingBackground = pList
073: .getBorderPaddingBackgroundProps();
074: columnNumber = pList.get(PR_COLUMN_NUMBER).getNumeric()
075: .getValue();
076: columnWidth = pList.get(PR_COLUMN_WIDTH).getLength();
077: numberColumnsRepeated = pList.get(PR_NUMBER_COLUMNS_REPEATED)
078: .getNumeric().getValue();
079: numberColumnsSpanned = pList.get(PR_NUMBER_COLUMNS_SPANNED)
080: .getNumeric().getValue();
081: super .bind(pList);
082:
083: if (numberColumnsRepeated <= 0) {
084: throw new PropertyException(
085: "number-columns-repeated must be 1 or bigger, "
086: + "but got " + numberColumnsRepeated);
087: }
088: if (numberColumnsSpanned <= 0) {
089: throw new PropertyException(
090: "number-columns-spanned must be 1 or bigger, "
091: + "but got " + numberColumnsSpanned);
092: }
093:
094: /* check for unspecified width and replace with default of
095: * proportional-column-width(1), in case of fixed table-layout
096: * warn only for explicit columns
097: */
098: if (columnWidth.getEnum() == EN_AUTO) {
099: if (!this .defaultColumn && !getTable().isAutoLayout()) {
100: log
101: .warn("table-layout=\"fixed\" and column-width unspecified "
102: + "=> falling back to proportional-column-width(1)");
103: }
104: columnWidth = new TableColLength(1.0, this );
105: }
106:
107: /* in case of explicit columns, from-table-column()
108: * can be used on descendants of the table-cells, so
109: * we need a reference to the column's property list
110: * (cleared in Table.endOfNode())
111: */
112: if (!this .defaultColumn) {
113: this .pList = pList;
114: }
115: }
116:
117: /**
118: * @see org.apache.fop.fo.FONode#startOfNode()
119: */
120: protected void startOfNode() throws FOPException {
121: getFOEventHandler().startColumn(this );
122: }
123:
124: /**
125: * @see org.apache.fop.fo.FONode#endOfNode
126: */
127: protected void endOfNode() throws FOPException {
128: getFOEventHandler().endColumn(this );
129: }
130:
131: /**
132: * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
133: * XSL Content Model: empty
134: */
135: protected void validateChildNode(Locator loc, String nsURI,
136: String localName) throws ValidationException {
137: invalidChildError(loc, nsURI, localName);
138: }
139:
140: /**
141: * @return the Common Border, Padding, and Background Properties.
142: */
143: public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
144: return commonBorderPaddingBackground;
145: }
146:
147: /**
148: * @return the "column-width" property.
149: */
150: public Length getColumnWidth() {
151: return columnWidth;
152: }
153:
154: /**
155: * Sets the column width.
156: * @param columnWidth the column width
157: */
158: public void setColumnWidth(Length columnWidth) {
159: this .columnWidth = columnWidth;
160: }
161:
162: /**
163: * @return the "column-number" property.
164: */
165: public int getColumnNumber() {
166: return columnNumber;
167: }
168:
169: /**
170: * Used for setting the column-number for an implicit column
171: * @param columnNumber
172: */
173: protected void setColumnNumber(int columnNumber) {
174: this .columnNumber = columnNumber;
175: }
176:
177: /** @return value for number-columns-repeated. */
178: public int getNumberColumnsRepeated() {
179: return numberColumnsRepeated;
180: }
181:
182: /** @return value for number-columns-spanned. */
183: public int getNumberColumnsSpanned() {
184: return numberColumnsSpanned;
185: }
186:
187: /** @see org.apache.fop.fo.FONode#getLocalName() */
188: public String getLocalName() {
189: return "table-column";
190: }
191:
192: /** @see org.apache.fop.fo.FObj#getNameId() */
193: public int getNameId() {
194: return FO_TABLE_COLUMN;
195: }
196:
197: /**
198: * Indicates whether this table-column has been created as
199: * default column for this table in case no table-columns
200: * have been defined.
201: * Note that this only used to provide better
202: * user feedback (see ColumnSetup).
203: * @return true if this table-column has been created as default column
204: */
205: public boolean isDefaultColumn() {
206: return defaultColumn;
207: }
208:
209: /** @see java.lang.Object#toString() */
210: public String toString() {
211: StringBuffer sb = new StringBuffer("fo:table-column");
212: sb.append(" column-number=").append(getColumnNumber());
213: if (getNumberColumnsRepeated() > 1) {
214: sb.append(" number-columns-repeated=").append(
215: getNumberColumnsRepeated());
216: }
217: if (getNumberColumnsSpanned() > 1) {
218: sb.append(" number-columns-spanned=").append(
219: getNumberColumnsSpanned());
220: }
221: sb.append(" column-width=").append(getColumnWidth());
222: return sb.toString();
223: }
224:
225: /**
226: * Retrieve a property value through its Id; used by
227: * from-table-column() function
228: *
229: * @param propId the id for the property to retrieve
230: * @return the requested Property
231: * @throws PropertyException
232: */
233: public Property getProperty(int propId) throws PropertyException {
234: return this .pList.get(propId);
235: }
236:
237: /**
238: * Clear the reference to the PropertyList (retained for
239: * from-table-column())
240: */
241: protected void releasePropertyList() {
242: this.pList = null;
243: }
244: }
|