diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2013-02-26 20:36:47 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2013-02-26 20:36:47 +1300 |
commit | cda6c01a2abc7f60a191d97e8b070218879f7f92 (patch) | |
tree | edf8a5a9be5d07249d86ca6e924d8925966042fc /src/org | |
parent | ebcedc38812405ba1cd03c518317bcf0cd52f925 (diff) | |
download | trackermap-web-cda6c01a2abc7f60a191d97e8b070218879f7f92.tar.gz trackermap-web-cda6c01a2abc7f60a191d97e8b070218879f7f92.tar.bz2 trackermap-web-cda6c01a2abc7f60a191d97e8b070218879f7f92.zip |
Add units preference (fix #7)
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/web/client/FormatterUtil.java | 33 | ||||
-rw-r--r-- | src/org/traccar/web/client/model/StateReader.java | 4 | ||||
-rw-r--r-- | src/org/traccar/web/client/view/ArchiveView.java | 13 |
3 files changed, 40 insertions, 10 deletions
diff --git a/src/org/traccar/web/client/FormatterUtil.java b/src/org/traccar/web/client/FormatterUtil.java index f5c7d3e1..36c24dcb 100644 --- a/src/org/traccar/web/client/FormatterUtil.java +++ b/src/org/traccar/web/client/FormatterUtil.java @@ -1,8 +1,8 @@ package org.traccar.web.client; -import java.util.Date; - +import com.google.gwt.i18n.client.CurrencyList; import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.NumberFormat; public class FormatterUtil { @@ -10,8 +10,33 @@ public class FormatterUtil { return DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss"); } - public String formatTime(Date time) { - return getTimeFormat().format(time); + 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); + } } } diff --git a/src/org/traccar/web/client/model/StateReader.java b/src/org/traccar/web/client/model/StateReader.java index 733bde62..667f474b 100644 --- a/src/org/traccar/web/client/model/StateReader.java +++ b/src/org/traccar/web/client/model/StateReader.java @@ -20,11 +20,11 @@ public class StateReader { List<StateItem> state = new LinkedList<StateItem>(); state.add(new StateItem("valid", toString(position.getValid()))); - state.add(new StateItem("time", ApplicationContext.getInstance().getFormatterUtil().formatTime(position.getTime()))); + state.add(new StateItem("time", ApplicationContext.getInstance().getFormatterUtil().getTimeFormat().format(position.getTime()))); state.add(new StateItem("latitude", toString(position.getLatitude()))); state.add(new StateItem("longitude", toString(position.getLongitude()))); state.add(new StateItem("altitude", toString(position.getAltitude()))); - state.add(new StateItem("speed", toString(position.getSpeed()))); + state.add(new StateItem("speed", ApplicationContext.getInstance().getFormatterUtil().getSpeedFormat().format(position.getSpeed()))); state.add(new StateItem("course", toString(position.getCourse()))); state.add(new StateItem("power", toString(position.getPower()))); state.add(new StateItem("address", position.getAddress())); diff --git a/src/org/traccar/web/client/view/ArchiveView.java b/src/org/traccar/web/client/view/ArchiveView.java index 04ece4af..28291d0d 100644 --- a/src/org/traccar/web/client/view/ArchiveView.java +++ b/src/org/traccar/web/client/view/ArchiveView.java @@ -32,6 +32,7 @@ import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.ui.Widget; +import com.sencha.gxt.cell.core.client.NumberCell; import com.sencha.gxt.core.client.Style.SelectionMode; import com.sencha.gxt.data.shared.ListStore; import com.sencha.gxt.data.shared.event.StoreHandlers; @@ -108,14 +109,18 @@ public class ArchiveView implements SelectionChangedEvent.SelectionChangedHandle columnConfigList.add(new ColumnConfig<Position, Boolean>(positionProperties.valid(), 0, "Valid")); - ColumnConfig<Position, Date> columnConfig = new ColumnConfig<Position, Date>(positionProperties.time(), 0, "Time"); - columnConfig.setCell(new DateCell(ApplicationContext.getInstance().getFormatterUtil().getTimeFormat())); - columnConfigList.add(columnConfig); + ColumnConfig<Position, Date> columnConfigDate = new ColumnConfig<Position, Date>(positionProperties.time(), 0, "Time"); + columnConfigDate.setCell(new DateCell(ApplicationContext.getInstance().getFormatterUtil().getTimeFormat())); + columnConfigList.add(columnConfigDate); columnConfigList.add(new ColumnConfig<Position, Double>(positionProperties.latitude(), 0, "Latitude")); columnConfigList.add(new ColumnConfig<Position, Double>(positionProperties.longitude(), 0, "Longitude")); columnConfigList.add(new ColumnConfig<Position, Double>(positionProperties.altitude(), 0, "Altitude")); - columnConfigList.add(new ColumnConfig<Position, Double>(positionProperties.speed(), 0, "Speed")); + + ColumnConfig<Position, Double> columnConfigDouble = new ColumnConfig<Position, Double>(positionProperties.speed(), 0, "Speed"); + columnConfigDouble.setCell(new NumberCell<Double>(ApplicationContext.getInstance().getFormatterUtil().getSpeedFormat())); + columnConfigList.add(columnConfigDouble); + columnConfigList.add(new ColumnConfig<Position, Double>(positionProperties.course(), 0, "Course")); columnConfigList.add(new ColumnConfig<Position, Double>(positionProperties.power(), 0, "Power")); |