com.google.gwt.i18n.client.NumberFormat Java Examples

The following examples show how to use com.google.gwt.i18n.client.NumberFormat. 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: TimeUtils.java    From EasyML with Apache License 2.0 7 votes vote down vote up
public static String timeDiff(Date date1, Date date2) {
	if( date1 == null || date2 == null ) return "";
	long nh = 1000 * 60 * 60;
	long nm = 1000 * 60;
	long ns = 1000;
	try {
		long diff = date2.getTime() - date1.getTime();

		// gap of hour
		long hour = diff / nh;
		// gap of min
		long min = diff % nh / nm;
		// gap of sec
		long sec = diff % nh % nm / ns;
		String res = NumberFormat.getFormat("#00").format(hour) + ":"
				+ NumberFormat.getFormat("#00").format(min) + ":"
				+ NumberFormat.getFormat("#00").format(sec);
		return res;
	} catch (IllegalArgumentException ex) {
		return null;
	}
}
 
Example #2
Source File: DBController.java    From EasyML with Apache License 2.0 6 votes vote down vote up
/**
 * Get dataset panel show values .
 * 
 * @param dataset
 * @param isUpdate
 * @return  Data panel show value array
 */
public static String[] getDatasetPanelValue(final Dataset dataset, boolean isUpdate) {
	String[] values = new String[7];
	Date dateNow = new Date();
	DateTimeFormat dateFormat = DateTimeFormat
			.getFormat("yyyy-MM-dd KK:mm:ss a");
	values[4] = dateFormat.format(dateNow);
	double version = 0;
	if ((!dataset.getVersion().contains("n"))&&isUpdate){
		version = Double.parseDouble(dataset.getVersion()) + 0.1;
	}else version = Double.parseDouble(dataset.getVersion());     
	values[3] = NumberFormat.
			getFormat("#0.0").format(version);

	values[1] = null;
	String TypeString = dataset.getContenttype();
	if (TypeString == null || TypeString.equals("") || "General".equals(TypeString)) values[2] = "General/CSV/TSV/JSON";
	else if ("TSV".equals(TypeString)) values[2] = "TSV/General/CSV/JSON";
	else if ("CSV".equals(TypeString)) values[2] = "CSV/General/TSV/JSON";
	else values[2] = "JSON/General/TSV/CSV";
	values[0] = dataset.getName();
	values[5] = AppController.email;
	values[6] = dataset.getDescription();
	return values;
}
 
Example #3
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 #4
Source File: DataSetSummary.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
String humanReadableRowCount(long rows) {
    int unit = 1000;
    if (rows < unit) return Long.toString(rows);
    int exp = (int) (Math.log(rows) / Math.log(unit));
    String pre = ("KMGTPE" ).charAt(exp-1) + ("");
    return NumberFormat.getFormat(ESTIMATIONS_FORMAT).format(rows / Math.pow(unit, exp)) + pre;
}
 
Example #5
Source File: DeploymentBrowseContentView.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String formatFileUnits(long length) {
    if (length <= 0) 
        return "0";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(length) / Math.log10(1024));
    return NumberFormat.getFormat("#,##0.#").format(length/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
 
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: OutputProgressBar.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setValue(T value) {
	this.value = value;
	double val = 0;
	if (value == null) {
		val = this.min;
	} else {
		val = value.doubleValue();
	}
	if (val > this.max) {
		val = this.max;
	} else if (val < this.min) {
		val = this.min;
	}

	this.progressBarElement.setAttribute(OutputProgressBar.ATT_ARIA_VALUE, value + "");
	double percent = 100 * (val - this.min) / (this.max - this.min);
	this.progressBarElement.getStyle().setProperty("width", percent, Unit.PCT);

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

	String stringToDisplay = this.format;
	stringToDisplay = RegExp.compile("\\{0\\}").replace(stringToDisplay, formatter.format(val));
	stringToDisplay = RegExp.compile("\\{1\\}").replace(stringToDisplay, formatter.format(percent));
	stringToDisplay = RegExp.compile("\\{2\\}").replace(stringToDisplay, formatter.format(this.min));
	stringToDisplay = RegExp.compile("\\{3\\}").replace(stringToDisplay, formatter.format(this.max));

	this.progressBarElement.removeAllChildren();
	if (this.displayValue) {
		this.progressBarElement.setInnerText(stringToDisplay);
	} else {
		SpanElement reader = Document.get().createSpanElement();
		reader.setInnerText(stringToDisplay);
		reader.addClassName("sr-only");
		this.progressBarElement.appendChild(reader);
	}
}
 
Example #8
Source File: NumberRenderer.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public NumberRenderer(String format) {
	if (format == null) {
		this.formater = NumberFormat.getDecimalFormat();
	} else {
		this.formater = NumberFormat.getFormat(format);
	}
}
 
Example #9
Source File: BigDecimalRenderer.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String render(BigDecimal object) {
	if (object == null) {
		return "";
	}

	return NumberFormat.getDecimalFormat().format(object);
}
 
Example #10
Source File: BigIntegerRenderer.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String render(BigInteger object) {
	if (object == null) {
		return "";
	}

	return NumberFormat.getDecimalFormat().format(object);
}
 
Example #11
Source File: FloatParser.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Float parse(CharSequence object) throws ParseException {
	if ("".equals(object.toString())) {
		return null;
	}

	try {
		return (float) NumberFormat.getDecimalFormat().parse(object.toString());
	} catch (NumberFormatException e) {
		throw new ParseException(e.getMessage(), 0);
	}
}
 
Example #12
Source File: BigIntegerParser.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BigInteger parse(CharSequence object) throws ParseException {
	if ("".equals(object.toString())) {
		return null;
	}

	try {
		return BigInteger.valueOf((long) NumberFormat.getDecimalFormat().parse(object.toString()));
	} catch (NumberFormatException e) {
		throw new ParseException(e.getMessage(), 0);
	}
}
 
Example #13
Source File: FloatRenderer.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String render(Float object) {
	if (object == null) {
		return "";
	}

	return NumberFormat.getDecimalFormat().format(object);
}
 
Example #14
Source File: BigDecimalParser.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public BigDecimal parse(CharSequence object) throws ParseException {
	if ("".equals(object.toString())) {
		return null;
	}

	try {
		return BigDecimal.valueOf(NumberFormat.getDecimalFormat().parse(object.toString()));
	} catch (NumberFormatException e) {
		throw new ParseException(e.getMessage(), 0);
	}
}
 
Example #15
Source File: DataSetSummary.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
String humanReadableByteCount(long bytes) {
    final String _b = " " + DataSetExplorerConstants.INSTANCE.bytes();
    int unit = 1024;
    if (bytes < unit) return Long.toString(bytes) + _b;
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = ("KMGTPE").charAt(exp-1) + _b;
    return NumberFormat.getFormat(ESTIMATIONS_FORMAT).format(bytes / Math.pow(unit, exp)) + pre;
}
 
Example #16
Source File: DisplayerGwtFormatter.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
protected NumberFormat getNumberFormat(String pattern) {
    if (StringUtils.isBlank(pattern)) {
        return getNumberFormat(ColumnSettings.NUMBER_PATTERN);
    }
    NumberFormat format = numberPatternMap.get(pattern);
    if (format == null) {
        format = NumberFormat.getFormat(pattern);
        numberPatternMap.put(pattern, format);
    }
    return format;
}
 
Example #17
Source File: InstructorsTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
protected Widget getCell(final InstructorInterface instructor, final InstructorsColumn column, final int idx) {
	switch (column) {
	case ID:
		if (instructor.getExternalId() == null) {
			Image warning = new Image(RESOURCES.warning());
			warning.setTitle(MESSAGES.warnInstructorHasNoExternalId(instructor.getFormattedName()));
			return warning;
		} else {
			return new Label(instructor.getExternalId());
		}
	case NAME:
		return new Label(instructor.getFormattedName());
	case POSITION:
		return new Label(instructor.getPosition() == null ? "" : instructor.getPosition().getLabel());
	case TEACHING_PREF:
		if (instructor.getTeachingPreference() == null) {
			return new Label("");
		} else {
			Label pref = new Label(instructor.getTeachingPreference().getName());
			if (instructor.getTeachingPreference().getColor() != null)
				pref.getElement().getStyle().setColor(instructor.getTeachingPreference().getColor());
			return pref;
		}
	case MAX_LOAD:
		return new Label(instructor.hasMaxLoad() ? NumberFormat.getFormat(CONSTANTS.teachingLoadFormat()).format(instructor.getMaxLoad()) : "");
	case SELECTION:
		return new SelectableCell(instructor);
	case ATTRIBUTES:
		AttributeTypeInterface type = iProperties.getAttributeTypes().get(idx);
		List<AttributeInterface> attributes = instructor.getAttributes(type);
		if (!attributes.isEmpty() && !isColumnVisible(getCellIndex(column) + idx)) {
			setColumnVisible(getCellIndex(column) + idx, true);
		}
		return new AttributesCell(attributes);
	default:
		return null;
	}
}
 
Example #18
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 #19
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 #20
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 #21
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 #22
Source File: GUIExtensibleObject.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Appends a new value for a given multiple attribute. Returns the new
 * attribute that represent the value
 *
 * @param name name of the attribute
 * 
 * @return the attribute
 */
public GUIAttribute addAttributeValue(String name) {
	List<GUIAttribute> actualValues = getValues(name);

	GUIAttribute lastValue = actualValues.get(actualValues.size() - 1);
	GUIAttribute newAtt = (GUIAttribute) lastValue.clone();
	newAtt.setValue(null);
	newAtt.setMultiple(false);
	newAtt.setParent(name);
	NumberFormat nf = NumberFormat.getFormat("0000");
	newAtt.setName(name + "-" + nf.format(actualValues.size()));
	putAttributeAfter(lastValue.getName(), newAtt);

	return newAtt;
}
 
Example #23
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);
}
 
Example #24
Source File: DBController.java    From EasyML with Apache License 2.0 4 votes vote down vote up
/**
 * Get program panel show values .
 * 
 * @param program
 * @param isUpdate
 * @return  Program panel show value array
 */
public static String[] getProgramPanelValue(final Program program, boolean isUpdate) {

	final String[] values = new String[10];
	int i = 0;
	values[i++] = program.getName();

	//for category
	values[i++] = null;
	String TypeString = program.getType();
	logger.info(TypeString.toLowerCase());
	if ("单机".equals(TypeString.toLowerCase()) || "standalone".equals(TypeString.toLowerCase()))
		values[i] = Constants.studioUIMsg.standalone() + "/" + Constants.studioUIMsg.distributed()+"/ETL"+"/Tensorflow";
	if ("spark".equals(TypeString) || "分布式".equals(TypeString) ||TypeString.equals("distributed")||TypeString.toLowerCase().equals("distributed")) {
		values[i] = Constants.studioUIMsg.distributed() + "/" + Constants.studioUIMsg.standalone() + "/ETL"+"/Tensorflow";
	}
	if ("etl".equals(TypeString))
		values[i] = "ETL/"+Constants.studioUIMsg.distributed() + "/" + Constants.studioUIMsg.standalone()+"/Tensorflow";
	if("tensorflow".equals(TypeString))
		values[i] = "Tensorflow/"+Constants.studioUIMsg.distributed() + "/" + Constants.studioUIMsg.standalone()+"/ETL";

	i ++;

	if( program.getProgramable() ) values[i] = Constants.studioUIMsg.yes() + "/" + Constants.studioUIMsg.no();
	else values[i] = Constants.studioUIMsg.no() + "/" + Constants.studioUIMsg.yes();
	i ++;

	boolean deterministic = program.getIsdeterministic();
	if (deterministic) values[i] = Constants.studioUIMsg.yes() + "/" + Constants.studioUIMsg.no();
	else values[i] = Constants.studioUIMsg.no() + "/" + Constants.studioUIMsg.yes();
	i ++;

	double version = 0;
	if ((!program.getVersion().contains("n"))&&isUpdate){
		version = Double.parseDouble(program.getVersion()) + 0.1;
	}else version = Double.parseDouble(program.getVersion());

	values[i] = NumberFormat.getFormat("#0.0").format(version);
	i ++;

	Date dateNow = new Date();
	DateTimeFormat dateFormat = DateTimeFormat
			.getFormat("yyyy-MM-dd KK:mm:ss a");
	values[i] = dateFormat.format(dateNow);
	i ++;

	values[i++] = AppController.email;
	values[i++] = program.getDescription();
	values[i++] = program.getCommandline();

	String tensorflowMode = program.getTensorflowMode();
	if("单机".equals(tensorflowMode) || "standalone".equals(tensorflowMode))
		values[i] = Constants.studioUIMsg.standalone()+"/"+Constants.studioUIMsg.modelDistributed()+"/"+Constants.studioUIMsg.dataDistributed();
	else if("模型分布".equals(tensorflowMode) || "model distributed".equals(tensorflowMode))
		values[i] = Constants.studioUIMsg.modelDistributed()+"/"+Constants.studioUIMsg.standalone()+"/"+Constants.studioUIMsg.dataDistributed();
	else if("数据分布".equals(tensorflowMode) || "data distributed".equals(tensorflowMode))
		values[i] = Constants.studioUIMsg.dataDistributed()+"/"+Constants.studioUIMsg.standalone()+"/"+Constants.studioUIMsg.modelDistributed();
	else 
		values[i]= Constants.studioUIMsg.standalone()+"/"+Constants.studioUIMsg.modelDistributed()+"/"+Constants.studioUIMsg.dataDistributed();

	return values;
}
 
Example #25
Source File: IntegerTokenHelper.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setFormater(String format) {
	this.formater = NumberFormat.getFormat(format);
}
 
Example #26
Source File: QueryOptionsView.java    From lumongo with Apache License 2.0 4 votes vote down vote up
public QueryOptionsView(UIQueryResults uiQueryResults) {
	setMargin(15);
	setPadding(10);

	uiQueryObject = uiQueryResults.getUiQueryObject();
	if (uiQueryObject == null) {
		uiQueryObject = new UIQueryObject();
	}

	if (!uiQueryResults.getJsonDocs().isEmpty()) {
		MaterialBadge resultsBadge = new MaterialBadge("Total Results: " + NumberFormat.getFormat("#,##0").format(uiQueryResults.getTotalResults()));
		add(resultsBadge);
		add(new Br());
	}

	MaterialButton executeButton = new MaterialButton("Execute", IconType.SEARCH);
	executeButton.addClickHandler(clickEvent -> runSearch());
	executeButton.setMarginRight(2);
	add(executeButton);

	MaterialButton resetButton = new MaterialButton("Reset", IconType.REFRESH);
	resetButton.addClickHandler(clickEvent -> MainController.get().goTo(new QueryPlace(null)));
	add(resetButton);

	MaterialListBox indexesListBox = new MaterialListBox();
	indexesListBox.setMultipleSelect(true);
	Option selectOneIndexOption = new Option("Select Indexes");
	selectOneIndexOption.setDisabled(true);
	indexesListBox.add(selectOneIndexOption);

	fieldNameCollapsible = new MaterialCollapsible();
	fieldNameCollapsible.setAccordion(false);
	for (IndexInfo indexInfo : uiQueryResults.getIndexes()) {
		createFieldNameCollapsible(indexInfo);

		Option option = new Option(indexInfo.getName());
		if (uiQueryObject.getIndexNames().contains(indexInfo.getName())) {
			option.setSelected(true);
			fieldItems.get(indexInfo.getName()).setVisible(true);
		}
		indexesListBox.add(option);
	}
	indexesListBox.addValueChangeHandler(valueChangeEvent -> {
		for (String indexName : fieldItems.keySet()) {
			fieldItems.get(indexName).setVisible(false);
		}
		for (String itemsSelected : indexesListBox.getItemsSelected()) {
			uiQueryObject.getIndexNames().add(itemsSelected);
			fieldItems.get(itemsSelected).setVisible(true);
		}
	});

	add(indexesListBox);
	add(fieldNameCollapsible);

	CustomTextBox searchBox = new CustomTextBox(true);
	searchBox.setPlaceHolder("q=*:*");
	searchBox.setValue(uiQueryObject.getQuery());
	searchBox.addKeyUpHandler(clickEvent -> {
		if (clickEvent.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
			uiQueryObject.setQuery(searchBox.getValue());
			runSearch();
		}
	});

	searchBox.getButton().setTitle("Execute Query");
	searchBox.getButton().addClickHandler(clickEvent -> {
		uiQueryObject.setQuery(searchBox.getValue());
		runSearch();
	});

	add(searchBox);

	CustomTextBox rowsIntegerBox = new CustomTextBox();
	rowsIntegerBox.setPlaceHolder("rows (defaults to 10)");
	if (uiQueryObject != null && uiQueryObject.getRows() != 10) {
		rowsIntegerBox.setValue(uiQueryObject.getRows() + "");
	}
	rowsIntegerBox.getTextBox().addChangeHandler(changeEvent -> uiQueryObject.setRows(Integer.valueOf(rowsIntegerBox.getValue())));
	rowsIntegerBox.addKeyUpHandler(clickEvent -> {
		if (clickEvent.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
			runSearch();
		}
	});

	add(rowsIntegerBox);

	filterQueryDiv = new Div();
	if (!uiQueryObject.getFilterQueries().isEmpty()) {
		for (String fq : uiQueryObject.getFilterQueries()) {
			createFilterQueryWidget(fq);
		}
	}
	else {
		createFilterQueryWidget(null);
	}

	add(filterQueryDiv);

}
 
Example #27
Source File: DecimalFormat.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DecimalFormat(String pattern) {
  formatter = NumberFormat.getFormat(pattern);
}