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:MainClass.java

public MainClass() {
    userPrefs = Preferences.userNodeForPackage(MainClass.class);

    System.out.println(userPrefs.get(NAMEPREF, ""));
    System.out.println(userPrefs.get(EMAILPREF, ""));
    System.out.println(userPrefs.get(AGEPREF, ""));
    System.out.println(userPrefs.get(PHONEPREF, ""));

    userPrefs.put(NAMEPREF, "name");
    userPrefs.put(AGEPREF, "Text");
    userPrefs.put(EMAILPREF, "email");
    userPrefs.put(PHONEPREF, "phone");
    System.out.println("Preferences stored");

    Preferences.userNodeForPackage(MainClass.class).addPreferenceChangeListener(this);
}

From source file:PreferenceExample.java

public void printInformation(Preferences p) throws BackingStoreException {
    System.out.println("Node's absolute path: " + p.absolutePath());

    System.out.print("Node's children: ");
    for (String s : p.childrenNames()) {
        System.out.print(s + " ");
    }//from  ww  w. ja  va 2  s.  c  om
    System.out.println("");

    System.out.print("Node's keys: ");
    for (String s : p.keys()) {
        System.out.print(s + " ");
    }
    System.out.println("");

    System.out.println("Node's name: " + p.name());
    System.out.println("Node's parent: " + p.parent());
    System.out.println("NODE: " + p);
    System.out.println("userNodeForPackage: " + Preferences.userNodeForPackage(PreferenceExample.class));

    System.out.println("All information in node");
    for (String s : p.keys()) {
        System.out.println("  " + s + " = " + p.get(s, ""));
    }
}

From source file:put.semantic.fcanew.preferences.PreferencesProvider.java

protected Preferences getNode() {
    return Preferences.userNodeForPackage(MainWindow.class);
}

From source file:de.nrw.hbz.regal.sync.MyPreferences.java

MyPreferences(Class<?> cl) {
    try {//from   w  ww.ja v a 2  s.c o  m
        Preferences p = Preferences.userNodeForPackage(cl);
        for (String preference : p.keys()) {
            this.addProperty(preference, p.get(preference, null));
        }
    } catch (BackingStoreException e) {
        // empty preferences are ok
    }
}

From source file:net.bican.wordpress.configuration.PreferencesConfiguration.java

/**
 * @param cl Calling class/*from   w  w  w .  java 2  s  .co m*/
 */
public PreferencesConfiguration(Class<?> cl) {
    try {
        Preferences p = Preferences.userNodeForPackage(cl);
        for (String preference : p.keys()) {
            this.addProperty(preference, p.get(preference, null));
        }
    } catch (BackingStoreException e) {
        // then we end up with an empty set of preferences, no big deal
    }
}

From source file:org.shingo.insightdatareshaper.MySQLHelper.java

private void getCredentialsFromSettings() {
    this.prefs = Preferences.userNodeForPackage(MySQLSettingsController.class);
    USERNAME = prefs.get("username", "root");
    HOST = prefs.get("host", "localhost");
    PASSWORD = prefs.get("password", "password");
}

From source file:au.org.ala.delta.editor.EditorPreferences.java

/**
 * @return An array of the most recently used filenames
 *///from  w  w  w  .j  av a2s  . c om
public static String[] getPreviouslyUsedFiles() {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        String mru = prefs.get(MRU_PREF_KEY, "");
        if (!StringUtils.isEmpty(mru)) {
            return mru.split(MRU_SEPARATOR);
        }
    }

    return null;
}

From source file:com.mirth.connect.client.ui.AttachmentExportDialog.java

public AttachmentExportDialog() {
    super(PlatformUI.MIRTH_FRAME);
    userPreferences = Preferences.userNodeForPackage(Mirth.class);

    setTitle("Export Attachment");
    setPreferredSize(new Dimension(500, 155));
    getContentPane().setBackground(Color.white);
    setLocationRelativeTo(null);//from w w w  .  j  av a 2  s.  c  o  m
    setResizable(false);
    setModal(true);

    initComponents();
    initLayout();
    pack();
}

From source file:de.unibayreuth.bayeos.goat.chart.StatusXYPlot.java

/** Creates a new instance of StatusXYPlot */
public StatusXYPlot(XYDataset data, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) {
    super(data, domainAxis, rangeAxis, renderer);
    legendcol = new LegendItemCollection();
    Preferences pref = Preferences.userNodeForPackage(JMainFrame.class);
    addLegendItem("not set", StatusColors.getNullColor());
    addLegendItem("valid", StatusColors.getOkColor());
    addLegendItem("invalid", StatusColors.getInvalidColor());
    addLegendItem("others", StatusColors.getOthersColor());

}

From source file:com.igormaznitsa.sciareto.preferences.PreferencesManager.java

private PreferencesManager() {
    this.prefs = Preferences.userNodeForPackage(PreferencesManager.class);
    String packedUuid = this.prefs.get(PROPERTY_UUID, null);
    if (packedUuid == null) {
        try {//from w  ww.jav a 2 s.  c om
            final UUID newUUID = UUID.randomUUID();
            packedUuid = Base64.encodeBase64String(IOUtils.packData(newUUID.toString().getBytes("UTF-8")));
            this.prefs.put(PROPERTY_UUID, packedUuid);
            this.prefs.flush();
            LOGGER.info("Generated new installation UUID : " + newUUID.toString());

            final Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    LOGGER.info("Send first start metrics");
                    com.igormaznitsa.sciareto.metrics.MetricsService.getInstance().onFirstStart();
                }
            }, "SCIARETO_FIRST_START_METRICS");
            thread.setDaemon(true);
            thread.start();

        } catch (Exception ex) {
            LOGGER.error("Can't generate UUID", ex);
        }
    }
    try {
        this.installationUUID = UUID
                .fromString(new String(IOUtils.unpackData(Base64.decodeBase64(packedUuid)), "UTF-8"));
        LOGGER.info("Installation UUID : " + this.installationUUID.toString());
    } catch (UnsupportedEncodingException ex) {
        LOGGER.error("Can't decode UUID", ex);
        throw new Error("Unexpected error", ex);
    }
}