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:com.client.celltable.SimplePager.java

License:Apache License

/**
 * Get the text to display in the pager that reflects the state of the
 * pager.//  ww  w  .  j a va 2 s  .c  o m
 * 
 * @return the text
 */
protected String createText() {
    // Default text is 1 based.
    NumberFormat formatter = NumberFormat.getFormat("#,###");
    HasRows display = getDisplay();
    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();
    return formatter.format(pageStart) + "-" + formatter.format(endIndex) + (exact ? " of " : " of over ")
            + formatter.format(dataSize);
}

From source file:com.client.celltable.SimplePager.java

License:Apache License

private int pageNumber() {
    NumberFormat formatter = NumberFormat.getFormat("#,###");
    HasRows display = getDisplay();//from   ww  w  .j  a  v a  2 s  .  c  o  m
    Range range = display.getVisibleRange();
    int pageStart = range.getStart() + 1;
    return pageStart;
}

From source file:com.cooper.client.ItemListGrid.java

License:Open Source License

public ItemListGrid(DataSource supplyItemDS) {

    setDataSource(supplyItemDS);/*  ww  w. j  a v a  2s.c om*/
    setUseAllDataSourceFields(true);

    ListGridField itemName = new ListGridField("itemName", "Name");
    itemName.setShowHover(true);
    ListGridField unitCost = new ListGridField("unitCost");

    unitCost.setCellFormatter(new CellFormatter() {
        public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null)
                return null;
            try {
                NumberFormat nf = NumberFormat.getFormat("##0.00");
                return "$" + nf.format(((Number) value).floatValue());
            } catch (Exception e) {
                return value.toString();
            }
        }
    });

    SpinnerItem spinnerItem = new SpinnerItem();
    spinnerItem.setStep(0.01);
    unitCost.setEditorType(spinnerItem);

    ListGridField sku = new ListGridField("SKU");
    sku.setCanEdit(false);

    ListGridField description = new ListGridField("description");
    description.setShowHover(true);

    ListGridField category = new ListGridField("category");
    category.setCanEdit(false);

    ListGridField inStock = new ListGridField("inStock");
    inStock.setWidth(55);
    inStock.setAlign(Alignment.CENTER);

    ListGridField nextShipment = new ListGridField("nextShipent");
    nextShipment.setShowIfCondition(new ListGridFieldIfFunction() {
        public boolean execute(ListGrid grid, ListGridField field, int fieldNum) {
            return false;
        }
    });

    setFields(itemName, unitCost, sku, description, category, inStock);
    setCanEdit(true);
    setCanDragRecordsOut(true);
    setHoverWidth(200);
    setHoverHeight(20);
    setSelectionType(SelectionStyle.SINGLE);
}

From source file:com.dawg6.web.dhcalc.client.DHCalc.java

License:Open Source License

@Override
public void onModuleLoad() {

    Util.getInstance().setFormatter(new Util.Formatter() {

        @Override//from ww w .j a v  a2 s  .c o  m
        public String format(double d) {
            return NumberFormat.getFormat("#,###.####").format(d);
        }
    });

    Util.getInstance().setLogger(new ILogger() {

        @Override
        public void log(String message) {
            GWT.log(message);
        }

        @Override
        public void log(String message, Throwable t) {
            GWT.log(message, t);
        }
    });

    Window.setTitle("DH Damage Calculator (" + Version.getShortVersionString() + ")");

    final MainPanel panel = new MainPanel();

    Service.getInstance().execute(new AsyncTask() {

        @Override
        public void run(final AsyncTaskHandler handler) {

            Scheduler.get().scheduleDeferred(new Command() {

                @Override
                public void execute() {
                    RootPanel.get("main").add(panel);
                    handler.taskCompleted();
                }
            });

        }
    });

}

From source file:com.dawg6.web.dhcalc.client.LeaderboardPanel.java

License:Open Source License

protected void populateLeaders(Leaderboard result) {
    leaders = new ListBox();

    for (LeaderboardRow row : result.rows) {
        Long rift = null;/*  w  w  w .j  a  v a  2  s  .com*/
        Long time = null;
        Long rank = null;

        for (LeaderboardData d : row.data) {
            if (d.id.equals("Rank")) {
                rank = d.number;
            } else if (d.id.equals("RiftLevel")) {
                rift = d.number;
            } else if (d.id.equals("RiftTime")) {
                time = d.timestamp;
            }

            if ((rift != null) && (time != null) && (rank != null)) {
                break;
            }
        }

        if ((rift != null) && (time != null) && (rank != null)) {

            for (Account pl : row.players) {
                String btag = null;
                Long heroId = null;
                boolean isDh = false;

                for (LeaderboardData d : pl.data) {
                    if (d.id.equals("HeroClass")) {
                        if (d.string.equals("demon hunter")) {
                            isDh = true;
                        } else {
                            break;
                        }
                    } else if (d.id.equals("HeroBattleTag")) {
                        btag = d.string;
                    } else if (d.id.equals("HeroId")) {
                        heroId = d.number;
                    }

                    if (isDh && (btag != null) && (heroId != null))
                        break;
                }

                if (isDh && (btag != null) && (heroId != null)) {
                    long minutes = time / 60000L;
                    long seconds = (time - (minutes * 60000)) / 1000L;
                    String ts = NumberFormat.getFormat("00").format(minutes) + ":"
                            + NumberFormat.getFormat("00").format(seconds);
                    String label = rank + ") Level " + rift + ": " + ts + " - " + btag;
                    leaders.addItem(label, btag + "#" + heroId);
                }
            }
        }
    }

    HorizontalPanel row = new HorizontalPanel();
    row.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    row.setSpacing(5);

    row.add(leaders);

    this.table.setWidget(this.leaderboardRow, 0, row);
    this.table.getFlexCellFormatter().setColSpan(this.leaderboardRow, 0, 6);

    Anchor career = new Anchor("profile");
    career.setHref("javascript:void(0)");
    row.add(career);

    career.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            showCareer();
        }
    });

    Anchor hero = new Anchor("hero");
    hero.setHref("javascript:void(0)");
    row.add(hero);

    hero.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            showHero();
        }
    });

    hero.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            showHero();
        }
    });

    Anchor paperdoll = new Anchor("paperdoll");
    paperdoll.setHref("javascript:void(0)");
    row.add(paperdoll);

    paperdoll.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            showPaperdoll();
        }
    });

    Button button = new Button("Import Profile");
    row.add(button);

    button.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            getHeroList();
        }
    });
}

From source file:com.demo.gwt.app.ItemListGrid.java

License:Open Source License

public ItemListGrid(DataSource supplyItemDS) {

    setDataSource(supplyItemDS);/*from  www. jav  a 2s .c  om*/
    setUseAllDataSourceFields(true);

    ListGridField itemName = new ListGridField("itemName", "Name");
    itemName.setShowHover(true);
    ListGridField unitCost = new ListGridField("unitCost");

    unitCost.setCellFormatter(new CellFormatter() {
        public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null)
                return null;
            try {
                NumberFormat nf = NumberFormat.getFormat("##0.00");
                return "$" + nf.format(((Number) value).floatValue());
            } catch (Exception e) {
                return value.toString();
            }
        }
    });

    SpinnerItem spinnerItem = new SpinnerItem();
    spinnerItem.setStep(0.01);
    unitCost.setEditorProperties(spinnerItem);

    ListGridField sku = new ListGridField("SKU");
    sku.setCanEdit(false);

    ListGridField description = new ListGridField("description");
    description.setShowHover(true);

    ListGridField category = new ListGridField("category");
    category.setCanEdit(false);

    ListGridField inStock = new ListGridField("inStock");
    inStock.setWidth(55);
    inStock.setAlign(Alignment.CENTER);

    ListGridField nextShipment = new ListGridField("nextShipent");
    nextShipment.setShowIfCondition(new ListGridFieldIfFunction() {
        public boolean execute(ListGrid grid, ListGridField field, int fieldNum) {
            return false;
        }
    });

    setFields(itemName, unitCost, sku, description, category, inStock);
    setCanEdit(true);
    setCanDragRecordsOut(true);
    setHoverWidth(200);
    setHoverHeight(20);
    setSelectionType(SelectionStyle.SINGLE);
}

From source file:com.ephesoft.gxt.admin.client.presenter.kvextraction.AdvancedKVExtraction.AdvancedKVExtractionInputPanelPresenter.java

License:Open Source License

private Float getRange(Float val) {
    NumberFormat format = NumberFormat.getFormat(".##");
    Float range = val;
    String str = format.format(range);
    range = Float.valueOf(str);/*from   w  w  w.  ja  v  a 2s  .co m*/
    return range;
}

From source file:com.ephesoft.gxt.admin.client.view.kvextraction.KVExtractionGridView.java

License:Open Source License

public Float getRange(Float val) {
    NumberFormat format = NumberFormat.getFormat(".##");
    Float range = val;
    String str = format.format(range);
    range = Float.valueOf(str);/*from  ww w.  j a va 2 s  . c  o  m*/
    return range;
}

From source file:com.ephesoft.gxt.core.shared.util.NumberUtil.java

License:Open Source License

/**
 * Rounds off the double value up to 2 decimal digits.
 * /* w w w.  j av a2 s. co  m*/
 * example : 12.456 would be rounded off to 12.45, 12.534 would be rounded off to 12.53.
 * 
 * @param doubleValue {@link Double} value to be rounded off. If null, returns null.
 * @return {@link Double} rounded double value.
 */
public static final double getRoundedValue(double doubleValue) {
    return Double.parseDouble(NumberFormat.getFormat(ROUND_UPTO_TWO_DECIMAL_FORMAT).format(doubleValue));
}

From source file:com.ephesoft.gxt.core.shared.util.NumberUtil.java

License:Open Source License

/**
 * Rounds off the float value up to 2 decimal digits.
 * //from  w w w  .j  ava 2s .  c  o  m
 * example : 12.456 would be rounded off to 12.45, 12.534 would be rounded off to 12.53.
 * 
 * @param floatValue {@link Float} value to be rounded off. If null, returns null.
 * @return {@link Float} rounded float value.
 */
public static final float getRoundedValue(float floatValue) {
    return Float.parseFloat(NumberFormat.getFormat(ROUND_UPTO_TWO_DECIMAL_FORMAT).format(floatValue));
}