Subversion Repository Public Repository

litesoft

Diff Revisions 282 vs 475 for /trunk/Java/GWT/Client/src/com/google/gwt/gen2/table/client/FlexTable.java

Diff revisions: vs.
  @@ -15,295 +15,342 @@
15 15 */
16 16 package com.google.gwt.gen2.table.client;
17 17
18 - import com.google.gwt.user.client.DOM;
19 - import com.google.gwt.user.client.Element;
18 + import com.google.gwt.user.client.*;
20 19
21 20 /**
22 21 * This class should replace the actual class of the same name.
23 - *
22 + * <p/>
24 23 * TODO: Incorporate changes into actual class.
25 24 */
26 - public class FlexTable extends HTMLTable {
25 + public class FlexTable extends HTMLTable
26 + {
27 27
28 - /**
29 - * FlexTable-specific implementation of {@link HTMLTable.CellFormatter}. The
30 - * formatter retrieved from {@link HTMLTable#getCellFormatter()} may be cast
31 - * to this class.
32 - */
33 - public class FlexCellFormatter extends CellFormatter {
28 + /**
29 + * FlexTable-specific implementation of {@link HTMLTable.CellFormatter}. The
30 + * formatter retrieved from {@link HTMLTable#getCellFormatter()} may be cast
31 + * to this class.
32 + */
33 + public class FlexCellFormatter extends CellFormatter
34 + {
35 +
36 + /**
37 + * Gets the column span for the given cell. This is the number of logical
38 + * columns covered by the cell.
39 + *
40 + * @param row the cell's row
41 + * @param column the cell's column
42 + *
43 + * @return the cell's column span
44 + *
45 + * @throws IndexOutOfBoundsException
46 + */
47 + public int getColSpan( int row, int column )
48 + {
49 + return DOM.getElementPropertyInt( getElement( row, column ), "colSpan" );
50 + }
51 +
52 + /**
53 + * Gets the row span for the given cell. This is the number of logical rows
54 + * covered by the cell.
55 + *
56 + * @param row the cell's row
57 + * @param column the cell's column
58 + *
59 + * @return the cell's row span
60 + *
61 + * @throws IndexOutOfBoundsException
62 + */
63 + public int getRowSpan( int row, int column )
64 + {
65 + return DOM.getElementPropertyInt( getElement( row, column ), "rowSpan" );
66 + }
67 +
68 + /**
69 + * Sets the column span for the given cell. This is the number of logical
70 + * columns covered by the cell.
71 + *
72 + * @param row the cell's row
73 + * @param column the cell's column
74 + * @param colSpan the cell's column span
75 + *
76 + * @throws IndexOutOfBoundsException
77 + */
78 + public void setColSpan( int row, int column, int colSpan )
79 + {
80 + DOM.setElementPropertyInt( ensureElement( row, column ), "colSpan", colSpan );
81 + }
82 +
83 + /**
84 + * Sets the row span for the given cell. This is the number of logical rows
85 + * covered by the cell.
86 + *
87 + * @param row the cell's row
88 + * @param column the cell's column
89 + * @param rowSpan the cell's row span
90 + *
91 + * @throws IndexOutOfBoundsException
92 + */
93 + public void setRowSpan( int row, int column, int rowSpan )
94 + {
95 + DOM.setElementPropertyInt( ensureElement( row, column ), "rowSpan", rowSpan );
96 + }
97 + }
34 98
35 99 /**
36 - * Gets the column span for the given cell. This is the number of logical
37 - * columns covered by the cell.
38 - *
39 - * @param row the cell's row
40 - * @param column the cell's column
41 - * @return the cell's column span
100 + * Add cells to the specified row.
101 + *
102 + * @param table the table to affect
103 + * @param row the row to affect
104 + * @param num the number of cells to add
105 + */
106 + private static native void addCells( Element table, int row, int num )/*-{
107 + var rowElem = table.rows[row];
108 + for ( var i = 0; i < num; i++ )
109 + {
110 + var cell = $doc.createElement( "td" );
111 + cell['colSpan'] = 1;
112 + cell['rowSpan'] = 1;
113 + rowElem.appendChild( cell );
114 + }
115 + }-*/;
116 +
117 + public FlexTable()
118 + {
119 + super();
120 + setCellFormatter( new FlexCellFormatter() );
121 + setRowFormatter( new RowFormatter() );
122 + setColumnFormatter( new ColumnFormatter() );
123 + }
124 +
125 + /**
126 + * Appends a cell to the specified row.
127 + *
128 + * @param row the row to which the new cell will be added
129 + *
42 130 * @throws IndexOutOfBoundsException
43 131 */
44 - public int getColSpan(int row, int column) {
45 - return DOM.getElementPropertyInt(getElement(row, column), "colSpan");
132 + public void addCell( int row )
133 + {
134 + insertCell( row, getCellCount( row ) );
46 135 }
47 136
48 137 /**
49 - * Gets the row span for the given cell. This is the number of logical rows
50 - * covered by the cell.
51 - *
52 - * @param row the cell's row
53 - * @param column the cell's column
54 - * @return the cell's row span
138 + * Gets the number of cells on a given row.
139 + *
140 + * @param row the row whose cells are to be counted
141 + *
142 + * @return the number of cells present
143 + *
55 144 * @throws IndexOutOfBoundsException
56 145 */
57 - public int getRowSpan(int row, int column) {
58 - return DOM.getElementPropertyInt(getElement(row, column), "rowSpan");
146 + @Override
147 + public int getCellCount( int row )
148 + {
149 + checkRowBounds( row );
150 + return getDOMCellCount( row );
59 151 }
60 152
61 153 /**
62 - * Sets the column span for the given cell. This is the number of logical
63 - * columns covered by the cell.
64 - *
65 - * @param row the cell's row
154 + * Gets the overall column index of this cell as if this table were a grid, as
155 + * determined by the rowspan and colspan of other cells in the table.
156 + *
157 + * @param row the cell's row
66 158 * @param column the cell's column
67 - * @param colSpan the cell's column span
159 + *
160 + * @return the cell's column index
161 + *
68 162 * @throws IndexOutOfBoundsException
69 163 */
70 - public void setColSpan(int row, int column, int colSpan) {
71 - DOM.setElementPropertyInt(ensureElement(row, column), "colSpan", colSpan);
164 + public int getColumnIndex( int row, int column )
165 + {
166 + checkCellBounds( row, column );
167 + return getRawColumnIndex( row, column );
72 168 }
73 169
74 170 /**
75 - * Sets the row span for the given cell. This is the number of logical rows
76 - * covered by the cell.
77 - *
78 - * @param row the cell's row
79 - * @param column the cell's column
80 - * @param rowSpan the cell's row span
171 + * Explicitly gets the {@link FlexCellFormatter}. The results of
172 + * {@link HTMLTable#getCellFormatter()} may also be downcast to a
173 + * {@link FlexCellFormatter}.
174 + *
175 + * @return the FlexTable's cell formatter
176 + */
177 + public FlexCellFormatter getFlexCellFormatter()
178 + {
179 + return (FlexCellFormatter) getCellFormatter();
180 + }
181 +
182 + /**
183 + * Gets the number of rows.
184 + *
185 + * @return number of rows
186 + */
187 + @Override
188 + public int getRowCount()
189 + {
190 + return getDOMRowCount();
191 + }
192 +
193 + /**
194 + * Inserts a cell into the FlexTable.
195 + *
196 + * @param beforeRow the cell's row
197 + * @param beforeColumn the cell's column
198 + *
199 + * @return the element
200 + */
201 + @Override
202 + public Element insertCell( int beforeRow, int beforeColumn )
203 + {
204 + return super.insertCell( beforeRow, beforeColumn );
205 + }
206 +
207 + /**
208 + * Inserts a row into the FlexTable.
209 + *
210 + * @param beforeRow the row to insert
211 + */
212 + @Override
213 + public int insertRow( int beforeRow )
214 + {
215 + return super.insertRow( beforeRow );
216 + }
217 +
218 + /**
219 + * Removes the specified cell from the table.
220 + *
221 + * @param row the row of the cell to remove
222 + * @param column the column of cell to remove
223 + *
81 224 * @throws IndexOutOfBoundsException
82 225 */
83 - public void setRowSpan(int row, int column, int rowSpan) {
84 - DOM.setElementPropertyInt(ensureElement(row, column), "rowSpan", rowSpan);
226 + @Override
227 + public void removeCell( int row, int column )
228 + {
229 + super.removeCell( row, column );
85 230 }
86 - }
87 231
88 - /**
89 - * Add cells to the specified row.
90 - *
91 - * @param table the table to affect
92 - * @param row the row to affect
93 - * @param num the number of cells to add
94 - */
95 - private static native void addCells(Element table, int row, int num)/*-{
96 - var rowElem = table.rows[row];
97 - for(var i = 0; i < num; i++){
98 - var cell = $doc.createElement("td");
99 - cell['colSpan'] = 1;
100 - cell['rowSpan'] = 1;
101 - rowElem.appendChild(cell);
102 - }
103 - }-*/;
104 -
105 - public FlexTable() {
106 - super();
107 - setCellFormatter(new FlexCellFormatter());
108 - setRowFormatter(new RowFormatter());
109 - setColumnFormatter(new ColumnFormatter());
110 - }
111 -
112 - /**
113 - * Appends a cell to the specified row.
114 - *
115 - * @param row the row to which the new cell will be added
116 - * @throws IndexOutOfBoundsException
117 - */
118 - public void addCell(int row) {
119 - insertCell(row, getCellCount(row));
120 - }
121 -
122 - /**
123 - * Gets the number of cells on a given row.
124 - *
125 - * @param row the row whose cells are to be counted
126 - * @return the number of cells present
127 - * @throws IndexOutOfBoundsException
128 - */
129 - @Override
130 - public int getCellCount(int row) {
131 - checkRowBounds(row);
132 - return getDOMCellCount(row);
133 - }
134 -
135 - /**
136 - * Gets the overall column index of this cell as if this table were a grid, as
137 - * determined by the rowspan and colspan of other cells in the table.
138 - *
139 - * @param row the cell's row
140 - * @param column the cell's column
141 - * @return the cell's column index
142 - * @throws IndexOutOfBoundsException
143 - */
144 - public int getColumnIndex(int row, int column) {
145 - checkCellBounds(row, column);
146 - return getRawColumnIndex(row, column);
147 - }
148 -
149 - /**
150 - * Explicitly gets the {@link FlexCellFormatter}. The results of
151 - * {@link HTMLTable#getCellFormatter()} may also be downcast to a
152 - * {@link FlexCellFormatter}.
153 - *
154 - * @return the FlexTable's cell formatter
155 - */
156 - public FlexCellFormatter getFlexCellFormatter() {
157 - return (FlexCellFormatter) getCellFormatter();
158 - }
159 -
160 - /**
161 - * Gets the number of rows.
162 - *
163 - * @return number of rows
164 - */
165 - @Override
166 - public int getRowCount() {
167 - return getDOMRowCount();
168 - }
169 -
170 - /**
171 - * Inserts a cell into the FlexTable.
172 - *
173 - * @param beforeRow the cell's row
174 - * @param beforeColumn the cell's column
175 - * @return the element
176 - */
177 - @Override
178 - public Element insertCell(int beforeRow, int beforeColumn) {
179 - return super.insertCell(beforeRow, beforeColumn);
180 - }
181 -
182 - /**
183 - * Inserts a row into the FlexTable.
184 - *
185 - * @param beforeRow the row to insert
186 - */
187 - @Override
188 - public int insertRow(int beforeRow) {
189 - return super.insertRow(beforeRow);
190 - }
191 -
192 - /**
193 - * Removes the specified cell from the table.
194 - *
195 - * @param row the row of the cell to remove
196 - * @param column the column of cell to remove
197 - * @throws IndexOutOfBoundsException
198 - */
199 - @Override
200 - public void removeCell(int row, int column) {
201 - super.removeCell(row, column);
202 - }
203 -
204 - /**
205 - * Removes a number of cells from a row in the table.
206 - *
207 - * @param row the row of the cells to be removed
208 - * @param column the column of the first cell to be removed
209 - * @param num the number of cells to be removed
210 - * @throws IndexOutOfBoundsException
211 - */
212 - public void removeCells(int row, int column, int num) {
213 - for (int i = 0; i < num; i++) {
214 - removeCell(row, column);
215 - }
216 - }
217 -
218 - @Override
219 - public void removeRow(int row) {
220 - super.removeRow(row);
221 - }
222 -
223 - /**
224 - * Add cells to the specified row.
225 - *
226 - * @param row the row to affect
227 - * @param num the number of cells to add
228 - */
229 - protected void addCells(int row, int num) {
230 - addCells(getBodyElement(), row, num);
231 - }
232 -
233 - /**
234 - * Ensure that the cell exists.
235 - *
236 - * @param row the row to prepare.
237 - * @param column the column to prepare.
238 - * @throws IndexOutOfBoundsException if the row is negative
239 - */
240 - @Override
241 - protected void prepareCell(int row, int column) {
242 - prepareRow(row);
243 - if (column < 0) {
244 - throw new IndexOutOfBoundsException(
245 - "Cannot create a column with a negative index: " + column);
246 - }
247 -
248 - // Ensure that the requested column exists.
249 - int cellCount = getCellCount(row);
250 - int required = column + 1 - cellCount;
251 - if (required > 0) {
252 - addCells(row, required);
253 - }
254 - }
255 -
256 - /**
257 - * Ensure that the row exists.
258 - *
259 - * @param row The row to prepare.
260 - * @throws IndexOutOfBoundsException if the row is negative
261 - */
262 - @Override
263 - protected void prepareRow(int row) {
264 - if (row < 0) {
265 - throw new IndexOutOfBoundsException(
266 - "Cannot create a row with a negative index: " + row);
267 - }
268 -
269 - // Ensure that the requested row exists.
270 - int rowCount = getRowCount();
271 - for (int i = rowCount; i <= row; i++) {
272 - insertRow(i);
273 - }
274 - }
275 -
276 - /**
277 - * Gets the overall column index of this cell as if this table were a grid, as
278 - * determined by the rowspan and colspan of other cells in the table. This
279 - * helper method doesn't check the bounds on every recursive call.
280 - *
281 - * @param row the cell's row
282 - * @param column the cell's column
283 - * @return the cell's column index
284 - * @throws IndexOutOfBoundsException
285 - */
286 - private int getRawColumnIndex(int row, int column) {
287 - // Get cells before me in my row
288 - FlexCellFormatter formatter = getFlexCellFormatter();
289 - int columnIndex = 0;
290 - for (int curCell = 0; curCell < column; curCell++) {
291 - columnIndex += formatter.getColSpan(row, curCell);
292 - }
293 -
294 - // Get cells that span down into my row
295 - int numCells = 0;
296 - for (int curRow = 0; curRow < row; curRow++) {
297 - numCells = getCellCount(curRow);
298 - for (int curCell = 0; curCell < numCells; curCell++) {
299 - if ((curRow + formatter.getRowSpan(curRow, curCell) - 1) >= row) {
300 - if (getRawColumnIndex(curRow, curCell) <= columnIndex) {
301 - columnIndex += formatter.getColSpan(curRow, curCell);
302 - }
232 + /**
233 + * Removes a number of cells from a row in the table.
234 + *
235 + * @param row the row of the cells to be removed
236 + * @param column the column of the first cell to be removed
237 + * @param num the number of cells to be removed
238 + *
239 + * @throws IndexOutOfBoundsException
240 + */
241 + public void removeCells( int row, int column, int num )
242 + {
243 + for ( int i = 0; i < num; i++ )
244 + {
245 + removeCell( row, column );
303 246 }
304 - }
305 247 }
306 248
307 - return columnIndex;
308 - }
249 + @Override
250 + public void removeRow( int row )
251 + {
252 + super.removeRow( row );
253 + }
254 +
255 + /**
256 + * Add cells to the specified row.
257 + *
258 + * @param row the row to affect
259 + * @param num the number of cells to add
260 + */
261 + protected void addCells( int row, int num )
262 + {
263 + addCells( getBodyElement(), row, num );
264 + }
265 +
266 + /**
267 + * Ensure that the cell exists.
268 + *
269 + * @param row the row to prepare.
270 + * @param column the column to prepare.
271 + *
272 + * @throws IndexOutOfBoundsException if the row is negative
273 + */
274 + @Override
275 + protected void prepareCell( int row, int column )
276 + {
277 + prepareRow( row );
278 + if ( column < 0 )
279 + {
280 + throw new IndexOutOfBoundsException( "Cannot create a column with a negative index: " + column );
281 + }
282 +
283 + // Ensure that the requested column exists.
284 + int cellCount = getCellCount( row );
285 + int required = column + 1 - cellCount;
286 + if ( required > 0 )
287 + {
288 + addCells( row, required );
289 + }
290 + }
291 +
292 + /**
293 + * Ensure that the row exists.
294 + *
295 + * @param row The row to prepare.
296 + *
297 + * @throws IndexOutOfBoundsException if the row is negative
298 + */
299 + @Override
300 + protected void prepareRow( int row )
301 + {
302 + if ( row < 0 )
303 + {
304 + throw new IndexOutOfBoundsException( "Cannot create a row with a negative index: " + row );
305 + }
306 +
307 + // Ensure that the requested row exists.
308 + int rowCount = getRowCount();
309 + for ( int i = rowCount; i <= row; i++ )
310 + {
311 + insertRow( i );
312 + }
313 + }
314 +
315 + /**
316 + * Gets the overall column index of this cell as if this table were a grid, as
317 + * determined by the rowspan and colspan of other cells in the table. This
318 + * helper method doesn't check the bounds on every recursive call.
319 + *
320 + * @param row the cell's row
321 + * @param column the cell's column
322 + *
323 + * @return the cell's column index
324 + *
325 + * @throws IndexOutOfBoundsException
326 + */
327 + private int getRawColumnIndex( int row, int column )
328 + {
329 + // Get cells before me in my row
330 + FlexCellFormatter formatter = getFlexCellFormatter();
331 + int columnIndex = 0;
332 + for ( int curCell = 0; curCell < column; curCell++ )
333 + {
334 + columnIndex += formatter.getColSpan( row, curCell );
335 + }
336 +
337 + // Get cells that span down into my row
338 + int numCells = 0;
339 + for ( int curRow = 0; curRow < row; curRow++ )
340 + {
341 + numCells = getCellCount( curRow );
342 + for ( int curCell = 0; curCell < numCells; curCell++ )
343 + {
344 + if ( (curRow + formatter.getRowSpan( curRow, curCell ) - 1) >= row )
345 + {
346 + if ( getRawColumnIndex( curRow, curCell ) <= columnIndex )
347 + {
348 + columnIndex += formatter.getColSpan( curRow, curCell );
349 + }
350 + }
351 + }
352 + }
353 +
354 + return columnIndex;
355 + }
309 356 }