KickJava   Java API By Example, From Geeks To Geeks.

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


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: CondLengthProperty.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.datatypes.CompoundDatatype;
23 import org.apache.fop.datatypes.Length;
24 import org.apache.fop.datatypes.PercentBaseContext;
25 import org.apache.fop.fo.Constants;
26 import org.apache.fop.fo.FObj;
27 import org.apache.fop.fo.PropertyList;
28 import org.apache.fop.fo.expr.PropertyException;
29
30 /**
31  * Superclass for properties that have conditional lengths
32  */

33 public class CondLengthProperty extends Property implements CompoundDatatype {
34     private Property length;
35     private Property conditionality;
36
37     /**
38      * Inner class for creating instances of CondLengthProperty
39      */

40     public static class Maker extends CompoundPropertyMaker {
41
42         /**
43          * @param propId the id of the property for which a Maker should be created
44          */

45         public Maker(int propId) {
46             super(propId);
47         }
48
49         /**
50          * Create a new empty instance of CondLengthProperty.
51          * @return the new instance.
52          */

53         public Property makeNewProperty() {
54             return new CondLengthProperty();
55         }
56
57         /**
58          * @see CompoundPropertyMaker#convertProperty
59          */

60         public Property convertProperty(Property p, PropertyList propertyList, FObj fo)
61                     throws PropertyException {
62             if (p instanceof KeepProperty) {
63                 return p;
64             }
65             return super.convertProperty(p, propertyList, fo);
66         }
67     }
68
69     /**
70      * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean)
71      */

72     public void setComponent(int cmpId, Property cmpnValue,
73                              boolean bIsDefault) {
74         if (cmpId == CP_LENGTH) {
75             length = cmpnValue;
76         } else if (cmpId == CP_CONDITIONALITY) {
77             conditionality = cmpnValue;
78         }
79     }
80
81     /**
82      * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int)
83      */

84     public Property getComponent(int cmpId) {
85         if (cmpId == CP_LENGTH) {
86             return length;
87         } else if (cmpId == CP_CONDITIONALITY) {
88             return conditionality;
89         } else {
90             return null;
91         }
92     }
93
94     /**
95      * Returns the conditionality.
96      * @return the conditionality
97      */

98     public Property getConditionality() {
99         return this.conditionality;
100     }
101
102     /**
103      * Returns the length.
104      * @return the length
105      */

106     public Property getLengthComponent() {
107         return this.length;
108     }
109
110     /**
111      * Indicates if the length can be discarded on certain conditions.
112      * @return true if the length can be discarded.
113      */

114     public boolean isDiscard() {
115         return this.conditionality.getEnum() == Constants.EN_DISCARD;
116     }
117
118     /**
119      * Returns the computed length value.
120      * @return the length in millipoints
121      */

122     public int getLengthValue() {
123         return this.length.getLength().getValue();
124     }
125
126     /**
127      * Returns the computed length value.
128      * @param context The context for the length calculation (for percentage based lengths)
129      * @return the length in millipoints
130      */

131     public int getLengthValue(PercentBaseContext context) {
132         return this.length.getLength().getValue(context);
133     }
134
135     /** @see java.lang.Object#toString() */
136     public String JavaDoc toString() {
137         return "CondLength[" + length.getObject().toString()
138                 + ", " + (isDiscard()
139                         ? conditionality.toString().toLowerCase()
140                         : conditionality.toString()) + "]";
141     }
142
143     /**
144      * @return this.condLength
145      */

146     public CondLengthProperty getCondLength() {
147         return this;
148     }
149
150     /**
151      * TODO: Should we allow this?
152      * @return this.condLength cast as a Length
153      */

154     public Length getLength() {
155         return length.getLength();
156     }
157
158     /**
159      * @return this.condLength cast as an Object
160      */

161     public Object JavaDoc getObject() {
162         return this;
163     }
164
165 }
166
Popular Tags