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:se.trixon.jota.client.ClientOptions.java

private ClientOptions() {
    mPreferences = Preferences.userNodeForPackage(this.getClass());
}

From source file:net.sourceforge.metware.binche.loader.OfficialChEBIOboLoader.java

/**
 * The constructor loads the OBO file from the ChEBI ftp and executes the reasoning steps.
 *
 * @throws IOException/*from  ww w . j a  v a  2s  . c  om*/
 * @throws BackingStoreException
 */
public OfficialChEBIOboLoader() throws IOException, BackingStoreException {
    Preferences binchePrefs = Preferences.userNodeForPackage(BiNChe.class);

    if (binchePrefs.keys().length == 0) {
        binchePrefs = (new DefaultPreferenceSetter()).getDefaultSetPrefs();
    }

    PreProcessOboFile ppof = new PreProcessOboFile();
    File tmpFileObo = File.createTempFile("BiNChE", ".obo");
    FileUtils.copyURLToFile(new URL(oboURL), tmpFileObo);
    ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(),
            binchePrefs.get(BiNChEOntologyPrefs.RoleOntology.name(), null), false, true,
            BiNChEOntologyPrefs.RoleOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label"),
            new ArrayList<String>());
    File tmpRoleOnt = new File(binchePrefs.get(BiNChEOntologyPrefs.RoleOntology.name(), null) + ".temp");
    tmpRoleOnt.delete();

    ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(),
            binchePrefs.get(BiNChEOntologyPrefs.StructureOntology.name(), null), false, false,
            BiNChEOntologyPrefs.StructureOntology.getRootChEBIEntries(), Arrays.asList("rdfs:label", "InChI"),
            new ArrayList<String>());
    File tmpStructOnt = new File(binchePrefs.get(BiNChEOntologyPrefs.StructureOntology.name(), null) + ".temp");
    tmpStructOnt.delete();

    ppof.getTransitiveClosure(tmpFileObo.getAbsolutePath(),
            binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null), true, true,
            BiNChEOntologyPrefs.RoleAndStructOntology.getRootChEBIEntries(),
            Arrays.asList("rdfs:label", "InChI"), Arrays.asList("http://purl.obolibrary.org/obo/RO_0000087"));
    File tmpStructRoleOnt = new File(
            binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null) + ".temp");
    tmpStructRoleOnt.delete();
    File structRoleAnnot = new File(
            binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null).replace(".obo", ".txt"));
    String fullPath = binchePrefs.get(BiNChEOntologyPrefs.RoleAndStructOntology.name(), null);
    structRoleAnnot.renameTo(new File(
            fullPath.substring(0, fullPath.lastIndexOf(File.separator)) + File.separator + "chebi_roles.anno"));

    tmpFileObo.delete();
}

From source file:com.cyberninjas.xerobillableexpenses.util.Settings.java

public Settings() {
    try {//from  w ww  .  j a v a 2 s  .c o m
        String parentClass = new Exception().getStackTrace()[1].getClassName();
        this.prefs = Preferences.userNodeForPackage(Class.forName(parentClass));
        Random r = new SecureRandom();

        //Set IV
        this.iv = prefs.getByteArray("DRUGS", null);

        //Pick Random PWD
        byte[] b = new byte[128];
        r.nextBytes(b);
        MessageDigest sha = MessageDigest.getInstance("SHA-1");
        sha.update(b);
        String sHash = new String(Base64.encodeBase64(sha.digest()));

        String password = prefs.get("LAYOUT", sHash);
        if (password.equals(sHash))
            prefs.put("LAYOUT", sHash);

        //Keep 'em Guessing
        r.nextBytes(b);
        sha.update(b);
        prefs.put("PASSWORD", new String(Base64.encodeBase64(sha.digest())));

        //Set Random Salt
        byte[] tSalt = new byte[8];
        r.nextBytes(tSalt);
        byte[] salt = prefs.getByteArray("HIMALAYAN", tSalt);
        if (Arrays.equals(salt, tSalt))
            prefs.putByteArray("HIMALAYAN", salt);

        /* Derive the key, given password and salt. */
        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 128);
        SecretKey tmp = factory.generateSecret(spec);
        this.secret = new SecretKeySpec(tmp.getEncoded(), "AES");

        cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(RSAx509CertGen.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvalidKeySpecException ex) {
        Logger.getLogger(RSAx509CertGen.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(RSAx509CertGen.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.docwhat.iated.AppState.java

private AppState() {
    store = Preferences.userNodeForPackage(this.getClass());
}

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

/**
 * Construct and show the application./*from  w  w  w  . ja v a  2s.  c o m*/
 */
public Mirth(Client mirthClient) throws ClientException {
    PlatformUI.MIRTH_FRAME = new Frame();

    UIManager.put("Tree.leafIcon", UIConstants.LEAF_ICON);
    UIManager.put("Tree.openIcon", UIConstants.OPEN_ICON);
    UIManager.put("Tree.closedIcon", UIConstants.CLOSED_ICON);

    userPreferences = Preferences.userNodeForPackage(Mirth.class);
    LoginPanel.getInstance().setStatus("Loading components...");
    PlatformUI.MIRTH_FRAME.setupFrame(mirthClient);

    boolean maximized;
    int width;
    int height;

    if (SystemUtils.IS_OS_MAC) {
        /*
         * The window is only maximized when there is no width or height preference saved.
         * Previously, we just set the dimensions on mac and didn't bother with the maximized
         * state because the user could maximize the window then manually resize it, leaving the
         * maximum state as true. As of MIRTH-3691, this no longer happens.
         */
        maximized = (userPreferences.get("width", null) == null || userPreferences.get("height", null) == null)
                || (userPreferences.getInt("maximizedState", Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH);

        width = userPreferences.getInt("width", UIConstants.MIRTH_WIDTH);
        height = userPreferences.getInt("height", UIConstants.MIRTH_WIDTH);
    } else {
        /*
         * Maximize it if it's supposed to be maximized or if there is no maximized preference
         * saved. Unmaximizing will bring the window back to default size.
         */
        maximized = (userPreferences.getInt("maximizedState", Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH);

        if (maximized) {
            // If it is maximized, use the default width and height for unmaximizing
            width = UIConstants.MIRTH_WIDTH;
            height = UIConstants.MIRTH_HEIGHT;
        } else {
            // If it's not maximized, get the saved width and height
            width = userPreferences.getInt("width", UIConstants.MIRTH_WIDTH);
            height = userPreferences.getInt("height", UIConstants.MIRTH_HEIGHT);
        }
    }

    // Now set the width and height (saved or default)
    PlatformUI.MIRTH_FRAME.setSize(width, height);
    PlatformUI.MIRTH_FRAME.setLocationRelativeTo(null);

    if (maximized) {
        PlatformUI.MIRTH_FRAME.setExtendedState(Frame.MAXIMIZED_BOTH);
    }

    PlatformUI.MIRTH_FRAME.setVisible(true);
}

From source file:ome.formats.utests.IniFileLoaderTest.java

@BeforeMethod
public void setUp() throws Exception {
    temporaryFile = TempFileManager.create_path("initest");
    System.err.println("Temporary file: " + temporaryFile.getAbsolutePath());
    ini = new IniFileLoader(null);
    maps = Preferences.userNodeForPackage(getClass());
}

From source file:ch.astina.hesperid.installer.web.services.InstallationManager.java

public String getApplicationHomeDirectoryPath() {
    Preferences prefs = Preferences.userNodeForPackage(InstallationManager.class);

    String installDir = prefs.get(HOME_DIRECTORY, null);

    return installDir;
}

From source file:org.micromanager.CRISP.CRISPFrame.java

/** Creates new form CRISPFrame */
public CRISPFrame(ScriptInterface gui) {
    gui_ = gui;// w  w w .j  av a 2  s.  c om
    core_ = gui.getMMCore();
    prefs_ = Preferences.userNodeForPackage(this.getClass());
    CRISP_ = "";

    mmcorej.StrVector afs = core_.getLoadedDevicesOfType(DeviceType.AutoFocusDevice);
    boolean found = false;
    for (String af : afs) {
        try {
            if (core_.hasProperty(af, "Description")) {
                if (core_.getProperty(af, "Description").equals("ASI CRISP Autofocus adapter")) {
                    found = true;
                    CRISP_ = af;
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(CRISPFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (!found) {
        gui_.showError("This plugin needs the ASI CRISP Autofcous");
        throw new IllegalArgumentException("This plugin needs at least one camera");
    }

    frameXPos_ = prefs_.getInt(FRAMEXPOS, frameXPos_);
    frameYPos_ = prefs_.getInt(FRAMEYPOS, frameYPos_);

    initComponents();

    setLocation(frameXPos_, frameYPos_);

    setBackground(gui_.getBackgroundColor());
    gui_.addMMBackgroundListener(this);

    updateValues();
}

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

/**
 * Removes the specified file from the most recently used file list
 * @param filename The filename to remove
 *///from ww w.j  a  va  2  s.  c  om
public static void removeFileFromMRU(String filename) {

    String[] existingFiles = getPreviouslyUsedFiles();

    StringBuilder b = new StringBuilder();
    for (int i = 0; i < existingFiles.length; ++i) {

        if (!existingFiles[i].equalsIgnoreCase(filename)) {

            if (b.length() > 0) {
                b.append(MRU_SEPARATOR);
            }
            b.append(existingFiles[i]);
        }
    }

    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    prefs.put(MRU_PREF_KEY, b.toString());
    try {
        prefs.sync();
    } catch (BackingStoreException e) {
        throw new RuntimeException(e);
    }

}

From source file:net.chaosserver.timelord.swingui.AnnoyTimeDialog.java

/**
 * Constructs a annoy time dialog for setting the dialog.
 *
 * @param applicationFrame the parent frame
 *//*from w w w. j  av  a 2s .  c  om*/
public AnnoyTimeDialog(JFrame applicationFrame) {
    super(applicationFrame, "Set Day Start Time", true);

    JPanel annoyTimePanel = new JPanel();

    minuteSlider = new JSlider(0, 60);
    minuteSlider.setMajorTickSpacing(15);
    minuteSlider.setMinorTickSpacing(3);
    minuteSlider.setPaintLabels(true);
    minuteSlider.setPaintTicks(true);
    minuteSlider.setSnapToTicks(true);

    Preferences preferences = Preferences.userNodeForPackage(Timelord.class);

    double timeIncrement = preferences.getDouble(Timelord.TIME_INCREMENT, 0.25);

    if (log.isDebugEnabled()) {
        log.debug("Loaded Time Increment Preference [" + timeIncrement + "] from preference ["
                + Timelord.TIME_INCREMENT + "]");
    }

    minuteSlider.setValue((int) (timeIncrement * 60));

    annoyTimePanel.add(minuteSlider);

    JButton okayButton = new JButton(
            resourceBundle.getString("net.chaosserver.timelord.swingui.TimelordMenu.okay"));
    okayButton.setActionCommand(ACTION_OK);
    okayButton.addActionListener(this);
    annoyTimePanel.add(okayButton);

    JButton cancelButton = new JButton(
            resourceBundle.getString("net.chaosserver.timelord.swingui.TimelordMenu.cancel"));
    cancelButton.setActionCommand(ACTION_CANCEL);
    cancelButton.addActionListener(this);
    annoyTimePanel.add(cancelButton);

    this.getContentPane().add(annoyTimePanel);
    this.pack();

    this.setLocationRelativeTo(applicationFrame);
}