Example usage for java.text NumberFormat getPercentInstance

List of usage examples for java.text NumberFormat getPercentInstance

Introduction

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

Prototype

public static final NumberFormat getPercentInstance() 

Source Link

Document

Returns a percentage format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:de.alpharogroup.wicket.js.addon.core.PercentNumberFormatTextValue.java

/**
 * Gets the percent formatted./*from  ww w.j  a  va 2  s  .co m*/
 *
 * @param value
 *            the value
 * @return the percent formatted
 */
private String getPercentFormatted(final Integer value) {
    final Integer val = checkQuietly(getName(), value);
    return NumberFormat.getPercentInstance().format((double) val / 100);
}

From source file:com.github.gerbsen.math.Frequency.java

/**
 * Return a string representation of this frequency
 * distribution./*w w w .  j a v a  2  s .co m*/
 *
 * @return a string representation.
 */
@Override
public String toString() {
    NumberFormat nf = NumberFormat.getPercentInstance();
    StringBuilder outBuffer = new StringBuilder();
    outBuffer.append("Value \t Freq. \t Pct. \t Cum Pct. \n");
    Iterator<Comparable<?>> iter = freqTable.keySet().iterator();
    while (iter.hasNext()) {
        Comparable<?> value = iter.next();
        outBuffer.append(value);
        outBuffer.append('\t');
        outBuffer.append(getCount(value));
        outBuffer.append('\t');
        outBuffer.append(nf.format(getPct(value)));
        outBuffer.append('\t');
        outBuffer.append(nf.format(getCumPct(value)));
        outBuffer.append('\n');
    }
    return outBuffer.toString();
}

From source file:de.main.sessioncreator.ReportingHelper.java

/**
 * Creates a chart//from   w  ww .  jav a 2 s  . c  om
 */
private JFreeChart createChart(PieDataset dataset, String title) {

    //        JFreeChart chart = ChartFactory.createPieChart3D(
    JFreeChart chart = ChartFactory.createPieChart(title, // chart title
            dataset, // data
            false, // include legend
            true, false);

    //        PiePlot3D plot = (PiePlot3D) chart.getPlot();
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setStartAngle(90);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    return chart;

}

From source file:edu.monash.merc.struts2.action.TLSumChartAction.java

@SuppressWarnings("unchecked")
public String piechart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Green", l4);
    dataset.setValue("Yellow", l3);
    dataset.setValue("Red", l2);
    dataset.setValue("Black", l1);

    chart = ChartFactory.createPieChart(dt, dataset, true, true, false);
    PiePlot plot = (PiePlot) chart.getPlot();

    plot.setBackgroundPaint(Color.WHITE);
    //no border//from  w  ww .  j ava 2s.com
    plot.setOutlineStroke(null);
    //no label
    plot.setLabelGenerator(null);

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(2);
    plot.setLegendLabelGenerator(
            new StandardPieSectionLabelGenerator("{0}={2}", NumberFormat.getNumberInstance(), percentFormat));
    //set specific colors  green, yellow, red and black
    Color[] colors = { new Color(0, 140, 0), new Color(254, 172, 0), new Color(226, 0, 40),
            new Color(0, 0, 0) };
    setColor(plot, dataset, colors);

    chart.setBackgroundPaint(Color.WHITE);
    chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(11.0f));
    return SUCCESS;
}

From source file:com.vladium.emma.report.html.ReportGenerator.java

public ReportGenerator() {
    m_format = (DecimalFormat) NumberFormat.getPercentInstance(); // TODO: locale
    m_fieldPosition = new FieldPosition(DecimalFormat.INTEGER_FIELD);

    m_format.setMaximumFractionDigits(0);
}

From source file:net.droidsolutions.droidcharts.core.label.AbstractCategoryItemLabelGenerator.java

/**
 * Creates a label generator with the specified number formatter.
 *
 * @param labelFormat  the label format string (<code>null</code> not
 *                     permitted).//from   ww w  .  j a  v  a  2  s  .  com
 * @param formatter  the number formatter (<code>null</code> not permitted).
 */
protected AbstractCategoryItemLabelGenerator(String labelFormat, NumberFormat formatter) {
    this(labelFormat, formatter, NumberFormat.getPercentInstance());
}

From source file:com.twocents.report.charts.StandardPieItemLabelGenerator.java

/**
 * Creates an item label generator using default number formatters.
 *///w  w  w  .  j  a v  a2s .  co m
public StandardPieItemLabelGenerator() {
    this(DEFAULT_SECTION_LABEL_FORMAT, NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance());
}

From source file:cn.edu.thss.iise.bpmdemo.statistics.actions.ModelReusePanel.java

private JPanel createPanel() throws IOException {
    createDataSet();/*from   ww w . j a  v  a 2 s. com*/

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Reused Times", // chart
            // title
            data1, // dataset
            false, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(222, 222, 255));

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setCircular(true);
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    String[] columnNames = { "Name", "Reuse Times" };
    JTable table = new JTable(data2, columnNames);
    JPanel panel = new JPanel();
    panel.add(chartPanel);
    panel.add(table);
    final Rotator rotator = new Rotator(plot);
    rotator.start();
    return panel;
}

From source file:org.codekaizen.vtj.text.BpNumberFormatTest.java

/**
 * DOCUMENT ME!//from  w w w .  j a  v  a2 s  .co  m
 */
@Test
public void testFormatting() {
    NumberFormat fmt1 = null;
    NumberFormat fmt2 = null;
    String s1 = null;
    String s2 = null;
    Number num1 = null;

    fmt1 = new BpNumberFormat(BpNumberFormat.JVM_NUMBER, null);
    fmt2 = NumberFormat.getNumberInstance();
    num1 = new Integer(25436);
    s1 = fmt1.format(num1);
    s2 = fmt2.format(num1);
    assertEquals(s2, s1);

    num1 = new Double(1228.744);
    s1 = fmt1.format(num1);
    s2 = fmt2.format(num1);
    assertEquals(s2, s1);

    fmt1 = new BpNumberFormat(BpNumberFormat.JVM_CURRENCY, null);
    fmt2 = NumberFormat.getCurrencyInstance();
    num1 = new Integer(25436);
    s1 = fmt1.format(num1);
    s2 = fmt2.format(num1);
    assertEquals(s2, s1);

    num1 = new Double(1228.744);
    s1 = fmt1.format(num1);
    s2 = fmt2.format(num1);
    assertEquals(s2, s1);

    fmt1 = new BpNumberFormat(BpNumberFormat.JVM_CURRENCY, Locale.CANADA);
    fmt2 = NumberFormat.getCurrencyInstance(Locale.CANADA);
    num1 = new Integer(25436);
    s1 = fmt1.format(num1);
    s2 = fmt2.format(num1);
    assertEquals(s2, s1);

    num1 = new Double(1228.744);
    s1 = fmt1.format(num1);
    s2 = fmt2.format(num1);
    assertEquals(s2, s1);

    fmt1 = new BpNumberFormat(BpNumberFormat.JVM_PERCENT, null);
    fmt2 = NumberFormat.getPercentInstance();
    num1 = new Double(0.7444);
    s1 = fmt1.format(num1);
    s2 = fmt2.format(num1);
    assertEquals(s2, s1);

}

From source file:de.uhh.l2g.upload.FileUploadProgressListener.java

/**
 * Gets the file upload status./*from  ww  w .j  a  v a2s.  c o m*/
 *
 * @return the file upload status
 */
private String getFileUploadStatus() {
    // per looks like 0% - 100%, remove % before submission
    String per = NumberFormat.getPercentInstance().format((double) bytesTransferred / (double) fileSize);
    String ret = per.substring(0, per.length() - 1);
    return ret;
}