|
22 | 22 | import org.phoebus.util.time.TimeParser; |
23 | 23 | import org.phoebus.util.time.TimeRelativeInterval; |
24 | 24 |
|
25 | | -/** Helper for reading preference settings |
| 25 | +/** |
| 26 | + * Helper for reading preference settings |
26 | 27 | * |
27 | | - * @author Kay Kasemir |
| 28 | + * @author Kay Kasemir |
28 | 29 | */ |
29 | 30 | @SuppressWarnings("nls") |
30 | | -public class Preferences |
31 | | -{ |
32 | | - /** Preference tags. |
33 | | - * For explanation of the settings see preferences.ini |
| 31 | +public class Preferences { |
| 32 | + /** |
| 33 | + * Preference tags. |
| 34 | + * For explanation of the settings see preferences.ini |
34 | 35 | */ |
35 | | - final private static String |
36 | | - PROMPT_FOR_RAW_DATA = "prompt_for_raw_data_request", |
37 | | - PROMPT_FOR_VISIBILITY = "prompt_for_visibility"; |
| 36 | + final private static String PROMPT_FOR_RAW_DATA = "prompt_for_raw_data_request", |
| 37 | + PROMPT_FOR_VISIBILITY = "prompt_for_visibility"; |
38 | 38 |
|
39 | 39 | /** Predefined time range */ |
40 | | - public static class TimePreset |
41 | | - { |
| 40 | + public static class TimePreset { |
42 | 41 | /** Label */ |
43 | 42 | public final String label; |
44 | 43 | /** Time range */ |
45 | 44 | public final TimeRelativeInterval range; |
46 | 45 |
|
47 | | - TimePreset(final String label, final TimeRelativeInterval range) |
48 | | - { |
| 46 | + TimePreset(final String label, final TimeRelativeInterval range) { |
49 | 47 | this.label = label; |
50 | 48 | this.range = range; |
51 | 49 | } |
52 | 50 | } |
53 | 51 |
|
54 | 52 | /** Setting */ |
55 | | - @Preference public static int archive_fetch_delay; |
| 53 | + @Preference |
| 54 | + public static int archive_fetch_delay; |
56 | 55 | /** Setting */ |
57 | | - @Preference public static int concurrent_requests; |
| 56 | + @Preference |
| 57 | + public static int concurrent_requests; |
58 | 58 | /** Setting */ |
59 | | - @Preference public static ArchiveRescale archive_rescale; |
| 59 | + @Preference |
| 60 | + public static ArchiveRescale archive_rescale; |
60 | 61 | /** Setting */ |
61 | 62 | public static List<ArchiveDataSource> archive_urls; |
62 | 63 | /** Setting */ |
63 | 64 | public static List<ArchiveDataSource> archives; |
64 | 65 | /** Setting */ |
65 | | - @Preference public static boolean automatic_history_refresh; |
| 66 | + @Preference |
| 67 | + public static boolean automatic_history_refresh; |
66 | 68 | /** Setting */ |
67 | | - @Preference public static int live_buffer_size; |
| 69 | + @Preference |
| 70 | + public static int live_buffer_size; |
68 | 71 | /** Setting */ |
69 | | - @Preference public static int line_width; |
| 72 | + @Preference |
| 73 | + public static int line_width; |
70 | 74 | /** Setting */ |
71 | | - @Preference public static int opacity; |
| 75 | + @Preference |
| 76 | + public static int opacity; |
72 | 77 | /** Setting */ |
73 | | - @Preference public static int plot_bins; |
| 78 | + @Preference |
| 79 | + public static int plot_bins; |
74 | 80 | /** Setting */ |
75 | | - @Preference public static double scan_period; |
| 81 | + @Preference |
| 82 | + public static double scan_period; |
76 | 83 | /** Setting */ |
77 | 84 | public static Duration scroll_step; |
78 | 85 | /** Setting */ |
79 | 86 | public static Duration time_span; |
80 | 87 | /** Setting */ |
81 | | - @Preference public static TraceType trace_type; |
| 88 | + @Preference |
| 89 | + public static TraceType trace_type; |
82 | 90 | /** Setting */ |
83 | | - @Preference public static double update_period; |
| 91 | + @Preference |
| 92 | + public static double update_period; |
84 | 93 | /** Setting */ |
85 | | - @Preference public static boolean use_auto_scale; |
| 94 | + @Preference |
| 95 | + public static boolean use_auto_scale; |
86 | 96 | /** Setting */ |
87 | | - @Preference public static boolean use_default_archives; |
| 97 | + @Preference |
| 98 | + public static boolean use_default_archives; |
88 | 99 | /** Setting */ |
89 | | - @Preference public static boolean drop_failed_archives; |
| 100 | + @Preference |
| 101 | + public static boolean drop_failed_archives; |
90 | 102 | /** Setting */ |
91 | 103 | @Deprecated |
92 | | - @Preference public static String[] equivalent_pv_prefixes; |
| 104 | + @Preference |
| 105 | + public static String[] equivalent_pv_prefixes; |
93 | 106 | /** Setting */ |
94 | | - @Preference public static boolean use_trace_names; |
| 107 | + @Preference |
| 108 | + public static boolean use_trace_names; |
95 | 109 | /** Setting */ |
96 | | - @Preference public static boolean prompt_for_raw_data_request; |
| 110 | + @Preference |
| 111 | + public static boolean prompt_for_raw_data_request; |
97 | 112 | /** Setting */ |
98 | | - @Preference public static boolean prompt_for_visibility; |
| 113 | + @Preference |
| 114 | + public static boolean prompt_for_visibility; |
99 | 115 | /** Setting */ |
100 | 116 | public static final List<TimePreset> time_presets = new ArrayList<>(); |
101 | 117 | /** Setting */ |
102 | | - @Preference public static boolean config_dialog_supported; |
| 118 | + @Preference |
| 119 | + public static boolean config_dialog_supported; |
103 | 120 |
|
104 | 121 | @Preference |
105 | 122 | public static boolean assign_pvs_from_clipboard_to_the_same_axis_by_default; |
106 | 123 |
|
107 | | - |
108 | 124 | @Preference |
109 | 125 | public static String value_axis_label_policy; |
110 | 126 |
|
111 | | - |
112 | | - static |
113 | | - { |
114 | | - final PreferencesReader prefs = AnnotatedPreferences.initialize(Activator.class, Preferences.class, "/databrowser_preferences.properties"); |
| 127 | + static { |
| 128 | + final PreferencesReader prefs = AnnotatedPreferences.initialize(Activator.class, Preferences.class, |
| 129 | + "/databrowser_preferences.properties"); |
115 | 130 |
|
116 | 131 | // Allow at least one at a time |
117 | 132 | if (concurrent_requests < 1) |
118 | | - concurrent_requests = 1; |
| 133 | + concurrent_requests = 1; |
119 | 134 |
|
120 | 135 | archive_urls = parseArchives(prefs.get("urls")); |
121 | 136 | archives = parseArchives(prefs.get("archives")); |
122 | 137 |
|
123 | | - scroll_step = Duration.ofSeconds( Math.max(1, prefs.getInt("scroll_step")) ); |
124 | | - time_span = Duration.ofSeconds( Math.round( Math.max(prefs.getDouble("time_span"), 1.0) ) ); |
| 138 | + scroll_step = Duration.ofSeconds(Math.max(1, prefs.getInt("scroll_step"))); |
| 139 | + time_span = Duration.ofSeconds(Math.round(Math.max(prefs.getDouble("time_span"), 1.0))); |
125 | 140 |
|
126 | | - for (String preset : prefs.get("time_span_shortcuts").split("\\|")) |
127 | | - { |
| 141 | + for (String preset : prefs.get("time_span_shortcuts").split("\\|")) { |
128 | 142 | final String[] label_span = preset.split(","); |
129 | | - time_presets.add(new TimePreset(label_span[0], TimeRelativeInterval.startsAt(TimeParser.parseTemporalAmount(label_span[1])))); |
| 143 | + time_presets.add(new TimePreset(label_span[0], |
| 144 | + TimeRelativeInterval.startsAt(TimeParser.parseTemporalAmount(label_span[1])))); |
130 | 145 | } |
131 | 146 | } |
132 | 147 |
|
133 | 148 | /** @param show Display warning regarding raw data? */ |
134 | | - public static void setRawDataPrompt(final boolean show) |
135 | | - { |
| 149 | + public static void setRawDataPrompt(final boolean show) { |
136 | 150 | prompt_for_raw_data_request = show; |
137 | 151 | update(PROMPT_FOR_RAW_DATA, show); |
138 | 152 | } |
139 | 153 |
|
140 | 154 | /** @param show Display warning regarding trace visiblity? */ |
141 | | - public static void setVisibilityPrompt(final boolean show) |
142 | | - { |
| 155 | + public static void setVisibilityPrompt(final boolean show) { |
143 | 156 | prompt_for_visibility = show; |
144 | 157 | update(PROMPT_FOR_VISIBILITY, show); |
145 | 158 | } |
146 | 159 |
|
147 | | - private static void update(final String setting, final boolean value) |
148 | | - { |
| 160 | + private static void update(final String setting, final boolean value) { |
149 | 161 | final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(Activator.class); |
150 | 162 | prefs.putBoolean(setting, value); |
151 | | - try |
152 | | - { |
| 163 | + try { |
153 | 164 | prefs.flush(); |
154 | | - } |
155 | | - catch (Exception ex) |
156 | | - { |
| 165 | + } catch (Exception ex) { |
157 | 166 | Activator.logger.log(Level.WARNING, "Cannot write preferences", ex); |
158 | 167 | } |
159 | 168 | } |
160 | 169 |
|
161 | | - /** @param setting Text with list of archives, separated by 'pipe' symbol |
162 | | - * @return List of parsed data sources |
| 170 | + /** |
| 171 | + * @param setting Text with list of archives, separated by 'pipe' symbol |
| 172 | + * @return List of parsed data sources |
163 | 173 | */ |
164 | | - public static List<ArchiveDataSource> parseArchives(final String setting) |
165 | | - { |
| 174 | + public static List<ArchiveDataSource> parseArchives(final String setting) { |
166 | 175 | final List<ArchiveDataSource> urls = new ArrayList<>(); |
167 | | - for (String fragment : setting.split("\\*")) |
168 | | - { |
169 | | - final String[] strs = fragment.split("\\|"); |
170 | | - if (strs.length == 1) |
171 | | - urls.add(new ArchiveDataSource(strs[0], strs[0])); |
172 | | - else if (strs.length >= 2) |
173 | | - urls.add(new ArchiveDataSource(strs[0], strs[1])); |
| 176 | + //When settings is empty do not search for a archive datasource |
| 177 | + if (setting != null && !setting.trim().isEmpty()) { |
| 178 | + for (String fragment : setting.split("\\*")) { |
| 179 | + final String[] strs = fragment.split("\\|"); |
| 180 | + if (strs.length == 1) |
| 181 | + urls.add(new ArchiveDataSource(strs[0], strs[0])); |
| 182 | + else if (strs.length >= 2) |
| 183 | + urls.add(new ArchiveDataSource(strs[0], strs[1])); |
| 184 | + } |
174 | 185 | } |
175 | 186 | return urls; |
176 | 187 | } |
|
0 commit comments