use of java.text.FieldPosition in project Sprog-App by PaulKlinger.
the class Graphs method initGraph.
public static void initGraph(Context context, XYPlot plot, List<Number> xs, List<Number> ys, int type, int yStep) {
XYSeries data = new SimpleXYSeries(xs, ys, "");
if (type == BAR) {
BarFormatter formatter = new BarFormatter(ContextCompat.getColor(context, R.color.colorGraph), Color.TRANSPARENT);
formatter.setLegendIconEnabled(false);
plot.addSeries(data, formatter);
BarRenderer br = plot.getRenderer(BarRenderer.class);
br.setBarGroupWidth(BarRenderer.BarGroupWidthMode.FIXED_GAP, 2);
plot.getGraph().getDomainGridLinePaint().setColor(Color.TRANSPARENT);
} else if (type == LINE) {
LineAndPointFormatter formatter = new LineAndPointFormatter(ContextCompat.getColor(context, R.color.colorGraph), Color.TRANSPARENT, Color.TRANSPARENT, null);
formatter.setLegendIconEnabled(false);
plot.addSeries(data, formatter);
} else {
throw new UnsupportedOperationException();
}
plot.setDomainBoundaries((int) xs.get(xs.size() - 1) - Util.getDisplayWidthDp(context) / 20, xs.get(xs.size() - 1).intValue() + 0.5, BoundaryMode.FIXED);
int maxy = Stream.of(ys).mapToInt(n -> n.intValue()).max().orElse(0);
plot.setRangeBoundaries(0, maxy, BoundaryMode.FIXED);
PanZoom panZoom = PanZoom.attach(plot);
panZoom.setPan(PanZoom.Pan.HORIZONTAL);
panZoom.setZoom(PanZoom.Zoom.NONE);
plot.getOuterLimits().set((int) xs.get(0) - 1, xs.get(xs.size() - 1).intValue() + 0.5, -10, maxy);
plot.getGraph().setLineLabelEdges(XYGraphWidget.Edge.BOTTOM, XYGraphWidget.Edge.LEFT);
plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).setFormat(new NumberFormat() {
@Override
public StringBuffer format(long val, StringBuffer buffer, FieldPosition pos) {
return null;
}
@Override
public Number parse(String source, ParsePosition parsePosition) {
return null;
}
@Override
public StringBuffer format(double val, StringBuffer buffer, FieldPosition pos) {
int year = (int) val / 12;
int month = (int) val % 12 + 1;
if (month == 1) {
return new StringBuffer(String.format("%d-%d", year, month));
} else {
return new StringBuffer(String.format("%d", month));
}
}
});
plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.LEFT).setFormat(new NumberFormat() {
@Override
public StringBuffer format(long obj, StringBuffer buffer, FieldPosition pos) {
return null;
}
@Override
public Number parse(String source, ParsePosition parsePosition) {
return null;
}
@Override
public StringBuffer format(double val, StringBuffer buffer, FieldPosition pos) {
if (val < 1000) {
return new StringBuffer(String.format("%.0f", val));
} else {
return new StringBuffer(String.format("%.0fK", val / 1000));
}
}
});
// This makes vertical lines move with panning
plot.setUserDomainOrigin(0);
plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 2);
plot.getGraph().setLinesPerDomainLabel(1);
plot.setRangeStep(StepMode.INCREMENT_BY_VAL, yStep);
plot.setLinesPerRangeLabel(1);
plot.setBorderPaint(null);
plot.getBackgroundPaint().setColor(Color.TRANSPARENT);
plot.setPlotMargins(0, 0, 0, 0);
}
use of java.text.FieldPosition in project robolectric by robolectric.
the class ShadowDateIntervalFormat method formatDateInterval.
@Implementation(maxSdk = LOLLIPOP_MR1)
@SuppressWarnings("JdkObsolete")
public static String formatDateInterval(long address, long fromDate, long toDate) {
StringBuffer buffer = new StringBuffer();
FieldPosition pos = new FieldPosition(0);
INTERVAL_CACHE.get(address).format(new com.ibm.icu.util.DateInterval(fromDate, toDate), buffer, pos);
return buffer.toString();
}
use of java.text.FieldPosition in project dbeaver by serge-rider.
the class DateTimeDataFormatter method init.
@Override
public void init(DBSTypedObject type, Locale locale, Map<String, Object> properties) {
pattern = CommonUtils.toString(properties.get(PROP_PATTERN));
dateFormat = new ExtendedDateFormat(pattern, locale);
// We shouldn't use lanient formatter (#7244)
dateFormat.setLenient(false);
buffer = new StringBuffer();
position = new FieldPosition(0);
// DateTimeFormatter pattern for nanoseconds is "n" but old "f" (ExtendedDateFormat)
String java8DatePattern = pattern.replaceAll("f+", "n");
dateTimeFormatter = DateTimeFormatter.ofPattern(java8DatePattern);
}
use of java.text.FieldPosition in project dbeaver by serge-rider.
the class NumberDataFormatter method init.
@Override
public void init(DBSTypedObject type, Locale locale, Map<String, Object> properties) {
numberFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale);
Object useGrouping = properties.get(NumberFormatSample.PROP_USE_GROUPING);
if (useGrouping != null) {
numberFormat.setGroupingUsed(CommonUtils.toBoolean(useGrouping));
}
Object maxIntDigits = properties.get(NumberFormatSample.PROP_MAX_INT_DIGITS);
if (maxIntDigits != null) {
numberFormat.setMaximumIntegerDigits(CommonUtils.toInt(maxIntDigits));
}
Object minIntDigits = properties.get(NumberFormatSample.PROP_MIN_INT_DIGITS);
if (minIntDigits != null) {
numberFormat.setMinimumIntegerDigits(CommonUtils.toInt(minIntDigits));
}
if (type != null && type.getScale() != null) {
int typeScale = type.getScale();
// #6111 + #6914.
// Here is a trick. We can't set max digiter bigger than scale (otherwise long numbers are corrupted)
Object maxFractDigits = properties.get(NumberFormatSample.PROP_MAX_FRACT_DIGITS);
if (maxFractDigits != null) {
int maxFD = CommonUtils.toInt(maxFractDigits);
if (typeScale > 0 && maxFD > typeScale) {
maxFD = typeScale;
}
numberFormat.setMaximumFractionDigits(maxFD);
}
Object minFractDigits = properties.get(NumberFormatSample.PROP_MIN_FRACT_DIGITS);
if (minFractDigits != null) {
numberFormat.setMinimumFractionDigits(CommonUtils.toInt(minFractDigits));
} else {
numberFormat.setMinimumFractionDigits(0);
}
}
String roundingMode = CommonUtils.toString(properties.get(NumberFormatSample.PROP_ROUNDING_MODE));
if (!CommonUtils.isEmpty(roundingMode)) {
try {
numberFormat.setRoundingMode(RoundingMode.valueOf(roundingMode));
} catch (Exception e) {
// just skip it
}
}
if (type != null && CommonUtils.toBoolean(properties.get(NumberFormatSample.PROP_USE_TYPE_SCALE))) {
if (type.getScale() != null && type.getScale() > 0) {
int fractionDigits = type.getScale();
if (fractionDigits > MAX_DEFAULT_FRACTIONS_DIGITS)
fractionDigits = MAX_DEFAULT_FRACTIONS_DIGITS;
numberFormat.setMinimumFractionDigits(fractionDigits);
}
}
if (type != null && (type.getTypeModifiers() & DBSTypedObject.TYPE_MOD_NUMBER_LEADING_ZEROES) > 0) {
// Override number format style set from properties in favor of type's own formatting rules
numberFormat.setMinimumIntegerDigits((int) type.getMaxLength());
numberFormat.setGroupingUsed(false);
}
buffer = new StringBuffer();
position = new FieldPosition(0);
}
use of java.text.FieldPosition in project es6draft by anba.
the class PluralRulesObject method toFixedDecimal.
@SuppressWarnings("deprecation")
com.ibm.icu.text.PluralRules.FixedDecimal toFixedDecimal(double n) {
NumberFormat nf = getNumberFormat();
StringBuffer sb = new StringBuffer();
FieldPosition fp = new FieldPosition(DecimalFormat.FRACTION_FIELD);
nf.format(n, sb, fp);
int v = fp.getEndIndex() - fp.getBeginIndex();
long f = 0;
if (v > 0) {
ParsePosition pp = new ParsePosition(fp.getBeginIndex());
f = nf.parse(sb.toString(), pp).longValue();
}
return new com.ibm.icu.text.PluralRules.FixedDecimal(n, v, f);
}
Aggregations