Subversion Repository Public Repository

litesoft

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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.client.widgets.nonpublic;

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

import java.util.*;

public abstract class AbstractSizeableTwoDimensionalPanel extends AbstractSizeableHasAlignmentPanel implements IndexedPanel {
    /**
     * Table element.
     */
    private Element tableElem;

    /**
     * Table's body.
     */
    private Element bodyElem;

    private WidgetCollection mChildren = new WidgetCollection( this );

    protected AbstractSizeableTwoDimensionalPanel() {
        tableElem = DOM.createTable();
        bodyElem = DOM.createTBody();
        DOM.appendChild( tableElem, bodyElem );
        setElement( tableElem ); // todo: ...
    }

    @Override
    public boolean anyChildren() {
        return (mChildren.size() != 0);
    }

    // vvvvvvvvvvv HasWidgets

    /**
     * Removes all child widgets.
     */
    @Override
    public void clear() {
        if ( anyChildren() ) {
            // todo: ...
        }
    }

    /**
     * Gets an iterator for the contained widgets. This iterator is required to
     * implement {@link Iterator#remove()}.
     */
    @SuppressWarnings({"unchecked"})
    @Override
    public Iterator iterator() {
        return mChildren.iterator();
    }

    /**
     * Adds a child widget.
     *
     * @param pWidget the widget to be added
     *
     * @throws UnsupportedOperationException if this method is not supported (most
     *                                       often this means that a specific overload must be called)
     */
    @Override
    public void add( Widget pWidget ) {
        // todo: ...
    }

    /**
     * Removes a child widget.
     *
     * @param pWidget the widget to be removed
     *
     * @return <code>true</code> if the widget was present
     */
    @Override
    public boolean remove( Widget pWidget ) {
        // Make sure this panel actually contains the child widget.
        if ( !mChildren.contains( pWidget ) ) {
            return false;
        }

        // Disown it.
        disown( pWidget );
        return true;
    }

    // ^^^^^^^^^^^ HasWidgets

    // vvvvvvvvvvv IndexedPanel

    @Override
    public Widget getWidget( int pIndex ) {
        return null; // todo: getChildren().get( pIndex );
    }

    @Override
    public int getWidgetCount() {
        return 0; // todo: getChildren().size();
    }

    @Override
    public int getWidgetIndex( Widget pChild ) {
        return 0; // todo: getChildren().indexOf( pChild );
    }

    @Override
    public boolean remove( int pIndex ) {
        return remove( getWidget( pIndex ) );
    }

    // ^^^^^^^^^^^ IndexedPanel

    /**
     * Sets the horizontal alignment of the last cell.
     *
     * @param hAlign a constant representing left, center or right alignment
     *
     * @see HasAlignment
     */
    public void setCellHorizontalAlignment( HorizontalAlignmentConstant hAlign ) {
//        if ( m_cellMap.size() == 0 )
//        {
//            throw new IllegalStateException();
//        }
//
//        setCellHorizontalAlignment( getCellCount() - 1, hAlign );
    }

    /**
     * Sets the vertical alignment of the last cell.
     *
     * @param vAlign a constant representing top, middle or bottom alignment
     *
     * @see HasAlignment
     */
    public void setCellVerticalAlignment( VerticalAlignmentConstant vAlign ) {
//        if ( m_cellMap.size() == 0 )
//        {
//            throw new IllegalStateException();
//        }
//
//        setCellVerticalAlignment( getCellCount() - 1, vAlign );
    }

    public static void setTdHorizontalAlignment( Element td, HorizontalAlignmentConstant hAlign ) {
        CommonElementHelper.setTDalign( td, hAlign );
    }

    public static void setTdVerticalAlignment( Element td, VerticalAlignmentConstant vAlign ) {
        CommonElementHelper.setTDvAlign( td, vAlign );
    }

    /**
     * Gets the column span for the given cell. This is the number of logical
     * columns covered by the cell.
     *
     * @param row    the cell's row
     * @param column the cell's column
     *
     * @return the cell's column span
     *
     * @throws IndexOutOfBoundsException
     */
    public int getColSpan( int row, int column ) {
        return DOM.getElementPropertyInt( getElement( row, column ), "colSpan" );
    }

    /**
     * Gets the row span for the given cell. This is the number of logical rows
     * covered by the cell.
     *
     * @param row    the cell's row
     * @param column the cell's column
     *
     * @return the cell's row span
     *
     * @throws IndexOutOfBoundsException
     */
    public int getRowSpan( int row, int column ) {
        return DOM.getElementPropertyInt( getElement( row, column ), "rowSpan" );
    }

    /**
     * Gets the TD element representing the specified cell.
     *
     * @param row    the row of the cell to be retrieved
     * @param column the column of the cell to be retrieved
     *
     * @return the column's TD element
     *
     * @throws IndexOutOfBoundsException
     */
    public Element getElement( int row, int column ) {
        checkCellBounds( row, column );
        return getCellElement( bodyElem, row, column );
    }

    /**
     * Bounds checks that the cell exists at the specified location.
     *
     * @param row    cell's row
     * @param column cell's column
     *
     * @throws IndexOutOfBoundsException
     */
    protected void checkCellBounds( int row, int column ) {
        checkRowBounds( row );
        if ( column < 0 ) {
            throw new IndexOutOfBoundsException( "Column " + column + " must be non-negative: " + column );
        }
        int cellSize = getCellCount( row );
        if ( cellSize <= column ) {
            throw new IndexOutOfBoundsException( "Column index: " + column + ", Column size: " + getCellCount( row ) );
        }
    }

    /**
     * Checks that the row is within the correct bounds.
     *
     * @param row row index to check
     *
     * @throws IndexOutOfBoundsException
     */
    protected void checkRowBounds( int row ) {
        int rowSize = getRowCount();
        if ( (row >= rowSize) || (row < 0) ) {
            throw new IndexOutOfBoundsException( "Row index: " + row + ", Row size: " + rowSize );
        }
    }

    /**
     * Gets the number of rows present in this table.
     *
     * @return the table's row count
     */
    public abstract int getRowCount();

    /**
     * Gets the number of cells in a given row.
     *
     * @param row the row whose cells are to be counted
     *
     * @return the number of cells present in the row
     */
    public abstract int getCellCount( int row );

    /**
     * Native method to get a cell's element.
     *
     * @param table the table element
     * @param row   the row of the cell
     * @param col   the column of the cell
     *
     * @return the element
     */
    private native Element getCellElement( Element table, int row, int col ) /*-{
        var out = table.rows[row].cells[col];
        return (out == null ? null : out);
    }-*/;

    @Override
    protected final Element adopt( Widget w, Element container ) {
        throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" );
    }

    /**
     * Do everything to insert pWidget at the appropriate place
     *
     * @param pWidget !null
     */
    protected void adopt( Widget pWidget, int pBeforeIndex ) {
        if ( aboutToAdopt( pWidget, pBeforeIndex ) ) {
            LLadopt( pWidget, pBeforeIndex );
            justAdopted( pWidget, pBeforeIndex );
        }
    }

    /**
     * Do everything to remove pWidget
     *
     * @param pWidget !null
     */
    @Override
    protected Element disown( Widget pWidget ) {
        int index = mChildren.indexOf( pWidget );
        if ( index == -1 ) {
            throw new IllegalStateException( "Attempt to 'disown' widget (" + pWidget + ") not owned by: " + this );
        }
        if ( aboutToDisown( pWidget, index ) ) {
            LLdisown( pWidget, index );
            justDisowned( pWidget, index );
        }
        return null; // We Don't Care
    }

    protected void LLdisown( Widget pWidget, int pIndex ) {
        Element td = abstractSizeablePanel_disown( pWidget ); // remove Widget from td
        DOM.removeChild( getContainerElement(), unwrap( td ) );
        mChildren.remove( pIndex );
    }

    protected void LLadopt( Widget pWidget, int pBeforeIndex ) {
        pWidget.removeFromParent();
        Element td = DOM.createTD();
        abstractSizeablePanel_adopt( pWidget, td ); // put Widget in TD
        DOM.insertChild( getContainerElement(), wrap( td ), pBeforeIndex );
        mChildren.insert( pWidget, pBeforeIndex );
    }

    protected Element abstractSizeablePanel_disown( Widget pWidget ) {
        return super.disown( pWidget );
    }

    protected void abstractSizeablePanel_adopt( Widget pWidget, Element pContainer ) {
        super.adopt( pWidget, pContainer );
    }

    /**
     * Override point for special behavior of index based addition, before adding.
     * Could throw an exception!
     *
     * @return true if OK to add
     */
    @SuppressWarnings({"UnusedParameters"})
    protected boolean aboutToAdopt( Widget pWidget, int pBeforeIndex ) {
        return true;
    }

    /**
     * Override point for special behavior of index based addition.
     * Should not throw an exception!
     */
    @SuppressWarnings({"UnusedParameters"})
    protected void justAdopted( Widget pWidget, int pWidgetIndex ) {
    }

    /**
     * Override point for special behavior of index based removal, before removing.
     * Could throw an exception!
     *
     * @return true if OK to add
     */
    @SuppressWarnings({"UnusedParameters"})
    protected boolean aboutToDisown( Widget pWidget, int pBeforeIndex ) {
        return true;
    }

    /**
     * Override point for special behavior of index based removal.
     * Should not throw an exception!
     */
    @SuppressWarnings({"UnusedParameters"})
    protected void justDisowned( Widget pWidget, int pWidgetIndex ) {
    }

    abstract protected Element unwrap( Element pTD );

    abstract protected Element wrap( Element pTD );
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractSizeableTwoDimensionalPanel.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

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

243 Diff Diff GeorgeS picture GeorgeS Sun 05 Jun, 2011 20:29:12 +0000
151 Diff Diff GeorgeS picture GeorgeS Thu 17 Mar, 2011 04:16:22 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

23 Diff Diff GeorgeS picture GeorgeS Wed 24 Feb, 2010 00:34:32 +0000
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000