Search in sources :

Example 96 with Preferences

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();
    }
}
Also used : FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) File(java.io.File) Engine(jgnash.engine.Engine)

Example 97 with Preferences

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;
}
Also used : FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 98 with Preferences

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());
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences) File(java.io.File) Date(java.util.Date) Profile(jmri.profile.Profile)

Example 99 with Preferences

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);
}
Also used : BackingStoreException(java.util.prefs.BackingStoreException) Preferences(java.util.prefs.Preferences) File(java.io.File) Date(java.util.Date) Profile(jmri.profile.Profile)

Example 100 with Preferences

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);
    }
}
Also used : FileLocationsPreferences(jmri.implementation.FileLocationsPreferences) Preferences(java.util.prefs.Preferences) InitializationException(jmri.util.prefs.InitializationException)

Aggregations

Preferences (java.util.prefs.Preferences)291 BackingStoreException (java.util.prefs.BackingStoreException)49 File (java.io.File)45 ResourceBundle (java.util.ResourceBundle)24 FileChooser (javafx.stage.FileChooser)21 ArrayList (java.util.ArrayList)17 FXML (javafx.fxml.FXML)16 IOException (java.io.IOException)14 JFileChooser (javax.swing.JFileChooser)12 List (java.util.List)8 SwingWorker (javax.swing.SwingWorker)8 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)7 Engine (jgnash.engine.Engine)7 AutoCompletePreferences (org.jabref.logic.autocompleter.AutoCompletePreferences)6 FieldContentParserPreferences (org.jabref.logic.bibtex.FieldContentParserPreferences)6 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)6 BibtexKeyPatternPreferences (org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)6 CleanupPreferences (org.jabref.logic.cleanup.CleanupPreferences)6 ImportFormatPreferences (org.jabref.logic.importer.ImportFormatPreferences)6 JournalAbbreviationPreferences (org.jabref.logic.journals.JournalAbbreviationPreferences)6