1 21 24 package org.lobobrowser.html.renderer; 25 26 import java.awt.Insets ; 27 28 import org.lobobrowser.html.*; 29 import org.lobobrowser.html.domimpl.*; 30 import org.lobobrowser.html.style.RenderState; 31 import org.lobobrowser.html.style.TableCellRenderState; 32 33 class RTableCell extends RBlock { 34 private final HTMLTableCellElementImpl cellElement; 35 private VirtualCell topLeftVirtualCell; 36 private int cellPadding; 37 38 41 public RTableCell(HTMLTableCellElementImpl element, UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext, RenderableContainer tableAsContainer) { 42 super(element, 0, pcontext, rcontext, frameContext, tableAsContainer); 43 this.cellElement = element; 44 } 45 46 public void setCellPadding(int value) { 47 this.cellPadding = value; 48 } 49 50 protected int getDeclaredHeight(int availHeight) { 51 return -1; 53 } 54 55 protected int getDeclaredWidth(int availWidth) { 56 return -1; 58 } 59 60 68 public void finalize() throws Throwable { 69 super.finalize(); 70 } 71 72 public void setTopLeftVirtualCell(VirtualCell vc) { 73 this.topLeftVirtualCell = vc; 74 } 75 76 public VirtualCell getTopLeftVirtualCell() { 77 return this.topLeftVirtualCell; 78 } 79 80 private int colSpan = -1; 81 private int rowSpan = -1; 82 83 86 public int getVirtualColumn() { 87 VirtualCell vc = this.topLeftVirtualCell; 88 return vc == null ? 0 : vc.getColumn(); 89 } 90 91 94 public int getVirtualRow() { 95 VirtualCell vc = this.topLeftVirtualCell; 96 return vc == null ? 0 : vc.getRow(); 97 } 98 99 public int getColSpan() { 100 int cs = this.colSpan; 101 if(cs == -1) { 102 cs = this.cellElement.getColSpan(); 103 if(cs < 1) { 104 cs = 1; 105 } 106 this.colSpan = cs; 107 } 108 return cs; 109 } 110 111 public int getRowSpan() { 112 int rs = this.rowSpan; 113 if(rs == -1) { 114 rs = this.cellElement.getRowSpan(); 115 if(rs < 1) { 116 rs = 1; 117 } 118 this.rowSpan = rs; 119 } 120 return rs; 121 } 122 123 public String getHeightText() { 124 return this.cellElement.getHeight(); 125 } 126 127 public String getWidthText() { 128 return this.cellElement.getWidth(); 129 } 130 131 132 133 141 public void setCellBounds(TableMatrix.SizeInfo[] colSizes, TableMatrix.SizeInfo[] rowSizes, int hasBorder, int cellSpacingX, int cellSpacingY) { 142 int vcol = this.getVirtualColumn(); 143 int vrow = this.getVirtualRow(); 144 TableMatrix.SizeInfo colSize = colSizes[vcol]; 145 TableMatrix.SizeInfo rowSize = rowSizes[vrow]; 146 int x = colSize.offset; 147 int y = rowSize.offset; 148 int width; 149 int height; 150 int colSpan = this.getColSpan(); 151 if(colSpan > 1) { 152 width = 0; 153 for(int i = 0; i < colSpan; i++) { 154 int vc = vcol + i; 155 width += colSizes[vc].actualSize; 156 if(i + 1 < colSpan) { 157 width += cellSpacingX + hasBorder * 2; 158 } 159 } 160 } 161 else { 162 width = colSizes[vcol].actualSize; 163 } 164 int rowSpan = this.getRowSpan(); 165 if(rowSpan > 1) { 166 height = 0; 167 for(int i = 0; i < rowSpan; i++) { 168 int vr = vrow + i; 169 height += rowSizes[vr].actualSize; 170 if(i + 1 < rowSpan) { 171 height += cellSpacingY + hasBorder * 2; 172 } 173 } 174 } 175 else { 176 height = rowSizes[vrow].actualSize; 177 } 178 this.setBounds(x, y, width, height); 179 } 180 } 181 | Popular Tags |