Example usage for com.google.gwt.widgetideas.client HSliderBar HSliderBar

List of usage examples for com.google.gwt.widgetideas.client HSliderBar HSliderBar

Introduction

In this page you can find the example usage for com.google.gwt.widgetideas.client HSliderBar HSliderBar.

Prototype

public HSliderBar(double minValue, double maxValue, LabelFormatter labelFormatter,
        AbstractImagePrototype[] images, String styleBaseName) 

Source Link

Document

Create a slider bar.

Usage

From source file:org.vectomatic.client.rep.view.PlainColorMenu.java

License:Open Source License

public PlainColorMenu(RepApplication app, StyleController styleController) {
    super(true, true);
    _app = app;/*from w  ww .  j  ava2s.  co  m*/
    _pickColorController = new PickColorController(app, styleController);
    setStyleName("plainColorMenu");
    ColorEditor colorEditor = new ColorEditor(_app);
    _paletteEditor = new PaletteEditor(_app, colorEditor, this);
    _styleController = styleController;
    _paletteWidget = new PaletteWidget(_paletteEditor.getSelectedPalette(), null);
    _paletteWidget.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            _styleController.setStyle(_paletteWidget.getSelectedColor());
            hide();
        }
    });

    Label alphaLabel = new Label(_app.getConstants().transparencyLabel());
    _alphaTextBox = new TextBox();
    _alphaTextBox.setMaxLength(3);
    _alphaTextBox.setWidth("50px");
    _alphaTextBox.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            if (!_eventsDisabled) {
                _eventsDisabled = true;
                try {
                    double value = Double.parseDouble(_alphaTextBox.getText());
                    if (value >= _alphaSlider.getMinValue() && value <= _alphaSlider.getMaxValue()) {
                        _alphaSlider.setCurrentValue(value);
                        _styleController.setOpacity(
                                new FloatAttributeValue((float) (_alphaSlider.getCurrentValue() / 100d)));
                    } else {
                        _alphaTextBox.setText(Integer.toString((int) _alphaSlider.getCurrentValue()));
                    }
                } catch (NumberFormatException e) {
                }
                _eventsDisabled = false;
            }
        }
    });

    _alphaSlider = new HSliderBar(0d, 100d, null,
            new AbstractImagePrototype[] { _app.getIcons().chslider(), _app.getIcons().chsliderSliding() },
            "plainColorMenu-HSliderBar");
    _alphaSlider.setStepSize(1d);
    _alphaSlider.addSliderListener(new SliderListenerAdapter() {
        @Override
        public void onValueChanged(SliderBar slider, double curValue) {
            if (!_eventsDisabled) {
                _eventsDisabled = true;
                _alphaTextBox.setText(Integer.toString((int) curValue));
                _eventsDisabled = false;
            }
        }

        @Override
        public void onStopSliding(SliderBar slider) {
            _styleController.setOpacity(new FloatAttributeValue((float) (slider.getCurrentValue() / 100d)));
        }
    });
    _alphaSlider.setCurrentValue(0d);

    HorizontalPanel hpanel = new HorizontalPanel();
    hpanel.add(alphaLabel);
    hpanel.add(_alphaTextBox);
    hpanel.add(_alphaSlider);

    Label editPaletteLabel = new Label(_app.getConstants().editPaletteButton());
    editPaletteLabel.setStyleName("plainColorMenuItem");
    editPaletteLabel.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            editPalette();
        }
    });
    Label pickColorLabel = new Label(_app.getConstants().pickColorButton());
    pickColorLabel.setStyleName("plainColorMenuItem");
    pickColorLabel.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            pickColor();
        }
    });
    VerticalPanel vpanel = new VerticalPanel();
    vpanel.add(_paletteWidget);
    vpanel.add(hpanel);
    vpanel.add(editPaletteLabel);
    vpanel.add(pickColorLabel);
    setWidget(vpanel);
}