Java Code Examples for com.google.gwt.i18n.client.NumberFormat#format()

The following examples show how to use com.google.gwt.i18n.client.NumberFormat#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HitsListPanel.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onSearchArrived() {
	/**
	 * Update the cursor. Prepare a stack for 2 sections the Title with
	 * search time and the list of hits
	 */
	NumberFormat format = NumberFormat.getFormat("#.###");

	String stats = I18N.message("aboutresults", new String[] { "" + Search.get().getEstimatedHits(),
			format.format((double) Search.get().getTime() / (double) 1000) });
	stats += " (<b>" + format.format((double) Search.get().getTime() / (double) 1000) + "</b> "
			+ I18N.message("seconds").toLowerCase() + ")";
	cursor.setMessage(stats);

	GUISearchOptions options = Search.get().getOptions();
	if (options.getType() == GUISearchOptions.TYPE_FULLTEXT)
		grid.setCanExpandRows();
	GUIDocument[] result = Search.get().getLastResult();
	if (result != null)
		grid.setDocuments(result);
	
	if (Search.get().isHasMore())
		Log.warn(I18N.message("possiblemorehits"), I18N.message("possiblemorehitsdetail"));

	cursor.setMaxDisplayedRecords(options.getMaxHits());
}
 
Example 2
Source File: Util.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String formatLong(long number) {
	String str;
	NumberFormat fmt = NumberFormat.getFormat("#,###");
	str = fmt.format(number);
	str = str.replace(',', I18N.groupingSepator());
	return str;
}
 
Example 3
Source File: Util.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Format file size in KB.
 * 
 * @param size The file size in bytes.
 * 
 * @return The formated file size.
 */
public static String formatSizeKB(double size) {
	String str;
	if (size < 1) {
		str = "0 KB";
	} else if (size < 1024) {
		str = "1 KB";
	} else {
		NumberFormat fmt = NumberFormat.getFormat("#,###");
		str = fmt.format(Math.ceil(size / 1024)) + " KB";
		str = str.replace(',', I18N.groupingSepator());
	}
	return str;
}
 
Example 4
Source File: Util.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Format file size in bytes
 * 
 * @param size The file size in bytes
 * 
 * @return the formatted size
 */
public static String formatSizeBytes(double size) {
	String str;
	NumberFormat fmt = NumberFormat.getFormat("#,###");
	str = fmt.format(size) + " bytes";
	str = str.replace(',', I18N.groupingSepator());
	return str;
}
 
Example 5
Source File: BaseWidget.java    From EasyML with Apache License 2.0 5 votes vote down vote up
public void printMessage(String eventName, int code, boolean modifier, boolean control) {
	final NumberFormat formatter = NumberFormat.getDecimalFormat();
	String message = eventName + " -  Char Code: " + formatter.format(code) + ".  ";

	if(code == KeyCodes.KEY_ENTER) {
		message += "Key is ENTER.  ";
	}

	if(modifier)
		message += "Modifier is down.  ";

	if(control)
		message += "CTRL is down.  ";
	logger.info("message"+message);
}
 
Example 6
Source File: InputFile.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void redraw() {
	this.cancelBtn.removeFromParent();
	this.uploadBtn.removeFromParent();
	this.fileNameAnchor.removeFromParent();
	this.placeholderText.removeFromParent();
	this.progressBarWrapper.removeFromParent();
	if (this.fileId != null) {
		this.append(this.progressBarWrapper);
		this.addAddon(this.cancelBtn);
	} else {
		FileDto value = this.getValue();
		if (value != null) {
			NumberFormat nf = NumberFormat.getFormat("#.##");

			long size = value.getContentLength();
			String displaySize = "";
			if (size > 1024 * 1024) {
				displaySize = nf.format(size / (1024 * 1024D)) + " MB";
			} else if (size > 1024) {
				displaySize = nf.format(size / 1024D) + " KB";
			} else {
				displaySize = nf.format(size) + " B";
			}

			this.fileNameAnchor.setLink(urlDownload + value.getToken());
			this.fileNameAnchor.setText(value.getName() + " - (" + displaySize + ")");
			this.placeholderText.setText(null);
			this.append(this.fileNameAnchor);
			this.addAddon(this.cancelBtn);
		} else {
			this.fileNameAnchor.setLink(null);
			this.fileNameAnchor.setText(null);
			this.placeholderText.setText(this.placeholder);
			this.append(this.placeholderText);
		}
		this.addAddon(this.uploadBtn);
	}
}
 
Example 7
Source File: DisplayerGwtFormatter.java    From dashbuilder with Apache License 2.0 4 votes vote down vote up
@Override
public String formatNumber(String pattern, Number n) {
    NumberFormat f = getNumberFormat(pattern);
    return f.format(n);
}