|
@@ -1,49 +1,45 @@ |
1 |
1 |
|
package org.litesoft.GWT.client.widgets.sliderbar.client.view; |
2 |
2 |
|
|
3 |
|
- |
import java.util.ArrayList; |
|
3 |
+ |
import org.litesoft.GWT.client.widgets.sliderbar.client.event.*; |
|
4 |
+ |
import org.litesoft.GWT.client.widgets.sliderbar.client.exception.*; |
|
5 |
+ |
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.*; |
|
6 |
+ |
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.Presenter.*; |
|
7 |
+ |
|
|
8 |
+ |
import com.google.gwt.event.shared.*; |
|
9 |
+ |
import com.google.gwt.user.client.*; |
|
10 |
+ |
import com.google.gwt.user.client.ui.*; |
4 |
11 |
|
|
5 |
|
- |
import com.google.gwt.event.dom.client.MouseEvent; |
6 |
|
- |
import com.google.gwt.event.shared.HandlerRegistration; |
7 |
|
- |
import com.google.gwt.user.client.DOM; |
8 |
|
- |
import com.google.gwt.user.client.ui.FocusPanel; |
9 |
|
- |
import com.google.gwt.user.client.ui.Widget; |
10 |
|
- |
import org.litesoft.GWT.client.widgets.sliderbar.client.event.BarValueChangedHandler; |
11 |
|
- |
import org.litesoft.GWT.client.widgets.sliderbar.client.exception.WidgetNotFoundError; |
12 |
|
- |
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.Display; |
13 |
|
- |
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.Presenter; |
14 |
|
- |
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.Presenter.Orientation; |
|
12 |
+ |
import java.util.*; |
15 |
13 |
|
|
16 |
14 |
|
/** |
17 |
|
- |
* |
18 |
15 |
|
* @author kiouri |
19 |
|
- |
* The base class for Horizontal and Vertical SliderBar |
20 |
|
- |
* |
|
16 |
+ |
* The base class for Horizontal and Vertical SliderBar |
21 |
17 |
|
*/ |
22 |
|
- |
public abstract class SliderBar extends FocusPanel implements Display{ |
|
18 |
+ |
public abstract class SliderBar extends FocusPanel implements Display { |
23 |
19 |
|
|
24 |
20 |
|
protected Widget scale, drag; |
25 |
21 |
|
protected int scaleSize, startPosition, delimSize; |
26 |
22 |
|
protected ArrayList<Widget> less = new ArrayList<Widget>(), |
27 |
|
- |
more = new ArrayList<Widget>(), |
28 |
|
- |
orderedWidgets = new ArrayList<Widget>(); |
29 |
|
- |
protected TouchableAbsolutePanelPK absPanel = new TouchableAbsolutePanelPK(); |
|
23 |
+ |
more = new ArrayList<Widget>(), |
|
24 |
+ |
orderedWidgets = new ArrayList<Widget>(); |
|
25 |
+ |
protected TouchableAbsolutePanelPK absPanel = new TouchableAbsolutePanelPK(); |
30 |
26 |
|
protected boolean isMarksPlaced = false, wasInited = false; |
31 |
27 |
|
protected String color; |
32 |
28 |
|
protected Presenter presenter; |
33 |
29 |
|
|
34 |
|
- |
public SliderBar(){ |
35 |
|
- |
presenter = new Presenter(this, getOrientation()); |
36 |
|
- |
this.add(absPanel); |
|
30 |
+ |
public SliderBar() { |
|
31 |
+ |
presenter = new Presenter( this, getOrientation() ); |
|
32 |
+ |
this.add( absPanel ); |
37 |
33 |
|
} |
38 |
34 |
|
|
39 |
|
- |
public SliderBar(Presenter presenter){ |
40 |
|
- |
if (presenter == null){ |
41 |
|
- |
this.presenter = new Presenter(this, getOrientation()); |
|
35 |
+ |
public SliderBar( Presenter presenter ) { |
|
36 |
+ |
if ( presenter == null ) { |
|
37 |
+ |
this.presenter = new Presenter( this, getOrientation() ); |
42 |
38 |
|
} else { |
43 |
39 |
|
this.presenter = presenter; |
44 |
|
- |
presenter.setDislay(this); |
|
40 |
+ |
presenter.setDislay( this ); |
45 |
41 |
|
} |
46 |
|
- |
this.add(absPanel); |
|
42 |
+ |
this.add( absPanel ); |
47 |
43 |
|
} |
48 |
44 |
|
|
49 |
45 |
|
/** |
|
@@ -56,9 +52,9 @@ |
56 |
52 |
|
/** |
57 |
53 |
|
* Sets knob visible. Knob becomes invisible if maxValue equals zero. |
58 |
54 |
|
*/ |
59 |
|
- |
public void setDragVisible(boolean isVisible){ |
60 |
|
- |
if (drag != null){ |
61 |
|
- |
drag.setVisible(isVisible); |
|
55 |
+ |
public void setDragVisible( boolean isVisible ) { |
|
56 |
+ |
if ( drag != null ) { |
|
57 |
+ |
drag.setVisible( isVisible ); |
62 |
58 |
|
} |
63 |
59 |
|
} |
64 |
60 |
|
|
|
@@ -70,10 +66,10 @@ |
70 |
66 |
|
} |
71 |
67 |
|
|
72 |
68 |
|
/** |
73 |
|
- |
* @return list of buttons that reduce the current value (knob moves left or up) |
|
69 |
+ |
* @return list of buttons that reduce the current value (knob moves left or up) |
74 |
70 |
|
*/ |
75 |
71 |
|
public ArrayList<Widget> getMoreWidgets() { |
76 |
|
- |
return more; |
|
72 |
+ |
return more; |
77 |
73 |
|
} |
78 |
74 |
|
|
79 |
75 |
|
public Widget getScaleWidget() { |
|
@@ -86,40 +82,39 @@ |
86 |
82 |
|
|
87 |
83 |
|
/** |
88 |
84 |
|
* Sets the button for increase the current value (knob moves right or down) |
|
85 |
+ |
* |
89 |
86 |
|
* @param moreWidget - widget which supports handling of onMouseClick event |
90 |
87 |
|
*/ |
91 |
|
- |
protected void setMoreWidget(Widget moreWidget){ |
92 |
|
- |
orderedWidgets.add(moreWidget); |
93 |
|
- |
more.add(moreWidget); |
|
88 |
+ |
protected void setMoreWidget( Widget moreWidget ) { |
|
89 |
+ |
orderedWidgets.add( moreWidget ); |
|
90 |
+ |
more.add( moreWidget ); |
94 |
91 |
|
} |
95 |
92 |
|
|
96 |
93 |
|
/** |
97 |
94 |
|
* Sets the button for decrease the current value (knob moves left or up) |
|
95 |
+ |
* |
98 |
96 |
|
* @param moreWidget - widget which supports handling of onMouseClick event |
99 |
97 |
|
*/ |
100 |
|
- |
protected void setLessWidget(Widget lessWidget){ |
101 |
|
- |
orderedWidgets.add(lessWidget); |
102 |
|
- |
less.add(lessWidget); |
|
98 |
+ |
protected void setLessWidget( Widget lessWidget ) { |
|
99 |
+ |
orderedWidgets.add( lessWidget ); |
|
100 |
+ |
less.add( lessWidget ); |
103 |
101 |
|
} |
104 |
102 |
|
|
105 |
103 |
|
/** |
106 |
|
- |
* |
107 |
104 |
|
* @param drag - widget for knob representing |
108 |
105 |
|
*/ |
109 |
|
- |
protected void setDragWidget(Widget drag){ |
|
106 |
+ |
protected void setDragWidget( Widget drag ) { |
110 |
107 |
|
this.drag = drag; |
111 |
108 |
|
} |
112 |
109 |
|
|
113 |
110 |
|
/** |
114 |
|
- |
* |
115 |
111 |
|
* @param scaleWidget - widget for scale representing |
116 |
|
- |
* @param scaleSize - height of scale for horizontal sliderbar |
117 |
|
- |
* or width of scale for vertical sliderbar.<br> |
118 |
|
- |
* It is possible to adjust thickness of scale with help of this parameter. |
119 |
|
- |
* |
|
112 |
+ |
* @param scaleSize - height of scale for horizontal sliderbar |
|
113 |
+ |
* or width of scale for vertical sliderbar.<br> |
|
114 |
+ |
* It is possible to adjust thickness of scale with help of this parameter. |
120 |
115 |
|
*/ |
121 |
|
- |
protected void setScaleWidget(Widget scaleWidget, int scaleSize){ |
122 |
|
- |
orderedWidgets.add(scaleWidget); |
|
116 |
+ |
protected void setScaleWidget( Widget scaleWidget, int scaleSize ) { |
|
117 |
+ |
orderedWidgets.add( scaleWidget ); |
123 |
118 |
|
this.scale = scaleWidget; |
124 |
119 |
|
this.scaleSize = scaleSize; |
125 |
120 |
|
} |
|
@@ -131,33 +126,34 @@ |
131 |
126 |
|
/** |
132 |
127 |
|
* With help of this method it is possible to control appearance of outline border around the sliderbar when sliderbar is in focus. |
133 |
128 |
|
*/ |
134 |
|
- |
public void setNotSelectedInFocus(){ |
135 |
|
- |
DOM.setStyleAttribute(this.getElement(), "outline", "0px"); |
|
129 |
+ |
public void setNotSelectedInFocus() { |
|
130 |
+ |
DOM.setStyleAttribute( this.getElement(), "outline", "0px" ); |
136 |
131 |
|
} |
137 |
132 |
|
|
138 |
133 |
|
/** |
139 |
134 |
|
* With help of this method it is possible to draw marks of discret positions of knob on scale |
140 |
|
- |
* @param color - color of marks |
|
135 |
+ |
* |
|
136 |
+ |
* @param color - color of marks |
141 |
137 |
|
* @param delimSize - height of marks for horizontal sliderbar or width of marks for vertical sliderbar |
142 |
138 |
|
*/ |
143 |
|
- |
public void drawMarks( String color, int delimSize ){ |
144 |
|
- |
if (!isMarksPlaced){ |
145 |
|
- |
this.color = color; |
146 |
|
- |
this.delimSize = delimSize; |
147 |
|
- |
presenter.drawMarks(color, delimSize); |
148 |
|
- |
isMarksPlaced = true; |
149 |
|
- |
} |
|
139 |
+ |
public void drawMarks( String color, int delimSize ) { |
|
140 |
+ |
if ( !isMarksPlaced ) { |
|
141 |
+ |
this.color = color; |
|
142 |
+ |
this.delimSize = delimSize; |
|
143 |
+ |
presenter.drawMarks( color, delimSize ); |
|
144 |
+ |
isMarksPlaced = true; |
|
145 |
+ |
} |
150 |
146 |
|
} |
151 |
147 |
|
|
152 |
148 |
|
/** |
153 |
|
- |
* Remove scale marks from sliderbar |
|
149 |
+ |
* Remove scale marks from sliderbar |
154 |
150 |
|
*/ |
155 |
|
- |
public void removeMarks(){ |
|
151 |
+ |
public void removeMarks() { |
156 |
152 |
|
int childCount = absPanel.getWidgetCount(); |
157 |
|
- |
for (int i = 0; i < childCount; i++){ |
158 |
|
- |
Widget widget = absPanel.getWidget(i); |
159 |
|
- |
if (widget instanceof Mark){ |
160 |
|
- |
absPanel.remove(i); |
|
153 |
+ |
for ( int i = 0; i < childCount; i++ ) { |
|
154 |
+ |
Widget widget = absPanel.getWidget( i ); |
|
155 |
+ |
if ( widget instanceof Mark ) { |
|
156 |
+ |
absPanel.remove( i ); |
161 |
157 |
|
childCount--; |
162 |
158 |
|
i--; |
163 |
159 |
|
} |
|
@@ -167,118 +163,122 @@ |
167 |
163 |
|
|
168 |
164 |
|
/** |
169 |
165 |
|
* Adds BarValueChangedHandler (for handling changes of knob position) |
|
166 |
+ |
* |
170 |
167 |
|
* @param barValueChangedHandler |
|
168 |
+ |
* |
171 |
169 |
|
* @return HandlerRegistration used to remove this handler |
172 |
170 |
|
*/ |
173 |
171 |
|
public HandlerRegistration addBarValueChangedHandler( |
174 |
|
- |
BarValueChangedHandler barValueChangedHandler) { |
175 |
|
- |
return presenter.addBarValueChangedHandler(barValueChangedHandler); |
|
172 |
+ |
BarValueChangedHandler barValueChangedHandler ) { |
|
173 |
+ |
return presenter.addBarValueChangedHandler( barValueChangedHandler ); |
176 |
174 |
|
} |
177 |
175 |
|
|
178 |
176 |
|
/** |
179 |
177 |
|
* Sets current value. Knob will be moved to correspond position. |
|
178 |
+ |
* |
180 |
179 |
|
* @param value |
181 |
180 |
|
*/ |
182 |
|
- |
public void setValue(int value){ |
183 |
|
- |
presenter.setValue(value); |
|
181 |
+ |
public void setValue( int value ) { |
|
182 |
+ |
presenter.setValue( value ); |
184 |
183 |
|
} |
185 |
184 |
|
|
186 |
|
- |
protected void prepare(int maxValue, int pixelSize){ |
187 |
|
- |
drawScrollBar(pixelSize); |
188 |
|
- |
presenter.setMaxValue(maxValue); |
189 |
|
- |
presenter.setAbsMaxLength(getAbsMaxLength()); |
|
185 |
+ |
protected void prepare( int maxValue, int pixelSize ) { |
|
186 |
+ |
drawScrollBar( pixelSize ); |
|
187 |
+ |
presenter.setMaxValue( maxValue ); |
|
188 |
+ |
presenter.setAbsMaxLength( getAbsMaxLength() ); |
190 |
189 |
|
presenter.processParams(); |
191 |
|
- |
presenter.setValue(getValue()); |
|
190 |
+ |
presenter.setValue( getValue() ); |
192 |
191 |
|
} |
193 |
192 |
|
|
194 |
193 |
|
/** |
195 |
|
- |
* |
196 |
194 |
|
* @return max possible value which knob may point to. This value corresponds to rightmost knob position for horizontal sliderbar or |
197 |
195 |
|
* bottommost knob position for vertical sliderbar |
198 |
196 |
|
*/ |
199 |
|
- |
public int getMaxValue(){ |
|
197 |
+ |
public int getMaxValue() { |
200 |
198 |
|
return presenter.getMaxValue(); |
201 |
199 |
|
} |
202 |
200 |
|
|
203 |
201 |
|
/** |
204 |
202 |
|
* Sets value which corresponds to rightmost position of knob for horizontal sliderbar o bottommost position |
205 |
203 |
|
* for vertical sliderbar. |
|
204 |
+ |
* |
206 |
205 |
|
* @param maxValue |
207 |
206 |
|
*/ |
208 |
|
- |
public void setMaxValue(int maxValue) { |
209 |
|
- |
presenter.setMaxValue(maxValue); |
|
207 |
+ |
public void setMaxValue( int maxValue ) { |
|
208 |
+ |
presenter.setMaxValue( maxValue ); |
210 |
209 |
|
presenter.processParams(); |
211 |
210 |
|
try { |
212 |
|
- |
if (isMarksPlaced) { |
|
211 |
+ |
if ( isMarksPlaced ) { |
213 |
212 |
|
this.removeMarks(); |
214 |
|
- |
this.drawMarks(color, delimSize); |
|
213 |
+ |
this.drawMarks( color, delimSize ); |
215 |
214 |
|
} |
216 |
|
- |
setValue(getValue()); |
217 |
|
- |
} catch (Exception e) { |
|
215 |
+ |
setValue( getValue() ); |
|
216 |
+ |
} |
|
217 |
+ |
catch ( Exception e ) { |
218 |
218 |
|
} |
219 |
219 |
|
} |
220 |
220 |
|
|
221 |
|
- |
public void processParams(){ |
|
221 |
+ |
public void processParams() { |
222 |
222 |
|
presenter.processParams(); |
223 |
|
- |
if (isMarksPlaced){ |
|
223 |
+ |
if ( isMarksPlaced ) { |
224 |
224 |
|
isMarksPlaced = false; |
225 |
|
- |
this.drawMarks(color, delimSize); |
|
225 |
+ |
this.drawMarks( color, delimSize ); |
226 |
226 |
|
} |
227 |
227 |
|
} |
228 |
228 |
|
|
229 |
229 |
|
/** |
230 |
230 |
|
* Returns the value which corresponds to current position of knob |
|
231 |
+ |
* |
231 |
232 |
|
* @return |
232 |
233 |
|
*/ |
233 |
|
- |
public int getValue(){ |
|
234 |
+ |
public int getValue() { |
234 |
235 |
|
return presenter.getValue(); |
235 |
236 |
|
} |
236 |
237 |
|
|
237 |
238 |
|
protected void onLoad() { |
238 |
239 |
|
super.onLoad(); |
239 |
240 |
|
|
240 |
|
- |
if (drag == null){ |
241 |
|
- |
throw new WidgetNotFoundError("Drag widget not found..."); |
|
241 |
+ |
if ( drag == null ) { |
|
242 |
+ |
throw new WidgetNotFoundError( "Drag widget not found..." ); |
242 |
243 |
|
} |
243 |
244 |
|
|
244 |
|
- |
if (scale == null){ |
245 |
|
- |
throw new WidgetNotFoundError("Scale widget not found..."); |
|
245 |
+ |
if ( scale == null ) { |
|
246 |
+ |
throw new WidgetNotFoundError( "Scale widget not found..." ); |
246 |
247 |
|
} |
247 |
248 |
|
|
248 |
|
- |
|
249 |
|
- |
if (!wasInited) { |
|
249 |
+ |
if ( !wasInited ) { |
250 |
250 |
|
presenter.bind(); |
251 |
251 |
|
wasInited = true; |
252 |
252 |
|
} |
253 |
|
- |
if (this.getOrientation() == Orientation.HORIZONTAL) { |
254 |
|
- |
this.prepare(presenter.getMaxValue(), this.getOffsetWidth()); |
|
253 |
+ |
if ( this.getOrientation() == Orientation.HORIZONTAL ) { |
|
254 |
+ |
this.prepare( presenter.getMaxValue(), this.getOffsetWidth() ); |
255 |
255 |
|
} else { |
256 |
|
- |
this.prepare(presenter.getMaxValue(), this.getOffsetHeight()); |
|
256 |
+ |
this.prepare( presenter.getMaxValue(), this.getOffsetHeight() ); |
257 |
257 |
|
} |
258 |
258 |
|
reDrawMarks(); |
259 |
259 |
|
} |
260 |
260 |
|
|
261 |
|
- |
protected void reDrawMarks(){ |
262 |
|
- |
if (isMarksPlaced) { |
|
261 |
+ |
protected void reDrawMarks() { |
|
262 |
+ |
if ( isMarksPlaced ) { |
263 |
263 |
|
this.removeMarks(); |
264 |
|
- |
this.drawMarks(color, delimSize); |
|
264 |
+ |
this.drawMarks( color, delimSize ); |
265 |
265 |
|
} |
266 |
266 |
|
} |
267 |
267 |
|
|
268 |
|
- |
protected void putWidgetsToAbsPanel(){ |
269 |
|
- |
for (int i = 0; i < orderedWidgets.size(); i++){ |
270 |
|
- |
absPanel.add(orderedWidgets.get(i)); |
271 |
|
- |
} |
272 |
|
- |
this.absPanel.add(drag, 0,0); |
273 |
|
- |
DOM.setStyleAttribute(drag.getElement(), "zIndex", "500"); |
274 |
|
- |
} |
275 |
|
- |
|
276 |
|
- |
/** |
277 |
|
- |
* Sets minimal distance between scale marks in pixels. If distance between marks will be less then this value - marks will not be drowning. |
278 |
|
- |
* @param minMarkStep |
279 |
|
- |
*/ |
280 |
|
- |
public void setMinMarkStep(int minMarkStep){ |
281 |
|
- |
presenter.setMinMarkStep(minMarkStep); |
282 |
|
- |
} |
|
268 |
+ |
protected void putWidgetsToAbsPanel() { |
|
269 |
+ |
for ( int i = 0; i < orderedWidgets.size(); i++ ) { |
|
270 |
+ |
absPanel.add( orderedWidgets.get( i ) ); |
|
271 |
+ |
} |
|
272 |
+ |
this.absPanel.add( drag, 0, 0 ); |
|
273 |
+ |
DOM.setStyleAttribute( drag.getElement(), "zIndex", "500" ); |
|
274 |
+ |
} |
283 |
275 |
|
|
|
276 |
+ |
/** |
|
277 |
+ |
* Sets minimal distance between scale marks in pixels. If distance between marks will be less then this value - marks will not be drowning. |
|
278 |
+ |
* |
|
279 |
+ |
* @param minMarkStep |
|
280 |
+ |
*/ |
|
281 |
+ |
public void setMinMarkStep( int minMarkStep ) { |
|
282 |
+ |
presenter.setMinMarkStep( minMarkStep ); |
|
283 |
+ |
} |
284 |
284 |
|
} |