Example usage for java.text NumberFormat getIntegerInstance

List of usage examples for java.text NumberFormat getIntegerInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getIntegerInstance.

Prototype

public static NumberFormat getIntegerInstance(Locale inLocale) 

Source Link

Document

Returns an integer number format for the specified locale.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getIntegerInstance(Locale.CANADA);
    System.out.println(numberFormat.getMaximumFractionDigits());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    JFrame frame = new JFrame("Number Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Font font = new Font("SansSerif", Font.BOLD, 16);

    JLabel label;//from ww  w  .  j  av a2s. c o m
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format integer = NumberFormat.getIntegerInstance(Locale.ITALIAN);
    label = new JLabel("Italian integer:");
    input = new JFormattedTextField(integer);
    input.setValue(2424.50);
    input.setColumns(20);
    input.setFont(font);
    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);
    frame.add(panel);

    frame.pack();
    frame.setVisible(true);
}

From source file:org.mycore.frontend.editor.MCREditorVariable.java

private static NumberFormat getSortFormater() {
    NumberFormat format = NumberFormat.getIntegerInstance(Locale.ROOT);
    format.setMinimumIntegerDigits(4);/*from www .  ja  va  2  s. co  m*/
    format.setGroupingUsed(false);
    return format;
}

From source file:org.sonar.plugins.core.charts.DistributionAreaChart.java

@Override
protected Plot getPlot(ChartParameters params) {
    DefaultCategoryDataset dataset = createDataset(params);

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setCategoryMargin(0.0);/*from www  .  j av a  2s  .c o m*/
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance(params.getLocale()));
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    AreaRenderer renderer = new AreaRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    plot.setForegroundAlpha(0.5f);
    plot.setDomainGridlinesVisible(true);
    configureColors(dataset, plot, params.getValues(PARAM_COLORS, ","));
    return plot;
}

From source file:de.uka.aifb.com.systemDynamics.gui.ModelExecutionChartPanel.java

/**
 * Constructor./*from   ww  w . ja  v  a  2  s  .  c  o m*/
 * 
 * @param start {@link de.uka.aifb.com.systemDynamics.SystemDynamics} instance
 * @param model {@link de.uka.aifb.com.systemDynamics.model.Model} instance
 */
public ModelExecutionChartPanel(SystemDynamics start, Model model) {
    super(null);

    if (start == null) {
        throw new IllegalArgumentException("'start' must not be null");
    }
    if (model == null) {
        throw new IllegalArgumentException("'model' must not be null");
    }

    this.model = model;

    locale = start.getLocale();
    messages = start.getMessages();

    integerNumberFormatter = NumberFormat.getIntegerInstance(locale);

    createPanel();
}

From source file:org.mycore.frontend.cli.MCRCommand.java

/**
 * Creates a new MCRCommand./*from  w w w .  j ava 2s.co m*/
 * 
 * @param format
 *            the command syntax, e.g. "save document {0} to directory {1}"
 * @param methodSignature
 *            the method to invoke, e.g. "miless.commandline.DocumentCommands.saveDoc int String"
 * @param helpText
 *            the helpt text for this command
 */
public MCRCommand(String format, String methodSignature, String helpText) {
    StringTokenizer st = new StringTokenizer(methodSignature, " ");

    String token = st.nextToken();
    int point = token.lastIndexOf(".");

    className = token.substring(0, point);
    methodName = token.substring(point + 1);
    int numParameters = st.countTokens();
    parameterTypes = new Class<?>[numParameters];
    messageFormat = new MessageFormat(format, Locale.ROOT);

    for (int i = 0; i < numParameters; i++) {
        token = st.nextToken();

        Format f = null;
        switch (token) {
        case "int":
            parameterTypes[i] = Integer.TYPE;
            f = NumberFormat.getIntegerInstance(Locale.ROOT);
            break;
        case "long":
            parameterTypes[i] = Long.TYPE;
            f = NumberFormat.getIntegerInstance(Locale.ROOT);
            break;
        case "String":
            parameterTypes[i] = String.class;
            break;
        default:
            unsupportedArgException(methodSignature, token);
        }
        messageFormat.setFormat(i, f);
    }

    int pos = format.indexOf("{");
    suffix = pos == -1 ? format : format.substring(0, pos);

    if (helpText != null) {
        help = helpText;
    } else {
        help = "No help text available for this command";
    }
}

From source file:org.apache.empire.struts2.jsp.controls.TextInputControl.java

@Override
protected String formatValue(Object value, ValueInfo vi, boolean hasError) {
    // Lookup and Print value
    Options options = vi.getOptions();/*from  w  w w . j a va2 s  . c om*/
    if (options != null && !options.isEmpty()) { // Check for Options
        String text = options.get(value);
        if (text != null)
            return vi.getTranslation(text);
        // Error
        log.error("The element '" + String.valueOf(value) + "' is not part of the supplied option list.");
    }
    // Check Value
    if (value == null) { // Try to use default value 
        if (value != vi.getNullValue())
            return formatValue(vi.getNullValue(), vi, false);
        // Empty String
        return "";
    }
    // Format Value
    Column column = vi.getColumn();
    DataType dataType = getValueType(value, (column != null) ? column.getDataType() : DataType.UNKNOWN);
    if (dataType == DataType.TEXT || dataType == DataType.UNKNOWN) { // String
        String s = String.valueOf(value);
        if (hasFormatOption(vi, "noencode"))
            return s;
        // Encoded text
        return StringEscapeUtils.escapeHtml(s);
    }
    if (dataType == DataType.INTEGER || dataType == DataType.AUTOINC) { // Integer
        NumberFormat nf = NumberFormat.getIntegerInstance(vi.getUserLocale());
        nf.setGroupingUsed(false);
        return nf.format(value);
    }
    if (dataType == DataType.DECIMAL || dataType == DataType.FLOAT) { // Dezimal oder Double
        NumberFormat nf = getNumberFormat(dataType, vi.getUserLocale(), column);
        return nf.format(value);
    }
    if (dataType == DataType.DATE || dataType == DataType.DATETIME) { // Date or DateTime
        if (dataType == DataType.DATETIME && hasFormatOption(vi, "notime"))
            dataType = DataType.DATE;
        // Now format the date according to the user's locale
        DateFormat df = getDateFormat(dataType, vi.getUserLocale(), column);
        return df.format(value);
    }
    /*
     * if (dataType == DBDataType.BOOL) {
     *  }
     */
    // Convert to String
    return StringEscapeUtils.escapeHtml(String.valueOf(value));
}

From source file:com.norconex.commons.lang.unit.DataUnitFormatter.java

/**
 * Formats a data amount of the given unit to a human-readable 
 * representation.//from  w  w w  . j  a va2s.  c o  m
 * @param amount the amount to format
 * @param unit the data unit type of the amount
 * @return formatted string
 */
public String format(long amount, DataUnit unit) {

    // If no unit specified, return as string without a suffix
    if (unit == null) {
        return Long.toString(amount);
    }

    // Use coarser unit if applicable to make value more human-readable
    DataUnit finalUnit = unit;
    long finalAmount = amount;
    int ordinalShift = 0;
    if (!fixedUnit) {
        ordinalShift = (int) (Math.log(amount) / Math.log(K));
        if (ordinalShift > 0) {
            finalUnit = DATA_UNITS[Math.min(unit.ordinal() + ordinalShift, DATA_UNITS.length - 1)];
            finalAmount = finalUnit.convert(amount, unit);
        }
    }

    // Find out decimals
    long decimals = 0;
    if (decimalPrecision > 0 && unit.ordinal() < finalUnit.ordinal()) {
        int previousOrdinal = finalUnit.ordinal() - 1;
        if (previousOrdinal >= 0) {
            long originalBytes = unit.toBytes(amount);
            long finalBytes = finalUnit.toBytes(finalAmount);
            long diff = originalBytes - finalBytes;
            DataUnit previousUnit = DATA_UNITS[previousOrdinal];
            long remainder = previousUnit.convert(diff, DataUnit.B);
            long base = remainder * (long) Math.pow(D, decimalPrecision);
            decimals = base / K;
        }
    }

    Locale finalLocale = locale;
    if (finalLocale == null) {
        finalLocale = Locale.getDefault();
    }
    StringBuilder b = new StringBuilder();
    b.append(NumberFormat.getIntegerInstance(finalLocale).format(finalAmount));
    if (decimals > 0) {
        b.append(DecimalFormatSymbols.getInstance(finalLocale).getDecimalSeparator());
        b.append(StringUtils.left(Long.toString(decimals), decimalPrecision));
    }
    b.append('\u00A0').append(finalUnit.toString());
    return b.toString();
}

From source file:org.mycore.frontend.cli.MCRCommand.java

public MCRCommand(Method cmd) {
    className = cmd.getDeclaringClass().getName();
    methodName = cmd.getName();/*from  w ww  .j a  va2s  .c  o m*/
    parameterTypes = cmd.getParameterTypes();
    org.mycore.frontend.cli.annotation.MCRCommand cmdAnnotation = cmd
            .getAnnotation(org.mycore.frontend.cli.annotation.MCRCommand.class);
    help = cmdAnnotation.help();
    messageFormat = new MessageFormat(cmdAnnotation.syntax(), Locale.ROOT);
    setMethod(cmd);

    for (int i = 0; i < parameterTypes.length; i++) {
        Class<?> paramtype = parameterTypes[i];
        if (ClassUtils.isAssignable(paramtype, Integer.class, true)
                || ClassUtils.isAssignable(paramtype, Long.class, true)) {
            messageFormat.setFormat(i, NumberFormat.getIntegerInstance(Locale.ROOT));
        } else if (!String.class.isAssignableFrom(paramtype)) {
            unsupportedArgException(className + "." + methodName, paramtype.getName());
        }
    }

    int pos = cmdAnnotation.syntax().indexOf("{");
    suffix = pos == -1 ? cmdAnnotation.syntax() : cmdAnnotation.syntax().substring(0, pos);
}

From source file:connect.app.com.connect.calendar.SimpleMonthView.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SimpleMonthView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final Resources res = context.getResources();
    mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.date_picker_month_height);
    mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_of_week_height);
    mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_height);
    mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.date_picker_day_width);
    mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.date_picker_day_selector_radius);

    // Set up accessibility components.
    mTouchHelper = new MonthViewTouchHelper(this);
    //        setAccessibilityDelegate(mTouchHelper);
    setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);

    final Locale locale = res.getConfiguration().locale;
    final String titleFormat = DateFormat.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT);
    mTitleFormatter = new SimpleDateFormat(titleFormat, locale);
    mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale);
    mDayFormatter = NumberFormat.getIntegerInstance(locale);

    initPaints(res);/*from w w w  .ja  v  a  2  s.c o  m*/
}