FileDocCategorySizeDatePackage
I18N.javaAPI DocExample8136Mon Aug 27 20:11:56 BST 2007com.google.gwt.sample.i18n.client

I18N

public class I18N extends Object implements com.google.gwt.core.client.EntryPoint
A sample module that demonstrates how to localize text resources.

Fields Summary
Constructors Summary
Methods Summary
private voidbindElement(java.lang.String id, java.lang.String text)

    Element elem = DOM.getElementById(id);
    if (elem == null) {
      throw new NoSuchElementException(id);
    }
    DOM.setInnerText(elem, text);
  
private voidbindElement(java.lang.String id, com.google.gwt.user.client.ui.Widget widget)

    RootPanel rp = RootPanel.get(id);
    if (rp == null) {
      throw new NoSuchElementException(id);
    }
    rp.clear();
    rp.add(widget);
  
private voidinitConstantsExample()

    ConstantsExampleConstants constants = (ConstantsExampleConstants) GWT.create(ConstantsExampleConstants.class);
    ListBox colorChoices = new ListBox();

    for (Iterator iter = constants.colorMap().values().iterator(); iter.hasNext();) {
      String color = (String) iter.next();
      colorChoices.addItem(color);
    }

    TextBox txtFirstName = new TextBox();
    TextBox txtLastName = new TextBox();

    bindElement("constantsFirstNameCaption", constants.firstName());
    bindElement("constantsFirstNameText", txtFirstName);
    bindElement("constantsLastNameCaption", constants.lastName());
    bindElement("constantsLastNameText", txtLastName);
    bindElement("constantsFavoriteColorCaption", constants.favoriteColor());
    bindElement("constantsFavoriteColorList", colorChoices);

    txtFirstName.setText("Amelie");
    txtLastName.setText("Crutcher");
  
private voidinitConstantsWithLookupExample(ConstantsWithLookupExampleController controller)

    ConstantsWithLookupExampleConstants constants = controller.getConstants();
    bindElement("constantsWithLookupInputCaption", constants.input());
    bindElement("constantsWithLookupInputText", controller.txtInput);
    bindElement("constantsWithLookupResultsCaption", constants.result());
    bindElement("constantsWithLookupResultsText", controller.txtResult);
  
private voidinitDateTimeFormatExample(DateTimeFormatExampleController controller)

    DateTimeFormatExampleConstants constants = controller.getConstants();
    bindElement("dateTimeFormatPatternCaption", constants.pattern());
    bindElement("dateTimeFormatPatternList", controller.lstSamplePatterns);
    bindElement("dateTimeFormatPatternText", controller.txtCurrentPattern);
    bindElement("dateTimeFormatPatternError", controller.lblPatternError);
    bindElement("dateTimeFormatInputCaption", constants.inputValue());
    bindElement("dateTimeFormatInputText", controller.txtInput);
    bindElement("dateTimeFormatInputError", controller.lblParseError);
    bindElement("dateTimeFormatOutputCaption", constants.formattedOutput());
    bindElement("dateTimeFormatOutputText", controller.lblFormattedOutput);
  
private voidinitDictionaryExample()

    FlexTable t = new FlexTable();
    t.setStyleName("i18n-dictionary");
    bindElement("dictionaryExample", t);

    Dictionary userInfo = Dictionary.getDictionary("userInfo");
    Iterator s = userInfo.keySet().iterator();
    for (int i = 0; s.hasNext(); i++) {
      String key = (String) s.next();
      t.setText(0, i, key);
      t.setText(1, i, userInfo.get(key));
    }
    t.getRowFormatter().setStyleName(0, "i18n-dictionary-header-row");
  
private voidinitMessagesExample(MessagesExampleController controller)

    MessagesExampleConstants constants = controller.getConstants();
    bindElement("messagesTemplateCaption", constants.messageTemplate());
    bindElement("messagesTemplateText", controller.lblMessageTemplate);
    bindElement("messagesArg1Caption", constants.arg1());
    bindElement("messagesArg1Text", controller.txtArg1);
    bindElement("messagesArg2Caption", constants.arg2());
    bindElement("messagesArg2Text", controller.txtArg2);
    bindElement("messagesArg3Caption", constants.arg3());
    bindElement("messagesArg3Text", controller.txtArg3);
    bindElement("messagesFormattedOutputCaption", constants.formattedMessage());
    bindElement("messagesFormattedOutputText", controller.lblFormattedMessage);
  
private voidinitNumberFormatExample(NumberFormatExampleController controller)

    NumberFormatExampleConstants constants = controller.getConstants();
    bindElement("numberFormatPatternCaption", constants.pattern());
    bindElement("numberFormatPatternList", controller.lstSamplePatterns);
    bindElement("numberFormatPatternText", controller.txtCurrentPattern);
    bindElement("numberFormatPatternError", controller.lblPatternError);
    bindElement("numberFormatInputCaption", constants.inputValue());
    bindElement("numberFormatInputText", controller.txtInput);
    bindElement("numberFormatInputError", controller.lblParseError);
    bindElement("numberFormatOutputCaption", constants.formattedOutput());
    bindElement("numberFormatOutputText", controller.lblFormattedOutput);
  
public voidonModuleLoad()
Attaches logical controllers to various elements on the page. Note that this module is logic only; it assumes the HTML handles all layout and styling.

see
com.google.gwt.core.client.EntryPoint#onModuleLoad()

    // An example that demonstrates NumberFormat.
    NumberFormatExampleConstants numberFormatConstants = (NumberFormatExampleConstants) GWT.create(NumberFormatExampleConstants.class);
    NumberFormatExampleController numberFormatController = new NumberFormatExampleController(
        numberFormatConstants);
    initNumberFormatExample(numberFormatController);

    // An example that demonstrates DateTimeFormat.
    DateTimeFormatExampleConstants dateTimeFormatConstants = (DateTimeFormatExampleConstants) GWT.create(DateTimeFormatExampleConstants.class);
    DateTimeFormatExampleController dateTimeFormatController = new DateTimeFormatExampleController(
        dateTimeFormatConstants);
    initDateTimeFormatExample(dateTimeFormatController);

    // An example that demonstrates Constants.
    initConstantsExample();

    // An example that demonstrates ConstantsWithLookup.
    ConstantsWithLookupExampleConstants constantsWithLookupConstants = (ConstantsWithLookupExampleConstants) GWT.create(ConstantsWithLookupExampleConstants.class);
    ConstantsWithLookupExampleController constantsWithLookupController = new ConstantsWithLookupExampleController(
        constantsWithLookupConstants);
    initConstantsWithLookupExample(constantsWithLookupController);

    // An example that demonstrates Messages.
    MessagesExampleConstants messagesExampleConstants = (MessagesExampleConstants) GWT.create(MessagesExampleConstants.class);
    MessagesExampleController messagesController = new MessagesExampleController(
        messagesExampleConstants);
    initMessagesExample(messagesController);

    // An example that demonstrates Dictionary.
    initDictionaryExample();

    TextBox initiallyFocusedTextBox = numberFormatController.txtInput;
    initiallyFocusedTextBox.setFocus(true);
    initiallyFocusedTextBox.selectAll();