Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/WidgetTabBar.java

Diff revisions: vs.
  @@ -28,8 +28,7 @@
28 28 * </p>
29 29 */
30 30 public class WidgetTabBar extends Composite implements SourcesTabEvents,
31 - ClickListener
32 - {
31 + ClickListener {
33 32
34 33 private HorizontalPanel panel = new HorizontalPanel();
35 34 private Widget selectedTab;
  @@ -38,8 +37,7 @@
38 37 /**
39 38 * Creates an empty tab bar.
40 39 */
41 - public WidgetTabBar()
42 - {
40 + public WidgetTabBar() {
43 41 initWidget( panel );
44 42 sinkEvents( Event.ONCLICK );
45 43 //noinspection GWTStyleCheck
  @@ -67,8 +65,7 @@
67 65 *
68 66 * @param text the new tab's text
69 67 */
70 - public void addTab( String text )
71 - {
68 + public void addTab( String text ) {
72 69 insertTab( text, getTabCount() );
73 70 }
74 71
  @@ -78,16 +75,13 @@
78 75 * @param text the new tab's text
79 76 * @param asHTML <code>true</code> to treat the specified text as html
80 77 */
81 - public void addTab( String text, boolean asHTML )
82 - {
78 + public void addTab( String text, boolean asHTML ) {
83 79 insertTab( text, asHTML, getTabCount() );
84 80 }
85 81
86 82 @Override
87 - public void addTabListener( TabListener listener )
88 - {
89 - if ( tabListeners == null )
90 - {
83 + public void addTabListener( TabListener listener ) {
84 + if ( tabListeners == null ) {
91 85 tabListeners = new TabListenerCollection();
92 86 }
93 87 tabListeners.add( listener );
  @@ -98,10 +92,8 @@
98 92 *
99 93 * @return the selected tab
100 94 */
101 - public int getSelectedTab()
102 - {
103 - if ( selectedTab == null )
104 - {
95 + public int getSelectedTab() {
96 + if ( selectedTab == null ) {
105 97 return -1;
106 98 }
107 99 return panel.getWidgetIndex( selectedTab ) - 1;
  @@ -112,8 +104,7 @@
112 104 *
113 105 * @return the tab count
114 106 */
115 - public int getTabCount()
116 - {
107 + public int getTabCount() {
117 108 return panel.getWidgetCount() - 2;
118 109 }
119 110
  @@ -124,25 +115,19 @@
124 115 *
125 116 * @return the tab's HTML
126 117 */
127 - public String getTabHTML( int index )
128 - {
129 - if ( index >= getTabCount() )
130 - {
118 + public String getTabHTML( int index ) {
119 + if ( index >= getTabCount() ) {
131 120 return null;
132 121 }
133 122 Widget widget = panel.getWidget( index + 1 );
134 - if ( widget instanceof HTML )
135 - {
123 + if ( widget instanceof HTML ) {
136 124 return ((HTML) widget).getHTML();
137 - }
138 - else
139 - {
125 + } else {
140 126 return ((Label) widget).getText();
141 127 }
142 128 }
143 129
144 - public Widget getWidget( int pIndex )
145 - {
130 + public Widget getWidget( int pIndex ) {
146 131 return panel.getWidget( pIndex + 1 );
147 132 }
148 133
  @@ -153,20 +138,15 @@
153 138 * @param asHTML <code>true</code> to treat the specified text as HTML
154 139 * @param beforeIndex the index before which this tab will be inserted
155 140 */
156 - public void insertTab( String text, boolean asHTML, int beforeIndex )
157 - {
158 - if ( (beforeIndex < 0) || (beforeIndex > getTabCount()) )
159 - {
141 + public void insertTab( String text, boolean asHTML, int beforeIndex ) {
142 + if ( (beforeIndex < 0) || (beforeIndex > getTabCount()) ) {
160 143 throw new IndexOutOfBoundsException( String.valueOf( beforeIndex ) );
161 144 }
162 145
163 146 Label item;
164 - if ( asHTML )
165 - {
147 + if ( asHTML ) {
166 148 item = new HTML( text );
167 - }
168 - else
169 - {
149 + } else {
170 150 item = new Label( text );
171 151 }
172 152
  @@ -184,18 +164,14 @@
184 164 * @param text the new tab's text
185 165 * @param beforeIndex the index before which this tab will be inserted
186 166 */
187 - public void insertTab( String text, int beforeIndex )
188 - {
167 + public void insertTab( String text, int beforeIndex ) {
189 168 insertTab( text, false, beforeIndex );
190 169 }
191 170
192 171 @Override
193 - public void onClick( Widget sender )
194 - {
195 - for ( int i = 1; i < panel.getWidgetCount() - 1; ++i )
196 - {
197 - if ( panel.getWidget( i ) == sender )
198 - {
172 + public void onClick( Widget sender ) {
173 + for ( int i = 1; i < panel.getWidgetCount() - 1; ++i ) {
174 + if ( panel.getWidget( i ) == sender ) {
199 175 selectTab( i - 1 );
200 176 return;
201 177 }
  @@ -207,24 +183,20 @@
207 183 *
208 184 * @param index the index of the tab to be removed
209 185 */
210 - public void removeTab( int index )
211 - {
186 + public void removeTab( int index ) {
212 187 checkTabIndex( index );
213 188
214 189 // (index + 1) to account for 'first' placeholder widget.
215 190 Widget toRemove = panel.getWidget( index + 1 );
216 - if ( toRemove == selectedTab )
217 - {
191 + if ( toRemove == selectedTab ) {
218 192 selectedTab = null;
219 193 }
220 194 panel.remove( toRemove );
221 195 }
222 196
223 197 @Override
224 - public void removeTabListener( TabListener listener )
225 - {
226 - if ( tabListeners != null )
227 - {
198 + public void removeTabListener( TabListener listener ) {
199 + if ( tabListeners != null ) {
228 200 tabListeners.remove( listener );
229 201 }
230 202 }
  @@ -236,24 +208,20 @@
236 208 * @param index the index of the tab to be selected.
237 209 *
238 210 * @return <code>true</code> if successful, <code>false</code> if the
239 - * change is denied by the {@link TabListener}.
211 + * change is denied by the {@link TabListener}.
240 212 */
241 - public boolean selectTab( int index )
242 - {
213 + public boolean selectTab( int index ) {
243 214 checkTabIndex( index );
244 215
245 - if ( tabListeners != null )
246 - {
247 - if ( !tabListeners.fireBeforeTabSelected( this, index ) )
248 - {
216 + if ( tabListeners != null ) {
217 + if ( !tabListeners.fireBeforeTabSelected( this, index ) ) {
249 218 return false;
250 219 }
251 220 }
252 221
253 222 // Check for -1.
254 223 setSelectionStyle( selectedTab, false );
255 - if ( index == -1 )
256 - {
224 + if ( index == -1 ) {
257 225 selectedTab = null;
258 226 return true;
259 227 }
  @@ -261,32 +229,24 @@
261 229 selectedTab = panel.getWidget( index + 1 );
262 230 setSelectionStyle( selectedTab, true );
263 231
264 - if ( tabListeners != null )
265 - {
232 + if ( tabListeners != null ) {
266 233 tabListeners.fireTabSelected( this, index );
267 234 }
268 235 return true;
269 236 }
270 237
271 - private void checkTabIndex( int index )
272 - {
273 - if ( (index < -1) || (index >= getTabCount()) )
274 - {
238 + private void checkTabIndex( int index ) {
239 + if ( (index < -1) || (index >= getTabCount()) ) {
275 240 throw new IndexOutOfBoundsException( String.valueOf( index ) );
276 241 }
277 242 }
278 243
279 - private void setSelectionStyle( Widget item, boolean selected )
280 - {
281 - if ( item != null )
282 - {
283 - if ( selected )
284 - {
244 + private void setSelectionStyle( Widget item, boolean selected ) {
245 + if ( item != null ) {
246 + if ( selected ) {
285 247 //noinspection GWTStyleCheck
286 248 item.addStyleName( "gwt-TabBarItem-selected" );
287 - }
288 - else
289 - {
249 + } else {
290 250 //noinspection GWTStyleCheck
291 251 item.removeStyleName( "gwt-TabBarItem-selected" );
292 252 }