1 17 18 19 20 package org.apache.fop.area; 21 22 import java.util.List ; 23 24 32 public class Span extends Area { 33 private List flowAreas; 35 private int colCount; 36 private int colGap; 37 private int colWidth; private int curFlowIdx; 40 47 public Span(int colCount, int colGap, int ipd) { 48 addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE); 49 this.colCount = colCount; 50 this.colGap = colGap; 51 this.ipd = ipd; 52 curFlowIdx = 0; 53 createNormalFlows(); 54 } 55 56 59 private void createNormalFlows() { 60 flowAreas = new java.util.ArrayList (colCount); 61 colWidth = (ipd - ((colCount - 1) * colGap)) / colCount; 62 63 for (int i = 0; i < colCount; i++) { 64 NormalFlow newFlow = new NormalFlow(colWidth); 65 flowAreas.add(newFlow); 66 } 67 } 68 69 74 public int getColumnCount() { 75 return colCount; 76 } 77 78 83 public int getColumnWidth() { 84 return colWidth; 85 } 86 87 92 public int getHeight() { 93 return getBPD(); 94 } 95 96 97 103 public NormalFlow getNormalFlow(int colRequested) { 104 if (colRequested >= 0 && colRequested < colCount) { 105 return (NormalFlow) flowAreas.get(colRequested); 106 } else { throw new IllegalArgumentException ("Invalid column number " 108 + colRequested + " requested; only 0-" + (colCount - 1) 109 + " available."); 110 } 111 } 112 113 118 public NormalFlow getCurrentFlow() { 119 return getNormalFlow(curFlowIdx); 120 } 121 122 123 public int getCurrentFlowIndex() { 124 return curFlowIdx; 125 } 126 127 133 public NormalFlow moveToNextFlow() { 134 if (hasMoreFlows()) { 135 curFlowIdx++; 136 return getNormalFlow(curFlowIdx); 137 } else { 138 throw new IllegalStateException ("(Internal error.) No more flows left in span."); 139 } 140 } 141 142 148 public boolean hasMoreFlows() { 149 return (curFlowIdx < colCount - 1); 150 } 151 152 156 public void notifyFlowsFinished() { 157 int maxFlowBPD = Integer.MIN_VALUE; 158 for (int i = 0; i < colCount; i++) { 159 maxFlowBPD = Math.max(maxFlowBPD, getNormalFlow(i).getAllocBPD()); 160 } 161 bpd = maxFlowBPD; 162 } 163 164 170 public boolean isEmpty() { 171 int areaCount = 0; 172 for (int i = 0; i < getColumnCount(); i++) { 173 NormalFlow flow = getNormalFlow(i); 174 if (flow != null) { 175 if (flow.getChildAreas() != null) { 176 areaCount += flow.getChildAreas().size(); 177 } 178 } 179 } 180 return (areaCount == 0); 181 } 182 183 184 public String toString() { 185 StringBuffer sb = new StringBuffer (super.toString()); 186 if (colCount > 1) { 187 sb.append(" {colCount=").append(colCount); 188 sb.append(", colWidth=").append(colWidth); 189 sb.append(", curFlowIdx=").append(this.curFlowIdx); 190 sb.append("}"); 191 } 192 return sb.toString(); 193 } 194 195 } 196 197 | Popular Tags |