Skip to content

Commit 4ef6f00

Browse files
committed
Update Prefs usage to PrefService
All Contextual classes that used the Prefs static utility class should now be using PrefService.
1 parent 9f210a7 commit 4ef6f00

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

src/main/java/org/scijava/io/DefaultRecentFileService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
import org.scijava.module.ModuleService;
4949
import org.scijava.plugin.Parameter;
5050
import org.scijava.plugin.Plugin;
51+
import org.scijava.preferences.PrefService;
5152
import org.scijava.service.AbstractService;
5253
import org.scijava.service.Service;
5354
import org.scijava.util.FileUtils;
54-
import org.scijava.util.Prefs;
5555

5656
// TODO - DefaultRecentFileService, DefaultWindowService, and DefaultLUTService
5757
// all build menus dynamically (see createInfo()). We may be able to abstract a
@@ -98,6 +98,9 @@ public final class DefaultRecentFileService extends AbstractService implements
9898
@Parameter
9999
private CommandService commandService;
100100

101+
@Parameter
102+
private PrefService prefService;
103+
101104
private List<String> recentFiles;
102105
private Map<String, ModuleInfo> recentModules;
103106

@@ -112,7 +115,7 @@ public void add(final String path) {
112115
recentFiles.add(path);
113116

114117
// persist the updated list
115-
Prefs.putList(recentFiles, RECENT_FILES_KEY);
118+
prefService.putList(recentFiles, RECENT_FILES_KEY);
116119

117120
if (present) {
118121
// path already present; update linked module info
@@ -136,7 +139,7 @@ public boolean remove(final String path) {
136139
final boolean success = recentFiles.remove(path);
137140

138141
// persist the updated list
139-
Prefs.putList(recentFiles, RECENT_FILES_KEY);
142+
prefService.putList(recentFiles, RECENT_FILES_KEY);
140143

141144
// remove linked module info
142145
final ModuleInfo info = recentModules.remove(path);
@@ -148,7 +151,7 @@ public boolean remove(final String path) {
148151
@Override
149152
public void clear() {
150153
recentFiles.clear();
151-
Prefs.clear(RECENT_FILES_KEY);
154+
prefService.clear(RECENT_FILES_KEY);
152155

153156
// unregister the modules with the module service
154157
moduleService.removeModules(recentModules.values());
@@ -165,7 +168,7 @@ public List<String> getRecentFiles() {
165168

166169
@Override
167170
public void initialize() {
168-
recentFiles = Prefs.getList(RECENT_FILES_KEY);
171+
recentFiles = prefService.getList(RECENT_FILES_KEY);
169172
recentModules = new HashMap<String, ModuleInfo>();
170173
for (final String path : recentFiles) {
171174
recentModules.put(path, createInfo(path));

src/main/java/org/scijava/options/OptionsPlugin.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.scijava.options.event.OptionsEvent;
3838
import org.scijava.plugin.Parameter;
3939
import org.scijava.plugin.SingletonPlugin;
40-
import org.scijava.util.Prefs;
40+
import org.scijava.preferences.PrefService;
4141

4242
// TODO - outline for how to address issues with options (initializing, aggregating into 1 dialog)
4343

@@ -77,6 +77,9 @@ public class OptionsPlugin extends DynamicCommand implements SingletonPlugin {
7777
@Parameter
7878
protected EventService eventService;
7979

80+
@Parameter
81+
private PrefService prefService;
82+
8083
// -- OptionsPlugin methods --
8184

8285
/** Loads option values from persistent storage. */
@@ -95,7 +98,7 @@ public void save() {
9598

9699
/** Clears option values from persistent storage. */
97100
public void reset() {
98-
Prefs.clear(getClass());
101+
prefService.clear(getClass());
99102
}
100103

101104
// -- Runnable methods --

src/main/java/org/scijava/ui/AbstractUserInterface.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
import org.scijava.plugin.Parameter;
4343
import org.scijava.plugin.PluginInfo;
4444
import org.scijava.plugin.PluginService;
45+
import org.scijava.preferences.PrefService;
4546
import org.scijava.thread.ThreadService;
4647
import org.scijava.ui.viewer.DisplayViewer;
4748
import org.scijava.ui.viewer.DisplayWindow;
48-
import org.scijava.util.Prefs;
4949

5050
/**
5151
* Abstract superclass for {@link UserInterface} implementations.
@@ -80,6 +80,9 @@ public abstract class AbstractUserInterface extends AbstractRichPlugin
8080
@Parameter
8181
private UIService uiService;
8282

83+
@Parameter
84+
private PrefService prefService;
85+
8386
/** Whether the UI is currently being displayed. */
8487
private boolean visible = false;
8588

@@ -181,17 +184,17 @@ public StatusBar getStatusBar() {
181184
public void saveLocation() {
182185
final ApplicationFrame appFrame = getApplicationFrame();
183186
if (appFrame != null) {
184-
Prefs.put(getClass(), LAST_X, appFrame.getLocationX());
185-
Prefs.put(getClass(), LAST_Y, appFrame.getLocationY());
187+
prefService.put(getClass(), LAST_X, appFrame.getLocationX());
188+
prefService.put(getClass(), LAST_Y, appFrame.getLocationY());
186189
}
187190
}
188191

189192
@Override
190193
public void restoreLocation() {
191194
final ApplicationFrame appFrame = getApplicationFrame();
192195
if (appFrame != null) {
193-
final int lastX = Prefs.getInt(getClass(), LAST_X, 0);
194-
final int lastY = Prefs.getInt(getClass(), LAST_Y, 0);
196+
final int lastX = prefService.getInt(getClass(), LAST_X, 0);
197+
final int lastY = prefService.getInt(getClass(), LAST_Y, 0);
195198
appFrame.setLocation(lastX, lastY);
196199
}
197200
}

src/main/java/org/scijava/welcome/DefaultWelcomeService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
import org.scijava.log.LogService;
4343
import org.scijava.plugin.Parameter;
4444
import org.scijava.plugin.Plugin;
45+
import org.scijava.preferences.PrefService;
4546
import org.scijava.service.AbstractService;
4647
import org.scijava.service.Service;
4748
import org.scijava.text.TextService;
4849
import org.scijava.ui.event.UIShownEvent;
4950
import org.scijava.util.DigestUtils;
50-
import org.scijava.util.Prefs;
5151
import org.scijava.welcome.event.WelcomeEvent;
5252

5353
/**
@@ -82,6 +82,9 @@ public class DefaultWelcomeService extends AbstractService implements
8282
@Parameter
8383
private EventService eventService;
8484

85+
@Parameter
86+
private PrefService prefService;
87+
8588
// -- ReadmeService methods --
8689

8790
@Override
@@ -96,9 +99,9 @@ private void displayWelcome(final boolean force) {
9699
if (welcomeFile.exists()) {
97100
final String welcomeText = textService.asHTML(welcomeFile);
98101
final String checksum = DigestUtils.bestHex(welcomeText);
99-
final String previousChecksum = Prefs.get(getClass(), CHECKSUM_PREFS_KEY);
102+
final String previousChecksum = prefService.get(getClass(), CHECKSUM_PREFS_KEY);
100103
if (!force && checksum.equals(previousChecksum)) return;
101-
Prefs.put(getClass(), CHECKSUM_PREFS_KEY, checksum);
104+
prefService.put(getClass(), CHECKSUM_PREFS_KEY, checksum);
102105
displayService.createDisplay(welcomeText);
103106
}
104107
}
@@ -109,13 +112,13 @@ private void displayWelcome(final boolean force) {
109112

110113
@Override
111114
public boolean isFirstRun() {
112-
final String firstRun = Prefs.get(getClass(), firstRunPrefKey());
115+
final String firstRun = prefService.get(getClass(), firstRunPrefKey());
113116
return firstRun == null || Boolean.parseBoolean(firstRun);
114117
}
115118

116119
@Override
117120
public void setFirstRun(final boolean firstRun) {
118-
Prefs.put(getClass(), firstRunPrefKey(), firstRun);
121+
prefService.put(getClass(), firstRunPrefKey(), firstRun);
119122
}
120123

121124
// -- Event handlers --

0 commit comments

Comments
 (0)