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.eurekastreams.web.client.ui.pages.metrics.MetricsSummaryContent.java

License:Apache License

/**
 * Build the page.//from w  ww . j  a  v  a 2  s .  c  om
 * 
 * @param inMetrics
 *            the UsageMetricSummaryDTO.
 */
private void buildPage(final UsageMetricSummaryDTO inMetrics) {
    // displayed directly
    long uniqueVisitorCount = inMetrics.getAverageDailyUniqueVisitorCount();
    long streamViewerCount = inMetrics.getAverageDailyStreamViewerCount();
    long streamViewCount = inMetrics.getAverageDailyStreamViewCount();
    long avgActivityResponseTime = inMetrics.getAverageDailyActivityResponseTime();

    // used in calculations
    long streamContributorCount = inMetrics.getAverageDailyStreamContributorCount();
    long pageViewCount = inMetrics.getAverageDailyPageViewCount();
    long messageCount = inMetrics.getAverageDailyMessageCount();

    // calculated and displayed.
    double pageViewsPerUniqueVisitor = uniqueVisitorCount == 0 ? 0
            : (double) pageViewCount / (double) uniqueVisitorCount;

    double streamViewsPerStreamViewer = streamViewerCount == 0 ? 0
            : (double) streamViewCount / (double) streamViewerCount;

    double messagesPostedPerStreamContributor = streamContributorCount == 0 ? 0
            : (double) messageCount / (double) streamContributorCount;

    NumberFormat formatter = NumberFormat.getFormat("0.0");

    uniqueVisitorsUi.setInnerText(Long.toString(uniqueVisitorCount));
    visitsPerVisitorUi.setInnerText(formatter.format(pageViewsPerUniqueVisitor));
    streamViewersUi.setInnerText(Long.toString(streamViewerCount));
    streamViewsPerSpectatorUi.setInnerText(formatter.format(streamViewsPerStreamViewer));
    postersUi.setInnerText(Long.toString(streamContributorCount));
    messagesPerContributorUi.setInnerText(formatter.format(messagesPostedPerStreamContributor));
    averageTimeToResponseUi.setInnerText(Long.toString(avgActivityResponseTime));
}

From source file:org.geomajas.example.gwt.client.samples.controller.CustomControllerSample.java

License:Open Source License

public Canvas getViewPanel() {
    VLayout layout = new VLayout();
    layout.setWidth100();//  w w w. ja  v a 2  s  .  co  m
    layout.setHeight100();

    VLayout mapLayout = new VLayout();
    mapLayout.setShowEdges(true);
    mapLayout.setHeight("60%");

    // Map with ID wmsMap is defined in the XML configuration. (mapWms.xml)
    final MapWidget map = new MapWidget("mapWms", "gwt-samples");
    mapLayout.addMember(map);

    VLayout labelLayout = new VLayout();
    final Label label = new Label();
    labelLayout.addMember(label);

    // Create the custom controller:
    GraphicsController customController = new AbstractGraphicsController(map) {

        public void onMouseMove(MouseMoveEvent event) {
            Coordinate screenPosition = getScreenPosition(event);
            Coordinate worldPosition = getWorldPosition(event);
            String x = NumberFormat.getFormat("0.000").format(worldPosition.getX());
            String y = NumberFormat.getFormat("0.000").format(worldPosition.getY());
            label.setContents(I18nProvider.getSampleMessages().customControllerScreenCoordinates() + " = "
                    + screenPosition + "<br/>"
                    + I18nProvider.getSampleMessages().customControllerWorldCoordinates() + " = (" + x + ", "
                    + y + ")");
        }

    };

    // Set the controller on the map:
    map.setController(customController);

    layout.addMember(mapLayout);
    layout.addMember(labelLayout);
    return layout;
}

From source file:org.geomajas.example.gwt.client.samples.controller.MouseMoveListenerSample.java

License:Open Source License

/**
 * @return The viewPanel Canvas/*from   www . j  a  v a  2s .  c om*/
 */
public Canvas getViewPanel() {
    VLayout layout = new VLayout();
    layout.setWidth100();
    layout.setHeight100();

    // Create the map, using the wmsMap configuration (mapOsm.xml):
    final MapWidget map = new MapWidget("mapOsm", "gwt-samples");

    VLayout mapLayout = new VLayout();
    mapLayout.setShowEdges(true);
    mapLayout.setHeight("60%");
    mapLayout.addMember(map);

    VLayout labelLayout = new VLayout();
    final Label label = new Label();
    labelLayout.addMember(label);

    /**
     * Listener implementation that prints out the mouse position.
     * 
     * @author Pieter De Graef
     */
    class MouseMoveListener extends AbstractListener {

        public void onMouseMove(ListenerEvent event) {
            Coordinate screenPosition = event.getScreenPosition();
            Coordinate worldPosition = event.getWorldPosition();
            String x = NumberFormat.getFormat("0.000").format(worldPosition.getX());
            String y = NumberFormat.getFormat("0.000").format(worldPosition.getY());
            label.setContents(I18nProvider.getSampleMessages().customControllerScreenCoordinates() + " = "
                    + screenPosition + "<br/>"
                    + I18nProvider.getSampleMessages().customControllerWorldCoordinates() + " = (" + x + ", "
                    + y + ")");
        }
    }
    map.addListener(new MouseMoveListener());

    layout.addMember(mapLayout);
    layout.addMember(labelLayout);

    return layout;
}

From source file:org.geomajas.gwt.client.widget.ScaleConverter.java

License:Open Source License

/**
 * Convert a scale to a string representation.
 *
 * @param scale scale to convert/* www .jav  a 2s .  c o  m*/
 * @param precision precision for the scale, or 0
 * @param significantDigits maximum number of significant digits
 * @return string representation for the scale
 */
public static String scaleToString(double scale, int precision, int significantDigits) {
    NumberFormat numberFormat = NumberFormat.getFormat("###,###");
    if (scale > 0 && scale < 1.0) {
        int denominator = round((int) Math.round(1.0 / scale), precision, significantDigits);
        return "1 : " + numberFormat.format(denominator);
    } else if (scale >= 1.0) {
        int nominator = round((int) Math.round(scale), precision, significantDigits);
        return numberFormat.format(nominator) + " : 1";
    } else {
        return ERROR_SCALE;
    }
}

From source file:org.geomajas.gwt.client.widget.ScaleConverter.java

License:Open Source License

/**
 * Parse scale from string representation.
 *
 * @param value to parse/*from   ww w.j  a  v  a 2 s  .c o  m*/
 * @return scale value
 */
public static Double stringToScale(String value) {
    NumberFormat numberFormat = NumberFormat.getFormat("###,###");
    String[] scale2 = value.split(":");
    if (scale2.length == 1) {
        return 1.0 / numberFormat.parse(scale2[0].trim());
    } else {
        return numberFormat.parse(scale2[0].trim()) / numberFormat.parse(scale2[1].trim());
    }
}

From source file:org.geomajas.gwt.example.client.sample.controller.CustomControllerSample.java

License:Open Source License

public Canvas getViewPanel() {
    VLayout layout = new VLayout();
    layout.setWidth100();/*ww  w. j  av a2 s.co m*/
    layout.setHeight100();

    VLayout mapLayout = new VLayout();
    mapLayout.setShowEdges(true);
    mapLayout.setHeight("60%");

    // Map with ID wmsMap is defined in the XML configuration. (mapWms.xml)
    final MapWidget map = new MapWidget("mapWms", "gwtExample");
    mapLayout.addMember(map);

    VLayout labelLayout = new VLayout();
    final Label label = new Label();
    labelLayout.addMember(label);

    // Create the custom controller:
    GraphicsController customController = new AbstractGraphicsController(map) {

        public void onMouseMove(MouseMoveEvent event) {
            Coordinate screenPosition = getScreenPosition(event);
            Coordinate worldPosition = getWorldPosition(event);
            String x = NumberFormat.getFormat("0.000").format(worldPosition.getX());
            String y = NumberFormat.getFormat("0.000").format(worldPosition.getY());
            label.setContents(MESSAGES.customControllerScreenCoordinates() + " = " + screenPosition + "<br/>"
                    + MESSAGES.customControllerWorldCoordinates() + " = (" + x + ", " + y + ")");
        }

    };

    // Set the controller on the map:
    map.setController(customController);

    layout.addMember(mapLayout);
    layout.addMember(labelLayout);
    return layout;
}

From source file:org.geomajas.gwt.example.client.sample.controller.MouseMoveListenerSample.java

License:Open Source License

/**
 * @return The viewPanel Canvas/*from   w ww.ja  v  a2s .c om*/
 */
public Canvas getViewPanel() {
    VLayout layout = new VLayout();
    layout.setWidth100();
    layout.setHeight100();

    // Create the map, using the wmsMap configuration (mapOsm.xml):
    final MapWidget map = new MapWidget("mapOsm", "gwtExample");

    VLayout mapLayout = new VLayout();
    mapLayout.setShowEdges(true);
    mapLayout.setHeight("60%");
    mapLayout.addMember(map);

    VLayout labelLayout = new VLayout();
    final Label label = new Label();
    labelLayout.addMember(label);

    /**
     * Listener implementation that prints out the mouse position.
     * 
     * @author Pieter De Graef
     */
    class MouseMoveListener extends AbstractListener {

        public void onMouseMove(ListenerEvent event) {
            Coordinate screenPosition = event.getScreenPosition();
            Coordinate worldPosition = event.getWorldPosition();
            String x = NumberFormat.getFormat("0.000").format(worldPosition.getX());
            String y = NumberFormat.getFormat("0.000").format(worldPosition.getY());
            label.setContents(MESSAGES.customControllerScreenCoordinates() + " = " + screenPosition + "<br/>"
                    + MESSAGES.customControllerWorldCoordinates() + " = (" + x + ", " + y + ")");
        }
    }
    map.addListener(new MouseMoveListener());

    layout.addMember(mapLayout);
    layout.addMember(labelLayout);

    return layout;
}

From source file:org.geomajas.plugin.deskmanager.client.gwt.manager.service.SensibleScaleConverter.java

License:Open Source License

public static String scaleToString(ScaleInfo scale) {
    NumberFormat numberFormat = NumberFormat.getFormat("###,###");
    return numberFormat.format(scale.getNumerator()) + " : " + numberFormat.format(scale.getDenominator());
}

From source file:org.geomajas.plugin.deskmanager.client.gwt.manager.service.SensibleScaleConverter.java

License:Open Source License

public static ScaleInfo stringToScale(String value) {
    NumberFormat numberFormat = NumberFormat.getFormat("###,###");
    String[] scale2 = value.split(":");
    ScaleInfo si;/*from   w w  w  . java2 s .  co m*/
    if (scale2.length == 1) {
        si = new ScaleInfo(1D, numberFormat.parse(scale2[0].trim()));
    } else {
        si = new ScaleInfo(numberFormat.parse(scale2[0].trim()), numberFormat.parse(scale2[1].trim()));
    }
    si.setPixelPerUnit(si.getNumerator() / si.getDenominator() * PPM);
    return si;
}

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

License:Open Source License

private void initField(NumberField field) {
    field.setFieldLabel(getField().getLabel());
    field.setInputStyleAttribute("text-align", "right");

    // format/*from  w  ww . j  a  v a2 s .c  o m*/
    String format = getField().getFormat();
    if (!format.equals("")) {
        field.setFormat(NumberFormat.getFormat(format));
        addNumListener(field);
    }
    String value = getField().getValue();
    if (value.matches(IRegExpUtils.FLOAT)) {
        field.setValue(Double.valueOf(value));
        field.fireEvent(Events.Change);
    }
}