aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/client/FormatterUtil.java
blob: 36c24dcbc1bd9a3aa57c20296b4b3ec56566027d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.traccar.web.client;

import com.google.gwt.i18n.client.CurrencyList;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;

public class FormatterUtil {

    public DateTimeFormat getTimeFormat() {
        return DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
    }

    private class SpeedNumberFormat extends NumberFormat {

        private final String unit;
        private final double factor;

        public SpeedNumberFormat(String unit, double factor) {
            super("0.##", CurrencyList.get().getDefault(), true);
            this.unit = unit;
            this.factor = factor;
        }

        @Override
        public String format(double number) {
            return super.format(number * factor) + " " + unit;
        }

    }

    public NumberFormat getSpeedFormat() {
        switch (ApplicationContext.getInstance().getUserSettings().getSpeedUnit()) {
        case kilometersPerHour:
            return new SpeedNumberFormat("km/h", 1.852);
        case milesPerHour:
            return new SpeedNumberFormat("mph", 1.150779);
        default:
            return new SpeedNumberFormat("kn", 1);
        }
    }

}