KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > properties > TableColLength


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: TableColLength.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.datatypes.LengthBase;
23 import org.apache.fop.datatypes.PercentBaseContext;
24 import org.apache.fop.fo.FObj;
25
26 /**
27  * A table-column width specification, possibly including some
28  * number of proportional "column-units". The absolute size of a
29  * column-unit depends on the fixed and proportional sizes of all
30  * columns in the table, and on the overall size of the table.
31  * It can't be calculated until all columns have been specified and until
32  * the actual width of the table is known. Since this can be specified
33  * as a percent of its parent containing width, the calculation is done
34  * during layout.
35  * NOTE: this is only supposed to be allowed if table-layout=fixed.
36  */

37 public class TableColLength extends LengthProperty {
38     /**
39      * Number of table-column proportional units
40      */

41     private double tcolUnits;
42
43     /**
44      * The column the column-units are defined on.
45      */

46     private FObj column;
47
48     /**
49      * Construct an object with tcolUnits of proportional measure.
50      * @param tcolUnits number of table-column proportional units
51      * @param column the column the column-units are defined on
52      */

53     public TableColLength(double tcolUnits, FObj column) {
54         this.tcolUnits = tcolUnits;
55         this.column = column;
56     }
57
58     /**
59      * Override the method in Length
60      * @return the number of specified proportional table-column units.
61      */

62     public double getTableUnits() {
63         return tcolUnits;
64     }
65
66     /**
67      * Return false because table-col-units are a relative numeric.
68      * @see org.apache.fop.datatypes.Numeric#isAbsolute()
69      */

70     public boolean isAbsolute() {
71         return false;
72     }
73
74     /**
75      * Return the value as a numeric value.
76      * @see org.apache.fop.datatypes.Numeric#getNumericValue()
77      */

78     public double getNumericValue() {
79         throw new UnsupportedOperationException JavaDoc(
80                 "Must call getNumericValue with PercentBaseContext");
81     }
82
83     /**
84      * @see org.apache.fop.datatypes.Numeric#getNumericValue(PercentBaseContext)
85      */

86     public double getNumericValue(PercentBaseContext context) {
87         return tcolUnits * context.getBaseLength(LengthBase.TABLE_UNITS, column);
88     }
89
90     /**
91      * Return the value as a length.
92      * @see org.apache.fop.datatypes.Length#getValue()
93      */

94     public int getValue() {
95         throw new UnsupportedOperationException JavaDoc(
96                 "Must call getValue with PercentBaseContext");
97     }
98
99     /**
100      * @see org.apache.fop.datatypes.Numeric#getValue(PercentBaseContext)
101      */

102     public int getValue(PercentBaseContext context) {
103         return (int) (tcolUnits * context.getBaseLength(LengthBase.TABLE_UNITS, column));
104     }
105
106     /**
107      * Convert this to a String
108      * @return the string representation of this
109      */

110     public String JavaDoc toString() {
111         return (Double.toString(tcolUnits) + " table-column-units");
112     }
113
114 }
115
Popular Tags