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

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

Introduction

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

Prototype

public Label() 

Source Link

Document

Creates an empty label.

Usage

From source file:com.codenvy.example.gwt.client.GWTEntryPoint.java

License:Open Source License

/**
 * This is the entry point method./*from  w  w  w  .ja v a 2s. c o  m*/
 */
public void onModuleLoad() {
    final Button sendButton = new Button(messages.sendButton());
    final TextBox nameField = new TextBox();
    nameField.setText(messages.nameField());
    final Label errorLabel = new Label();

    // We can add style names to widgets
    sendButton.addStyleName("sendButton");

    // Add the nameField and sendButton to the RootPanel
    // Use RootPanel.get() to get the entire body element
    RootPanel.get("nameFieldContainer").add(nameField);
    RootPanel.get("sendButtonContainer").add(sendButton);
    RootPanel.get("errorLabelContainer").add(errorLabel);

    // Focus the cursor on the name field when the app loads
    nameField.setFocus(true);
    nameField.selectAll();

    // Create the popup dialog box
    final DialogBox dialogBox = new DialogBox();
    dialogBox.setText("Remote Procedure Call");
    dialogBox.setAnimationEnabled(true);
    final Button closeButton = new Button("Close");
    // We can set the id of a widget by accessing its Element
    closeButton.getElement().setId("closeButton");
    final Label textToServerLabel = new Label();
    final HTML serverResponseLabel = new HTML();
    VerticalPanel dialogVPanel = new VerticalPanel();
    dialogVPanel.addStyleName("dialogVPanel");
    dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
    dialogVPanel.add(textToServerLabel);
    dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
    dialogVPanel.add(serverResponseLabel);
    dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    dialogVPanel.add(closeButton);
    dialogBox.setWidget(dialogVPanel);

    // Add a handler to close the DialogBox
    closeButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            sendButton.setEnabled(true);
            sendButton.setFocus(true);
        }
    });

    // Create a handler for the sendButton and nameField
    class MyHandler implements ClickHandler, KeyUpHandler {
        /**
         * Fired when the user clicks on the sendButton.
         */
        public void onClick(ClickEvent event) {
            sendNameToServer();
        }

        /**
         * Fired when the user types in the nameField.
         */
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                sendNameToServer();
            }
        }

        /**
         * Send the name from the nameField to the server and wait for a response.
         */
        private void sendNameToServer() {
            // First, we validate the input.
            errorLabel.setText("");
            String textToServer = nameField.getText();
            if (!FieldVerifier.isValidName(textToServer)) {
                errorLabel.setText("Please enter at least four characters");
                return;
            }

            // Then, we send the input to the server.
            sendButton.setEnabled(false);
            textToServerLabel.setText(textToServer);
            serverResponseLabel.setText("");
            greetingService.greetServer(textToServer, new AsyncCallback<String>() {
                public void onFailure(Throwable caught) {
                    // Show the RPC error message to the user
                    dialogBox.setText("Remote Procedure Call - Failure");
                    serverResponseLabel.addStyleName("serverResponseLabelError");
                    serverResponseLabel.setHTML(SERVER_ERROR);
                    dialogBox.center();
                    closeButton.setFocus(true);
                }

                public void onSuccess(String result) {
                    dialogBox.setText("Remote Procedure Call");
                    serverResponseLabel.removeStyleName("serverResponseLabelError");
                    serverResponseLabel.setHTML(result);
                    dialogBox.center();
                    closeButton.setFocus(true);
                }
            });
        }
    }

    // Add a handler to send the name to the server
    MyHandler handler = new MyHandler();
    sendButton.addClickHandler(handler);
    nameField.addKeyUpHandler(handler);
}

From source file:com.codenvy.ide.client.elements.widgets.element.ElementViewImpl.java

License:Open Source License

@Nonnull
private Label createTitle() {
    Label title = new Label();

    title.addStyleName(editorCSS.fontStyle());
    title.addStyleName(editorCSS.titleBold());
    title.addStyleName(editorCSS.textAlign());

    return title;
}

From source file:com.connoisseur.menuapp.client.Authenticate.java

/** This is essentially the main method for the menu app. */
public static void go() {
    storage.clear(); // uncomment to completely reset app

    final DialogBox startupBox = new DialogBox(); // movable box that contains widgets
    startupBox.setAnimationEnabled(true);
    final VerticalPanel startupPanel = new VerticalPanel(); // can contain other widgets
    startupPanel.addStyleName("marginPanel"); // interacts with Menuapp.css
    startupPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);

    // check to see if storage is supported
    if (storage != null) {

        // load viewer if license key and restID have been submitted before
        if (storage.getLength() > 0) {
            Viewer.loadViewer();//www .  j  av  a  2 s  . com
        }

        // otherwise load authentication UI in order to receive input
        else {
            final Button submitButton = new Button("Submit"); // "Submit" appears on button
            submitButton.addStyleName("myButton"); // interacts with Menuapp.css
            final HorizontalPanel buttonPanel = new HorizontalPanel(); // used to center button
            buttonPanel.addStyleName("marginlessPanel");

            // license widgets
            final Label licenseErrorLabel = new Label(); // dynamic text
            licenseErrorLabel.addStyleName("errorLabel"); // interacts with Menuapp.css
            final TextBox submitLicense = new TextBox(); // user can input text using this
            submitLicense.setText("license key..."); // default text to be seen on load

            // restaurant ID widgets
            final Label restErrorLabel = new Label();
            restErrorLabel.addStyleName("errorLabel");
            final TextBox submitRestID = new TextBox();
            submitRestID.setText("restaurant ID...");

            // organize UI
            startupPanel.add(new HTML("Please enter your license key:"));
            startupPanel.add(submitLicense);
            startupPanel.add(licenseErrorLabel);
            startupPanel.add(new HTML("<br>Please enter your restaurant ID:"));
            startupPanel.add(submitRestID);
            startupPanel.add(restErrorLabel);
            startupPanel.add(new HTML("<br>"));
            buttonPanel.add(submitButton);
            startupPanel.add(buttonPanel);

            // setup startupBox, which is what will be seen by the user
            startupBox.setWidget(startupPanel); // connects the two widgets
            startupBox.center(); // also shows the box

            // focus the cursor on submitLicense when startupBox appears
            submitLicense.setFocus(true);
            submitLicense.selectAll();

            // create a handler for submitButton, submitLicense and submitRestID
            class MyHandler implements ClickHandler, KeyUpHandler {
                /** Fired when the user clicks submit. */
                public void onClick(ClickEvent event) {
                    submit();
                }

                /** Fired when the user presses Enter in a submit field. */
                public void onKeyUp(KeyUpEvent event) {
                    if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)
                        submit();
                }

                /** Checks the submitted license key and restaurant ID for validity. Loads Viewer if valid. */
                private void submit() {
                    String license = submitLicense.getText(); // unused for now
                    String restID = submitRestID.getText(); // not sure how to validate yet
                    int returnFlag = 0; // so that both tests can be done
                    licenseErrorLabel.setText("");
                    restErrorLabel.setText("");

                    // validate license
                    String result = FieldVerifier.isValidLicenseKey(license); // from FieldVerifier.java
                    if (!result.equals("")) { // error
                        licenseErrorLabel.setText("You submitted an invalid license key.");
                        submitLicense.selectAll();
                        returnFlag = 1;
                    }

                    // validate restID
                    result = FieldVerifier.isValidRestaurantID(restID);
                    if (!result.equals("")) { // error
                        restErrorLabel.setText("You submitted an invalid restaurant ID.");
                        submitRestID.selectAll();
                        returnFlag = 1;
                    }

                    // don't do anything until the errors are resolved
                    if (returnFlag == 1)
                        return;

                    // clean up
                    submitButton.setEnabled(false);
                    submitLicense.setEnabled(false);
                    submitRestID.setEnabled(false);
                    startupBox.hide();

                    // set up storage
                    storage.setItem("license", license); // secret key for security
                    storage.setItem("restID", restID); // used for almost every call to the backend

                    // show menu
                    Viewer.loadViewer();
                }
            } // MyHandler

            // attach the handler
            final MyHandler handler = new MyHandler();
            submitButton.addClickHandler(handler);
            submitLicense.addKeyUpHandler(handler);
            submitRestID.addKeyUpHandler(handler);
        } // else load authentication UI

    } // if storage supported

    // storage is not supported, so report error
    else {
        startupPanel.add(new HTML("<font color=red>The app will not function because local<br>"
                + "storage is not supported on this platform.</font>"));
        startupBox.setWidget(startupPanel);
        startupBox.center();
    }
}

From source file:com.databasepreservation.visualization.client.common.search.Dropdown.java

public Dropdown() {
    focusPanel = new FocusPanel();
    panel = new SimplePanel();
    selectedLabel = new Label();
    popup = new PopupPanel(true);
    popupPanel = new VerticalPanel();
    popupValues = new HashMap<String, String>();

    panel.add(selectedLabel);/*from   ww w. jav a 2s  . c  o  m*/
    focusPanel.add(panel);

    focusPanel.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            popup();
        }
    });

    popup.addCloseHandler(new CloseHandler<PopupPanel>() {

        @Override
        public void onClose(CloseEvent<PopupPanel> event) {
            panel.removeStyleName("open");
        }
    });

    initWidget(focusPanel);

    focusPanel.addStyleName("dropdown");
    panel.addStyleName("dropdown-panel");
    selectedLabel.addStyleName("dropdown-label");
    popup.addStyleName("dropdown-popup");
}

From source file:com.databasepreservation.visualization.client.common.search.SearchFieldPanel.java

public SearchFieldPanel() {
    panel = new FlowPanel();
    leftPanel = new FlowPanel();
    inputPanel = new FlowPanel();
    fieldLabel = new Label();
    searchAdvancedFields = new ListBox();
    columnVisibility = new CheckBox();

    setVisibilityCheckboxValue(true, false);

    columnVisibilityPanel = new SimplePanel(columnVisibility);

    DateBox.DefaultFormat dateFormat = new DateBox.DefaultFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));

    inputText = new TextBox();

    inputDateFromForDate = new UTCDateBox();
    inputDateFromForDate.getDateBox().setFormat(dateFormat);
    inputDateFromForDate.getDateBox().getDatePicker().setYearArrowsVisible(true);
    inputDateFromForDate.getDateBox().setFireNullValues(true);
    inputDateFromForDate.getElement().setPropertyString("placeholder",
            messages.searchFieldDateFromPlaceHolder());

    inputDateToForDate = new UTCDateBox();
    inputDateToForDate.getDateBox().setFormat(dateFormat);
    inputDateToForDate.getDateBox().getDatePicker().setYearArrowsVisible(true);
    inputDateToForDate.getDateBox().setFireNullValues(true);
    inputDateToForDate.getElement().setPropertyString("placeholder", messages.searchFieldDateToPlaceHolder());

    inputDateFromForDateTime = new UTCDateBox();
    inputDateFromForDateTime.getDateBox().setFormat(dateFormat);
    inputDateFromForDateTime.getDateBox().getDatePicker().setYearArrowsVisible(true);
    inputDateFromForDateTime.getDateBox().setFireNullValues(true);
    inputDateFromForDateTime.getElement().setPropertyString("placeholder",
            messages.searchFieldDateFromPlaceHolder());

    inputTimeFromForDateTime = new UTCTimeBox(timeFormat);
    inputTimeFromForDateTime.getElement().setPropertyString("placeholder",
            messages.searchFieldTimeFromPlaceHolder());

    inputDateToForDateTime = new UTCDateBox();
    inputDateToForDateTime.getDateBox().setFormat(dateFormat);
    inputDateToForDateTime.getDateBox().getDatePicker().setYearArrowsVisible(true);
    inputDateToForDateTime.getDateBox().setFireNullValues(true);
    inputDateToForDateTime.getElement().setPropertyString("placeholder",
            messages.searchFieldDateToPlaceHolder());

    inputTimeToForDateTime = new UTCTimeBox(timeFormat);
    inputTimeToForDateTime.getElement().setPropertyString("placeholder",
            messages.searchFieldTimeToPlaceHolder());

    inputTimeFromForTime = new UTCTimeBox(timeFormat);
    inputTimeFromForTime.getElement().setPropertyString("placeholder",
            messages.searchFieldTimeFromPlaceHolder());

    inputTimeToForTime = new UTCTimeBox(timeFormat);
    inputTimeToForTime.getElement().setPropertyString("placeholder", messages.searchFieldTimeToPlaceHolder());

    inputNumeric = new TextBox();
    inputNumeric.getElement().setPropertyString("placeholder", messages.searchFieldNumericPlaceHolder());
    inputNumeric.getElement().setAttribute("type", "number");
    inputNumericFrom = new TextBox();
    inputNumericFrom.getElement().setPropertyString("placeholder",
            messages.searchFieldNumericFromPlaceHolder());
    inputNumericFrom.getElement().setAttribute("type", "number");
    inputNumericTo = new TextBox();
    inputNumericTo.getElement().setPropertyString("placeholder", messages.searchFieldNumericToPlaceHolder());
    inputNumericTo.getElement().setAttribute("type", "number");

    inputStorageSizeFrom = new TextBox();
    inputStorageSizeFrom.getElement().setPropertyString("placeholder",
            messages.searchFieldNumericFromPlaceHolder());
    inputStorageSizeFrom.getElement().setAttribute("type", "number");
    inputStorageSizeTo = new TextBox();
    inputStorageSizeTo.getElement().setPropertyString("placeholder",
            messages.searchFieldNumericToPlaceHolder());
    inputStorageSizeTo.getElement().setAttribute("type", "number");
    inputStorageSizeList = new ListBox();
    for (String unit : Humanize.UNITS) {
        inputStorageSizeList.addItem(unit, unit);
    }// w w w.j a  va 2s. c  o  m

    inputCheckBox = new CheckBox();

    labelTo = new Label("to");
    labelAt1 = new Label("at");
    labelAt2 = new Label("at");

    panel.add(leftPanel);

    initWidget(panel);

    searchAdvancedFields.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            listBoxSearchField(searchAdvancedFields.getSelectedValue());

            // handle checkbox
            String columnDisplayName = getSearchField().getLabel();
            if (columnDisplayNameToVisibleState.containsKey(columnDisplayName)) {
                columnVisibility.setValue(columnDisplayNameToVisibleState.get(columnDisplayName), false);
            } else {
                columnVisibility.setValue(true, false);
            }
        }
    });

    panel.addStyleName("search-field");
    leftPanel.addStyleName("search-field-left-panel");
    inputPanel.addStyleName("search-field-input-panel");
    inputPanel.addStyleName("full_width");
    remove.addStyleName("search-field-remove");
    fieldLabel.addStyleName("search-field-label");
    searchAdvancedFields.addStyleName("form-listbox");
    // columnVisibilityPanel.setStyleName("form-listbox search-field-input-panel");
    columnVisibility.setStyleName("visibility-checkbox");

    labelTo.addStyleName("label");
    labelAt1.addStyleName("label");
    labelAt2.addStyleName("label");
    inputText.addStyleName("form-textbox");
    inputDateFromForDate.addStyleName("form-textbox form-textbox-small");
    inputDateToForDate.addStyleName("form-textbox form-textbox-small");
    inputDateFromForDateTime.addStyleName("form-textbox form-textbox-small");
    inputDateToForDateTime.addStyleName("form-textbox form-textbox-small");
    inputTimeFromForDateTime.addStyleName("form-textbox form-textbox-small");
    inputTimeToForDateTime.addStyleName("form-textbox form-textbox-small");
    inputTimeFromForTime.addStyleName("form-textbox form-textbox-small");
    inputTimeToForTime.addStyleName("form-textbox form-textbox-small");
    inputNumeric.addStyleName("form-textbox form-textbox-small");
    inputNumericFrom.addStyleName("form-textbox form-textbox-small");
    inputNumericTo.addStyleName("form-textbox form-textbox-small");
    inputStorageSizeFrom.addStyleName("form-textbox form-textbox-small");
    inputStorageSizeTo.addStyleName("form-textbox form-textbox-small");
    inputStorageSizeList.addStyleName("form-listbox");
    inputCheckBox.addStyleName("form-checkbox");
}