KickJava   Java API By Example, From Geeks To Geeks.

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


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: CorrespondingPropertyMaker.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.apps.FOPException;
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  */

29 public class CorrespondingPropertyMaker {
30     protected PropertyMaker baseMaker;
31     protected int lr_tb;
32     protected int rl_tb;
33     protected int tb_rl;
34     protected boolean useParent;
35     private boolean relative;
36     
37     public CorrespondingPropertyMaker(PropertyMaker baseMaker) {
38         this.baseMaker = baseMaker;
39         baseMaker.setCorresponding(this);
40     }
41     
42     
43     public void setCorresponding(int lr_tb, int rl_tb, int tb_rl) {
44         this.lr_tb = lr_tb;
45         this.rl_tb = rl_tb;
46         this.tb_rl = tb_rl;
47     }
48     
49     public void setUseParent(boolean useParent) {
50         this.useParent = useParent;
51     }
52
53     public void setRelative(boolean relative) {
54         this.relative = relative;
55     }
56     
57     /**
58      * For properties that operate on a relative direction (before, after,
59      * start, end) instead of an absolute direction (top, bottom, left,
60      * right), this method determines whether a corresponding property
61      * is specified on the corresponding absolute direction. For example,
62      * the border-start-color property in a lr-tb writing-mode specifies
63      * the same thing that the border-left-color property specifies. In this
64      * example, if the Maker for the border-start-color property is testing,
65      * and if the border-left-color is specified in the properties,
66      * this method should return true.
67      * @param propertyList collection of properties to be tested
68      * @return true iff 1) the property operates on a relative direction,
69      * AND 2) the property has a corresponding property on an absolute
70      * direction, AND 3) the corresponding property on that absolute
71      * direction has been specified in the input properties
72      */

73     public boolean isCorrespondingForced(PropertyList propertyList) {
74
75         if (!relative) {
76             return false;
77         }
78         
79         PropertyList pList = getWMPropertyList(propertyList);
80         if (pList != null) {
81             int correspondingId = pList.getWritingMode(lr_tb, rl_tb, tb_rl);
82         
83             if (pList.getExplicit(correspondingId) != null) {
84                 return true;
85             }
86         }
87         return false;
88     }
89     
90     /**
91      * Return a Property object representing the value of this property,
92      * based on other property values for this FO.
93      * A special case is properties which inherit the specified value,
94      * rather than the computed value.
95      * @param propertyList The PropertyList for the FO.
96      * @return Property A computed Property value or null if no rules
97      * are specified (in foproperties.xml) to compute the value.
98      * @throws FOPException for invalid or inconsistent FO input
99      */

100     public Property compute(PropertyList propertyList) throws PropertyException {
101         PropertyList pList = getWMPropertyList(propertyList);
102         if (pList == null) {
103             return null;
104         }
105         int correspondingId = pList.getWritingMode(lr_tb, rl_tb, tb_rl);
106             
107         Property p = propertyList.getExplicitOrShorthand(correspondingId);
108         if (p != null) {
109             FObj parentFO = propertyList.getParentFObj();
110             p = baseMaker.convertProperty(p, propertyList, parentFO);
111         }
112         return p;
113     }
114     
115     /**
116      * Return the property list to use for fetching writing mode depending property
117      * ids.
118      */

119     protected PropertyList getWMPropertyList(PropertyList pList) {
120         if (useParent) {
121             return pList.getParentPropertyList();
122         } else {
123             return pList;
124         }
125     }
126 }
127
128
Popular Tags