litesoft
@ HEAD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
package org.litesoft.GWT.client.widgets.sliderbar.client.presenter; public class SliderBarCalculator { protected int maxValue; protected int absMaxLength; protected int minPosition, maxPosition; private int step; private double k; public int getMaxValue() { return maxValue; } public void setMaxValue( int maxValue ) { this.maxValue = maxValue; } public void setAbsMaxLength( int absMaxLength ) { this.absMaxLength = absMaxLength; } protected void processParams() { int usedAbsLength = absMaxLength; minPosition = 0; maxPosition = absMaxLength; if ( absMaxLength >= maxValue ) { usedAbsLength = absMaxLength - absMaxLength % maxValue; minPosition = (absMaxLength - usedAbsLength) / 2; maxPosition = minPosition + usedAbsLength; } step = usedAbsLength / maxValue; if ( step == 0 ) { step = 1; } k = (double) usedAbsLength / maxValue; } public int checkAbsPosition( int absPosition ) { if ( absPosition < minPosition ) { absPosition = minPosition; } if ( absPosition > maxPosition ) { absPosition = maxPosition; } return absPosition; } protected int clcValueByAbsPosition( int currentAbsPosition ) { currentAbsPosition = checkAbsPosition( currentAbsPosition ) - minPosition; int value = (int) Math.round( (currentAbsPosition / k) ); return value; } protected int clcAbsPositionByValue( int value ) { int absPosition; if ( k >= 1 ) { absPosition = value * step; } else { absPosition = (int) Math.round( value * k ); } return absPosition + minPosition; } } |