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:com.tr4android.support.extension.picker.date.SimpleMonthView.java

public SimpleMonthView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    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);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

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

    initPaints(res);//  w  w  w  .  ja  v a  2  s. co m
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

private void init() {
    mContext = getContext();/*  w w w.j  a va2s . c  o m*/

    mTouchSlopSquared = ViewConfiguration.get(mContext).getScaledTouchSlop()
            * ViewConfiguration.get(mContext).getScaledTouchSlop();

    final Resources res = mContext.getResources();
    mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_month_height);
    mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_of_week_height);
    mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_height);
    mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_width);
    mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_selector_radius);
    mPaddingRangeIndicator = res.getDimensionPixelSize(R.dimen.sp_month_view_range_padding);

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

    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    final Locale locale = res.getConfiguration().locale;

    String titleFormat;

    if (SUtils.isApi_18_OrHigher()) {
        titleFormat = DateFormat.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT);
    } else {
        titleFormat = DateTimePatternHelper.getBestDateTimePattern(locale, DateTimePatternHelper.PATTERN_MMMMy);
    }

    mTitleFormatter = new SimpleDateFormat(titleFormat, locale);
    mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale);
    mDayFormatter = NumberFormat.getIntegerInstance(locale);

    initPaints(res);
}

From source file:org.mycore.datamodel.ifs.MCRAudioVideoExtender.java

/**
 * Returns the duration of the asset, formatted as a timcode, e. g.
 * "01:15:00" for an asset thats duration is one hour and 15 minutes.
 * //from  w  w w  .  j  a  va2 s .  c o  m
 * @return the duration foramatted as a timecode like "hh:mm:ss"
 */
public String getDurationTimecode() {
    NumberFormat formatter = NumberFormat.getIntegerInstance(Locale.ROOT);
    formatter.setGroupingUsed(false);
    formatter.setMinimumIntegerDigits(2);
    StringBuilder sb = new StringBuilder();
    sb.append(formatter.format(durationHours));
    sb.append(":");
    sb.append(formatter.format(durationMinutes));
    sb.append(":");
    sb.append(formatter.format(durationSeconds));

    return sb.toString();
}

From source file:com.miuhouse.yourcompany.student.view.widget.date.datepicker.SimpleMonthView.java

private void init() {
    mContext = getContext();//  w  ww  . ja v  a2 s . co  m

    mTouchSlopSquared = ViewConfiguration.get(mContext).getScaledTouchSlop()
            * ViewConfiguration.get(mContext).getScaledTouchSlop();

    final Resources res = mContext.getResources();
    mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_month_height);
    mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_of_week_height);
    mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_height);
    mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_width);
    mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_selector_radius);
    mPaddingRangeIndicator = res.getDimensionPixelSize(R.dimen.sp_month_view_range_padding);

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

    //        ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    final Locale locale = res.getConfiguration().locale;

    String titleFormat;

    if (SUtils.isApi_18_OrHigher()) {
        titleFormat = DateFormat.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT);
    } else {
        titleFormat = DateTimePatternHelper.getBestDateTimePattern(locale, DateTimePatternHelper.PATTERN_MMMMy);
    }

    mTitleFormatter = new SimpleDateFormat(titleFormat, locale);
    mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale);
    mDayFormatter = NumberFormat.getIntegerInstance(locale);

    initPaints(res);
}

From source file:com.rapidminer.tools.Tools.java

public static void setFormatLocale(Locale locale) {
    FORMAT_LOCALE = locale;/*  w w w . j  a  v a 2  s .c  o m*/
    NUMBER_FORMAT = NumberFormat.getInstance(locale);
    INTEGER_FORMAT = NumberFormat.getIntegerInstance(locale);
    PERCENT_FORMAT = NumberFormat.getPercentInstance(locale);
    FORMAT_SYMBOLS = new DecimalFormatSymbols(locale);
}

From source file:org.apache.solr.handler.admin.SolrInfoMBeanHandler.java

public Object diffObject(Object ref, Object now) {
    if (ref instanceof NamedList) {
        return diffNamedList((NamedList) ref, (NamedList) now);
    }//from   w ww .j  a va  2s. c  om
    if (ref.equals(now)) {
        return ref;
    }
    StringBuilder str = new StringBuilder();
    str.append("Was: ").append(ref).append(", Now: ").append(now);

    if (ref instanceof Number) {
        NumberFormat nf = NumberFormat.getIntegerInstance(Locale.ROOT);
        if ((ref instanceof Double) || (ref instanceof Float)) {
            nf = NumberFormat.getInstance(Locale.ROOT);
        }
        double dref = ((Number) ref).doubleValue();
        double dnow = ((Number) now).doubleValue();
        double diff = Double.NaN;
        if (Double.isNaN(dref)) {
            diff = dnow;
        } else if (Double.isNaN(dnow)) {
            diff = dref;
        } else {
            diff = dnow - dref;
        }
        str.append(", Delta: ").append(nf.format(diff));
    }
    return str.toString();
}

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

protected NumberFormat getNumberFormat(DataType dataType, Locale locale, Column column) {
    if (column == null)
        return NumberFormat.getNumberInstance(locale);
    // Column is supplied
    String type = StringUtils.valueOf(column.getAttribute(InputControl.NUMBER_FORMAT_ATTRIBUTE));
    NumberFormat nf = null;/*w  w w.ja  v  a2 s  .com*/
    if (type.equalsIgnoreCase("Integer"))
        nf = NumberFormat.getIntegerInstance(locale);
    /*
    else if (type.equalsIgnoreCase("Currency"))
    {   // nf = NumberFormat.getCurrencyInstance(locale);
    // Currency does not work as desired!
    nf = NumberFormat.getNumberInstance(locale);
    }
    else if (type.equalsIgnoreCase("Percent"))
    nf = NumberFormat.getPercentInstance(locale);
    */
    else
        nf = NumberFormat.getNumberInstance(locale);
    // Groups Separator?
    Object groupSep = column.getAttribute(InputControl.NUMBER_GROUPSEP_ATTRIBUTE);
    if (groupSep != null)
        nf.setGroupingUsed(ObjectUtils.getBoolean(groupSep));
    // Fraction Digits?
    Object fractDigit = column.getAttribute(InputControl.NUMBER_FRACTION_DIGITS);
    if (fractDigit != null) {
        int fractionDigits = ObjectUtils.getInteger(fractDigit);
        nf.setMaximumFractionDigits(fractionDigits);
        nf.setMinimumFractionDigits(fractionDigits);
    }
    // Number format
    return nf;
}

From source file:org.codehaus.groovy.grails.web.binding.GrailsDataBinder.java

/**
 * Registers all known//from  w  ww  .ja  va  2  s  .  co  m
 *
 * @param grailsWebRequest
 * @param registry
 * @param locale
 */
public static void registerCustomEditors(GrailsWebRequest grailsWebRequest, PropertyEditorRegistry registry,
        Locale locale) {
    // Formatters for the different number types.
    NumberFormat floatFormat = NumberFormat.getInstance(locale);
    NumberFormat integerFormat = NumberFormat.getIntegerInstance(locale);

    DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT, locale);

    registry.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    registry.registerCustomEditor(BigDecimal.class,
            new CustomNumberEditor(BigDecimal.class, floatFormat, true));
    registry.registerCustomEditor(BigInteger.class,
            new CustomNumberEditor(BigInteger.class, floatFormat, true));
    registry.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, floatFormat, true));
    registry.registerCustomEditor(double.class, new CustomNumberEditor(Double.class, floatFormat, true));
    registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, floatFormat, true));
    registry.registerCustomEditor(float.class, new CustomNumberEditor(Float.class, floatFormat, true));
    registry.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, integerFormat, true));
    registry.registerCustomEditor(long.class, new CustomNumberEditor(Long.class, integerFormat, true));
    registry.registerCustomEditor(Integer.class, new CustomNumberEditor(Integer.class, integerFormat, true));
    registry.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, integerFormat, true));
    registry.registerCustomEditor(Short.class, new CustomNumberEditor(Short.class, integerFormat, true));
    registry.registerCustomEditor(short.class, new CustomNumberEditor(Short.class, integerFormat, true));
    registry.registerCustomEditor(Date.class, new CompositeEditor(new StructuredDateEditor(dateFormat, true),
            new CustomDateEditor(new SimpleDateFormat(JSON_DATE_FORMAT), true)));
    registry.registerCustomEditor(Calendar.class, new StructuredDateEditor(dateFormat, true));

    ServletContext servletContext = grailsWebRequest != null ? grailsWebRequest.getServletContext() : null;
    registerCustomEditors(servletContext, registry);
}

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

/**
 * Creates the XY line chart.//from w  w  w. ja v  a 2s. c  om
 * 
 * @return XY line chart
 */
private JFreeChart createChart() {
    levelNodes = new LevelNode[model.getLevelNodes().size()];
    int i = 0;
    for (LevelNode levelNode : model.getLevelNodes()) {
        levelNodes[i++] = levelNode;
    }
    // sort level nodes alphabetically
    Arrays.sort(levelNodes);

    xySeriesArray = new XYSeries[levelNodes.length];
    XYSeriesCollection data = new XYSeriesCollection();
    for (i = 0; i < xySeriesArray.length; i++) {
        XYSeries xySeries = new XYSeries(levelNodes[i].getNodeName());
        xySeries.add(0.0, levelNodes[i].getCurrentValue());
        data.addSeries(xySeries);
        xySeriesArray[i] = xySeries;
    }
    nextRound = 1;

    chart = ChartFactory.createXYLineChart(null, messages.getString("ModelExecutionChartPanel.Round"),
            messages.getString("ModelExecutionChartPanel.Value"), data, PlotOrientation.VERTICAL, true, false,
            false);
    XYPlot plot = chart.getXYPlot();

    // horizontal axis range: 0 ... maximal rounds
    ((NumberAxis) (chart.getXYPlot().getDomainAxis())).setRangeType(RangeType.POSITIVE);
    plot.getDomainAxis().setAutoRangeMinimumSize(20);

    // only integer values as labels for horizontal axis
    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // number formatting according to current locale
    ((NumberAxis) (plot.getDomainAxis())).setNumberFormatOverride(NumberFormat.getIntegerInstance(locale));
    ((NumberAxis) (plot.getRangeAxis())).setNumberFormatOverride(NumberFormat.getInstance(locale));

    // legend at top position
    chart.getLegend().setPosition(RectangleEdge.TOP);

    return chart;
}