Example usage for com.google.gwt.gen2.datepicker.client DateBox getCursorPos

List of usage examples for com.google.gwt.gen2.datepicker.client DateBox getCursorPos

Introduction

In this page you can find the example usage for com.google.gwt.gen2.datepicker.client DateBox getCursorPos.

Prototype

public int getCursorPos() 

Source Link

Document

Gets the current cursor position in the date box.

Usage

From source file:com.google.gwt.gen2.demo.datepicker.client.DatePickerDemo.java

License:Apache License

private Widget dateRange() {
    VerticalPanel v = new VerticalPanel();
    HorizontalPanel p = new HorizontalPanel();
    v.add(p);/*from   www . ja  va2  s  .  co m*/
    start = new DateBox();
    start.setAnimationEnabled(true);
    final DateBox end = new DateBox();
    end.setAnimationEnabled(true);

    start.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent e) {
            if (e.isRightKeyCode() && start.getCursorPos() == start.getText().length()) {
                start.hideDatePicker();
                end.setFocus(true);
            }
        }
    });

    end.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent e) {
            if ((e.isLeftKeyCode()) && end.getCursorPos() == 0) {
                start.setFocus(true);
                end.hideDatePicker();
            }
        }
    });

    end.getDatePicker().addSelectionHandler(new SelectionHandler<Date>() {
        public void onSelection(SelectionEvent<Date> event) {
            start.removeStyleName("user-modified");
        }
    });

    start.showDate(new Date());

    p.add(start);
    Label l = new Label(" - ");
    l.setStyleName("filler");
    p.add(l);
    p.add(end);
    HorizontalPanel h2 = new HorizontalPanel();
    v.add(h2);
    h2.add(new Button("Short format", new ClickListener() {

        public void onClick(Widget sender) {
            start.setDateFormat(DateTimeFormat.getShortDateFormat());
            end.setDateFormat(DateTimeFormat.getShortDateFormat());
        }
    }));
    h2.add(new Button("Long format", new ClickListener() {

        public void onClick(Widget sender) {
            start.setDateFormat(DateTimeFormat.getLongDateFormat());
            end.setDateFormat(DateTimeFormat.getLongDateFormat());
        }
    }));

    h2.add(new Button("clear", new ClickListener() {
        public void onClick(Widget sender) {
            start.clear();
            end.clear();
        }
    }));
    return v;
}