Skip to content

Instantly share code, notes, and snippets.

@pavanandhukuri
Last active June 24, 2017 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavanandhukuri/c63635b73c16ff5abe6bd2192599cf23 to your computer and use it in GitHub Desktop.
Save pavanandhukuri/c63635b73c16ff5abe6bd2192599cf23 to your computer and use it in GitHub Desktop.
Number Spinner Control on GWT
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.IntegerBox;
/**
* NumberSpinner Custom Control
*
* @author Pavan Andhukuri
*
*/
public class NumberSpinner extends Composite {
private int RATE = 1;
private IntegerBox integerBox;
public NumberSpinner() {
this(1);
}
public NumberSpinner(int defaultValue) {
AbsolutePanel absolutePanel = new AbsolutePanel();
initWidget(absolutePanel);
absolutePanel.setSize(“55px”, “23px”);
integerBox = new IntegerBox();
absolutePanel.add(integerBox, 0, 0);
integerBox.setSize(“30px”, “16px”);
integerBox.setValue(defaultValue);
Button upButton = new Button();
upButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
setValue(getValue() + RATE);
}
});
upButton.setStyleName(“dp-spinner-upbutton”);
absolutePanel.add(upButton, 34, 1);
upButton.setSize(“12px”, “10px”);
Button downButton = new Button();
downButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (getValue() == 0)
return;
setValue(getValue() – RATE);
}
});
downButton.setStyleName(“dp-spinner-downbutton”);
absolutePanel.add(downButton, 34, 11);
downButton.setSize(“12px”, “10px”);
}
/**
* Returns the value being held.
*
* @return
*/
public int getValue() {
return integerBox.getValue() == null ? 0 : integerBox.getValue();
}
/**
* Sets the value to the control
*
* @param value
* Value to be set
*/
public void setValue(int value) {
integerBox.setValue(value);
}
/**
* Sets the rate at which increment or decrement is done.
*
* @param rate
*/
public void setRate(int rate) {
this.RATE = rate;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment