1 51 package org.apache.fop.fo.flow; 52 53 public class RowSpanMgr { 54 class SpanInfo { 55 int cellHeight; 56 int totalRowHeight; 57 int rowsRemaining; 58 TableCell cell; 60 61 SpanInfo(TableCell cell, int cellHeight, int rowsSpanned) { 62 this.cell = cell; 63 this.cellHeight = cellHeight; 64 this.totalRowHeight = 0; 65 this.rowsRemaining = rowsSpanned; 66 } 67 68 71 int heightRemaining() { 72 int hl = cellHeight - totalRowHeight; 73 return (hl > 0) ? hl : 0; 74 } 75 76 boolean isInLastRow() { 77 return (rowsRemaining == 1); 78 } 79 80 boolean finishRow(int rowHeight) { 81 totalRowHeight += rowHeight; 82 if (--rowsRemaining == 0) { 83 if (cell != null) { 84 cell.setRowHeight(totalRowHeight); 85 } 86 return true; 87 } else 88 return false; 89 } 90 91 } 92 93 private SpanInfo spanInfo[]; 94 95 private boolean ignoreKeeps = false; 96 97 public RowSpanMgr(int numCols) { 98 this.spanInfo = new SpanInfo[numCols]; 99 } 100 101 public void addRowSpan(TableCell cell, int firstCol, int numCols, 102 int cellHeight, int rowsSpanned) { 103 spanInfo[firstCol - 1] = new SpanInfo(cell, cellHeight, rowsSpanned); 104 for (int i = 0; i < numCols - 1; i++) { 105 spanInfo[firstCol + i] = new SpanInfo(null, cellHeight, 106 rowsSpanned); } 108 } 109 110 public boolean isSpanned(int colNum) { 111 return (spanInfo[colNum - 1] != null); 112 } 113 114 115 public TableCell getSpanningCell(int colNum) { 116 if (spanInfo[colNum - 1] != null) { 117 return spanInfo[colNum - 1].cell; 118 } else 119 return null; 120 } 121 122 123 126 public boolean hasUnfinishedSpans() { 127 for (int i = 0; i < spanInfo.length; i++) { 128 if (spanInfo[i] != null) 129 return true; 130 } 131 return false; 132 } 133 134 143 public void finishRow(int rowHeight) { 144 for (int i = 0; i < spanInfo.length; i++) { 145 if (spanInfo[i] != null && spanInfo[i].finishRow(rowHeight)) 146 spanInfo[i] = null; 147 } 148 } 149 150 156 public int getRemainingHeight(int colNum) { 157 if (spanInfo[colNum - 1] != null) { 158 return spanInfo[colNum - 1].heightRemaining(); 159 } else 160 return 0; 161 } 162 163 public boolean isInLastRow(int colNum) { 164 if (spanInfo[colNum - 1] != null) { 165 return spanInfo[colNum - 1].isInLastRow(); 166 } else 167 return false; 168 } 169 170 175 public void setIgnoreKeeps(boolean ignoreKeeps) { 176 this.ignoreKeeps = ignoreKeeps; 177 } 178 179 184 public boolean ignoreKeeps() { 185 return ignoreKeeps; 186 } 187 188 } 189 | Popular Tags |