List of usage examples for java.text NumberFormat NumberFormat
protected NumberFormat()
From source file:project.pamela.slambench.fragments.RankPlot.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Replace LinearLayout by the type of the root element of the layout you're trying to load LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.rank_plot, container, false); TextView oclLegend = (TextView) llLayout.findViewById(R.id.oclLegend); TextView cppLegend = (TextView) llLayout.findViewById(R.id.cppLegend); TextView otherLegend = (TextView) llLayout.findViewById(R.id.otherLegend); TextView yoursLegend = (TextView) llLayout.findViewById(R.id.yoursLegend); oclLegend.setBackgroundColor(getResources().getColor(R.color.oclLegendColor)); cppLegend.setBackgroundColor(getResources().getColor(R.color.cppLegendColor)); otherLegend.setBackgroundColor(getResources().getColor(R.color.othersLegendColor)); yoursLegend.setBackgroundColor(getResources().getColor(R.color.yoursLegendColor)); /*// www. j av a 2 s . c o m if (SLAMBenchApplication.getBenchmark() == null) { // Need to run the configuration download .... try { InputStream inputStream = this.getActivity().getAssets().open("demo.xml"); SLAMBenchXmlParser parser = new SLAMBenchXmlParser(); SLAMConfiguration entries = parser.parse(inputStream); inputStream.close(); SLAMBenchApplication.setBenchmark(new SLAMBench(entries)); if (entries == null ) { Log.e(SLAMBenchApplication.LOG_TAG, getString(R.string.log_configuration_error)); } } catch (IOException e) { Log.e(SLAMBenchApplication.LOG_TAG, getString(R.string.log_configuration_error), e); } catch (XmlPullParserException e) { Log.e(SLAMBenchApplication.LOG_TAG, getString(R.string.log_configuration_error), e); } } */ if (SLAMBenchApplication.getBenchmark() == null) { return llLayout; } List<SLAMRank> ranks = SLAMBenchApplication.getBenchmark().getDevicesRank(); values = new Double[ranks.size() + 1]; devices = new String[ranks.size() + 1]; versions = new String[ranks.size() + 1]; for (int i = 0; i < ranks.size(); i++) { SLAMRank r = ranks.get(i); values[i] = r.get_result(); devices[i] = r.get_device(); versions[i] = (r.get_test() == null) ? "" : r.get_test().name; } double best = SLAMBenchApplication.getBenchmark().getBestSpeed(); values[values.length - 1] = (best <= 0) ? 0 : 1.0 / best; devices[values.length - 1] = YOUR_DEVICE; if (SLAMBenchApplication.getBenchmark() != null && SLAMBenchApplication.getBenchmark().getBestResult() != null && SLAMBenchApplication.getBenchmark().getBestResult().test != null) { versions[values.length - 1] = SLAMBenchApplication.getBenchmark().getBestResult().test.name; } else { versions[values.length - 1] = ""; } for (int n = 0; n < values.length; n++) { for (int m = 0; m < values.length - 1 - n; m++) { if ((values[m].compareTo(values[m + 1])) <= 0) { String swapString = devices[m]; devices[m] = devices[m + 1]; devices[m + 1] = swapString; swapString = versions[m]; versions[m] = versions[m + 1]; versions[m + 1] = swapString; Double swapInt = values[m]; values[m] = values[m + 1]; values[m + 1] = swapInt; } } } int start = Math.max(0, values.length - RANK_SIZE - 1); int end = values.length - 1; Log.d(SLAMBenchApplication.LOG_TAG, "Default ArrayOfRange(" + Integer.valueOf(start) + "," + Integer.valueOf(end) + ")"); for (int i = 0; i < values.length; i++) { if (devices[i].equals(YOUR_DEVICE)) { start = Math.max(0, i - (RANK_SIZE / 2)); end = Math.min(values.length - 1, start + RANK_SIZE); if (end - start < RANK_SIZE) { start = Math.max(0, end - RANK_SIZE); } break; } } Log.d(SLAMBenchApplication.LOG_TAG, "ArrayOfRange(" + Integer.valueOf(start) + "," + Integer.valueOf(end) + ")"); if (best > 0) { values = Arrays.copyOfRange(values, start, end); devices = Arrays.copyOfRange(devices, start, end); versions = Arrays.copyOfRange(versions, start, end); } else { values = Arrays.copyOf(values, values.length - 1); devices = Arrays.copyOf(devices, devices.length - 1); versions = Arrays.copyOf(versions, versions.length - 1); } // initialize our XYPlot reference: plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot); // colors plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE); plot.getBorderPaint().setColor(Color.WHITE); plot.getBackgroundPaint().setColor(Color.WHITE); plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeLabelPaint().setTextSize(20); plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK); plot.getGraphWidget().getDomainGridLinePaint().setColor(Color.TRANSPARENT); //plot.getGraphWidget().getRangeGridLinePaint().setColor(Color.TRANSPARENT); formatter1 = new MyBarFormatter(getResources().getColor(R.color.othersLegendColor), Color.WHITE); openclFormatter = new MyBarFormatter(getResources().getColor(R.color.oclLegendColor), Color.WHITE); cppFormatter = new MyBarFormatter(getResources().getColor(R.color.cppLegendColor), Color.WHITE); currentFormatter = new MyBarFormatter(getResources().getColor(R.color.yoursLegendColor), Color.WHITE); plot.setTicksPerRangeLabel(1); //plot.getLayoutManager().remove(plot.getLegendWidget()); plot.getLayoutManager().remove(plot.getTitleWidget()); plot.getLayoutManager().remove(plot.getDomainLabelWidget()); plot.getLayoutManager().remove(plot.getRangeLabelWidget()); plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 0.5); plot.getGraphWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_LEFT, 0, YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM); plot.getGraphWidget().setSize(new SizeMetrics(0, SizeLayoutType.FILL, 0, SizeLayoutType.FILL)); plot.setDomainValueFormat(new NumberFormat() { @Override public StringBuffer format(double value, StringBuffer buffer, FieldPosition field) { int index = (int) (value); //if ((index) == (value)) { // return new StringBuffer(devices[index]); //} return new StringBuffer(""); } @Override public StringBuffer format(long value, StringBuffer buffer, FieldPosition field) { throw new UnsupportedOperationException("Not yet implemented."); } @Override public Number parse(String string, ParsePosition position) { throw new UnsupportedOperationException("Not yet implemented."); } }); // Setup our Series with the selected number of elements series1 = new SimpleXYSeries(Arrays.asList(values), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "devices"); // add a new series' to the xyplot: plot.addSeries(series1, formatter1); // Setup the BarRenderer with our selected options MyBarRenderer renderer = ((MyBarRenderer) plot.getRenderer(MyBarRenderer.class)); renderer.setBarRenderStyle(BarRenderer.BarRenderStyle.OVERLAID); renderer.setBarWidthStyle(BarRenderer.BarWidthStyle.VARIABLE_WIDTH); renderer.setBarWidth(BAR_GAP); renderer.setBarGap(BAR_GAP); plot.getGraphWidget().setDomainLabelOrientation(-90); plot.getGraphWidget().setGridPaddingRight(0); plot.getGraphWidget().setGridPaddingTop(0); plot.getGraphWidget().setGridPaddingLeft(0); plot.getGraphWidget().setGridPaddingBottom(0); plot.calculateMinMaxVals(); PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue()); PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue()); plot.setDomainBoundaries(minXY.x - 0.5, maxXY.x + 0.5, BoundaryMode.FIXED); plot.setRangeBoundaries(0, (int) (maxXY.y / 10) * 10f + 10f, BoundaryMode.FIXED); plot.redraw(); return llLayout; }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
@Override public void setUseXLabels(final IScope scope, final IExpression expval) { // if there is something to do to use custom X axis final XYPlot pp = (XYPlot) chart.getPlot(); ((NumberAxis) pp.getDomainAxis()).setNumberFormatOverride(new NumberFormat() { @Override/*w ww . jav a 2s . c o m*/ public StringBuffer format(final double number, final StringBuffer toAppendTo, final FieldPosition pos) { final int ind = chartdataset.XSeriesValues.indexOf(number); if (ind >= 0) { return new StringBuffer("" + chartdataset.Xcategories.get(ind)); } return new StringBuffer(""); } @Override public StringBuffer format(final long number, final StringBuffer toAppendTo, final FieldPosition pos) { return new StringBuffer("n" + number); // return new StringBuffer(String.format("%s", number)); } @Override public Number parse(final String source, final ParsePosition parsePosition) { return null; } }); }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
@Override public void setUseYLabels(final IScope scope, final IExpression expval) { // if there is something to do to use custom X axis final XYPlot pp = (XYPlot) chart.getPlot(); ((NumberAxis) pp.getRangeAxis()).setNumberFormatOverride(new NumberFormat() { @Override/* ww w. j ava2 s . c om*/ public StringBuffer format(final double number, final StringBuffer toAppendTo, final FieldPosition pos) { final int ind = chartdataset.YSeriesValues.indexOf(number); if (ind >= 0) { return new StringBuffer("" + chartdataset.Ycategories.get(ind)); } return new StringBuffer(""); } @Override public StringBuffer format(final long number, final StringBuffer toAppendTo, final FieldPosition pos) { return new StringBuffer("n" + number); // return new StringBuffer(String.format("%s", number)); } @Override public Number parse(final String source, final ParsePosition parsePosition) { return null; } }); }