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.cruxframework.crux.gwt.client.NumberFormatUtil.java

License:Apache License

/**
 * Gets a NumberFormat object based on the patternString parameter. 
 * @param patternString/*  w  ww.  j av a 2  s . c  o m*/
 * @return
 */
public static NumberFormat getNumberFormat(String patternString) {
    NumberFormat result;

    if (DECIMAL_PATTERN.equals(patternString)) {
        result = NumberFormat.getDecimalFormat();
    } else if (CURRENCY_PATTERN.equals(patternString)) {
        result = NumberFormat.getCurrencyFormat();
    } else if (PERCENT_PATTERN.equals(patternString)) {
        result = NumberFormat.getPercentFormat();
    } else if (SCIENTIFIC_PATTERN.equals(patternString)) {
        result = NumberFormat.getScientificFormat();
    } else {
        result = NumberFormat.getFormat(patternString);
    }

    return result;
}

From source file:org.cruxframework.crux.smartfaces.client.input.NumberBox.java

License:Apache License

public void setFormatterOptions(FormatterOptions formatterOptions) {
    StringBuilder pattern = new StringBuilder("0");

    if (formatterOptions.showGroupSeparators) {
        for (int i = 0; i < formatterOptions.groupSize - 1; i++) {
            pattern.insert(0, "#");
        }//from w w w . j  a  v a 2  s  . com
        pattern.insert(0, "#,");
        if (StringUtils.isEmpty(formatterOptions.groupSeparator)) {
            formatterOptions.groupSeparator = localeGroupSeparator;
        }

    }
    if (formatterOptions.fractionDigits > 0) {
        pattern.append(".");
        for (int i = 0; i < formatterOptions.fractionDigits; i++) {
            pattern.append("0");
        }

        if (StringUtils.isEmpty(formatterOptions.decimalSeparator)) {
            formatterOptions.decimalSeparator = localeDecimalSeparator;
        }

    }
    assert (!StringUtils.unsafeEquals(formatterOptions.decimalSeparator,
            formatterOptions.groupSeparator)) : "Invalid options. Decimal separator can not be equals to group separator.";

    NumberFormat numberFormat = NumberFormat.getFormat(pattern.toString());
    renderer.setNumberFormat(numberFormat);
    this.formatterOptions = formatterOptions;
}

From source file:org.dashbuilder.client.widgets.dataset.editor.widgets.DataSetExplorerView.java

License:Apache License

public String humanReadableByteCount(long bytes, boolean si) {
    int unit = si ? 1000 : 1024;
    if (bytes < unit)
        return Long.toString(bytes);
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
    return NumberFormat.getFormat("#.0").format(bytes / Math.pow(unit, exp)) + pre;
}

From source file:org.dashbuilder.client.widgets.dataset.editor.widgets.DataSetExplorerView.java

License:Apache License

public String humanReadableRowCount(long rows) {
    int unit = 1000;
    if (rows < unit)
        return Long.toString(rows);
    int exp = (int) (Math.log(rows) / Math.log(unit));
    String pre = ("kMGTPE").charAt(exp - 1) + ("");
    return NumberFormat.getFormat("#.0").format(rows / Math.pow(unit, exp)) + pre;
}

From source file:org.dashbuilder.client.widgets.dataset.explorer.DataSetSummary.java

License:Apache License

String humanReadableByteCount(long bytes) {
    final String _b = " " + DataSetExplorerConstants.INSTANCE.bytes();
    int unit = 1024;
    if (bytes < unit)
        return Long.toString(bytes) + _b;
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = ("KMGTPE").charAt(exp - 1) + _b;
    return NumberFormat.getFormat(ESTIMATIONS_FORMAT).format(bytes / Math.pow(unit, exp)) + pre;
}

From source file:org.dashbuilder.client.widgets.dataset.explorer.DataSetSummary.java

License:Apache License

String humanReadableRowCount(long rows) {
    int unit = 1000;
    if (rows < unit)
        return Long.toString(rows);
    int exp = (int) (Math.log(rows) / Math.log(unit));
    String pre = ("KMGTPE").charAt(exp - 1) + ("");
    return NumberFormat.getFormat(ESTIMATIONS_FORMAT).format(rows / Math.pow(unit, exp)) + pre;
}

From source file:org.dashbuilder.displayer.client.DisplayerGwtFormatter.java

License:Apache License

protected NumberFormat getNumberFormat(String pattern) {
    if (StringUtils.isBlank(pattern)) {
        return getNumberFormat(ColumnSettings.NUMBER_PATTERN);
    }//ww w  .  j  ava  2 s.co  m
    NumberFormat format = numberPatternMap.get(pattern);
    if (format == null) {
        format = NumberFormat.getFormat(pattern);
        numberPatternMap.put(pattern, format);
    }
    return format;
}

From source file:org.dashbuilder.renderer.c3.client.C3Displayer.java

License:Apache License

protected C3Tick createTickY() {
    return factory.createC3Tick(f -> {
        try {/*from  ww w.  j a v a  2 s.  c om*/
            double doubleFormat = Double.parseDouble(f);
            return NumberFormat.getFormat("#,###.##").format(doubleFormat);
        } catch (NumberFormatException e) {
            return f;
        }
    });
}

From source file:org.dashbuilder.renderer.table.client.TableDisplayer.java

License:Apache License

private Column<Integer, ?> createColumn(ColumnType columnType, String columnId, final int columnNumber) {

    switch (columnType) {
    case LABEL:/*w  ww  .j  av  a2 s.c  o  m*/
        return new Column<Integer, String>(new SelectableTextCell(columnId)) {
            public String getValue(Integer row) {
                Object value = dataSet.getValueAt(row, columnNumber);
                if (value == null)
                    return "---";
                return value.toString();
            }
        };

    case TEXT:
        return new Column<Integer, String>(new TextCell()) {
            public String getValue(Integer row) {
                Object value = dataSet.getValueAt(row, columnNumber);
                if (value == null)
                    return "---";
                return value.toString();
            }
        };

    case NUMBER:
        return new Column<Integer, Number>(new NumberCell(NumberFormat.getFormat("#.###"))) {
            public Number getValue(Integer row) {
                Object value = dataSet.getValueAt(row, columnNumber);
                if (value == null)
                    return 0;
                return (Number) value;
            }
        };

    case DATE:
        return new Column<Integer, Date>(
                new DateCell(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM))) {
            public Date getValue(Integer row) {
                Object value = dataSet.getValueAt(row, columnNumber);
                if (value == null)
                    return new Date();
                return (Date) value;
            }
        };
    }
    return null;
}

From source file:org.drools.guvnor.client.widgets.tables.GuvnorSimplePager.java

License:Apache License

protected String createText() {
    NumberFormat formatter = NumberFormat.getFormat("#,###");
    HasRows display = getDisplay();/*from ww w .  jav  a 2 s. com*/
    Range range = display.getVisibleRange();
    int pageStart = range.getStart() + 1;
    int pageSize = range.getLength();
    int dataSize = display.getRowCount();
    int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
    endIndex = Math.max(pageStart, endIndex);
    boolean exact = display.isRowCountExact();
    if (dataSize == 0) {
        return "0 of 0";
    } else if (pageStart == endIndex) {
        return formatter.format(pageStart) + " of " + formatter.format(dataSize);
    }
    return formatter.format(pageStart) + "-" + formatter.format(endIndex) + (exact ? " of " : " of over ")
            + formatter.format(dataSize);
}