Search in sources :

Example 96 with FieldPosition

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);
}
Also used : SimpleXYSeries(com.androidplot.xy.SimpleXYSeries) XYSeries(com.androidplot.xy.XYSeries) PanZoom(com.androidplot.xy.PanZoom) BarFormatter(com.androidplot.xy.BarFormatter) SimpleXYSeries(com.androidplot.xy.SimpleXYSeries) BarRenderer(com.androidplot.xy.BarRenderer) FieldPosition(java.text.FieldPosition) LineAndPointFormatter(com.androidplot.xy.LineAndPointFormatter) NumberFormat(java.text.NumberFormat) ParsePosition(java.text.ParsePosition)

Example 97 with FieldPosition

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();
}
Also used : FieldPosition(java.text.FieldPosition) Implementation(org.robolectric.annotation.Implementation)

Example 98 with FieldPosition

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);
}
Also used : ExtendedDateFormat(org.jkiss.utils.time.ExtendedDateFormat) FieldPosition(java.text.FieldPosition)

Example 99 with FieldPosition

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);
}
Also used : DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) FieldPosition(java.text.FieldPosition) ParseException(java.text.ParseException)

Example 100 with FieldPosition

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);
}
Also used : FieldPosition(java.text.FieldPosition) NumberFormat(com.ibm.icu.text.NumberFormat) ParsePosition(java.text.ParsePosition)

Aggregations

FieldPosition (java.text.FieldPosition)100 Date (java.util.Date)31 SimpleDateFormat (java.text.SimpleDateFormat)28 DecimalFormat (java.text.DecimalFormat)12 NumberFormat (java.text.NumberFormat)12 ParsePosition (java.text.ParsePosition)12 IsoDateFormat (alma.acs.util.IsoDateFormat)9 Test (org.junit.Test)9 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)8 Format (java.text.Format)8 MessageFormat (java.text.MessageFormat)8 DateFormat (java.text.DateFormat)6 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)5 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Vector (java.util.Vector)3 ExtendedDateFormat (org.jkiss.utils.time.ExtendedDateFormat)3 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2