Example usage for java.util.prefs Preferences userNodeForPackage

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

Introduction

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

Prototype

public static Preferences userNodeForPackage(Class<?> c) 

Source Link

Document

Returns the preference node from the calling user's preference tree that is associated (by convention) with the specified class's package.

Usage

From source file:codeswarm.repository.svn.SVNHistory.java

/**
 * clears the entire revision cache./*from   w w w . ja  va  2  s .  c  o  m*/
 */
public static void clearCache() {
    try {
        Preferences.userNodeForPackage(SVNHistory.class).clear();
    } catch (BackingStoreException ex) {
        logger.error(null, ex);
    }
}

From source file:se.trixon.jota.server.ServerOptions.java

private ServerOptions() {
    mPreferences = Preferences.userNodeForPackage(this.getClass());
    try {//  w w  w .  j a  va2 s  .com
        mSpeedDials = getSpeedDials();
    } catch (BackingStoreException ex) {
        Logger.getLogger(ServerOptions.class.getName()).log(Level.SEVERE, null, ex);
        mSpeedDials = new HashMap<>();
    }
}

From source file:hr.fer.zemris.vhdllab.platform.ui.command.WelcomeCommand.java

@Override
protected void doExecuteCommand() {
    Preferences pref = Preferences.userNodeForPackage(WelcomeCommand.class);
    int count = pref.getInt(PREF_WELCOME_DIALOG_SHOW_COUNT, 0);

    if (count < 10) {
        showWelcomeDialog();//from   ww  w.j a v a  2 s . co m
        showUpdateJavaDialog();

        pref.putInt(PREF_WELCOME_DIALOG_SHOW_COUNT, count + 1);
    }
}

From source file:com.vaadin.tools.ReportUsage.java

public static void report() {
    long currentTimeMillis = System.currentTimeMillis();
    Preferences prefs = Preferences.userNodeForPackage(ReportUsage.class);
    String lastPing = prefs.get(LAST_PING, "0");
    if (lastPing != null) {
        try {/*w ww.ja  va2s.  c o m*/
            long lastPingTime = Long.parseLong(lastPing);
            if (currentTimeMillis < lastPingTime + ONE_DAY) {
                return;
            }
        } catch (NumberFormatException e) {
            // error parsing last ping time, ignore and ping
        }
    }

    StringBuilder url = new StringBuilder(QUERY_URL);
    url.append(V_QPARAM);
    url.append(Version.getFullVersion());
    url.append(ID_QPARAM);
    url.append(ANONYMOUS_ID).append(R_QPARAM);

    // TODO add more relevant entry point if feasible
    String entryPoint = COMPILER;

    if (entryPoint != null) {
        url.append(E_QPARAM).append(entryPoint);
    }

    doHttpGet(makeUserAgent(), url.toString());

    prefs.put(LAST_PING, String.valueOf(currentTimeMillis));
}

From source file:de.tbuchloh.kiskis.KisKis.java

/**
 * @throws KisKisException/*from  www  .  j  a v a 2s .  c o  m*/
 *             exports the preferences
 */
public static void exportPreferences() throws KisKisException {
    try {
        LOG.info("exporting preferences to " + KisKis.PREF_FILE);
        Preferences.userNodeForPackage(KisKis.class).exportSubtree(new FileOutputStream(KisKis.PREF_FILE));
    } catch (final Exception e) {
        throw new KisKisException(e.getMessage(), e);
    }
}

From source file:org.intermine.modelviewer.store.MineManagerBackingStore.java

/**
 * Create a new instance of MineManagerBackingStore.
 */
protected MineManagerBackingStore() {
    prefs = Preferences.userNodeForPackage(IntermineModelViewer.class);
}

From source file:verdandi.ui.action.ImportPluginAction.java

/**
 * Ask the import file from the user//  w  w  w  .  j  a va  2s .  com
 */
private File getFile() {
    File res = null;
    Preferences prefs = Preferences.userNodeForPackage(getClass());
    File importDir = new File(prefs.get(KEY_CWD, System.getProperty("user.home")));

    JFileChooser chooser = new JFileChooser(importDir);
    chooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".jar") || f.isDirectory();
        }

        @Override
        public String getDescription() {
            return RC.getString("pluginimportaction.filechooser.jarfilter.description");
        }
    });

    chooser.setDialogTitle(RC.getString("pluginimportaction.filechooser.title"));
    chooser.setMultiSelectionEnabled(false);

    if (chooser.showOpenDialog(parent) != JFileChooser.APPROVE_OPTION) {
        LOG.debug("User cancelled");
        return null;
    }
    res = chooser.getSelectedFile();

    prefs.put("import.dir", res.getParent());
    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Cannot write export file preference", e);
    }

    return res;
}

From source file:abfab3d.param.editor.URIEditor.java

public URIEditor(Parameter param) {
    super(param);

    m_textField = new TextField(EDITOR_SIZE);
    Object val = m_param.getValue();
    String sval = "";
    if (val != null) {
        sval = val.toString();
    }/*from  w  w  w .  ja  v a  2 s.  c  om*/
    m_textField.setText(sval);
    m_textField.addActionListener(this);

    m_open = new JButton("Open");
    m_open.setToolTipText("Open File");

    panel = new JPanel(new FlowLayout());
    panel.add(m_open);
    panel.add(m_textField);

    String user_dir = System.getProperty("user.dir");

    Preferences prefs = Preferences.userNodeForPackage(URIEditor.class);

    String last_dir = prefs.get(LASTDIR_PROPERTY, null);
    String dir;

    if (last_dir != null)
        dir = last_dir;
    else
        dir = user_dir;

    fc = new JFileChooser(dir);

    m_open.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int returnVal = fc.showDialog(parent, "Open File");
            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File file = fc.getSelectedFile();

                String dir = file.getPath();

                int idx = dir.lastIndexOf(File.separator);

                if (idx > 0) {
                    dir = dir.substring(0, idx);

                    Preferences prefs = Preferences.userNodeForPackage(URIEditor.class);

                    prefs.put(LASTDIR_PROPERTY, dir);
                }

                m_param.setValue(file.getAbsolutePath());
                informParamChangedListeners();
            }

        }
    });
}

From source file:de.rkl.tools.tzconv.configuration.PreferencesProvider.java

@SuppressWarnings("unused")
public PreferencesProvider() {
    applicationPreferences = Preferences.userNodeForPackage(PreferencesProvider.class);
}

From source file:net.lmxm.ute.preferences.AbstractPreferences.java

/**
 * Instantiates a new abstract preferences.
 * /*w w w. j  a v  a  2  s .c  om*/
 * @param userNode the user node
 */
public AbstractPreferences(final Class<?> userNode) {
    preferences = Preferences.userNodeForPackage(userNode);
}