Example usage for com.google.gwt.i18n.client NumberFormat getFormat

List of usage examples for com.google.gwt.i18n.client NumberFormat getFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client NumberFormat getFormat.

Prototype

public static NumberFormat getFormat(String pattern) 

Source Link

Document

Gets a NumberFormat instance for the default locale using the specified pattern and the default currencyCode.

Usage

From source file:org.gk.engine.client.build.form.field.SpinnerFieldBuilder.java

License:Open Source License

private void initField(SpinnerField field) {
    field.setFieldLabel(getField().getLabel());
    // maxValue?minValue?inc?value?format?
    int maxDecimalLength = 0;
    String numType = getField().getAttribute("numType", "");
    String inc = getField().getAttribute("inc", "");
    String maxValue = getField().getAttribute("maxValue", "");
    String minValue = getField().getAttribute("minValue", "");
    String value = getField().getValue();
    String format = getField().getFormat();

    // number type
    if (!numType.equals("")) {
        field.getPropertyEditor().setType(getNumberType(numType));
    }//w w w  .j av a 2s  .c  om
    // ?
    if (inc.matches(IRegExpUtils.FLOAT)) {
        field.setIncrement(Double.parseDouble(inc));
        maxDecimalLength = getMaxDecLength(inc, maxDecimalLength);
    }
    // 
    if (maxValue.matches(IRegExpUtils.FLOAT)) {
        field.setMaxValue(Double.parseDouble(maxValue));
        maxDecimalLength = getMaxDecLength(maxValue, maxDecimalLength);
    }
    // ?
    if (minValue.matches(IRegExpUtils.FLOAT)) {
        field.setMinValue(Double.parseDouble(minValue));
        maxDecimalLength = getMaxDecLength(minValue, maxDecimalLength);
    }
    // ?
    if (value.matches(IRegExpUtils.FLOAT)) {
        field.setValue(Double.parseDouble(value));
        field.fireEvent(Events.Change);
        maxDecimalLength = getMaxDecLength(value, maxDecimalLength);
    }
    // format
    if (!format.equals("")) {
        field.getPropertyEditor().setFormat(NumberFormat.getFormat(format));
    } else {
        String zeroStr = ((long) Math.pow(10, maxDecimalLength) + "").replaceAll("1", "");
        format = "##0" + (zeroStr.equals("") ? "" : "." + zeroStr);
        field.getPropertyEditor().setFormat(NumberFormat.getFormat(format));
    }
}

From source file:org.gk.engine.client.build.grid.field.GAggregationRowBuilder.java

License:Open Source License

/**
 * ?NumberFormat/*from  w ww .  j  a  va 2 s. com*/
 * 
 * @param format
 * @return NumberFormat
 */
private NumberFormat getSummaryFormat(String format) {
    NumberFormat nf = null;
    if (format.equalsIgnoreCase("currency")) {
        nf = NumberFormat.getCurrencyFormat();
    } else if (format.equalsIgnoreCase("scientific")) {
        nf = NumberFormat.getScientificFormat();
    } else if (format.equalsIgnoreCase("decimal")) {
        nf = NumberFormat.getDecimalFormat();
    } else if (format.equalsIgnoreCase("percent")) {
        nf = NumberFormat.getPercentFormat();
    } else {
        nf = NumberFormat.getFormat(format);
    }
    return nf;
}

From source file:org.gk.engine.client.build.grid.field.GNumFieldBuilder.java

License:Open Source License

@Override
public ColumnConfig create() {
    final XGridField x = (XGridField) getField().clone();
    ColumnConfig cc = new gkNumberColumnConfig(x) {

        @Override//from www  .j  ava 2  s  . co m
        public void onField(Field field) {
            String value = x.getValue();
            String format = x.getFormat();
            if (field instanceof NumberField) {
                NumberField nf = (NumberField) field;
                // format
                if (!format.equals("")) {
                    nf.setFormat(NumberFormat.getFormat(format));
                }
                // value??
                if (value.matches(IRegExpUtils.FLOAT)) {
                    nf.setValue(Double.valueOf(value));
                }
            }
            setAttribute(field, x);
        }
    };
    return cc;
}

From source file:org.gk.engine.client.build.grid.field.GSpinnerFieldBuilder.java

License:Open Source License

@Override
public ColumnConfig create() {
    final XGridField x = (XGridField) getField().clone();
    ColumnConfig cc = new gkSpinnerColumnConfig(x) {

        @Override//from  ww  w .  java  2  s  .co m
        public void onField(Field field) {
            setAttribute(field, x);
        }

        @Override
        public Field createField() {
            // maxValue?minValue?inc?value?format?
            int maxDecimalLength = 0;
            String numType = x.getAttribute("numType", "");
            String inc = x.getAttribute("inc", "");
            String maxValue = x.getAttribute("maxValue", "");
            String minValue = x.getAttribute("minValue", "");
            String value = x.getValue();
            String format = x.getFormat();

            SpinnerField sf = new SpinnerField() {
                @Override
                public void focus() {
                    if (rendered) {
                        getFocusEl().focus();
                        onFocus(new FieldEvent(this));
                    }
                    if (!hasFocus) {
                        fireEvent(Events.Focus);
                    }
                }

                @Override
                public void setFieldLabel(String fieldLabel) {
                    super.setFieldLabel(fieldLabel);
                    setHeader(fieldLabel);
                }

                @Override
                protected void blur() {
                    if (rendered) {
                        getFocusEl().blur();
                    }
                    if (hasFocus) {
                        fireEvent(Events.Blur);
                        hasFocus = false;
                    }
                }
            };

            // number type
            if (!numType.equals("")) {
                sf.getPropertyEditor().setType(getNumberType(numType));
            }
            // ?
            if (inc.matches(IRegExpUtils.FLOAT)) {
                sf.setIncrement(Double.parseDouble(inc));
                maxDecimalLength = getMaxDecLength(inc, maxDecimalLength);
            }
            // 
            if (maxValue.matches(IRegExpUtils.FLOAT)) {
                sf.setMaxValue(Double.parseDouble(maxValue));
                maxDecimalLength = getMaxDecLength(maxValue, maxDecimalLength);
            }
            // ?
            if (minValue.matches(IRegExpUtils.FLOAT)) {
                sf.setMinValue(Double.parseDouble(minValue));
                maxDecimalLength = getMaxDecLength(minValue, maxDecimalLength);
            }
            // ?
            if (value.matches(IRegExpUtils.FLOAT)) {
                sf.setValue(Double.parseDouble(value));
                maxDecimalLength = getMaxDecLength(value, maxDecimalLength);
            }
            // format
            if (!format.equals("")) {
                sf.getPropertyEditor().setFormat(NumberFormat.getFormat(format));
            } else {
                String zeroStr = ((long) Math.pow(10, maxDecimalLength) + "").replaceAll("1", "");
                format = "##0" + (zeroStr.equals("") ? "" : "." + zeroStr);
                sf.getPropertyEditor().setFormat(NumberFormat.getFormat(format));
            }
            return sf;
        }
    };
    return cc;
}

From source file:org.glom.web.client.Utils.java

License:Open Source License

public static NumberFormat getNumberFormat(final NumericFormat numericFormat) {

    final StringBuilder pattern = new StringBuilder("0.");

    // add pattern for thousands separator
    if (numericFormat.getUseThousandsSeparator()) {
        pattern.insert(0, "#,##");
    }/*from   w  ww.  j a va2s .  c  om*/

    // add pattern for restricted decimal places
    if (numericFormat.getDecimalPlacesRestricted()) {
        for (int i = 0; i < numericFormat.getDecimalPlaces(); i++) {
            pattern.append('0');
        }
    } else {
        // The default precision in libglom is 15.
        pattern.append("###############");
    }

    // TODO use exponential numbers when more than 15 decimal places

    return NumberFormat.getFormat(pattern.toString());

}

From source file:org.gss_project.gss.common.dto.FileBodyDTO.java

License:Open Source License

private String getSize(Long size, Double division) {
    Double res = Double.valueOf(size.toString()) / division;
    NumberFormat nf = NumberFormat.getFormat("######.###");
    return nf.format(res);
}

From source file:org.gss_project.gss.common.dto.StatsDTO.java

License:Open Source License

private String getSize(Long size, Double division) {
    Double res = Double.valueOf(size.toString()) / division;
    NumberFormat nf = NumberFormat.getFormat("######.#");
    return nf.format(res);
}

From source file:org.gss_project.gss.common.dto.UserClassDTO.java

License:Open Source License

private String getSize(Long size, Double divisor) {
    Double res = Double.valueOf(size.toString()) / divisor;
    NumberFormat nf = NumberFormat.getFormat("######.#");
    return nf.format(res);
}

From source file:org.gss_project.gss.web.client.rest.resource.FileResource.java

License:Open Source License

private static String getSize(Long size, Double division) {
    Double res = Double.valueOf(size.toString()) / division;
    NumberFormat nf = NumberFormat.getFormat("######.#");
    return nf.format(res);
}

From source file:org.jahia.ajax.gwt.client.util.Formatter.java

License:Open Source License

/**
 * Get a human readable size from a byte size.
 *
 * @param size the size to format//from   w w  w  . j ava  2 s .co  m
 * @return the formatted size
 */
public static String getFormattedSize(long size) {
    NumberFormat nf = NumberFormat.getFormat("0.00");
    StringBuffer dispSize = new StringBuffer();
    if (size >= GB) {
        dispSize.append(String.valueOf(nf.format(size / GB))).append(" GB");
    } else if (size >= MB) {
        dispSize.append(String.valueOf(nf.format(size / MB))).append(" MB");
    } else if (size >= KB) {
        dispSize.append(String.valueOf(nf.format(size / KB))).append(" KB");
    } else {
        dispSize.append(String.valueOf(nf.format(size))).append(" B");
    }
    return dispSize.toString();
}