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