From 2a940c45a38cec42a6a85714f7941ee8613f48ee Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 17 Feb 2013 11:42:55 +1300 Subject: Added formatter utility --- src/org/traccar/web/client/ApplicationContext.java | 55 ++++++++++++++++++++++ src/org/traccar/web/client/Context.java | 42 ----------------- src/org/traccar/web/client/model/StateReader.java | 5 +- src/org/traccar/web/client/view/ArchiveView.java | 4 +- 4 files changed, 59 insertions(+), 47 deletions(-) create mode 100644 src/org/traccar/web/client/ApplicationContext.java delete mode 100644 src/org/traccar/web/client/Context.java (limited to 'src/org/traccar/web') diff --git a/src/org/traccar/web/client/ApplicationContext.java b/src/org/traccar/web/client/ApplicationContext.java new file mode 100644 index 00000000..f5053243 --- /dev/null +++ b/src/org/traccar/web/client/ApplicationContext.java @@ -0,0 +1,55 @@ +package org.traccar.web.client; + +import org.traccar.web.shared.model.ApplicationSettings; +import org.traccar.web.shared.model.UserSettings; + +public class ApplicationContext { + + private static final ApplicationContext context = new ApplicationContext(); + + public static ApplicationContext getInstance() { + return context; + } + + private FormatterUtil formatterUtil; + + public void setFormatterUtil(FormatterUtil formatterUtil) { + this.formatterUtil = formatterUtil; + } + + public FormatterUtil getFormatterUtil() { + if (formatterUtil == null) { + formatterUtil = new FormatterUtil(); + } + return formatterUtil; + } + + private ApplicationSettings applicationSettings; + + public void setApplicationSettings(ApplicationSettings applicationSettings) { + this.applicationSettings = applicationSettings; + } + + public ApplicationSettings getApplicationSettings() { + if (applicationSettings != null) { + return applicationSettings; + } else { + return new ApplicationSettings(); // default settings + } + } + + private UserSettings userSettings; + + public void setUserSettings(UserSettings userSettings) { + this.userSettings = userSettings; + } + + public UserSettings getUserSettings() { + if (userSettings != null) { + return userSettings; + } else { + return new UserSettings(); // default settings + } + } + +} diff --git a/src/org/traccar/web/client/Context.java b/src/org/traccar/web/client/Context.java deleted file mode 100644 index 6cc6f0c4..00000000 --- a/src/org/traccar/web/client/Context.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.traccar.web.client; - -import org.traccar.web.shared.model.ApplicationSettings; -import org.traccar.web.shared.model.UserSettings; - -public class Context { - - private static final Context context = new Context(); - - public Context getInstance() { - return context; - } - - private ApplicationSettings applicationSettings; - - public void setApplicationSettings(ApplicationSettings applicationSettings) { - this.applicationSettings = applicationSettings; - } - - public ApplicationSettings getApplicationSettings() { - if (applicationSettings != null) { - return applicationSettings; - } else { - return new ApplicationSettings(); // default settings - } - } - - private UserSettings userSettings; - - public void setUserSettings(UserSettings userSettings) { - this.userSettings = userSettings; - } - - public UserSettings getUserSettings() { - if (userSettings != null) { - return userSettings; - } else { - return new UserSettings(); // default settings - } - } - -} diff --git a/src/org/traccar/web/client/model/StateReader.java b/src/org/traccar/web/client/model/StateReader.java index a3549179..733bde62 100644 --- a/src/org/traccar/web/client/model/StateReader.java +++ b/src/org/traccar/web/client/model/StateReader.java @@ -3,11 +3,10 @@ package org.traccar.web.client.model; import java.util.LinkedList; import java.util.List; +import org.traccar.web.client.ApplicationContext; import org.traccar.web.shared.model.Position; import org.traccar.web.shared.model.XmlParser; -import com.google.gwt.i18n.client.DateTimeFormat; - public class StateReader { private static String toString(Object object) { @@ -21,7 +20,7 @@ public class StateReader { List state = new LinkedList(); state.add(new StateItem("valid", toString(position.getValid()))); - state.add(new StateItem("time", DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format(position.getTime()))); + state.add(new StateItem("time", ApplicationContext.getInstance().getFormatterUtil().formatTime(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()))); diff --git a/src/org/traccar/web/client/view/ArchiveView.java b/src/org/traccar/web/client/view/ArchiveView.java index 32e569eb..d510cbe1 100644 --- a/src/org/traccar/web/client/view/ArchiveView.java +++ b/src/org/traccar/web/client/view/ArchiveView.java @@ -19,6 +19,7 @@ import java.util.Date; import java.util.LinkedList; import java.util.List; +import org.traccar.web.client.ApplicationContext; import org.traccar.web.client.model.BaseStoreHandlers; import org.traccar.web.client.model.DeviceProperties; import org.traccar.web.client.model.PositionProperties; @@ -27,7 +28,6 @@ import org.traccar.web.shared.model.Position; import com.google.gwt.cell.client.DateCell; import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; @@ -109,7 +109,7 @@ public class ArchiveView implements SelectionChangedEvent.SelectionChangedHandle columnConfigList.add(new ColumnConfig(positionProperties.valid(), 0, "Valid")); ColumnConfig columnConfig = new ColumnConfig(positionProperties.time(), 0, "Time"); - columnConfig.setCell(new DateCell(DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss"))); + columnConfig.setCell(new DateCell(ApplicationContext.getInstance().getFormatterUtil().getTimeFormat())); columnConfigList.add(columnConfig); columnConfigList.add(new ColumnConfig(positionProperties.latitude(), 0, "Latitude")); -- cgit v1.2.3