List of usage examples for java.text NumberFormat getNumberInstance
public static final NumberFormat getNumberInstance()
From source file:com.projity.pm.graphic.chart.TimeChartPanel.java
protected JFreeChart buildChart() { JFreeChart newChart = ChartHelper.createChart(chartInfo.getModel().getDataset(), chartInfo.isHistogram(), chartInfo.getModel().getSecondDataset()); NumberFormat numberFormat = NumberFormat.getPercentInstance(); // default Object[] traces = chartInfo.getTraces(); // chartInfo.getModel().dumpDataset(traces); if (!chartInfo.isSimple() && (traces.length > 0 && traces[0] instanceof Field)) { Field field = (Field) traces[0]; if (field.isMoney()) { numberFormat = new NumberFormat() { @Override//from w w w . jav a2 s.com public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { return toAppendTo.append(Money.formatCurrency(number, true)); } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { // TODO Auto-generated method stub return null; } @Override public Number parse(String source, ParsePosition parsePosition) { // TODO Auto-generated method stub return null; } }; } else { Format format = field.getFormat(); if (format instanceof NumberFormat) numberFormat = (NumberFormat) format; else numberFormat = NumberFormat.getNumberInstance(); } } ((NumberAxis) newChart.getXYPlot().getRangeAxis()).setNumberFormatOverride(numberFormat); return newChart; }
From source file:com.vgi.mafscaling.Rescale.java
private void createControlPanel(JPanel dataPanel) { JPanel cntlPanel = new JPanel(); GridBagConstraints gbl_ctrlPanel = new GridBagConstraints(); gbl_ctrlPanel.insets = insets3;/*from w w w. j a v a2s . c om*/ gbl_ctrlPanel.anchor = GridBagConstraints.PAGE_START; gbl_ctrlPanel.fill = GridBagConstraints.HORIZONTAL; gbl_ctrlPanel.weightx = 1.0; gbl_ctrlPanel.gridx = 0; gbl_ctrlPanel.gridy = 0; dataPanel.add(cntlPanel, gbl_ctrlPanel); GridBagLayout gbl_cntlPanel = new GridBagLayout(); gbl_cntlPanel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; gbl_cntlPanel.rowHeights = new int[] { 0, 0 }; gbl_cntlPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; gbl_cntlPanel.rowWeights = new double[] { 0 }; cntlPanel.setLayout(gbl_cntlPanel); NumberFormat doubleFmt = NumberFormat.getNumberInstance(); doubleFmt.setGroupingUsed(false); doubleFmt.setMaximumIntegerDigits(1); doubleFmt.setMinimumIntegerDigits(1); doubleFmt.setMaximumFractionDigits(3); doubleFmt.setMinimumFractionDigits(1); doubleFmt.setRoundingMode(RoundingMode.HALF_UP); NumberFormat scaleDoubleFmt = NumberFormat.getNumberInstance(); scaleDoubleFmt.setGroupingUsed(false); scaleDoubleFmt.setMaximumIntegerDigits(1); scaleDoubleFmt.setMinimumIntegerDigits(1); scaleDoubleFmt.setMaximumFractionDigits(8); scaleDoubleFmt.setMinimumFractionDigits(1); scaleDoubleFmt.setRoundingMode(RoundingMode.HALF_UP); GridBagConstraints gbc_cntlPanelLabel = new GridBagConstraints(); gbc_cntlPanelLabel.anchor = GridBagConstraints.EAST; gbc_cntlPanelLabel.insets = new Insets(2, 3, 2, 1); gbc_cntlPanelLabel.gridx = 0; gbc_cntlPanelLabel.gridy = 0; GridBagConstraints gbc_cntlPanelInput = new GridBagConstraints(); gbc_cntlPanelInput.anchor = GridBagConstraints.WEST; gbc_cntlPanelInput.insets = new Insets(2, 1, 2, 3); gbc_cntlPanelInput.gridx = 1; gbc_cntlPanelInput.gridy = 0; cntlPanel.add(new JLabel("New Max V"), gbc_cntlPanelLabel); newMaxVFmtTextBox = new JFormattedTextField(doubleFmt); newMaxVFmtTextBox.setColumns(7); newMaxVFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object source = e.getSource(); if (source == newMaxVFmtTextBox) updateNewMafScale(); } }); cntlPanel.add(newMaxVFmtTextBox, gbc_cntlPanelInput); gbc_cntlPanelLabel.gridx += 2; cntlPanel.add(new JLabel("Min V"), gbc_cntlPanelLabel); minVFmtTextBox = new JFormattedTextField(doubleFmt); minVFmtTextBox.setColumns(7); minVFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object source = e.getSource(); if (source == minVFmtTextBox) updateNewMafScale(); } }); gbc_cntlPanelInput.gridx += 2; cntlPanel.add(minVFmtTextBox, gbc_cntlPanelInput); gbc_cntlPanelLabel.gridx += 2; cntlPanel.add(new JLabel("Max Unchanged"), gbc_cntlPanelLabel); maxVUnchangedFmtTextBox = new JFormattedTextField(doubleFmt); maxVUnchangedFmtTextBox.setColumns(7); maxVUnchangedFmtTextBox.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object source = e.getSource(); if (source == maxVUnchangedFmtTextBox) updateNewMafScale(); } }); gbc_cntlPanelInput.gridx += 2; cntlPanel.add(maxVUnchangedFmtTextBox, gbc_cntlPanelInput); gbc_cntlPanelLabel.gridx += 2; cntlPanel.add(new JLabel("Mode deltaV"), gbc_cntlPanelLabel); modeDeltaVFmtTextBox = new JFormattedTextField(scaleDoubleFmt); modeDeltaVFmtTextBox.setColumns(7); modeDeltaVFmtTextBox.setEditable(false); modeDeltaVFmtTextBox.setBackground(new Color(210, 210, 210)); gbc_cntlPanelInput.gridx += 2; cntlPanel.add(modeDeltaVFmtTextBox, gbc_cntlPanelInput); }
From source file:jgnash.ui.report.compiled.RunningAccountBalanceChart.java
private JFreeChart createVerticalXYBarChart(Account a) { DateFormat df = new SimpleDateFormat("MM/yy"); TimeSeriesCollection data = createTimeSeriesCollection(a); DateAxis dateAxis = new DateAxis(rb.getString("Column.Date")); dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df)); dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); LocalDate start = DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()); LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()); dateAxis.setRange(DateUtils.asDate(start), DateUtils.asDate(end)); NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance")); StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df, NumberFormat.getNumberInstance()); XYBarRenderer renderer = new XYBarRenderer(0.2); renderer.setBaseToolTipGenerator(tooltipGenerator); XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer); String title = rb.getString("Title.EndMonthBalance") + " - " + a.getPathName(); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(null);/*from w ww . ja va 2 s . co m*/ return chart; }
From source file:com.att.aro.ui.view.overviewtab.TraceBenchmarkChartPanel.java
/** * Creates the plot data set from the current analysis * // w ww. ja va2 s. c om * @return CategoryDataset The plot data set for promotion ratio , * throughput and J/Kb. */ private CategoryDataset createDataset() { double throughputPct = 0; double jpkbPct = 0; double promotionRatioPct = 0; double kbps = 0; double jpkb = 0; double promo = 0; if (CommonHelper.isNotNull(traceBenchmarkData)) { throughputPct = traceBenchmarkData.getThroughputPct(); jpkbPct = traceBenchmarkData.getJpkbPct(); promotionRatioPct = traceBenchmarkData.getPromotionRatioPct(); kbps = traceBenchmarkData.getKbps(); jpkb = traceBenchmarkData.getJpkb(); promo = traceBenchmarkData.getPromoRatioPercentail(); } NumberFormat nFormat = NumberFormat.getNumberInstance(); nFormat.setMaximumFractionDigits(1); nFormat.setMinimumFractionDigits(1); double[][] data = new double[2][3]; data[0][0] = throughputPct; data[0][1] = jpkbPct; data[0][2] = promotionRatioPct; data[1][0] = 100.0 - throughputPct; data[1][1] = 100.0 - jpkbPct; data[1][2] = 100.0 - promotionRatioPct; return DatasetUtilities.createCategoryDataset(new Integer[] { 1, 2 }, new String[] { MessageFormat.format(ResourceBundleHelper.getMessageString("overview.traceoverview.throughput"), nFormat.format(kbps)), MessageFormat.format(ResourceBundleHelper.getMessageString("overview.traceoverview.jpkb"), nFormat.format(jpkb)), MessageFormat.format(ResourceBundleHelper.getMessageString("overview.traceoverview.promoratio"), nFormat.format(promo)) }, data); }
From source file:net.sf.maltcms.common.charts.ui.XYChartTopComponent.java
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed final String renderer = (String) jComboBox1.getSelectedItem(); Task t = RequestProcessor.getDefault().create(new Runnable() { @Override/* w ww. jav a 2s . co m*/ public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { panel.setEnabled(false); panel.invalidate(); panel.validate(); } }); int nrenderer = panel.getChart().getXYPlot().getRendererCount(); XYPlot plot = panel.getChart().getXYPlot(); int ndatasets = panel.getChart().getXYPlot().getDatasetCount(); List<Shape> shapes = new LinkedList<>(); for (int i = 0; i < nrenderer; i++) { for (int j = 0; j < plot.getDataset(i).getSeriesCount(); j++) { XYDataset d = plot.getDataset(i); for (int k = 0; k < d.getSeriesCount(); k++) { Shape s = plot.getRendererForDataset(d).getSeriesShape(k); shapes.add(s); } } } switch (renderer) { case "Line And Shape": panel.getChart().getXYPlot().setRenderer(new XYLineAndShapeRenderer(true, true)); break; case "Line": panel.getChart().getXYPlot().setRenderer(new XYLineAndShapeRenderer(true, false)); break; case "Shape": panel.getChart().getXYPlot().setRenderer(new XYLineAndShapeRenderer(false, true)); break; case "Area": panel.getChart().getXYPlot().setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA)); break; case "Area w/ Shapes": panel.getChart().getXYPlot().setRenderer(new XYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES)); break; } panel.getChart().getXYPlot().getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator( "%2.5f", NumberFormat.getNumberInstance(), NumberFormat.getNumberInstance())); int shapeIndex = 0; for (int i = 0; i < nrenderer; i++) { for (int j = 0; j < plot.getDataset(i).getSeriesCount(); j++) { XYDataset d = plot.getDataset(i); for (int k = 0; k < d.getSeriesCount(); k++) { plot.getRendererForDataset(d).setSeriesShape(k, shapes.get(shapeIndex)); shapeIndex++; } } } customizeChart(panel); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { panel.setEnabled(true); panel.invalidate(); panel.validate(); } }); } }); t.addTaskListener(new XYChartLoaderTaskListener()); RequestProcessor.getDefault().post(t); }
From source file:com.att.aro.main.TraceOverviewPanel.java
/** * Creates the plot data set from the current analysis * /*from w ww . j a va 2 s . c o m*/ * @param analysis * The analysis data for the trace * @return CategoryDataset The plot data set for promotion ratio , * throughput and J/Kb. */ private CategoryDataset createDataset(TraceData.Analysis analysis) { this.throughputPct = analysis != null ? analysis.calculateThroughputPercentage(analysis) : 0; this.jpkbPct = analysis != null ? analysis.calculateJpkbPercentage(analysis) : 0; this.promotionRatioPct = analysis != null ? analysis.calculatePromotionRatioPercentage(analysis) : 0; this.kbps = analysis != null ? analysis.getAvgKbps() : 0; this.jpkb = analysis != null ? analysis.getRrcStateMachine().getJoulesPerKilobyte() : 0; this.promo = analysis != null ? analysis.getRrcStateMachine().getPromotionRatio() : 0; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(1); nf.setMinimumFractionDigits(1); double[][] data = new double[2][3]; data[0][0] = throughputPct; data[0][1] = jpkbPct; data[0][2] = promotionRatioPct; data[1][0] = 100.0 - throughputPct; data[1][1] = 100.0 - jpkbPct; data[1][2] = 100.0 - promotionRatioPct; return DatasetUtilities.createCategoryDataset(new Integer[] { 1, 2 }, new String[] { MessageFormat.format(rb.getString("overview.traceoverview.throughput"), nf.format(kbps)), MessageFormat.format(rb.getString("overview.traceoverview.jpkb"), nf.format(jpkb)), MessageFormat.format(rb.getString("overview.traceoverview.promoratio"), nf.format(promo)) }, data); }
From source file:massbank.BatchJobWorker.java
/** * Ytt@C???ieLXg`?j//from w ww. j ava2 s. co m * @param time NGXg * @param resultFile t@C * @param textFile YtpeLXgt@C */ private void createTextFile(String time, File resultFile, File textFile) { NumberFormat nf = NumberFormat.getNumberInstance(); LineNumberReader in = null; PrintWriter out = null; try { in = new LineNumberReader(new FileReader(resultFile)); out = new PrintWriter(new BufferedWriter(new FileWriter(textFile))); // wb_?[?o String reqIonStr = "Both"; try { if (Integer.parseInt(this.ion) > 0) { reqIonStr = "Positive"; } else if (Integer.parseInt(this.ion) < 0) { reqIonStr = "Negative"; } } catch (NumberFormatException nfe) { nfe.printStackTrace(); } out.println("***** MassBank Batch Service Results *****"); out.println(); out.println("Request Date: " + time); out.println("# Instrument Type: " + this.inst); out.println("# Ion Mode: " + reqIonStr); out.println(); out.println(); // ?o String line; long queryCnt = 0; boolean readName = false; boolean readHit = false; boolean readNum = false; boolean isFinalLine = false; while ((line = in.readLine()) != null) { isFinalLine = false; if (in.getLineNumber() < 4) { continue; } if (!readName) { queryCnt++; out.println("### Query " + nf.format(queryCnt) + " ###"); out.println("# Name: " + line.trim()); readName = true; } else if (!readHit) { out.println("# Hit: " + nf.format(Integer.parseInt(line.trim()))); out.println(); readHit = true; } else if (!readNum) { out.println("Top " + line.trim() + " List"); out.println("Accession\tTitle\tFormula\tIon\tScore\tHit"); out.println(); readNum = true; } else { if (!line.trim().equals("")) { String[] data = formatLine(line); StringBuilder sb = new StringBuilder(); sb.append(data[0]).append("\t").append(data[1]).append("\t").append(data[2]).append("\t") .append(data[3]).append("\t").append(data[4]).append("\t").append(data[5]); out.println(sb.toString()); } else { out.println(); out.println(); readName = false; readHit = false; readNum = false; isFinalLine = true; } } } if (!isFinalLine) { out.println(); out.println(); } out.println("##### END #####"); out.println(); out.println("**********************************************************"); out.println("* MassBank.jp - High Resolution Mass Spectral Database *"); out.println("* URL: http://www.massbank.jp/ *"); out.println("**********************************************************"); out.println(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { } if (out != null) { out.flush(); out.close(); } } }
From source file:com.mgmtp.perfload.loadprofiles.util.PlotFileCreator.java
/** * Create a plot of the start times of load events for all given load curve assignements. This * plot is normally used for diagnostic purposes. * //w w w .j a v a 2s . co m * @param file * The plot file * @param eventList * List of events to be plotted. * @param loadCurveAssignments * load curve assignements, by which the load events are grouped * @param nClients * Number of clients * @param timeUnitPlot * time unit of the plot. */ public static void createPlot(final File file, final Collection<LoadEvent> eventList, final List<LoadCurveAssignment> loadCurveAssignments, final int nClients, final String timeUnitPlot) throws IOException { double timeScalingFactor = LoadCurveCalculator.getTimeScalingFactor(LoadCurveCalculator.timeUnit_hour, timeUnitPlot); int nAssignements = loadCurveAssignments.size(); int[][] operationsOfType = new int[nAssignements][nClients]; String[] operationNames = new String[nAssignements]; for (int iAssignement = 0; iAssignement < nAssignements; iAssignement++) { operationNames[iAssignement] = loadCurveAssignments.get(iAssignement).getOperationName(); } for (int iClient = 0; iClient < nClients; iClient++) { for (LoadEvent event : eventList) { if (event.getClientId() == iClient) { int operationId = getOperationId(event.getOperation().getName(), operationNames); operationsOfType[operationId][iClient]++; } } } PrintWriter pw = null; try { pw = new PrintWriter(file, "UTF-8"); Format format = NumberFormat.getNumberInstance(); for (int iClient = 0; iClient < nClients; iClient++) { for (int iAssignement = 0; iAssignement < nAssignements; iAssignement++) { pw.println("Eventtime " + timeUnitPlot + "; Client " + iClient + " " + loadCurveAssignments.get(iAssignement).getLoadCurve().getName() + " " + operationNames[iAssignement]); log.info("Writing " + operationsOfType[iAssignement][iClient] + " operations of type " + loadCurveAssignments.get(iAssignement).getOperationName() + " for client " + iClient); for (LoadEvent event : eventList) { if (event.getClientId() == iClient) { if (event.getOperation().getName().equals(operationNames[iAssignement])) { double x = timeScalingFactor * event.getTime(); double y = LoadCurveCalculator .r(loadCurveAssignments.get(iAssignement).getLoadCurve(), event.getTime()); pw.println(format.format(x) + "; " + format.format(y)); } } } pw.println(); } } } finally { IOUtils.closeQuietly(pw); } }
From source file:org.totschnig.myexpenses.util.Utils.java
public static char getDefaultDecimalSeparator() { char sep = '.'; NumberFormat nfDLocal = NumberFormat.getNumberInstance(); if (nfDLocal instanceof DecimalFormat) { DecimalFormatSymbols symbols = ((DecimalFormat) nfDLocal).getDecimalFormatSymbols(); sep = symbols.getDecimalSeparator(); }// w w w . j a v a 2 s . c om return sep; }
From source file:com.github.sdbg.debug.core.internal.sourcemaps.SourceMap.java
@Override public String toString() { return "[" + getPath().lastSegment() + ", " + NumberFormat.getNumberInstance().format(entries.length) + " lines]"; }