litesoft
@ 948
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
package org.litesoft.GWT.client.widgets.sliderbar.client.view; import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.*; import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.Presenter.*; import com.google.gwt.event.dom.client.*; import com.google.gwt.user.client.ui.*; import java.util.*; /** * @author kiouri */ public class SliderBarVertical extends SliderBar { protected int barWidth, barHeight, dragLeftPosition, scaleHeight; public SliderBarVertical( Presenter presenter ) { super( presenter ); } public SliderBarVertical() { super(); } public int getBarWidth() { barWidth = drag.getOffsetWidth(); for ( int i = 0; i < orderedWidgets.size(); i++ ) { if ( orderedWidgets.get( i ) == scale ) { barWidth = Math.max( barWidth, scaleSize ); } else { barWidth = Math.max( barWidth, orderedWidgets.get( i ).getOffsetWidth() ); } } barWidth = Math.max( barWidth, scaleSize ); return barWidth; } public void ajustScaleSize( int widgetHeight ) { scaleHeight = widgetHeight; if ( less != null ) { for ( int i = 0; i < less.size(); i++ ) { scaleHeight -= less.get( i ).getOffsetHeight(); } } if ( more != null ) { for ( int i = 0; i < more.size(); i++ ) { scaleHeight -= more.get( i ).getOffsetHeight(); } } scale.setPixelSize( scaleSize, scaleHeight ); } public int getAbsMaxLength() { return scaleHeight - drag.getOffsetHeight(); } public void drawScrollBar( int barHeight ) { absPanel.clear(); putWidgetsToAbsPanel(); initVariables( barHeight ); ajustScaleSize( barHeight ); this.setWidth( getBarWidth() + "px" ); absPanel.setPixelSize( getBarWidth(), barHeight ); placeWidgets( orderedWidgets ); absPanel.setWidgetPosition( drag, dragLeftPosition, getScaleTop( orderedWidgets ) ); } protected void initVariables( int barHeight ) { this.barHeight = barHeight; startPosition = getScaleTop( orderedWidgets ); dragLeftPosition = (getBarWidth() - drag.getOffsetWidth()) / 2; } protected int getScaleTop( ArrayList<Widget> widgets ) { int sPosition = 0; for ( int i = 0; i < widgets.size(); i++ ) { if ( widgets.get( i ) != scale ) { sPosition += widgets.get( i ).getOffsetHeight(); } else { return sPosition; } } return sPosition; } protected void placeWidgets( ArrayList<Widget> widgets ) { int tmpPosition = 0; int barWidth = getBarWidth(); for ( int i = 0; i < widgets.size(); i++ ) { if ( widgets.get( i ) == scale ) { absPanel.setWidgetPosition( widgets.get( i ), (barWidth - scaleSize) / 2, tmpPosition ); } else { absPanel.setWidgetPosition( widgets.get( i ), (barWidth - widgets.get( i ).getOffsetWidth()) / 2, tmpPosition ); } tmpPosition += widgets.get( i ).getOffsetHeight(); } } public void setDragPosition( int position ) { position = startPosition + position; absPanel.setWidgetPosition( drag, dragLeftPosition, position ); } public int getScaleTouchPosition( MouseEvent event ) { return event.getRelativeY( this.getElement() ) - startPosition - drag.getOffsetHeight() / 2; } public int getDragPosition() { return absPanel.getWidgetTop( drag ) - startPosition; } public void putMark( Mark mark, int markPosition ) { int markX = (this.barWidth - mark.getMarkWidth()) / 2; this.absPanel.add( mark, markX, startPosition + markPosition + drag.getOffsetHeight() / 2 ); } public Orientation getOrientation() { return Orientation.VERTICAL; } @Override public void setHeight( String height ) { super.setHeight( height ); if ( this.isAttached() ) { presenter.setBarPixelSize( this.getOffsetHeight() ); presenter.processParams(); reDrawMarks(); setValue( getValue() ); } } /** * It is not possible to adjust width of vertical sliderbar with help of this method. * Width of horizontal sliderbar is automatically calculated on base of height of components which are included in widget */ @Override public void setWidth( String width ) { super.setWidth( getBarWidth() + "px" ); } public void setScaleWidget( Widget scaleWidget, int scaleWidth ) { super.setScaleWidget( scaleWidget, scaleWidth ); } } |