KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > layoutmgr > SpaceElement


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: SpaceElement.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.layoutmgr;
21
22 import org.apache.fop.datatypes.PercentBaseContext;
23 import org.apache.fop.fo.Constants;
24 import org.apache.fop.fo.properties.SpaceProperty;
25 import org.apache.fop.traits.MinOptMax;
26
27 /**
28  * This class represents an unresolved space element.
29  */

30 public class SpaceElement extends UnresolvedListElementWithLength {
31
32     private int precedence;
33     
34     /**
35      * Main constructor
36      * @param position the Position instance needed by the addAreas stage of the LMs.
37      * @param space the space property
38      * @param side the side to which this space element applies.
39      * @param isFirst true if this is a space-before of the first area generated.
40      * @param isLast true if this is a space-after of the last area generated.
41      * @param context the property evaluation context
42      */

43     public SpaceElement(Position position, SpaceProperty space, RelSide side,
44             boolean isFirst, boolean isLast,
45             PercentBaseContext context) {
46         super(position,
47                 MinOptMaxUtil.toMinOptMax(
48                         space.getSpace().getLengthRange(),
49                 context), side, space.isDiscard(), isFirst, isLast);
50         int en = space.getSpace().getPrecedence().getEnum();
51         if (en == Constants.EN_FORCE) {
52             this.precedence = Integer.MAX_VALUE;
53         } else {
54             this.precedence = space.getSpace().getPrecedence().getNumber().intValue();
55         }
56     }
57     
58     /** @return true if the space is forcing. */
59     public boolean isForcing() {
60         return this.precedence == Integer.MAX_VALUE;
61     }
62
63     /** @return the precedence of the space */
64     public int getPrecedence() {
65         return this.precedence;
66     }
67     
68     /** @see org.apache.fop.layoutmgr.UnresolvedListElementWithLength */
69     public void notifyLayoutManager(MinOptMax effectiveLength) {
70         LayoutManager lm = getOriginatingLayoutManager();
71         if (lm instanceof ConditionalElementListener) {
72             ((ConditionalElementListener)lm).notifySpace(
73                     getSide(), effectiveLength);
74         } else {
75             log.warn("Cannot notify LM. It does not implement ConditionalElementListener:"
76                     + lm.getClass().getName());
77         }
78     }
79     
80     /** @see java.lang.Object#toString() */
81     public String JavaDoc toString() {
82         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Space[");
83         sb.append(super.toString());
84         sb.append(", precedence=");
85         if (isForcing()) {
86             sb.append("forcing");
87         } else {
88             sb.append(getPrecedence());
89         }
90         sb.append("]");
91         return sb.toString();
92     }
93
94 }
95
Popular Tags