View Javadoc
1   /**
2    * This file Copyright (c) 2013-2015 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.ui.vaadin.gwt.client.layout.thumbnaillayout.widget;
35  
36  import info.magnolia.ui.vaadin.gwt.client.icon.widget.IconWidget;
37  import info.magnolia.ui.vaadin.gwt.client.mgwt.SliderClientBundle;
38  
39  import com.google.gwt.core.shared.GWT;
40  import com.google.gwt.dom.client.Style;
41  import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
42  import com.google.gwt.event.logical.shared.ValueChangeHandler;
43  import com.google.gwt.event.shared.HandlerRegistration;
44  import com.google.gwt.user.client.ui.Composite;
45  import com.google.gwt.user.client.ui.FlowPanel;
46  import com.google.gwt.user.client.ui.HasValue;
47  import com.googlecode.mgwt.ui.client.widget.MSlider;
48  
49  /**
50   * Simple client-side slider widget, wraps mgwt's slider.
51   */
52  public class Slider extends Composite implements HasValueChangeHandlers<Integer>, HasValue<Integer> {
53  
54      private final SliderClientBundle cssBundle = GWT.create(SliderClientBundle.class);
55  
56      private final MSlider slider = new MSlider(cssBundle.css());
57  
58      private FlowPanel panel = new FlowPanel();
59  
60      public Slider() {
61          super();
62  
63          IconWidget iconSizeSmall = new IconWidget();
64          iconSizeSmall.setIconName("search");
65          iconSizeSmall.setSize(20);
66          iconSizeSmall.setColor("#aaa");
67          iconSizeSmall.getElement().getStyle().setVerticalAlign(Style.VerticalAlign.TOP);
68  
69          panel.addStyleName("slider-panel");
70          panel.getElement().getStyle().setPadding(10, Style.Unit.PX);
71          panel.add(iconSizeSmall);
72          panel.add(slider);
73  
74          slider.setWidth("125px");
75          initWidget(panel);
76      }
77  
78      @Override
79      public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Integer> integerValueChangeHandler) {
80          return slider.addValueChangeHandler(integerValueChangeHandler);
81      }
82  
83      @Override
84      public Integer getValue() {
85          return slider.getValue();
86      }
87  
88      @Override
89      public void setValue(Integer value) {
90          slider.setValue(value);
91      }
92  
93      @Override
94      public void setValue(Integer value, boolean fireEvents) {
95          slider.setValue(value, fireEvents);
96      }
97  }