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:au.org.ala.delta.intkey.ui.UIUtils.java

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

    List<Pair<String, String>> existingFiles = getPreviouslyUsedFiles();

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

        Pair<String, String> fileNameTitlePair = existingFiles.get(i);
        String existingFileName = fileNameTitlePair.getFirst();

        if (!existingFileName.equalsIgnoreCase(filename)) {

            if (b.length() > 0) {
                b.append(MRU_FILES_SEPARATOR);
            }
            b.append(fileNameTitlePair.getFirst() + MRU_ITEM_SEPARATOR + fileNameTitlePair.getSecond());
        }
    }

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

}

From source file:edu.umd.cs.findbugs.gui2.GUISaveState.java

public void save() {
    Preferences p = Preferences.userNodeForPackage(GUISaveState.class);

    p.putInt(TAB_SIZE, tabSize);/*from  www.jav  a2s.co m*/

    p.putFloat(FONT_SIZE, fontSize);

    try {
        p.put(STARTERDIRECTORY, starterDirectoryForLoadBugs.getCanonicalPath());
    } catch (IOException e) {
        Debug.println(e);
    }
    int sorterLength = MainFrame.getInstance().getSorter().getColumnCount();
    ArrayList<Sortables> sortables = MainFrame.getInstance().getSorter().getOrder();
    p.putInt(GUISaveState.SORTERTABLELENGTH, sorterLength);

    String[] sorterKeys = GUISaveState.generateSorterKeys(sorterLength);
    for (int x = 0; x < sorterKeys.length; x++) {
        p.put(sorterKeys[x], sortables.get(x).prettyName);
    }

    p.putInt(GUISaveState.PREVCOMMENTSSIZE, previousComments.size());

    for (int x = 0; x < previousComments.size(); x++) {
        String comment = previousComments.get(x);
        p.put(GUISaveState.COMMENTKEYS[x], comment);
    }

    int size = recentFiles.size();
    while (recentFiles.size() > MAXNUMRECENTPROJECTS) {
        recentFiles.remove(0);
    }

    p.putInt(GUISaveState.NUMPROJECTS, Math.min(size, MAXNUMRECENTPROJECTS));
    for (int x = 0; x < Math.min(size, MAXNUMRECENTPROJECTS); x++) {
        File file = recentFiles.get(x);
        p.put(GUISaveState.RECENTPROJECTKEYS[x], file.getAbsolutePath());
    }

    p.putByteArray(DOCKINGLAYOUT, dockingLayout);

    p.put(FRAME_BOUNDS,
            frameBounds.x + "," + frameBounds.y + "," + frameBounds.width + "," + frameBounds.height);
    p.putInt(EXTENDED_WINDOW_STATE, extendedWindowState);

    p.putInt(SPLIT_MAIN, splitMain);
    p.putDouble(SPLIT_SUMMARY_NEW, splitSummary);
    p.putInt(SPLIT_TOP, splitTop);
    p.putInt(SPLIT_TREE_COMMENTS, splitTreeComments);
    p.putInt(PACKAGE_PREFIX_SEGEMENTS, packagePrefixSegments);

    p.put(ENABLED_PLUGINS, StringUtils.join(enabledPlugins, ','));
    p.put(DISABLED_PLUGINS, StringUtils.join(disabledPlugins, ','));
    p.put(CUSTOM_PLUGINS, StringUtils.join(customPlugins, ' '));
}

From source file:gov.bnl.channelfinder.api.ChannelFinderClientImpl.java

@Deprecated
public static void resetPreferences() {
    try {//from   www  . ja  v a  2 s  .c  om
        Preferences.userNodeForPackage(ChannelFinderClientImpl.class).clear();
    } catch (BackingStoreException e) {
        e.printStackTrace();
    }
}

From source file:org.domainmath.gui.MainFrame.java

/** 
 * Creates new form MainFrame.//from w  w w  .  ja  v a 2 s. c o  m
 * @param args
 */
public MainFrame(String args[]) {

    // create folders called cache and log.
    cache = new File(System.getProperty("user.dir") + File.separator + "cache");
    logDir = new File(System.getProperty("user.dir") + File.separator + "log");
    worksDir = new File(System.getProperty("user.dir") + File.separator + "works");
    cache.mkdir();
    logDir.mkdir();

    if (!worksDir.exists()) {
        worksDir.mkdir();
    }

    parent_root = cache.getAbsolutePath() + File.separator;
    log_root = logDir.getAbsolutePath() + File.separator;
    preferencesDlg = new PreferencesDlg(this, true);
    layout_file = new File(System.getProperty("user.dir") + File.separator + "layout.ini");
    initComponents();
    new PackageLoader(this);
    new ToolsLoader(this);
    makeMenu();

    setIconImage(icon);
    Preferences pr2 = Preferences.userNodeForPackage(this.getClass());

    setSize(pr2.getInt("Frame_width", 800), pr2.getInt("Frame_height", 600));
    setLocationRelativeTo(null);

    FILE_TAB_INDEX = 0;

    //create octavepanel.
    octavePanel = new OctavePanel(this);
    commandArea = octavePanel.commandArea;

    octavePath = preferencesDlg.getPath();
    startupCmd = preferencesDlg.getStartupCmd();
    wantedToClearText = preferencesDlg.wantedToClearText();
    cmdLineOptions = preferencesDlg.getCmdLineOptions();

    // set up histroy widget.
    histArea = new RSyntaxTextArea();
    histArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_OCTAVE);
    histScrollPane = new RTextScrollPane(histArea);
    histScrollPane.setWheelScrollingEnabled(true);

    workspace = new WorkspacePanel(parent_root + "DomainMath_OctaveVariables.dat", this);
    dbstackPanel = new DbstackPanel(parent_root + "DomainMath_OctaveDbStack.dat", this);

    // create recent files menu.
    recentFileMenu = new RecentFileMenu("RecentFiles", MAX_NUM_RECENT_FILES) {
        @Override
        public void onSelectFile(String filePath, ActionEvent action_event) {
            onRecentFile(filePath, action_event);
        }
    };
    this.fileMenu.add(recentFileMenu, MainFrame.RECENT_MENU_ORDER);

    statusPanel = new StatusPanel();
    fileTab.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    fileTreePanel = new FileTreePanel(this);
    quickHelpPanel = new QuickHelpPanel();
    pathPanel = new PathsPanel(parent_root + "DomainMath_OctavePaths.dat");
    pkgViewPanel = new PkgViewPanel(parent_root + "DomainMath_OctavePackages.dat", this);

    histPanel();
    this.popupTab();

    dir = pr2.get("DomainMath_StartUpDir", System.getProperty("user.dir"));

    if (dir.equals(worksDir.getAbsolutePath())) {
        startupDir = dir;
    } else {
        startupDir = worksDir.getAbsolutePath();
    }

    currentDirFileTab = null;
    fileTabView = new View("Code Editor", null, fileTab);
    pathsView = new View("Set Paths", null, pathPanel);
    pkgView = new View("Packages", null, pkgViewPanel);
    consoleScrollPane = new JScrollPane();
    consoleScrollPane.getVerticalScrollBar().setUnitIncrement(16);
    consoleScrollPane.setViewportView(octavePanel);
    consoleView = new View("Console", null, consoleScrollPane);
    arrayEditorView = new View("Array Editor", null, new ArrayEditorPanel());
    workspaceView = new View("Workspace", null, workspace);
    debuggerView = new View("Debugger", null, this.dbstackPanel);
    filesView = new View("Files", null, fileTreePanel);
    quickHelpView = new View("Quick Help", null, quickHelpPanel);
    createRootWindow();
    setDefaultLayout();

    add(rootWindow, BorderLayout.CENTER);
    add(statusPanel, BorderLayout.PAGE_END);
    dragNDrop();
    debugMarksList = new ArrayList<>();
    breakPointMarksList = new ArrayList<>();
    breakPointList = new ArrayList<>();
    fileTab2 = fileTab;
    if (args != null) {
        openStartUpFiles(args);
    }

}

From source file:com.mirth.connect.connectors.http.HttpListener.java

public void setResponseHeaders(Map<String, List<String>> responseHeaders) {
    int size = 0;
    for (List<String> property : responseHeaders.values()) {
        size += property.size();/*from   ww w.ja  v  a2 s  . co m*/
    }

    Object[][] tableData = new Object[size][2];

    responseHeadersTable = new MirthTable();

    int j = 0;
    Iterator i = responseHeaders.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        for (String keyValue : (List<String>) entry.getValue()) {
            tableData[j][NAME_COLUMN] = (String) entry.getKey();
            tableData[j][VALUE_COLUMN] = keyValue;
            j++;
        }
    }

    responseHeadersTable.setModel(new javax.swing.table.DefaultTableModel(tableData,
            new String[] { NAME_COLUMN_NAME, VALUE_COLUMN_NAME }) {

        boolean[] canEdit = new boolean[] { true, true };

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
        }
    });

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

        public void valueChanged(ListSelectionEvent evt) {
            if (getSelectedRow(responseHeadersTable) != -1) {
                responseHeadersLastIndex = getSelectedRow(responseHeadersTable);
                responseHeadersDeleteButton.setEnabled(true);
            } else {
                responseHeadersDeleteButton.setEnabled(false);
            }
        }
    });

    class HTTPTableCellEditor extends TextFieldCellEditor {

        boolean checkProperties;

        public HTTPTableCellEditor(boolean checkProperties) {
            super();
            this.checkProperties = checkProperties;
        }

        @Override
        public boolean isCellEditable(EventObject evt) {
            boolean editable = super.isCellEditable(evt);

            if (editable) {
                responseHeadersDeleteButton.setEnabled(false);
            }

            return editable;
        }

        @Override
        protected boolean valueChanged(String value) {
            responseHeadersDeleteButton.setEnabled(true);

            if (checkProperties && (value.length() == 0)) {
                return false;
            }

            parent.setSaveEnabled(true);
            return true;
        }
    }

    responseHeadersTable.getColumnModel()
            .getColumn(responseHeadersTable.getColumnModel().getColumnIndex(NAME_COLUMN_NAME))
            .setCellEditor(new HTTPTableCellEditor(true));
    responseHeadersTable.getColumnModel()
            .getColumn(responseHeadersTable.getColumnModel().getColumnIndex(VALUE_COLUMN_NAME))
            .setCellEditor(new HTTPTableCellEditor(false));
    responseHeadersTable.setCustomEditorControls(true);

    responseHeadersTable.setSelectionMode(0);
    responseHeadersTable.setRowSelectionAllowed(true);
    responseHeadersTable.setRowHeight(UIConstants.ROW_HEIGHT);
    responseHeadersTable.setDragEnabled(false);
    responseHeadersTable.setOpaque(true);
    responseHeadersTable.setSortable(false);
    responseHeadersTable.getTableHeader().setReorderingAllowed(false);

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

    responseHeadersPane.setViewportView(responseHeadersTable);
    responseHeadersDeleteButton.setEnabled(false);
}

From source file:au.org.ala.delta.intkey.ui.UIUtils.java

/**
 * Adds the supplied filename to the top of the most recently used files.
 * /*from   w  w w . ja  v a  2 s.c om*/
 * @param filename
 */
public static void addFileToMRU(String filename, String title, List<Pair<String, String>> existingFiles) {
    // Strip any RTF formatting, and characters used as separators in the MRU text from the title.
    title = RTFUtils.stripFormatting(title);
    title = title.replace(MRU_ITEM_SEPARATOR, " ");
    title = title.replace(MRU_FILES_SEPARATOR, " ");

    Queue<String> q = new LinkedList<String>();

    String newFilePathAndTitle;
    if (StringUtils.isEmpty(title)) {
        newFilePathAndTitle = filename + MRU_ITEM_SEPARATOR + filename;
    } else {
        newFilePathAndTitle = filename + MRU_ITEM_SEPARATOR + title;
    }
    q.add(newFilePathAndTitle);

    if (existingFiles != null) {
        for (Pair<String, String> existingFile : existingFiles) {
            String existingFilePathAndTitle = existingFile.getFirst() + MRU_ITEM_SEPARATOR
                    + existingFile.getSecond();
            if (!q.contains(existingFilePathAndTitle)) {
                q.add(existingFilePathAndTitle);
            }
        }
    }

    StringBuilder b = new StringBuilder();
    for (int i = 0; i < MAX_SIZE_MRU && q.size() > 0; ++i) {
        if (i > 0) {
            b.append(MRU_FILES_SEPARATOR);
        }
        b.append(q.poll());
    }

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

From source file:com.vaadin.testbench.tools.CvalChecker.java

private CvalInfo getCachedLicenseInfo(String productName) {
    Preferences p = Preferences.userNodeForPackage(CvalInfo.class);
    String json = p.get(productName, "");
    if (!json.isEmpty()) {
        CvalInfo info = parseJson(json);
        if (info != null) {
            return info;
        }/*from w w  w.  j a va2  s .com*/
    }
    return null;
}

From source file:speedith.cli.CliOptions.java

/**
 * Returns the spider diagram formula output format that should be used
 * when exporting spider diagrams (to the standard output) in the batch
 * mode.// w w w  .ja v a 2 s . c o  m
 * <p>If the user did not provide an output format, a default is used.</p>
 * <p>If the user <span style="font-weight:bold">did</span> provide an
 * output format, it is stored in the preferences and will be the default
 * henceforth (in all successive application invocations).</p>
 * <p>This method also checks whether the export format actually exists. If
 * the exporter does not exist, this method throws a {@link
 * RuntimeException} with an explanation.</p>
 * @return the output format name (see {@link SDExporting} for more
 * information).
 */
public String getOutputFormat() {
    if (m_cachedOf == null) {
        String outputFormat = getParsedOptions().getOptionValue(OPTION_OF);
        // Check that the format is supported (if any was given,
        // otherwise use a default one).
        if (outputFormat == null) {
            // Use the default output format
            outputFormat = Preferences.userNodeForPackage(Main.class).get(PREF_DEFAULT_OUTPUT_FORMAT,
                    Isabelle2011ExportProvider.FormatName);
        } else {
            Preferences.userNodeForPackage(Main.class).put(PREF_DEFAULT_OUTPUT_FORMAT, outputFormat);
        }
        // Check if the provider is actually supported
        if (SDExporting.getProvider(outputFormat) == null) {
            throw new RuntimeException(i18n("ERR_CLI_UNKNOWN_EXPORT_FORMAT", outputFormat));
        }
        m_cachedOf = outputFormat;
    }
    return m_cachedOf;
}

From source file:au.org.ala.delta.intkey.ui.UIUtils.java

/**
 * @return true if the last time the application was closed, advanced mode
 *         was in use//from  ww w . ja va  2  s  .  c o  m
 */
public static boolean getPreviousApplicationMode() {
    Preferences prefs = Preferences.userNodeForPackage(Intkey.class);
    if (prefs != null) {
        String previouslyUsedMode = prefs.get(MODE_PREF_KEY, "");
        if (!StringUtils.isEmpty(previouslyUsedMode)) {
            return previouslyUsedMode.equals(ADVANCED_MODE_PREF_VALUE);
        }
    }
    return false;
}

From source file:reaper.model.Project.java

public String projectPath() {
    Preferences prefs = Preferences.userNodeForPackage(Reaper.class);
    String path = prefs.get(PreferenceKeys.GALLERY_PATH.getKey(),
            (String) PreferenceKeys.GALLERY_PATH.getKey());
    if (!path.endsWith("/")) {
        path += "/";
    }/*from  ww  w  .  ja v a 2s . c  om*/
    path += name + "/";
    return path;
}