tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / properties / TmfTimePreferences.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.properties;
14
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;
18
19 /**
20 * TMF Time format preferences
21 *
22 * @author Francois Chouinard
23 * @version 1.0
24 * @since 2.0
25 */
26 @SuppressWarnings("javadoc")
27 public class TmfTimePreferences {
28
29 // ------------------------------------------------------------------------
30 // Constants
31 // ------------------------------------------------------------------------
32
33 public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss.SSS_CCC_NNN"; //$NON-NLS-1$
34
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$
38
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$
42
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$
49
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$
55
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$
60
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$
71
72 // ------------------------------------------------------------------------
73 // Attributes
74 // ------------------------------------------------------------------------
75
76 private static TmfTimePreferences fPreferences;
77
78 private static IPreferenceStore fPreferenceStore;
79 private static String fTimestampPattern;
80 private static String fIntervalPattern;
81
82 private String fDatimeFormat;
83 private String fDateFormat;
84 private String fTimeFormat;
85 private String fSSecFormat;
86
87 private String fDateFieldSep = "-"; //$NON-NLS-1$
88 private String fTimeFieldSep = ":"; //$NON-NLS-1$
89 private String fSSecFieldSep = " "; //$NON-NLS-1$
90
91 // ------------------------------------------------------------------------
92 // Constructor
93 // ------------------------------------------------------------------------
94
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);
102
103 // Create the singleton and initialize format preferences
104 getInstance();
105 }
106
107 public static synchronized IPreferenceStore getPreferenceStore() {
108 if (fPreferenceStore == null) {
109 init();
110 }
111 return fPreferenceStore;
112 }
113
114 public static synchronized TmfTimePreferences getInstance() {
115 if (fPreferences == null) {
116 fPreferences = new TmfTimePreferences();
117 }
118 return fPreferences;
119 }
120
121 /**
122 * Local constructor
123 */
124 private TmfTimePreferences() {
125 initPatterns();
126 setTimePattern(fTimestampPattern);
127 }
128
129 // ------------------------------------------------------------------------
130 // Getters/Setters
131 // ------------------------------------------------------------------------
132
133 /**
134 * @return the timestamp pattern
135 */
136 public static String getTimePattern() {
137 return fTimestampPattern;
138 }
139
140 /**
141 * Sets the timestamp pattern and updates TmfTimestampFormat
142 *
143 * @param timePattern the new timestamp pattern
144 */
145 static void setTimePattern(String timePattern) {
146 fTimestampPattern = timePattern;
147 TmfTimestampFormat.setDefaultTimeFormat(fTimestampPattern);
148 TmfTimestampFormat.setDefaultIntervalFormat(fIntervalPattern);
149 }
150
151 /**
152 * Update the Date field separator
153 * @param pattern the Date field separator
154 */
155 void setDateFieldSep(String pattern) {
156 fDateFieldSep = pattern;
157 }
158
159 /**
160 * Update the Time field separator
161 * @param pattern the Time field separator
162 */
163 void setTimeFieldSep(String pattern) {
164 fTimeFieldSep = pattern;
165 }
166
167 /**
168 * Update the Subseconds field separator
169 * @param pattern the Subseconds field separator
170 */
171 void setSSecFieldSep(String pattern) {
172 fSSecFieldSep = pattern;
173 }
174
175 /**
176 * Update the Date/Time format
177 * @param pattern the Date/Time format
178 */
179 void setDateTimeFormat(String pattern) {
180 fDatimeFormat = pattern;
181 if (fDatimeFormat == null) {
182 fDatimeFormat = DEFAULT_TIME_PATTERN;
183 }
184 int index = fDatimeFormat.indexOf(' ');
185 if (index != -1) {
186 fDateFormat = fDatimeFormat.substring(0, fDatimeFormat.indexOf(' ') + 1);
187 fTimeFormat = fDatimeFormat.substring(fDateFormat.length());
188 } else {
189 fDateFormat = ""; //$NON-NLS-1$
190 fTimeFormat = fDatimeFormat;
191 }
192 }
193
194 /**
195 * Update the Subseconds format
196 * @param pattern the Subseconds format
197 */
198 void setSSecFormat(String pattern) {
199 fSSecFormat = pattern;
200 }
201
202 // ------------------------------------------------------------------------
203 // Operations
204 // ------------------------------------------------------------------------
205
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);
212 updatePatterns();
213 }
214
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$
219
220 fTimestampPattern = dateFmt + timeFmt + "." + ssecFmt; //$NON-NLS-1$
221 fIntervalPattern = "TTT." + ssecFmt; //$NON-NLS-1$
222 }
223
224 void setDefaults() {
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);
230 updatePatterns();
231 }
232
233 }
This page took 0.034642 seconds and 5 git commands to generate.