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.jboss.as.console.client.v3.deployment.DeploymentBrowseContentView.java

License:Open Source License

public String formatFileUnits(long length) {
    if (length <= 0)
        return "0";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(length) / Math.log10(1024));
    return NumberFormat.getFormat("#,##0.#").format(length / Math.pow(1024, digitGroups)) + " "
            + units[digitGroups];//from w w w .  j ava2s . c o  m
}

From source file:org.jboss.errai.common.client.logging.util.StringFormat.java

License:Apache License

private static String buildReplacement(Conversion conv, boolean upper, int width, int prec, String suffix,
        Object arg) {/*www .  j a v a 2 s  .  c om*/
    String res = null;
    switch (conv) {
    case bool:
        if (arg instanceof Boolean) {
            if ((Boolean) arg) {
                res = "true";
            } else {
                res = "false";
            }
        } else if (arg != null) {
            res = "true";
        } else {
            res = "false";
        }
        break;
    case date:
        if (suffix == null || suffix.length() != 1)
            throw new IllegalArgumentException("Must provide suffix with date conversion.");
        if (arg instanceof Long)
            arg = new Date((Long) arg);
        res = processDate((Date) arg, upper, suffix.charAt(0));
        break;
    case decInt:
        res = String.valueOf((Integer) arg);
        break;
    case decNum:
        if (arg instanceof Float) {
            res = String.valueOf((Float) arg);
        } else {
            res = String.valueOf((Double) arg);
        }
        break;
    case hexInt:
        res = Integer.toHexString((Integer) arg);
        break;
    case hexStr:
        if (arg == null)
            res = "null";
        else
            res = Integer.toHexString(arg.hashCode());
        break;
    case octInt:
        res = Integer.toOctalString((Integer) arg);
        break;
    case str:
        if (arg == null)
            res = "null";
        else
            res = arg.toString();
        break;
    case uniChar:
        if (arg instanceof Integer)
            arg = Character.valueOf((char) ((Integer) arg).intValue());
        res = Character.toString((Character) arg);
        break;
    case compNum:
    case sciInt:
        if (arg instanceof Float) {
            arg = Double.valueOf((Float) arg);
        }
        if (Integer.MAX_VALUE == prec)
            prec = 6;
        final StringBuilder formatString = new StringBuilder(prec + 5);
        formatString.append("0.");
        for (int i = 0; i < prec; i++)
            formatString.append('0');
        formatString.append("E00");

        res = NumberFormat.getFormat(formatString.toString()).format((Double) arg);
        if (!upper)
            res = res.toLowerCase();

        return padOrTrunc(res, width, Integer.MAX_VALUE);
    // TODO
    case hexNum:
        throw new UnsupportedOperationException();
    case line:
        return "\n";
    case escLit:
        return "%";
    }
    res = padOrTrunc(res, width, prec);
    if (upper)
        return res.toUpperCase();
    else
        return res;
}

From source file:org.jdna.eloaa.shared.util.Utils.java

License:Apache License

public static String readableFileSize(long size) {
    if (size <= 0)
        return "0";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
    return NumberFormat.getFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " "
            + units[digitGroups];/*from ww w . j a v  a2  s  .  c  o m*/
}

From source file:org.jdna.eloaa.shared.util.Utils.java

License:Apache License

public static String formatPercent(double percent) {
    return NumberFormat.getFormat("##0.##").format(percent) + "%";
}

From source file:org.kie.workbench.common.forms.dynamic.client.rendering.renderers.SliderFieldRenderer.java

License:Apache License

private NumberFormat createFormatter(int precision) {
    String pattern = "0";
    if (precision > 0) {
        pattern += ".";
        while (precision > 0) {
            pattern += "0";
            precision--;/*from   w w  w .  ja va  2s .co  m*/
        }
    }
    return NumberFormat.getFormat(pattern);
}

From source file:org.kino.client.monitoring.CurrentProjectsGrid.java

public CurrentProjectsGrid() {

    ListStore<ProjectItem> store = new ListStore<ProjectItem>(new ModelKeyProvider<ProjectItem>() {

        @Override/*from   ww  w.  j a v  a2  s.  co m*/
        public String getKey(ProjectItem item) {
            return String.valueOf(item.id);
        }
    });

    final ColumnConfig<ProjectItem, String> col_name = new ColumnConfig<ProjectItem, String>(
            new ReadOnlyValueProvider<ProjectItem, String>("rus_title") {

                @Override
                public String getValue(ProjectItem object) {
                    return object.rus_name;
                }
            }, 100, "?");

    ColumnConfig<ProjectItem, Date> col_date_accept = new ColumnConfig<ProjectItem, Date>(
            new ReadOnlyValueProvider<ProjectItem, Date>("date_accept") {

                @Override
                public Date getValue(ProjectItem object) {
                    return new Date(object.date_begin);
                }

            }, 100, " ?");
    col_date_accept.setCell(new DateCell(DateTimeFormat.getFormat("dd/MM/yyyy HH:mm:ss")) {

        @Override
        public void render(Cell.Context context, Date value, SafeHtmlBuilder sb) {
            if (value.getTime() == 0)
                sb.appendEscaped("-");
            else
                super.render(context, value, sb); //To change body of generated methods, choose Tools | Templates.
        }
    });
    final ColumnConfig<ProjectItem, ProjectItem> col_time_left = new ColumnConfig<ProjectItem, ProjectItem>(
            new ReadOnlyValueProvider<ProjectItem, ProjectItem>("time_left") {

                @Override
                public ProjectItem getValue(ProjectItem object) {
                    return object;
                }
            }, 100, "??");

    col_time_left.setCell(new AbstractCell<ProjectItem>() {

        @Override
        public void render(Cell.Context context, ProjectItem ob, SafeHtmlBuilder sb) {
            if (ob.status.equals("error") || ob.status.equals("done")) {
                sb.appendEscaped("0");
                return;
            }
            Long value = ob.time_left;
            if (value < 0)
                sb.appendHtmlConstant("<font size='4'>&#8734;</font>");
            else {
                if (value == 0)
                    sb.appendEscaped("0");
                else if (value < 60)
                    sb.appendEscaped(value.toString() + " ?");
                else if (value < 3600)
                    sb.appendEscaped((value / 60) + " ");
                else if (value < 86400) //60*60*24
                    sb.appendEscaped((value / (60 * 60)) + " ");
                else if (value < 2592000)
                    sb.appendEscaped((value / (60 * 60 * 24)) + " ");
                else
                    sb.appendEscaped(" ??");

            }

        }
    });

    final ColumnConfig<ProjectItem, ProjectItem> col_speed = new ColumnConfig<ProjectItem, ProjectItem>(
            new ReadOnlyValueProvider<ProjectItem, ProjectItem>("speed") {

                @Override
                public ProjectItem getValue(ProjectItem object) {
                    return object;
                }
            }, 100, "C?");
    col_speed.setCell(new AbstractCell<ProjectItem>() {
        NumberFormat decimalFormat = NumberFormat.getFormat(".##");

        @Override
        public void render(Cell.Context context, ProjectItem value, SafeHtmlBuilder sb) {
            if (value.status.equals("error") || value.status.equals("ready") || value.status.equals("done")) {
                sb.appendEscaped("0");
                return;
            }
            if (value.is_downloading == false) {
                sb.appendEscaped("0");
                return;
            }

            if (value.speed == 0)
                sb.appendHtmlConstant("0");
            else if (value.speed < 1024)
                sb.appendHtmlConstant(value.speed + " /c");
            else if (value.speed < (1024 * 1024))
                sb.appendHtmlConstant(decimalFormat.format(((double) value.speed) / 1024) + " /c");
            else
                sb.appendHtmlConstant(
                        decimalFormat.format(((double) value.speed) / (1024 * 1024)) + " /c");

        }
    });
    List<ColumnConfig<ProjectItem, ?>> list = new ArrayList<ColumnConfig<ProjectItem, ?>>();
    list.add(new RowNumberer<ProjectItem>(new IdentityValueProvider<ProjectItem>()));
    //list.add(col_poster);
    list.add(col_name);
    list.add(col_date_accept);
    //  list.add(col_client_count);
    list.add(col_time_left);
    list.add(col_speed);

    //  

    ColumnModel<ProjectItem> cm = new ColumnModel<ProjectItem>(list);

    grid = new Grid<ProjectItem>(store, cm);
    ToolBar bar = new ToolBar();
    TextButton but_refresh = new TextButton("", Resources.INSTANCE.refresh());
    bar.add(but_refresh);
    vert.add(bar, new VerticalLayoutContainer.VerticalLayoutData(1, -1));
    vert.add(grid, new VerticalLayoutContainer.VerticalLayoutData(1, 1));
    grid.getView().setEmptyText("? ?");

    but_refresh.addSelectHandler(new SelectEvent.SelectHandler() {

        @Override
        public void onSelect(SelectEvent event) {

            loadData();
        }
    });

}

From source file:org.ktunaxa.referral.client.layer.ReferenceSubLayer.java

License:Open Source License

protected String scaleToString(double scale) {
    NumberFormat numberFormat = NumberFormat.getFormat(DENOMINATOR_FORMAT);
    if (scale > 0 && scale < 1.0) {
        int denom = (int) Math.round(1. / scale);
        return "1 : " + numberFormat.format(denom);
    } else if (scale >= 1.0) {
        int denom = (int) Math.round(scale);
        return numberFormat.format(denom) + " : 1";
    } else {/* ww w  .ja  v  a  2 s.  c om*/
        return "negative scale not allowed";
    }
}

From source file:org.ktunaxa.referral.client.layer.ReferenceSubLayer.java

License:Open Source License

protected Double stringToScale(String s) {
    NumberFormat numberFormat = NumberFormat.getFormat(DENOMINATOR_FORMAT);
    String[] scale2 = s.split(":");
    if (scale2.length == 1) {
        double denominator = numberFormat.parse(scale2[0].trim());
        return denominator == 0 ? 0 : 1 / denominator;
    } else {/*from w  w w.  j  a  va 2 s  . c  o  m*/
        return numberFormat.parse(scale2[0].trim()) / numberFormat.parse(scale2[1].trim());
    }
}

From source file:org.kuali.student.core.document.ui.client.widgets.documenttool.DocumentTool.java

License:Educational Community License

@Override
protected Widget createWidget() {
    //This section title code does not seem consistent with other sections (i.e: of CourseProposal)
    //  section title is now instead displayed based on verticalSectionView in createUploadForm()
    /*SectionTitle viewTitle = SectionTitle.generateH2Title(getTitle());
              //  ww w.j  a v a2  s.c  om
    viewTitle.addStyleName("ks-layout-header");
    layout.add(viewTitle);*/

    layout.add(saveWarning);
    saveWarning.setVisible(false);
    buttonPanel.setButtonText(OkEnum.Ok, "Upload");
    buttonPanel.getButton(OkEnum.Ok).setStyleName(ButtonStyle.SECONDARY.getStyle());

    uploadList.add(createUploadForm());
    form.setWidget(uploadList);
    form.setMethod(FormPanel.METHOD_POST);
    form.setEncoding(FormPanel.ENCODING_MULTIPART);

    buttonPanel.setContent(form);
    if (showAllLink != null) {
        layout.add(showAllLink);
    }
    layout.add(buttonPanel);
    layout.add(documentList);
    documentList.setVisible(false);
    buttonPanel.setVisible(false);

    SectionTitle sectionTitle = SectionTitle.generateH2Title("Upload Status");
    progressWindow.setNonCaptionHeader(sectionTitle);
    progressPanel.add(progressLabel);
    progressPanel.add(progressBar);
    progressPanel.add(fileProgressTable);
    progressBar.setWidth("400px");
    progressBar.setTextFormatter(new TextFormatter() {

        @Override
        protected String getText(ProgressBar bar, double curProgress) {
            String result;
            NumberFormat nf = NumberFormat.getFormat("#.##");
            if (curProgress == bar.getMaxProgress()) {
                result = "Total Uploaded: " + nf.format(curProgress) + "kb";
            } else if (curProgress == 0 || bar.getMaxProgress() == 0) {
                result = "";
            } else {
                String curProgressString;
                String maxProgressString;

                if (curProgress < 1024) {
                    curProgressString = nf.format(curProgress) + "kb";
                } else {
                    curProgressString = nf.format(curProgress / 1024) + "mb";
                }

                if (bar.getMaxProgress() < 1024) {
                    maxProgressString = nf.format(bar.getMaxProgress()) + "kb";
                } else {
                    maxProgressString = nf.format((bar.getMaxProgress()) / 1024) + "mb";
                }
                result = curProgressString + " out of " + maxProgressString;
            }
            return result;
        }
    });
    progressBar.setHeight("30px");
    progressPanel.add(progressButtons);
    progressPanel.setWidth("500px");
    progressWindow.setWidget(progressPanel);
    progressWindow.setSize(520, 270);

    return layout;
}

From source file:org.lorislab.smonitor.admin.client.panel.AttributeGridPanel.java

License:Apache License

public static String convertBytes(double bytes) {
    int unit = 1024;
    int exp = 0;/* www  .j a  v  a2s.c  o  m*/
    double tmp = bytes;
    String pre = UNITS[exp];

    if (tmp >= unit) {
        exp = (int) (Math.log(tmp) / Math.log(unit));
        tmp = tmp / Math.pow(unit, exp);
        pre = UNITS[exp] + pre;
    }

    return NumberFormat.getFormat("#.00").format(tmp) + pre;
}