Example usage for java.text NumberFormat getNumberInstance

List of usage examples for java.text NumberFormat getNumberInstance

Introduction

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

Prototype

public static final NumberFormat getNumberInstance() 

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.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public void addAxisToPlot(DataItem item) {
    String axisName = item.getName();
    NumberAxis rangeAxis = new NumberAxis(axisName);
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRange(false);//from  w w  w  . java  2  s  . c o m
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    rangeAxis.setNumberFormatOverride(format);
    rangeAxis.setLowerBound(scene.getRangeMin());
    rangeAxis.setUpperBound(scene.getRangeMax());
    plot.setRangeAxis(rangeAxisCount, rangeAxis);
    axisTable.put(item, rangeAxisCount);
    rangeAxisCount++;
}

From source file:de.berlios.jhelpdesk.web.ticket.TicketNewWizardController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, nf, true));
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
    binder.registerCustomEditor(User.class, userEditor);
    binder.registerCustomEditor(TicketPriority.class, ticketPriorityEditor);
    binder.registerCustomEditor(TicketCategory.class, ticketCategoryEditor);
}

From source file:guineu.modules.dataanalysis.PCA.ProjectionPlotPanel.java

public ProjectionPlotPanel(ProjectionPlotWindow masterFrame, ProjectionPlotDataset dataset,
        ParameterSet parameters) {//from   w w w.j  a v  a2 s.  c  o  m
    super(null);

    boolean createLegend = true;
    if (dataset.getNumberOfGroups() > 20) {
        createLegend = false;
    }

    chart = ChartFactory.createXYAreaChart("", dataset.getXLabel(), dataset.getYLabel(), dataset,
            PlotOrientation.VERTICAL, createLegend, false, false);
    chart.setBackgroundPaint(Color.white);

    setChart(chart);

    // title

    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);
    chart.removeSubtitle(chartTitle);

    // disable maximum size (we don't want scaling)
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    plot.setForegroundAlpha(dataPointAlpha);

    NumberFormat numberFormat = NumberFormat.getNumberInstance();

    // set the X axis (component 1) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setNumberFormatOverride(numberFormat);

    // set the Y axis (component 2) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setNumberFormatOverride(numberFormat);

    plot.setDataset(dataset);

    spotRenderer = new ProjectionPlotRenderer(plot, dataset);
    itemLabelGenerator = new ProjectionPlotItemLabelGenerator(parameters);
    spotRenderer.setBaseItemLabelGenerator(itemLabelGenerator);
    spotRenderer.setBaseItemLabelsVisible(true);
    spotRenderer.setBaseToolTipGenerator(new ProjectionPlotToolTipGenerator(parameters));
    plot.setRenderer(spotRenderer);

    // Setup legend
    if (createLegend) {
        LegendItemCollection legendItemsCollection = new LegendItemCollection();
        for (int groupNumber = 0; groupNumber < dataset.getNumberOfGroups(); groupNumber++) {
            Object paramValue = dataset.getGroupParameterValue(groupNumber);
            if (paramValue == null) {
                // No parameter value available: search for raw data files
                // within this group, and use their names as group's name
                String fileNames = new String();
                for (int itemNumber = 0; itemNumber < dataset.getItemCount(0); itemNumber++) {
                    String rawDataFile = dataset.getRawDataFile(itemNumber);
                    if (dataset.getGroupNumber(itemNumber) == groupNumber) {
                        fileNames = fileNames.concat(rawDataFile);
                    }
                }
                if (fileNames.length() == 0) {
                    fileNames = "Empty group";
                }

                paramValue = fileNames;
            }
            Color nextColor = (Color) spotRenderer.getGroupPaint(groupNumber);
            Color groupColor = new Color(nextColor.getRed(), nextColor.getGreen(), nextColor.getBlue(),
                    (int) Math.round(255 * dataPointAlpha));
            legendItemsCollection.add(new LegendItem(paramValue.toString(), "-", null, null,
                    spotRenderer.getDataPointsShape(), groupColor));
        }
        plot.setFixedLegendItems(legendItemsCollection);
    } else {

        Dataset legends = new SimpleBasicDataset("Legends");
        legends.addColumnName("Samples");

        for (int groupNumber = 0; groupNumber < dataset.getNumberOfGroups(); groupNumber++) {
            Object paramValue = dataset.getGroupParameterValue(groupNumber);
            if (paramValue == null) {
                // No parameter value available: search for raw data files
                // within this group, and use their names as group's name
                String fileNames = new String();
                for (int itemNumber = 0; itemNumber < dataset.getItemCount(0); itemNumber++) {
                    String rawDataFile = dataset.getRawDataFile(itemNumber);
                    if (dataset.getGroupNumber(itemNumber) == groupNumber) {
                        fileNames = fileNames.concat(rawDataFile.toString());
                    }
                }
                if (fileNames.length() == 0) {
                    fileNames = "Empty group";
                }

                paramValue = fileNames;
            }

            Color nextColor = (Color) spotRenderer.getGroupPaint(groupNumber);
            Color groupColor = new Color(nextColor.getRed(), nextColor.getGreen(), nextColor.getBlue(),
                    (int) Math.round(255 * dataPointAlpha));

            PeakListRow row = new SimplePeakListRowOther();
            row.setPeak("Samples", paramValue.toString());
            legends.addRow(row);
            legends.addRowColor(groupColor);
        }

        GuineuCore.getDesktop().AddNewFile(legends);
    }

}

From source file:com.pureinfo.srm.reports.impl.PieChartBuilder.java

/**
 * @throws PureException//from   w  ww  . j av a  2 s  . c o m
 * @see com.pureinfo.srm.reports.IChartBuilder#draw(java.util.List, int)
 */
public JFreeChart buildChart() {
    Iterator result = m_datas.iterator();
    DefaultPieDataset ds = getDataset(result);

    JFreeChart jfreechart = ChartFactory.createPieChart3D(null, ds, false, false, false);
    jfreechart.setBackgroundPaint(Color.WHITE);

    PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot();
    pieplot3d.setOutlinePaint(Color.GRAY);
    pieplot3d.setOutlineStroke(new BasicStroke(1));
    pieplot3d.setStartAngle(30D);
    pieplot3d.setDepthFactor(0.04);
    pieplot3d.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(),
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));

    pieplot3d.setCircular(false);
    pieplot3d.setDirection(Rotation.CLOCKWISE);
    pieplot3d.setOutlinePaint(Color.WHITE);
    pieplot3d.setInteriorGap(.15);
    Color color = new Color(0xaa, 0xaa, 0xaa, 255);
    pieplot3d.setBaseSectionOutlinePaint(color);
    pieplot3d.setBaseSectionOutlineStroke(new BasicStroke(0));
    pieplot3d.setForegroundAlpha(0.6f);
    pieplot3d.setLabelLinkStroke(new BasicStroke(1));
    pieplot3d.setLabelOutlinePaint(new Color(0x777777));
    pieplot3d.setLabelBackgroundPaint(new Color(0xf1f1f7));
    pieplot3d.setLabelLinkPaint(new Color(0xaa, 0xaa, 0xaa, 60));
    pieplot3d.setNoDataMessage("No data to display");
    pieplot3d.setLabelShadowPaint(new Color(0xdddddd));
    pieplot3d.setLabelFont(new Font("", Font.PLAIN, 10));
    if (m_nType == TYPE_PERCENT) {

        pieplot3d.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}",
                NumberFormat.getNumberInstance(), PERCENT_NUMBER_FORMAT));
    }

    fillChartInfo(ds);
    return jfreechart;
}

From source file:io.github.mzmine.util.jfreechart.ManualZoomDialog.java

@FXML
public void initialize() {

    NumberFormat xAxisFormatter;/* w ww .ja va2 s .com*/
    if (xAxis instanceof NumberAxis)
        xAxisFormatter = ((NumberAxis) xAxis).getNumberFormatOverride();
    else
        xAxisFormatter = NumberFormat.getNumberInstance();

    NumberFormat yAxisFormatter;
    if (yAxis instanceof NumberAxis)
        yAxisFormatter = ((NumberAxis) yAxis).getNumberFormatOverride();
    else
        yAxisFormatter = NumberFormat.getNumberInstance();

    xAxisLabel.setText(xAxis.getLabel());
    yAxisLabel.setText(yAxis.getLabel());

    xAxisRangeMin.setTextFormatter(new TextFormatter<>(new NumberStringConverter(xAxisFormatter)));
    xAxisRangeMin.disableProperty().bind(xAxisAutoRange.selectedProperty());
    xAxisRangeMin.setText(String.valueOf(xAxis.getLowerBound()));
    xAxisRangeMax.setTextFormatter(new TextFormatter<>(new NumberStringConverter(xAxisFormatter)));
    xAxisRangeMax.disableProperty().bind(xAxisAutoRange.selectedProperty());
    xAxisRangeMax.setText(String.valueOf(xAxis.getUpperBound()));
    xAxisAutoRange.setSelected(xAxis.isAutoRange());

    yAxisRangeMin.setTextFormatter(new TextFormatter<>(new NumberStringConverter(yAxisFormatter)));
    yAxisRangeMin.setText(String.valueOf(yAxis.getLowerBound()));
    yAxisRangeMin.disableProperty().bind(yAxisAutoRange.selectedProperty());
    yAxisRangeMax.setTextFormatter(new TextFormatter<>(new NumberStringConverter(yAxisFormatter)));
    yAxisRangeMax.setText(String.valueOf(yAxis.getUpperBound()));
    yAxisRangeMax.disableProperty().bind(yAxisAutoRange.selectedProperty());
    yAxisAutoRange.setSelected(yAxis.isAutoRange());

    xAxisTickSize.disableProperty().bind(xAxisAutoTickSize.selectedProperty());
    xAxisTickSize.setText(String.valueOf(xAxis.getTickUnit().getSize()));
    xAxisAutoTickSize.setSelected(xAxis.isAutoTickUnitSelection());

    yAxisTickSize.setTextFormatter(new TextFormatter<>(new NumberStringConverter(yAxisFormatter)));
    yAxisTickSize.setText(String.valueOf(yAxis.getTickUnit().getSize()));
    yAxisTickSize.disableProperty().bind(yAxisAutoTickSize.selectedProperty());
    yAxisAutoTickSize.setSelected(yAxis.isAutoTickUnitSelection());

}

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

/**
 * Creates a chart// w  w w. j a  va 2  s. co  m
 */
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:net.sf.dynamicreports.design.transformation.chartcustomizer.ShowValuesCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    if (chart.getPlot() instanceof CategoryPlot) {
        CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
        if (StringUtils.isBlank(valuePattern)) {
            renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        } else {/*from  w  ww. ja v  a2s .c om*/
            renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
                    StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING,
                    new DecimalFormat(valuePattern)));
        }
        renderer.setBaseItemLabelsVisible(Boolean.TRUE);
        chart.getCategoryPlot().getRangeAxis().zoomRange(0, 1.1);
        if (renderer.getClass().equals(BarRenderer3D.class)) {
            ((BarRenderer3D) renderer).setItemLabelAnchorOffset(10D);
            renderer.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
        }
    } else if (chart.getPlot() instanceof XYPlot) {
        XYItemRenderer renderer = chart.getXYPlot().getRenderer();
        if (StringUtils.isBlank(valuePattern)) {
            renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
        } else {
            renderer.setBaseItemLabelGenerator(
                    new StandardXYItemLabelGenerator(StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT,
                            NumberFormat.getNumberInstance(), new DecimalFormat(valuePattern)));
        }
        renderer.setBaseItemLabelsVisible(Boolean.TRUE);
        chart.getXYPlot().getRangeAxis().zoomRange(0, 1.1);
    }
}

From source file:org.apache.hadoop.hive.ql.udf.UDFNumberFormat.java

public String evaluate(DoubleWritable d, IntWritable fracMax, IntWritable intMax) {
    if (d == null || fracMax == null || intMax == null) {
        return null;
    }//from ww w.j  av  a 2 s.c  om
    double ori = d.get();
    try {
        NumberFormat nFormat = NumberFormat.getNumberInstance();
        nFormat.setMaximumFractionDigits(fracMax.get());
        nFormat.setMaximumIntegerDigits(intMax.get());
        nFormat.setGroupingUsed(false);
        return nFormat.format(ori);
    } catch (Exception e) {
        LOG.error("can not format value:  " + ori);
        return null;
    }
}

From source file:com.ouc.cpss.view.SupTradeChartBuilder.java

private static JFreeChart createJFreeChart(PieDataset dataset) {
    /**/*from w  w w  .  j a  v a2s. com*/
     * JFreeChart
     */
    //?     
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //     
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //    
    standardChartTheme.setRegularFont(new Font("", Font.PLAIN, 15));
    //?     
    standardChartTheme.setLargeFont(new Font("", Font.PLAIN, 15));
    //?   
    ChartFactory.setChartTheme(standardChartTheme);
    //??  
    //createPieChart 2D; createPieChart3D  3D
    JFreeChart chart = ChartFactory.createPieChart("", dataset, true, true, false);

    //,?
    chart.setTitle(new TextTitle("", new Font("", Font.ITALIC, 22)));

    //?
    LegendTitle legend = chart.getLegend(0);
    //,ture,?
    legend.setItemFont(new Font("", Font.BOLD, 20));

    //?(??)
    PiePlot plot = (PiePlot) chart.getPlot();
    //?==?
    plot.setLabelFont(new Font("", Font.BOLD, 22));
    //
    plot.setBaseSectionOutlinePaint(Color.BLUE);
    //
    plot.setBaseSectionOutlineStroke(new BasicStroke(0.5f));
    //?,??,??
    plot.setDirection(Rotation.CLOCKWISE);//,Rotation.CLOCKWISE
    //()
    plot.setStartAngle(70);
    //???
    //plot.setExplodePercent(1, 0.5D);
    //plot.setExplodePercent("One", 0.5D);
    //,3D?
    plot.setExplodePercent(dataset.getKey(0), 0.1d);
    //
    plot.setLabelLinkPaint(Color.BLUE);
    //
    plot.setLabelOutlinePaint(Color.black);
    //
    plot.setLabelShadowPaint(Color.RED);
    //
    plot.setSectionPaint(1, Color.BLACK);
    // :,{0},{1},{2}?,???
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}\r\n{2}",
            NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));

    //
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={2}"));
    //:(true),(false)
    plot.setCircular(true);
    //?
    plot.setNoDataMessage("??...");

    //???
    plot.setToolTipGenerator(new StandardPieToolTipGenerator());
    //
    //plot.setURLGenerator(new StandardPieURLGenerator("detail.jsp"));

    return chart;
}

From source file:io.pcp.parfait.benchmark.CPUThreadTest.java

private void report(List<CPUThreadTestRunner> cpuThreadTestRunners, double timeTakenms, int iterations,
        boolean cpuTracingEnabled, CPUThreadTestRunner.CpuLookupMethod cpuLookupMethod) {
    long totalBlockedCount = computeTotalBlockedCount(
            transformToListOfBlockedMetricCollectors(cpuThreadTestRunners));
    long totalBlockedTime = computeTotalBlockedTime(
            transformToListOfBlockedMetricCollectors(cpuThreadTestRunners));

    double iterationsPerSecond = iterations / (timeTakenms / 1000);
    NumberFormat numberInstance = NumberFormat.getNumberInstance();
    String iterationsPerSecondString = numberInstance.format(iterationsPerSecond);

    System.out.printf(/*w  ww  .  ja v  a2 s  .  co m*/
            "cpuTracingEnabled: %s\tcpuLookupMethod: %s\titerations/sec: %s\tblockedCount: %d\tblockedTime: %d\n",
            leftPadBoolean(cpuTracingEnabled), formatCpuLookupMethod(cpuLookupMethod),
            iterationsPerSecondString, totalBlockedCount, totalBlockedTime);
}