001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: UnresolvedListElementWithLength.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.layoutmgr;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.fop.traits.MinOptMax;
025:
026: /**
027: * This class represents an unresolved list element element with a (conditional) length. This
028: * is the base class for spaces, borders and paddings.
029: */
030: public abstract class UnresolvedListElementWithLength extends
031: UnresolvedListElement {
032:
033: /** Logger instance */
034: protected static Log log = LogFactory
035: .getLog(UnresolvedListElementWithLength.class);
036:
037: private MinOptMax length;
038: private boolean conditional;
039: private RelSide side;
040: private boolean isFirst;
041: private boolean isLast;
042:
043: /**
044: * Main constructor
045: * @param position the Position instance needed by the addAreas stage of the LMs.
046: * @param length the length of the element
047: * @param side the side to which this element applies
048: * @param conditional true if it's a conditional element (conditionality=discard)
049: * @param isFirst true if this is a space-before of the first area generated.
050: * @param isLast true if this is a space-after of the last area generated.
051: */
052: public UnresolvedListElementWithLength(Position position,
053: MinOptMax length, RelSide side, boolean conditional,
054: boolean isFirst, boolean isLast) {
055: super (position);
056: this .length = length;
057: this .side = side;
058: this .conditional = conditional;
059: this .isFirst = isFirst;
060: this .isLast = isLast;
061: }
062:
063: /** @see org.apache.fop.layoutmgr.UnresolvedListElement#isConditional() */
064: public boolean isConditional() {
065: return this .conditional;
066: }
067:
068: /** @return the space as resolved MinOptMax instance */
069: public MinOptMax getLength() {
070: return this .length;
071: }
072:
073: /** @return the side this element was generated for */
074: public RelSide getSide() {
075: return this .side;
076: }
077:
078: /** @return true if this is a space-before of the first area generated. */
079: public boolean isFirst() {
080: return this .isFirst;
081: }
082:
083: /** @return true if this is a space-after of the last area generated. */
084: public boolean isLast() {
085: return this .isLast;
086: }
087:
088: /**
089: * Called to notify the affected layout manager about the effective length after resolution.
090: * This method is called once before each call to the layout manager's addAreas() method.
091: * @param effectiveLength the effective length after resolution (may be null which equals to
092: * zero effective length)
093: */
094: public abstract void notifyLayoutManager(MinOptMax effectiveLength);
095:
096: /** @see java.lang.Object#toString() */
097: public String toString() {
098: StringBuffer sb = new StringBuffer();
099: sb.append(getSide().getName()).append(", ");
100: sb.append(this .length.toString());
101: if (isConditional()) {
102: sb.append("[discard]");
103: } else {
104: sb.append("[RETAIN]");
105: }
106: if (isFirst()) {
107: sb.append("[first]");
108: }
109: if (isLast()) {
110: sb.append("[last]");
111: }
112: return sb.toString();
113: }
114:
115: }
|