KickJava   Java API By Example, From Geeks To Geeks.

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


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: LengthProperty.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.datatypes.Length;
23 import org.apache.fop.datatypes.Numeric;
24 import org.apache.fop.fo.FObj;
25 import org.apache.fop.fo.PropertyList;
26 import org.apache.fop.fo.expr.PropertyException;
27
28 /**
29  * Superclass for properties wrapping a Length value.
30  */

31 public abstract class LengthProperty extends Property
32     implements Length, Numeric {
33     
34     /**
35      * Inner class for making instances of LengthProperty
36      */

37     public static class Maker extends PropertyMaker {
38
39         /**
40          * @param propId the id of the property for which a Maker should be created
41          */

42         public Maker(int propId) {
43             super(propId);
44         }
45
46         /**
47          * @see org.apache.fop.fo.properties.PropertyMaker#convertProperty(
48          * org.apache.fop.fo.properties.Property, org.apache.fop.fo.PropertyList,
49          * org.apache.fop.fo.FObj)
50          */

51         public Property convertProperty(Property p,
52                                         PropertyList propertyList,
53                                         FObj fo) throws PropertyException {
54             if (p instanceof EnumProperty) {
55                 return new EnumLength(p);
56             }
57             if (p instanceof LengthProperty) {
58                 return p;
59             }
60             if (p instanceof NumberProperty) {
61                 //Assume pixels (like in HTML) when there's no unit
62
return new FixedLength(p.getNumeric().getNumericValue(), "px");
63             }
64             Length val = p.getLength();
65             if (val != null) {
66                 return (Property) val;
67             }
68             /* always null ?? */
69             return convertPropertyDatatype(p, propertyList, fo);
70         }
71
72     }
73
74     /**
75      * Return the number of table units which are included in this
76      * length specification.
77      * This will always be 0 unless the property specification used
78      * the proportional-column-width() function (only only table
79      * column FOs).
80      * <p>If this value is not 0, the actual value of the Length cannot
81      * be known without looking at all of the columns in the table to
82      * determine the value of a "table-unit".
83      * @return The number of table units which are included in this
84      * length specification.
85      */

86     public double getTableUnits() {
87         return 0.0;
88     }
89
90     /**
91      * @return the numeric dimension. Length always a dimension of 1.
92      */

93     public int getDimension() {
94         return 1;
95     }
96
97     /**
98      * @return this.length cast as a Numeric
99      */

100     public Numeric getNumeric() {
101         return this;
102     }
103
104     /**
105      * @return this.length
106      */

107     public Length getLength() {
108         return this;
109     }
110
111     /**
112      * @return this.length cast as an Object
113      */

114     public Object JavaDoc getObject() {
115         return this;
116     }
117
118 }
119
120
Popular Tags