1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.properties
;
15 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
16 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestampFormat
;
20 * TMF Time format preferences
22 * @author Francois Chouinard
26 @SuppressWarnings("javadoc")
27 public class TmfTimePreferences
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 public static final String DEFAULT_TIME_PATTERN
= "HH:mm:ss.SSS_CCC_NNN"; //$NON-NLS-1$
35 static final String TIME_FORMAT_PREF
= "org.eclipse.linuxtools.tmf.ui.prefs.time.format"; //$NON-NLS-1$
36 static final String DATIME
= TIME_FORMAT_PREF
+ ".datime"; //$NON-NLS-1$
37 static final String SUBSEC
= TIME_FORMAT_PREF
+ ".subsec"; //$NON-NLS-1$
39 static final String DATE_DELIMITER
= TIME_FORMAT_PREF
+ ".date.delimiter"; //$NON-NLS-1$
40 static final String TIME_DELIMITER
= TIME_FORMAT_PREF
+ ".time.delimiter"; //$NON-NLS-1$
41 static final String SSEC_DELIMITER
= TIME_FORMAT_PREF
+ ".ssec.delimiter"; //$NON-NLS-1$
43 static final String DATE_YEAR_FMT
= "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$
44 static final String DATE_YEAR2_FMT
= "yy-MM-dd HH:mm:ss"; //$NON-NLS-1$
45 static final String DATE_MONTH_FMT
= "MM-dd HH:mm:ss"; //$NON-NLS-1$
46 static final String DATE_DAY_FMT
= "dd HH:mm:ss"; //$NON-NLS-1$
47 static final String DATE_JDAY_FMT
= "DDD HH:mm:ss"; //$NON-NLS-1$
48 static final String DATE_NO_FMT
= "HH:mm:ss"; //$NON-NLS-1$
50 static final String TIME_HOUR_FMT
= "HH:mm:ss"; //$NON-NLS-1$
51 static final String TIME_MINUTE_FMT
= "mm:ss"; //$NON-NLS-1$
52 static final String TIME_SECOND_FMT
= "ss"; //$NON-NLS-1$
53 static final String TIME_ELAPSED_FMT
= "TTT"; //$NON-NLS-1$
54 static final String TIME_NO_FMT
= ""; //$NON-NLS-1$
56 static final String SUBSEC_MILLI_FMT
= "SSS"; //$NON-NLS-1$
57 static final String SUBSEC_MICRO_FMT
= "SSS CCC"; //$NON-NLS-1$
58 static final String SUBSEC_NANO_FMT
= "SSS CCC NNN"; //$NON-NLS-1$
59 static final String SUBSEC_NO_FMT
= ""; //$NON-NLS-1$
61 static final String DELIMITER_NONE
= ""; //$NON-NLS-1$
62 static final String DELIMITER_SPACE
= " "; //$NON-NLS-1$
63 static final String DELIMITER_PERIOD
= "."; //$NON-NLS-1$
64 static final String DELIMITER_COMMA
= ","; //$NON-NLS-1$
65 static final String DELIMITER_DASH
= "-"; //$NON-NLS-1$
66 static final String DELIMITER_UNDERLINE
= "_"; //$NON-NLS-1$
67 static final String DELIMITER_COLON
= ":"; //$NON-NLS-1$
68 static final String DELIMITER_SEMICOLON
= ";"; //$NON-NLS-1$
69 static final String DELIMITER_SLASH
= "/"; //$NON-NLS-1$
70 static final String DELIMITER_DQUOT
= "\""; //$NON-NLS-1$
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
76 private static TmfTimePreferences fPreferences
;
78 private static IPreferenceStore fPreferenceStore
;
79 private static String fTimestampPattern
;
80 private static String fIntervalPattern
;
82 private String fDatimeFormat
;
83 private String fDateFormat
;
84 private String fTimeFormat
;
85 private String fSSecFormat
;
87 private String fDateFieldSep
= "-"; //$NON-NLS-1$
88 private String fTimeFieldSep
= ":"; //$NON-NLS-1$
89 private String fSSecFieldSep
= " "; //$NON-NLS-1$
91 // ------------------------------------------------------------------------
93 // ------------------------------------------------------------------------
95 public static void init() {
96 fPreferenceStore
= Activator
.getDefault().getPreferenceStore();
97 fPreferenceStore
.setDefault(TmfTimePreferences
.DATIME
, TIME_HOUR_FMT
);
98 fPreferenceStore
.setDefault(TmfTimePreferences
.SUBSEC
, SUBSEC_NANO_FMT
);
99 fPreferenceStore
.setDefault(TmfTimePreferences
.DATE_DELIMITER
, DELIMITER_DASH
);
100 fPreferenceStore
.setDefault(TmfTimePreferences
.TIME_DELIMITER
, DELIMITER_COLON
);
101 fPreferenceStore
.setDefault(TmfTimePreferences
.SSEC_DELIMITER
, DELIMITER_SPACE
);
103 // Create the singleton and initialize format preferences
107 public static synchronized IPreferenceStore
getPreferenceStore() {
108 if (fPreferenceStore
== null) {
111 return fPreferenceStore
;
114 public static synchronized TmfTimePreferences
getInstance() {
115 if (fPreferences
== null) {
116 fPreferences
= new TmfTimePreferences();
124 private TmfTimePreferences() {
126 setTimePattern(fTimestampPattern
);
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
134 * @return the timestamp pattern
136 public static String
getTimePattern() {
137 return fTimestampPattern
;
141 * Sets the timestamp pattern and updates TmfTimestampFormat
143 * @param timePattern the new timestamp pattern
145 static void setTimePattern(String timePattern
) {
146 fTimestampPattern
= timePattern
;
147 TmfTimestampFormat
.setDefaultTimeFormat(fTimestampPattern
);
148 TmfTimestampFormat
.setDefaultIntervalFormat(fIntervalPattern
);
152 * Update the Date field separator
153 * @param pattern the Date field separator
155 void setDateFieldSep(String pattern
) {
156 fDateFieldSep
= pattern
;
160 * Update the Time field separator
161 * @param pattern the Time field separator
163 void setTimeFieldSep(String pattern
) {
164 fTimeFieldSep
= pattern
;
168 * Update the Subseconds field separator
169 * @param pattern the Subseconds field separator
171 void setSSecFieldSep(String pattern
) {
172 fSSecFieldSep
= pattern
;
176 * Update the Date/Time format
177 * @param pattern the Date/Time format
179 void setDateTimeFormat(String pattern
) {
180 fDatimeFormat
= pattern
;
181 if (fDatimeFormat
== null) {
182 fDatimeFormat
= DEFAULT_TIME_PATTERN
;
184 int index
= fDatimeFormat
.indexOf(' ');
186 fDateFormat
= fDatimeFormat
.substring(0, fDatimeFormat
.indexOf(' ') + 1);
187 fTimeFormat
= fDatimeFormat
.substring(fDateFormat
.length());
189 fDateFormat
= ""; //$NON-NLS-1$
190 fTimeFormat
= fDatimeFormat
;
195 * Update the Subseconds format
196 * @param pattern the Subseconds format
198 void setSSecFormat(String pattern
) {
199 fSSecFormat
= pattern
;
202 // ------------------------------------------------------------------------
204 // ------------------------------------------------------------------------
206 void initPatterns() {
207 setDateTimeFormat(fPreferenceStore
.getString(DATIME
));
208 fSSecFormat
= fPreferenceStore
.getString(SUBSEC
);
209 fDateFieldSep
= fPreferenceStore
.getString(DATE_DELIMITER
);
210 fTimeFieldSep
= fPreferenceStore
.getString(TIME_DELIMITER
);
211 fSSecFieldSep
= fPreferenceStore
.getString(SSEC_DELIMITER
);
215 void updatePatterns() {
216 String dateFmt
= fDateFormat
.replaceAll("-", fDateFieldSep
); //$NON-NLS-1$
217 String timeFmt
= fTimeFormat
.replaceAll(":", fTimeFieldSep
); //$NON-NLS-1$
218 String ssecFmt
= fSSecFormat
.replaceAll(" ", fSSecFieldSep
); //$NON-NLS-1$
220 fTimestampPattern
= dateFmt
+ timeFmt
+ "." + ssecFmt
; //$NON-NLS-1$
221 fIntervalPattern
= "TTT." + ssecFmt
; //$NON-NLS-1$
225 setDateTimeFormat(TmfTimePreferences
.TIME_HOUR_FMT
);
226 setSSecFormat(TmfTimePreferences
.SUBSEC_NANO_FMT
);
227 setDateFieldSep(TmfTimePreferences
.DELIMITER_DASH
);
228 setTimeFieldSep(TmfTimePreferences
.DELIMITER_COLON
);
229 setSSecFieldSep(TmfTimePreferences
.DELIMITER_SPACE
);