Subversion Repository Public Repository

litesoft

@ 950
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * Copyright 2006 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.gen2.table.client;

import org.litesoft.commonfoundation.html.*;

import com.google.gwt.user.client.*;

/**
 * This class should replace the actual class of the same name.
 * <p/>
 * TODO: Incorporate changes into actual class.
 */
public class Grid extends HTMLTable {
    /**
     * Number of columns in the current grid.
     */
    protected int numColumns;

    /**
     * Number of rows in the current grid.
     */
    protected int numRows;

    /**
     * Constructor for <code>Grid</code>.
     */
    public Grid() {
        super();
        setClearText( HtmlEntity.NBSP );
        setCellFormatter( new CellFormatter() );
        setRowFormatter( new RowFormatter() );
        setColumnFormatter( new ColumnFormatter() );
    }

    /**
     * Constructs a grid with the requested size.
     *
     * @param rows    the number of rows
     * @param columns the number of columns
     *
     * @throws IndexOutOfBoundsException
     */
    public Grid( int rows, int columns ) {
        this();
        resize( rows, columns );
    }

    /**
     * Return number of columns. For grid, row argument is ignored as all grids
     * are rectangular.
     */
    @Override
    public int getCellCount( int row ) {
        return numColumns;
    }

    /**
     * Gets the number of columns in this grid.
     *
     * @return the number of columns
     */
    public int getColumnCount() {
        return numColumns;
    }

    /**
     * Return number of rows.
     */
    @Override
    public int getRowCount() {
        return numRows;
    }

    /**
     * Inserts a new row into the table. If you want to add multiple rows at once,
     * use {@link #resize(int, int)} or {@link #resizeRows(int)} as they are more
     * efficient.
     *
     * @param beforeRow the index before which the new row will be inserted
     *
     * @return the index of the newly-created row
     *
     * @throws IndexOutOfBoundsException
     */
    @Override
    public int insertRow( int beforeRow ) {
        int index = super.insertRow( beforeRow );
        numRows++;
        return index;
    }

    @Override
    public void removeRow( int row ) {
        super.removeRow( row );
        numRows--;
    }

    /**
     * Resizes the grid.
     *
     * @param rows    the number of rows
     * @param columns the number of columns
     *
     * @throws IndexOutOfBoundsException
     */
    public void resize( int rows, int columns ) {
        resizeColumns( columns );
        resizeRows( rows );
    }

    /**
     * Resizes the grid to the specified number of columns.
     *
     * @param columns the number of columns
     *
     * @throws IndexOutOfBoundsException
     */
    public void resizeColumns( int columns ) {
        if ( numColumns == columns ) {
            return;
        }
        if ( columns < 0 ) {
            throw new IndexOutOfBoundsException( "Cannot set number of columns to " + columns );
        }

        if ( numColumns > columns ) {
            // Fewer columns. Remove extraneous cells.
            for ( int i = 0; i < numRows; i++ ) {
                for ( int j = numColumns - 1; j >= columns; j-- ) {
                    removeCell( i, j );
                }
            }
        } else {
            // More columns. add cells where necessary.
            for ( int i = 0; i < numRows; i++ ) {
                for ( int j = numColumns; j < columns; j++ ) {
                    insertCell( i, j );
                }
            }
        }
        numColumns = columns;
    }

    /**
     * Resizes the grid to the specified number of rows.
     *
     * @param rows the number of rows
     *
     * @throws IndexOutOfBoundsException
     */
    public void resizeRows( int rows ) {
        if ( numRows == rows ) {
            return;
        }
        if ( rows < 0 ) {
            throw new IndexOutOfBoundsException( "Cannot set number of rows to " + rows );
        }
        if ( numRows < rows ) {
            Element tr = createRow();
            getBodyElement().appendChild( tr );
            for ( int i = numRows + 1; i < rows; i++ ) {
                getBodyElement().appendChild( tr.cloneNode( true ) );
            }
            numRows = rows;
        } else {
            while ( numRows > rows ) {
                // Fewer rows. Remove extraneous ones.
                removeRow( numRows - 1 );
            }
        }
    }

    /**
     * Creates a new, empty cell.
     */
    @Override
    protected Element createCell() {
        Element td = super.createCell();

        // Add a non-breaking space to the TD. This ensures that the cell is
        // displayed.
        DOM.setInnerHTML( td, HtmlEntity.NBSP );
        return td;
    }

    @Override
    protected Element createRow() {
        Element tr = super.createRow();
        for ( int i = 0; i < numColumns; i++ ) {
            tr.appendChild( createCell() );
        }
        return tr;
    }

    /**
     * Checks that a cell is a valid cell in the table.
     *
     * @param row    the cell's row
     * @param column the cell's column
     *
     * @throws IndexOutOfBoundsException
     */
    @Override
    protected void prepareCell( int row, int column ) {
        // Ensure that the indices are not negative.
        prepareRow( row );
        if ( column < 0 ) {
            throw new IndexOutOfBoundsException( "Cannot access a column with a negative index: " + column );
        }

        if ( column >= numColumns ) {
            throw new IndexOutOfBoundsException( "Column index: " + column + ", Column size: " + numColumns );
        }
    }

    /**
     * Checks that the column index is valid.
     *
     * @param column The column index to be checked
     *
     * @throws IndexOutOfBoundsException if the column is negative
     */
    @Override
    protected void prepareColumn( int column ) {
        // Ensure that the indices are not negative.
        if ( column < 0 ) {
            throw new IndexOutOfBoundsException( "Cannot access a column with a negative index: " + column );
        }

        /**
         * Grid does not lazily create cells, so simply ensure that the requested
         * column and column are valid
         */
        if ( column >= numColumns ) {
            throw new IndexOutOfBoundsException( "Column index: " + column + ", Column size: " + numColumns );
        }
    }

    /**
     * Checks that the row index is valid.
     *
     * @param row The row index to be checked
     *
     * @throws IndexOutOfBoundsException if the row is negative
     */
    @Override
    protected void prepareRow( int row ) {
        // Ensure that the indices are not negative.
        if ( row < 0 ) {
            throw new IndexOutOfBoundsException( "Cannot access a row with a negative index: " + row );
        }

        /**
         * Grid does not lazily create cells, so simply ensure that the requested
         * row and column are valid
         */
        if ( row >= numRows ) {
            throw new IndexOutOfBoundsException( "Row index: " + row + ", Row size: " + numRows );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/com/google/gwt/gen2/table/client/Grid.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

942 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 23:41:46 +0000

Extracting commonfoundation

760 Diff Diff GeorgeS picture GeorgeS Wed 11 Jul, 2012 05:10:55 +0000
712 Diff Diff GeorgeS picture GeorgeS Sat 09 Jun, 2012 22:46:04 +0000

Move PAV stuff into LiteSoft

475 Diff Diff GeorgeS picture GeorgeS Sat 03 Sep, 2011 13:54:51 +0000
282 GeorgeS picture GeorgeS Fri 17 Jun, 2011 13:54:39 +0000