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: UnresolvedListElementWithLength.java 1296526 2012-03-03 00:18:45Z gadams $ */ 19 20 package org.apache.fop.layoutmgr; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.apache.fop.traits.MinOptMax; 26 27 /** 28 * This class represents an unresolved list element element with a (conditional) length. This 29 * is the base class for spaces, borders and paddings. 30 */ 31 public abstract class UnresolvedListElementWithLength extends UnresolvedListElement { 32 33 /** Logger instance */ 34 protected static final Log log = LogFactory.getLog(UnresolvedListElementWithLength.class); 35 36 private MinOptMax length; 37 private boolean conditional; 38 private RelSide side; 39 private boolean isFirst; 40 private boolean isLast; 41 42 /** 43 * Main constructor 44 * @param position the Position instance needed by the addAreas stage of the LMs. 45 * @param length the length of the element 46 * @param side the side to which this element applies 47 * @param conditional true if it's a conditional element (conditionality=discard) 48 * @param isFirst true if this is a space-before of the first area generated. 49 * @param isLast true if this is a space-after of the last area generated. 50 */ UnresolvedListElementWithLength(Position position, MinOptMax length, RelSide side, boolean conditional, boolean isFirst, boolean isLast)51 public UnresolvedListElementWithLength(Position position, MinOptMax length, 52 RelSide side, 53 boolean conditional, boolean isFirst, boolean isLast) { 54 super(position); 55 this.length = length; 56 this.side = side; 57 this.conditional = conditional; 58 this.isFirst = isFirst; 59 this.isLast = isLast; 60 } 61 62 /** {@inheritDoc} */ isConditional()63 public boolean isConditional() { 64 return this.conditional; 65 } 66 67 /** @return the space as resolved MinOptMax instance */ getLength()68 public MinOptMax getLength() { 69 return this.length; 70 } 71 72 /** @return the side this element was generated for */ getSide()73 public RelSide getSide() { 74 return this.side; 75 } 76 77 /** @return true if this is a space-before of the first area generated. */ isFirst()78 public boolean isFirst() { 79 return this.isFirst; 80 } 81 82 /** @return true if this is a space-after of the last area generated. */ isLast()83 public boolean isLast() { 84 return this.isLast; 85 } 86 87 /** 88 * Called to notify the affected layout manager about the effective length after resolution. 89 * This method is called once before each call to the layout manager's addAreas() method. 90 * @param effectiveLength the effective length after resolution (may be null which equals to 91 * zero effective length) 92 */ notifyLayoutManager(MinOptMax effectiveLength)93 public abstract void notifyLayoutManager(MinOptMax effectiveLength); 94 95 /** {@inheritDoc} */ toString()96 public String toString() { 97 StringBuffer sb = new StringBuffer(); 98 sb.append(getSide().getName()).append(", "); 99 sb.append(this.length.toString()); 100 if (isConditional()) { 101 sb.append("[discard]"); 102 } else { 103 sb.append("[RETAIN]"); 104 } 105 if (isFirst()) { 106 sb.append("[first]"); 107 } 108 if (isLast()) { 109 sb.append("[last]"); 110 } 111 return sb.toString(); 112 } 113 114 } 115