Example usage for java.text NumberFormat getInstance

List of usage examples for java.text NumberFormat getInstance

Introduction

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

Prototype

public static final NumberFormat getInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:org.jajuk.ui.views.StatView.java

/**
 * Creates the bar chart3 d./*from w  w  w  .  jav a 2 s .co m*/
 * 
 * 
 * @param title 
 * @param categoryAxisLabel 
 * @param valueAxisLabel 
 * @param dataset 
 * @param orientation 
 * @param legend 
 * @param tooltips 
 * @param urls 
 * @param format 
 * 
 * @return the j free chart
 */
public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls,
        String format) {
    if (orientation == null)
        throw new IllegalArgumentException("Null 'orientation' argument.");
    CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel);
    BarRenderer3D renderer = new BarRenderer3D();
    if (tooltips)
        renderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator(format, NumberFormat.getInstance()));
    if (urls)
        renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        plot.setRowRenderingOrder(SortOrder.DESCENDING);
        plot.setColumnRenderingOrder(SortOrder.DESCENDING);
    }
    plot.setForegroundAlpha(0.75F);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    ChartFactory.getChartTheme().apply(chart);
    return chart;
}

From source file:com.joulespersecond.seattlebusbot.RegionsFragment.java

/**
 * Sets the text view that contains distance with units based on input parameters
 *
 * @param text     the TextView to be set
 * @param distance the distance to be used, in miles (for imperial) or kilometers (for metric)
 * @param units    the units to be used from strings.xml, either preferences_preferred_units_option_metric
 *                 or preferences_preferred_units_option_imperial
 *//*from  www  .  j a v a 2s  . c  o m*/
private void setDistanceTextView(TextView text, double distance, String units) {
    Resources r = getResources();
    NumberFormat fmt = NumberFormat.getInstance();
    if (fmt instanceof DecimalFormat) {
        ((DecimalFormat) fmt).setMaximumFractionDigits(1);
    }

    if (units.equalsIgnoreCase(getString(R.string.preferences_preferred_units_option_imperial))) {
        text.setText(
                r.getQuantityString(R.plurals.region_distance_miles, (int) distance, fmt.format(distance)));
    } else if (units.equalsIgnoreCase(getString(R.string.preferences_preferred_units_option_metric))) {
        text.setText(r.getQuantityString(R.plurals.region_distance_kilometers, (int) distance,
                fmt.format(distance)));
    }
}

From source file:uk.ac.lkl.cram.ui.chart.HoursChartMaker.java

/**
 * Create a chart from the provided category dataset
 * @return a Chart that can be rendered in a ChartPanel
 *///  w  ww . j a  va 2s. co m
@Override
protected JFreeChart createChart() {
    //Create a vertical stacked bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs
    JFreeChart chart = ChartFactory.createStackedBarChart(null, null, null, (CategoryDataset) dataset,
            PlotOrientation.VERTICAL, true, true, false);
    //Get the font from the platform UI
    Font chartFont = UIManager.getFont("Label.font");
    //Get the plot from the chart
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //Get the renderer from the plot
    StackedBarRenderer sbRenderer = (StackedBarRenderer) plot.getRenderer();
    //Set the rendered to use a standard bar painter (nothing fancy)
    sbRenderer.setBarPainter(new StandardBarPainter());
    //Set the colours for the bars
    sbRenderer.setSeriesPaint(0, PREPARATION_COLOR);
    sbRenderer.setSeriesPaint(1, SUPPORT_COLOR);
    //Set the tooltip to be series, category and value
    sbRenderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{0}, {1} ({2})", NumberFormat.getInstance()));
    //Get the category axis (that's the X-axis in this case)
    CategoryAxis categoryAxis = plot.getDomainAxis();
    //Set the font for rendering the labels on the x-axis to be the platform default
    categoryAxis.setLabelFont(chartFont);
    //Get the number axis (that's the Y-axis in this case)
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    //Use the same font as the x-axis
    numberAxis.setLabelFont(chartFont);
    return chart;
}

From source file:net.fabiszewski.ulogger.MainActivity.java

/**
 * Called when the user clicks the track text view
 * @param view View/*w  w w  .j av  a  2s  .  c  o  m*/
 */
public void trackSummary(@SuppressWarnings("UnusedParameters") View view) {
    final TrackSummary summary = db.getTrackSummary();
    if (summary == null) {
        showToast(getString(R.string.no_positions));
        return;
    }

    @SuppressLint("InflateParams")
    View summaryView = getLayoutInflater().inflate(R.layout.summary, null, false);
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle(getString(R.string.track_summary));
    alertDialog.setView(summaryView);
    alertDialog.setIcon(R.drawable.ic_equalizer_white_24dp);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();

    final TextView summaryDistance = (TextView) alertDialog.findViewById(R.id.summary_distance);
    final TextView summaryDuration = (TextView) alertDialog.findViewById(R.id.summary_duration);
    final TextView summaryPositions = (TextView) alertDialog.findViewById(R.id.summary_positions);
    double distance = (double) summary.getDistance() / 1000;
    String unitName = getString(R.string.unit_kilometer);
    if (pref_units.equals(getString(R.string.pref_units_imperial))) {
        distance *= KM_MILE;
        unitName = getString(R.string.unit_mile);
    }
    final NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    final String distanceString = nf.format(distance);
    summaryDistance.setText(getString(R.string.summary_distance, distanceString, unitName));
    final long h = summary.getDuration() / 3600;
    final long m = summary.getDuration() % 3600 / 60;
    summaryDuration.setText(getString(R.string.summary_duration, h, m));
    int positionsCount = (int) summary.getPositionsCount();
    if (needsPluralFewHack(positionsCount)) {
        summaryPositions.setText(getResources().getString(R.string.summary_positions_few, positionsCount));
    } else {
        summaryPositions.setText(
                getResources().getQuantityString(R.plurals.summary_positions, positionsCount, positionsCount));
    }
}

From source file:com.commander4j.util.JUtility.java

public static String bigDecimaltoString(BigDecimal bd) {
    String result = "";
    NumberFormat nf1 = NumberFormat.getInstance();

    nf1 = NumberFormat.getInstance();
    nf1.setMinimumFractionDigits(3);//from   w w  w .  jav a  2 s.  co  m
    nf1.setMaximumFractionDigits(3);
    result = nf1.format(bd);

    return result;
}

From source file:com.levien.audiobuffersize.AudioBufferSize.java

ThreadMeasurement analyzeJitter(double[] arr) {
    int n = arr.length / 4;
    double maxCbDoneDelay = 0;
    double maxThreadDelay = 0;
    double maxRenderDelay = 0;
    for (int i = 100; i < n; i++) {
        double callback_ts = arr[i - 0];
        double cbdone_ts = arr[n + i];
        double thread_ts = arr[2 * n + i];
        double render_ts = arr[3 * n + i];
        maxCbDoneDelay = Math.max(maxCbDoneDelay, cbdone_ts - callback_ts);
        maxThreadDelay = Math.max(maxThreadDelay, thread_ts - callback_ts);
        maxRenderDelay = Math.max(maxRenderDelay, render_ts - callback_ts);
    }//from  w  w  w  .  j a  v a  2s. co m
    NumberFormat f = NumberFormat.getInstance();
    f.setMinimumFractionDigits(3);
    f.setMaximumFractionDigits(3);
    ThreadMeasurement tm = new ThreadMeasurement();
    tm.cbDone = maxCbDoneDelay;
    tm.renderStart = maxThreadDelay;
    tm.renderEnd = maxRenderDelay;
    return tm;
}

From source file:org.datacleaner.widgets.result.AbstractCrosstabResultSwingRenderer.java

private static String getLabelText(Object value) {
    if (value == null) {
        return LabelUtils.NULL_LABEL;
    } else if ("".equals(value)) {
        return LabelUtils.BLANK_LABEL;
    } else if (value instanceof Double || value instanceof Float) {
        return NumberFormat.getInstance().format(value);
    } else {/*  w w w.jav a 2  s .  co  m*/
        return value.toString();
    }
}

From source file:com.streak.logging.analysis.AnalysisUtility.java

private static NumberFormat createFixedPointFormat() {
    if (fixedPoint == null) {
        // Avoid scientific notation output
        fixedPoint = NumberFormat.getInstance();
        fixedPoint.setGroupingUsed(false);
        fixedPoint.setParseIntegerOnly(false);
        fixedPoint.setMinimumFractionDigits(1);
        fixedPoint.setMaximumFractionDigits(30);
        fixedPoint.setMinimumIntegerDigits(1);
        fixedPoint.setMaximumIntegerDigits(30);
    }//from  w  ww .  ja v  a 2s .com
    return fixedPoint;
}

From source file:net.sourceforge.dvb.projectx.common.Common.java

/**
 * /*from   www.  j av  a2 s  . c om*/
 */
public static String formatNumber(long val) {
    return NumberFormat.getInstance().format(val);
}

From source file:TextBouncer.java

public AnimationFrame(TextBouncer ac) {
    super();/*  w  w  w. j a va 2s. com*/
    setLayout(new BorderLayout());
    add(ac, BorderLayout.CENTER);
    add(mStatusLabel = new Label(), BorderLayout.SOUTH);
    // Create a number formatter.
    mFormat = NumberFormat.getInstance();
    mFormat.setMaximumFractionDigits(1);
    // Listen for the frame rate changes.
    ac.setRateListener(this);
    // Kick off the animation.
    Thread t = new Thread(ac);
    t.start();
}