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:com.vaadin.integration.maven.wscdn.CvalChecker.java

static void cacheLicenseInfo(CvalInfo info) {
    if (info != null) {
        Preferences p = Preferences.userNodeForPackage(CvalInfo.class);
        if (info.toString().length() > Preferences.MAX_VALUE_LENGTH) {
            // This should never happen since MAX_VALUE_LENGTH is big
            // enough.
            // But server could eventually send a very big message, so we
            // discard it in cache and would use hard-coded messages.
            info.setMessage(null);//from  w ww .  j a v  a  2 s.c om
        }
        p.put(info.getProduct().getName(), info.toString());
    }
}

From source file:com.mirth.connect.connectors.jdbc.DatabaseMetadataDialog.java

/**
 * Makes the alert table with a parameter that is true if a new alert should be added as well.
 *///www  . j a v  a 2s . c o  m
public void makeIncludedMetaDataTable(Set<Table> metaData) {
    updateIncludedMetaDataTable(metaData);

    includedMetaDataTable.setDragEnabled(false);
    includedMetaDataTable.setRowSelectionAllowed(false);
    includedMetaDataTable.setRowHeight(UIConstants.ROW_HEIGHT);
    includedMetaDataTable.setFocusable(false);
    includedMetaDataTable.setOpaque(true);
    includedMetaDataTable.getTableHeader().setReorderingAllowed(false);
    includedMetaDataTable.setSortable(false);

    includedMetaDataTable.getColumnExt(INCLUDED_STATUS_COLUMN_NAME).setMaxWidth(50);
    includedMetaDataTable.getColumnExt(INCLUDED_STATUS_COLUMN_NAME).setMinWidth(50);
    includedMetaDataTable.getColumnExt(INCLUDED_TYPE_COLUMN_NAME).setVisible(false);
    includedMetaDataTable.getColumnExt(INCLUDED_TYPE_COLUMN_NAME).setMinWidth(5);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        includedMetaDataTable.setHighlighters(highlighter);
    }

    includedMetaDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
        }
    });

    includedMetaDataPane.setViewportView(includedMetaDataTable);

    // Mouse listener for trigger-button popup on the table.
    includedMetaDataTable.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mousePressed(java.awt.event.MouseEvent evt) {
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
            checkTableNameSelected(evt);
        }
    });

}

From source file:org.broad.igv.DirectoryManager.java

public static File getIgvDirectory() {

    if (IGV_DIRECTORY == null) {

        // Hack for known Java / Windows bug.   Attempt to remvoe (possible) read-only bit from user directory
        if (System.getProperty("os.name").startsWith("Windows")) {
            try {
                Runtime.getRuntime().exec("attrib -r \"" + getUserDirectory().getAbsolutePath() + "\"");
            } catch (Exception e) {
                // We tried
            }/* w  ww .j  av  a 2s  .  co  m*/
        }

        IGV_DIRECTORY = getIgvDirectoryOverride();

        // If still null, try the default place
        if (IGV_DIRECTORY == null) {
            File rootDir = getUserHome();
            IGV_DIRECTORY = new File(rootDir, "igv");

            if (!IGV_DIRECTORY.exists()) {
                // See if a pre-2.1 release directory exists, if so copy it
                File legacyDirectory = null;
                try {
                    legacyDirectory = getLegacyIGVDirectory();
                    if (legacyDirectory.exists()) {
                        log.info("Copying " + legacyDirectory + " => " + IGV_DIRECTORY);
                        FileUtils.copyDirectory(legacyDirectory, IGV_DIRECTORY);
                    }
                } catch (IOException e) {
                    log.error("Error copying igv directory " + legacyDirectory + " => " + IGV_DIRECTORY, e);
                }
            }

            if (!IGV_DIRECTORY.exists()) {
                try {
                    boolean wasSuccessful = IGV_DIRECTORY.mkdir();
                    if (!wasSuccessful) {
                        System.err.println("Failed to create user directory!");
                        IGV_DIRECTORY = null;
                    }
                } catch (Exception e) {
                    log.error("Error creating igv directory", e);
                }
            }
        }

        // The IGV directory either doesn't exist or isn't writeable.  This situation can arise with Windows Vista
        // and Windows 7 due to a Java bug (http://bugs.sun.com/view_bug.do?bug_id=4787931)
        if (IGV_DIRECTORY == null || !IGV_DIRECTORY.exists() || !canWrite(IGV_DIRECTORY)) {
            if (Globals.isHeadless() || Globals.isSuppressMessages()) {
                System.err.println("Cannot write to igv directory: " + IGV_DIRECTORY.getAbsolutePath());
                IGV_DIRECTORY = (new File(".")).getParentFile();
            } else {
                int option = JOptionPane.showConfirmDialog(null,
                        "<html>The default IGV directory (" + IGV_DIRECTORY + ") "
                                + "cannot be accessed.  Click Yes to choose a new folder or No to exit.<br>"
                                + "This folder will be used to create the 'igv' directory",
                        "IGV Directory Error", JOptionPane.YES_NO_OPTION);

                if (option == JOptionPane.YES_OPTION) {
                    File parentDirectory = FileDialogUtils
                            .chooseDirectory("Select a location for the igv directory", null);
                    if (parentDirectory != null) {
                        IGV_DIRECTORY = new File(parentDirectory, "igv");
                        IGV_DIRECTORY.mkdir();
                        Preferences prefs = Preferences.userNodeForPackage(Globals.class);
                        prefs.put(IGV_DIR_USERPREF, IGV_DIRECTORY.getAbsolutePath());
                    }
                }
            }
        }

        if (IGV_DIRECTORY == null || !IGV_DIRECTORY.canRead()) {
            throw new DataLoadException("Cannot read from user directory", IGV_DIRECTORY.getAbsolutePath());
        } else if (!canWrite(IGV_DIRECTORY)) {
            throw new DataLoadException("Cannot write to user directory", IGV_DIRECTORY.getAbsolutePath());
        }

        log.info("IGV Directory: " + IGV_DIRECTORY.getAbsolutePath());
    }
    return IGV_DIRECTORY;
}

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

public static void setPreferredLookAndFeel(String lookAndFeelName) {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        prefs.put(LOOK_AND_FEEL_KEY, lookAndFeelName);
    }//from ww  w  .j a  v  a 2  s  .  c om
}

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

private void initInboundReplacementTable() {
    inboundReplacementTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    DefaultTableModel model = new DefaultTableModel(new Object[][] {},
            new String[] { "Replace All", "Replace With" }) {
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
        }//from  w w  w.  j ava  2  s .  c om

        @Override
        public void setValueAt(Object value, int row, int column) {
            if (!value.equals(getValueAt(row, column))) {
                parent.setSaveEnabled(true);
            }

            super.setValueAt(value, row, column);
        }
    };

    inboundReplacementTable.setSortable(false);
    inboundReplacementTable.getTableHeader().setReorderingAllowed(false);
    inboundReplacementTable.setModel(model);

    inboundReplacementTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            inboundDeleteButton.setEnabled(inboundReplacementTable.getSelectedRow() != -1);
        }
    });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        inboundReplacementTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    inboundDeleteButton.setEnabled(false);
}

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

public static String getPreferredLookAndFeel() {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        return prefs.get(LOOK_AND_FEEL_KEY, DEFAULT_LOOK_AND_FEEL);
    }/*w  w w .  java 2 s . com*/
    return DEFAULT_LOOK_AND_FEEL;
}

From source file:de.tbuchloh.kiskis.util.Settings.java

public static Preferences initPreferences() {
    final Preferences n = Preferences.userNodeForPackage(Settings.class);
    final String newVersion = BuildProperties.getVersion();
    final String previousVersion = n.get(K_PROGRAM_VERSION, newVersion);

    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("oldVersion=%1$s, newVersion=%2$s", previousVersion, newVersion));
    }/*from www  .ja  va  2  s  .  c o  m*/

    if (!VersionTools.isCompatible(previousVersion, newVersion)) {
        LOG.debug("Versions not compatible! Recreating preference node for version=" + newVersion);
        try {
            n.removeNode();
        } catch (final BackingStoreException e) {
            LOG.error("Could not remove preference node", e);
        }

        final Preferences newN = Preferences.userNodeForPackage(Settings.class);
        newN.put(K_PROGRAM_VERSION, newVersion);
        return newN;
    }

    LOG.debug("Preferences seem to be compatible");
    return n;
}

From source file:com.mirth.connect.client.ui.alert.AlertActionPane.java

private void makeActionTable() {
    actionTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    actionTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    actionTable.getColumnExt(PROTOCOL_COLUMN_NAME).setCellEditor(new MirthComboBoxTableCellEditor(actionTable,
            protocols.keySet().toArray(), 1, false, new ActionListener() {

                @Override/*from  w w w. j a  v  a  2s . c o m*/
                public void actionPerformed(ActionEvent e) {
                    JComboBox comboBox = (JComboBox) e.getSource();
                    if (comboBox.isPopupVisible()) {
                        PlatformUI.MIRTH_FRAME.setSaveEnabled(true);
                    }
                }

            }));

    actionTable.getColumnExt(PROTOCOL_COLUMN_NAME)
            .setCellRenderer(new MirthComboBoxTableCellRenderer(protocols.keySet().toArray()));

    actionTable.getColumnExt(RECIPIENT_COLUMN_INDEX).setCellRenderer(new RecipientCellRenderer());

    actionTable.getColumnExt(RECIPIENT_COLUMN_NAME).setCellEditor(new RecipientCellEditor());

    actionTable.setRowHeight(UIConstants.ROW_HEIGHT);
    actionTable.setSortable(false);
    actionTable.setOpaque(true);
    actionTable.setDragEnabled(false);
    actionTable.getTableHeader().setReorderingAllowed(false);
    actionTable.setShowGrid(true, true);
    actionTable.setAutoCreateColumnsFromModel(false);

    actionTable.getColumnExt(PROTOCOL_COLUMN_NAME).setMaxWidth(PROTOCOL_COLUMN_WIDTH);
    actionTable.getColumnExt(PROTOCOL_COLUMN_NAME).setMinWidth(PROTOCOL_COLUMN_WIDTH);
    actionTable.getColumnExt(PROTOCOL_COLUMN_NAME).setResizable(false);

    actionTable.getColumnExt(RECIPIENT_COLUMN_NAME).setMinWidth(UIConstants.MIN_WIDTH);
    actionTable.getColumnExt(RECIPIENT_COLUMN_NAME).setResizable(false);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        actionTable.setHighlighters(highlighter);
    }
}

From source file:verdandi.ui.settings.DefaultSettingsPanel.java

public void storePrefs() {
    Preferences prefs = Preferences.userNodeForPackage(DurationFormatter.class);

    if (radioFormatHHQuarters.isSelected()) {
        prefs.putInt(DurationFormatter.PREF_DISPLAY_MODE, DurationFormatter.DISPLAY_DURATION_HH_QUARTER);
    } else if (radioFormatHHMM.isSelected()) {
        prefs.putInt(DurationFormatter.PREF_DISPLAY_MODE, DurationFormatter.DISPLAY_DURATION_HHMM);
    }//  w  w  w  .  java2s.c  o  m

    try {
        prefs.flush();
    } catch (BackingStoreException e) {
        LOG.error("Cannot store Prefs: ", e);
    }
    conf.setStorePasswd(storePasswordCheckBox.isSelected());
    conf.setShowTimerOnStartup(showTimerOnStartupCheckBox.isSelected());

    for (Entry<String, JTextField> pt : persistenceFields.entrySet()) {
        conf.setConfigProperty(pt.getKey(), pt.getValue().getText());
    }

    conf.setConfigProperty(AnnotatedWorkRecordView.PREF_RESTORE_ON_INIT,
            Boolean.toString(initAnnotatedWorkRecordsOnStartup.isSelected()));

    workDaySettingsPanel.commit();

}

From source file:com.vaadin.integration.maven.wscdn.CvalChecker.java

static void deleteCache(String productName) {
    Preferences p = Preferences.userNodeForPackage(CvalInfo.class);
    p.remove(productName);
}