Example usage for com.google.gwt.event.dom.client KeyUpHandler KeyUpHandler

List of usage examples for com.google.gwt.event.dom.client KeyUpHandler KeyUpHandler

Introduction

In this page you can find the example usage for com.google.gwt.event.dom.client KeyUpHandler KeyUpHandler.

Prototype

KeyUpHandler

Source Link

Usage

From source file:at.ait.dme.yuma.suite.apps.image.core.client.tagging.TagSuggestBox.java

License:EUPL

public TagSuggestBox(int maxItems) {
    this.limit = maxItems;

    tagService = (TagServiceAsync) GWT.create(TagService.class);

    suggestBox.setLimit(limit);//  w w w .j ava2  s.c  o m
    suggestBox.getTextBox().addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent evt) {
            int key = evt.getNativeKeyCode();
            if (key != KeyCodes.KEY_DOWN && key != KeyCodes.KEY_UP) {
                tagService.getTagSuggestions(suggestBox.getText().trim(), limit,
                        new AsyncCallback<Collection<SemanticTag>>() {
                            @Override
                            public void onFailure(Throwable arg0) {
                                // Ignore
                            }

                            @Override
                            public void onSuccess(Collection<SemanticTag> result) {
                                for (SemanticTag t : result) {
                                    oracle.add(t.getPrimaryLabel());
                                    tags.put(t.getPrimaryLabel(), t);
                                }
                                suggestBox.showSuggestionList();
                            }
                        });
            }
        }
    });
    initWidget(suggestBox);
}

From source file:burrito.client.widgets.ExpandingTextArea.java

License:Apache License

public ExpandingTextArea() {
    addKeyDownHandler(new KeyDownHandler() {

        @Override//from   w w  w  .  j  a  v a 2  s .  c o  m
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                updateHeight(true);
            }
        }
    });
    addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE
                    || event.getNativeKeyCode() == KeyCodes.KEY_DELETE) {
                updateHeight(false);
            }
        }
    });
}

From source file:cc.alcina.framework.gwt.client.gwittir.widget.RichTextArea.java

License:Apache License

@SuppressWarnings("unchecked")
public RichTextArea(boolean withToolbar, String defaultFontSize) {
    this.defaultFontSize = defaultFontSize;
    old = base.getHTML();//w  w w  .  j  av  a 2s. co m
    this.setComparator(SimpleComparator.INSTANCE);
    this.base.addBlurHandler(new BlurHandler() {
        public void onBlur(BlurEvent event) {
            EventTarget eventTarget = event.getNativeEvent().getEventTarget();
            if (Node.is(eventTarget)) {
                Node elt = Node.as(eventTarget);
                if (DomUtils.isAncestorOf(toolbar.getElement(), elt)) {
                    return;
                }
            }
            changes.firePropertyChange("value", old, getValue());
        }
    });
    this.base.addKeyUpHandler(new KeyUpHandler() {
        public void onKeyUp(KeyUpEvent event) {
            int keyCode = event.getNativeKeyCode();
            if (keyCode == 'M' && event.isControlKeyDown()) {
                if (maximised) {
                    RichTextArea.this.removeStyleName("max");
                    WidgetUtils.restoreFromMaximise();
                } else {
                    WidgetUtils.maximiseWidget(RichTextArea.this);
                    RichTextArea.this.addStyleName("max");
                }
                maximised = !maximised;
            }
        }
    });
    this.base.addInitializeHandler(new InitializeHandler() {
        @Override
        public void onInitialize(InitializeEvent event) {
            styleBody(base.getElement(), "12px");
        }
    });
    FlowPanel fp = new FlowPanel();
    if (withToolbar) {
        FlowPanel tbHolder = new FlowPanel();
        tbHolder.setStyleName("alcina-richTextToolbarBkg");
        tbHolder.add(toolbar);
        fp.add(tbHolder);
    }
    fp.add(base);
    super.initWidget(fp);
}

From source file:cc.alcina.framework.gwt.client.widget.SelectWithSearch.java

License:Apache License

public Widget createWidget(Map<G, List<T>> itemMap, ClickHandler clickHandler, int charWidth,
        LazyDataProvider<G, T> lazyProvider) {
    this.clickHandler = clickHandler;
    this.charWidth = charWidth;
    this.lazyProvider = lazyProvider;
    this.holder = isFlowLayout() ? new FlowPanelClickable() : new FlowPanel100pcHeight();
    filter = new FilterWidget(hint);
    filter.getTextBox().addKeyUpHandler(selectableNavigation);
    filter.getTextBox().addKeyDownHandler(selectableNavigation);
    if (getInitialFilterValue() != null) {
        filter.setInitialCursorPos(getInitialFilterCursorPos());
        filter.setValue(getInitialFilterValue());
    }//from  w  ww .  j av a2s  .c om
    filter.setFocusOnAttach(isFocusOnAttach());
    filter.addAttachHandler(filterAttachHandler);
    filter.registerFilterable(this);
    selectableNavigation.setWrappedEnterListener(new ClickHandler() {
        // the listeners aren't registered on every source...pretty sure
        // this is logical...
        @Override
        public void onClick(ClickEvent event) {
            HasClickHandlers sender = (HasClickHandlers) event.getSource();
            if (enterHandler != null) {
                WidgetUtils.fireClickOnHandler(sender, enterHandler);
            }
            if (popdown) {
                WidgetUtils.fireClickOnHandler(sender, popdownHider);
            }
        }
    });
    createItemHolder();
    if (inPanelHint != null) {
        hintLabel = new HTML(inPanelHint);
        hintLabel.setStyleName("hint");
        if (showHintStrategy != null) {
            showHintStrategy.registerHintWidget(hintLabel);
            showHintStrategy.registerFilter(filter);
        }
        itemHolderAsHasWidgets().add(hintLabel);
    }
    groupCaptions = new ArrayList<Label>();
    popdownHider = new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            maybeClosePopdown(event);
        }
    };
    filter.getTextBox().addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            System.out.println("onblur - ignore:" + ignoreNextBlur);
            if (System.currentTimeMillis() - ignoreNextBlur < 100) {
                ignoreNextBlur = 0;
                filter.getTextBox().setFocus(true);
            } else {
                handleFilterBlur();
            }
        }
    });
    if (itemMap != null) {
        setItemMap(itemMap);
    }
    this.scroller = isFlowLayout() ? new ScrollPanel(itemHolder) : new ScrollPanel100pcHeight300px(itemHolder);
    if (!isFlowLayout()) {
        scroller.setSize("100%", "100%");
    }
    scroller.setStyleName("selector-scroller");
    holder.setStyleName("alcina-Chooser");
    holder.add(filter);
    if (popdown) {
        filter.getTextBox().addFocusHandler(this);
        filter.getTextBox().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                checkShowPopup();
            }
        });
        filter.getTextBox().addKeyUpHandler(new KeyUpHandler() {
            @Override
            public void onKeyUp(KeyUpEvent event) {
                if (Event.getCurrentEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
                    if (popdown) {
                        maybeClosePopdown(null);
                    }
                } else {
                    checkShowPopup();
                }
                if (CommonUtils.isNullOrEmpty(filter.getTextBox().getText()) && popdown
                        && isCloseOnPopdownFilterEmpty()) {
                    maybeClosePopdown(null);
                }
            }
        });
    } else {
        if (!isFlowLayout()) {
            holder.setHeight(holderHeight);
        }
        holder.add(scroller);
    }
    if (!popdown && lazyProvider != null) {
        AsyncCallback<LazyData> callback = new AsyncCallbackStd<SelectWithSearch.LazyData>() {
            @Override
            public void onSuccess(LazyData lazyData) {
                if (lazyData != null) {
                    setKeys(lazyData.keys);
                    setItemMap(lazyData.data);
                }
            }
        };
        lazyProvider.getData(callback);
    }
    return holder;
}

From source file:cc.kune.core.client.sitebar.search.SitebarSearchPresenter.java

License:GNU Affero Public License

@Override
protected void onBind() {
    super.onBind();
    getView().getButton().addClickHandler(new ClickHandler() {
        @Override//from   w w  w .j av  a2 s. co m
        public void onClick(final ClickEvent event) {
            doSearch();
        }
    });
    getView().getKeyHandler().addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(final KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                if (getView().getTextBox().getText().length() > 0) {
                    NotifyUser.showProgressSearching();
                    doSearch();
                }
            }
        }
    });
}

From source file:ch.unifr.pai.ice.client.textedit.TextEditor.java

License:Apache License

public TextEditor(TextEntry1Space parentWidget, int userNo, int nbTextEntry) {
    super();//w w w .  jav a  2  s  .  c  om
    parent = parentWidget;
    logVector = new Vector<String>();
    this.userNo = userNo;
    this.nbTextEntry = nbTextEntry;
    if (parentWidget instanceof AbsolutePanel)
        isAPanel = true;

    if (nbTextEntry == 1) // if it's training
    {
        wordlist = traininglist;
    }

    text = new Label(wordlist[0]);
    text.getElement().getStyle().setColor("#fff");
    text.getElement().getStyle().setFontSize(20, Unit.PT);
    text.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    hPanel.setWidth("100%");
    hPanel.add(text);
    this.add(hPanel);

    MultiFocus.setVisible(true);
    MultiFocus.setWidth("100%");
    MultiFocus.setHeight("100px");
    MultiFocus.setWidth("250px");

    MultiFocus.getElement().getStyle().setBackgroundColor("#fff");

    // this.add(ta);
    this.add(MultiFocus);
    this.setBorderWidth(1);

    MultiFocus.addDomHandler(new KeyPressHandler() { //Listen for KeyPress events on MultiFocusTextBox
        @Override
        public void onKeyPress(KeyPressEvent event) {

            if (!isStarted) {
                startTime = System.currentTimeMillis();

                if (!isSetStarted) {
                    setStartTime = startTime; // set experiment start time
                    isSetStarted = true;
                }

                isStarted = true;
            }
            typedText = typedText + event.getCharCode();

        }
    }, KeyPressEvent.getType());

    MultiFocus.addDomHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {

            if (event.getNativeEvent().getKeyCode() == 13) {

                if (isSetFinished && !isLast) { // for the second set

                    log(typedText, ta.getText());
                    parent.setLoggedData(logVector, false, true); // done with experiment

                    iteration++;
                    text.setText(secondwordlist[iteration]);

                    typedText = "";
                    isStarted = false;
                }

                if (isLast) {
                    log(typedText, ta.getText());
                    parent.setLoggedData(logVector, true, true); // done with experiment

                    text.setText(secondwordlist[0]);
                    typedText = "";
                    isStarted = false;

                    iteration = 0;
                    isLast = false;
                }

                if (!isSetFinished) {

                    if (!isLast) {
                        iteration++;
                        text.setText(wordlist[iteration]);

                        log(typedText, ta.getText()); // log for wordlist[iteration-1]
                        typedText = "";
                        isStarted = false;

                        if ((iteration == (wordlist.length - 1))) { //last element
                            isSetFinished = true;
                            isLast = true;
                        }
                    }

                }

            }

            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_BACKSPACE) {

                typedText = typedText + "~";
            }

        }
    }, KeyUpEvent.getType());
}

From source file:ch.unifr.pai.twice.multipointer.client.widgets.MultiFocusTextBox.java

License:Apache License

public MultiFocusTextBox() {
    blinkTimer = new Timer() {

        @Override//from  w w w.  j  a v  a  2s  .com
        public void run() {
            for (Cursor c : cursors.values()) {
                c.setVisible(cursorsVisible);
            }
            cursorsVisible = !cursorsVisible;
        }
    };
    blinkTimer.scheduleRepeating(cursorSpeed);
    p.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
    c = Canvas.createIfSupported();
    c.setCoordinateSpaceWidth(10000);
    c.addStyleName("multiFocusWidget");
    c.getElement().getStyle().setBorderWidth(0, Unit.PX);
    c.getElement().getStyle().setProperty("outline", "none");
    c.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            processInput(MultiCursorController.getUUID(event.getNativeEvent()), event.getCharCode());
        }
    });
    c.addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {
            Cursor c = cursors.get(MultiCursorController.getUUID(event.getNativeEvent()));
            if (c != null) {
                switch (event.getNativeKeyCode()) {
                case KeyCodes.KEY_LEFT:
                    c.setPosition(Math.max(0, c.position - 1));
                    scrollIfNecessary();
                    break;
                case KeyCodes.KEY_RIGHT:
                    c.setPosition(Math.min(value.length(), c.position + 1));
                    scrollIfNecessary();
                    break;
                case KeyCodes.KEY_UP:
                    c.setPosition(0);
                    scrollIfNecessary();
                    break;
                case KeyCodes.KEY_DOWN:
                    c.setPosition(value != null ? value.length() : 0);
                    scrollIfNecessary();
                    break;
                case KeyCodes.KEY_DELETE:
                    if (value != null && c.position < value.length()) {
                        setValue(value.substring(0, c.position) + value.substring(c.position + 1));
                        for (Cursor cursor : cursors.values()) {
                            if (c.position < cursor.getPosition()) {
                                cursor.setPosition(cursor.getPosition() - 1);
                            }
                        }
                        scrollIfNecessary();
                    }
                    break;
                case KeyCodes.KEY_BACKSPACE:
                    if (value != null && c.position > 0 && c.position <= value.length()) {
                        setValue(value.substring(0, c.position - 1) + value.substring(c.position));
                        c.setPosition(c.position - 1);
                        for (Cursor cursor : cursors.values()) {
                            if (c.position < cursor.position) {
                                cursor.setPosition(cursor.getPosition() - 1);
                            }
                        }
                        scrollIfNecessary();
                    }
                    break;
                }
            }
        }
    });
    c.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            repositionCursor(MultiCursorController.getUUID(event.getNativeEvent()),
                    MultiCursorController.getColorNative(event.getNativeEvent()),
                    event.getRelativeX(c.getCanvasElement()), event.getRelativeY(c.getCanvasElement()));
        }
    });
    multiFocus.insert(c, 0, 0, 0);
    initWidget(multiFocus);
    context = c.getContext2d();
    context.setTextAlign(TextAlign.LEFT);
    context.setTextBaseline(TextBaseline.TOP);
    context.setFont("normal " + fontSize + "px sans-serif");
    c.getElement().getStyle().setPadding(padding, Unit.PX);
    setStyle();
    // TODO Auto-generated constructor stub
    // multiFocus.setVisible(false);

    multiFocus.setWidth("161px");
    multiFocus.setHeight("25px");

}

From source file:ch.unifr.pai.twice.multipointer.client.widgets.RemoteTextArea.java

License:Apache License

private void extend() {
    this.addKeyPressHandler(new KeyPressHandler() {

        @Override/* w  w w  .ja  v  a2s  .  c o  m*/
        public void onKeyPress(KeyPressEvent event) {
            if (MultiCursorController.getUUID(event.getNativeEvent()) != null) {
                if (getValue() == null)
                    setValue(String.valueOf(event.getCharCode()));
                else if (getCursorPos() <= getValue().length()) {
                    setValue(getValue().substring(0, getCursorPos()) + event.getCharCode()
                            + ((getCursorPos() == getValue().length()) ? ""
                                    : getValue().substring(getCursorPos())));
                }
            }
        }
    });
    this.addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {
            int cursorPos = getCursorPos();
            if (MultiCursorController.getUUID(event.getNativeEvent()) != null) {
                switch (event.getNativeKeyCode()) {

                case KeyCodes.KEY_DELETE:
                    if (getValue() != null && cursorPos < getValue().length()) {
                        setValue(getValue().substring(0, cursorPos) + getValue().substring(cursorPos + 1));
                    }
                    break;
                case KeyCodes.KEY_BACKSPACE:
                    if (getValue() != null && cursorPos > 0 && cursorPos <= getValue().length()) {
                        setValue(getValue().substring(0, cursorPos - 1) + getValue().substring(cursorPos));
                        setCursorPos(cursorPos - 1);
                    }
                    break;
                }
            }
        }
    });
}

From source file:ch.unifr.pai.twice.multipointer.provider.client.widgets.MultiFocusTextBox.java

License:Apache License

public MultiFocusTextBox() {

    blinkTimer = new Timer() {

        @Override/*from w  ww  .j  a  v  a2  s.c  o  m*/
        public void run() {
            for (Cursor c : cursors.values()) {
                c.setVisible(cursorsVisible);
            }
            cursorsVisible = !cursorsVisible;
        }
    };

    blinkTimer.scheduleRepeating(cursorSpeed);
    p.getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
    c = Canvas.createIfSupported();
    c.setCoordinateSpaceWidth(10000);
    c.addStyleName("multiFocusWidget");
    c.getElement().getStyle().setBorderWidth(0, Unit.PX);
    c.getElement().getStyle().setProperty("outline", "none");
    c.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            processInput(NoMultiCursorController.getUUID(event.getNativeEvent()), event.getCharCode());
            String textcolor = NoMultiCursorController.getColorNative(event.getNativeEvent());
            setTextColor(textcolor);

        }
    });

    c.addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {
            Cursor c = cursors.get(NoMultiCursorController.getUUID(event.getNativeEvent()));

            if (c != null) {

                switch (event.getNativeKeyCode()) {
                case KeyCodes.KEY_LEFT:
                    c.setPosition(Math.max(0, c.position - 1));
                    scrollIfNecessary();
                    break;
                case KeyCodes.KEY_RIGHT:
                    c.setPosition(Math.min(value.length(), c.position + 1));
                    scrollIfNecessary();
                    break;
                case KeyCodes.KEY_UP:
                    c.setPosition(0);
                    scrollIfNecessary();
                    break;
                case KeyCodes.KEY_DOWN:
                    c.setPosition(value != null ? value.length() : 0);
                    scrollIfNecessary();
                    break;
                case KeyCodes.KEY_DELETE:
                    if (value != null && c.position < value.length()) {
                        setValue(value.substring(0, c.position) + value.substring(c.position + 1));
                        for (Cursor cursor : cursors.values()) {
                            if (c.position < cursor.getPosition()) {
                                cursor.setPosition(cursor.getPosition() - 1);
                            }
                        }
                        scrollIfNecessary();
                    }
                    break;
                case KeyCodes.KEY_BACKSPACE:
                    if (value != null && c.position > 0 && c.position <= value.length()) {
                        setValue(value.substring(0, c.position - 1) + value.substring(c.position));
                        c.setPosition(c.position - 1);
                        for (Cursor cursor : cursors.values()) {
                            if (c.position < cursor.position) {
                                cursor.setPosition(cursor.getPosition() - 1);
                            }
                        }
                        scrollIfNecessary();
                    }
                    break;
                case KeyCodes.KEY_ENTER: //ICEExperiments-TextEdit
                    setValue("");
                    c.setPosition(0);

                    break;
                }
            }
        }
    });

    c.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            repositionCursor(NoMultiCursorController.getUUID(event.getNativeEvent()),
                    NoMultiCursorController.getColorNative(event.getNativeEvent()),
                    event.getRelativeX(c.getCanvasElement()), event.getRelativeY(c.getCanvasElement()));
        }
    });
    multiFocus.insert(c, 0, 0, 0);
    initWidget(multiFocus);
    context = c.getContext2d();
    context.setTextAlign(TextAlign.LEFT);
    context.setTextBaseline(TextBaseline.TOP);
    context.setFont("normal " + fontSize + "px sans-serif");
    c.getElement().getStyle().setPadding(padding, Unit.PX);
    setStyle();
    // TODO Auto-generated constructor stub
    // multiFocus.setVisible(false);

    multiFocus.setWidth("161px");
    multiFocus.setHeight("25px");

}

From source file:ch.unifr.pai.twice.multipointer.provider.client.widgets.RemoteTextArea.java

License:Apache License

private void extend() {

    this.addKeyPressHandler(new KeyPressHandler() {

        @Override/*from   w ww.  j av  a 2 s  . com*/
        public void onKeyPress(KeyPressEvent event) {
            if (NoMultiCursorController.getUUID(event.getNativeEvent()) != null) {
                if (getValue() == null)
                    setValue(String.valueOf(event.getCharCode()));
                else if (getCursorPos() <= getValue().length()) {
                    setValue(getValue().substring(0, getCursorPos()) + event.getCharCode() // fix double char type
                            + ((getCursorPos() == getValue().length()) ? ""
                                    : getValue().substring(getCursorPos())));
                }
            }
        }
    });

    this.addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {

            int cursorPos = getCursorPos();
            if (NoMultiCursorController.getUUID(event.getNativeEvent()) != null) {
                switch (event.getNativeKeyCode()) {

                case KeyCodes.KEY_DELETE:
                    if (getValue() != null && cursorPos < getValue().length()) {
                        setValue(getValue().substring(0, cursorPos) + getValue().substring(cursorPos + 1));
                    }
                    break;
                case KeyCodes.KEY_BACKSPACE:
                    if (getValue() != null && cursorPos > 0 && cursorPos <= getValue().length()) {
                        setValue(getValue().substring(0, cursorPos - 1) //cursorPos+1  
                                + getValue().substring(cursorPos)); //cursorpos+1   
                        setCursorPos(cursorPos - 1); //cursorPos
                    }
                    break;
                }
            }
        }
    });
}