Subversion Repository Public Repository

litesoft

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package org.litesoft.GWT.client.widgets.sliderbar.client.view;

import org.litesoft.GWT.client.widgets.sliderbar.client.event.*;
import org.litesoft.GWT.client.widgets.sliderbar.client.exception.*;
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.*;
import org.litesoft.GWT.client.widgets.sliderbar.client.presenter.Presenter.*;

import com.google.gwt.event.shared.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;

import java.util.*;

/**
 * @author kiouri
 *         The base class for Horizontal and Vertical SliderBar
 */
public abstract class SliderBar extends FocusPanel implements Display {

    protected Widget scale, drag;
    protected int scaleSize, startPosition, delimSize;
    protected ArrayList<Widget> less = new ArrayList<Widget>(),
            more = new ArrayList<Widget>(),
            orderedWidgets = new ArrayList<Widget>();
    protected TouchableAbsolutePanelPK absPanel = new TouchableAbsolutePanelPK();
    protected boolean isMarksPlaced = false, wasInited = false;
    protected String color;
    protected Presenter presenter;

    public SliderBar() {
        presenter = new Presenter( this, getOrientation() );
        this.add( absPanel );
    }

    public SliderBar( Presenter presenter ) {
        if ( presenter == null ) {
            this.presenter = new Presenter( this, getOrientation() );
        } else {
            this.presenter = presenter;
            presenter.setDislay( this );
        }
        this.add( absPanel );
    }

    /**
     * @return knob widget
     */
    public Widget getDragWidget() {
        return drag;
    }

    /**
     * Sets knob visible. Knob becomes invisible if maxValue equals zero.
     */
    public void setDragVisible( boolean isVisible ) {
        if ( drag != null ) {
            drag.setVisible( isVisible );
        }
    }

    /**
     * @return list of buttons that increase the current value (knob moves right or down)
     */
    public ArrayList<Widget> getLessWidgets() {
        return less;
    }

    /**
     * @return list of buttons that reduce the current value (knob moves left or up)
     */
    public ArrayList<Widget> getMoreWidgets() {
        return more;
    }

    public Widget getScaleWidget() {
        return scale;
    }

    protected int getStartPosition() {
        return this.startPosition;
    }

    /**
     * Sets the button for increase the current value (knob moves right or down)
     *
     * @param moreWidget - widget which supports handling of onMouseClick event
     */
    protected void setMoreWidget( Widget moreWidget ) {
        orderedWidgets.add( moreWidget );
        more.add( moreWidget );
    }

    /**
     * Sets the button for decrease the current value (knob moves left or up)
     *
     * @param moreWidget - widget which supports handling of onMouseClick event
     */
    protected void setLessWidget( Widget lessWidget ) {
        orderedWidgets.add( lessWidget );
        less.add( lessWidget );
    }

    /**
     * @param drag - widget for knob representing
     */
    protected void setDragWidget( Widget drag ) {
        this.drag = drag;
    }

    /**
     * @param scaleWidget - widget for scale representing
     * @param scaleSize   - height of scale for horizontal sliderbar
     *                    or width of scale for vertical sliderbar.<br>
     *                    It is possible to adjust thickness of scale with help of this parameter.
     */
    protected void setScaleWidget( Widget scaleWidget, int scaleSize ) {
        orderedWidgets.add( scaleWidget );
        this.scale = scaleWidget;
        this.scaleSize = scaleSize;
    }

    public Widget getRootWidget() {
        return this;
    }

    /**
     * With help of this method it is possible to control appearance of outline border around the sliderbar when sliderbar is in focus.
     */
    public void setNotSelectedInFocus() {
        DOM.setStyleAttribute( this.getElement(), "outline", "0px" );
    }

    /**
     * With help of this method it is possible to draw marks of discret positions of knob on scale
     *
     * @param color     - color of marks
     * @param delimSize - height of marks for horizontal sliderbar or width of marks for vertical sliderbar
     */
    public void drawMarks( String color, int delimSize ) {
        if ( !isMarksPlaced ) {
            this.color = color;
            this.delimSize = delimSize;
            presenter.drawMarks( color, delimSize );
            isMarksPlaced = true;
        }
    }

    /**
     * Remove scale marks from sliderbar
     */
    public void removeMarks() {
        int childCount = absPanel.getWidgetCount();
        for ( int i = 0; i < childCount; i++ ) {
            Widget widget = absPanel.getWidget( i );
            if ( widget instanceof Mark ) {
                absPanel.remove( i );
                childCount--;
                i--;
            }
        }
        isMarksPlaced = false;
    }

    /**
     * Adds BarValueChangedHandler (for handling changes of knob position)
     *
     * @param barValueChangedHandler
     *
     * @return HandlerRegistration used to remove this handler
     */
    public HandlerRegistration addBarValueChangedHandler(
            BarValueChangedHandler barValueChangedHandler ) {
        return presenter.addBarValueChangedHandler( barValueChangedHandler );
    }

    /**
     * Sets current value. Knob will be moved to correspond position.
     *
     * @param value
     */
    public void setValue( int value ) {
        presenter.setValue( value );
    }

    protected void prepare( int maxValue, int pixelSize ) {
        drawScrollBar( pixelSize );
        presenter.setMaxValue( maxValue );
        presenter.setAbsMaxLength( getAbsMaxLength() );
        presenter.processParams();
        presenter.setValue( getValue() );
    }

    /**
     * @return max possible value which knob may point to. This value corresponds to rightmost knob position for horizontal sliderbar or
     * bottommost knob position for vertical sliderbar
     */
    public int getMaxValue() {
        return presenter.getMaxValue();
    }

    /**
     * Sets value which corresponds to rightmost position of knob for horizontal sliderbar o bottommost position
     * for vertical sliderbar.
     *
     * @param maxValue
     */
    public void setMaxValue( int maxValue ) {
        presenter.setMaxValue( maxValue );
        presenter.processParams();
        try {
            if ( isMarksPlaced ) {
                this.removeMarks();
                this.drawMarks( color, delimSize );
            }
            setValue( getValue() );
        }
        catch ( Exception e ) {
        }
    }

    public void processParams() {
        presenter.processParams();
        if ( isMarksPlaced ) {
            isMarksPlaced = false;
            this.drawMarks( color, delimSize );
        }
    }

    /**
     * Returns the value which corresponds to current position of knob
     *
     * @return
     */
    public int getValue() {
        return presenter.getValue();
    }

    protected void onLoad() {
        super.onLoad();

        if ( drag == null ) {
            throw new WidgetNotFoundError( "Drag widget not found..." );
        }

        if ( scale == null ) {
            throw new WidgetNotFoundError( "Scale widget not found..." );
        }

        if ( !wasInited ) {
            presenter.bind();
            wasInited = true;
        }
        if ( this.getOrientation() == Orientation.HORIZONTAL ) {
            this.prepare( presenter.getMaxValue(), this.getOffsetWidth() );
        } else {
            this.prepare( presenter.getMaxValue(), this.getOffsetHeight() );
        }
        reDrawMarks();
    }

    protected void reDrawMarks() {
        if ( isMarksPlaced ) {
            this.removeMarks();
            this.drawMarks( color, delimSize );
        }
    }

    protected void putWidgetsToAbsPanel() {
        for ( int i = 0; i < orderedWidgets.size(); i++ ) {
            absPanel.add( orderedWidgets.get( i ) );
        }
        this.absPanel.add( drag, 0, 0 );
        DOM.setStyleAttribute( drag.getElement(), "zIndex", "500" );
    }

    /**
     * Sets minimal distance between scale marks in pixels. If distance between marks will be less then this value - marks will not be drowning.
     *
     * @param minMarkStep
     */
    public void setMinMarkStep( int minMarkStep ) {
        presenter.setMinMarkStep( minMarkStep );
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/sliderbar/client/view/SliderBar.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

917 GeorgeS picture GeorgeS Sun 08 Dec, 2013 20:49:56 +0000

1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model!