|
@@ -1,171 +1,171 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
5 |
|
- |
|
6 |
|
- |
import com.google.gwt.user.client.ui.*; |
7 |
|
- |
|
8 |
|
- |
public class SizeableDeckPanel extends AbstractSizeableComplexPanel implements IndexedPanel { |
9 |
|
- |
private Widget mVisibleWidget; |
10 |
|
- |
|
11 |
|
- |
public SizeableDeckPanel() { |
12 |
|
- |
initializeElements( getHelper().create_OeTable_SeDiv_IeDiv( true ), "LayoutSizeableDeckPanel" ); |
13 |
|
- |
} |
14 |
|
- |
|
15 |
|
- |
public SizeableDeckPanel style( String pStyleName ) { |
16 |
|
- |
addStyleName( pStyleName ); |
17 |
|
- |
return this; |
18 |
|
- |
} |
19 |
|
- |
|
20 |
|
- |
/** |
21 |
|
- |
* Adds the specified widget to the deck. |
22 |
|
- |
* |
23 |
|
- |
* @param w the widget to be added |
24 |
|
- |
*/ |
25 |
|
- |
@Override |
26 |
|
- |
public void add( Widget w ) { |
27 |
|
- |
insert( w, getWidgetCount() ); |
28 |
|
- |
} |
29 |
|
- |
|
30 |
|
- |
/** |
31 |
|
- |
* Gets the index of the currently-visible widget. |
32 |
|
- |
* |
33 |
|
- |
* @return the visible widget's index |
34 |
|
- |
*/ |
35 |
|
- |
public int getVisibleWidget() { |
36 |
|
- |
return getWidgetIndex( mVisibleWidget ); |
37 |
|
- |
} |
38 |
|
- |
|
39 |
|
- |
@Override |
40 |
|
- |
public Widget getWidget( int index ) { |
41 |
|
- |
return getChildren().get( index ); |
42 |
|
- |
} |
43 |
|
- |
|
44 |
|
- |
@Override |
45 |
|
- |
public int getWidgetCount() { |
46 |
|
- |
return getChildren().size(); |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
@Override |
50 |
|
- |
public int getWidgetIndex( Widget child ) { |
51 |
|
- |
return getChildren().indexOf( child ); |
52 |
|
- |
} |
53 |
|
- |
|
54 |
|
- |
/** |
55 |
|
- |
* Inserts a widget before the specified index. |
56 |
|
- |
* |
57 |
|
- |
* @param w the widget to be inserted |
58 |
|
- |
* @param beforeIndex the index before which it will be inserted |
59 |
|
- |
* |
60 |
|
- |
* @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of |
61 |
|
- |
* range |
62 |
|
- |
*/ |
63 |
|
- |
public void insert( Widget w, int beforeIndex ) { |
64 |
|
- |
if ( (beforeIndex < 0) || (beforeIndex > getWidgetCount()) ) { |
65 |
|
- |
throw new IndexOutOfBoundsException( String.valueOf( beforeIndex ) ); |
66 |
|
- |
} |
67 |
|
- |
|
68 |
|
- |
super.insert( w, getContainerElement(), beforeIndex ); |
69 |
|
- |
|
70 |
|
- |
if ( mVisibleWidget == null ) { |
71 |
|
- |
showAwidget( 0 ); |
72 |
|
- |
} else { |
73 |
|
- |
w.setVisible( false ); |
74 |
|
- |
} |
75 |
|
- |
} |
76 |
|
- |
|
77 |
|
- |
@Override |
78 |
|
- |
public boolean remove( int index ) { |
79 |
|
- |
return remove( getWidget( index ) ); |
80 |
|
- |
} |
81 |
|
- |
|
82 |
|
- |
@Override |
83 |
|
- |
public boolean remove( Widget w ) { |
84 |
|
- |
if ( !super.remove( w ) ) { |
85 |
|
- |
return false; |
86 |
|
- |
} |
87 |
|
- |
|
88 |
|
- |
if ( mVisibleWidget == w ) { |
89 |
|
- |
mVisibleWidget = null; |
90 |
|
- |
if ( getWidgetCount() != 0 ) { |
91 |
|
- |
showAwidget( 0 ); |
92 |
|
- |
} |
93 |
|
- |
} |
94 |
|
- |
|
95 |
|
- |
return true; |
96 |
|
- |
} |
97 |
|
- |
|
98 |
|
- |
/** |
99 |
|
- |
* Shows the widget at the specified index. This causes the currently- visible |
100 |
|
- |
* widget to be hidden. |
101 |
|
- |
* |
102 |
|
- |
* @param index the index of the widget to be shown |
103 |
|
- |
*/ |
104 |
|
- |
public void showWidget( int index ) { |
105 |
|
- |
checkIndex( index ); |
106 |
|
- |
|
107 |
|
- |
if ( mVisibleWidget != null ) { |
108 |
|
- |
mVisibleWidget.setVisible( false ); |
109 |
|
- |
} |
110 |
|
- |
showAwidget( index ); |
111 |
|
- |
} |
112 |
|
- |
|
113 |
|
- |
private void checkIndex( int index ) { |
114 |
|
- |
if ( (index < 0) || (index >= getWidgetCount()) ) { |
115 |
|
- |
throw new IndexOutOfBoundsException( String.valueOf( index ) ); |
116 |
|
- |
} |
117 |
|
- |
} |
118 |
|
- |
|
119 |
|
- |
//****** Implementation Code Block to support delegation to AbsoluteSizeHelper |
120 |
|
- |
|
121 |
|
- |
public SizeableDeckPanel stretchable() { |
122 |
|
- |
LLstretchable(); |
123 |
|
- |
return this; |
124 |
|
- |
} |
125 |
|
- |
|
126 |
|
- |
public SizeableDeckPanel stretchableVertically() { |
127 |
|
- |
LLstretchableVertically(); |
128 |
|
- |
return this; |
129 |
|
- |
} |
130 |
|
- |
|
131 |
|
- |
public SizeableDeckPanel stretchableHorizontally() { |
132 |
|
- |
LLstretchableHorizontally(); |
133 |
|
- |
return this; |
134 |
|
- |
} |
135 |
|
- |
|
136 |
|
- |
@Override |
137 |
|
- |
public void setWidth( String width ) { |
138 |
|
- |
super.setWidth( width ); // for stacktrace Debugging |
139 |
|
- |
} |
140 |
|
- |
|
141 |
|
- |
@Override |
142 |
|
- |
public void setHeight( String height ) { |
143 |
|
- |
super.setHeight( height ); // for stacktrace Debugging |
144 |
|
- |
} |
145 |
|
- |
|
146 |
|
- |
private void showAwidget( int index ) { |
147 |
|
- |
mVisibleWidget = getWidget( index ); |
148 |
|
- |
mVisibleWidget.setVisible( true ); |
149 |
|
- |
|
150 |
|
- |
distributeToChildrenChangedWidth(); |
151 |
|
- |
distributeToChildrenChangedHeight(); |
152 |
|
- |
} |
153 |
|
- |
|
154 |
|
- |
@Override |
155 |
|
- |
protected void distributeToChildrenChangedWidth() { |
156 |
|
- |
if ( anyChildren() ) { |
157 |
|
- |
adjustSizeOnShownWidget( getWidthHelper() ); |
158 |
|
- |
} |
159 |
|
- |
} |
160 |
|
- |
|
161 |
|
- |
@Override |
162 |
|
- |
protected void distributeToChildrenChangedHeight() { |
163 |
|
- |
if ( anyChildren() ) { |
164 |
|
- |
adjustSizeOnShownWidget( getHeightHelper() ); |
165 |
|
- |
} |
166 |
|
- |
} |
167 |
|
- |
|
168 |
|
- |
private void adjustSizeOnShownWidget( ISizeableDimensionHelper pDimensionHelper ) { |
169 |
|
- |
getHelper().applyChangedDimensionToChild( mVisibleWidget, pDimensionHelper ); |
170 |
|
- |
} |
171 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
5 |
+ |
|
|
6 |
+ |
import com.google.gwt.user.client.ui.*; |
|
7 |
+ |
|
|
8 |
+ |
public class SizeableDeckPanel extends AbstractSizeableComplexPanel implements IndexedPanel { |
|
9 |
+ |
private Widget mVisibleWidget; |
|
10 |
+ |
|
|
11 |
+ |
public SizeableDeckPanel() { |
|
12 |
+ |
initializeElements( getHelper().create_OeTable_SeDiv_IeDiv( true ), "LayoutSizeableDeckPanel" ); |
|
13 |
+ |
} |
|
14 |
+ |
|
|
15 |
+ |
public SizeableDeckPanel style( String pStyleName ) { |
|
16 |
+ |
addStyleName( pStyleName ); |
|
17 |
+ |
return this; |
|
18 |
+ |
} |
|
19 |
+ |
|
|
20 |
+ |
/** |
|
21 |
+ |
* Adds the specified widget to the deck. |
|
22 |
+ |
* |
|
23 |
+ |
* @param w the widget to be added |
|
24 |
+ |
*/ |
|
25 |
+ |
@Override |
|
26 |
+ |
public void add( Widget w ) { |
|
27 |
+ |
insert( w, getWidgetCount() ); |
|
28 |
+ |
} |
|
29 |
+ |
|
|
30 |
+ |
/** |
|
31 |
+ |
* Gets the index of the currently-visible widget. |
|
32 |
+ |
* |
|
33 |
+ |
* @return the visible widget's index |
|
34 |
+ |
*/ |
|
35 |
+ |
public int getVisibleWidget() { |
|
36 |
+ |
return getWidgetIndex( mVisibleWidget ); |
|
37 |
+ |
} |
|
38 |
+ |
|
|
39 |
+ |
@Override |
|
40 |
+ |
public Widget getWidget( int index ) { |
|
41 |
+ |
return getChildren().get( index ); |
|
42 |
+ |
} |
|
43 |
+ |
|
|
44 |
+ |
@Override |
|
45 |
+ |
public int getWidgetCount() { |
|
46 |
+ |
return getChildren().size(); |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
@Override |
|
50 |
+ |
public int getWidgetIndex( Widget child ) { |
|
51 |
+ |
return getChildren().indexOf( child ); |
|
52 |
+ |
} |
|
53 |
+ |
|
|
54 |
+ |
/** |
|
55 |
+ |
* Inserts a widget before the specified index. |
|
56 |
+ |
* |
|
57 |
+ |
* @param w the widget to be inserted |
|
58 |
+ |
* @param beforeIndex the index before which it will be inserted |
|
59 |
+ |
* |
|
60 |
+ |
* @throws IndexOutOfBoundsException if <code>beforeIndex</code> is out of |
|
61 |
+ |
* range |
|
62 |
+ |
*/ |
|
63 |
+ |
public void insert( Widget w, int beforeIndex ) { |
|
64 |
+ |
if ( (beforeIndex < 0) || (beforeIndex > getWidgetCount()) ) { |
|
65 |
+ |
throw new IndexOutOfBoundsException( String.valueOf( beforeIndex ) ); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
super.insert( w, getContainerElement(), beforeIndex ); |
|
69 |
+ |
|
|
70 |
+ |
if ( mVisibleWidget == null ) { |
|
71 |
+ |
showAwidget( 0 ); |
|
72 |
+ |
} else { |
|
73 |
+ |
w.setVisible( false ); |
|
74 |
+ |
} |
|
75 |
+ |
} |
|
76 |
+ |
|
|
77 |
+ |
@Override |
|
78 |
+ |
public boolean remove( int index ) { |
|
79 |
+ |
return remove( getWidget( index ) ); |
|
80 |
+ |
} |
|
81 |
+ |
|
|
82 |
+ |
@Override |
|
83 |
+ |
public boolean remove( Widget w ) { |
|
84 |
+ |
if ( !super.remove( w ) ) { |
|
85 |
+ |
return false; |
|
86 |
+ |
} |
|
87 |
+ |
|
|
88 |
+ |
if ( mVisibleWidget == w ) { |
|
89 |
+ |
mVisibleWidget = null; |
|
90 |
+ |
if ( getWidgetCount() != 0 ) { |
|
91 |
+ |
showAwidget( 0 ); |
|
92 |
+ |
} |
|
93 |
+ |
} |
|
94 |
+ |
|
|
95 |
+ |
return true; |
|
96 |
+ |
} |
|
97 |
+ |
|
|
98 |
+ |
/** |
|
99 |
+ |
* Shows the widget at the specified index. This causes the currently- visible |
|
100 |
+ |
* widget to be hidden. |
|
101 |
+ |
* |
|
102 |
+ |
* @param index the index of the widget to be shown |
|
103 |
+ |
*/ |
|
104 |
+ |
public void showWidget( int index ) { |
|
105 |
+ |
checkIndex( index ); |
|
106 |
+ |
|
|
107 |
+ |
if ( mVisibleWidget != null ) { |
|
108 |
+ |
mVisibleWidget.setVisible( false ); |
|
109 |
+ |
} |
|
110 |
+ |
showAwidget( index ); |
|
111 |
+ |
} |
|
112 |
+ |
|
|
113 |
+ |
private void checkIndex( int index ) { |
|
114 |
+ |
if ( (index < 0) || (index >= getWidgetCount()) ) { |
|
115 |
+ |
throw new IndexOutOfBoundsException( String.valueOf( index ) ); |
|
116 |
+ |
} |
|
117 |
+ |
} |
|
118 |
+ |
|
|
119 |
+ |
//****** Implementation Code Block to support delegation to AbsoluteSizeHelper |
|
120 |
+ |
|
|
121 |
+ |
public SizeableDeckPanel stretchable() { |
|
122 |
+ |
LLstretchable(); |
|
123 |
+ |
return this; |
|
124 |
+ |
} |
|
125 |
+ |
|
|
126 |
+ |
public SizeableDeckPanel stretchableVertically() { |
|
127 |
+ |
LLstretchableVertically(); |
|
128 |
+ |
return this; |
|
129 |
+ |
} |
|
130 |
+ |
|
|
131 |
+ |
public SizeableDeckPanel stretchableHorizontally() { |
|
132 |
+ |
LLstretchableHorizontally(); |
|
133 |
+ |
return this; |
|
134 |
+ |
} |
|
135 |
+ |
|
|
136 |
+ |
@Override |
|
137 |
+ |
public void setWidth( String width ) { |
|
138 |
+ |
super.setWidth( width ); // for stacktrace Debugging |
|
139 |
+ |
} |
|
140 |
+ |
|
|
141 |
+ |
@Override |
|
142 |
+ |
public void setHeight( String height ) { |
|
143 |
+ |
super.setHeight( height ); // for stacktrace Debugging |
|
144 |
+ |
} |
|
145 |
+ |
|
|
146 |
+ |
private void showAwidget( int index ) { |
|
147 |
+ |
mVisibleWidget = getWidget( index ); |
|
148 |
+ |
mVisibleWidget.setVisible( true ); |
|
149 |
+ |
|
|
150 |
+ |
distributeToChildrenChangedWidth(); |
|
151 |
+ |
distributeToChildrenChangedHeight(); |
|
152 |
+ |
} |
|
153 |
+ |
|
|
154 |
+ |
@Override |
|
155 |
+ |
protected void distributeToChildrenChangedWidth() { |
|
156 |
+ |
if ( anyChildren() ) { |
|
157 |
+ |
adjustSizeOnShownWidget( getWidthHelper() ); |
|
158 |
+ |
} |
|
159 |
+ |
} |
|
160 |
+ |
|
|
161 |
+ |
@Override |
|
162 |
+ |
protected void distributeToChildrenChangedHeight() { |
|
163 |
+ |
if ( anyChildren() ) { |
|
164 |
+ |
adjustSizeOnShownWidget( getHeightHelper() ); |
|
165 |
+ |
} |
|
166 |
+ |
} |
|
167 |
+ |
|
|
168 |
+ |
private void adjustSizeOnShownWidget( ISizeableDimensionHelper pDimensionHelper ) { |
|
169 |
+ |
getHelper().applyChangedDimensionToChild( mVisibleWidget, pDimensionHelper ); |
|
170 |
+ |
} |
|
171 |
+ |
} |