use of java.util.prefs.Preferences in project jgnash by ccavanaugh.
the class ImportMt940FxAction method showAndWait.
static void showAndWait() {
final ResourceBundle resources = ResourceUtils.getBundle();
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine == null || engine.getRootAccount().getChildCount() == 0) {
jgnash.ui.StaticUIMethods.displayError(resources.getString("Message.Error.CreateBasicAccounts"));
return;
}
final FileChooser fileChooser = configureFileChooser();
fileChooser.setTitle(resources.getString("Title.SelFile"));
final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
if (file != null) {
Preferences pref = Preferences.userNodeForPackage(ImportMt940FxAction.class);
pref.put(LAST_DIR, file.getParentFile().getAbsolutePath());
new Thread(new ImportTask(file)).start();
}
}
use of java.util.prefs.Preferences in project jgnash by ccavanaugh.
the class ImportMt940FxAction method configureFileChooser.
private static FileChooser configureFileChooser() {
final Preferences pref = Preferences.userNodeForPackage(ImportMt940FxAction.class);
final FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(pref.get(LAST_DIR, System.getProperty("user.home"))));
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("All Files (*.*)", "*.*"));
return fileChooser;
}
use of java.util.prefs.Preferences in project JMRI by JMRI.
the class JmriPreferencesProviderTest method testGetPreferences.
/**
* Test of getPreferences method, of class JmriPreferencesProvider.
* @throws java.io.IOException
*/
public void testGetPreferences() throws IOException {
String id = Long.toString((new Date()).getTime());
Profile project = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
Class<?> clazz = this.getClass();
Preferences shared = JmriPreferencesProvider.getPreferences(project, clazz, true);
Preferences privat = JmriPreferencesProvider.getPreferences(project, clazz, false);
assertNotNull(shared);
assertNotNull(privat);
assertNotSame(shared, privat);
try {
assertEquals(shared.keys().length, 0);
} catch (BackingStoreException ex) {
assertNotNull(ex);
}
try {
assertEquals(privat.keys().length, 0);
} catch (BackingStoreException ex) {
assertNotNull(ex);
}
FileUtil.delete(project.getPath());
}
use of java.util.prefs.Preferences in project JMRI by JMRI.
the class JmriPreferencesProviderTest method testIsFirstUse.
/**
* Test of isFirstUse method, of class JmriPreferencesProvider.
* @throws java.io.IOException
*/
public void testIsFirstUse() throws IOException {
String id = Long.toString((new Date()).getTime());
Profile project = new Profile(this.getName(), id, new File(this.workspace.toFile(), id));
JmriPreferencesProvider shared = JmriPreferencesProvider.findProvider(project.getPath(), true);
assertEquals(shared.isFirstUse(), true);
Preferences prefs = shared.getPreferences(this.getClass());
prefs.put("test", "test");
try {
// force write
prefs.flush();
} catch (BackingStoreException ex) {
assertNull(ex);
}
shared = new JmriPreferencesProvider(project.getPath(), true);
assertEquals(shared.isFirstUse(), false);
}
use of java.util.prefs.Preferences in project JMRI by JMRI.
the class RosterConfigManager method initialize.
@Override
public void initialize(Profile profile) throws InitializationException {
if (!this.isInitialized(profile)) {
Preferences preferences = ProfileUtils.getPreferences(profile, this.getClass(), true);
this.setDefaultOwner(preferences.get(DEFAULT_OWNER, this.getDefaultOwner()));
try {
this.setDirectory(preferences.get(DIRECTORY, this.getDirectory()));
} catch (IllegalArgumentException ex) {
this.setInitialized(profile, true);
throw new InitializationException(Bundle.getMessage(Locale.ENGLISH, "IllegalRosterLocation", preferences.get(DIRECTORY, this.getDirectory())), ex.getMessage(), ex);
}
Roster.getDefault().setRosterLocation(this.getDirectory());
this.setInitialized(profile, true);
}
}
Aggregations