1 17 18 19 20 package org.apache.fop.layoutmgr.table; 21 22 import org.apache.fop.fo.FONode; 23 import org.apache.fop.fo.flow.Table; 24 import org.apache.fop.fo.flow.TableBody; 25 import org.apache.fop.fo.flow.TableCell; 26 import org.apache.fop.fo.flow.TableColumn; 27 import org.apache.fop.fo.flow.TableRow; 28 import org.apache.fop.fo.properties.CommonBorderPaddingBackground; 29 import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo; 30 31 34 public class GridUnit { 35 36 37 public static final int IN_FIRST_COLUMN = 0; 38 39 public static final int IN_LAST_COLUMN = 1; 40 41 public static final int FIRST_IN_TABLE = 2; 42 43 public static final int FIRST_IN_PART = 3; 44 45 public static final int LAST_IN_PART = 4; 46 47 public static final int LAST_IN_TABLE = 5; 48 49 public static final int KEEP_WITH_NEXT_PENDING = 6; 50 51 public static final int KEEP_WITH_PREVIOUS_PENDING = 7; 52 53 54 private PrimaryGridUnit primary; 55 56 private TableCell cell; 57 58 private TableRow row; 59 60 private TableColumn column; 61 62 63 private int startCol; 64 65 private int colSpanIndex; 66 67 private int rowSpanIndex; 68 69 private CommonBorderPaddingBackground effectiveBorders; 70 71 private byte flags = 0; 72 73 74 82 public GridUnit(TableCell cell, TableColumn column, int startCol, int colSpanIndex) { 83 this(null, cell, column, startCol, colSpanIndex); 84 } 85 86 94 public GridUnit(PrimaryGridUnit primary, TableColumn column, int startCol, int colSpanIndex) { 95 this(primary, primary.getCell(), column, startCol, colSpanIndex); 96 } 97 98 107 protected GridUnit(PrimaryGridUnit primary, TableCell cell, TableColumn column, int startCol, int colSpanIndex) { 108 this.primary = primary; 109 this.cell = cell; 110 this.column = column; 111 this.startCol = startCol; 112 this.colSpanIndex = colSpanIndex; 113 } 114 115 public TableCell getCell() { 116 return cell; 117 } 118 119 public TableColumn getColumn() { 120 return column; 121 } 122 123 public TableRow getRow() { 124 if (row != null) { 125 return row; 126 } else if (getCell().getParent() instanceof TableRow) { 127 return (TableRow)getCell().getParent(); 128 } else { 129 return null; 130 } 131 } 132 133 137 public void setRow(TableRow row) { 138 this.row = row; 139 } 140 141 public TableBody getBody() { 142 FONode node = getCell(); 143 while (node != null && !(node instanceof TableBody)) { 144 node = node.getParent(); 145 } 146 return (TableBody)node; 147 } 148 149 public Table getTable() { 150 FONode node = getBody(); 151 while (node != null && !(node instanceof Table)) { 152 node = node.getParent(); 153 } 154 if (node == null && getColumn() != null) { 155 node = getColumn().getParent(); 156 } 157 return (Table)node; 158 } 159 160 163 public PrimaryGridUnit getPrimary() { 164 return (isPrimary() ? (PrimaryGridUnit)this : primary); 165 } 166 167 public boolean isPrimary() { 168 return false; 169 } 170 171 public boolean isEmpty() { 172 return cell == null; 173 } 174 175 public int getStartCol() { 176 return startCol; 177 } 178 179 180 public boolean isLastGridUnitColSpan() { 181 if (cell != null) { 182 return (colSpanIndex == cell.getNumberColumnsSpanned() - 1); 183 } else { 184 return true; 185 } 186 } 187 188 189 public boolean isLastGridUnitRowSpan() { 190 if (cell != null) { 191 return (rowSpanIndex == cell.getNumberRowsSpanned() - 1); 192 } else { 193 return true; 194 } 195 } 196 197 200 public int getRowSpanIndex() { 201 return rowSpanIndex; 202 } 203 204 207 public int getColSpanIndex() { 208 return colSpanIndex; 209 } 210 211 218 public BorderInfo getOriginalBorderInfoForCell(int side) { 219 if (cell != null) { 220 return cell.getCommonBorderPaddingBackground().getBorderInfo(side); 221 } else { 222 return null; 223 } 224 } 225 226 229 public CommonBorderPaddingBackground getBorders() { 230 return effectiveBorders; 231 } 232 233 236 public boolean hasBorders() { 237 return (getBorders() != null) && getBorders().hasBorder(); 238 } 239 240 244 public void assignBorderForSeparateBorderModel() { 245 if (cell != null) { 246 effectiveBorders = cell.getCommonBorderPaddingBackground(); 247 } 248 } 249 250 255 public void resolveBorder(GridUnit other, int side) { 256 resolveBorder(other, side, 0); 257 } 258 259 265 public void resolveBorder(GridUnit other, int side, int resFlags) { 266 CollapsingBorderModel borderModel = CollapsingBorderModel.getBorderModelFor( 267 getTable().getBorderCollapse()); 268 if (effectiveBorders == null) { 269 effectiveBorders = new CommonBorderPaddingBackground(); 270 } 271 effectiveBorders.setBorderInfo(borderModel.determineWinner(this, other, 272 side, resFlags), side); 273 if (cell != null) { 274 effectiveBorders.setPadding(cell.getCommonBorderPaddingBackground()); 275 } 276 } 277 278 283 public boolean getFlag(int which) { 284 return (flags & (1 << which)) != 0; 285 } 286 287 292 public void setFlag(int which, boolean value) { 293 if (value) { 294 flags |= (1 << which); } else { 296 flags &= ~(1 << which); } 298 } 299 300 303 public GridUnit createNextRowSpanningGridUnit() { 304 if (isLastGridUnitRowSpan()) { 305 return null; 306 } else { 307 GridUnit gu = new GridUnit(getPrimary(), getColumn(), startCol, colSpanIndex); 309 gu.rowSpanIndex = rowSpanIndex + 1; 310 return gu; 311 } 312 } 313 314 315 public String toString() { 316 StringBuffer buffer = new StringBuffer (); 317 if (isEmpty()) { 318 buffer.append("EMPTY"); 319 } else if (isPrimary()) { 320 buffer.append("Primary"); 321 } 322 buffer.append("GridUnit:"); 323 if (colSpanIndex > 0) { 324 buffer.append(" colSpan=").append(colSpanIndex); 325 } 326 if (rowSpanIndex > 0) { 327 buffer.append(" rowSpan=").append(rowSpanIndex); 328 } 329 buffer.append(" startCol=").append(startCol); 330 buffer.append(" flags=").append(Integer.toBinaryString(flags)); 331 return buffer.toString(); 332 } 333 334 } 335 | Popular Tags |