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

protected Label(Element element) 

Source Link

Document

This constructor may be used by subclasses to explicitly use an existing element.

Usage

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

License:Apache License

public AlertDialog(String caption, String message) {
    super(false, true);
    setText(caption);/*from ww w.  j av  a  2  s .  co  m*/

    VerticalPanel mainP = new VerticalPanel();
    mainP.add(new Label(message));
    HorizontalPanel buttonP = new HorizontalPanel();

    Button okB = new Button("Ok");
    okB.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            hide();
        }
    });

    buttonP.add(okB);
    mainP.add(buttonP);
    setWidget(mainP);
}

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.
 * // w ww.  j  a v a  2 s .c o m
 * @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.ext.YesNoDialog.java

License:Apache License

public YesNoDialog(String caption, String question, final Command onYes, final Command onNo, String noText,
        String yesText) {/*from  w  w w .j a va2  s . co  m*/
    super(false, true);
    setText(caption);
    VerticalPanel mainP = new VerticalPanel();
    mainP.add(new Label(question));
    HorizontalPanel buttonP = new HorizontalPanel();

    Button yesB = new Button(yesText);
    yesB.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            onYes.execute();
            hide();
        }
    });
    Button noB = new Button(noText);
    noB.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            onNo.execute();
            hide();
        }
    });
    buttonP.add(noB);
    buttonP.add(yesB);
    mainP.add(buttonP);
    setWidget(mainP);
}

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

License:Apache License

private void setupForm() {
    form = new FormPanel();

    form.setAction(Interactive.getRelativeURL(SECURITY_URL));

    form.setMethod(FormPanel.METHOD_POST);

    // Create a panel to hold all of the form widgets.

    VerticalPanel panel = new VerticalPanel();

    DecoratedTabPanel tabs = new DecoratedTabPanel();
    tabs.add(getOpenIDTab(), "OpenID");
    tabs.add(getUPTab(), "Username/Password");
    tabs.selectTab(1);/* w ww . j a  v a  2s . com*/

    panel.add(tabs);

    messageLabel = new Label("");
    panel.add(messageLabel);

    form.addFormHandler(new FormHandler() {

        // note, this doesn't need to be perfectly secure. We just
        // want to know that we think we're secure. The next request
        // will tell us for sure
        public void onSubmitComplete(FormSubmitCompleteEvent event) {

            Log.debug("submit event results " + event.getResults());
            if (event.getResults().equals("OK")) {
                success();
            } else {
                Log.warn("Login Fail: " + event.getResults());
                failure();
            }

            // // TODO parse bad password etc. Super-Fragile string
            // comps
            // if (event.getResults() == null
            // || -1 != event.getResults().indexOf(
            // "not successful")
            // || -1 != event.getResults().indexOf(
            // "Bad credentials")
            // || -1 != event.getResults().indexOf("404")) {
            // Log.warn("Login Fail: " + event.getResults());
            // failure();
            // } else {
            // Log.info("Login Success");
            // Log.debug(event.getResults());
            // success();
            // }

        }

        public void onSubmit(FormSubmitEvent event) {
            Log.debug("submit to " + form.getAction());

            // This event is fired just before the form is submitted.
            // We can take
            // this opportunity to perform validation.
            // if (username.getText().length() == 0) {
            // AlertDialog.alert("Username cannot be empty");
            // event.setCancelled(true);
            // }
            // if (password.getText().length() == 0) {
            // AlertDialog.alert("Password cannot be empty");
            // event.setCancelled(true);
            // }
            lastNameEntered = username.getText();
        }
    });

    form.setWidget(panel);

}

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);/*from  w w  w  . jav a 2s .com*/

    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.college.gui.MyApplications.java

License:Apache License

public MyApplications(ServiceCache serviceCache) {

    this.serviceCache = serviceCache;

    mainP = new SimplePanel();
    mainP.add(new Label("Loading"));

    initWidget(mainP);/*from   w w  w .j  a  v a2s . co m*/

}

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

License:Apache License

public void load(User user) {

    List<ProcessType> processTypes = user.getNonStatusProcessTypes();

    List<Application> applications = user.getSchoolRankings();

    mainGrid = new Grid(applications.size() + 1, processTypes.size() + 2);

    int row = 0;//from   www  .  ja va 2  s . co m
    int col = 1;

    mainGrid.setWidget(0, col, new Label("Status"));
    col++;

    for (ProcessType processType : user.getNonStatusProcessTypes()) {
        mainGrid.setWidget(0, col, new VerticalLabel(processType.getName()));
        col++;
    }
    // doWorkerPoolDemo();

    row++;

    DeferredCommand.addCommand(new AddApplicationRows(applications, user, row));

    mainP.setWidget(mainGrid);
}

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

License:Apache License

public ProConDispPanel(String string, List<String> list, CollegeEntry collegeEntry) {
    this.collegeEntry = collegeEntry;
    mainPanel = new VerticalPanel();
    mainPanel.add(new Label(string));
    for (String str : list) {
        addRow(str);/*from  w  ww .  ja  va 2  s.c o m*/
    }

    mainPanel.setStylePrimaryName("ProConPanel");
    mainPanel.addStyleDependentName(string);

    HorizontalPanel addP = new HorizontalPanel();
    addTextBox = new TextBox();
    Button addB = new Button("Add");
    addB.addClickListener(this);
    addP.add(addTextBox);
    addP.add(addB);
    mainPanel.add(addP);

    initWidget(mainPanel);

}

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

License:Apache License

public SchoolRanks() {
    VerticalPanel mainPanel = new VerticalPanel();
    mainPanel.add(new Label("Rankings"));

    rankPanel = new VerticalPanel();

    mainPanel.add(rankPanel);/*from  ww  w .  ja v  a 2 s.  c  om*/

    initWidget(mainPanel);
}

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

License:Apache License

public void load(User user) {
    thisUser = user;//from ww  w.  j  a  v a  2  s.  c o m
    rankPanel.clear();
    int i = 1;
    for (ApplicationAndScore aas : thisUser.getPrioritizedRankings()) {

        double pct = aas.getScore() / (double) aas.getTotal();

        SchoolLink link = new SchoolLink(aas.getApplication().getSchool());

        Label pctL = new Label(pctFormat.format(pct));

        HorizontalPanel hP = new HorizontalPanel();
        hP.setStyleName("TC-DecisionRanked");
        if (i % 2 == 0) {
            hP.addStyleName("TC-DecisionRanked-Even");
        }

        Label rankL = new Label(i + "");
        rankL.addStyleName("TC-DecisionRanked-Rank");
        pctL.addStyleName("TC-DecisionRanked-Pct");

        hP.add(rankL);
        hP.add(link);
        hP.add(pctL);

        rankPanel.add(hP);
        i++;
    }
}