1 17 18 19 20 package org.apache.fop.layoutmgr.table; 21 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 import org.apache.fop.fo.flow.TableCell; 26 import org.apache.fop.fo.flow.TableColumn; 27 28 31 public class PrimaryGridUnit extends GridUnit { 32 33 34 private TableCellLayoutManager cellLM; 35 36 private LinkedList elements; 37 38 private int startRow; 39 40 private List rows; 41 42 private int contentLength = -1; 43 44 52 public PrimaryGridUnit(TableCell cell, TableColumn column, int startCol, int startRow) { 53 super(cell, column, startCol, 0); 54 this.startRow = startRow; 55 if (cell != null) { 56 cellLM = new TableCellLayoutManager(cell, this); 57 } 58 } 59 60 public TableCellLayoutManager getCellLM() { 61 return cellLM; 62 } 63 64 public boolean isPrimary() { 65 return true; 66 } 67 68 73 public void setElements(LinkedList elements) { 74 this.elements = elements; 75 } 76 77 public LinkedList getElements() { 78 return this.elements; 79 } 80 81 84 public int getHalfMaxBeforeBorderWidth() { 85 int value = 0; 86 if (getRows() != null) { 87 int before = 0; 88 GridUnit[] row = (GridUnit[])getRows().get(0); 90 for (int i = 0; i < row.length; i++) { 91 if (row[i].hasBorders()) { 92 before = Math.max(before, 93 row[i].getBorders().getBorderBeforeWidth(false)); 94 } 95 } 96 value += before / 2; 97 } else { 98 if (hasBorders()) { 99 value += getBorders().getBorderBeforeWidth(false) / 2; 100 } 101 } 102 return value; 103 } 104 105 108 public int getHalfMaxAfterBorderWidth() { 109 int value = 0; 110 if (getRows() != null) { 111 int after = 0; 113 GridUnit[] row = (GridUnit[])getRows().get(getRows().size() - 1); 114 for (int i = 0; i < row.length; i++) { 115 if (row[i].hasBorders()) { 116 after = Math.max(after, row[i].getBorders().getBorderAfterWidth(false)); 117 } 118 } 119 value += after / 2; 120 } else { 121 if (hasBorders()) { 122 value += getBorders().getBorderAfterWidth(false) / 2; 123 } 124 } 125 return value; 126 } 127 128 132 public int getHalfMaxBorderWidth() { 133 return getHalfMaxBeforeBorderWidth() + getHalfMaxAfterBorderWidth(); 134 } 135 136 137 public void setContentLength(int value) { 138 this.contentLength = value; 139 } 140 141 142 public int getContentLength() { 143 return contentLength; 144 } 145 146 147 public boolean hasBPD() { 148 if (!getCell().getBlockProgressionDimension().getOptimum(null).isAuto()) { 149 return true; 150 } 151 if (getRow() != null 152 && !getRow().getBlockProgressionDimension().getOptimum(null).isAuto()) { 153 return true; 154 } 155 return false; 156 } 157 158 163 public List getRows() { 164 return this.rows; 165 } 166 167 public void addRow(GridUnit[] row) { 168 if (rows == null) { 169 rows = new java.util.ArrayList (); 170 } 171 rows.add(row); 172 } 173 174 179 public int getStartRow() { 180 return this.startRow; 181 } 182 183 190 public int[] getStartEndBorderWidths() { 191 int[] widths = new int[2]; 192 if (rows == null) { 193 widths[0] = getBorders().getBorderStartWidth(false); 194 widths[1] = getBorders().getBorderEndWidth(false); 195 } else { 196 for (int i = 0; i < rows.size(); i++) { 197 GridUnit[] gridUnits = (GridUnit[])rows.get(i); 198 widths[0] = Math.max(widths[0], 199 (gridUnits[0]). 200 getBorders().getBorderStartWidth(false)); 201 widths[1] = Math.max(widths[1], 202 (gridUnits[gridUnits.length - 1]). 203 getBorders().getBorderEndWidth(false)); 204 } 205 } 206 return widths; 207 } 208 209 210 public String toString() { 211 StringBuffer sb = new StringBuffer (super.toString()); 212 sb.append(" startRow=").append(startRow); 213 return sb.toString(); 214 } 215 216 217 public boolean hasSpanning() { 218 return (getCell().getNumberColumnsSpanned() > 1) 219 || (getCell().getNumberRowsSpanned() > 1); 220 } 221 222 } 223 | Popular Tags |