List of usage examples for java.text NumberFormat getPercentInstance
public static final NumberFormat getPercentInstance()
From source file:edu.berkeley.boinc.PrefsFragment.java
private void setupSliderDialog(PrefsListItemWrapper item, final Dialog dialog) { final PrefsListItemWrapperValue valueWrapper = (PrefsListItemWrapperValue) item; dialog.setContentView(R.layout.prefs_layout_dialog_pct); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar); if (valueWrapper.ID == R.string.battery_charge_min_pct_header || valueWrapper.ID == R.string.prefs_disk_max_pct_header || valueWrapper.ID == R.string.prefs_cpu_time_max_header || valueWrapper.ID == R.string.prefs_cpu_other_load_suspension_header || valueWrapper.ID == R.string.prefs_memory_max_idle_header) { Double seekBarDefault = valueWrapper.status / 10; slider.setProgress(seekBarDefault.intValue()); final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener; slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { final String progressString = NumberFormat.getPercentInstance().format(progress / 10.0); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); }/*from w ww . java 2 s.c o m*/ @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); onSeekBarChangeListener.onProgressChanged(slider, seekBarDefault.intValue(), false); } else if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) { if (!getHostInfo()) { if (Logging.WARNING) Log.w(Logging.TAG, "onItemClick missing hostInfo"); return; } slider.setMax(hostinfo.p_ncpus <= 1 ? 0 : hostinfo.p_ncpus - 1); final int statusValue; slider.setProgress((statusValue = valueWrapper.status.intValue()) <= 0 ? 0 : statusValue - 1 > slider.getMax() ? slider.getMax() : statusValue - 1); Log.d(Logging.TAG, String.format("statusValue == %,d", statusValue)); final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener; slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { final String progressString = NumberFormat.getIntegerInstance() .format(progress <= 0 ? 1 : progress + 1); // do not allow 0 cpus TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); onSeekBarChangeListener.onProgressChanged(slider, statusValue - 1, false); } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) { slider.setMax(5); slider.setProgress(valueWrapper.status.intValue()); final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener; slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { String progressString = NumberFormat.getIntegerInstance().format(progress); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); onSeekBarChangeListener.onProgressChanged(slider, valueWrapper.status.intValue(), false); } setupDialogButtons(item, dialog); }
From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java
/** * Generates the image of a pie chart that displays the percentage of * expenses of the different books which for a given year are loosing money * (not profitable)//from ww w . j av a2 s. c o m * * @return the relative random URL generated */ @DependsOn({ "selectedBook", "clientType", "monthlyReportYear" }) public String getDeficitPieChartURL() { if (bookSelection.getSelectedBook() == null) { return ""; } List<Annotation> anotations = getAnnotationsInAscendingDateOrder(Optional.of(monthlyReportYear)); PieDataset categoryModel = ChartDataModel.deficitsPieChartDataset(anotations); JFreeChart jfchart = ChartFactory.createPieChart( "Dficit ( ingresos menos gastos, siendo los gastos mayores a los ingresos )", categoryModel, true, true, false); PiePlot piePlot = ((PiePlot) jfchart.getPlot()); piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} (-{1} , {2} )", NumberFomatter.PERCENTAGE_FORMATTER, NumberFormat.getPercentInstance())); piePlot.setBackgroundPaint(Color.white); return ResourceImageGenerator.getFunction().apply(jfchart); }
From source file:org.alfresco.repo.batch.BatchProcessor.java
/** * Reports the current progress.//from w w w . jav a 2 s. com * * @param last * Have all jobs been processed? If <code>false</code> then progress is only reported after the number of * entries indicated by {@link #loggingInterval}. If <code>true</code> then progress is reported if this * is not one of the entries indicated by {@link #loggingInterval}. */ private synchronized void reportProgress(boolean last) { int processed = this.successfullyProcessedEntries + this.totalErrors; if (processed % this.loggingInterval == 0 ^ last) { StringBuilder message = new StringBuilder(100).append(getProcessName()).append(": Processed ") .append(processed).append(" entries"); int totalResults = this.workProvider.getTotalEstimatedWorkSize(); if (totalResults >= processed) { message.append(" out of ").append(totalResults).append(". ") .append(NumberFormat.getPercentInstance() .format(totalResults == 0 ? 1.0F : (float) processed / totalResults)) .append(" complete"); } long duration = System.currentTimeMillis() - this.startTime.getTime(); if (duration > 0) { message.append(". Rate: ").append(processed * 1000L / duration).append(" per second"); } message.append(". " + this.totalErrors + " failures detected."); this.logger.info(message); } }
From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java
/** * Generates the image of a pie chart that displays the percentage of income * of the different books which for a given year are profitable * //from w w w .j ava 2 s. c om * @return the relative random URL generated */ @DependsOn({ "selectedBook", "clientType", "monthlyReportYear" }) public String getIncomePieChartURL() { if (bookSelection.getSelectedBook() == null) { return ""; } List<Annotation> anotations = getAnnotationsInAscendingDateOrder(Optional.of(monthlyReportYear)); PieDataset categoryModel = ChartDataModel.incomesPieChartDataset(anotations); JFreeChart jfchart = ChartFactory.createPieChart( "Beneficios ( ingresos menos gastos, siendo los ingresos mayores a los gastos )", categoryModel, true, true, false); PiePlot piePlot = ((PiePlot) jfchart.getPlot()); piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} , {2} )", NumberFomatter.PERCENTAGE_FORMATTER, NumberFormat.getPercentInstance())); piePlot.setBackgroundPaint(Color.white); return ResourceImageGenerator.getFunction().apply(jfchart); }
From source file:org.exist.storage.index.BFile.java
@Override public void printStatistics() { super.printStatistics(); final NumberFormat nf = NumberFormat.getPercentInstance(); final StringBuilder buf = new StringBuilder(); buf.append(getFile().getName()).append(" DATA "); buf.append("Buffers occupation : "); if (dataCache.getBuffers() == 0 && dataCache.getUsedBuffers() == 0) { buf.append("N/A"); } else {//from www. jav a2 s . c o m buf.append(nf.format(dataCache.getUsedBuffers() / (float) dataCache.getBuffers())); } buf.append(" (" + dataCache.getUsedBuffers() + " out of " + dataCache.getBuffers() + ")"); //buf.append(dataCache.getBuffers()).append(" / "); //buf.append(dataCache.getUsedBuffers()).append(" / "); buf.append(" Cache efficiency : "); if (dataCache.getHits() == 0 && dataCache.getFails() == 0) { buf.append("N/A"); } else { buf.append(nf.format(dataCache.getHits() / (float) (dataCache.getHits() + dataCache.getFails()))); } //buf.append(dataCache.getHits()).append(" / "); //buf.append(dataCache.getFails()); LOGSTATS.info(buf.toString()); }
From source file:com.jd.survey.web.pdf.StatisticsPdf.java
private void writeBooleanQuestionStatistics(Document document, Question question, List<QuestionStatistic> questionStatistics, String optionLabel, String optionFrequencyLabel, String trueLabel, String falseLabel) throws Exception { NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(1); Table statsTable = createOptionsQuestionStatisticsTableHeader(optionLabel, optionFrequencyLabel); Cell cell;/*from ww w . ja v a 2 s . co m*/ Boolean foundOption = false; cell = new Cell(new Paragraph(trueLabel, normalFont)); statsTable.addCell(cell); if (questionStatistics != null && questionStatistics.size() > 0) { for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getEntry().equals("1")) { foundOption = true; cell = new Cell( new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); statsTable.addCell(cell); cell = new Cell(); Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } } if (!foundOption) { cell = new Cell(new Paragraph(percentFormat.format(0), normalFont)); statsTable.addCell(cell); cell = new Cell(); cell.setColspan(5); statsTable.addCell(cell); } foundOption = false; cell = new Cell(new Paragraph(falseLabel, normalFont)); statsTable.addCell(cell); if (questionStatistics != null && questionStatistics.size() > 0) { for (QuestionStatistic questionStatistic : questionStatistics) { if (questionStatistic.getEntry().equals("0")) { foundOption = true; cell = new Cell( new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont)); statsTable.addCell(cell); cell = new Cell(); Image img = Image.getInstance(this.getClass().getResource("/chartbar.png")); cell.setColspan(5); img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f); cell.addElement(img); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); statsTable.addCell(cell); break; } } } if (!foundOption) { cell = new Cell(new Paragraph(percentFormat.format(0), normalFont)); statsTable.addCell(cell); cell = new Cell(); cell.setColspan(5); statsTable.addCell(cell); } document.add(statsTable); }
From source file:org.toobsframework.pres.chart.ChartBuilder.java
public ValueAxis createValueAxis(IRequest componentRequest, RangeAxisDef valueAxisDef, Map params, boolean is3D) { ValueAxis valueAxis;//w ww. j av a 2 s . c o m if (is3D) { valueAxis = new NumberAxis3D(); } else { valueAxis = new NumberAxis(); } if (valueAxisDef != null) { if (valueAxisDef.getRangeLabel() != null) { valueAxis.setLabel( ChartUtil.evaluateTextLabel(componentRequest, valueAxisDef.getRangeLabel(), params)); if (valueAxisDef.getRangeLabel().getFont() != null) { valueAxis.setLabelFont(ChartUtil.getFont(valueAxisDef.getRangeLabel(), null)); } valueAxis.setLabelPaint(ChartUtil.getColor(valueAxisDef.getRangeLabel().getColor())); } if (valueAxisDef.getIntegerTicks()) { valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } if (valueAxisDef.getNumberFormater() != null) { switch (valueAxisDef.getNumberFormater().getType()) { case AxisDefNumberFormaterType.PERCENT_TYPE: ((NumberAxis) valueAxis).setNumberFormatOverride(NumberFormat.getPercentInstance()); break; case AxisDefNumberFormaterType.CUSTOMBEAN_TYPE: ((NumberAxis) valueAxis).setNumberFormatOverride( (NumberFormat) beanFactory.getBean(valueAxisDef.getCustomFormatBean())); break; } } } return valueAxis; }
From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java
/** * Generates the image of a pie chart that displays the percentage of * expenses of the different concept which for a given year are loosing * money (not profitable)//from w w w . ja va 2s . c o m * * NOTE: usually, a given concept is only related to either income or * expenses but this *not* always the case (for example, in stocks the * concept is the company involved and there can be incomes and expenses) * * @return the relative random URL generated */ @DependsOn({ "selectedBook", "clientType", "monthlyReportYear" }) public String getExpensesPieChartURL() { if (bookSelection.getSelectedBook() == null) { return ""; } Map<String, Double> expensesDataForBook = AnnotationsBusiness.getExpensesDataForBook(bookSelection, monthlyReportYear, clientType); PieDataset categoryModel = ChartDataModel.expensesPieChartDataset(expensesDataForBook); JFreeChart jfchart = ChartFactory.createPieChart("Gastos (nicamente gastos)", categoryModel, true, true, false); PiePlot piePlot = ((PiePlot) jfchart.getPlot()); piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1} , {2} )", NumberFomatter.PERCENTAGE_FORMATTER, NumberFormat.getPercentInstance())); piePlot.setBackgroundPaint(Color.white); return ResourceImageGenerator.getFunction().apply(jfchart); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample pie chart. * * @return a sample pie chart./*from w w w. jav a 2s. c om*/ */ public JFreeChart createPieChartTwo() { // create a default chart based on some sample data... final String title = this.resources.getString("pie.pie2.title"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final Comparable category = (Comparable) data.getColumnKeys().get(1); final PieDataset extracted = DatasetUtilities.createPieDatasetForColumn(data, category); final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false); // then customise it a little... chart.setBackgroundPaint(Color.lightGray); final PiePlot pie = (PiePlot) chart.getPlot(); pie.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); pie.setBackgroundImage(JFreeChart.INFO.getLogo()); pie.setBackgroundPaint(Color.white); pie.setBackgroundAlpha(0.6f); pie.setForegroundAlpha(0.75f); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a pie chart with default settings that compares 2 datasets. * The colour of each section will be determined by the move from the value * for the same key in <code>previousDataset</code>. ie if value1 > value2 * then the section will be in green (unless <code>greenForIncrease</code> * is <code>false</code>, in which case it would be <code>red</code>). * Each section can have a shade of red or green as the difference can be * tailored between 0% (black) and percentDiffForMaxScale% (bright * red/green). /*from w w w .j av a2s . co m*/ * <p> * For instance if <code>percentDiffForMaxScale</code> is 10 (10%), a * difference of 5% will have a half shade of red/green, a difference of * 10% or more will have a maximum shade/brightness of red/green. * <P> * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * <p> * Written by <a href="mailto:opensource@objectlab.co.uk">Benoit * Xhenseval</a>. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param previousDataset the dataset for the last run, this will be used * to compare each key in the dataset * @param percentDiffForMaxScale scale goes from bright red/green to black, * percentDiffForMaxScale indicate the change * required to reach top scale. * @param greenForIncrease an increase since previousDataset will be * displayed in green (decrease red) if true. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param locale the locale (<code>null</code> not permitted). * @param subTitle displays a subtitle with colour scheme if true * @param showDifference create a new dataset that will show the % * difference between the two datasets. * * @return A pie chart. * * @since 1.0.7 */ public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, Locale locale, boolean subTitle, boolean showDifference) { PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator(locale)); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator(locale)); } List keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (Iterator it = keys.iterator(); it.hasNext();) { Comparable key = (Comparable) it.next(); Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.green); } else { plot.setSectionPaint(key, Color.red); } if (showDifference) { series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); if (subTitle) { TextTitle subtitle = null; subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } return chart; }