KickJava   Java API By Example, From Geeks To Geeks.

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


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: SpaceProperty.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.fo.Constants;
23 import org.apache.fop.fo.FObj;
24 import org.apache.fop.fo.PropertyList;
25 import org.apache.fop.fo.expr.PropertyException;
26
27 /**
28  * Base class used for handling properties of the fo:space-before and
29  * fo:space-after variety. It is extended by org.apache.fop.fo.properties.GenericSpace,
30  * which is extended by many other properties.
31  */

32 public class SpaceProperty extends LengthRangeProperty {
33     private Property precedence;
34     private Property conditionality;
35
36     /**
37      * Inner class used to create new instances of SpaceProperty
38      */

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

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

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

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

74     public void setComponent(int cmpId, Property cmpnValue,
75                              boolean bIsDefault) {
76         if (cmpId == CP_PRECEDENCE) {
77             setPrecedence(cmpnValue, bIsDefault);
78         } else if (cmpId == CP_CONDITIONALITY) {
79             setConditionality(cmpnValue, bIsDefault);
80         } else {
81             super.setComponent(cmpId, cmpnValue, bIsDefault);
82         }
83     }
84
85     /**
86      * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int)
87      */

88     public Property getComponent(int cmpId) {
89         if (cmpId == CP_PRECEDENCE) {
90             return getPrecedence();
91         } else if (cmpId == CP_CONDITIONALITY) {
92             return getConditionality();
93         } else {
94             return super.getComponent(cmpId);
95         }
96     }
97
98     /**
99      *
100      * @param precedence precedence Property to set
101      * @param bIsDefault (is not used anywhere)
102      */

103     protected void setPrecedence(Property precedence, boolean bIsDefault) {
104         this.precedence = precedence;
105     }
106
107     /**
108      *
109      * @param conditionality conditionality Property to set
110      * @param bIsDefault (is not used anywhere)
111      */

112     protected void setConditionality(Property conditionality,
113                                      boolean bIsDefault) {
114         this.conditionality = conditionality;
115     }
116
117     /**
118      * @return precedence Property
119      */

120     public Property getPrecedence() {
121         return this.precedence;
122     }
123
124     /**
125      * @return conditionality Property
126      */

127     public Property getConditionality() {
128         return this.conditionality;
129     }
130
131     /**
132      * Indicates if the length can be discarded on certain conditions.
133      * @return true if the length can be discarded.
134      */

135     public boolean isDiscard() {
136         return this.conditionality.getEnum() == Constants.EN_DISCARD;
137     }
138
139     public String JavaDoc toString() {
140         return "Space[" +
141         "min:" + getMinimum(null).getObject() +
142         ", max:" + getMaximum(null).getObject() +
143         ", opt:" + getOptimum(null).getObject() +
144         ", precedence:" + precedence.getObject() +
145         ", conditionality:" + conditionality.getObject() + "]";
146     }
147
148     /**
149      * @return the Space (datatype) object contained here
150      */

151     public SpaceProperty getSpace() {
152         return this;
153     }
154
155     /**
156      * Space extends LengthRange.
157      * @return the Space (datatype) object contained here
158      */

159     public LengthRangeProperty getLengthRange() {
160         return this;
161     }
162
163     /**
164      * @return the Space (datatype) object contained here
165      */

166     public Object JavaDoc getObject() {
167         return this;
168     }
169
170 }
171
Popular Tags