Example usage for com.google.gwt.user.client.ui KeyboardListenerAdapter KeyboardListenerAdapter

List of usage examples for com.google.gwt.user.client.ui KeyboardListenerAdapter KeyboardListenerAdapter

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui KeyboardListenerAdapter KeyboardListenerAdapter.

Prototype

KeyboardListenerAdapter

Source Link

Usage

From source file:com.apress.progwt.client.college.gui.ext.EditableLabelExtension.java

License:Apache License

/**
 * Creates the Label, the TextBox and Buttons. Also associates the
 * update method provided in the constructor with this instance.
 * /*from ww  w.j  av  a2 s  . c  om*/
 * @param labelText
 *            The value of the initial Label.
 * @param onUpdate
 *            The class that provides the update method called when
 *            the Label has been updated.
 * @param visibleLength
 *            The visible length (width) of the TextBox/TextArea.
 * @param maxLength
 *            The maximum length of text in the TextBox.
 * @param maxHeight
 *            The maximum number of visible lines of the TextArea
 * @param okButtonText
 *            The text diplayed in the OK button.
 * @param cancelButtonText
 *            The text displayed in the Cancel button.
 */
private void createEditableLabel(String labelText, ChangeListener onUpdate, String okButtonText,
        String cancelButtonText) {
    // Put everything in a VerticalPanel
    FlowPanel instance = new FlowPanel();

    if (labelText == null || labelText.length() < 1) {
        labelText = "Click to edit me";
    }

    // Create the Label element and add a ClickListener to call out
    // Change method when clicked
    text = new Label(labelText);
    text.setStylePrimaryName("editableLabel-label");

    text.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            changeTextLabel();
        }
    });
    text.addMouseListener(new MouseListenerAdapter() {
        public void onMouseEnter(Widget sender) {
            text.addStyleDependentName(HOVER_STYLE);
        }

        public void onMouseLeave(Widget sender) {
            text.removeStyleDependentName(HOVER_STYLE);
        }
    });

    // Create the TextBox element used for non word wrapped Labels
    // and add a KeyboardListener for Return and Esc key presses
    changeText = new TextBox();
    changeText.setStyleName("editableLabel-textBox");

    changeText.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            // If return then save, if Esc cancel the change,
            // otherwise do nothing
            switch (keyCode) {
            case 13:
                setTextLabel();
                break;
            case 27:
                cancelLabelChange();
                break;
            }
        }
    });

    // Create the TextAre element used for word-wrapped Labels
    // and add a KeyboardListener for Esc key presses (not return in
    // this case)

    changeTextArea = new TextArea();
    changeTextArea.setStyleName("editableLabel-textArea");

    changeTextArea.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            // If Esc then cancel the change, otherwise do nothing
            switch (keyCode) {
            case 27:
                cancelLabelChange();
                break;
            }
        }
    });

    // Set up Confirmation Button
    confirmChange = createConfirmButton(okButtonText);

    if (!(confirmChange instanceof SourcesClickEvents)) {
        throw new RuntimeException("Confirm change button must allow for click events");
    }

    ((SourcesClickEvents) confirmChange).addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            setTextLabel();
        }
    });

    // Set up Cancel Button
    cancelChange = createCancelButton(cancelButtonText);
    if (!(cancelChange instanceof SourcesClickEvents)) {
        throw new RuntimeException("Cancel change button must allow for click events");
    }

    ((SourcesClickEvents) cancelChange).addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            cancelLabelChange();
        }
    });

    // Put the buttons in a panel
    FlowPanel buttonPanel = new FlowPanel();
    buttonPanel.setStyleName("editableLabel-buttonPanel");
    buttonPanel.add(confirmChange);
    buttonPanel.add(cancelChange);

    // Add panels/widgets to the widget panel
    instance.add(text);
    instance.add(changeText);
    instance.add(changeTextArea);
    instance.add(buttonPanel);

    // Set initial visibilities. This needs to be after
    // adding the widgets to the panel because the FlowPanel
    // will mess them up when added.
    text.setVisible(true);
    changeText.setVisible(false);
    changeTextArea.setVisible(false);
    confirmChange.setVisible(false);
    cancelChange.setVisible(false);

    // Set the updater method.
    updater = onUpdate;

    // Assume that this is a non word wrapped Label unless explicitly
    // set otherwise
    text.setWordWrap(false);

    // Set the widget that this Composite represents
    initWidget(instance);
}

From source file:com.apress.progwt.client.college.gui.LoginWindow.java

License:Apache License

private Widget getUPTab() {
    VerticalPanel uptab = new VerticalPanel();
    username = new TextBox();
    username.setName("j_username");
    username.setText(lastNameEntered);/*  w  w  w . j a va 2s. c  o  m*/

    KeyboardListener enterListener = new KeyboardListenerAdapter() {
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KEY_ENTER) {
                form.submit();
            }
        }
    };

    final PasswordTextBox password = new PasswordTextBox();
    password.setName("j_password");
    password.addKeyboardListener(enterListener);

    username.setText("test");
    password.setText("testaroo");

    HorizontalPanel userP = new HorizontalPanel();

    userP.add(new Label("Username"));
    userP.add(username);

    HorizontalPanel passPanel = new HorizontalPanel();
    passPanel.add(new Label("Password"));
    passPanel.add(password);

    uptab.add(userP);
    uptab.add(passPanel);
    uptab.add(new Button("Login", new ClickListener() {
        public void onClick(Widget sender) {
            form.submit();
        }
    }));
    return uptab;
}

From source file:com.apress.progwt.client.suggest.AbstractCompleter.java

License:Apache License

public AbstractCompleter(AbstractSuggestOracle<T> oracle, CompleteListener<T> completeListener) {
    super();// www  .j a  va  2  s.c om
    this.oracle = oracle;
    this.completeListener = completeListener;

    suggestBox = new SuggestBox(oracle);
    suggestBox.addEventHandler(new SuggestionHandler() {

        public void onSuggestionSelected(SuggestionEvent event) {
            Log.debug("On Suggestion Selected! " + event.getSelectedSuggestion().getReplacementString());

            // Important, this prevents duplications
            if (keyboardEnterTimer != null) {
                keyboardEnterTimer.cancel();
            }

            complete(event.getSelectedSuggestion().getReplacementString());
        }
    });

    suggestBox.addKeyboardListener(new KeyboardListenerAdapter() {
        // @Override
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KEY_ENTER) {

                keyboardEnterTimer = new Timer() {
                    // @Override
                    public void run() {
                        complete(suggestBox.getText());
                    }
                };
                keyboardEnterTimer.schedule(400);
            }
        }
    });
    initWidget(suggestBox);
}

From source file:com.dimdim.conference.ui.common.client.user.NewChatPanel.java

License:Open Source License

/**
 * Same chat panel is used for global as well as personal chats. Global
 * chat is simply identified by using 'other' argument as null.
 */// www.  j  av  a2  s  .c  o m
public NewChatPanel(UIRosterEntry me, UIRosterEntry other) {
    this.me = me;
    this.other = other;
    if (other != null) {
        this.toId = other.getUserId();
    }
    this.lastActivityTime = System.currentTimeMillis();
    if (ConferenceGlobals.isBrowserIE()) {
        spaceSequence = "DIMDIM_LTwbr>";
    }

    //   Add the central scroll panel that will hold the messages.

    scrollPanel = new ScrollPanel();
    scrollPanel.add(this.chatMessages);
    scrollPanel.setStyleName("dm-chat-message-area");

    //   A small and short instructions / message area.

    instructionPanel = new HorizontalPanel();
    instructionPanel.setStyleName("chat-instruction-panel");
    instructionPanel.setWidth("248px");

    //in public chat add powered by dimdim logo else have the help text
    if (null == toId) {
        HorizontalPanel hp = new HorizontalPanel();

        HorizontalPanel tempSpacer = new HorizontalPanel();
        tempSpacer.setWidth("10px");
        tempSpacer.add(new Label("  "));
        hp.add(tempSpacer);
        hp.setCellHorizontalAlignment(tempSpacer, HorizontalPanel.ALIGN_LEFT);
        hp.setCellVerticalAlignment(tempSpacer, VerticalPanel.ALIGN_MIDDLE);

        PNGImage image = new PNGImage("images/logo_powered.png", 8, 14);
        hp.add(image);
        //instructionPanel.setCellWidth(image,"100%");
        hp.setCellHorizontalAlignment(image, HorizontalPanel.ALIGN_LEFT);
        hp.setCellVerticalAlignment(image, VerticalPanel.ALIGN_MIDDLE);

        //hp.setBorderWidth(1);
        HTML instruction = new HTML("Powered By <a href='#'><u> Dimdim </u></a>");
        instruction.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                openDimdimWebSite();
            }
        });
        instruction.setStyleName("poweredby-text");
        hp.add(instruction);
        //instructionPanel.setCellWidth(instruction,"100%");
        hp.setCellHorizontalAlignment(instruction, HorizontalPanel.ALIGN_LEFT);
        hp.setCellVerticalAlignment(instruction, VerticalPanel.ALIGN_MIDDLE);

        instructionPanel.add(hp);
        //instructionPanel.setCellWidth(instruction,"100%");
        instructionPanel.setCellHorizontalAlignment(hp, HorizontalPanel.ALIGN_LEFT);
        instructionPanel.setCellVerticalAlignment(hp, VerticalPanel.ALIGN_MIDDLE);

    } else {
        Label instruction = new Label(UIStrings.getChatPanelInstruction());
        instruction.setStyleName("chat-instruction");
        instructionPanel.add(instruction);
        //instructionPanel.setCellWidth(instruction,"100%");
        instructionPanel.setCellHorizontalAlignment(instruction, HorizontalPanel.ALIGN_LEFT);
        instructionPanel.setCellVerticalAlignment(instruction, VerticalPanel.ALIGN_MIDDLE);
    }

    Label emoticon = new Label(UIStrings.getChatPanelEmoticonInstruction());
    emoticon.setStyleName("chat-emoticon-lable");
    instructionPanel.add(emoticon);
    //instructionPanel.setCellWidth(emoticon,"30%");
    instructionPanel.setCellHorizontalAlignment(emoticon, HorizontalPanel.ALIGN_RIGHT);
    instructionPanel.setCellVerticalAlignment(emoticon, VerticalPanel.ALIGN_MIDDLE);

    //   Add the text area that the users will type their messages in.

    sendText = new TextArea();
    sendText.setText("");
    if (null == toId) {
        sendText.setText(UIStrings.getChatPanelInstruction());
        sendText.setStyleName("chat-instruction");
    }
    //if (ConferenceGlobals.isBrowserIE())
    //{
    sendText.setVisibleLines(2);
    //}
    //else
    //{
    //   sendText.setVisibleLines(1);
    //}
    sendText.setStyleName("chat-text-area");

    keyboardListener = new KeyboardListenerAdapter() {
        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
        }

        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KeyboardListener.KEY_ENTER) {
                sendChatMessage();
            }
        }
    };
    sendText.addKeyboardListener(keyboardListener);
    sendText.addFocusListener(this);

    //   Assemble the overall chat panel.

    initWidget(pane);
    pane.setWidth("100%");
    pane.add(outer);
    outer.setWidth("100%");

    outer.add(scrollPanel);
    scrollPanel.addStyleName("dm-chat-message-area-pane");

    outer.add(this.instructionPanel);
    outer.setCellWidth(this.instructionPanel, "100%");
    outer.setCellHorizontalAlignment(this.instructionPanel, HorizontalPanel.ALIGN_LEFT);

    outer.add(this.sendText);
    outer.setCellWidth(this.sendText, "100%");
    outer.setCellHorizontalAlignment(this.sendText, HorizontalPanel.ALIGN_CENTER);
    this.sendText.setStyleName("dm-chat-text-area");

    this.rosterModel = ClientModel.getClientModel().getRosterModel();

    //      Window.alert("created popup..");
    //setting up emoticons popup panel
    ePopUP = new EmoticonsPopup(sendText);
    emoticon.addMouseListener(new MouseListenerAdapter() {
        public void onMouseEnter(Widget sender) {
            int left = sender.getAbsoluteLeft() - 5;
            int top = sender.getAbsoluteTop() - 75;
            ePopUP.setPopupPosition(left, top);
            ePopUP.showHoverPopup();
            ePopUP.popupVisible();
        }
    });

    if (emoticonsMap == null) {
        emoticonsMap = new HashMap();
        prepareEmoticonsList();
        //         this is to handle :) and :( also         
    }
}

From source file:com.dimdim.conference.ui.dialogues.client.InvitationPreviewDialog.java

License:Open Source License

protected Widget getContent() {
    basePanel = new VerticalPanel();
    presenters = new TextArea();
    attendees = new TextArea();
    message = new TextArea();

    //      basePanel.setStyleName("send-invitation-preview-box");
    //      Window.alert("3");

    //      HTML presentersComment = new HTML(UIGlobals.getInvitePresentersComment());
    //      basePanel.add(presentersComment);
    //      basePanel.setCellWidth(presentersComment,"100%");
    //      presentersComment.setStyleName("invitations-preview-comment");
    //      basePanel.add(presenters);
    //      basePanel.setCellWidth(presenters,"100%");
    //      presenters.setStyleName("invitations-preview-textarea");

    HTML line1 = new HTML("&nbsp;");
    line1.setStyleName("line-break");
    basePanel.add(line1);//from  w w  w. j av  a 2s.  c  o m

    //      Window.alert("4");
    HTML attendeesComment = new HTML(UIGlobals.getInviteAttendeesComment());
    basePanel.add(attendeesComment);
    basePanel.setCellWidth(attendeesComment, "100%");
    attendeesComment.setStyleName("invitations-preview-comment");
    basePanel.add(attendees);
    basePanel.setCellWidth(attendees, "100%");
    attendees.setStyleName("invitations-preview-textarea");

    HTML line2 = new HTML("&nbsp;");
    line2.setStyleName("line-break");
    basePanel.add(line2);

    //      Window.alert("5");
    HTML messageComment = new HTML(UIGlobals.getAddPersonalMessageComment());
    basePanel.add(messageComment);
    basePanel.setCellWidth(messageComment, "100%");
    messageComment.setStyleName("invitations-preview-comment");
    basePanel.add(message);
    message.setVisibleLines(4);
    message.setText(UIGlobals.getDefaultInvitationPersonalMessage());
    basePanel.setCellWidth(message, "100%");
    message.setStyleName("invitations-preview-textarea");

    HTML line3 = new HTML("&nbsp;");
    line3.setStyleName("line-break");
    basePanel.add(line3);

    attendees.setTabIndex(1);
    message.setTabIndex(2);
    //      Window.alert("6");
    if (this.currentAttendees != null) {
        this.attendees.setText(this.currentAttendees);
    }
    if (this.currentPresenters != null) {
        this.presenters.setText(this.currentPresenters);
    }

    errorMessageLabel = new Label(UIStrings.getValidEmailRquired());
    errorMessageLabel.setStyleName("email-error-message");
    errorMessageLabel.setWordWrap(true);
    errorMessageLabel.setVisible(false);
    this.basePanel.add(errorMessageLabel);
    this.basePanel.setCellVerticalAlignment(errorMessageLabel, VerticalPanel.ALIGN_BOTTOM);

    //      RoundedPanel rp = new RoundedPanel(basePanel);
    //      rp.setStyleName("send-invitation-preview-rounded-corner-box");

    //      Window.alert("7");

    attendees.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyDown(Widget arg0, char arg1, int arg2) {
            errorMessageLabel.setVisible(false);
        }
    });

    return basePanel;
}

From source file:com.dimdim.conference.ui.resources.client.EnterURLDialog.java

License:Open Source License

protected Widget getContent() {
    VerticalPanel contentPanel = new VerticalPanel();
    //      contentPanel.setStyleName("enter-url-content-panel");

    Label comment1 = new Label(UIStrings.getEnterURLLabel());
    comment1.addStyleName("common-text");
    contentPanel.add(comment1);/* www.j a  va2s  .c om*/

    this.url.setStyleName("common-text");
    this.url.addStyleName("enter-url-field");
    contentPanel.add(this.url);
    url.setFocus(true);
    KeyboardListenerAdapter keyboardListener = new KeyboardListenerAdapter() {
        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
        }

        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KeyboardListener.KEY_ENTER) {
                onClick(applyButton);
            }
        }
    };
    url.addKeyboardListener(keyboardListener);
    return contentPanel;
}

From source file:com.ephesoft.dcma.gwt.rv.client.view.ValidatePanel.java

License:Open Source License

public ValidatePanel() {
    super();/*from  w  ww . j  a v  a2 s. co  m*/
    initWidget(BINDER.createAndBindUi(this));
    scrollPanel.addStyleName(ReviewValidateConstants.OVERFLOW_SCROLL);
    scrollValidationTableFocusPanel.add(validationTable);
    scrollValidationTableFocusPanel.setHeight("98%");
    scrollValidationTableFocusPanel.setWidth("99%");
    scrollPanel.setHeight("100%");
    scrollPanel.add(scrollValidationTableFocusPanel);
    fuzzySearchBtn = new Button();
    showTableViewBtn = new Button();
    showTableViewBtn.setStyleName("tableViewButton");
    showTableViewBtn.setTitle(
            LocaleDictionary.get().getConstantValue(ReviewValidateConstants.TITLE_TABLE_VIEW_TOOLTIP));
    fuzzySearchText = new TextBox();
    fuzzySearchBtn
            .setText(LocaleDictionary.get().getConstantValue(ReviewValidateConstants.FUZZY_SEARCH_GO_BTN));
    fuzzySearchBtn
            .setTitle(LocaleDictionary.get().getConstantValue(ReviewValidateConstants.FUZZY_SEARCH_TOOLTIP));
    fuzzySearchBtn.setStyleName("fuzzySearchButton");

    fuzzySearchTextBox = new ValidatableWidget<TextBox>(fuzzySearchText);
    fuzzySearchTextBox.getWidget().addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            fuzzySearchTextBox.toggleValidDateBox();
            fuzzySearchTextBox.getWidget().addStyleName("validatePanelListBox");
        }
    });
    // fuzzySearchTextBox.addValidator(new EmptyStringValidator(fuzzySearchText));
    fuzzySearchTextBox.getWidget().addStyleName("validatePanelListBox");
    fuzzySearchText.addKeyboardListener(new KeyboardListenerAdapter() {

        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            if (keyCode == (char) KEY_ENTER) {
                fuzzySearchBtn.click();
            }
        }
    });

    showTableViewBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent arg0) {
            presenter.setTableView(Boolean.TRUE);
            presenter.onTableViewButtonClicked();
        }
    });

    fuzzySearchBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            ScreenMaskUtility.maskScreen();
            String value = fuzzySearchText.getValue();
            if (null == value || value.trim().isEmpty()) {
                final ConfirmationDialog confirmationDialog = ConfirmationDialogUtil.showConfirmationDialog(
                        LocaleDictionary.get()
                                .getMessageValue(ReviewValidateMessages.MSG_FUZZY_SEARCH_INVALID_ENTRY),
                        LocaleDictionary.get().getConstantValue(ReviewValidateConstants.FUZZY_SEARCH_TOOLTIP),
                        Boolean.TRUE);
                confirmationDialog.addDialogListener(new DialogListener() {

                    @Override
                    public void onOkClick() {
                        confirmationDialog.hide();
                        ScreenMaskUtility.unmaskScreen();
                        presenter.setFocus();
                    }

                    @Override
                    public void onCancelClick() {
                        ScreenMaskUtility.unmaskScreen();
                        presenter.setFocus();
                    }
                });

            } else {
                performFuzzySearch(value);
            }
            fuzzySearchText.setText("");
        }
    });

}

From source file:com.google.gwt.gears.sample.database.client.DatabaseDemo.java

License:Apache License

public void onModuleLoad() {
    VerticalPanel outerPanel = new VerticalPanel();
    outerPanel.setSpacing(10);/*w w w.j a va  2 s .  c om*/
    outerPanel.getElement().getStyle().setPropertyPx("margin", 15);

    HorizontalPanel textAndButtonsPanel = new HorizontalPanel();
    textAndButtonsPanel.add(new Label("Enter a Phrase: "));
    textAndButtonsPanel.add(input);
    textAndButtonsPanel.add(addButton);
    textAndButtonsPanel.add(clearButton);
    outerPanel.add(textAndButtonsPanel);
    outerPanel.add(new Label("Last 3 Entries:"));
    outerPanel.add(dataTable);

    for (int i = 0; i <= NUM_SAVED_ROWS; ++i) {
        dataTable.insertRow(i);
        for (int j = 0; j < NUM_DATA_TABLE_COLUMNS; j++) {
            dataTable.addCell(i);
        }
    }
    dataTable.setWidget(0, 0, new HTML("<b>Id</b>"));
    dataTable.setWidget(0, 1, new HTML("<b>Phrase</b>"));
    dataTable.setWidget(0, 2, new HTML("<b>Timestamp</b>"));

    // Create the database if it doesn't exist.
    try {
        db = Factory.getInstance().createDatabase();
        db.open("database-demo");
        db.execute(
                "CREATE TABLE IF NOT EXISTS Phrases (Id INTEGER PRIMARY KEY AUTOINCREMENT, Phrase VARCHAR(255), Timestamp INTEGER)");
    } catch (DatabaseException e) {
        RootPanel.get("demo").add(new HTML(
                "Error opening or creating database: <font color=\"red\">" + e.toString() + "</font>"));
        // Fatal error.  Do not build the interface.
        return;
    }

    input.addKeyboardListener(new KeyboardListenerAdapter() {
        @Override
        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KeyboardListener.KEY_ENTER) {
                insertPhrase();
            }
        }
    });

    addButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            insertPhrase();
        }
    });

    clearButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            clearPhrases();
            displayRecentPhrases();
        }
    });

    RootPanel.get("demo").add(outerPanel);
    displayRecentPhrases();
}

From source file:com.google.gwt.gears.sample.gwtnote.client.ui.RichTextWidget.java

License:Apache License

/**
 * Creates a new widget. This class needs access to certain fields and methods
 * on the application enclosing it./* w  ww  . j  a  v  a2  s  . c o  m*/
 * 
 * @param parent the host application
 */
public RichTextWidget(final GWTNote parent) {
    super();

    VerticalPanel top = new VerticalPanel();
    top.setWidth("100%");
    HorizontalPanel header = new HorizontalPanel();
    top.add(header);
    header.setWidth("100%");

    header.add(new Label("GWT GearsNote"));

    header.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    status = new Label("Ready");
    header.add(status);

    this.bodyWidget = new RichTextArea();
    bodyWidget.addKeyboardListener(new KeyboardListenerAdapter() {
        @Override
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            String newText = bodyWidget.getText();
            if (((newText == null) && (curText != null)) || ((newText != null) && !newText.equals(curText))) {
                curText = newText;
            }
        }
    });

    HorizontalPanel controls = new HorizontalPanel();
    RichTextToolbar tb = new RichTextToolbar(this.bodyWidget);
    name = new TextBox();
    name.setText("default");
    name.setEnabled(false);
    nameEdit = new PushButton("Edit");
    nameEdit.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            String curName = name.getText();
            boolean doNotify = !oldName.equals(curName);
            if (!nameEditable) { // if becoming editable, store off current value
                oldName = curName;
            }
            if (nameEditable && (curName == null || "".equals(curName))) {
                // if becoming un-editable, check to make sure it's valid
                Window.alert("The note name cannot be blank. Please try again.");
                nameEdit.setText(oldName);
                return;
            }
            // if all else is good, just flip the state
            nameEditable = !nameEditable;
            name.setEnabled(nameEditable);
            nameEdit.getUpFace().setText((nameEditable ? "Confirm" : "Edit"));
            if (doNotify) {
                notifyNameListeners();
            }
        }
    });
    nameEdit.addStyleName("edit-button");

    options = new ListBox();
    controls.add(tb);
    options.addItem("default");
    options.setSelectedIndex(0);
    options.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            String newName = options.getItemText(options.getSelectedIndex());
            name.setText(newName);
            notifyNameListeners();
        }
    });
    HorizontalPanel tmp = new HorizontalPanel();
    tmp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    tmp.add(new Label("Note name:"));
    tmp.add(name);
    tmp.add(nameEdit);
    tmp.add(options);
    controls.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    controls.setWidth("100%");
    controls.add(tmp);
    top.add(controls);

    top.add(bodyWidget);
    this.bodyWidget.setWidth("100%");
    top.setCellHeight(bodyWidget, ((int) (Window.getClientHeight() * .75)) + "px");
    this.bodyWidget.setHeight("100%");

    initWidget(top);
}

From source file:com.google.gwt.sample.hellomaps.client.HelloMaps.java

License:Apache License

private void createMap() {
    // Set the map up in a Dialog box, just for fun.
    final DialogBox dialog = new DialogBox(false, false);
    final Map theMap = new Map();
    final Button findButton = new Button("Address:");
    final TextBox tb = new TextBox();
    tb.addKeyboardListener(new KeyboardListenerAdapter() {
        @Override/* ww  w . j  av a  2s  . c  o m*/
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KEY_ENTER) {
                theMap.setLocation(((TextBox) sender).getText());
            } else if (keyCode == KEY_ESCAPE) {
                dialog.removeFromParent();
            }
        }
    });
    findButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            theMap.setLocation(tb.getText());
        }
    });
    tb.setWidth("100%");

    final HorizontalPanel hp = new HorizontalPanel();
    hp.add(findButton);
    hp.setCellWidth(findButton, "15%");
    hp.add(tb);
    hp.setCellWidth(tb, "85%");

    final VerticalPanel vp = new VerticalPanel();
    vp.add(hp);
    vp.add(theMap);

    dialog.setText("Drag me!");
    dialog.setWidget(vp);
    dialog.center();
}