use of com.ibm.icu.text.NumberFormat in project tdi-studio-se by Talend.
the class BusinessRulersAndGridComposite method setInput.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.views.properties.tabbed.ISection#setInput(org.eclipse.ui.IWorkbenchPart,
* org.eclipse.jface.viewers.ISelection)
*/
public void setInput() {
// super.setInput(part, selection);
// Set up workspace property listener
initWorkspacePropertyListener();
double value = getWorkspacePropertyDouble(WorkspaceViewerProperties.GRIDSPACING);
NumberFormat numberFormatter = NumberFormat.getNumberInstance();
textWidget.setText(numberFormatter.format(value));
rulerVisibilityButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.VIEWRULERS));
gridVisibilityButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.VIEWGRID));
gridOrderButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.GRIDORDER));
snapToGridButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.SNAPTOGRID));
snapToGeometryButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.SNAPTOGEOMETRY));
int rulerValue = getValue(WorkspaceViewerProperties.RULERUNIT);
int styleValue = getValue(WorkspaceViewerProperties.GRIDLINESTYLE) - 1;
rulerUnitCombo.setText(getUnits()[rulerValue]);
lineStyleCombo.setText(getStyles()[styleValue]);
Image overlyedImage = new ColorOverlayImageDescriptor((DiagramUIPropertiesImages.DESC_LINE_COLOR).getImageData(), FigureUtilities.integerToRGB(getWorkspacePropertyInt(WorkspaceViewerProperties.GRIDLINECOLOR))).createImage();
disposeImage(lineColorButton.getImage());
lineColorButton.setImage(overlyedImage);
}
use of com.ibm.icu.text.NumberFormat in project closure-templates by google.
the class I18NDirectivesRuntime method formatNum.
/**
* Formats a number using ICU4J. Note: If min or max fraction digits is null, the param will be
* ignored.
*/
public static String formatNum(ULocale uLocale, double number, String formatType, String numbersKeyword, @Nullable Integer minFractionDigits, @Nullable Integer maxFractionDigits) {
uLocale = uLocale.setKeywordValue("numbers", numbersKeyword);
NumberFormat numberFormat;
switch(formatType) {
case "decimal":
numberFormat = NumberFormat.getInstance(uLocale);
break;
case "percent":
numberFormat = NumberFormat.getPercentInstance(uLocale);
break;
case "currency":
numberFormat = NumberFormat.getCurrencyInstance(uLocale);
break;
case "scientific":
numberFormat = NumberFormat.getScientificInstance(uLocale);
break;
case "compact_short":
{
CompactDecimalFormat compactNumberFormat = CompactDecimalFormat.getInstance(uLocale, CompactStyle.SHORT);
compactNumberFormat.setMaximumSignificantDigits(3);
numberFormat = compactNumberFormat;
break;
}
case "compact_long":
{
CompactDecimalFormat compactNumberFormat = CompactDecimalFormat.getInstance(uLocale, CompactStyle.LONG);
compactNumberFormat.setMaximumSignificantDigits(3);
numberFormat = compactNumberFormat;
break;
}
default:
throw new IllegalArgumentException("First argument to formatNum must be " + "constant, and one of: 'decimal', 'currency', 'percent', 'scientific', " + "'compact_short', or 'compact_long'.");
}
if (minFractionDigits != null) {
numberFormat.setMinimumFractionDigits(minFractionDigits);
}
if (maxFractionDigits != null) {
numberFormat.setMaximumFractionDigits(maxFractionDigits);
}
return numberFormat.format(number);
}
use of com.ibm.icu.text.NumberFormat in project tdi-studio-se by Talend.
the class BusinessRulersAndGridComposite method convertUnits.
/**
*
* converts fromUnits to toUnits (e.g. inches to pixels)
*
* @param fromUnits
* @param toUnits
* @return equivalent number of toUnits for the given fromUnits
*/
private String convertUnits(int fromUnits, int toUnits) {
String valueStr = textWidget.getText();
if (fromUnits == toUnits) {
return valueStr;
}
Double value = convertStringToDouble(valueStr);
double pixelValue = 0;
switch(fromUnits) {
case INCHES:
pixelValue = value.doubleValue() * Display.getDefault().getDPI().x;
break;
case CENTIMETERS:
pixelValue = value.doubleValue() * Display.getDefault().getDPI().x / INCH2CM;
break;
case PIXELS:
pixelValue = value.intValue();
}
double returnValue = 0;
switch(toUnits) {
case INCHES:
returnValue = pixelValue / Display.getDefault().getDPI().x;
break;
case CENTIMETERS:
returnValue = pixelValue * INCH2CM / Display.getDefault().getDPI().x;
break;
case PIXELS:
returnValue = Math.round(pixelValue);
}
NumberFormat numberFormatter = NumberFormat.getInstance();
return numberFormatter.format(returnValue);
}
use of com.ibm.icu.text.NumberFormat in project tdi-studio-se by Talend.
the class BusinessRulersAndGridComposite method convertStringToDouble.
private Double convertStringToDouble(String strValue) {
NumberFormat numberFormatter = NumberFormat.getInstance();
Double value;
try {
value = forceDouble(numberFormatter.parse(strValue));
} catch (ParseException e) {
// default value
value = new Double(getWorkspacePropertyDouble(WorkspaceViewerProperties.GRIDSPACING));
setGridSpacing(value.doubleValue());
}
return value;
}
use of com.ibm.icu.text.NumberFormat in project tdi-studio-se by Talend.
the class BusinessRulersAndGridComposite method setGridSpacing.
private void setGridSpacing(double value) {
// Set grid spacing back to the input value
NumberFormat numberFormater = NumberFormat.getInstance();
textWidget.setText(numberFormater.format(value));
textWidget.selectAll();
}
Aggregations