FileDocCategorySizeDatePackage
Text.javaAPI DocExample4500Mon Aug 27 20:12:26 BST 2007com.google.gwt.sample.kitchensink.client

Text

public class Text extends Sink
Demonstrates the various text widgets.

Fields Summary
private com.google.gwt.user.client.ui.PasswordTextBox
passwordText
private com.google.gwt.user.client.ui.TextArea
textArea
private com.google.gwt.user.client.ui.TextBox
textBox
Constructors Summary
public Text()


    
    TextBox readOnlyTextBox = new TextBox();
    readOnlyTextBox.setReadOnly(true);
    readOnlyTextBox.setText("read only");

    VerticalPanel vp = new VerticalPanel();
    vp.setSpacing(8);
    vp.add(new HTML("Normal text box:"));
    vp.add(createTextThing(textBox, true));
    vp.add(createTextThing(readOnlyTextBox, false));
    vp.add(new HTML("Password text box:"));
    vp.add(createTextThing(passwordText, true));
    vp.add(new HTML("Text area:"));
    vp.add(createTextThing(textArea, true));

    textArea.setVisibleLines(5);

    Widget richText = createRichText();
    richText.setWidth("32em");

    HorizontalPanel hp = new HorizontalPanel();
    hp.add(vp);
    hp.add(richText);
    hp.setCellHorizontalAlignment(vp, HorizontalPanel.ALIGN_LEFT);
    hp.setCellHorizontalAlignment(richText, HorizontalPanel.ALIGN_RIGHT);

    initWidget(hp);
    hp.setWidth("100%");
  
Methods Summary
private com.google.gwt.user.client.ui.WidgetcreateRichText()

    RichTextArea area = new RichTextArea();
    RichTextToolbar tb = new RichTextToolbar(area);

    VerticalPanel p = new VerticalPanel();
    p.add(tb);
    p.add(area);

    area.setHeight("14em");
    area.setWidth("100%");
    tb.setWidth("100%");
    p.setWidth("100%");
    DOM.setStyleAttribute(p.getElement(), "margin-right", "4px");
    return p;
  
private com.google.gwt.user.client.ui.WidgetcreateTextThing(com.google.gwt.user.client.ui.TextBoxBase textBox, boolean addSelection)

    HorizontalPanel p = new HorizontalPanel();
    p.setSpacing(4);

    textBox.setWidth("20em");
    p.add(textBox);

    if (addSelection) {
      final HTML echo = new HTML();
  
      p.add(echo);
      textBox.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
          updateText(textBox, echo);
        }
      });
  
      textBox.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
          updateText(textBox, echo);
        }
      });
  
      updateText(textBox, echo);
    }
    return p;
  
public static SinkInfoinit()

    return new SinkInfo(
        "Text",
        "<h2>Basic and Rich Text</h2>"
            + "<p>GWT includes the standard complement of text-entry widgets, each of which "
            + "supports keyboard and selection events you can use to control text entry.  "
            + "In particular, notice that the selection range for each widget is "
            + "updated whenever you press a key.</p>"
            + "<p>Also notice the rich-text area to the right. This is supported on "
            + "all major browsers, and will fall back gracefully to the level of "
            + "functionality supported on each.</p>") {

      public Sink createInstance() {
        return new Text();
      }

      public String getColor() {
        return "#2fba10";
      }
    };
  
public voidonShow()

  
private voidupdateText(com.google.gwt.user.client.ui.TextBoxBase text, com.google.gwt.user.client.ui.HTML echo)

    echo.setHTML("Selection: " + text.getCursorPos() + ", "
        + text.getSelectionLength());