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.gwtcx.sample.serendipity.client.view.desktop.DashboardsDesktopView.java

License:Open Source License

public Chart createFunnelChart() {

    final Chart chart = new Chart().setType(Series.Type.FUNNEL)
            .setChartTitleText("<b>" + "Funnel Chart" + "</b>")
            // .setNeckWidth("100%")
            // .setNeckHeight("0%")
            .setMargin(50, 10, 60, 170).setPlotBackgroundColor((String) null).setPlotBorderWidth(null)
            .setPlotShadow(false)//from w ww  .j a v  a2s .c om
            .setFunnelPlotOptions(new FunnelPlotOptions()
                    .setFunnelDataLabels(new FunnelDataLabels().setAlign(Labels.Align.LEFT).setX(-300)
                            .setEnabled(true).setColor("#000000").setFormatter(new DataLabelsFormatter() {
                                public String format(DataLabelsData dataLabelsData) {
                                    // return dataLabelsData.getPointName();
                                    return "<b>"
                                            + dataLabelsData.getPointName() + "</b>: (" + NumberFormat
                                                    .getFormat("#,###").format(dataLabelsData.getYAsDouble())
                                            + ")";
                                }
                            })))
            .setLegend(new Legend().setEnabled(false)).setCredits(new Credits().setEnabled(false))
            .setToolTip(new ToolTip().setFormatter(new ToolTipFormatter() {
                public String format(ToolTipData toolTipData) {
                    return "<b>" + toolTipData.getPointName() + "</b>: "
                            + NumberFormat.getFormat("#,###").format(toolTipData.getYAsDouble());
                }
            }));

    // chart.setWidth("0%");

    chart.addSeries(chart.createSeries().setName("Lifecycle")
            .setPoints(new Point[] { new Point("Impressions", 15654), new Point("Clicks", 4064),
                    new Point("Downloads", 1987), new Point("Purchase", 976),
                    new Point("Repeat Purchase", 846) })

    /*
            
    chart.addSeries(chart.createSeries()
        .setName("Lifecycle")
        .setPoints(new Point[]{
      new Point("Repeat Purchase", 846),
      new Point("Purchase", 976),
      new Point("Downloads", 1987),
      new Point("Clicks", 4064),
      new Point("Impressions", 15654)
        })
            
    */

    );

    return chart;
}

From source file:com.gwtcx.sample.serendipity.client.view.desktop.DashboardsDesktopView.java

License:Open Source License

public Chart createPyramidChart() {

    final Chart chart = new Chart().setType(Series.Type.PYRAMID)
            .setChartTitleText("<b>" + "Pyramid Chart" + "</b>")
            // .setNeckWidth("100%")
            // .setNeckHeight("0%")
            .setMargin(50, 10, 60, 170).setPlotBackgroundColor((String) null).setPlotBorderWidth(null)
            .setPlotShadow(false)/* w  w w  . j  a v a2 s.  c om*/
            .setPyramidPlotOptions(new PyramidPlotOptions().setPyramidDataLabels(new PyramidDataLabels()
                    // .setAlign(Labels.Align.LEFT)
                    // .setX(-300)
                    .setEnabled(true).setColor("#000000").setFormatter(new DataLabelsFormatter() {
                        public String format(DataLabelsData dataLabelsData) {
                            // return dataLabelsData.getPointName();
                            return "<b>" + dataLabelsData.getPointName() + "</b>: ("
                                    + NumberFormat.getFormat("#,###").format(dataLabelsData.getYAsDouble())
                                    + ")";
                        }
                    })))
            .setLegend(new Legend().setEnabled(false)).setCredits(new Credits().setEnabled(false))
            .setToolTip(new ToolTip().setFormatter(new ToolTipFormatter() {
                public String format(ToolTipData toolTipData) {
                    return "<b>" + toolTipData.getPointName() + "</b>: "
                            + NumberFormat.getFormat("#,###").format(toolTipData.getYAsDouble());
                }
            }));

    // chart.setWidth("0%");

    chart.addSeries(chart.createSeries().setName("Lifecycle")
            .setPoints(new Point[] { new Point("Repeat Purchase", 846), new Point("Purchase", 976),
                    new Point("Downloads", 1987), new Point("Clicks", 4064),
                    new Point("Impressions", 15654) }));

    return chart;
}

From source file:com.gwtcx.sample.serendipity.client.view.desktop.DashboardsDesktopView.java

License:Open Source License

public Chart createStackedAreaChart() {

    final Chart chart = new Chart().setType(Series.Type.AREA)
            .setChartTitleText("Historic and Estimated Worldwide Population Growth by Region")
            .setChartSubtitleText("Source: Wikipedia.org")
            .setAreaPlotOptions(//from   www . j a  va2 s . co m
                    new AreaPlotOptions().setStacking(PlotOptions.Stacking.NORMAL).setLineColor("#666666")
                            .setLineWidth(1).setMarker(new Marker().setLineWidth(1).setLineColor("#666666")))
            .setToolTip(new ToolTip().setFormatter(new ToolTipFormatter() {
                public String format(ToolTipData toolTipData) {
                    return toolTipData.getXAsDouble() + ": "
                            + NumberFormat.getFormat("#,###").format(toolTipData.getYAsDouble()) + " millions";
                }
            }));

    chart.getXAxis().setCategories("1750", "1800", "1850", "1900", "1950", "1999", "2050")
            .setTickmarkPlacement(XAxis.TickmarkPlacement.ON).setAxisTitleText(null);

    chart.getYAxis().setAxisTitleText("Billions")
            .setLabels(new YAxisLabels().setFormatter(new AxisLabelsFormatter() {
                public String format(AxisLabelsData axisLabelsData) {
                    return String.valueOf(axisLabelsData.getValueAsLong() / 1000);
                }
            }));

    chart.addSeries(chart.createSeries().setName("Asia")
            .setPoints(new Number[] { 502, 635, 809, 947, 1402, 3634, 5268 }));
    chart.addSeries(chart.createSeries().setName("Africa")
            .setPoints(new Number[] { 106, 107, 111, 133, 221, 767, 1766 }));
    chart.addSeries(chart.createSeries().setName("Europe")
            .setPoints(new Number[] { 163, 203, 276, 408, 547, 729, 628 }));
    chart.addSeries(chart.createSeries().setName("America")
            .setPoints(new Number[] { 18, 31, 54, 156, 339, 818, 1201 }));
    chart.addSeries(chart.createSeries().setName("Oceania").setPoints(new Number[] { 2, 2, 2, 6, 13, 30, 46 }));

    return chart;
}

From source file:com.gwtcx.sample.serendipity.client.view.desktop.DashboardsDesktopView.java

License:Open Source License

public Chart createDynamicSplineChart() {

    final Chart chart = new Chart().setType(Series.Type.SPLINE).setMarginRight(10)
            .setChartTitleText("Live random data")
            .setBarPlotOptions(new BarPlotOptions().setDataLabels(new DataLabels().setEnabled(true)))
            .setLegend(new Legend().setEnabled(false)).setCredits(new Credits().setEnabled(false))
            .setToolTip(new ToolTip().setFormatter(new ToolTipFormatter() {
                public String format(ToolTipData toolTipData) {
                    return "<b>" + toolTipData.getSeriesName() + "</b><br/>"
                            + DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss")
                                    .format(new Date(toolTipData.getXAsLong()))
                            + "<br/>" + NumberFormat.getFormat("0.00").format(toolTipData.getYAsDouble());
                }//from  ww  w. jav  a 2 s .co  m
            }));

    chart.getXAxis().setType(Axis.Type.DATE_TIME).setTickPixelInterval(150);

    chart.getYAxis().setAxisTitleText("Value")
            .setPlotLines(chart.getYAxis().createPlotLine().setValue(0).setWidth(1).setColor("#808080"));

    final Series series = chart.createSeries();
    chart.addSeries(series.setName("Random data"));

    // Generate an array of random data
    long time = new Date().getTime();
    for (int i = -19; i <= 0; i++) {
        series.addPoint(time + i * 1000, com.google.gwt.user.client.Random.nextDouble());
    }

    Timer tempTimer = new Timer() {
        @Override
        public void run() {
            series.addPoint(new Date().getTime(), com.google.gwt.user.client.Random.nextDouble(), true, true,
                    true);
        }
    };
    tempTimer.scheduleRepeating(1000);

    return chart;
}

From source file:com.gwtplatform.carstore.client.application.report.renderer.ReportCell.java

License:Apache License

@Inject
ReportCell(Renderer uiRenderer) {
    this.uiRenderer = uiRenderer;
    this.numberFormat = NumberFormat.getFormat("#,##0.0#");
}

From source file:com.howard.lsp.lab8.lab9.stockwatcher.StockWatcher.client.StockWatcher.java

License:Open Source License

private void updateTable(StockPrice stockPrice) {
    // make sure the stock is still in our watch list
    if (!stocks.contains(stockPrice.getSymbol())) {
        return;//from   w ww. jav a2 s  . c  o m
    }

    int row = stocks.indexOf(stockPrice.getSymbol()) + 1;

    // Format the data in the Price and Change fields.
    String priceText = NumberFormat.getFormat("#,##0.00").format(stockPrice.getPrice());
    NumberFormat changeFormat = NumberFormat.getFormat("+#,##0.00;-#,##0.00");
    String changeText = changeFormat.format(stockPrice.getChange());
    String changePercentText = changeFormat.format(stockPrice.getChangePercent());

    // Populate the Price and Change fields with new data.
    stocksFlexTable.setText(row, 1, priceText);
    stocksFlexTable.setText(row, 2, changeText + " (" + changePercentText + "%)");
}

From source file:com.jitlogic.zico.client.ClientUtil.java

License:Open Source License

public static String formatDuration(Long time) {
    long t = time / 1000000L;

    return NumberFormat.getFormat("#,##0").format(t);
}

From source file:com.jitlogic.zico.client.views.traces.TraceRecordSearchDialog.java

License:Open Source License

private void doSearch() {

    TraceRecordSearchQuery expr = new TraceRecordSearchQuery();

    expr.setType(chkEql.getValue() ? TraceRecordSearchQuery.EQL_QUERY : TraceRecordSearchQuery.TXT_QUERY);

    GWT.log("Search Type=" + expr.getType());

    expr.setFlags((chkErrorsOnly.getValue() ? TraceRecordSearchQuery.ERRORS_ONLY : 0)
            | (chkMethodsWithAttrs.getValue() ? TraceRecordSearchQuery.METHODS_WITH_ATTRS : 0)
            | (chkClass.getValue() ? TraceRecordSearchQuery.SEARCH_CLASSES : 0)
            | (chkMethod.getValue() ? TraceRecordSearchQuery.SEARCH_METHODS : 0)
            | (chkAttribs.getValue() ? TraceRecordSearchQuery.SEARCH_ATTRS : 0)
            | (chkExceptionText.getValue() ? TraceRecordSearchQuery.SEARCH_EX_MSG : 0)
            | (chkIgnoreCase.getValue() ? TraceRecordSearchQuery.IGNORE_CASE : 0));

    expr.setSearchExpr(txtSearchFilter.getText().length() > 0 ? txtSearchFilter.getText() : null);

    GWT.log("Search flags=" + expr.getFlags());

    md.info(MDS, "Searching records ...");

    expr.setHostName(trace.getHostName());
    expr.setTraceOffs(trace.getDataOffs());
    expr.setMinTime(0);/*  w w w  . ja v a  2  s  .c o  m*/
    expr.setPath(rootPath);

    traceDataService.searchRecords(expr, new MethodCallback<TraceRecordSearchResult>() {
        @Override
        public void onFailure(Method method, Throwable e) {
            md.error(MDS, "Error performing search request", e);
        }

        @Override
        public void onSuccess(Method method, TraceRecordSearchResult response) {
            resultsStore.getList().clear();
            resultsStore.getList().addAll(response.getResult());
            lblSumStats.setText(response.getResult().size() + " methods, "
                    + NumberFormat.getFormat("###.0").format(response.getRecurPct())
                    + "% of trace execution time. " + "Time: "
                    + ClientUtil.formatDuration(response.getRecurTime()) + " non-recursive" + ", "
                    + ClientUtil.formatDuration(response.getMinTime()) + " min, " + ", "
                    + ClientUtil.formatDuration(response.getMaxTime()) + " max."

            );
            txtSearchFilter.setFocus(true);
            md.clear(MDS);
        }
    });
}

From source file:com.laskysoftware.GXTPagingGrid.client.GridExample.java

License:sencha.com license

@Override
public Widget asWidget() {
    if (root == null) {
        final NumberFormat number = NumberFormat.getFormat("0.00");

        ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 50, "Company");
        ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
        ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

        ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change");
        changeCol.setCell(new AbstractCell<Double>() {

            @Override//from   w ww  . j av  a2  s . co  m
            public void render(Context context, Double value, SafeHtmlBuilder sb) {
                String style = "style='color: " + (value < 0 ? "red" : "green") + "'";
                String v = number.format(value);
                sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>");
            }
        });

        ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100,
                "Last Updated");
        lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy")));

        List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
        l.add(nameCol);
        l.add(symbolCol);
        l.add(lastCol);
        l.add(changeCol);
        l.add(lastTransCol);
        ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

        ListStore<Stock> store = new ListStore<Stock>(props.key());
        store.addAll(TestData.getStocks());

        root = new ContentPanel();
        root.setHeadingText("Basic Grid");
        root.getHeader().setIcon(ExampleImages.INSTANCE.table());
        root.setPixelSize(600, 300);
        root.addStyleName("margin-10");

        ToolButton info = new ToolButton(ToolButton.QUESTION);
        ToolTipConfig config = new ToolTipConfig("Example Info",
                "This examples includes resizable panel, reorderable columns and grid state.");
        config.setMaxWidth(225);
        info.setToolTipConfig(config);
        root.addTool(info);

        new Resizable(root, Dir.E, Dir.SE, Dir.S);

        final Grid<Stock> grid = new Grid<Stock>(store, cm);
        grid.getView().setAutoExpandColumn(nameCol);
        grid.getView().setStripeRows(true);
        grid.getView().setColumnLines(true);
        grid.setBorders(false);

        grid.setColumnReordering(true);
        grid.setStateful(true);
        grid.setStateId("gridExample");

        GridStateHandler<Stock> state = new GridStateHandler<Stock>(grid);
        state.loadState();

        ToolBar toolBar = new ToolBar();
        toolBar.add(new LabelToolItem("Selection Mode: "));

        SimpleComboBox<String> type = new SimpleComboBox<String>(new StringLabelProvider<String>());
        type.setTriggerAction(TriggerAction.ALL);
        type.setEditable(false);
        type.setWidth(100);
        type.add("Row");
        type.add("Cell");
        type.setValue("Row");
        // we want to change selection model on select, not value change which fires on blur
        type.addSelectionHandler(new SelectionHandler<String>() {

            @Override
            public void onSelection(SelectionEvent<String> event) {
                boolean cell = event.getSelectedItem().equals("Cell");
                if (cell) {
                    CellSelectionModel<Stock> c = new CellSelectionModel<Stock>();
                    c.addCellSelectionChangedHandler(new CellSelectionChangedHandler<Stock>() {

                        @Override
                        public void onCellSelectionChanged(CellSelectionChangedEvent<Stock> event) {

                        }
                    });

                    grid.setSelectionModel(c);
                } else {
                    grid.setSelectionModel(new GridSelectionModel<Stock>());
                }
            }
        });
        type.addValueChangeHandler(new ValueChangeHandler<String>() {

            @Override
            public void onValueChange(ValueChangeEvent<String> event) {

            }
        });
        toolBar.add(type);

        VerticalLayoutContainer con = new VerticalLayoutContainer();
        root.setWidget(con);

        con.add(toolBar, new VerticalLayoutData(1, -1));
        con.add(grid, new VerticalLayoutData(1, 1));

        // needed to enable quicktips (qtitle for the heading and qtip for the
        // content) that are setup in the change GridCellRenderer
        new QuickTip(grid);
    }

    return root;
}

From source file:com.laskysoftware.GXTPagingGrid.client.GridExampleLocking.java

License:sencha.com license

@Override
public Widget asWidget() {
    if (root == null) {
        final NumberFormat number = NumberFormat.getFormat("0.00");

        ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 50,
                SafeHtmlUtils.fromTrustedString("<b>Company</b>"));

        ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
        ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

        ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change");
        changeCol.setCell(new AbstractCell<Double>() {

            @Override//ww  w  .j  a va2  s .c om
            public void render(Context context, Double value, SafeHtmlBuilder sb) {
                String style = "style='color: " + (value < 0 ? "red" : "green") + "'";
                String v = number.format(value);
                sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>");
            }
        });

        ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100,
                "Last Updated");
        lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy")));

        List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
        //Remove name from main set of columns
        //l.add(nameCol);
        l.add(symbolCol);
        l.add(lastCol);
        l.add(changeCol);
        l.add(lastTransCol);

        //create two column models, one for the locked section
        ColumnModel<Stock> lockedCm = new ColumnModel<Stock>(
                Collections.<ColumnConfig<Stock, ?>>singletonList(nameCol));
        ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

        ListStore<Stock> store = new ListStore<Stock>(props.key());
        store.addAll(TestData.getStocks());

        root = new ContentPanel();
        root.setHeadingText("Locked Grid Sample");
        root.setPixelSize(600, 300);

        final Resizable resizable = new Resizable(root, Dir.E, Dir.SE, Dir.S);
        root.addExpandHandler(new ExpandHandler() {
            @Override
            public void onExpand(ExpandEvent event) {
                resizable.setEnabled(true);
            }
        });
        root.addCollapseHandler(new CollapseHandler() {
            @Override
            public void onCollapse(CollapseEvent event) {
                resizable.setEnabled(false);
            }
        });

        //locked grid
        final Grid<Stock> lockedGrid = new Grid<Stock>(store, lockedCm) {
            @Override
            protected Size adjustSize(Size size) {
                //this is a tricky part - convince the grid to draw just slightly too wide
                //and so push the scrollbar out of sight
                return new Size(size.getWidth() + XDOM.getScrollBarWidth() - 1, size.getHeight());
            }
        };
        lockedGrid.setView(new GridView<Stock>() {
            {
                this.scrollOffset = 0;
            }
        });
        //require columns to always fit, preventing scrollbar
        lockedGrid.getView().setForceFit(true);

        //main grid, with horiz scrollbar
        final Grid<Stock> grid = new Grid<Stock>(store, cm);
        //don't want this feature, want to encourage horizontal scrollbars
        //grid.getView().setAutoExpandColumn(nameCol);
        grid.getView().setStripeRows(true);
        grid.getView().setColumnLines(true);
        grid.setBorders(false);

        grid.setColumnReordering(true);
        grid.setStateful(true);
        grid.setStateId("gridExample");

        //link scrolling
        lockedGrid.addBodyScrollHandler(new BodyScrollHandler() {
            @Override
            public void onBodyScroll(BodyScrollEvent event) {
                grid.getView().getScroller().scrollTo(ScrollDirection.TOP, event.getScrollTop());
            }
        });
        grid.addBodyScrollHandler(new BodyScrollHandler() {
            @Override
            public void onBodyScroll(BodyScrollEvent event) {
                lockedGrid.getView().getScroller().scrollTo(ScrollDirection.TOP, event.getScrollTop());
            }
        });

        HorizontalLayoutContainer gridWrapper = new HorizontalLayoutContainer();
        root.setWidget(gridWrapper);

        //add locked column, only 300px wide (in this example, use layouts to change how this works
        HorizontalLayoutData lockedColumnLayoutData = new HorizontalLayoutData(300, 1.0);

        //this is optional - without this, you get a little offset issue at the very bottom of the non-locked grid
        lockedColumnLayoutData.setMargins(new Margins(0, 0, XDOM.getScrollBarWidth(), 0));

        gridWrapper.add(lockedGrid, lockedColumnLayoutData);

        //add non-locked section, taking up all remaining width
        gridWrapper.add(grid, new HorizontalLayoutData(1.0, 1.0));
    }

    return root;
}