List of usage examples for java.text NumberFormat getInstance
public static final NumberFormat getInstance()
From source file:org.perfrepo.web.controller.reports.testgroup.TestGroupChartBean.java
public void drawChart(OutputStream out, Object data) throws IOException { if (data instanceof ChartData) { ChartData chartData = (ChartData) data; JFreeChart chart = ChartFactory.createBarChart(chartData.getTitle(), "Test", "%", processDataSet(chartData), PlotOrientation.HORIZONTAL, false, true, false); chart.addSubtitle(new TextTitle("Comparison", new Font("Dialog", Font.ITALIC, 10))); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); CustomRenderer renderer = new CustomRenderer(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}%", NumberFormat.getInstance())); renderer.setBaseItemLabelsVisible(true); renderer.setDrawBarOutline(false); renderer.setMaximumBarWidth(1d / (chartData.getTests().length + 4.0)); plot.setRenderer(renderer);// w ww . j a va 2 s. co m CategoryAxis categoryAxis = plot.getDomainAxis(); categoryAxis.setCategoryMargin(0.1); categoryAxis.setUpperMargin(0.1); categoryAxis.setLowerMargin(0.1); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.10); BufferedImage buffImg = chart.createBufferedImage(640, chartData.getTests().length * 100 + 100); ImageIO.write(buffImg, "gif", out); } }
From source file:com.talent.aio.examples.im.client.ui.JFrameMain.java
public static void updateConnectionCount() { if (isNeedUpdateConnectionCount) { isNeedUpdateConnectionCount = false; NumberFormat numberFormat = NumberFormat.getInstance(); ClientGroupContext<Object, ImPacket, Object> clientGroupContext = imClientStarter .getClientGroupContext(); int connectionCount = clientGroupContext.getConnections().size(); instance.connectionCountLabel.setText("" + numberFormat.format(connectionCount)); int connectedCount = clientGroupContext.getConnecteds().size(); instance.connectedCountLabel.setText("" + numberFormat.format(connectedCount)); int closedCount = clientGroupContext.getCloseds().size(); instance.closedCountLabel.setText("" + numberFormat.format(closedCount)); // log.error("{},{},{}", connectionCount, connectedCount, closedCount); }/*from w w w.ja v a 2s .co m*/ }
From source file:com.dgtlrepublic.anitomyj.ParserNumber.java
/** Returns whether or not the {@code number} is a valid episode number. */ public boolean isValidEpisodeNumber(String number) { try {//from w w w . j a va 2s . c o m return NumberFormat.getInstance().parse(number).doubleValue() <= kEpisodeNumberMax; } catch (ParseException | NullPointerException | NumberFormatException e) { return false; } }
From source file:com.googlecode.logVisualizer.chart.HorizontalStackedBarChartBuilder.java
private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createStackedBarChart(getTitle(), xLable, yLable, dataset, PlotOrientation.HORIZONTAL, isIncludeLegend(), true, false); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); final StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); final CategoryAxis categoryAxis = plot.getDomainAxis(); final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); plot.setNoDataMessage("No data available"); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.black); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); setBarShadowVisible(chart, false);//from ww w . ja v a 2 s . c om renderer.setDrawBarOutline(false); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance())); categoryAxis.setCategoryMargin(0.02); categoryAxis.setUpperMargin(0.02); categoryAxis.setLowerMargin(0.02); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberAxis.setUpperMargin(0.1); return chart; }
From source file:com.panet.imeta.trans.steps.getxmldata.GetXMLDataData.java
/** * // w ww . ja va 2 s . com */ public GetXMLDataData() { super(); thisline = null; nextline = null; nf = NumberFormat.getInstance(); df = (DecimalFormat) nf; dfs = new DecimalFormatSymbols(); daf = new SimpleDateFormat(); dafs = new DateFormatSymbols(); nr_repeats = 0; previousRow = null; filenr = 0; fr = null; is = null; indexOfXmlField = -1; nrInputFields = -1; PathValue = null; tokenStart = "@_"; tokenEnd = "-"; nodenr = 0; nodesize = 0; an = null; readrow = null; totalpreviousfields = 0; prunePath = ""; stopPruning = false; errorInRowButContinue = false; }
From source file:Visuals.BarChart.java
public ChartPanel drawBarChart() { DefaultCategoryDataset bardataset = new DefaultCategoryDataset(); bardataset.addValue(new Double(low), "Low (" + low + ")", lowValue); bardataset.addValue(new Double(medium), "Medium (" + medium + ")", mediumValue); bardataset.addValue(new Double(high), "High (" + high + ")", highValue); bardataset.addValue(new Double(critical), "Critical (" + critical + ")", criticalValue); JFreeChart barchart = ChartFactory.createBarChart(title, // Title riskCategory, riskCountTitle, bardataset // Dataset );/*from ww w.ja v a 2 s .c o m*/ final CategoryPlot plot = barchart.getCategoryPlot(); CategoryItemRenderer renderer = new CustomRenderer(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator(riskCountTitle, NumberFormat.getInstance())); DecimalFormat df = new DecimalFormat("##"); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", df)); Font m1Font; m1Font = new Font("Cambria", Font.BOLD, 16); renderer.setItemLabelFont(m1Font); renderer.setItemLabelPaint(null); //barchart.removeLegend(); plot.setRenderer(renderer); //renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE5, TextAnchor.CENTER)); //renderer.setItemLabelsVisible(true); barchart.getCategoryPlot().setRenderer(renderer); LegendItemCollection chartLegend = new LegendItemCollection(); Shape shape = new Rectangle(10, 10); chartLegend.add(new LegendItem("Low (" + low + ")", null, null, null, shape, new Color(230, 219, 27))); chartLegend .add(new LegendItem("Medium (" + medium + ")", null, null, null, shape, new Color(85, 144, 176))); chartLegend.add(new LegendItem("High (" + high + ")", null, null, null, shape, new Color(230, 90, 27))); chartLegend.add( new LegendItem("Critical (" + critical + ")", null, null, null, shape, new Color(230, 27, 27))); plot.setFixedLegendItems(chartLegend); plot.setBackgroundPaint(new Color(210, 234, 243)); ChartPanel chartPanel = new ChartPanel(barchart); return chartPanel; }
From source file:de.tor.tribes.util.bb.KillStatsFormatter.java
private String[] getStatSpecificReplacements(Stats pStats) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0);//from www .ja va 2s .c o m nf.setMaximumFractionDigits(0); String tribe = pStats.getParent().getTribe().toBBCode(); String killsBefore = nf.format(pStats.getBashOffStart()); String killsAfter = nf.format(pStats.getBashOffEnd()); String killsDiff = nf.format(pStats.getBashOffDiff()); if (pStats.getBashOffDiff() > 0) { killsDiff = "[color=green]" + killsDiff + "[/color]"; } else { killsDiff = "[color=red]" + killsDiff + "[/color]"; } long pBefore = pStats.getBashOffStart(); double perc = 0; if (pBefore > 0) { perc = (double) 100 * (double) pStats.getBashOffDiff() / (double) pBefore; } String percentDiff = ((perc >= 0) ? "+" : "") + nf.format(perc) + "%"; if (perc > 0) { percentDiff = "[color=green]" + percentDiff + "[/color]"; } else { percentDiff = "[color=red]" + percentDiff + "[/color]"; } return new String[] { tribe, killsBefore, killsAfter, killsDiff, percentDiff }; }
From source file:de.tor.tribes.util.bb.DefStatsFormatter.java
private String[] getStatSpecificReplacements(Stats pStats) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0);/*from ww w. ja v a 2 s. c o m*/ nf.setMaximumFractionDigits(0); String tribe = pStats.getParent().getTribe().toBBCode(); String killsBefore = nf.format(pStats.getBashDefStart()); String killsAfter = nf.format(pStats.getBashDefEnd()); String killsDiff = nf.format(pStats.getBashDefDiff()); if (pStats.getBashDefDiff() > 0) { killsDiff = "[color=green]" + killsDiff + "[/color]"; } else { killsDiff = "[color=red]" + killsDiff + "[/color]"; } long pBefore = pStats.getBashDefStart(); double perc = 0; if (pBefore > 0) { perc = (double) 100 * (double) pStats.getBashDefDiff() / (double) pBefore; } String percentDiff = ((perc >= 0) ? "+" : "") + nf.format(perc) + "%"; if (perc > 0) { percentDiff = "[color=green]" + percentDiff + "[/color]"; } else { percentDiff = "[color=red]" + percentDiff + "[/color]"; } return new String[] { tribe, killsBefore, killsAfter, killsDiff, percentDiff }; }
From source file:com.saiton.ccs.validations.FormatAndValidate.java
public String FormatDecimal(Float d) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2);//from w ww.java2 s.co m nf.setMinimumFractionDigits(2); return nf.format(d); }
From source file:net.nosleep.superanalyzer.util.Misc.java
private static String formatCount(double value, String unitSingular, String unitPlural, boolean showFraction) { NumberFormat numberFormat = NumberFormat.getInstance(); if (showFraction == true) { numberFormat.setMinimumFractionDigits(0); numberFormat.setMaximumFractionDigits(1); }// w w w. j a v a2 s . c o m if (value > 1.0 && value < 1.01) return numberFormat.format(value) + " " + capitalizeByLocale(unitSingular); else return numberFormat.format(value) + " " + capitalizeByLocale(unitPlural); }