Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -1,269 +1,269 @@
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 - import java.util.*;
9 -
10 - public class SizeableTabPanel extends AbstractSizeableComposite implements TabListener,
11 - SourcesTabEvents,
12 - HasWidgets,
13 - IndexedPanel,
14 - ISizeableTabPanel {
15 - private WidgetCollection mChildren = new WidgetCollection( this );
16 - private SizeableDeckPanel mDeck = new SizeableDeckPanel();
17 - private WidgetTabBar mTabBar = new WidgetTabBar();
18 - private TabListenerCollection mTabListeners;
19 - private static final String STYLE_TAB_NON_ERROR = "gwt-TabBarItem-NonError";
20 - private static final String STYLE_TAB_ERROR = "gwt-TabBarItem-Error";
21 - private boolean mErrorable;
22 -
23 - public SizeableTabPanel() {
24 - this( false );
25 - }
26 -
27 - public SizeableTabPanel( boolean pErrorable ) {
28 - mErrorable = pErrorable;
29 - SizeableVerticalPanel vp = new SizeableVerticalPanel();
30 -
31 - vp.add( mTabBar );
32 - vp.add( mDeck );
33 -
34 - initWidget( vp );
35 -
36 - style( "LayoutSizeableTabPanel" );
37 - style( "gwt-TabPanel" );
38 - mDeck.style( "gwt-TabPanelBottom" );
39 -
40 - mTabBar.addTabListener( this );
41 - }
42 -
43 - public SizeableTabPanel style( String pStyleName ) {
44 - addStyleName( pStyleName );
45 - return this;
46 - }
47 -
48 - @Override
49 - public void add( Widget w ) {
50 - throw new UnsupportedOperationException( "A tabText parameter must be specified with add()." );
51 - }
52 -
53 - /**
54 - * Inserts a widget into the tab panel.
55 - *
56 - * @param pBeforeIndex the index before which it will be inserted
57 - * @param pLabelText the text to be shown on its tab
58 - * @param pWidget the widget to be inserted
59 - */
60 - @Override
61 - public void insertTab( int pBeforeIndex, String pLabelText, Widget pWidget ) {
62 - insertTab( pBeforeIndex, pLabelText, false, pWidget );
63 - }
64 -
65 - /**
66 - * Inserts a widget into the tab panel.
67 - *
68 - * @param pBeforeIndex the index before which it will be inserted
69 - * @param pLabelText the text to be shown on its tab
70 - * @param pAsHTML <code>true</code> to treat the specified text as HTML
71 - * @param pWidget the widget to be inserted
72 - */
73 - @Override
74 - public void insertTab( int pBeforeIndex, String pLabelText, boolean pAsHTML, Widget pWidget ) {
75 - pWidget.removeFromParent();
76 - pBeforeIndex = Helper.normalizeBeforeIndex( pBeforeIndex, this );
77 - mChildren.insert( pWidget, pBeforeIndex );
78 - mTabBar.insertTab( Helper.augment( pLabelText, mErrorable ), true, pBeforeIndex );
79 - mDeck.insert( pWidget, pBeforeIndex );
80 - forceTabSelection( -1, mTabBar.getSelectedTab() );
81 - }
82 -
83 - @Override
84 - public void removeTab( int pIndex ) {
85 - if ( Helper.indexOK( pIndex, this ) ) {
86 - remove( pIndex );
87 - }
88 - }
89 -
90 - /**
91 - * Adds a widget to the tab panel.
92 - *
93 - * @param pLabelText
94 - * @param pWidget
95 - */
96 - @Override
97 - public void addTab( String pLabelText, Widget pWidget ) {
98 - insertTab( getWidgetCount(), pLabelText, pWidget );
99 - }
100 -
101 - /**
102 - * Adds a widget to the tab panel.
103 - *
104 - * @param pLabelText the text to be shown on its tab
105 - * @param pAsHTML <code>true</code> to treat the specified text as HTML
106 - * @param pWidget the widget to be added
107 - */
108 - @Override
109 - public void addTab( String pLabelText, boolean pAsHTML, Widget pWidget ) {
110 - insertTab( getWidgetCount(), pLabelText, pAsHTML, pWidget );
111 - }
112 -
113 - @Override
114 - public int getTabCount() {
115 - return getWidgetCount();
116 - }
117 -
118 - @Override
119 - public int getSelectedTab() {
120 - return mTabBar.getSelectedTab();
121 - }
122 -
123 - /**
124 - * Programmatically selects the specified tab.
125 - *
126 - * @param pIndex the index of the tab to be selected
127 - */
128 - @Override
129 - public void selectTab( int pIndex ) {
130 - if ( Helper.indexOK( pIndex, this ) ) {
131 - mTabBar.selectTab( pIndex );
132 - }
133 - }
134 -
135 - @Override
136 - public void addTabListener( TabListener listener ) {
137 - if ( mTabListeners == null ) {
138 - mTabListeners = new TabListenerCollection();
139 - }
140 - //noinspection unchecked
141 - mTabListeners.add( listener );
142 - }
143 -
144 - @Override
145 - public void clear() {
146 - while ( getWidgetCount() > 0 ) {
147 - remove( getWidget( 0 ) );
148 - }
149 - }
150 -
151 - @Override
152 - public Iterator<Widget> iterator() {
153 - return mChildren.iterator();
154 - }
155 -
156 - @Override
157 - public boolean onBeforeTabSelected( SourcesTabEvents sender, int tabIndex ) {
158 - return (mTabListeners == null) || mTabListeners.fireBeforeTabSelected( this, tabIndex );
159 - }
160 -
161 - @Override
162 - public void onTabSelected( SourcesTabEvents sender, int tabIndex ) {
163 - mDeck.showWidget( tabIndex );
164 - if ( mTabListeners != null ) {
165 - mTabListeners.fireTabSelected( this, tabIndex );
166 - }
167 - }
168 -
169 - @Override
170 - public Widget getWidget( int index ) {
171 - return mChildren.get( index );
172 - }
173 -
174 - @Override
175 - public int getWidgetCount() {
176 - return mChildren.size();
177 - }
178 -
179 - @Override
180 - public int getWidgetIndex( Widget widget ) {
181 - return mChildren.indexOf( widget );
182 - }
183 -
184 - @Override
185 - public boolean remove( int pIndex ) {
186 - if ( Helper.indexOK( pIndex, this ) ) {
187 - int prevSelectedTab = mTabBar.getSelectedTab();
188 - mChildren.remove( pIndex );
189 - mTabBar.removeTab( pIndex );
190 - mDeck.remove( pIndex );
191 - forceTabSelection( pIndex, prevSelectedTab );
192 - return true;
193 - }
194 - return false;
195 - }
196 -
197 - /**
198 - * Removes the given widget, and its associated tab.
199 - *
200 - * @param widget the widget to be removed
201 - */
202 - @Override
203 - public boolean remove( Widget widget ) {
204 - return remove( getWidgetIndex( widget ) );
205 - }
206 -
207 - @Override
208 - public void removeTabListener( TabListener listener ) {
209 - if ( mTabListeners != null ) {
210 - mTabListeners.remove( listener );
211 - }
212 - }
213 -
214 - private void forceTabSelection( int pRemovedIndex, int pPrevSelectedTab ) {
215 - int count = mTabBar.getTabCount();
216 - if ( (count > 0) && (pRemovedIndex == pPrevSelectedTab) ) {
217 - int toSelect = (pPrevSelectedTab < 0) ? //
218 - 0 : //
219 - (pPrevSelectedTab < count) ? //
220 - pPrevSelectedTab : //
221 - count - 1;
222 - selectTab( toSelect );
223 - }
224 - }
225 -
226 - //****** Implementation Code Block to support delegation to AbsoluteSizeHelper
227 -
228 - public SizeableTabPanel stretchable() {
229 - LLstretchable();
230 - mDeck.stretchable();
231 - return this;
232 - }
233 -
234 - public SizeableTabPanel stretchableVertically() {
235 - LLstretchableVertically();
236 - mDeck.stretchableVertically();
237 - return this;
238 - }
239 -
240 - public SizeableTabPanel stretchableHorizontally() {
241 - LLstretchableHorizontally();
242 - mDeck.stretchableHorizontally();
243 - return this;
244 - }
245 -
246 - @Override
247 - public void setWidth( String width ) {
248 - super.setWidth( width ); // for stacktrace Debugging
249 - }
250 -
251 - @Override
252 - public void setHeight( String height ) {
253 - super.setHeight( height ); // for stacktrace Debugging
254 - }
255 -
256 - @Override
257 - public void setError( int pIndex, boolean pError ) {
258 - if ( Helper.indexOK( pIndex, this ) ) {
259 - Widget widget = mTabBar.getWidget( pIndex );
260 - if ( pError ) {
261 - widget.removeStyleName( STYLE_TAB_NON_ERROR );
262 - widget.addStyleName( STYLE_TAB_ERROR );
263 - } else {
264 - widget.removeStyleName( STYLE_TAB_ERROR );
265 - widget.addStyleName( STYLE_TAB_NON_ERROR );
266 - }
267 - }
268 - }
269 - }
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 + import java.util.*;
9 +
10 + public class SizeableTabPanel extends AbstractSizeableComposite implements TabListener,
11 + SourcesTabEvents,
12 + HasWidgets,
13 + IndexedPanel,
14 + ISizeableTabPanel {
15 + private WidgetCollection mChildren = new WidgetCollection( this );
16 + private SizeableDeckPanel mDeck = new SizeableDeckPanel();
17 + private WidgetTabBar mTabBar = new WidgetTabBar();
18 + private TabListenerCollection mTabListeners;
19 + private static final String STYLE_TAB_NON_ERROR = "gwt-TabBarItem-NonError";
20 + private static final String STYLE_TAB_ERROR = "gwt-TabBarItem-Error";
21 + private boolean mErrorable;
22 +
23 + public SizeableTabPanel() {
24 + this( false );
25 + }
26 +
27 + public SizeableTabPanel( boolean pErrorable ) {
28 + mErrorable = pErrorable;
29 + SizeableVerticalPanel vp = new SizeableVerticalPanel();
30 +
31 + vp.add( mTabBar );
32 + vp.add( mDeck );
33 +
34 + initWidget( vp );
35 +
36 + style( "LayoutSizeableTabPanel" );
37 + style( "gwt-TabPanel" );
38 + mDeck.style( "gwt-TabPanelBottom" );
39 +
40 + mTabBar.addTabListener( this );
41 + }
42 +
43 + public SizeableTabPanel style( String pStyleName ) {
44 + addStyleName( pStyleName );
45 + return this;
46 + }
47 +
48 + @Override
49 + public void add( Widget w ) {
50 + throw new UnsupportedOperationException( "A tabText parameter must be specified with add()." );
51 + }
52 +
53 + /**
54 + * Inserts a widget into the tab panel.
55 + *
56 + * @param pBeforeIndex the index before which it will be inserted
57 + * @param pLabelText the text to be shown on its tab
58 + * @param pWidget the widget to be inserted
59 + */
60 + @Override
61 + public void insertTab( int pBeforeIndex, String pLabelText, Widget pWidget ) {
62 + insertTab( pBeforeIndex, pLabelText, false, pWidget );
63 + }
64 +
65 + /**
66 + * Inserts a widget into the tab panel.
67 + *
68 + * @param pBeforeIndex the index before which it will be inserted
69 + * @param pLabelText the text to be shown on its tab
70 + * @param pAsHTML <code>true</code> to treat the specified text as HTML
71 + * @param pWidget the widget to be inserted
72 + */
73 + @Override
74 + public void insertTab( int pBeforeIndex, String pLabelText, boolean pAsHTML, Widget pWidget ) {
75 + pWidget.removeFromParent();
76 + pBeforeIndex = Helper.normalizeBeforeIndex( pBeforeIndex, this );
77 + mChildren.insert( pWidget, pBeforeIndex );
78 + mTabBar.insertTab( Helper.augment( pLabelText, mErrorable ), true, pBeforeIndex );
79 + mDeck.insert( pWidget, pBeforeIndex );
80 + forceTabSelection( -1, mTabBar.getSelectedTab() );
81 + }
82 +
83 + @Override
84 + public void removeTab( int pIndex ) {
85 + if ( Helper.indexOK( pIndex, this ) ) {
86 + remove( pIndex );
87 + }
88 + }
89 +
90 + /**
91 + * Adds a widget to the tab panel.
92 + *
93 + * @param pLabelText
94 + * @param pWidget
95 + */
96 + @Override
97 + public void addTab( String pLabelText, Widget pWidget ) {
98 + insertTab( getWidgetCount(), pLabelText, pWidget );
99 + }
100 +
101 + /**
102 + * Adds a widget to the tab panel.
103 + *
104 + * @param pLabelText the text to be shown on its tab
105 + * @param pAsHTML <code>true</code> to treat the specified text as HTML
106 + * @param pWidget the widget to be added
107 + */
108 + @Override
109 + public void addTab( String pLabelText, boolean pAsHTML, Widget pWidget ) {
110 + insertTab( getWidgetCount(), pLabelText, pAsHTML, pWidget );
111 + }
112 +
113 + @Override
114 + public int getTabCount() {
115 + return getWidgetCount();
116 + }
117 +
118 + @Override
119 + public int getSelectedTab() {
120 + return mTabBar.getSelectedTab();
121 + }
122 +
123 + /**
124 + * Programmatically selects the specified tab.
125 + *
126 + * @param pIndex the index of the tab to be selected
127 + */
128 + @Override
129 + public void selectTab( int pIndex ) {
130 + if ( Helper.indexOK( pIndex, this ) ) {
131 + mTabBar.selectTab( pIndex );
132 + }
133 + }
134 +
135 + @Override
136 + public void addTabListener( TabListener listener ) {
137 + if ( mTabListeners == null ) {
138 + mTabListeners = new TabListenerCollection();
139 + }
140 + //noinspection unchecked
141 + mTabListeners.add( listener );
142 + }
143 +
144 + @Override
145 + public void clear() {
146 + while ( getWidgetCount() > 0 ) {
147 + remove( getWidget( 0 ) );
148 + }
149 + }
150 +
151 + @Override
152 + public Iterator<Widget> iterator() {
153 + return mChildren.iterator();
154 + }
155 +
156 + @Override
157 + public boolean onBeforeTabSelected( SourcesTabEvents sender, int tabIndex ) {
158 + return (mTabListeners == null) || mTabListeners.fireBeforeTabSelected( this, tabIndex );
159 + }
160 +
161 + @Override
162 + public void onTabSelected( SourcesTabEvents sender, int tabIndex ) {
163 + mDeck.showWidget( tabIndex );
164 + if ( mTabListeners != null ) {
165 + mTabListeners.fireTabSelected( this, tabIndex );
166 + }
167 + }
168 +
169 + @Override
170 + public Widget getWidget( int index ) {
171 + return mChildren.get( index );
172 + }
173 +
174 + @Override
175 + public int getWidgetCount() {
176 + return mChildren.size();
177 + }
178 +
179 + @Override
180 + public int getWidgetIndex( Widget widget ) {
181 + return mChildren.indexOf( widget );
182 + }
183 +
184 + @Override
185 + public boolean remove( int pIndex ) {
186 + if ( Helper.indexOK( pIndex, this ) ) {
187 + int prevSelectedTab = mTabBar.getSelectedTab();
188 + mChildren.remove( pIndex );
189 + mTabBar.removeTab( pIndex );
190 + mDeck.remove( pIndex );
191 + forceTabSelection( pIndex, prevSelectedTab );
192 + return true;
193 + }
194 + return false;
195 + }
196 +
197 + /**
198 + * Removes the given widget, and its associated tab.
199 + *
200 + * @param widget the widget to be removed
201 + */
202 + @Override
203 + public boolean remove( Widget widget ) {
204 + return remove( getWidgetIndex( widget ) );
205 + }
206 +
207 + @Override
208 + public void removeTabListener( TabListener listener ) {
209 + if ( mTabListeners != null ) {
210 + mTabListeners.remove( listener );
211 + }
212 + }
213 +
214 + private void forceTabSelection( int pRemovedIndex, int pPrevSelectedTab ) {
215 + int count = mTabBar.getTabCount();
216 + if ( (count > 0) && (pRemovedIndex == pPrevSelectedTab) ) {
217 + int toSelect = (pPrevSelectedTab < 0) ? //
218 + 0 : //
219 + (pPrevSelectedTab < count) ? //
220 + pPrevSelectedTab : //
221 + count - 1;
222 + selectTab( toSelect );
223 + }
224 + }
225 +
226 + //****** Implementation Code Block to support delegation to AbsoluteSizeHelper
227 +
228 + public SizeableTabPanel stretchable() {
229 + LLstretchable();
230 + mDeck.stretchable();
231 + return this;
232 + }
233 +
234 + public SizeableTabPanel stretchableVertically() {
235 + LLstretchableVertically();
236 + mDeck.stretchableVertically();
237 + return this;
238 + }
239 +
240 + public SizeableTabPanel stretchableHorizontally() {
241 + LLstretchableHorizontally();
242 + mDeck.stretchableHorizontally();
243 + return this;
244 + }
245 +
246 + @Override
247 + public void setWidth( String width ) {
248 + super.setWidth( width ); // for stacktrace Debugging
249 + }
250 +
251 + @Override
252 + public void setHeight( String height ) {
253 + super.setHeight( height ); // for stacktrace Debugging
254 + }
255 +
256 + @Override
257 + public void setError( int pIndex, boolean pError ) {
258 + if ( Helper.indexOK( pIndex, this ) ) {
259 + Widget widget = mTabBar.getWidget( pIndex );
260 + if ( pError ) {
261 + widget.removeStyleName( STYLE_TAB_NON_ERROR );
262 + widget.addStyleName( STYLE_TAB_ERROR );
263 + } else {
264 + widget.removeStyleName( STYLE_TAB_ERROR );
265 + widget.addStyleName( STYLE_TAB_NON_ERROR );
266 + }
267 + }
268 + }
269 + }