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

ConstantsWithLookupExampleController

public class ConstantsWithLookupExampleController extends Object
Demonstrates {@link ConstantsWithLookup}.

Fields Summary
private static final String
DEFAULT_INPUT
private static final ColorConstants
COLORS
public final com.google.gwt.user.client.ui.TextBox
txtInput
public final com.google.gwt.user.client.ui.TextBox
txtResult
private String
prevText
private final ConstantsWithLookupExampleConstants
constants
Constructors Summary
public ConstantsWithLookupExampleController(ConstantsWithLookupExampleConstants constants)


   
         

    this.constants = constants;
    txtResult.setText(constants.noInputResult());
    txtResult.setReadOnly(true);

    txtInput.addKeyboardListener(new KeyboardListenerAdapter() {
      public void onKeyUp(Widget sender, char keyCode, int modifiers) {
        maybeRefreshLookup(constants);
      }
    });

    txtInput.setText(DEFAULT_INPUT);
    maybeRefreshLookup(constants);
  
Methods Summary
public ConstantsWithLookupExampleConstantsgetConstants()

    return constants;
  
private voidmaybeRefreshLookup(ConstantsWithLookupExampleConstants constants)

    final String currText = txtInput.getText().trim();
    if (!currText.equals(prevText)) {
      prevText = currText;
      if ("".equals(currText)) {
        txtResult.setText(constants.noInputResult());
      } else {
        try {
          String color = COLORS.getString(currText);
          txtResult.setText(color);
        } catch (MissingResourceException e) {
          txtResult.setText(constants.noMatchingResult());
        }
      }
    }