Example usage for com.vaadin.ui Button removeClickShortcut

List of usage examples for com.vaadin.ui Button removeClickShortcut

Introduction

In this page you can find the example usage for com.vaadin.ui Button removeClickShortcut.

Prototype

public void removeClickShortcut() 

Source Link

Document

Removes the keyboard shortcut previously set with #setClickShortcut(int,int) .

Usage

From source file:com.snowy.Chat.java

public Chat(int id, data d) {

    this.d = d;/*from   w w  w  .j  a  v  a 2 s. c  o  m*/
    this.id = id;
    tf.setSizeFull();
    //ts = d.getCurrentSqlTimestamp();
    //Logger.getLogger(Chat.class).info(ts.toString());
    //tA.setValue("hello\n");
    lastMessageId = d.lastMessageIdFromCurrent(id);
    HorizontalLayout fl = new HorizontalLayout();
    fl.addComponent(tf);
    Button b = new Button("Send");
    fl.addComponent(b);
    tf.setSizeFull();
    fl.setExpandRatio(tf, 1);
    b.addClickListener(e -> {
        if (tf.getValue().length() != 0) {

            d.sendMessage(id, (tf.getValue().length() < 200 ? tf.getValue() : tf.getValue().substring(0, 199)));

            tf.clear();
        }

    });
    /*tf.addTextChangeListener(e->{
    Logger.getLogger(Chat.class).info(e.getText().charAt(e.getText().length()-1)+"");
    if(e.getText().charAt(e.getText().length()-1)==10){
        b.click();
    }
            
    });*/
    tf.addFocusListener(new FocusListener() {
        @Override
        public void focus(final FocusEvent event) {
            b.setClickShortcut(KeyCode.ENTER);
        }

    });
    tf.addBlurListener(new BlurListener() {
        @Override
        public void blur(final BlurEvent event) {
            b.removeClickShortcut();
        }
    });
    fl.setSizeFull();
    fl.setHeightUndefined();
    tA.setSizeFull();
    //tA.setReadOnly(true);
    tf.setHeightUndefined();
    tA.setWordwrap(true);
    tA.setImmediate(true);

    this.addComponent(tA);
    this.addComponent(fl);
    this.setExpandRatio(tA, 2);
    tA.setReadOnly(true);

    //this.setExpandRatio(fl, 0);
    this.setSizeFull();
}

From source file:dhbw.clippinggorilla.userinterface.views.GroupView.java

public GroupView() {
    User user = UserUtils.getCurrent();// w ww .  java 2 s .c om
    Set<Group> groups = UserUtils.getAllGroups(user);

    CssLayout newGroupGroup = new CssLayout();
    newGroupGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);

    TextField textFieldNewGroupName = new TextField();
    Language.setCustom(Word.GROUP_NAME, s -> textFieldNewGroupName.setPlaceholder(s));
    textFieldNewGroupName.setWidth("260px");
    textFieldNewGroupName.setMaxLength(255);
    newGroupGroup.addComponent(textFieldNewGroupName);

    Button buttonNewGroup = new Button();
    buttonNewGroup.setIcon(VaadinIcons.PLUS);
    buttonNewGroup.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonNewGroup.addClickListener(e -> {
        TabSheet.Tab newTab = accordion.addTab(createTab(createEmptyGroup(textFieldNewGroupName.getValue())),
                textFieldNewGroupName.getValue());
        accordion.setSelectedTab(newTab);
        accordion.setWidth("100%");
        textFieldNewGroupName.clear();
    });
    newGroupGroup.addComponent(buttonNewGroup);
    textFieldNewGroupName
            .addFocusListener(f -> buttonNewGroup.setClickShortcut(ShortcutAction.KeyCode.ENTER, null));
    textFieldNewGroupName.addBlurListener(f -> buttonNewGroup.removeClickShortcut());

    groups.forEach(g -> {
        accordion.addTab(createTab(g), g.getName());
    });
    addComponents(newGroupGroup, accordion);
    //SESSIONS.put(user, this);
}

From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java

public InterestProfileView() {
    User user = UserUtils.getCurrent();//w  w  w.  ja v  a 2s.  c o m
    Set<InterestProfile> profiles = UserUtils.getAllInterestProfiles(user);

    CssLayout newProfileGroup = new CssLayout();
    newProfileGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);

    TextField textFieldNewProfileName = new TextField();
    Language.setCustom(Word.PROFILE_NAME, s -> textFieldNewProfileName.setPlaceholder(s));
    textFieldNewProfileName.setWidth("260px");
    textFieldNewProfileName.setMaxLength(255);
    newProfileGroup.addComponent(textFieldNewProfileName);

    Button buttonNewProfile = new Button();
    buttonNewProfile.setIcon(VaadinIcons.PLUS);
    buttonNewProfile.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonNewProfile.addClickListener(e -> {
        Tab newTab = accordion.addTab(createTab(createEmptyProfile(textFieldNewProfileName.getValue())),
                textFieldNewProfileName.getValue());
        accordion.setSelectedTab(newTab);
        accordion.setWidth("100%");
        textFieldNewProfileName.clear();
    });
    newProfileGroup.addComponent(buttonNewProfile);
    textFieldNewProfileName
            .addFocusListener(f -> buttonNewProfile.setClickShortcut(ShortcutAction.KeyCode.ENTER, null));
    textFieldNewProfileName.addBlurListener(f -> buttonNewProfile.removeClickShortcut());

    profiles.forEach((InterestProfile profile) -> {
        accordion.addTab(createTab(profile), profile.getName());
    });
    addComponents(newProfileGroup, accordion);
    SESSIONS.put(user, this);
}

From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java

private Component getAddTagGroup(InterestProfile profile, boolean included) {
    CssLayout newTagGroup = new CssLayout();
    newTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);

    TextField textFieldTag = new TextField();
    textFieldTag.setWidth("325px");
    textFieldTag.setMaxLength(255);//www  .  ja  v a2 s  .  c o m
    Language.setCustom(Word.NEW_TAG, s -> textFieldTag.setPlaceholder(s));

    Button buttonAddTag = new Button(VaadinIcons.PLUS);
    buttonAddTag.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttonAddTag.addClickListener(event -> {
        addRow(profile, included, textFieldTag.getValue());
        profile.getTags().put(textFieldTag.getValue(), included);
        textFieldTag.clear();
    });
    textFieldTag.addFocusListener(f -> buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null));
    textFieldTag.addBlurListener(f -> buttonAddTag.removeClickShortcut());

    newTagGroup.addComponents(textFieldTag, buttonAddTag);
    newTagGroup.setWidth("100%");
    return newTagGroup;
}

From source file:dhbw.clippinggorilla.userinterface.windows.GroupProfileWindow.java

private Component getAddTagGroup(GroupInterestProfile profile, boolean included) {
    CssLayout newTagGroup = new CssLayout();
    newTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);

    TextField textFieldTag = new TextField();
    textFieldTag.setWidth("325px");
    textFieldTag.setMaxLength(255);/*from www  .  java  2s .co m*/
    Language.setCustom(Word.NEW_TAG, s -> textFieldTag.setPlaceholder(s));

    Button buttonAddTag = new Button(VaadinIcons.PLUS);
    buttonAddTag.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttonAddTag.addClickListener(event -> {
        addRow(profile, included, textFieldTag.getValue(), true);
        profile.getTags().put(textFieldTag.getValue(), included);
        textFieldTag.clear();
    });
    textFieldTag.addFocusListener(f -> buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null));
    textFieldTag.addBlurListener(f -> buttonAddTag.removeClickShortcut());

    newTagGroup.addComponents(textFieldTag, buttonAddTag);
    newTagGroup.setWidth("100%");
    return newTagGroup;
}

From source file:org.lucidj.vaadinui.Login.java

License:Apache License

@Override // LoginForm
protected Component createContent(TextField userNameField, PasswordField passwordField, Button loginButton) {
    // Save the predefined components
    this.userNameField = userNameField;
    this.passwordField = passwordField;
    this.loginButton = loginButton;

    // Make LoginForm container full-screen
    setSizeFull();/*from  ww  w . ja  v  a  2s  .  com*/

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();
    layout.addStyleName("login-wallpaper");

    final VerticalLayout loginPanel = new VerticalLayout();
    loginPanel.setSizeUndefined();
    loginPanel.setMargin(true);
    loginPanel.setSpacing(true);
    Responsive.makeResponsive(loginPanel);
    loginPanel.addStyleName("card");

    //--------
    // HEADER
    //--------

    final HorizontalLayout labels = new HorizontalLayout();
    labels.setWidth("100%");

    final Label title = new Label("<h3><strong>LucidJ</strong> Console</h3>", ContentMode.HTML);
    labels.addComponent(title);
    labels.setExpandRatio(title, 1);

    loginPanel.addComponent(labels);

    //--------
    // FIELDS
    //--------

    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);
    fields.addStyleName("fields");

    userNameField.setImmediate(true);
    userNameField.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER);
    final ShortcutListener username_enter_listener = new ShortcutListener("Next field (Tab)",
            ShortcutAction.KeyCode.ENTER, null) {
        @Override
        public void handleAction(Object o, Object o1) {
            passwordField.setValue("");
            passwordField.focus();
        }
    };
    userNameField.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(FieldEvents.TextChangeEvent textChangeEvent) {
            show_default_message();

            int new_username_length = textChangeEvent.getText().length();

            // Check for autofill
            if (userNameField.isEmpty() && new_username_length > 1 && !userNameField_filling) {
                // This is autofill
                userNameField.removeShortcutListener(username_enter_listener);
                userNameField.setCursorPosition(new_username_length);
                userNameField.setSelectionRange(0, new_username_length);
            } else {
                userNameField_filling = true;
                passwordField.setValue("");
                userNameField.addShortcutListener(username_enter_listener);
            }
        }
    });
    userNameField.addFocusListener(new FieldEvents.FocusListener() {
        @Override
        public void focus(FieldEvents.FocusEvent focusEvent) {
            // Cursor on username, Enter jump to password
            loginButton.removeClickShortcut();
            userNameField.addShortcutListener(username_enter_listener);
        }
    });
    userNameField.addBlurListener(new FieldEvents.BlurListener() {
        @Override
        public void blur(FieldEvents.BlurEvent blurEvent) {
            // Cursor on password or elsewhere, enter submits
            userNameField.removeShortcutListener(username_enter_listener);
            loginButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
        }
    });

    passwordField.setImmediate(true);
    passwordField.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.EAGER);
    passwordField.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(FieldEvents.TextChangeEvent textChangeEvent) {
            show_default_message();
        }
    });

    loginButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
    loginButton.setDisableOnClick(true);

    fields.addComponents(userNameField, passwordField, loginButton);
    fields.setComponentAlignment(loginButton, Alignment.BOTTOM_LEFT);

    loginPanel.addComponent(fields);

    //--------
    // FOOTER
    //--------

    loginPanel.addComponent(new CheckBox("Remember me", true));

    loginPanel.addComponent(message_label);
    show_default_message();

    layout.addComponent(loginPanel);
    layout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
    return (layout);
}

From source file:org.vaadin.tori.view.thread.PostEditor.java

License:Apache License

private Component buildButtons() {
    HorizontalLayout result = new HorizontalLayout();
    result.addStyleName("buttonslayout");
    result.setWidth(100.0f, Unit.PERCENTAGE);
    result.setSpacing(true);/*from w  ww  .  j  a  va  2  s.c om*/
    result.setMargin(true);
    final Button cancelButton = ComponentUtil.getSecondaryButton("Discard Changes", new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            event.getButton().removeClickShortcut();
            listener.cancelEdit();
        }
    });
    result.addComponent(new Button("Confirm Edit", new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            cancelButton.removeClickShortcut();
            listener.submitEdit(editor.getValue());
        }
    }));

    cancelButton.setClickShortcut(KeyCode.ESCAPE);
    result.addComponent(cancelButton);
    result.setExpandRatio(cancelButton, 1.0f);
    return result;
}