|
@@ -1,102 +1,102 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
5 |
|
- |
|
6 |
|
- |
import com.google.gwt.user.client.*; |
7 |
|
- |
import com.google.gwt.user.client.ui.*; |
8 |
|
- |
|
9 |
|
- |
import java.util.*; |
10 |
|
- |
|
11 |
|
- |
public abstract class AbstractSizeableComplexPanel extends AbstractSizeablePanel { |
12 |
|
- |
private WidgetCollection mChildren = new WidgetCollection( this ); |
13 |
|
- |
|
14 |
|
- |
/** |
15 |
|
- |
* Gets the list of children contained in this panel. |
16 |
|
- |
* |
17 |
|
- |
* @return a collection of child widgets |
18 |
|
- |
*/ |
19 |
|
- |
protected WidgetCollection getChildren() { |
20 |
|
- |
return mChildren; |
21 |
|
- |
} |
22 |
|
- |
|
23 |
|
- |
protected Widget getWidget( int index ) { |
24 |
|
- |
return getChildren().get( index ); |
25 |
|
- |
} |
26 |
|
- |
|
27 |
|
- |
protected int getWidgetCount() { |
28 |
|
- |
return getChildren().size(); |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
protected int getWidgetIndex( Widget child ) { |
32 |
|
- |
return getChildren().indexOf( child ); |
33 |
|
- |
} |
34 |
|
- |
|
35 |
|
- |
@Override |
36 |
|
- |
public boolean anyChildren() { |
37 |
|
- |
return (mChildren.size() != 0); |
38 |
|
- |
} |
39 |
|
- |
|
40 |
|
- |
@SuppressWarnings({"unchecked"}) |
41 |
|
- |
@Override |
42 |
|
- |
public Iterator iterator() { |
43 |
|
- |
return mChildren.iterator(); |
44 |
|
- |
} |
45 |
|
- |
|
46 |
|
- |
@Override |
47 |
|
- |
public boolean remove( Widget w ) { |
48 |
|
- |
// Make sure this panel actually contains the child widget. |
49 |
|
- |
if ( !mChildren.contains( w ) ) { |
50 |
|
- |
return false; |
51 |
|
- |
} |
52 |
|
- |
|
53 |
|
- |
// Disown it. |
54 |
|
- |
disown( w ); |
55 |
|
- |
|
56 |
|
- |
mChildren.remove( w ); |
57 |
|
- |
return true; |
58 |
|
- |
} |
59 |
|
- |
|
60 |
|
- |
/** |
61 |
|
- |
* Adds a new child widget to the panel. |
62 |
|
- |
* |
63 |
|
- |
* @param w the child widget to be added |
64 |
|
- |
* @param container the element within which the child will be contained |
65 |
|
- |
*/ |
66 |
|
- |
protected void add( Widget w, Element container ) { |
67 |
|
- |
insert( w, container, mChildren.size() ); |
68 |
|
- |
} |
69 |
|
- |
|
70 |
|
- |
/** |
71 |
|
- |
* Inserts a new child widget into the panel. |
72 |
|
- |
* |
73 |
|
- |
* @param child the child widget to be added |
74 |
|
- |
* @param container the element within which the child will be contained |
75 |
|
- |
* @param beforeIndex the index before which the widget will be added |
76 |
|
- |
*/ |
77 |
|
- |
protected void insert( Widget child, Element container, int beforeIndex ) { |
78 |
|
- |
beforeIndex = adjustIndexIfChildInteracts( beforeIndex, child ); |
79 |
|
- |
|
80 |
|
- |
adopt( child, container ); |
81 |
|
- |
|
82 |
|
- |
mChildren.insert( child, beforeIndex ); |
83 |
|
- |
} |
84 |
|
- |
|
85 |
|
- |
protected int adjustIndexIfChildInteracts( int pBeforeIndex, Widget pChild ) { |
86 |
|
- |
validateInsertionIndex( pBeforeIndex ); |
87 |
|
- |
|
88 |
|
- |
if ( (pChild.getParent() == this) && (getWidgetIndex( pChild ) < pBeforeIndex) ) { |
89 |
|
- |
return pBeforeIndex - 1; |
90 |
|
- |
} |
91 |
|
- |
|
92 |
|
- |
return pBeforeIndex; |
93 |
|
- |
} |
94 |
|
- |
|
95 |
|
- |
protected void validateReadIndex( int pIndex ) { |
96 |
|
- |
Integers.validateIndex( pIndex, getWidgetCount(), false ); |
97 |
|
- |
} |
98 |
|
- |
|
99 |
|
- |
protected void validateInsertionIndex( int pIndex ) { |
100 |
|
- |
Integers.validateIndex( pIndex, getWidgetCount(), true ); |
101 |
|
- |
} |
102 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
|
5 |
+ |
|
|
6 |
+ |
import com.google.gwt.user.client.*; |
|
7 |
+ |
import com.google.gwt.user.client.ui.*; |
|
8 |
+ |
|
|
9 |
+ |
import java.util.*; |
|
10 |
+ |
|
|
11 |
+ |
public abstract class AbstractSizeableComplexPanel extends AbstractSizeablePanel { |
|
12 |
+ |
private WidgetCollection mChildren = new WidgetCollection( this ); |
|
13 |
+ |
|
|
14 |
+ |
/** |
|
15 |
+ |
* Gets the list of children contained in this panel. |
|
16 |
+ |
* |
|
17 |
+ |
* @return a collection of child widgets |
|
18 |
+ |
*/ |
|
19 |
+ |
protected WidgetCollection getChildren() { |
|
20 |
+ |
return mChildren; |
|
21 |
+ |
} |
|
22 |
+ |
|
|
23 |
+ |
protected Widget getWidget( int index ) { |
|
24 |
+ |
return getChildren().get( index ); |
|
25 |
+ |
} |
|
26 |
+ |
|
|
27 |
+ |
protected int getWidgetCount() { |
|
28 |
+ |
return getChildren().size(); |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
protected int getWidgetIndex( Widget child ) { |
|
32 |
+ |
return getChildren().indexOf( child ); |
|
33 |
+ |
} |
|
34 |
+ |
|
|
35 |
+ |
@Override |
|
36 |
+ |
public boolean anyChildren() { |
|
37 |
+ |
return (mChildren.size() != 0); |
|
38 |
+ |
} |
|
39 |
+ |
|
|
40 |
+ |
@SuppressWarnings({"unchecked"}) |
|
41 |
+ |
@Override |
|
42 |
+ |
public Iterator iterator() { |
|
43 |
+ |
return mChildren.iterator(); |
|
44 |
+ |
} |
|
45 |
+ |
|
|
46 |
+ |
@Override |
|
47 |
+ |
public boolean remove( Widget w ) { |
|
48 |
+ |
// Make sure this panel actually contains the child widget. |
|
49 |
+ |
if ( !mChildren.contains( w ) ) { |
|
50 |
+ |
return false; |
|
51 |
+ |
} |
|
52 |
+ |
|
|
53 |
+ |
// Disown it. |
|
54 |
+ |
disown( w ); |
|
55 |
+ |
|
|
56 |
+ |
mChildren.remove( w ); |
|
57 |
+ |
return true; |
|
58 |
+ |
} |
|
59 |
+ |
|
|
60 |
+ |
/** |
|
61 |
+ |
* Adds a new child widget to the panel. |
|
62 |
+ |
* |
|
63 |
+ |
* @param w the child widget to be added |
|
64 |
+ |
* @param container the element within which the child will be contained |
|
65 |
+ |
*/ |
|
66 |
+ |
protected void add( Widget w, Element container ) { |
|
67 |
+ |
insert( w, container, mChildren.size() ); |
|
68 |
+ |
} |
|
69 |
+ |
|
|
70 |
+ |
/** |
|
71 |
+ |
* Inserts a new child widget into the panel. |
|
72 |
+ |
* |
|
73 |
+ |
* @param child the child widget to be added |
|
74 |
+ |
* @param container the element within which the child will be contained |
|
75 |
+ |
* @param beforeIndex the index before which the widget will be added |
|
76 |
+ |
*/ |
|
77 |
+ |
protected void insert( Widget child, Element container, int beforeIndex ) { |
|
78 |
+ |
beforeIndex = adjustIndexIfChildInteracts( beforeIndex, child ); |
|
79 |
+ |
|
|
80 |
+ |
adopt( child, container ); |
|
81 |
+ |
|
|
82 |
+ |
mChildren.insert( child, beforeIndex ); |
|
83 |
+ |
} |
|
84 |
+ |
|
|
85 |
+ |
protected int adjustIndexIfChildInteracts( int pBeforeIndex, Widget pChild ) { |
|
86 |
+ |
validateInsertionIndex( pBeforeIndex ); |
|
87 |
+ |
|
|
88 |
+ |
if ( (pChild.getParent() == this) && (getWidgetIndex( pChild ) < pBeforeIndex) ) { |
|
89 |
+ |
return pBeforeIndex - 1; |
|
90 |
+ |
} |
|
91 |
+ |
|
|
92 |
+ |
return pBeforeIndex; |
|
93 |
+ |
} |
|
94 |
+ |
|
|
95 |
+ |
protected void validateReadIndex( int pIndex ) { |
|
96 |
+ |
Integers.validateIndex( pIndex, getWidgetCount(), false ); |
|
97 |
+ |
} |
|
98 |
+ |
|
|
99 |
+ |
protected void validateInsertionIndex( int pIndex ) { |
|
100 |
+ |
Integers.validateIndex( pIndex, getWidgetCount(), true ); |
|
101 |
+ |
} |
|
102 |
+ |
} |