Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/AbstractSizeableTwoDimensionalPanel.java

Diff revisions: vs.
  @@ -1,360 +1,360 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.widgets.nonpublic;
3 -
4 - import com.google.gwt.user.client.*;
5 - import com.google.gwt.user.client.ui.*;
6 -
7 - import java.util.*;
8 -
9 - public abstract class AbstractSizeableTwoDimensionalPanel extends AbstractSizeableHasAlignmentPanel implements IndexedPanel {
10 - /**
11 - * Table element.
12 - */
13 - private Element tableElem;
14 -
15 - /**
16 - * Table's body.
17 - */
18 - private Element bodyElem;
19 -
20 - private WidgetCollection mChildren = new WidgetCollection( this );
21 -
22 - protected AbstractSizeableTwoDimensionalPanel() {
23 - tableElem = DOM.createTable();
24 - bodyElem = DOM.createTBody();
25 - DOM.appendChild( tableElem, bodyElem );
26 - setElement( tableElem ); // todo: ...
27 - }
28 -
29 - @Override
30 - public boolean anyChildren() {
31 - return (mChildren.size() != 0);
32 - }
33 -
34 - // vvvvvvvvvvv HasWidgets
35 -
36 - /**
37 - * Removes all child widgets.
38 - */
39 - @Override
40 - public void clear() {
41 - if ( anyChildren() ) {
42 - // todo: ...
43 - }
44 - }
45 -
46 - /**
47 - * Gets an iterator for the contained widgets. This iterator is required to
48 - * implement {@link Iterator#remove()}.
49 - */
50 - @SuppressWarnings({"unchecked"})
51 - @Override
52 - public Iterator iterator() {
53 - return mChildren.iterator();
54 - }
55 -
56 - /**
57 - * Adds a child widget.
58 - *
59 - * @param pWidget the widget to be added
60 - *
61 - * @throws UnsupportedOperationException if this method is not supported (most
62 - * often this means that a specific overload must be called)
63 - */
64 - @Override
65 - public void add( Widget pWidget ) {
66 - // todo: ...
67 - }
68 -
69 - /**
70 - * Removes a child widget.
71 - *
72 - * @param pWidget the widget to be removed
73 - *
74 - * @return <code>true</code> if the widget was present
75 - */
76 - @Override
77 - public boolean remove( Widget pWidget ) {
78 - // Make sure this panel actually contains the child widget.
79 - if ( !mChildren.contains( pWidget ) ) {
80 - return false;
81 - }
82 -
83 - // Disown it.
84 - disown( pWidget );
85 - return true;
86 - }
87 -
88 - // ^^^^^^^^^^^ HasWidgets
89 -
90 - // vvvvvvvvvvv IndexedPanel
91 -
92 - @Override
93 - public Widget getWidget( int pIndex ) {
94 - return null; // todo: getChildren().get( pIndex );
95 - }
96 -
97 - @Override
98 - public int getWidgetCount() {
99 - return 0; // todo: getChildren().size();
100 - }
101 -
102 - @Override
103 - public int getWidgetIndex( Widget pChild ) {
104 - return 0; // todo: getChildren().indexOf( pChild );
105 - }
106 -
107 - @Override
108 - public boolean remove( int pIndex ) {
109 - return remove( getWidget( pIndex ) );
110 - }
111 -
112 - // ^^^^^^^^^^^ IndexedPanel
113 -
114 - /**
115 - * Sets the horizontal alignment of the last cell.
116 - *
117 - * @param hAlign a constant representing left, center or right alignment
118 - *
119 - * @see HasAlignment
120 - */
121 - public void setCellHorizontalAlignment( HorizontalAlignmentConstant hAlign ) {
122 - // if ( m_cellMap.size() == 0 )
123 - // {
124 - // throw new IllegalStateException();
125 - // }
126 - //
127 - // setCellHorizontalAlignment( getCellCount() - 1, hAlign );
128 - }
129 -
130 - /**
131 - * Sets the vertical alignment of the last cell.
132 - *
133 - * @param vAlign a constant representing top, middle or bottom alignment
134 - *
135 - * @see HasAlignment
136 - */
137 - public void setCellVerticalAlignment( VerticalAlignmentConstant vAlign ) {
138 - // if ( m_cellMap.size() == 0 )
139 - // {
140 - // throw new IllegalStateException();
141 - // }
142 - //
143 - // setCellVerticalAlignment( getCellCount() - 1, vAlign );
144 - }
145 -
146 - public static void setTdHorizontalAlignment( Element td, HorizontalAlignmentConstant hAlign ) {
147 - CommonElementHelper.setTDalign( td, hAlign );
148 - }
149 -
150 - public static void setTdVerticalAlignment( Element td, VerticalAlignmentConstant vAlign ) {
151 - CommonElementHelper.setTDvAlign( td, vAlign );
152 - }
153 -
154 - /**
155 - * Gets the column span for the given cell. This is the number of logical
156 - * columns covered by the cell.
157 - *
158 - * @param row the cell's row
159 - * @param column the cell's column
160 - *
161 - * @return the cell's column span
162 - *
163 - * @throws IndexOutOfBoundsException
164 - */
165 - public int getColSpan( int row, int column ) {
166 - return DOM.getElementPropertyInt( getElement( row, column ), "colSpan" );
167 - }
168 -
169 - /**
170 - * Gets the row span for the given cell. This is the number of logical rows
171 - * covered by the cell.
172 - *
173 - * @param row the cell's row
174 - * @param column the cell's column
175 - *
176 - * @return the cell's row span
177 - *
178 - * @throws IndexOutOfBoundsException
179 - */
180 - public int getRowSpan( int row, int column ) {
181 - return DOM.getElementPropertyInt( getElement( row, column ), "rowSpan" );
182 - }
183 -
184 - /**
185 - * Gets the TD element representing the specified cell.
186 - *
187 - * @param row the row of the cell to be retrieved
188 - * @param column the column of the cell to be retrieved
189 - *
190 - * @return the column's TD element
191 - *
192 - * @throws IndexOutOfBoundsException
193 - */
194 - public Element getElement( int row, int column ) {
195 - checkCellBounds( row, column );
196 - return getCellElement( bodyElem, row, column );
197 - }
198 -
199 - /**
200 - * Bounds checks that the cell exists at the specified location.
201 - *
202 - * @param row cell's row
203 - * @param column cell's column
204 - *
205 - * @throws IndexOutOfBoundsException
206 - */
207 - protected void checkCellBounds( int row, int column ) {
208 - checkRowBounds( row );
209 - if ( column < 0 ) {
210 - throw new IndexOutOfBoundsException( "Column " + column + " must be non-negative: " + column );
211 - }
212 - int cellSize = getCellCount( row );
213 - if ( cellSize <= column ) {
214 - throw new IndexOutOfBoundsException( "Column index: " + column + ", Column size: " + getCellCount( row ) );
215 - }
216 - }
217 -
218 - /**
219 - * Checks that the row is within the correct bounds.
220 - *
221 - * @param row row index to check
222 - *
223 - * @throws IndexOutOfBoundsException
224 - */
225 - protected void checkRowBounds( int row ) {
226 - int rowSize = getRowCount();
227 - if ( (row >= rowSize) || (row < 0) ) {
228 - throw new IndexOutOfBoundsException( "Row index: " + row + ", Row size: " + rowSize );
229 - }
230 - }
231 -
232 - /**
233 - * Gets the number of rows present in this table.
234 - *
235 - * @return the table's row count
236 - */
237 - public abstract int getRowCount();
238 -
239 - /**
240 - * Gets the number of cells in a given row.
241 - *
242 - * @param row the row whose cells are to be counted
243 - *
244 - * @return the number of cells present in the row
245 - */
246 - public abstract int getCellCount( int row );
247 -
248 - /**
249 - * Native method to get a cell's element.
250 - *
251 - * @param table the table element
252 - * @param row the row of the cell
253 - * @param col the column of the cell
254 - *
255 - * @return the element
256 - */
257 - private native Element getCellElement( Element table, int row, int col ) /*-{
258 - var out = table.rows[row].cells[col];
259 - return (out == null ? null : out);
260 - }-*/;
261 -
262 - @Override
263 - protected final Element adopt( Widget w, Element container ) {
264 - throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" );
265 - }
266 -
267 - /**
268 - * Do everything to insert pWidget at the appropriate place
269 - *
270 - * @param pWidget !null
271 - */
272 - protected void adopt( Widget pWidget, int pBeforeIndex ) {
273 - if ( aboutToAdopt( pWidget, pBeforeIndex ) ) {
274 - LLadopt( pWidget, pBeforeIndex );
275 - justAdopted( pWidget, pBeforeIndex );
276 - }
277 - }
278 -
279 - /**
280 - * Do everything to remove pWidget
281 - *
282 - * @param pWidget !null
283 - */
284 - @Override
285 - protected Element disown( Widget pWidget ) {
286 - int index = mChildren.indexOf( pWidget );
287 - if ( index == -1 ) {
288 - throw new IllegalStateException( "Attempt to 'disown' widget (" + pWidget + ") not owned by: " + this );
289 - }
290 - if ( aboutToDisown( pWidget, index ) ) {
291 - LLdisown( pWidget, index );
292 - justDisowned( pWidget, index );
293 - }
294 - return null; // We Don't Care
295 - }
296 -
297 - protected void LLdisown( Widget pWidget, int pIndex ) {
298 - Element td = abstractSizeablePanel_disown( pWidget ); // remove Widget from td
299 - DOM.removeChild( getContainerElement(), unwrap( td ) );
300 - mChildren.remove( pIndex );
301 - }
302 -
303 - protected void LLadopt( Widget pWidget, int pBeforeIndex ) {
304 - pWidget.removeFromParent();
305 - Element td = DOM.createTD();
306 - abstractSizeablePanel_adopt( pWidget, td ); // put Widget in TD
307 - DOM.insertChild( getContainerElement(), wrap( td ), pBeforeIndex );
308 - mChildren.insert( pWidget, pBeforeIndex );
309 - }
310 -
311 - protected Element abstractSizeablePanel_disown( Widget pWidget ) {
312 - return super.disown( pWidget );
313 - }
314 -
315 - protected void abstractSizeablePanel_adopt( Widget pWidget, Element pContainer ) {
316 - super.adopt( pWidget, pContainer );
317 - }
318 -
319 - /**
320 - * Override point for special behavior of index based addition, before adding.
321 - * Could throw an exception!
322 - *
323 - * @return true if OK to add
324 - */
325 - @SuppressWarnings({"UnusedParameters"})
326 - protected boolean aboutToAdopt( Widget pWidget, int pBeforeIndex ) {
327 - return true;
328 - }
329 -
330 - /**
331 - * Override point for special behavior of index based addition.
332 - * Should not throw an exception!
333 - */
334 - @SuppressWarnings({"UnusedParameters"})
335 - protected void justAdopted( Widget pWidget, int pWidgetIndex ) {
336 - }
337 -
338 - /**
339 - * Override point for special behavior of index based removal, before removing.
340 - * Could throw an exception!
341 - *
342 - * @return true if OK to add
343 - */
344 - @SuppressWarnings({"UnusedParameters"})
345 - protected boolean aboutToDisown( Widget pWidget, int pBeforeIndex ) {
346 - return true;
347 - }
348 -
349 - /**
350 - * Override point for special behavior of index based removal.
351 - * Should not throw an exception!
352 - */
353 - @SuppressWarnings({"UnusedParameters"})
354 - protected void justDisowned( Widget pWidget, int pWidgetIndex ) {
355 - }
356 -
357 - abstract protected Element unwrap( Element pTD );
358 -
359 - abstract protected Element wrap( Element pTD );
360 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.widgets.nonpublic;
3 +
4 + import com.google.gwt.user.client.*;
5 + import com.google.gwt.user.client.ui.*;
6 +
7 + import java.util.*;
8 +
9 + public abstract class AbstractSizeableTwoDimensionalPanel extends AbstractSizeableHasAlignmentPanel implements IndexedPanel {
10 + /**
11 + * Table element.
12 + */
13 + private Element tableElem;
14 +
15 + /**
16 + * Table's body.
17 + */
18 + private Element bodyElem;
19 +
20 + private WidgetCollection mChildren = new WidgetCollection( this );
21 +
22 + protected AbstractSizeableTwoDimensionalPanel() {
23 + tableElem = DOM.createTable();
24 + bodyElem = DOM.createTBody();
25 + DOM.appendChild( tableElem, bodyElem );
26 + setElement( tableElem ); // todo: ...
27 + }
28 +
29 + @Override
30 + public boolean anyChildren() {
31 + return (mChildren.size() != 0);
32 + }
33 +
34 + // vvvvvvvvvvv HasWidgets
35 +
36 + /**
37 + * Removes all child widgets.
38 + */
39 + @Override
40 + public void clear() {
41 + if ( anyChildren() ) {
42 + // todo: ...
43 + }
44 + }
45 +
46 + /**
47 + * Gets an iterator for the contained widgets. This iterator is required to
48 + * implement {@link Iterator#remove()}.
49 + */
50 + @SuppressWarnings({"unchecked"})
51 + @Override
52 + public Iterator iterator() {
53 + return mChildren.iterator();
54 + }
55 +
56 + /**
57 + * Adds a child widget.
58 + *
59 + * @param pWidget the widget to be added
60 + *
61 + * @throws UnsupportedOperationException if this method is not supported (most
62 + * often this means that a specific overload must be called)
63 + */
64 + @Override
65 + public void add( Widget pWidget ) {
66 + // todo: ...
67 + }
68 +
69 + /**
70 + * Removes a child widget.
71 + *
72 + * @param pWidget the widget to be removed
73 + *
74 + * @return <code>true</code> if the widget was present
75 + */
76 + @Override
77 + public boolean remove( Widget pWidget ) {
78 + // Make sure this panel actually contains the child widget.
79 + if ( !mChildren.contains( pWidget ) ) {
80 + return false;
81 + }
82 +
83 + // Disown it.
84 + disown( pWidget );
85 + return true;
86 + }
87 +
88 + // ^^^^^^^^^^^ HasWidgets
89 +
90 + // vvvvvvvvvvv IndexedPanel
91 +
92 + @Override
93 + public Widget getWidget( int pIndex ) {
94 + return null; // todo: getChildren().get( pIndex );
95 + }
96 +
97 + @Override
98 + public int getWidgetCount() {
99 + return 0; // todo: getChildren().size();
100 + }
101 +
102 + @Override
103 + public int getWidgetIndex( Widget pChild ) {
104 + return 0; // todo: getChildren().indexOf( pChild );
105 + }
106 +
107 + @Override
108 + public boolean remove( int pIndex ) {
109 + return remove( getWidget( pIndex ) );
110 + }
111 +
112 + // ^^^^^^^^^^^ IndexedPanel
113 +
114 + /**
115 + * Sets the horizontal alignment of the last cell.
116 + *
117 + * @param hAlign a constant representing left, center or right alignment
118 + *
119 + * @see HasAlignment
120 + */
121 + public void setCellHorizontalAlignment( HorizontalAlignmentConstant hAlign ) {
122 + // if ( m_cellMap.size() == 0 )
123 + // {
124 + // throw new IllegalStateException();
125 + // }
126 + //
127 + // setCellHorizontalAlignment( getCellCount() - 1, hAlign );
128 + }
129 +
130 + /**
131 + * Sets the vertical alignment of the last cell.
132 + *
133 + * @param vAlign a constant representing top, middle or bottom alignment
134 + *
135 + * @see HasAlignment
136 + */
137 + public void setCellVerticalAlignment( VerticalAlignmentConstant vAlign ) {
138 + // if ( m_cellMap.size() == 0 )
139 + // {
140 + // throw new IllegalStateException();
141 + // }
142 + //
143 + // setCellVerticalAlignment( getCellCount() - 1, vAlign );
144 + }
145 +
146 + public static void setTdHorizontalAlignment( Element td, HorizontalAlignmentConstant hAlign ) {
147 + CommonElementHelper.setTDalign( td, hAlign );
148 + }
149 +
150 + public static void setTdVerticalAlignment( Element td, VerticalAlignmentConstant vAlign ) {
151 + CommonElementHelper.setTDvAlign( td, vAlign );
152 + }
153 +
154 + /**
155 + * Gets the column span for the given cell. This is the number of logical
156 + * columns covered by the cell.
157 + *
158 + * @param row the cell's row
159 + * @param column the cell's column
160 + *
161 + * @return the cell's column span
162 + *
163 + * @throws IndexOutOfBoundsException
164 + */
165 + public int getColSpan( int row, int column ) {
166 + return DOM.getElementPropertyInt( getElement( row, column ), "colSpan" );
167 + }
168 +
169 + /**
170 + * Gets the row span for the given cell. This is the number of logical rows
171 + * covered by the cell.
172 + *
173 + * @param row the cell's row
174 + * @param column the cell's column
175 + *
176 + * @return the cell's row span
177 + *
178 + * @throws IndexOutOfBoundsException
179 + */
180 + public int getRowSpan( int row, int column ) {
181 + return DOM.getElementPropertyInt( getElement( row, column ), "rowSpan" );
182 + }
183 +
184 + /**
185 + * Gets the TD element representing the specified cell.
186 + *
187 + * @param row the row of the cell to be retrieved
188 + * @param column the column of the cell to be retrieved
189 + *
190 + * @return the column's TD element
191 + *
192 + * @throws IndexOutOfBoundsException
193 + */
194 + public Element getElement( int row, int column ) {
195 + checkCellBounds( row, column );
196 + return getCellElement( bodyElem, row, column );
197 + }
198 +
199 + /**
200 + * Bounds checks that the cell exists at the specified location.
201 + *
202 + * @param row cell's row
203 + * @param column cell's column
204 + *
205 + * @throws IndexOutOfBoundsException
206 + */
207 + protected void checkCellBounds( int row, int column ) {
208 + checkRowBounds( row );
209 + if ( column < 0 ) {
210 + throw new IndexOutOfBoundsException( "Column " + column + " must be non-negative: " + column );
211 + }
212 + int cellSize = getCellCount( row );
213 + if ( cellSize <= column ) {
214 + throw new IndexOutOfBoundsException( "Column index: " + column + ", Column size: " + getCellCount( row ) );
215 + }
216 + }
217 +
218 + /**
219 + * Checks that the row is within the correct bounds.
220 + *
221 + * @param row row index to check
222 + *
223 + * @throws IndexOutOfBoundsException
224 + */
225 + protected void checkRowBounds( int row ) {
226 + int rowSize = getRowCount();
227 + if ( (row >= rowSize) || (row < 0) ) {
228 + throw new IndexOutOfBoundsException( "Row index: " + row + ", Row size: " + rowSize );
229 + }
230 + }
231 +
232 + /**
233 + * Gets the number of rows present in this table.
234 + *
235 + * @return the table's row count
236 + */
237 + public abstract int getRowCount();
238 +
239 + /**
240 + * Gets the number of cells in a given row.
241 + *
242 + * @param row the row whose cells are to be counted
243 + *
244 + * @return the number of cells present in the row
245 + */
246 + public abstract int getCellCount( int row );
247 +
248 + /**
249 + * Native method to get a cell's element.
250 + *
251 + * @param table the table element
252 + * @param row the row of the cell
253 + * @param col the column of the cell
254 + *
255 + * @return the element
256 + */
257 + private native Element getCellElement( Element table, int row, int col ) /*-{
258 + var out = table.rows[row].cells[col];
259 + return (out == null ? null : out);
260 + }-*/;
261 +
262 + @Override
263 + protected final Element adopt( Widget w, Element container ) {
264 + throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" );
265 + }
266 +
267 + /**
268 + * Do everything to insert pWidget at the appropriate place
269 + *
270 + * @param pWidget !null
271 + */
272 + protected void adopt( Widget pWidget, int pBeforeIndex ) {
273 + if ( aboutToAdopt( pWidget, pBeforeIndex ) ) {
274 + LLadopt( pWidget, pBeforeIndex );
275 + justAdopted( pWidget, pBeforeIndex );
276 + }
277 + }
278 +
279 + /**
280 + * Do everything to remove pWidget
281 + *
282 + * @param pWidget !null
283 + */
284 + @Override
285 + protected Element disown( Widget pWidget ) {
286 + int index = mChildren.indexOf( pWidget );
287 + if ( index == -1 ) {
288 + throw new IllegalStateException( "Attempt to 'disown' widget (" + pWidget + ") not owned by: " + this );
289 + }
290 + if ( aboutToDisown( pWidget, index ) ) {
291 + LLdisown( pWidget, index );
292 + justDisowned( pWidget, index );
293 + }
294 + return null; // We Don't Care
295 + }
296 +
297 + protected void LLdisown( Widget pWidget, int pIndex ) {
298 + Element td = abstractSizeablePanel_disown( pWidget ); // remove Widget from td
299 + DOM.removeChild( getContainerElement(), unwrap( td ) );
300 + mChildren.remove( pIndex );
301 + }
302 +
303 + protected void LLadopt( Widget pWidget, int pBeforeIndex ) {
304 + pWidget.removeFromParent();
305 + Element td = DOM.createTD();
306 + abstractSizeablePanel_adopt( pWidget, td ); // put Widget in TD
307 + DOM.insertChild( getContainerElement(), wrap( td ), pBeforeIndex );
308 + mChildren.insert( pWidget, pBeforeIndex );
309 + }
310 +
311 + protected Element abstractSizeablePanel_disown( Widget pWidget ) {
312 + return super.disown( pWidget );
313 + }
314 +
315 + protected void abstractSizeablePanel_adopt( Widget pWidget, Element pContainer ) {
316 + super.adopt( pWidget, pContainer );
317 + }
318 +
319 + /**
320 + * Override point for special behavior of index based addition, before adding.
321 + * Could throw an exception!
322 + *
323 + * @return true if OK to add
324 + */
325 + @SuppressWarnings({"UnusedParameters"})
326 + protected boolean aboutToAdopt( Widget pWidget, int pBeforeIndex ) {
327 + return true;
328 + }
329 +
330 + /**
331 + * Override point for special behavior of index based addition.
332 + * Should not throw an exception!
333 + */
334 + @SuppressWarnings({"UnusedParameters"})
335 + protected void justAdopted( Widget pWidget, int pWidgetIndex ) {
336 + }
337 +
338 + /**
339 + * Override point for special behavior of index based removal, before removing.
340 + * Could throw an exception!
341 + *
342 + * @return true if OK to add
343 + */
344 + @SuppressWarnings({"UnusedParameters"})
345 + protected boolean aboutToDisown( Widget pWidget, int pBeforeIndex ) {
346 + return true;
347 + }
348 +
349 + /**
350 + * Override point for special behavior of index based removal.
351 + * Should not throw an exception!
352 + */
353 + @SuppressWarnings({"UnusedParameters"})
354 + protected void justDisowned( Widget pWidget, int pWidgetIndex ) {
355 + }
356 +
357 + abstract protected Element unwrap( Element pTD );
358 +
359 + abstract protected Element wrap( Element pTD );
360 + }