KickJava   Java API By Example, From Geeks To Geeks.

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


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: LengthPairProperty.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.fo.FObj;
24 import org.apache.fop.fo.PropertyList;
25 import org.apache.fop.fo.expr.PropertyException;
26
27 /**
28  * Superclass for properties wrapping a LengthPair value
29  */

30 public class LengthPairProperty extends Property implements CompoundDatatype {
31     private Property ipd;
32     private Property bpd;
33
34     /**
35      * Inner class for creating instances of LengthPairProperty
36      */

37     public static class Maker extends CompoundPropertyMaker {
38
39         /**
40          * @param propId name of property for which this Maker should be created
41          */

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

50         public Property makeNewProperty() {
51             return new LengthPairProperty();
52         }
53
54         /**
55          * @see CompoundPropertyMaker#convertProperty
56          */

57         public Property convertProperty(Property p, PropertyList propertyList, FObj fo)
58             throws PropertyException {
59             if (p instanceof LengthPairProperty) {
60                 return p;
61             }
62             return super.convertProperty(p, propertyList, fo);
63         }
64     }
65
66     /**
67      * Creates a new LengthPairProperty with empty values.
68      */

69     public LengthPairProperty() {
70         super();
71     }
72     
73     /**
74      * Creates a new LengthPairProperty.
75      * @param ipd inline-progression-dimension
76      * @param bpd block-progression-dimension
77      */

78     public LengthPairProperty(Property ipd, Property bpd) {
79         this();
80         this.ipd = ipd;
81         this.bpd = bpd;
82     }
83     
84     /**
85      * Creates a new LengthPairProperty which sets both bpd and ipd to the
86      * same value.
87      * @param len length for both dimensions
88      */

89     public LengthPairProperty(Property len) {
90         this(len, len);
91     }
92     
93     /**
94      * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean)
95      */

96     public void setComponent(int cmpId, Property cmpnValue,
97                              boolean bIsDefault) {
98         if (cmpId == CP_BLOCK_PROGRESSION_DIRECTION) {
99             bpd = cmpnValue;
100         } else if (cmpId == CP_INLINE_PROGRESSION_DIRECTION) {
101             ipd = cmpnValue;
102         }
103     }
104
105     /**
106      * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int)
107      */

108     public Property getComponent(int cmpId) {
109         if (cmpId == CP_BLOCK_PROGRESSION_DIRECTION) {
110             return getBPD();
111         } else if (cmpId == CP_INLINE_PROGRESSION_DIRECTION) {
112             return getIPD();
113         } else {
114             return null; // SHOULDN'T HAPPEN
115
}
116     }
117
118     /**
119      * @return Property holding the ipd length
120      */

121     public Property getIPD() {
122         return this.ipd;
123     }
124
125     /**
126      * @return Property holding the bpd length
127      */

128     public Property getBPD() {
129         return this.bpd;
130     }
131
132     /** @see java.lang.Object#toString() */
133     public String JavaDoc toString() {
134         return "LengthPair["
135             + "ipd:" + getIPD().getObject()
136             + ", bpd:" + getBPD().getObject() + "]";
137     }
138
139     /**
140      * @return this.lengthPair
141      */

142     public LengthPairProperty getLengthPair() {
143         return this;
144     }
145
146     /**
147      * @return this.lengthPair cast as an Object
148      */

149     public Object JavaDoc getObject() {
150         return this;
151     }
152
153 }
154
Popular Tags