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

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

Introduction

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

Prototype

public static NumberFormat getPercentFormat() 

Source Link

Document

Provides the standard percent format for the default locale.

Usage

From source file:org.wisepersist.gwt.uploader.demo.client.TextButtonAndProgressText.java

License:Apache License

@Override
public Widget getUploaderPanel() {
    progressLabel.setStyleName("progressLabel");
    uploader.setUploadURL("/upload").setButtonText("<span class=\"buttonText\">Click to Upload</span>")
            .setButtonTextStyle(".buttonText {font-family: Arial, sans-serif; font-size: 14px; color: #BB4B44}")
            .setFileSizeLimit("50 MB").setButtonWidth(150).setButtonHeight(22)
            .setButtonCursor(Uploader.Cursor.HAND).setButtonAction(Uploader.ButtonAction.SELECT_FILE)
            .setUploadProgressHandler(new UploadProgressHandler() {
                public boolean onUploadProgress(UploadProgressEvent uploadProgressEvent) {
                    progressLabel.setText(NumberFormat.getPercentFormat()
                            .format((double) uploadProgressEvent.getBytesComplete()
                                    / (double) uploadProgressEvent.getBytesTotal()));
                    return true;
                }/*from  www  .  j a v a  2  s .c  o m*/
            }).setUploadSuccessHandler(new UploadSuccessHandler() {
                public boolean onUploadSuccess(UploadSuccessEvent uploadSuccessEvent) {
                    resetText();
                    StringBuilder sb = new StringBuilder();
                    sb.append("File ").append(uploadSuccessEvent.getFile().getName()).append(" (")
                            .append(NumberFormat.getDecimalFormat()
                                    .format(uploadSuccessEvent.getFile().getSize() / 1024))
                            .append(" KB)").append(" uploaded successfully at ")
                            .append(NumberFormat.getDecimalFormat()
                                    .format(uploadSuccessEvent.getFile().getAverageSpeed() / 1024))
                            .append(" Kb/second");
                    progressLabel.setText(sb.toString());
                    return true;
                }
            }).setFileDialogCompleteHandler(new FileDialogCompleteHandler() {
                public boolean onFileDialogComplete(FileDialogCompleteEvent fileDialogCompleteEvent) {
                    if (fileDialogCompleteEvent.getTotalFilesInQueue() > 0
                            && uploader.getStats().getUploadsInProgress() <= 0) {
                        progressLabel.setText("0%");
                        uploader.setButtonText("<span class=\"buttonText\">Uploading...</span>");
                        uploader.startUpload();
                    }
                    return true;
                }
            }).setFileQueueErrorHandler(new FileQueueErrorHandler() {
                public boolean onFileQueueError(FileQueueErrorEvent fileQueueErrorEvent) {
                    resetText();
                    Window.alert("Upload of file " + fileQueueErrorEvent.getFile().getName()
                            + " failed due to [" + fileQueueErrorEvent.getErrorCode().toString() + "]: "
                            + fileQueueErrorEvent.getMessage());
                    return true;
                }
            }).setUploadErrorHandler(new UploadErrorHandler() {
                public boolean onUploadError(UploadErrorEvent uploadErrorEvent) {
                    resetText();
                    Window.alert("Upload of file " + uploadErrorEvent.getFile().getName() + " failed due to ["
                            + uploadErrorEvent.getErrorCode().toString() + "]: "
                            + uploadErrorEvent.getMessage());
                    return true;
                }
            });

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.add(uploader);
    verticalPanel.add(progressLabel);
    verticalPanel.setCellHorizontalAlignment(uploader, HorizontalPanel.ALIGN_LEFT);
    verticalPanel.setCellHorizontalAlignment(progressLabel, HorizontalPanel.ALIGN_LEFT);
    return verticalPanel;
}