Example usage for java.util.prefs Preferences userRoot

List of usage examples for java.util.prefs Preferences userRoot

Introduction

In this page you can find the example usage for java.util.prefs Preferences userRoot.

Prototype

public static Preferences userRoot() 

Source Link

Document

Returns the root preference node for the calling user.

Usage

From source file:org.pdfsam.module.PreferencesUsageDataStoreTest.java

@Test
public void multipleClear() {
    victim.incrementUsageFor("moduleId");
    victim.clear();/*  w  ww . ja v a2s .c  o m*/
    victim.incrementUsageFor("moduleId");
    victim.clear();
    assertTrue(isBlank(Preferences.userRoot().node(PreferencesUsageDataStore.USAGE_PATH).node("moduleId")
            .get(PreferencesUsageDataStore.MODULE_USAGE_KEY, "")));
}

From source file:org.pdfsam.ui.StatefullPreferencesStageService.java

public Instant getLatestNewsStageDisplayInstant() {
    return Instant.ofEpochMilli(Preferences.userRoot().node(STAGE_PATH).getLong(NEWS_STAGE_DISPLAY_TIME_KEY,
            Instant.EPOCH.toEpochMilli()));
}

From source file:com.maxl.java.amikodesk.Emailer.java

public Emailer(String l, String p) {
    m_el = l;/*from   w ww .  ja v a 2s . com*/
    m_ep = p;
    m_map_of_attachments = new TreeMap<String, String>();
    m_prefs = Preferences.userRoot().node(SettingsPage.class.getName());
}

From source file:org.pdfsam.ui.PreferencesRecentWorkspacesServiceTest.java

@Test
public void flush() throws IOException, BackingStoreException {
    victim.addWorkspaceLastUsed(folder.newFile());
    victim.flush();//from www .j a  v a 2  s  .  co m
    assertTrue(Preferences.userRoot().node(WORKSPACES_PATH).keys().length > 0);
}

From source file:org.pdfsam.module.PreferencesUsageDataStore.java

public void clear() {
    Preferences prefs = Preferences.userRoot().node(USAGE_PATH);
    try {//from  ww w.ja  v  a 2s .  c  o  m
        prefs.removeNode();
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Unable to clear modules usage statistics", e);
    }
}

From source file:org.kuali.test.ui.components.dialogs.EmailDlg.java

/**
 *
 * @return/*from   w w  w.j av  a 2  s .  co  m*/
 */
@Override
protected boolean save() {
    boolean retval = false;
    boolean oktosave = true;
    if (StringUtils.isNotBlank(mailHost.getText()) && StringUtils.isNotBlank(subject.getText())
            && StringUtils.isNotBlank(fromAddress.getText()) && StringUtils.isNotBlank(toAddresses.getText())) {
    } else {
        displayRequiredFieldsMissingAlert("Email Setup", "mail host, subject, from address, to addreses");
        oktosave = false;
    }

    if (oktosave) {
        emailSetup.setMailHost(mailHost.getText());
        emailSetup.setSubject(subject.getText());
        emailSetup.setFromAddress(fromAddress.getText());
        emailSetup.setToAddresses(toAddresses.getText());

        Preferences proot = Preferences.userRoot();
        Preferences node = proot.node(Constants.PREFS_ROOT_NODE);
        node.put(Constants.LOCAL_RUN_EMAIL, localRunAddress.getText());

        try {
            node.flush();
        } catch (BackingStoreException ex) {
            LOG.warn(ex.toString(), ex);
        }

        setSaved(true);
        getConfiguration().setModified(true);
        dispose();
        retval = true;
    }

    return retval;
}

From source file:com.maxl.java.amikodesk.Emailer.java

public Emailer(String subject) {
    m_subject = subject;//from www  . j a  v a 2  s. co  m
    m_map_of_attachments = new TreeMap<String, String>();
    m_prefs = Preferences.userRoot().node(SettingsPage.class.getName());
}

From source file:org.pdfsam.ui.PreferencesRecentWorkspacesService.java

@Override
public void clear() {
    Preferences prefs = Preferences.userRoot().node(WORKSPACES_PATH);
    cache.clear();//from  w w  w.j  ava2s .  c o m
    try {
        prefs.removeNode();
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Unable to clear recently used workspaces", e);
    }
}

From source file:org.pdfsam.module.PreferencesUsageDataStore.java

private void incrementTotalUsage() {
    Preferences node = Preferences.userRoot().node(USAGE_PATH);
    node.putLong(TASKS_EXECUTED_KEY, node.getLong(TASKS_EXECUTED_KEY, 0) + 1);
}

From source file:de.scoopgmbh.copper.monitoring.client.context.ApplicationContext.java

public ApplicationContext() {
    mainStackPane = new StackPane();
    mainPane = new BorderPane();
    mainPane.setId("background");//important for css
    mainStackPane.getChildren().add(mainPane);
    messageProvider = new MessageProvider(ResourceBundle.getBundle("de.scoopgmbh.copper.gui.message"));

    final Preferences prefs = Preferences.userRoot().node("de.scoopgmbh.coppermonitor");

    SettingsModel defaultSettings = new SettingsModel();
    AuditralColorMapping newItem = new AuditralColorMapping();
    newItem.color.setValue(Color.rgb(255, 128, 128));
    newItem.loglevelRegEx.setValue("1");
    defaultSettings.auditralColorMappings.add(newItem);
    byte[] defaultModelbytes;
    ByteArrayOutputStream os = null;
    try {/*from w  ww.  j a  v  a2  s .  c  om*/
        os = new ByteArrayOutputStream();
        ObjectOutputStream o = new ObjectOutputStream(os);
        o.writeObject(defaultSettings);
        defaultModelbytes = os.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

    settingsModelSingleton = defaultSettings;
    ByteArrayInputStream is = null;
    try {
        is = new ByteArrayInputStream(prefs.getByteArray(SETTINGS_KEY, defaultModelbytes));
        ObjectInputStream o = new ObjectInputStream(is);
        Object object = o.readObject();
        if (object instanceof SettingsModel) {
            settingsModelSingleton = (SettingsModel) object;
        }
    } catch (Exception e) {
        logger.error("", e);
        getIssueReporterSingleton()
                .reportWarning("Can't load settings from (Preferences: " + prefs + ") use defaults instead", e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            ByteArrayOutputStream os = null;
            try {
                os = new ByteArrayOutputStream();
                ObjectOutputStream o = new ObjectOutputStream(os);
                o.writeObject(settingsModelSingleton);
                prefs.putByteArray(SETTINGS_KEY, os.toByteArray());
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                if (os != null) {
                    try {
                        os.close();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }));
}