|
@@ -1,139 +1,139 @@ |
1 |
|
- |
package org.litesoft.GWT.client.widgets.sliderbar.client.view; |
2 |
|
- |
|
3 |
|
- |
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.Presenter.*; |
4 |
|
- |
|
5 |
|
- |
import com.google.gwt.event.dom.client.*; |
6 |
|
- |
import com.google.gwt.user.client.ui.*; |
7 |
|
- |
|
8 |
|
- |
import java.util.*; |
9 |
|
- |
|
10 |
|
- |
/** |
11 |
|
- |
* @author kiouri |
12 |
|
- |
*/ |
13 |
|
- |
public class SliderBarHorizontal extends SliderBar { |
14 |
|
- |
|
15 |
|
- |
protected int barWidth, barHeight, dragTopPosition, scaleWidth; |
16 |
|
- |
|
17 |
|
- |
protected int getBarHeight() { |
18 |
|
- |
barHeight = drag.getOffsetHeight(); |
19 |
|
- |
for ( int i = 0; i < orderedWidgets.size(); i++ ) { |
20 |
|
- |
if ( orderedWidgets.get( i ) == scale ) { |
21 |
|
- |
barHeight = Math.max( barHeight, scaleSize ); |
22 |
|
- |
} else { |
23 |
|
- |
barHeight = Math.max( barHeight, orderedWidgets.get( i ).getOffsetHeight() ); |
24 |
|
- |
} |
25 |
|
- |
} |
26 |
|
- |
barHeight = Math.max( barHeight, scaleSize ); |
27 |
|
- |
return barHeight; |
28 |
|
- |
} |
29 |
|
- |
|
30 |
|
- |
protected void ajustScaleSize( int widgetWidth ) { |
31 |
|
- |
scaleWidth = widgetWidth; |
32 |
|
- |
if ( less != null ) { |
33 |
|
- |
for ( int i = 0; i < less.size(); i++ ) { |
34 |
|
- |
scaleWidth -= less.get( i ).getOffsetWidth(); |
35 |
|
- |
} |
36 |
|
- |
} |
37 |
|
- |
if ( more != null ) { |
38 |
|
- |
for ( int i = 0; i < more.size(); i++ ) { |
39 |
|
- |
scaleWidth -= more.get( i ).getOffsetWidth(); |
40 |
|
- |
} |
41 |
|
- |
} |
42 |
|
- |
scale.setPixelSize( scaleWidth, scaleSize ); |
43 |
|
- |
} |
44 |
|
- |
|
45 |
|
- |
public int getAbsMaxLength() { |
46 |
|
- |
return scaleWidth - drag.getOffsetWidth(); |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
public void drawScrollBar( int barWidth ) { |
50 |
|
- |
absPanel.clear(); |
51 |
|
- |
putWidgetsToAbsPanel(); |
52 |
|
- |
initVariables( barWidth ); |
53 |
|
- |
ajustScaleSize( barWidth ); |
54 |
|
- |
this.setHeight( getBarHeight() + "px" ); |
55 |
|
- |
absPanel.setPixelSize( barWidth, getBarHeight() ); |
56 |
|
- |
placeWidgets( orderedWidgets ); |
57 |
|
- |
absPanel.setWidgetPosition( drag, getScaleLeft( orderedWidgets ), dragTopPosition ); |
58 |
|
- |
} |
59 |
|
- |
|
60 |
|
- |
protected void initVariables( int barWidth ) { |
61 |
|
- |
this.barWidth = barWidth; |
62 |
|
- |
startPosition = getScaleLeft( orderedWidgets ); |
63 |
|
- |
dragTopPosition = (getBarHeight() - drag.getOffsetHeight()) / 2; |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
protected int getScaleLeft( ArrayList<Widget> widgets ) { |
67 |
|
- |
int sPosition = 0; |
68 |
|
- |
for ( int i = 0; i < widgets.size(); i++ ) { |
69 |
|
- |
if ( widgets.get( i ) != scale ) { |
70 |
|
- |
sPosition += widgets.get( i ).getOffsetWidth(); |
71 |
|
- |
} else { |
72 |
|
- |
return sPosition; |
73 |
|
- |
} |
74 |
|
- |
} |
75 |
|
- |
return sPosition; |
76 |
|
- |
} |
77 |
|
- |
|
78 |
|
- |
protected void placeWidgets( ArrayList<Widget> widgets ) { |
79 |
|
- |
int tmpPosition = 0; |
80 |
|
- |
int barHeight = getBarHeight(); |
81 |
|
- |
for ( int i = 0; i < widgets.size(); i++ ) { |
82 |
|
- |
if ( widgets.get( i ) == scale ) { |
83 |
|
- |
absPanel.setWidgetPosition( widgets.get( i ), tmpPosition, (barHeight - scaleSize) / 2 ); |
84 |
|
- |
} else { |
85 |
|
- |
absPanel.setWidgetPosition( widgets.get( i ), tmpPosition, (barHeight - widgets.get( i ).getOffsetHeight()) / 2 ); |
86 |
|
- |
} |
87 |
|
- |
tmpPosition += widgets.get( i ).getOffsetWidth(); |
88 |
|
- |
} |
89 |
|
- |
} |
90 |
|
- |
|
91 |
|
- |
public void setDragPosition( int position ) { |
92 |
|
- |
position = startPosition + position; |
93 |
|
- |
absPanel.setWidgetPosition( drag, position, dragTopPosition ); |
94 |
|
- |
} |
95 |
|
- |
|
96 |
|
- |
public int getScaleTouchPosition( MouseEvent event ) { |
97 |
|
- |
return event.getRelativeX( this.getElement() ) - startPosition - drag.getOffsetWidth() / 2; |
98 |
|
- |
} |
99 |
|
- |
|
100 |
|
- |
public int getDragPosition() { |
101 |
|
- |
return absPanel.getWidgetLeft( drag ) - startPosition; |
102 |
|
- |
} |
103 |
|
- |
|
104 |
|
- |
/** |
105 |
|
- |
* Sets scale mark to scale |
106 |
|
- |
*/ |
107 |
|
- |
public void putMark( Mark mark, int markPosition ) { |
108 |
|
- |
int markY = (this.barHeight - mark.getMarkHeight()) / 2; |
109 |
|
- |
this.absPanel.add( mark, this.startPosition + markPosition + drag.getOffsetWidth() / 2, markY ); |
110 |
|
- |
} |
111 |
|
- |
|
112 |
|
- |
public Orientation getOrientation() { |
113 |
|
- |
return Orientation.HORIZONTAL; |
114 |
|
- |
} |
115 |
|
- |
|
116 |
|
- |
@Override |
117 |
|
- |
/** |
118 |
|
- |
* It is not possible to adjust height of horizontal sliderbar with help of this method. |
119 |
|
- |
* Height of horizontal sliderbar is automatically calculated on base of height of components which are included in widget |
120 |
|
- |
*/ |
121 |
|
- |
public void setHeight( String height ) { |
122 |
|
- |
super.setHeight( getBarHeight() + "px" ); |
123 |
|
- |
} |
124 |
|
- |
|
125 |
|
- |
@Override |
126 |
|
- |
public void setWidth( String width ) { |
127 |
|
- |
super.setWidth( width ); |
128 |
|
- |
if ( isAttached() ) { |
129 |
|
- |
presenter.setBarPixelSize( this.getOffsetWidth() ); |
130 |
|
- |
presenter.processParams(); |
131 |
|
- |
reDrawMarks(); |
132 |
|
- |
setValue( getValue() ); |
133 |
|
- |
} |
134 |
|
- |
} |
135 |
|
- |
|
136 |
|
- |
public void setScaleWidget( Widget scaleWidget, int scaleHeight ) { |
137 |
|
- |
super.setScaleWidget( scaleWidget, scaleHeight ); |
138 |
|
- |
} |
139 |
|
- |
} |
|
1 |
+ |
package org.litesoft.GWT.client.widgets.sliderbar.client.view; |
|
2 |
+ |
|
|
3 |
+ |
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.Presenter.*; |
|
4 |
+ |
|
|
5 |
+ |
import com.google.gwt.event.dom.client.*; |
|
6 |
+ |
import com.google.gwt.user.client.ui.*; |
|
7 |
+ |
|
|
8 |
+ |
import java.util.*; |
|
9 |
+ |
|
|
10 |
+ |
/** |
|
11 |
+ |
* @author kiouri |
|
12 |
+ |
*/ |
|
13 |
+ |
public class SliderBarHorizontal extends SliderBar { |
|
14 |
+ |
|
|
15 |
+ |
protected int barWidth, barHeight, dragTopPosition, scaleWidth; |
|
16 |
+ |
|
|
17 |
+ |
protected int getBarHeight() { |
|
18 |
+ |
barHeight = drag.getOffsetHeight(); |
|
19 |
+ |
for ( int i = 0; i < orderedWidgets.size(); i++ ) { |
|
20 |
+ |
if ( orderedWidgets.get( i ) == scale ) { |
|
21 |
+ |
barHeight = Math.max( barHeight, scaleSize ); |
|
22 |
+ |
} else { |
|
23 |
+ |
barHeight = Math.max( barHeight, orderedWidgets.get( i ).getOffsetHeight() ); |
|
24 |
+ |
} |
|
25 |
+ |
} |
|
26 |
+ |
barHeight = Math.max( barHeight, scaleSize ); |
|
27 |
+ |
return barHeight; |
|
28 |
+ |
} |
|
29 |
+ |
|
|
30 |
+ |
protected void ajustScaleSize( int widgetWidth ) { |
|
31 |
+ |
scaleWidth = widgetWidth; |
|
32 |
+ |
if ( less != null ) { |
|
33 |
+ |
for ( int i = 0; i < less.size(); i++ ) { |
|
34 |
+ |
scaleWidth -= less.get( i ).getOffsetWidth(); |
|
35 |
+ |
} |
|
36 |
+ |
} |
|
37 |
+ |
if ( more != null ) { |
|
38 |
+ |
for ( int i = 0; i < more.size(); i++ ) { |
|
39 |
+ |
scaleWidth -= more.get( i ).getOffsetWidth(); |
|
40 |
+ |
} |
|
41 |
+ |
} |
|
42 |
+ |
scale.setPixelSize( scaleWidth, scaleSize ); |
|
43 |
+ |
} |
|
44 |
+ |
|
|
45 |
+ |
public int getAbsMaxLength() { |
|
46 |
+ |
return scaleWidth - drag.getOffsetWidth(); |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
public void drawScrollBar( int barWidth ) { |
|
50 |
+ |
absPanel.clear(); |
|
51 |
+ |
putWidgetsToAbsPanel(); |
|
52 |
+ |
initVariables( barWidth ); |
|
53 |
+ |
ajustScaleSize( barWidth ); |
|
54 |
+ |
this.setHeight( getBarHeight() + "px" ); |
|
55 |
+ |
absPanel.setPixelSize( barWidth, getBarHeight() ); |
|
56 |
+ |
placeWidgets( orderedWidgets ); |
|
57 |
+ |
absPanel.setWidgetPosition( drag, getScaleLeft( orderedWidgets ), dragTopPosition ); |
|
58 |
+ |
} |
|
59 |
+ |
|
|
60 |
+ |
protected void initVariables( int barWidth ) { |
|
61 |
+ |
this.barWidth = barWidth; |
|
62 |
+ |
startPosition = getScaleLeft( orderedWidgets ); |
|
63 |
+ |
dragTopPosition = (getBarHeight() - drag.getOffsetHeight()) / 2; |
|
64 |
+ |
} |
|
65 |
+ |
|
|
66 |
+ |
protected int getScaleLeft( ArrayList<Widget> widgets ) { |
|
67 |
+ |
int sPosition = 0; |
|
68 |
+ |
for ( int i = 0; i < widgets.size(); i++ ) { |
|
69 |
+ |
if ( widgets.get( i ) != scale ) { |
|
70 |
+ |
sPosition += widgets.get( i ).getOffsetWidth(); |
|
71 |
+ |
} else { |
|
72 |
+ |
return sPosition; |
|
73 |
+ |
} |
|
74 |
+ |
} |
|
75 |
+ |
return sPosition; |
|
76 |
+ |
} |
|
77 |
+ |
|
|
78 |
+ |
protected void placeWidgets( ArrayList<Widget> widgets ) { |
|
79 |
+ |
int tmpPosition = 0; |
|
80 |
+ |
int barHeight = getBarHeight(); |
|
81 |
+ |
for ( int i = 0; i < widgets.size(); i++ ) { |
|
82 |
+ |
if ( widgets.get( i ) == scale ) { |
|
83 |
+ |
absPanel.setWidgetPosition( widgets.get( i ), tmpPosition, (barHeight - scaleSize) / 2 ); |
|
84 |
+ |
} else { |
|
85 |
+ |
absPanel.setWidgetPosition( widgets.get( i ), tmpPosition, (barHeight - widgets.get( i ).getOffsetHeight()) / 2 ); |
|
86 |
+ |
} |
|
87 |
+ |
tmpPosition += widgets.get( i ).getOffsetWidth(); |
|
88 |
+ |
} |
|
89 |
+ |
} |
|
90 |
+ |
|
|
91 |
+ |
public void setDragPosition( int position ) { |
|
92 |
+ |
position = startPosition + position; |
|
93 |
+ |
absPanel.setWidgetPosition( drag, position, dragTopPosition ); |
|
94 |
+ |
} |
|
95 |
+ |
|
|
96 |
+ |
public int getScaleTouchPosition( MouseEvent event ) { |
|
97 |
+ |
return event.getRelativeX( this.getElement() ) - startPosition - drag.getOffsetWidth() / 2; |
|
98 |
+ |
} |
|
99 |
+ |
|
|
100 |
+ |
public int getDragPosition() { |
|
101 |
+ |
return absPanel.getWidgetLeft( drag ) - startPosition; |
|
102 |
+ |
} |
|
103 |
+ |
|
|
104 |
+ |
/** |
|
105 |
+ |
* Sets scale mark to scale |
|
106 |
+ |
*/ |
|
107 |
+ |
public void putMark( Mark mark, int markPosition ) { |
|
108 |
+ |
int markY = (this.barHeight - mark.getMarkHeight()) / 2; |
|
109 |
+ |
this.absPanel.add( mark, this.startPosition + markPosition + drag.getOffsetWidth() / 2, markY ); |
|
110 |
+ |
} |
|
111 |
+ |
|
|
112 |
+ |
public Orientation getOrientation() { |
|
113 |
+ |
return Orientation.HORIZONTAL; |
|
114 |
+ |
} |
|
115 |
+ |
|
|
116 |
+ |
@Override |
|
117 |
+ |
/** |
|
118 |
+ |
* It is not possible to adjust height of horizontal sliderbar with help of this method. |
|
119 |
+ |
* Height of horizontal sliderbar is automatically calculated on base of height of components which are included in widget |
|
120 |
+ |
*/ |
|
121 |
+ |
public void setHeight( String height ) { |
|
122 |
+ |
super.setHeight( getBarHeight() + "px" ); |
|
123 |
+ |
} |
|
124 |
+ |
|
|
125 |
+ |
@Override |
|
126 |
+ |
public void setWidth( String width ) { |
|
127 |
+ |
super.setWidth( width ); |
|
128 |
+ |
if ( isAttached() ) { |
|
129 |
+ |
presenter.setBarPixelSize( this.getOffsetWidth() ); |
|
130 |
+ |
presenter.processParams(); |
|
131 |
+ |
reDrawMarks(); |
|
132 |
+ |
setValue( getValue() ); |
|
133 |
+ |
} |
|
134 |
+ |
} |
|
135 |
+ |
|
|
136 |
+ |
public void setScaleWidget( Widget scaleWidget, int scaleHeight ) { |
|
137 |
+ |
super.setScaleWidget( scaleWidget, scaleHeight ); |
|
138 |
+ |
} |
|
139 |
+ |
} |