1 16 package com.google.gwt.user.client.ui; 17 18 import com.google.gwt.user.client.DOM; 19 import com.google.gwt.user.client.Element; 20 21 33 public class FlexTable extends HTMLTable { 34 35 40 public class FlexCellFormatter extends CellFormatter { 41 42 51 public int getColSpan(int row, int column) { 52 return DOM.getElementPropertyInt(getElement(row, column), "colSpan"); 53 } 54 55 64 public int getRowSpan(int row, int column) { 65 return DOM.getElementPropertyInt(getElement(row, column), "rowSpan"); 66 } 67 68 77 public void setColSpan(int row, int column, int colSpan) { 78 DOM.setElementPropertyInt(ensureElement(row, column), "colSpan", colSpan); 79 } 80 81 90 public void setRowSpan(int row, int column, int rowSpan) { 91 DOM.setElementPropertyInt(ensureElement(row, column), "rowSpan", rowSpan); 92 } 93 } 94 95 private static native void addCells(Element table, int row, int num); 102 103 public FlexTable() { 104 super(); 105 setCellFormatter(new FlexCellFormatter()); 106 setRowFormatter(new RowFormatter()); 107 setColumnFormatter(new ColumnFormatter()); 108 } 109 110 116 public void addCell(int row) { 117 insertCell(row, getCellCount(row)); 118 } 119 120 127 public int getCellCount(int row) { 128 checkRowBounds(row); 129 return super.getDOMCellCount(getBodyElement(), row); 130 } 131 132 139 public FlexCellFormatter getFlexCellFormatter() { 140 return (FlexCellFormatter) getCellFormatter(); 141 } 142 143 148 public int getRowCount() { 149 return getDOMRowCount(); 150 } 151 152 158 public void insertCell(int beforeRow, int beforeColumn) { 159 super.insertCell(beforeRow, beforeColumn); 160 } 161 162 167 public int insertRow(int beforeRow) { 168 return super.insertRow(beforeRow); 169 } 170 171 174 public void removeCell(int row, int col) { 175 super.removeCell(row, col); 176 } 177 178 186 public void removeCells(int row, int column, int num) { 187 for (int i = 0; i < num; i++) { 188 removeCell(row, column); 189 } 190 } 191 192 public void removeRow(int row) { 193 super.removeRow(row); 194 } 195 196 203 protected void prepareCell(int row, int column) { 204 prepareRow(row); 205 if (column < 0) { 206 throw new IndexOutOfBoundsException ( 207 "Cannot create a column with a negative index: " + column); 208 } 209 210 int cellCount = getCellCount(row); 212 int required = column + 1 - cellCount; 213 if (required > 0) { 214 addCells(getBodyElement(), row, required); 215 } 216 } 217 218 224 protected void prepareRow(int row) { 225 if (row < 0) { 226 throw new IndexOutOfBoundsException ( 227 "Cannot create a row with a negative index: " + row); 228 } 229 230 int rowCount = getRowCount(); 232 for (int i = rowCount; i <= row; i++) { 233 insertRow(i); 234 } 235 } 236 } 237 | Popular Tags |