Skip to content

Commit 9450512

Browse files
committed
2 parents 96b4c58 + 236ad5e commit 9450512

File tree

1 file changed

+76
-65
lines changed
  • app/databrowser/src/main/java/org/csstudio/trends/databrowser3/preferences

1 file changed

+76
-65
lines changed

app/databrowser/src/main/java/org/csstudio/trends/databrowser3/preferences/Preferences.java

Lines changed: 76 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,155 +22,166 @@
2222
import org.phoebus.util.time.TimeParser;
2323
import org.phoebus.util.time.TimeRelativeInterval;
2424

25-
/** Helper for reading preference settings
25+
/**
26+
* Helper for reading preference settings
2627
*
27-
* @author Kay Kasemir
28+
* @author Kay Kasemir
2829
*/
2930
@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
3435
*/
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";
3838

3939
/** Predefined time range */
40-
public static class TimePreset
41-
{
40+
public static class TimePreset {
4241
/** Label */
4342
public final String label;
4443
/** Time range */
4544
public final TimeRelativeInterval range;
4645

47-
TimePreset(final String label, final TimeRelativeInterval range)
48-
{
46+
TimePreset(final String label, final TimeRelativeInterval range) {
4947
this.label = label;
5048
this.range = range;
5149
}
5250
}
5351

5452
/** Setting */
55-
@Preference public static int archive_fetch_delay;
53+
@Preference
54+
public static int archive_fetch_delay;
5655
/** Setting */
57-
@Preference public static int concurrent_requests;
56+
@Preference
57+
public static int concurrent_requests;
5858
/** Setting */
59-
@Preference public static ArchiveRescale archive_rescale;
59+
@Preference
60+
public static ArchiveRescale archive_rescale;
6061
/** Setting */
6162
public static List<ArchiveDataSource> archive_urls;
6263
/** Setting */
6364
public static List<ArchiveDataSource> archives;
6465
/** Setting */
65-
@Preference public static boolean automatic_history_refresh;
66+
@Preference
67+
public static boolean automatic_history_refresh;
6668
/** Setting */
67-
@Preference public static int live_buffer_size;
69+
@Preference
70+
public static int live_buffer_size;
6871
/** Setting */
69-
@Preference public static int line_width;
72+
@Preference
73+
public static int line_width;
7074
/** Setting */
71-
@Preference public static int opacity;
75+
@Preference
76+
public static int opacity;
7277
/** Setting */
73-
@Preference public static int plot_bins;
78+
@Preference
79+
public static int plot_bins;
7480
/** Setting */
75-
@Preference public static double scan_period;
81+
@Preference
82+
public static double scan_period;
7683
/** Setting */
7784
public static Duration scroll_step;
7885
/** Setting */
7986
public static Duration time_span;
8087
/** Setting */
81-
@Preference public static TraceType trace_type;
88+
@Preference
89+
public static TraceType trace_type;
8290
/** Setting */
83-
@Preference public static double update_period;
91+
@Preference
92+
public static double update_period;
8493
/** Setting */
85-
@Preference public static boolean use_auto_scale;
94+
@Preference
95+
public static boolean use_auto_scale;
8696
/** Setting */
87-
@Preference public static boolean use_default_archives;
97+
@Preference
98+
public static boolean use_default_archives;
8899
/** Setting */
89-
@Preference public static boolean drop_failed_archives;
100+
@Preference
101+
public static boolean drop_failed_archives;
90102
/** Setting */
91103
@Deprecated
92-
@Preference public static String[] equivalent_pv_prefixes;
104+
@Preference
105+
public static String[] equivalent_pv_prefixes;
93106
/** Setting */
94-
@Preference public static boolean use_trace_names;
107+
@Preference
108+
public static boolean use_trace_names;
95109
/** Setting */
96-
@Preference public static boolean prompt_for_raw_data_request;
110+
@Preference
111+
public static boolean prompt_for_raw_data_request;
97112
/** Setting */
98-
@Preference public static boolean prompt_for_visibility;
113+
@Preference
114+
public static boolean prompt_for_visibility;
99115
/** Setting */
100116
public static final List<TimePreset> time_presets = new ArrayList<>();
101117
/** Setting */
102-
@Preference public static boolean config_dialog_supported;
118+
@Preference
119+
public static boolean config_dialog_supported;
103120

104121
@Preference
105122
public static boolean assign_pvs_from_clipboard_to_the_same_axis_by_default;
106123

107-
108124
@Preference
109125
public static String value_axis_label_policy;
110126

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");
115130

116131
// Allow at least one at a time
117132
if (concurrent_requests < 1)
118-
concurrent_requests = 1;
133+
concurrent_requests = 1;
119134

120135
archive_urls = parseArchives(prefs.get("urls"));
121136
archives = parseArchives(prefs.get("archives"));
122137

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)));
125140

126-
for (String preset : prefs.get("time_span_shortcuts").split("\\|"))
127-
{
141+
for (String preset : prefs.get("time_span_shortcuts").split("\\|")) {
128142
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]))));
130145
}
131146
}
132147

133148
/** @param show Display warning regarding raw data? */
134-
public static void setRawDataPrompt(final boolean show)
135-
{
149+
public static void setRawDataPrompt(final boolean show) {
136150
prompt_for_raw_data_request = show;
137151
update(PROMPT_FOR_RAW_DATA, show);
138152
}
139153

140154
/** @param show Display warning regarding trace visiblity? */
141-
public static void setVisibilityPrompt(final boolean show)
142-
{
155+
public static void setVisibilityPrompt(final boolean show) {
143156
prompt_for_visibility = show;
144157
update(PROMPT_FOR_VISIBILITY, show);
145158
}
146159

147-
private static void update(final String setting, final boolean value)
148-
{
160+
private static void update(final String setting, final boolean value) {
149161
final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(Activator.class);
150162
prefs.putBoolean(setting, value);
151-
try
152-
{
163+
try {
153164
prefs.flush();
154-
}
155-
catch (Exception ex)
156-
{
165+
} catch (Exception ex) {
157166
Activator.logger.log(Level.WARNING, "Cannot write preferences", ex);
158167
}
159168
}
160169

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
163173
*/
164-
public static List<ArchiveDataSource> parseArchives(final String setting)
165-
{
174+
public static List<ArchiveDataSource> parseArchives(final String setting) {
166175
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+
}
174185
}
175186
return urls;
176187
}

0 commit comments

Comments
 (0)