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
.event
.TmfTimestampFormat
;
20 * TMF Time format preferences
23 * @author Francois Chouinard
25 @SuppressWarnings("javadoc")
26 public class TmfTimePreferences
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 public static final String DEFAULT_TIME_PATTERN
= "HH:mm:ss.SSS_CCC_NNN"; //$NON-NLS-1$
34 static final String TIME_FORMAT_PREF
= "org.eclipse.linuxtools.tmf.ui.prefs.time.format"; //$NON-NLS-1$
35 static final String DATIME
= TIME_FORMAT_PREF
+ ".datime"; //$NON-NLS-1$
36 static final String SUBSEC
= TIME_FORMAT_PREF
+ ".subsec"; //$NON-NLS-1$
38 static final String DATE_DELIMITER
= TIME_FORMAT_PREF
+ ".date.delimiter"; //$NON-NLS-1$
39 static final String TIME_DELIMITER
= TIME_FORMAT_PREF
+ ".time.delimiter"; //$NON-NLS-1$
40 static final String SSEC_DELIMITER
= TIME_FORMAT_PREF
+ ".ssec.delimiter"; //$NON-NLS-1$
42 static final String DATE_YEAR_FMT
= "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$
43 static final String DATE_YEAR2_FMT
= "yy-MM-dd HH:mm:ss"; //$NON-NLS-1$
44 static final String DATE_MONTH_FMT
= "MM-dd HH:mm:ss"; //$NON-NLS-1$
45 static final String DATE_DAY_FMT
= "dd HH:mm:ss"; //$NON-NLS-1$
46 static final String DATE_JDAY_FMT
= "DDD HH:mm:ss"; //$NON-NLS-1$
47 static final String DATE_NO_FMT
= "HH:mm:ss"; //$NON-NLS-1$
49 static final String TIME_HOUR_FMT
= "HH:mm:ss"; //$NON-NLS-1$
50 static final String TIME_MINUTE_FMT
= "mm:ss"; //$NON-NLS-1$
51 static final String TIME_SECOND_FMT
= "ss"; //$NON-NLS-1$
52 static final String TIME_ELAPSED_FMT
= "TTT"; //$NON-NLS-1$
53 static final String TIME_NO_FMT
= ""; //$NON-NLS-1$
55 static final String SUBSEC_MILLI_FMT
= "SSS"; //$NON-NLS-1$
56 static final String SUBSEC_MICRO_FMT
= "SSS_CCC"; //$NON-NLS-1$
57 static final String SUBSEC_NANO_FMT
= "SSS_CCC_NNN"; //$NON-NLS-1$
58 static final String SUBSEC_NO_FMT
= ""; //$NON-NLS-1$
60 static final String DELIMITER_NONE
= ""; //$NON-NLS-1$
61 static final String DELIMITER_SPACE
= " "; //$NON-NLS-1$
62 static final String DELIMITER_PERIOD
= "."; //$NON-NLS-1$
63 static final String DELIMITER_COMMA
= ","; //$NON-NLS-1$
64 static final String DELIMITER_DASH
= "-"; //$NON-NLS-1$
65 static final String DELIMITER_UNDERLINE
= "_"; //$NON-NLS-1$
66 static final String DELIMITER_COLON
= ":"; //$NON-NLS-1$
67 static final String DELIMITER_SEMICOLON
= ";"; //$NON-NLS-1$
68 static final String DELIMITER_SLASH
= "/"; //$NON-NLS-1$
69 static final String DELIMITER_DQUOT
= "\""; //$NON-NLS-1$
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
75 private static TmfTimePreferences fPreferences
;
77 private static IPreferenceStore fPreferenceStore
;
78 private static String fTimestampPattern
;
79 private static String fIntervalPattern
;
81 private String fDatimeFormat
;
82 private String fDateFormat
;
83 private String fTimeFormat
;
84 private String fSSecFormat
;
86 private String fDateFieldSep
= "-"; //$NON-NLS-1$
87 private String fTimeFieldSep
= ":"; //$NON-NLS-1$
88 private String fSSecFieldSep
= " "; //$NON-NLS-1$
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
94 public static void init() {
95 fPreferenceStore
= Activator
.getDefault().getPreferenceStore();
96 fPreferenceStore
.setDefault(TmfTimePreferences
.DATIME
, TIME_HOUR_FMT
);
97 fPreferenceStore
.setDefault(TmfTimePreferences
.SUBSEC
, SUBSEC_NANO_FMT
);
98 fPreferenceStore
.setDefault(TmfTimePreferences
.DATE_DELIMITER
, DELIMITER_DASH
);
99 fPreferenceStore
.setDefault(TmfTimePreferences
.TIME_DELIMITER
, DELIMITER_COLON
);
100 fPreferenceStore
.setDefault(TmfTimePreferences
.SSEC_DELIMITER
, DELIMITER_UNDERLINE
);
102 // Create the singleton and initialize format preferences
106 public static synchronized IPreferenceStore
getPreferenceStore() {
107 if (fPreferenceStore
== null) {
110 return fPreferenceStore
;
113 public static synchronized TmfTimePreferences
getInstance() {
114 if (fPreferences
== null) {
115 fPreferences
= new TmfTimePreferences();
123 private TmfTimePreferences() {
125 setTimePattern(fTimestampPattern
);
128 // ------------------------------------------------------------------------
130 // ------------------------------------------------------------------------
133 * @return the timestamp pattern
135 public static String
getTimePattern() {
136 return fTimestampPattern
;
140 * Sets the timestamp pattern and updates TmfTimestampFormat
142 * @param timePattern the new timestamp pattern
144 static void setTimePattern(String timePattern
) {
145 fTimestampPattern
= timePattern
;
146 TmfTimestampFormat
.setDefaultTimeFormat(fTimestampPattern
);
147 TmfTimestampFormat
.setDefaultIntervalFormat(fIntervalPattern
);
151 * Update the Date field separator
152 * @param pattern the Date field separator
154 void setDateFieldSep(String pattern
) {
155 fDateFieldSep
= pattern
;
159 * Update the Time field separator
160 * @param pattern the Time field separator
162 void setTimeFieldSep(String pattern
) {
163 fTimeFieldSep
= pattern
;
167 * Update the Subseconds field separator
168 * @param pattern the Subseconds field separator
170 void setSSecFieldSep(String pattern
) {
171 fSSecFieldSep
= pattern
;
175 * Update the Date/Time format
176 * @param pattern the Date/Time format
178 void setDateTimeFormat(String pattern
) {
179 fDatimeFormat
= pattern
;
180 if (fDatimeFormat
== null) {
181 fDatimeFormat
= DEFAULT_TIME_PATTERN
;
183 int index
= fDatimeFormat
.indexOf(' ');
185 fDateFormat
= fDatimeFormat
.substring(0, fDatimeFormat
.indexOf(' ') + 1);
186 fTimeFormat
= fDatimeFormat
.substring(fDateFormat
.length());
188 fDateFormat
= ""; //$NON-NLS-1$
189 fTimeFormat
= fDatimeFormat
;
194 * Update the Subseconds format
195 * @param pattern the Subseconds format
197 void setSSecFormat(String pattern
) {
198 fSSecFormat
= pattern
;
201 // ------------------------------------------------------------------------
203 // ------------------------------------------------------------------------
205 void initPatterns() {
206 setDateTimeFormat(fPreferenceStore
.getString(DATIME
));
207 fSSecFormat
= fPreferenceStore
.getString(SUBSEC
);
208 fDateFieldSep
= fPreferenceStore
.getString(DATE_DELIMITER
);
209 fTimeFieldSep
= fPreferenceStore
.getString(TIME_DELIMITER
);
210 fSSecFieldSep
= fPreferenceStore
.getString(SSEC_DELIMITER
);
214 void updatePatterns() {
215 String dateFmt
= fDateFormat
.replaceAll("-", fDateFieldSep
); //$NON-NLS-1$
216 String timeFmt
= fTimeFormat
.replaceAll(":", fTimeFieldSep
); //$NON-NLS-1$
217 String ssecFmt
= fSSecFormat
.replaceAll("_", fSSecFieldSep
); //$NON-NLS-1$
219 fTimestampPattern
= dateFmt
+ timeFmt
+ "." + ssecFmt
; //$NON-NLS-1$
220 fIntervalPattern
= "TTT." + ssecFmt
; //$NON-NLS-1$
224 setDateTimeFormat(TmfTimePreferences
.TIME_HOUR_FMT
);
225 setSSecFormat(TmfTimePreferences
.SUBSEC_NANO_FMT
);
226 setDateFieldSep(TmfTimePreferences
.DELIMITER_DASH
);
227 setTimeFieldSep(TmfTimePreferences
.DELIMITER_COLON
);
228 setSSecFieldSep(TmfTimePreferences
.DELIMITER_UNDERLINE
);