Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -1,14 +1,13 @@
1 1 package org.litesoft.GWT.client.widgets.range;
2 2
3 - import java.util.*;
4 -
5 3 import com.google.gwt.event.dom.client.*;
6 4 import com.google.gwt.resources.client.*;
7 5 import com.google.gwt.user.client.*;
8 6 import com.google.gwt.user.client.ui.*;
9 7
10 - public class SliderEmulated extends FocusPanel implements Slider
11 - {
8 + import java.util.*;
9 +
10 + public class SliderEmulated extends FocusPanel implements Slider {
12 11 private int mMin, mStep, mMax;
13 12
14 13 /**
  @@ -73,8 +72,7 @@
73 72 /**
74 73 * Constructor
75 74 */
76 - public SliderEmulated( int pMin, int pStep, int pMax )
77 - {
75 + public SliderEmulated( int pMin, int pStep, int pMax ) {
78 76 mMin = pMin;
79 77 mStep = pStep;
80 78 mMax = pMax;
  @@ -96,33 +94,27 @@
96 94 }
97 95
98 96 @Override
99 - public Widget getWidget()
100 - {
97 + public Widget getWidget() {
101 98 return this;
102 99 }
103 100
104 - public int getMin()
105 - {
101 + public int getMin() {
106 102 return mMin;
107 103 }
108 104
109 - public int getStep()
110 - {
105 + public int getStep() {
111 106 return mStep;
112 107 }
113 108
114 - public int getMax()
115 - {
109 + public int getMax() {
116 110 return mMax;
117 111 }
118 112
119 - public void setKnobNormal( ImageResource knobNormal )
120 - {
113 + public void setKnobNormal( ImageResource knobNormal ) {
121 114 this.knobNormal = knobNormal;
122 115
123 116 // Create the knob
124 - if ( knobImage == null )
125 - {
117 + if ( knobImage == null ) {
126 118 knobImage = new Image( knobNormal );
127 119 Element knobElement = knobImage.getElement();
128 120 DOM.appendChild( getElement(), knobElement );
  @@ -134,13 +126,11 @@
134 126 }
135 127 }
136 128
137 - public void setKnobDisabled( ImageResource knobDisabled )
138 - {
129 + public void setKnobDisabled( ImageResource knobDisabled ) {
139 130 this.knobDisabled = knobDisabled;
140 131 }
141 132
142 - public void setKnobSliding( ImageResource knobSliding )
143 - {
133 + public void setKnobSliding( ImageResource knobSliding ) {
144 134 this.knobSliding = knobSliding;
145 135 }
146 136
  @@ -149,10 +139,8 @@
149 139 *
150 140 * @param listener the listener to add
151 141 */
152 - public void addChangeHandler( ChangeHandler listener )
153 - {
154 - if ( changeHandlers == null )
155 - {
142 + public void addChangeHandler( ChangeHandler listener ) {
143 + if ( changeHandlers == null ) {
156 144 changeHandlers = new ArrayList<ChangeHandler>();
157 145 }
158 146 changeHandlers.add( listener );
  @@ -163,8 +151,7 @@
163 151 *
164 152 * @return the current value
165 153 */
166 - public double getCurrentValue()
167 - {
154 + public double getCurrentValue() {
168 155 return curValue;
169 156 }
170 157
  @@ -173,8 +160,7 @@
173 160 *
174 161 * @return the max value
175 162 */
176 - public double getMaxValue()
177 - {
163 + public double getMaxValue() {
178 164 return maxValue;
179 165 }
180 166
  @@ -183,8 +169,7 @@
183 169 *
184 170 * @return the minimum value
185 171 */
186 - public double getMinValue()
187 - {
172 + public double getMinValue() {
188 173 return minValue;
189 174 }
190 175
  @@ -193,8 +178,7 @@
193 178 *
194 179 * @return the step size
195 180 */
196 - public double getStepSize()
197 - {
181 + public double getStepSize() {
198 182 return stepSize;
199 183 }
200 184
  @@ -203,14 +187,10 @@
203 187 *
204 188 * @return the total range
205 189 */
206 - public double getTotalRange()
207 - {
208 - if ( minValue > maxValue )
209 - {
190 + public double getTotalRange() {
191 + if ( minValue > maxValue ) {
210 192 return 0;
211 - }
212 - else
213 - {
193 + } else {
214 194 return maxValue - minValue;
215 195 }
216 196 }
  @@ -218,8 +198,7 @@
218 198 /**
219 199 * @return Gets whether this widget is enabled
220 200 */
221 - public boolean isEnabled()
222 - {
201 + public boolean isEnabled() {
223 202 return enabled;
224 203 }
225 204
  @@ -229,17 +208,13 @@
229 208 * @param event the event that occurred
230 209 */
231 210 @Override
232 - public void onBrowserEvent( Event event )
233 - {
211 + public void onBrowserEvent( Event event ) {
234 212 super.onBrowserEvent( event );
235 - if ( enabled )
236 - {
237 - switch ( DOM.eventGetType( event ) )
238 - {
213 + if ( enabled ) {
214 + switch ( DOM.eventGetType( event ) ) {
239 215 // Unhighlight and cancel keyboard events
240 216 case Event.ONBLUR:
241 - if ( slidingMouse )
242 - {
217 + if ( slidingMouse ) {
243 218 DOM.releaseCapture( getElement() );
244 219 slidingMouse = false;
245 220 slideKnob( event );
  @@ -257,12 +232,9 @@
257 232 case Event.ONMOUSEWHEEL:
258 233 int velocityY = DOM.eventGetMouseWheelVelocityY( event );
259 234 DOM.eventPreventDefault( event );
260 - if ( velocityY > 0 )
261 - {
235 + if ( velocityY > 0 ) {
262 236 shiftRight( 1 );
263 - }
264 - else
265 - {
237 + } else {
266 238 shiftLeft( 1 );
267 239 }
268 240 break;
  @@ -277,8 +249,7 @@
277 249 slideKnob( event );
278 250 break;
279 251 case Event.ONMOUSEUP:
280 - if ( slidingMouse )
281 - {
252 + if ( slidingMouse ) {
282 253 DOM.releaseCapture( getElement() );
283 254 slidingMouse = false;
284 255 slideKnob( event );
  @@ -286,8 +257,7 @@
286 257 }
287 258 break;
288 259 case Event.ONMOUSEMOVE:
289 - if ( slidingMouse )
290 - {
260 + if ( slidingMouse ) {
291 261 slideKnob( event );
292 262 }
293 263 break;
  @@ -303,8 +273,7 @@
303 273 * @param width the new client width of the element
304 274 * @param height the new client height of the element
305 275 */
306 - public void onResize( int width, int height )
307 - {
276 + public void onResize( int width, int height ) {
308 277 // Center the line in the shell
309 278 int lineWidth = DOM.getElementPropertyInt( lineElement, "offsetWidth" );
310 279 lineLeftOffset = (width / 2) - (lineWidth / 2);
  @@ -317,10 +286,8 @@
317 286 /**
318 287 * Redraw the progress bar when something changes the layout.
319 288 */
320 - public void redraw()
321 - {
322 - if ( isAttached() )
323 - {
289 + public void redraw() {
290 + if ( isAttached() ) {
324 291 int width = DOM.getElementPropertyInt( getElement(), "clientWidth" );
325 292 int height = DOM.getElementPropertyInt( getElement(), "clientHeight" );
326 293 onResize( width, height );
  @@ -332,10 +299,8 @@
332 299 *
333 300 * @param listener the listener to remove
334 301 */
335 - public void removeChangeHandler( ChangeHandler listener )
336 - {
337 - if ( changeHandlers != null )
338 - {
302 + public void removeChangeHandler( ChangeHandler listener ) {
303 + if ( changeHandlers != null ) {
339 304 changeHandlers.remove( listener );
340 305 }
341 306 }
  @@ -345,8 +310,7 @@
345 310 *
346 311 * @param curValue the current value
347 312 */
348 - public void setCurrentValue( double curValue )
349 - {
313 + public void setCurrentValue( double curValue ) {
350 314 setCurrentValue( curValue, true );
351 315 }
352 316
  @@ -356,16 +320,14 @@
356 320 * @param curValue the current value
357 321 * @param fireEvent fire the onValue change event if true
358 322 */
359 - public void setCurrentValue( double curValue, boolean fireEvent )
360 - {
323 + public void setCurrentValue( double curValue, boolean fireEvent ) {
361 324 // Confine the value to the range
362 325 this.curValue = Math.max( minValue, Math.min( maxValue, curValue ) );
363 326 double remainder = (this.curValue - minValue) % stepSize;
364 327 this.curValue -= remainder;
365 328
366 329 // Go to next step if more than halfway there
367 - if ( (remainder > (stepSize / 2)) && ((this.curValue + stepSize) <= maxValue) )
368 - {
330 + if ( (remainder > (stepSize / 2)) && ((this.curValue + stepSize) <= maxValue) ) {
369 331 this.curValue += stepSize;
370 332 }
371 333
  @@ -373,10 +335,8 @@
373 335 drawKnob();
374 336
375 337 // Fire the onValueChange event
376 - if ( fireEvent && (changeHandlers != null) )
377 - {
378 - for ( ChangeHandler changeHandler : changeHandlers )
379 - {
338 + if ( fireEvent && (changeHandlers != null) ) {
339 + for ( ChangeHandler changeHandler : changeHandlers ) {
380 340 changeHandler.onChange( null );
381 341 }
382 342 }
  @@ -387,15 +347,11 @@
387 347 *
388 348 * @param enabled true to enable the widget, false to disable it
389 349 */
390 - public void setEnabled( boolean enabled )
391 - {
350 + public void setEnabled( boolean enabled ) {
392 351 this.enabled = enabled;
393 - if ( enabled )
394 - {
352 + if ( enabled ) {
395 353 knobImage.setResource( knobNormal );
396 - }
397 - else
398 - {
354 + } else {
399 355 knobImage.setResource( knobDisabled );
400 356 }
401 357 redraw();
  @@ -406,8 +362,7 @@
406 362 *
407 363 * @param maxValue the current value
408 364 */
409 - public void setMaxValue( double maxValue )
410 - {
365 + public void setMaxValue( double maxValue ) {
411 366 this.maxValue = maxValue;
412 367 resetCurrentValue();
413 368 }
  @@ -417,8 +372,7 @@
417 372 *
418 373 * @param minValue the current value
419 374 */
420 - public void setMinValue( double minValue )
421 - {
375 + public void setMinValue( double minValue ) {
422 376 this.minValue = minValue;
423 377 resetCurrentValue();
424 378 }
  @@ -428,8 +382,7 @@
428 382 *
429 383 * @param stepSize the current value
430 384 */
431 - public void setStepSize( double stepSize )
432 - {
385 + public void setStepSize( double stepSize ) {
433 386 this.stepSize = stepSize;
434 387 resetCurrentValue();
435 388 }
  @@ -439,8 +392,7 @@
439 392 *
440 393 * @param numSteps the number of steps to shift
441 394 */
442 - public void shiftLeft( int numSteps )
443 - {
395 + public void shiftLeft( int numSteps ) {
444 396 setCurrentValue( getCurrentValue() - numSteps * stepSize );
445 397 }
446 398
  @@ -449,8 +401,7 @@
449 401 *
450 402 * @param numSteps the number of steps to shift
451 403 */
452 - public void shiftRight( int numSteps )
453 - {
404 + public void shiftRight( int numSteps ) {
454 405 setCurrentValue( getCurrentValue() + numSteps * stepSize );
455 406 }
456 407
  @@ -461,11 +412,9 @@
461 412 *
462 413 * @return the current percent complete
463 414 */
464 - protected double getKnobPercent()
465 - {
415 + protected double getKnobPercent() {
466 416 // If we have no range
467 - if ( maxValue <= minValue )
468 - {
417 + if ( maxValue <= minValue ) {
469 418 return 0;
470 419 }
471 420
  @@ -480,26 +429,22 @@
480 429 * browser's document.
481 430 */
482 431 @Override
483 - protected void onLoad()
484 - {
432 + protected void onLoad() {
485 433 // Reset the position attribute of the parent element
486 434 DOM.setStyleAttribute( getElement(), "position", "relative" );
487 435 redraw();
488 436 }
489 437
490 438 @Override
491 - protected void onUnload()
492 - {
439 + protected void onUnload() {
493 440 }
494 441
495 442 /**
496 443 * Draw the knob where it is supposed to be relative to the line.
497 444 */
498 - private void drawKnob()
499 - {
445 + private void drawKnob() {
500 446 // Abort if not attached
501 - if ( !isAttached() )
502 - {
447 + if ( !isAttached() ) {
503 448 return;
504 449 }
505 450
  @@ -515,8 +460,7 @@
515 460 /**
516 461 * Highlight this widget.
517 462 */
518 - private void highlight()
519 - {
463 + private void highlight() {
520 464 String styleName = getStylePrimaryName();
521 465 DOM.setElementProperty( getElement(), "className", styleName + " " + styleName + "-focused" );
522 466 }
  @@ -526,8 +470,7 @@
526 470 * and
527 471 * redraw the knob as needed.
528 472 */
529 - private void resetCurrentValue()
530 - {
473 + private void resetCurrentValue() {
531 474 setCurrentValue( getCurrentValue() );
532 475 }
533 476
  @@ -536,11 +479,9 @@
536 479 *
537 480 * @param event the mouse event
538 481 */
539 - private void slideKnob( Event event )
540 - {
482 + private void slideKnob( Event event ) {
541 483 int x = DOM.eventGetClientX( event );
542 - if ( x > 0 )
543 - {
484 + if ( x > 0 ) {
544 485 int lineWidth = DOM.getElementPropertyInt( lineElement, "offsetWidth" );
545 486 int lineLeft = DOM.getAbsoluteLeft( lineElement );
546 487 double percent = (double) (x - lineLeft) / lineWidth * 1.0;
  @@ -554,10 +495,8 @@
554 495 * @param highlight true to change the style
555 496 * @param fireEvent true to fire the event
556 497 */
557 - private void startSliding( boolean highlight, boolean fireEvent )
558 - {
559 - if ( highlight )
560 - {
498 + private void startSliding( boolean highlight, boolean fireEvent ) {
499 + if ( highlight ) {
561 500 DOM.setStyleAttribute( lineElement, "backgroundColor", "#DDDDDD" );
562 501 knobImage.setResource( knobSliding );
563 502 }
  @@ -569,10 +508,8 @@
569 508 * @param unhighlight true to change the style
570 509 * @param fireEvent true to fire the event
571 510 */
572 - private void stopSliding( boolean unhighlight, boolean fireEvent )
573 - {
574 - if ( unhighlight )
575 - {
511 + private void stopSliding( boolean unhighlight, boolean fireEvent ) {
512 + if ( unhighlight ) {
576 513 DOM.setStyleAttribute( lineElement, "backgroundColor", "white" );
577 514 knobImage.setResource( knobNormal );
578 515 }
  @@ -581,8 +518,7 @@
581 518 /**
582 519 * Unhighlight this widget.
583 520 */
584 - private void unhighlight()
585 - {
521 + private void unhighlight() {
586 522 DOM.setElementProperty( getElement(), "className", getStylePrimaryName() );
587 523 }
588 524 }