|
@@ -1,223 +1,223 @@ |
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 AbstractSizeableOneDimensionalPanel extends AbstractSizeableHasAlignmentPanel implements IndexedPanel { |
10 |
|
- |
private WidgetCollection mChildren = new WidgetCollection( this ); |
11 |
|
- |
|
12 |
|
- |
@Override |
13 |
|
- |
public boolean anyChildren() { |
14 |
|
- |
return (mChildren.size() != 0); |
15 |
|
- |
} |
16 |
|
- |
|
17 |
|
- |
/** |
18 |
|
- |
* Gets the list of children contained in this panel. |
19 |
|
- |
* |
20 |
|
- |
* @return a collection of child widgets |
21 |
|
- |
*/ |
22 |
|
- |
protected WidgetCollection getChildren() { |
23 |
|
- |
return mChildren; |
24 |
|
- |
} |
25 |
|
- |
|
26 |
|
- |
// vvvvvvvvvvv HasWidgets |
27 |
|
- |
|
28 |
|
- |
/** |
29 |
|
- |
* Removes all child widgets. |
30 |
|
- |
*/ |
31 |
|
- |
@Override |
32 |
|
- |
public void clear() { |
33 |
|
- |
// Reverse order for SplitPairs |
34 |
|
- |
while ( anyChildren() ) { |
35 |
|
- |
remove( getWidgetCount() - 1 ); |
36 |
|
- |
} |
37 |
|
- |
} |
38 |
|
- |
|
39 |
|
- |
/** |
40 |
|
- |
* Gets an iterator for the contained widgets. This iterator is required to |
41 |
|
- |
* implement {@link Iterator#remove()}. |
42 |
|
- |
*/ |
43 |
|
- |
@Override |
44 |
|
- |
public Iterator<Widget> iterator() { |
45 |
|
- |
return mChildren.iterator(); |
46 |
|
- |
} |
47 |
|
- |
|
48 |
|
- |
/** |
49 |
|
- |
* Adds a child widget. |
50 |
|
- |
* |
51 |
|
- |
* @param pWidget the widget to be added |
52 |
|
- |
* |
53 |
|
- |
* @throws UnsupportedOperationException if this method is not supported (most |
54 |
|
- |
* often this means that a specific overload must be called) |
55 |
|
- |
*/ |
56 |
|
- |
@Override |
57 |
|
- |
public void add( Widget pWidget ) { |
58 |
|
- |
insert( pWidget, getWidgetCount() ); |
59 |
|
- |
} |
60 |
|
- |
|
61 |
|
- |
/** |
62 |
|
- |
* Removes a child widget. |
63 |
|
- |
* |
64 |
|
- |
* @param pWidget the widget to be removed |
65 |
|
- |
* |
66 |
|
- |
* @return <code>true</code> if the widget was present |
67 |
|
- |
*/ |
68 |
|
- |
@Override |
69 |
|
- |
public boolean remove( Widget pWidget ) { |
70 |
|
- |
// Make sure this panel actually contains the child widget. |
71 |
|
- |
if ( !mChildren.contains( pWidget ) ) { |
72 |
|
- |
return false; |
73 |
|
- |
} |
74 |
|
- |
|
75 |
|
- |
// Disown it. |
76 |
|
- |
disown( pWidget ); |
77 |
|
- |
return true; |
78 |
|
- |
} |
79 |
|
- |
|
80 |
|
- |
// ^^^^^^^^^^^ HasWidgets |
81 |
|
- |
|
82 |
|
- |
/** |
83 |
|
- |
* Inserts a widget before the specified index. |
84 |
|
- |
* |
85 |
|
- |
* @param pWidget the widget to be inserted |
86 |
|
- |
* @param pBeforeIndex the index before which it will be inserted |
87 |
|
- |
* |
88 |
|
- |
* @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of |
89 |
|
- |
* range |
90 |
|
- |
*/ |
91 |
|
- |
public void insert( Widget pWidget, int pBeforeIndex ) { |
92 |
|
- |
if ( pWidget != null ) { |
93 |
|
- |
adopt( pWidget, pBeforeIndex ); |
94 |
|
- |
} |
95 |
|
- |
} |
96 |
|
- |
|
97 |
|
- |
protected Widget getFirstWidget() { |
98 |
|
- |
return anyChildren() ? getWidget( 0 ) : null; |
99 |
|
- |
} |
100 |
|
- |
|
101 |
|
- |
protected Widget getLastWidget() { |
102 |
|
- |
return anyChildren() ? getWidget( getWidgetCount() - 1 ) : null; |
103 |
|
- |
} |
104 |
|
- |
|
105 |
|
- |
// vvvvvvvvvvv IndexedPanel |
106 |
|
- |
|
107 |
|
- |
@Override |
108 |
|
- |
public Widget getWidget( int pIndex ) { |
109 |
|
- |
return getChildren().get( pIndex ); |
110 |
|
- |
} |
111 |
|
- |
|
112 |
|
- |
@Override |
113 |
|
- |
public int getWidgetCount() { |
114 |
|
- |
return getChildren().size(); |
115 |
|
- |
} |
116 |
|
- |
|
117 |
|
- |
@Override |
118 |
|
- |
public int getWidgetIndex( Widget pChild ) { |
119 |
|
- |
return getChildren().indexOf( pChild ); |
120 |
|
- |
} |
121 |
|
- |
|
122 |
|
- |
@Override |
123 |
|
- |
public boolean remove( int pIndex ) { |
124 |
|
- |
return remove( getWidget( pIndex ) ); |
125 |
|
- |
} |
126 |
|
- |
|
127 |
|
- |
// ^^^^^^^^^^^ IndexedPanel |
128 |
|
- |
|
129 |
|
- |
@Override |
130 |
|
- |
protected final Element adopt( Widget w, Element container ) { |
131 |
|
- |
throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" ); |
132 |
|
- |
} |
133 |
|
- |
|
134 |
|
- |
/** |
135 |
|
- |
* Do everything to insert pWidget at the appropriate place |
136 |
|
- |
* |
137 |
|
- |
* @param pWidget !null |
138 |
|
- |
*/ |
139 |
|
- |
protected void adopt( Widget pWidget, int pBeforeIndex ) { |
140 |
|
- |
if ( aboutToAdopt( pWidget, pBeforeIndex ) ) { |
141 |
|
- |
LLadopt( pWidget, pBeforeIndex ); |
142 |
|
- |
justAdopted( pWidget, pBeforeIndex ); |
143 |
|
- |
} |
144 |
|
- |
} |
145 |
|
- |
|
146 |
|
- |
/** |
147 |
|
- |
* Do everything to remove pWidget |
148 |
|
- |
* |
149 |
|
- |
* @param pWidget !null |
150 |
|
- |
*/ |
151 |
|
- |
@Override |
152 |
|
- |
protected Element disown( Widget pWidget ) { |
153 |
|
- |
int index = mChildren.indexOf( pWidget ); |
154 |
|
- |
if ( index == -1 ) { |
155 |
|
- |
throw new IllegalStateException( "Attempt to 'disown' widget (" + pWidget + ") not owned by: " + this ); |
156 |
|
- |
} |
157 |
|
- |
if ( aboutToDisown( pWidget, index ) ) { |
158 |
|
- |
LLdisown( pWidget, index ); |
159 |
|
- |
justDisowned( pWidget, index ); |
160 |
|
- |
} |
161 |
|
- |
return null; // We Don't Care |
162 |
|
- |
} |
163 |
|
- |
|
164 |
|
- |
protected void LLdisown( Widget pWidget, int pIndex ) { |
165 |
|
- |
Element td = abstractSizeablePanel_disown( pWidget ); // remove Widget from td |
166 |
|
- |
DOM.removeChild( getContainerElement(), unwrap( td ) ); |
167 |
|
- |
mChildren.remove( pIndex ); |
168 |
|
- |
} |
169 |
|
- |
|
170 |
|
- |
protected void LLadopt( Widget pWidget, int pBeforeIndex ) { |
171 |
|
- |
pWidget.removeFromParent(); |
172 |
|
- |
Element td = DOM.createTD(); |
173 |
|
- |
abstractSizeablePanel_adopt( pWidget, td ); // put Widget in TD |
174 |
|
- |
DOM.insertChild( getContainerElement(), wrap( td ), pBeforeIndex ); |
175 |
|
- |
mChildren.insert( pWidget, pBeforeIndex ); |
176 |
|
- |
} |
177 |
|
- |
|
178 |
|
- |
protected Element abstractSizeablePanel_disown( Widget pWidget ) { |
179 |
|
- |
return super.disown( pWidget ); |
180 |
|
- |
} |
181 |
|
- |
|
182 |
|
- |
protected void abstractSizeablePanel_adopt( Widget pWidget, Element pContainer ) { |
183 |
|
- |
super.adopt( pWidget, pContainer ); |
184 |
|
- |
} |
185 |
|
- |
|
186 |
|
- |
/** |
187 |
|
- |
* Override point for special behavior of index based addition, before adding. |
188 |
|
- |
* Could throw an exception! |
189 |
|
- |
* |
190 |
|
- |
* @return true if OK to add |
191 |
|
- |
*/ |
192 |
|
- |
protected boolean aboutToAdopt( Widget pWidget, int pBeforeIndex ) { |
193 |
|
- |
return true; |
194 |
|
- |
} |
195 |
|
- |
|
196 |
|
- |
/** |
197 |
|
- |
* Override point for special behavior of index based addition. |
198 |
|
- |
* Should not throw an exception! |
199 |
|
- |
*/ |
200 |
|
- |
protected void justAdopted( Widget pWidget, int pWidgetIndex ) { |
201 |
|
- |
} |
202 |
|
- |
|
203 |
|
- |
/** |
204 |
|
- |
* Override point for special behavior of index based removal, before removing. |
205 |
|
- |
* Could throw an exception! |
206 |
|
- |
* |
207 |
|
- |
* @return true if OK to add |
208 |
|
- |
*/ |
209 |
|
- |
protected boolean aboutToDisown( Widget pWidget, int pBeforeIndex ) { |
210 |
|
- |
return true; |
211 |
|
- |
} |
212 |
|
- |
|
213 |
|
- |
/** |
214 |
|
- |
* Override point for special behavior of index based removal. |
215 |
|
- |
* Should not throw an exception! |
216 |
|
- |
*/ |
217 |
|
- |
protected void justDisowned( Widget pWidget, int pWidgetIndex ) { |
218 |
|
- |
} |
219 |
|
- |
|
220 |
|
- |
abstract protected Element unwrap( Element pTD ); |
221 |
|
- |
|
222 |
|
- |
abstract protected Element wrap( Element pTD ); |
223 |
|
- |
} |
|
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 AbstractSizeableOneDimensionalPanel extends AbstractSizeableHasAlignmentPanel implements IndexedPanel { |
|
10 |
+ |
private WidgetCollection mChildren = new WidgetCollection( this ); |
|
11 |
+ |
|
|
12 |
+ |
@Override |
|
13 |
+ |
public boolean anyChildren() { |
|
14 |
+ |
return (mChildren.size() != 0); |
|
15 |
+ |
} |
|
16 |
+ |
|
|
17 |
+ |
/** |
|
18 |
+ |
* Gets the list of children contained in this panel. |
|
19 |
+ |
* |
|
20 |
+ |
* @return a collection of child widgets |
|
21 |
+ |
*/ |
|
22 |
+ |
protected WidgetCollection getChildren() { |
|
23 |
+ |
return mChildren; |
|
24 |
+ |
} |
|
25 |
+ |
|
|
26 |
+ |
// vvvvvvvvvvv HasWidgets |
|
27 |
+ |
|
|
28 |
+ |
/** |
|
29 |
+ |
* Removes all child widgets. |
|
30 |
+ |
*/ |
|
31 |
+ |
@Override |
|
32 |
+ |
public void clear() { |
|
33 |
+ |
// Reverse order for SplitPairs |
|
34 |
+ |
while ( anyChildren() ) { |
|
35 |
+ |
remove( getWidgetCount() - 1 ); |
|
36 |
+ |
} |
|
37 |
+ |
} |
|
38 |
+ |
|
|
39 |
+ |
/** |
|
40 |
+ |
* Gets an iterator for the contained widgets. This iterator is required to |
|
41 |
+ |
* implement {@link Iterator#remove()}. |
|
42 |
+ |
*/ |
|
43 |
+ |
@Override |
|
44 |
+ |
public Iterator<Widget> iterator() { |
|
45 |
+ |
return mChildren.iterator(); |
|
46 |
+ |
} |
|
47 |
+ |
|
|
48 |
+ |
/** |
|
49 |
+ |
* Adds a child widget. |
|
50 |
+ |
* |
|
51 |
+ |
* @param pWidget the widget to be added |
|
52 |
+ |
* |
|
53 |
+ |
* @throws UnsupportedOperationException if this method is not supported (most |
|
54 |
+ |
* often this means that a specific overload must be called) |
|
55 |
+ |
*/ |
|
56 |
+ |
@Override |
|
57 |
+ |
public void add( Widget pWidget ) { |
|
58 |
+ |
insert( pWidget, getWidgetCount() ); |
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
/** |
|
62 |
+ |
* Removes a child widget. |
|
63 |
+ |
* |
|
64 |
+ |
* @param pWidget the widget to be removed |
|
65 |
+ |
* |
|
66 |
+ |
* @return <code>true</code> if the widget was present |
|
67 |
+ |
*/ |
|
68 |
+ |
@Override |
|
69 |
+ |
public boolean remove( Widget pWidget ) { |
|
70 |
+ |
// Make sure this panel actually contains the child widget. |
|
71 |
+ |
if ( !mChildren.contains( pWidget ) ) { |
|
72 |
+ |
return false; |
|
73 |
+ |
} |
|
74 |
+ |
|
|
75 |
+ |
// Disown it. |
|
76 |
+ |
disown( pWidget ); |
|
77 |
+ |
return true; |
|
78 |
+ |
} |
|
79 |
+ |
|
|
80 |
+ |
// ^^^^^^^^^^^ HasWidgets |
|
81 |
+ |
|
|
82 |
+ |
/** |
|
83 |
+ |
* Inserts a widget before the specified index. |
|
84 |
+ |
* |
|
85 |
+ |
* @param pWidget the widget to be inserted |
|
86 |
+ |
* @param pBeforeIndex the index before which it will be inserted |
|
87 |
+ |
* |
|
88 |
+ |
* @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of |
|
89 |
+ |
* range |
|
90 |
+ |
*/ |
|
91 |
+ |
public void insert( Widget pWidget, int pBeforeIndex ) { |
|
92 |
+ |
if ( pWidget != null ) { |
|
93 |
+ |
adopt( pWidget, pBeforeIndex ); |
|
94 |
+ |
} |
|
95 |
+ |
} |
|
96 |
+ |
|
|
97 |
+ |
protected Widget getFirstWidget() { |
|
98 |
+ |
return anyChildren() ? getWidget( 0 ) : null; |
|
99 |
+ |
} |
|
100 |
+ |
|
|
101 |
+ |
protected Widget getLastWidget() { |
|
102 |
+ |
return anyChildren() ? getWidget( getWidgetCount() - 1 ) : null; |
|
103 |
+ |
} |
|
104 |
+ |
|
|
105 |
+ |
// vvvvvvvvvvv IndexedPanel |
|
106 |
+ |
|
|
107 |
+ |
@Override |
|
108 |
+ |
public Widget getWidget( int pIndex ) { |
|
109 |
+ |
return getChildren().get( pIndex ); |
|
110 |
+ |
} |
|
111 |
+ |
|
|
112 |
+ |
@Override |
|
113 |
+ |
public int getWidgetCount() { |
|
114 |
+ |
return getChildren().size(); |
|
115 |
+ |
} |
|
116 |
+ |
|
|
117 |
+ |
@Override |
|
118 |
+ |
public int getWidgetIndex( Widget pChild ) { |
|
119 |
+ |
return getChildren().indexOf( pChild ); |
|
120 |
+ |
} |
|
121 |
+ |
|
|
122 |
+ |
@Override |
|
123 |
+ |
public boolean remove( int pIndex ) { |
|
124 |
+ |
return remove( getWidget( pIndex ) ); |
|
125 |
+ |
} |
|
126 |
+ |
|
|
127 |
+ |
// ^^^^^^^^^^^ IndexedPanel |
|
128 |
+ |
|
|
129 |
+ |
@Override |
|
130 |
+ |
protected final Element adopt( Widget w, Element container ) { |
|
131 |
+ |
throw new IllegalStateException( "Inappropriate use of raw adopt( Widget w, Element container )" ); |
|
132 |
+ |
} |
|
133 |
+ |
|
|
134 |
+ |
/** |
|
135 |
+ |
* Do everything to insert pWidget at the appropriate place |
|
136 |
+ |
* |
|
137 |
+ |
* @param pWidget !null |
|
138 |
+ |
*/ |
|
139 |
+ |
protected void adopt( Widget pWidget, int pBeforeIndex ) { |
|
140 |
+ |
if ( aboutToAdopt( pWidget, pBeforeIndex ) ) { |
|
141 |
+ |
LLadopt( pWidget, pBeforeIndex ); |
|
142 |
+ |
justAdopted( pWidget, pBeforeIndex ); |
|
143 |
+ |
} |
|
144 |
+ |
} |
|
145 |
+ |
|
|
146 |
+ |
/** |
|
147 |
+ |
* Do everything to remove pWidget |
|
148 |
+ |
* |
|
149 |
+ |
* @param pWidget !null |
|
150 |
+ |
*/ |
|
151 |
+ |
@Override |
|
152 |
+ |
protected Element disown( Widget pWidget ) { |
|
153 |
+ |
int index = mChildren.indexOf( pWidget ); |
|
154 |
+ |
if ( index == -1 ) { |
|
155 |
+ |
throw new IllegalStateException( "Attempt to 'disown' widget (" + pWidget + ") not owned by: " + this ); |
|
156 |
+ |
} |
|
157 |
+ |
if ( aboutToDisown( pWidget, index ) ) { |
|
158 |
+ |
LLdisown( pWidget, index ); |
|
159 |
+ |
justDisowned( pWidget, index ); |
|
160 |
+ |
} |
|
161 |
+ |
return null; // We Don't Care |
|
162 |
+ |
} |
|
163 |
+ |
|
|
164 |
+ |
protected void LLdisown( Widget pWidget, int pIndex ) { |
|
165 |
+ |
Element td = abstractSizeablePanel_disown( pWidget ); // remove Widget from td |
|
166 |
+ |
DOM.removeChild( getContainerElement(), unwrap( td ) ); |
|
167 |
+ |
mChildren.remove( pIndex ); |
|
168 |
+ |
} |
|
169 |
+ |
|
|
170 |
+ |
protected void LLadopt( Widget pWidget, int pBeforeIndex ) { |
|
171 |
+ |
pWidget.removeFromParent(); |
|
172 |
+ |
Element td = DOM.createTD(); |
|
173 |
+ |
abstractSizeablePanel_adopt( pWidget, td ); // put Widget in TD |
|
174 |
+ |
DOM.insertChild( getContainerElement(), wrap( td ), pBeforeIndex ); |
|
175 |
+ |
mChildren.insert( pWidget, pBeforeIndex ); |
|
176 |
+ |
} |
|
177 |
+ |
|
|
178 |
+ |
protected Element abstractSizeablePanel_disown( Widget pWidget ) { |
|
179 |
+ |
return super.disown( pWidget ); |
|
180 |
+ |
} |
|
181 |
+ |
|
|
182 |
+ |
protected void abstractSizeablePanel_adopt( Widget pWidget, Element pContainer ) { |
|
183 |
+ |
super.adopt( pWidget, pContainer ); |
|
184 |
+ |
} |
|
185 |
+ |
|
|
186 |
+ |
/** |
|
187 |
+ |
* Override point for special behavior of index based addition, before adding. |
|
188 |
+ |
* Could throw an exception! |
|
189 |
+ |
* |
|
190 |
+ |
* @return true if OK to add |
|
191 |
+ |
*/ |
|
192 |
+ |
protected boolean aboutToAdopt( Widget pWidget, int pBeforeIndex ) { |
|
193 |
+ |
return true; |
|
194 |
+ |
} |
|
195 |
+ |
|
|
196 |
+ |
/** |
|
197 |
+ |
* Override point for special behavior of index based addition. |
|
198 |
+ |
* Should not throw an exception! |
|
199 |
+ |
*/ |
|
200 |
+ |
protected void justAdopted( Widget pWidget, int pWidgetIndex ) { |
|
201 |
+ |
} |
|
202 |
+ |
|
|
203 |
+ |
/** |
|
204 |
+ |
* Override point for special behavior of index based removal, before removing. |
|
205 |
+ |
* Could throw an exception! |
|
206 |
+ |
* |
|
207 |
+ |
* @return true if OK to add |
|
208 |
+ |
*/ |
|
209 |
+ |
protected boolean aboutToDisown( Widget pWidget, int pBeforeIndex ) { |
|
210 |
+ |
return true; |
|
211 |
+ |
} |
|
212 |
+ |
|
|
213 |
+ |
/** |
|
214 |
+ |
* Override point for special behavior of index based removal. |
|
215 |
+ |
* Should not throw an exception! |
|
216 |
+ |
*/ |
|
217 |
+ |
protected void justDisowned( Widget pWidget, int pWidgetIndex ) { |
|
218 |
+ |
} |
|
219 |
+ |
|
|
220 |
+ |
abstract protected Element unwrap( Element pTD ); |
|
221 |
+ |
|
|
222 |
+ |
abstract protected Element wrap( Element pTD ); |
|
223 |
+ |
} |