01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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,
44: RelSide side, boolean isFirst, boolean isLast,
45: PercentBaseContext context) {
46: super (position, MinOptMaxUtil.toMinOptMax(space.getSpace()
47: .getLengthRange(), context), side, space.isDiscard(),
48: isFirst, isLast);
49: int en = space.getSpace().getPrecedence().getEnum();
50: if (en == Constants.EN_FORCE) {
51: this .precedence = Integer.MAX_VALUE;
52: } else {
53: this .precedence = space.getSpace().getPrecedence()
54: .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(getSide(),
73: effectiveLength);
74: } else {
75: log
76: .warn("Cannot notify LM. It does not implement ConditionalElementListener:"
77: + lm.getClass().getName());
78: }
79: }
80:
81: /** @see java.lang.Object#toString() */
82: public String toString() {
83: StringBuffer sb = new StringBuffer("Space[");
84: sb.append(super .toString());
85: sb.append(", precedence=");
86: if (isForcing()) {
87: sb.append("forcing");
88: } else {
89: sb.append(getPrecedence());
90: }
91: sb.append("]");
92: return sb.toString();
93: }
94:
95: }
|