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

NumberFormatExampleController

public class NumberFormatExampleController extends AbstractFormatExampleController
Demonstrates how to use {@link NumberFormat}.

Fields Summary
private static final String
DEFAULT_INPUT
private com.google.gwt.i18n.client.NumberFormat
activeFormat
private final NumberFormatExampleConstants
constants
Constructors Summary
public NumberFormatExampleController(NumberFormatExampleConstants constants)


   
         
    super(DEFAULT_INPUT, constants.numberFormatPatterns());
    this.constants = constants;
  
Methods Summary
protected java.lang.StringdoGetPattern(java.lang.String patternKey)

    if ("currency".equals(patternKey)) {
      return NumberFormat.getCurrencyFormat().getPattern();
    }

    if ("decimal".equals(patternKey)) {
      return NumberFormat.getDecimalFormat().getPattern();
    }

    if ("scientific".equals(patternKey)) {
      return NumberFormat.getScientificFormat().getPattern();
    }

    if ("percent".equals(patternKey)) {
      return NumberFormat.getPercentFormat().getPattern();
    }

    throw new IllegalArgumentException("Unknown pattern key '" + patternKey
        + "'");
  
protected voiddoParseAndRememberPattern(java.lang.String pattern)

    activeFormat = NumberFormat.getFormat(pattern);
  
protected voiddoParseInput(java.lang.String toParse, com.google.gwt.user.client.ui.HasText output, com.google.gwt.user.client.ui.HasText error)

    if (!"".equals(toParse)) {
      try {
        double x = Double.parseDouble(toParse);
        String s = activeFormat.format(x);
        output.setText(s);
      } catch (NumberFormatException e) {
        String errMsg = constants.failedToParseInput();
        error.setText(errMsg);
      }
    } else {
      output.setText("<None>");
    }
  
public NumberFormatExampleConstantsgetConstants()

    return constants;