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

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

Introduction

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

Prototype

public String format(Number number) 

Source Link

Document

This method formats a Number to produce a string.

Usage

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);//from  ww w .jav  a2s .co 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.glom.web.client.ui.details.DetailsCell.java

License:Open Source License

public void setData(final DataItem dataItem) {
    detailsData.clear();/*from   w  w  w  .ja v  a2 s  .c  o m*/

    if (dataItem == null) {
        return;
    }

    Formatting formatting = layoutItem.getFormatting();

    // FIXME use the cell renderers from the list view to render the information here
    switch (this.dataType) {
    case TYPE_BOOLEAN:
        final CheckBox checkBox = new CheckBox();
        checkBox.setValue(dataItem.getBoolean());
        checkBox.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(final ClickEvent event) {
                // don't let users change the checkbox
                checkBox.setValue(dataItem.getBoolean());
            }
        });
        detailsData.add(checkBox);
        break;
    case TYPE_NUMERIC:
        if (formatting == null) {
            GWT.log("setData(): formatting is null");
            formatting = new Formatting(); // To avoid checks later.
        }
        final NumericFormat numericFormat = formatting.getNumericFormat();
        final NumberFormat gwtNumberFormat = Utils.getNumberFormat(numericFormat);

        // set the foreground color to red if the number is negative and this is requested
        if (numericFormat.getUseAltForegroundColorForNegatives() && dataItem.getNumber() < 0) {
            // The default alternative color in libglom is red.
            detailsData.getElement().getStyle()
                    .setColor(NumericFormat.getAlternativeColorForNegativesAsHTMLColor());
        }

        final String currencyCode = StringUtils.isEmpty(numericFormat.getCurrencySymbol()) ? ""
                : numericFormat.getCurrencySymbol().trim() + " ";
        detailsLabel.setText(currencyCode + gwtNumberFormat.format(dataItem.getNumber()));
        detailsData.add(detailsLabel);
        break;
    case TYPE_DATE:
    case TYPE_TIME:
    case TYPE_TEXT:
        final String text = StringUtils.defaultString(dataItem.getText());

        // Deal with multiline text differently than single line text.
        if ((formatting != null) && (formatting.getTextFormatMultilineHeightLines() > 1)) {
            detailsData.getElement().getStyle().setOverflow(Overflow.AUTO);
            // Convert '\n' to <br/> escaping the data so that it won't be rendered as HTML.
            try {
                // JavaScript requires the charsetName to be "UTF-8". CharsetName values that work in Java (such as
                // "UTF8") will not work when compiled to JavaScript.
                final String utf8NewLine = new String(new byte[] { 0x0A }, "UTF-8");
                final String[] lines = text.split(utf8NewLine);
                final SafeHtmlBuilder sb = new SafeHtmlBuilder();
                for (final String line : lines) {
                    sb.append(SafeHtmlUtils.fromString(line));
                    sb.append(SafeHtmlUtils.fromSafeConstant("<br/>"));
                }

                // Manually add the HTML to the detailsData container.
                final DivElement div = Document.get().createDivElement();
                div.setInnerHTML(sb.toSafeHtml().asString());
                detailsData.getElement().appendChild(div);

                // Expand the width of detailsData if a vertical scrollbar has been placed on the inside of the
                // detailsData container.
                final int scrollBarWidth = detailsData.getOffsetWidth() - div.getOffsetWidth();
                if (scrollBarWidth > 0) {
                    // A vertical scrollbar is on the inside.
                    detailsData.setWidth((detailsData.getOffsetWidth() + scrollBarWidth + 4) + "px");
                }

                // TODO Add horizontal scroll bars when detailsData expands beyond its container.

            } catch (final UnsupportedEncodingException e) {
                // If the new String() line throws an exception, don't try to add the <br/> tags. This is unlikely
                // to happen but we should do something if it does.
                detailsLabel.setText(text);
                detailsData.add(detailsLabel);
            }

        } else {
            final SingleLineText textPanel = new SingleLineText(text);
            detailsData.add(textPanel);
        }
        break;
    case TYPE_IMAGE:
        final Image image = new Image();
        final String imageDataUrl = dataItem.getImageDataUrl();
        if (imageDataUrl != null) {
            image.setUrl(imageDataUrl);

            // Set an arbitrary default size:
            // image.setPixelSize(200, 200);
        }

        detailsData.add(image);
        break;
    default:
        break;
    }

    this.dataItem = dataItem;

    // enable the navigation button if it's safe
    if (openButton != null && openButtonHandlerReg != null && this.dataItem != null) {
        openButton.setEnabled(true);
    }

}

From source file:org.gss_project.gss.common.dto.FileBodyDTO.java

License:Open Source License

private String getSize(Long size, Double division) {
    Double res = Double.valueOf(size.toString()) / division;
    NumberFormat nf = NumberFormat.getFormat("######.###");
    return nf.format(res);
}

From source file:org.gss_project.gss.common.dto.StatsDTO.java

License:Open Source License

private String getSize(Long size, Double division) {
    Double res = Double.valueOf(size.toString()) / division;
    NumberFormat nf = NumberFormat.getFormat("######.#");
    return nf.format(res);
}

From source file:org.gss_project.gss.common.dto.UserClassDTO.java

License:Open Source License

private String getSize(Long size, Double divisor) {
    Double res = Double.valueOf(size.toString()) / divisor;
    NumberFormat nf = NumberFormat.getFormat("######.#");
    return nf.format(res);
}

From source file:org.gss_project.gss.web.client.rest.resource.FileResource.java

License:Open Source License

private static String getSize(Long size, Double division) {
    Double res = Double.valueOf(size.toString()) / division;
    NumberFormat nf = NumberFormat.getFormat("######.#");
    return nf.format(res);
}

From source file:org.jahia.ajax.gwt.client.util.Formatter.java

License:Open Source License

/**
 * Get a human readable size from a byte size.
 *
 * @param size the size to format//w w w.  j ava2 s. c om
 * @return the formatted size
 */
public static String getFormattedSize(long size) {
    NumberFormat nf = NumberFormat.getFormat("0.00");
    StringBuffer dispSize = new StringBuffer();
    if (size >= GB) {
        dispSize.append(String.valueOf(nf.format(size / GB))).append(" GB");
    } else if (size >= MB) {
        dispSize.append(String.valueOf(nf.format(size / MB))).append(" MB");
    } else if (size >= KB) {
        dispSize.append(String.valueOf(nf.format(size / KB))).append(" KB");
    } else {
        dispSize.append(String.valueOf(nf.format(size))).append(" B");
    }
    return dispSize.toString();
}

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

License:Apache License

@Override
protected FormGroup getFormGroup(RenderMode renderMode) {
    slider = new Slider(field.getMin().doubleValue(), field.getMax().doubleValue(),
            field.getPrecision().doubleValue(), field.getStep().doubleValue());

    slider.setId(generateUniqueId());//  w w w.j  a v  a 2  s  . c  o m
    slider.setEnabled(!field.getReadOnly() && renderingContext.getRenderMode().equals(RenderMode.EDIT_MODE));

    int precision = field.getPrecision().intValue();
    NumberFormat format = createFormatter(precision);
    slider.setFormatter((Double value) -> format.format(value));

    SliderFormGroup formGroup = formGroupsInstance.get();

    formGroup.render(slider, field);

    return formGroup;
}

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 {// w w w.  j ava2s  . co  m
        return "negative scale not allowed";
    }
}

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());
              //from ww w  . j a va  2s .com
    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;
}