Example usage for com.google.gwt.i18n.client NumberFormat getDecimalFormat

List of usage examples for com.google.gwt.i18n.client NumberFormat getDecimalFormat

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client NumberFormat getDecimalFormat.

Prototype

public static NumberFormat getDecimalFormat() 

Source Link

Document

Provides the standard decimal format for the default locale.

Usage

From source file:org.geomajas.gwt.client.util.DistanceFormat.java

License:Open Source License

/**
 * Area formatting method. Requires an area as parameter, expressed in the CRS units of the given map.
 * /*from ww  w  . jav  a  2s .co  m*/
 * @param map
 *            The map for which an area should be formatted. This map may be configured to use the metric system or
 *            the English system.
 * @param area
 *            The original area, expressed in the coordinate reference system of the given map.
 * @return Returns a string that is the formatted area of the given area. Preference goes to meters or yards
 *            (depending on the configured unit type), but when the number is larger than meters (or yards), it will
 *            switch automatically to kilometers/miles.
 */
public static String asMapArea(MapWidget map, double area) {
    double unitLength = map.getUnitLength();
    double distance = area * unitLength * unitLength;

    String unit = "m";
    if (map.getMapModel().getMapInfo().getDisplayUnitType() == UnitType.METRIC) {
        // Right now, the distance is expressed in meter. Switch to km?
        if (distance > (METERS_IN_KM * METERS_IN_KM)) {
            distance /= (METERS_IN_KM * METERS_IN_KM);
            unit = "km";
        }
    } else if (map.getMapModel().getMapInfo().getDisplayUnitType() == UnitType.ENGLISH) {
        if (distance > (METERS_IN_MILE * METERS_IN_MILE)) {
            // Switch to mile:
            distance = distance / (METERS_IN_MILE * METERS_IN_MILE);
            unit = "mi";
        } else {
            distance /= (METERS_IN_YARD * METERS_IN_YARD); // use yards.
            unit = "yd";
        }
    } else if (map.getMapModel().getMapInfo().getDisplayUnitType() == UnitType.CRS) {
        unit = "u";
    }

    String formatted = NumberFormat.getDecimalFormat().format(distance);
    return formatted + unit + "²";
}

From source file:org.geomajas.gwt2.client.widget.control.scalebar.Scalebar.java

License:Open Source License

/**
 * format to human readable string converting to unit type.
 * //from ww w.j  a v a  2s  . co m
 * @param units
 * @return
 */
private String formatUnits(int units) {
    switch (unitType) {
    case ENGLISH:
        return NumberFormat.getDecimalFormat().format(units) + (widthInUnitsIsMiles ? " mi" : " yd");
    case ENGLISH_FOOT:
        return NumberFormat.getDecimalFormat().format(units) + (widthInUnitsIsMiles ? " mi" : " ft");
    case METRIC:
        if (units < 10000) {
            return NumberFormat.getDecimalFormat().format(units) + " m";
        } else {
            return NumberFormat.getDecimalFormat().format((double) units / 1000) + " km";
        }

    case CRS:
        return NumberFormat.getDecimalFormat().format(units) + " u";

    default:
        return "??";
    }
}

From source file:org.geomajas.gwt2.plugin.corewidget.example.client.sample.feature.featureinfo.MyAttributeWidgetFactory.java

License:Open Source License

/**
 * Create a custom widget for attributes of type {@link Double}. Simply applies a number
 * formatter on the attribute value and puts it in a panel.
 *
 * @param attributeValue the value of the attribute.
 * @return the custom widget./*from  ww  w .ja  va2s.  co  m*/
 */
private Widget createDoubleWidget(DoubleAttribute attributeValue) {
    VerticalPanel panel = new VerticalPanel();
    String formattedNumber = NumberFormat.getDecimalFormat().format(attributeValue.getValue());
    panel.getElement().setInnerText(formattedNumber);
    return panel;
}

From source file:org.geosdi.geoplatform.gui.client.widget.tab.binding.GPLayerDisplayBinding.java

License:Open Source License

@Override
public FormPanel createFormPanel() {
    FormPanel fp = new FormPanel();
    fp.setHeaderVisible(false);/*w w  w.ja  va  2 s . c o  m*/
    fp.setFrame(true);
    fp.setLayout(new FlowLayout());

    setSliderProperties();

    this.maxScale = new NumberField() {

        @Override
        public void setValue(Number value) {
            super.setValue(value);
            if (value != null) {
                NumberFormat nf = NumberFormat.getDecimalFormat();
                String formattedValue = nf.format(value.floatValue()).replaceAll(",", "");
                maxScale.setRawValue(formattedValue);
                logger.log(Level.INFO, "Updating maxScale field: " + formattedValue);
            }
        }
    };
    this.maxScale.setPropertyEditorType(Float.class);
    this.maxScale.setFieldLabel(LayerModuleConstants.INSTANCE.GPLayerDisplayBinding_maxScaleNumberFieldText());

    this.minScale = new NumberField() {

        @Override
        public void setValue(Number value) {
            super.setValue(value);
            if (value != null) {
                NumberFormat nf = NumberFormat.getDecimalFormat();
                String formattedValue = nf.format(value.floatValue()).replaceAll(",", "");
                minScale.setRawValue(formattedValue);
                logger.log(Level.INFO, "Updating minScale field: " + formattedValue);
            }
        }
    };
    this.minScale.setPropertyEditorType(Float.class);
    this.minScale.setFieldLabel(LayerModuleConstants.INSTANCE.GPLayerDisplayBinding_minScaleNumberFieldText());
    Button removeScale = new Button(
            LayerModuleConstants.INSTANCE.GPLayerDisplayBinding_removeLimitsButtonText(),
            AbstractImagePrototype.create(BasicWidgetResources.ICONS.delete()),
            new SelectionListener<ButtonEvent>() {

                @Override
                public void componentSelected(ButtonEvent ce) {
                    GeoPlatformMessage.confirmMessage(
                            LayerModuleConstants.INSTANCE.GPLayerDisplayBinding_removeLimitsMessageTitleText(),
                            LayerModuleConstants.INSTANCE.GPLayerDisplayBinding_removeLimitsMessageBodyText(),
                            new Listener<MessageBoxEvent>() {
                                @Override
                                public void handleEvent(MessageBoxEvent be) {
                                    if (Dialog.YES.equals(be.getButtonClicked().getItemId())) {
                                        removeScaleLimits();
                                    }
                                }
                            });
                }
            });

    final FieldSet scaleFieldSet = new FieldSet();
    scaleFieldSet.setLayout(new FormLayout());
    scaleFieldSet.setHeadingHtml(LayerModuleConstants.INSTANCE.GPLayerDisplayBinding_limitsByScaleFieldText());
    scaleFieldSet.add(maxScale);
    scaleFieldSet.add(minScale);
    scaleFieldSet.add(removeScale);

    final FieldSet opacityFieldSet = new FieldSet();
    opacityFieldSet.setHeadingHtml(LayerModuleConstants.INSTANCE.GPLayerDisplayBinding_opacityHeadingText());
    opacityFieldSet.setCollapsible(true);

    opacityFieldSet.addListener(Events.Collapse, new Listener<ComponentEvent>() {

        @Override
        public void handleEvent(ComponentEvent be) {
            ((DisplayLayersTabItem) opacityFieldSet.getParent().getParent()).updateWindowSize();
        }

    });

    sliderField = new GPSliderField(this.slider);
    sliderField.setName(GPRasterKeyValue.OPACITY.toString());

    sliderField.removeAllListeners();

    opacityFieldSet.add(sliderField);

    final FieldSet singleTileFieldSet = new FieldSet();
    singleTileFieldSet
            .setHeadingHtml(LayerModuleConstants.INSTANCE.GPLayerDisplayBinding_singleTileRequestHeadingText());

    this.singleTileComboBox = new ComboBox<GPBooleanBeanModel>() {
        @Override
        protected void onSelect(GPBooleanBeanModel model, int index) {
            super.onSelect(model, index);
            singleTileRequestBinding.updateModel();
        }
    };
    this.singleTileComboBoxStore = new ListStore<GPBooleanBeanModel>();
    this.singleTileComboBoxStore.add(GPBooleanBeanModel.getBooleanInstances());
    this.singleTileComboBox.setStore(this.singleTileComboBoxStore);
    this.singleTileComboBox.setWidth(200);
    //        this.singleTileComboBox.setEmptyText();
    this.singleTileComboBox.setTypeAhead(true);
    this.singleTileComboBox.setTriggerAction(ComboBox.TriggerAction.ALL);
    this.singleTileComboBox.setDisplayField(GPBooleanBeanModel.GPBooleanKeyValue.Boolean.getValue());
    singleTileFieldSet.add(this.singleTileComboBox);

    fp.add(scaleFieldSet);
    fp.add(opacityFieldSet);
    fp.add(singleTileFieldSet);

    this.singleTileRequestBinding = new GPRasterComboSingleTileRequestBinding(this.singleTileComboBox,
            GPBooleanBeanModel.GPBooleanKeyValue.Boolean.getValue());

    return fp;
}

From source file:org.geosdi.geoplatform.gui.client.widget.viewport.ViewportGridFieldSet.java

License:Open Source License

private Grid generateGrid() {
    List<ColumnConfig> configs = Lists.<ColumnConfig>newArrayList();
    final String idIsDefaultColumn = MapModuleConstants.INSTANCE.ViewportGridFieldSet_defaultViewportText();
    CheckColumnConfig isDefaultColumn = new CheckColumnConfig(ViewportEnum.IS_DEFAULT.toString(),
            idIsDefaultColumn, 50);/* w w  w .j  a va2s . c om*/
    configs.add(isDefaultColumn);
    final String idNameColumn = MapModuleConstants.INSTANCE.ViewportGridFieldSet_nameColumnText();
    ColumnConfig nameColumnConfig = new ColumnConfig(ViewportEnum.NAME.toString(), idNameColumn, 80);
    nameColumnConfig.setEditor(new CellEditor(new GPSecureStringTextField()));
    configs.add(nameColumnConfig);
    final String idDescriptionColumn = MapModuleConstants.INSTANCE.ViewportGridFieldSet_descriptionColumnText();
    ColumnConfig descriptionColumnConfig = new ColumnConfig(ViewportEnum.DESCRIPTION.toString(),
            idDescriptionColumn, 80);
    descriptionColumnConfig.setEditor(new CellEditor(new GPSecureStringTextField()));
    configs.add(descriptionColumnConfig);
    ColumnConfig minXColumnConfig = new ColumnConfig(ViewportEnum.LOWER_LEFT_X.toString(),
            MapModuleConstants.INSTANCE.ViewportGridFieldSet_minXColumnText(), 70);
    minXColumnConfig.setNumberFormat(NumberFormat.getDecimalFormat());
    NumberField numberFieldBBOX = new NumberField();
    numberFieldBBOX.setMaxValue(180);
    numberFieldBBOX.setMinValue(-180);
    minXColumnConfig.setEditor(new CellEditor(numberFieldBBOX));
    configs.add(minXColumnConfig);
    ColumnConfig minYColumnConfig = new ColumnConfig(ViewportEnum.LOWER_LEFT_Y.toString(),
            MapModuleConstants.INSTANCE.ViewportGridFieldSet_minYColumnText(), 70);
    minYColumnConfig.setNumberFormat(NumberFormat.getDecimalFormat());
    NumberField numberFieldBBOX2 = new NumberField();
    numberFieldBBOX2.setMaxValue(90);
    numberFieldBBOX2.setMinValue(90);
    minYColumnConfig.setEditor(new CellEditor(numberFieldBBOX2));
    configs.add(minYColumnConfig);
    ColumnConfig maxXColumnConfig = new ColumnConfig(ViewportEnum.UPPER_RIGHT_X.toString(),
            MapModuleConstants.INSTANCE.ViewportGridFieldSet_maxXColumnText(), 70);
    maxXColumnConfig.setNumberFormat(NumberFormat.getDecimalFormat());
    NumberField numberFieldBBOX3 = new NumberField();
    numberFieldBBOX3.setMaxValue(180);
    numberFieldBBOX3.setMinValue(-180);
    maxXColumnConfig.setEditor(new CellEditor(numberFieldBBOX3));
    configs.add(maxXColumnConfig);
    ColumnConfig maxYColumnConfig = new ColumnConfig(ViewportEnum.UPPER_RIGHT_Y.toString(),
            MapModuleConstants.INSTANCE.ViewportGridFieldSet_maxYColumnText(), 70);
    maxYColumnConfig.setNumberFormat(NumberFormat.getDecimalFormat());
    NumberField numberFieldBBOX4 = new NumberField();
    numberFieldBBOX4.setMaxValue(90);
    numberFieldBBOX4.setMinValue(-90);
    maxYColumnConfig.setEditor(new CellEditor(numberFieldBBOX4));
    configs.add(maxYColumnConfig);

    ColumnConfig zoomLevelColumnConfig = new ColumnConfig(ViewportEnum.ZOOM_LEVEL.toString(),
            MapModuleConstants.INSTANCE.ViewportGridFieldSet_zoomLevelColumnText(), 70);
    zoomLevelColumnConfig.setNumberFormat(NumberFormat.getDecimalFormat());
    NumberField numberFieldZoom = new NumberField();
    numberFieldZoom.setAllowNegative(Boolean.FALSE);
    numberFieldZoom.setMaxValue(MapLayoutWidget.NUM_ZOOM_LEVEL);
    numberFieldZoom.setMinValue(0);
    zoomLevelColumnConfig.setEditor(new CellEditor(numberFieldZoom));
    configs.add(zoomLevelColumnConfig);
    CheckBoxSelectionModel<GPClientViewport> checkBoxSelectionModel = new CheckBoxSelectionModel<GPClientViewport>();
    checkBoxSelectionModel.setSelectionMode(SelectionMode.MULTI);
    checkBoxSelectionModel.addSelectionChangedListener(new SelectionChangedListener<GPClientViewport>() {
        @Override
        public void selectionChanged(SelectionChangedEvent<GPClientViewport> se) {
            if (se.getSelection().isEmpty()) {
                deleteViewportButton.disable();
                gotoViewportButton.disable();
                setDefaultViewportButton.disable();
            } else {
                deleteViewportButton.enable();
                gotoViewportButton.enable();
                setDefaultViewportButton.enable();
            }
        }
    });
    checkBoxSelectionModel.setLocked(Boolean.FALSE);
    configs.add(checkBoxSelectionModel.getColumn());
    this.viewportGrid = new EditorGrid<GPClientViewport>(store, new ColumnModel(configs));
    this.viewportGrid.addPlugin(checkBoxSelectionModel);
    this.viewportGrid.setSelectionModel(checkBoxSelectionModel);
    this.viewportGrid.setBorders(Boolean.TRUE);
    this.viewportGrid.setStripeRows(Boolean.TRUE);
    this.viewportGrid.setBorders(Boolean.TRUE);
    this.viewportGrid.setClicksToEdit(EditorGrid.ClicksToEdit.TWO);
    viewportGrid.setStyleAttribute("borderTop", "none");
    viewportGrid.setAutoExpandColumn(ViewportEnum.DESCRIPTION.toString());
    viewportGrid.setAutoExpandMin(120);
    viewportGrid.setSize("250px", "300px");
    return viewportGrid;
}

From source file:org.gk.engine.client.build.grid.field.GAggregationRowBuilder.java

License:Open Source License

/**
 * ?NumberFormat/*from   w  w  w  . ja  va  2s .c  om*/
 * 
 * @param format
 * @return NumberFormat
 */
private NumberFormat getSummaryFormat(String format) {
    NumberFormat nf = null;
    if (format.equalsIgnoreCase("currency")) {
        nf = NumberFormat.getCurrencyFormat();
    } else if (format.equalsIgnoreCase("scientific")) {
        nf = NumberFormat.getScientificFormat();
    } else if (format.equalsIgnoreCase("decimal")) {
        nf = NumberFormat.getDecimalFormat();
    } else if (format.equalsIgnoreCase("percent")) {
        nf = NumberFormat.getPercentFormat();
    } else {
        nf = NumberFormat.getFormat(format);
    }
    return nf;
}

From source file:org.greatlogic.gxtexamples.client.glgwt.GLGridWidget.java

License:Apache License

private ColumnConfig<GLRecord, BigDecimal> createColumnConfigBigDecimal(final GLGridColumnDef gridColumnDef,
        final IGLColumn column) {
    final ColumnConfig<GLRecord, BigDecimal> result;
    final ValueProvider<GLRecord, BigDecimal> valueProvider;
    valueProvider = new GLBigDecimalValueProvider(column, column.getNumberOfDecimalPlaces());
    result = new ColumnConfig<GLRecord, BigDecimal>(valueProvider, gridColumnDef.getWidth(), //
            column.getTitle());//from  w w w.  j  av a2s  .co  m
    result.setHorizontalAlignment(gridColumnDef.getHorizontalAlignment());
    NumberFormat numberFormat;
    if (column.getDataType() == EGLColumnDataType.Currency) {
        numberFormat = NumberFormat.getSimpleCurrencyFormat();
    } else {
        numberFormat = NumberFormat.getDecimalFormat();
    }
    result.setCell(new NumberCell<BigDecimal>(numberFormat));
    return result;
}

From source file:org.gwtlib.samples.table.client.ui.PagingTableEntryPoint.java

License:Apache License

private PagingTable createTable() {
    // Set up the columns we want to be displayed
    final CheckBox checkAll = new CheckBox();
    final Column[] columns = { new Column(0, false, checkAll, "20", new CheckBoxRenderer()),
            new Column(1, true, "Text (StringRenderer)", "10%"),
            new Column(2, false, "Date (StringRenderer)", "10%"),
            new Column(3, false, "Number (StringRenderer)", "10%"),
            new Column(4, true, "Date (DateTimeRenderer)", "10%",
                    new DateTimeRenderer(DateTimeFormat.getFormat("yyyy-MM-dd"))),
            new Column(5, true, "Number (NumberRenderer)", "10%",
                    new NumberRenderer(NumberFormat.getDecimalFormat())),
            new Column(6, false, "(ListBoxRenderer)", "10%",
                    new ListBoxRenderer(new String[] { "One", "Two", "Three" }, "Select an item")),
            new Column(7, false, "(ButtonRenderer)", "10%", new ButtonRenderer("Click here")),
            new Column(8, false, "(TextBoxRenderer)", "10%", new TextBoxRenderer(50, 5, "Enter your message")),
            new Column(9, false, "(HyperlinkRenderer)", "10%", new HyperlinkRenderer("A Hyperlink")),
            new Column(10, false, "(ImageRenderer)", "10%", new ImageRenderer("An Image")), };
    // Generate some semi-random data for our example
    final Row[] rows = new Row[TOTAL_SIZE];
    for (int i = 0; i < rows.length; ++i) {
        Boolean check = new Boolean(false);
        StringBuffer label = new StringBuffer();
        for (int j = 0; j < 25; ++j)
            label.append((char) ('a' + i));
        Date date = new Date(NOW.getTime() + Random.nextInt(365 * 24 * 3600 * 1000));
        Integer number = new Integer(Random.nextInt(10000));
        rows[i] = new Row(i, new Object[] { check, label.toString(), date, number, date, number, "One",
                number.toString(), number.toString(), "Hyperlink", "img/down.gif" });
    }/* www .j a  v a2  s. c o m*/
    // Now configure the table
    ColumnLayout layout = new ColumnLayout(columns);
    final PagingTable table = new PagingTable(layout,
            new PagingBar(0, TOTAL_SIZE, 10, new int[] { 5, 10, 20, 50, 100 }));
    ContentProvider provider = new ContentProvider() {
        // Simulate retrieval of sample data, in requested sort order
        public void load(int begin, int end, final int sortId, boolean ascending) {
            final int sign = ascending ? 1 : -1;
            Row[] tmp = new Row[rows.length];
            for (int i = 0; i < rows.length; ++i)
                tmp[i] = rows[i];
            switch (sortId) {
            case 1:
                Arrays.sort(tmp, new Comparator<Row>() {
                    public int compare(Row o1, Row o2) {
                        String v1 = (String) o1.getValue(sortId);
                        String v2 = (String) o2.getValue(sortId);
                        return sign * (v1.compareTo(v2));
                    }
                });
                break;
            case 4:
                Arrays.sort(tmp, new Comparator<Row>() {
                    public int compare(Row o1, Row o2) {
                        Date v1 = (Date) o1.getValue(sortId);
                        Date v2 = (Date) o2.getValue(sortId);
                        return sign * (v1.compareTo(v2));
                    }
                });
                break;
            case 5:
                Arrays.sort(tmp, new Comparator<Row>() {
                    public int compare(Row o1, Row o2) {
                        int v1 = ((Integer) o1.getValue(sortId)).intValue();
                        int v2 = ((Integer) o2.getValue(sortId)).intValue();
                        return sign * (v1 < v2 ? -1 : (v1 == v2 ? 0 : 1));
                    }
                });
                break;
            default:
                break;
            }
            Row[] srows = new Row[Math.min(end - begin, tmp.length - begin)];
            for (int i = 0; i < srows.length; ++i)
                srows[i] = tmp[begin + i];
            table.onSuccess(new Rows(srows, begin, sortId, ascending));
        }
    };
    table.setContentProvider(provider);
    table.addTableListener(new TableListenerAdapter() {
        public void onCellClicked(SourcesTableEvents sender, Row row, Column column) {
            for (int i = 0; i < columns.length; ++i)
                columns[i].setState(Column.State.NONE);
            column.setState(Column.State.SELECT);
        }

        public void onRowClicked(SourcesTableEvents sender, Row row) {
            GWT.log("Row clicked (id " + row.getId() + ")", null);
            for (int i = 0; i < rows.length; ++i)
                rows[i].setState(Row.State.NONE);
            row.setState(Row.State.SELECT);
            table.refreshRowState();
        }

        public void onClick(SourcesTableEvents sender, Row row, Column column, Widget widget) {
            GWT.log("Renderer widget clicked", null);
            if (widget instanceof CheckBox) {
                row.setValue(0, new Boolean(((CheckBox) widget).getValue()));
            } else if (widget instanceof Button) {
                Window.alert(((Button) widget).getHTML());
            } else if (widget instanceof Hyperlink) {
                Window.alert(((Hyperlink) widget).getHTML());
            } else if (widget instanceof Image) {
                Window.alert(((Image) widget).getUrl());
            }
        }

        public void onChange(SourcesTableEvents sender, Row row, Column column, Widget widget) {
            GWT.log("Renderer widget changed", null);
            if (widget instanceof ListBox) {
                ListBox listBox = (ListBox) widget;
                row.setValue(6, listBox.getValue(listBox.getSelectedIndex()));
            } else if (widget instanceof TextBox) {
                row.setValue(8, ((TextBox) widget).getText());
            }
        }
    });
    checkAll.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            for (int i = 0; i < rows.length; ++i)
                rows[i].setValue(0, new Boolean(checkAll.getValue()));
            table.update();
        }
    });
    table.update();
    return table;
}

From source file:org.jbpm.console.ng.pr.client.editors.documents.list.ProcessDocumentListViewImpl.java

License:Apache License

public String readableFileSize(long size) {
    if (size <= 0) {
        return "0";
    }/* w  w  w  .jav  a 2 s  .c  o m*/
    int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
    return NumberFormat.getDecimalFormat().format(size / Math.pow(1024, digitGroups)) + " "
            + units[digitGroups];
}

From source file:org.kie.workbench.common.forms.jbpm.client.document.DocumentFieldRendererViewImpl.java

License:Apache License

protected String calculateSize() {
    String result = "";

    if (value != null) {
        double size = value.getSize();
        int position;
        for (position = 0; position < SIZE_UNITS.length && size > 1024; position++) {
            size = size / 1024;//  www  .ja  v a  2s  .  c om
        }

        result = NumberFormat.getDecimalFormat().format(size) + " " + SIZE_UNITS[position];
    }

    return result;
}