001 package org.gwtbootstrap3.extras.slider.client.ui;
002
003 /*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2013 - 2015 GwtBootstrap3
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023 import org.gwtbootstrap3.extras.slider.client.ui.base.SliderBase;
024
025 import com.google.gwt.dom.client.Element;
026 import com.google.gwt.uibinder.client.UiConstructor;
027 import com.google.gwt.user.client.Event;
028
029 /**
030 * This slider simply takes a numeric value.
031 *
032 * @author Xiaodong SUN
033 */
034 public class Slider extends SliderBase<Double> {
035
036 /**
037 * Creates a numerical slider.
038 */
039 public Slider() {
040 setRange(false);
041 }
042
043 /**
044 * Creates a numerical slider with min, max, and value.
045 *
046 * @param min
047 * @param max
048 * @param value
049 */
050 @UiConstructor
051 public Slider(final double min, final double max, final double value) {
052 this();
053 setMin(min);
054 setMax(max);
055 setValue(value);
056 }
057
058 @Override
059 protected native void setValue(Element e, Double value) /*-{
060 var doubleValue = value.@java.lang.Double::doubleValue()();
061 $wnd.jQuery(e).slider(@org.gwtbootstrap3.extras.slider.client.ui.base.SliderCommand::SET_VALUE, doubleValue);
062 }-*/;
063
064 @Override
065 protected native Double getValue(Element e) /*-{
066 var value = $wnd.jQuery(e).slider(@org.gwtbootstrap3.extras.slider.client.ui.base.SliderCommand::GET_VALUE);
067 return @java.lang.Double::new(D)(value);
068 }-*/;
069
070 @Override
071 protected Double convertValue(String value) {
072 if (value == null || value.isEmpty())
073 return null;
074 return Double.valueOf(value);
075 }
076
077 @Override
078 protected native void onSlide(Event event) /*-{
079 this.@org.gwtbootstrap3.extras.slider.client.ui.Slider::fireSlideEvent(Ljava/lang/Double;)(event.value);
080 }-*/;
081
082 @Override
083 protected native void onSlideStart(Event event) /*-{
084 this.@org.gwtbootstrap3.extras.slider.client.ui.Slider::fireSlideStartEvent(Ljava/lang/Double;)(event.value);
085 }-*/;
086
087 @Override
088 protected native void onSlideStop(Event event) /*-{
089 this.@org.gwtbootstrap3.extras.slider.client.ui.Slider::fireSlideStopEvent(Ljava/lang/Double;)(event.value);
090 }-*/;
091
092 @Override
093 protected native void onSlideChange(Event event) /*-{
094 this.@org.gwtbootstrap3.extras.slider.client.ui.Slider::fireChangeEvent(Ljava/lang/Double;)(event.value.newValue);
095 }-*/;
096
097 }