Package java.util.prefs

Examples of java.util.prefs.Preferences


        if (Platform.getType() != Platform.MacOSX) {
            addSeparator();
            add(new ExitMenuItem(frame));
        }
        // Update the "recent files" submenu when preferences change:
        Preferences prefs;
        prefs = Application.getPreferences();
        prefs.addPreferenceChangeListener(this);
    }
View Full Code Here


        );
    }

    public void dispose() {
        super.dispose();
        Preferences prefs = Application.getPreferences();
        prefs.removePreferenceChangeListener(this);
    }
View Full Code Here

        );
    }

    private static boolean askConfirmQuit(ComboFrame frame) {
        String ConfirmQuitKey = "ConfirmQuit";
        Preferences prefs = getPreferences();
        boolean ask = prefs.getBoolean(ConfirmQuitKey, true);
        int option = 0;
        if (ask) {
            String alwaysPrompt = LOCALE.get("ConfirmQuitAlwaysPrompt");
            JCheckBox alwaysCheck = new JCheckBox(alwaysPrompt);

            Box message = Box.createVerticalBox();
            message.add(new JLabel(LOCALE.get("ConfirmQuitQuestion")));
            message.add(alwaysCheck);

            option = JOptionPane.showOptionDialog(
                frame,
                message,
                "Quit LightZone",
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                new Object[] {
                    LOCALE.get("ConfirmQuitConfirmOption"),
                    LOCALE.get("ConfirmQuitCancelOption")
                },
                LOCALE.get("ConfirmQuitConfirmOption")
            );
            if (option == 0) {
                if (alwaysCheck.isSelected()) {
                    prefs.putBoolean(ConfirmQuitKey, false);
                }
            }
        }
        return (option == 0);
    }
View Full Code Here

    static SaveOptions getSaveOptions(Document doc) {
        SaveOptions options = doc.getSaveOptions();
        if (options == null) {
            ImageMetadata meta = doc.getMetadata();

            Preferences prefs = getPreferences();
            boolean byOriginal = prefs.getBoolean("SaveByOriginal", true);
            File dir;
            if (byOriginal || LastSaveOptions == null) {
                dir = meta.getFile().getParentFile();
            }
            else {
View Full Code Here

    }

    private final static String FirstLaunchTag = "FirstLaunch";

    private static void showFirstTimeHelp() {
        Preferences prefs = getPreferences();
        if (prefs.getBoolean(FirstLaunchTag, true)) {
            Env.showHelpTopic(HelpConstants.HELP_DISCOVER);
            prefs.putBoolean(FirstLaunchTag, false);
        }
        if (VideoLearningCenterDialog.shouldShowDialog()) {
            VideoLearningCenterDialog.showDialog();
        }
    }
View Full Code Here

    private final static String ExportTag = "Export";
    private final static String FrameBoundsTag = "Bounds";
    private final static String FrameStateTag = "State";

    private static void savePrefs() {
        Preferences prefs = getPreferences();

        ComboFrame active = getActiveFrame();
        if (active != null) {
            Rectangle bounds = active.getUnmaximizedBounds();
            if (bounds != null) {
                prefs.putInt(FrameBoundsTag + "X", bounds.x);
                prefs.putInt(FrameBoundsTag + "Y", bounds.y);
                prefs.putInt(FrameBoundsTag + "W", bounds.width);
                prefs.putInt(FrameBoundsTag + "H", bounds.height);
            }
            int state = active.getExtendedState();
            prefs.putInt(FrameStateTag, state);
        }
        int n;
        n = 0;
        String key;
        for (File file : RecentFiles) {
            key = RecentFileTag + n;
            String value = file.getAbsolutePath();
            prefs.put(key, value);
            n++;
        }
        // Clear out old recent-docs entries:
        key = RecentFileTag + n++;
        while (prefs.get(key, null) != null) {
            prefs.remove(key);
            key = RecentFileTag + n++;
        }
        n = 0;
        for (File file : RecentFolders) {
            key = RecentFolderTag + n;
            String value = file.getAbsolutePath();
            prefs.put(key, value);
            n++;
        }
        // Clear out old recent-directories entries:
        key = RecentFolderTag + n++;
        while (prefs.get(key, null) != null) {
            prefs.remove(key);
            key = RecentFolderTag + n++;
        }
        // needed: application events
        // (document open, document close, document change)
        // The "windows" menu is relying on static references for updates,
        // and while the set of current documents should be persisted in prefs,
        // a prefs change does not equal a document change, e.g. a new document
        // that has never been saved (image import).
        n = 0;
        for (ComboFrame frame : Current) {
            Document doc = frame.getDocument();
            if (doc == null) {
                continue;
            }
            File file = doc.getFile();
            key = CurrentTag + n;
            if (file != null) {
                String value = file.getAbsolutePath();
                prefs.put(key, value);
                n++;
            }
        }
        // Clear out old current-docs entries:
        key = CurrentTag + n++;
        while (prefs.get(key, null) != null) {
            prefs.remove(key);
            key = CurrentTag + n++;
        }
        if (LastOpenPath != null) {
            String path = LastOpenPath.getAbsolutePath();
            prefs.put(OpenTag, path);
        }
        if (LastSaveOptions != null) {
            // We're remembering the whole SaveOptions object, but
            // SaveOptions.getDefaultSaveOptions() is the authoritative
            // reposity for sticky options.  The LastSaveOptions is only
            // used to remember the recent folder.
            XmlDocument doc = new XmlDocument(SaveTag);
            LastSaveOptions.save(doc.getRoot());
            saveXmlPrefs(SaveTag, doc);
        }
        if (LastPrintLayout != null) {
            XmlDocument doc = new XmlDocument(PrintTag);
            LastPrintLayout.save(doc.getRoot());
            saveXmlPrefs(PrintTag, doc);
        }
        if (LastExportOptions != null) {
            XmlDocument doc = new XmlDocument(ExportTag);
            LastExportOptions.write(doc.getRoot());
            saveXmlPrefs(ExportTag, doc);
        }
        try {
            prefs.sync();
        }
        catch (BackingStoreException e) {
            showError(LOCALE.get("PrefsWriteError"), e, null);
        }
    }
View Full Code Here

            showError(LOCALE.get("PrefsWriteError"), e, null);
        }
    }

    private static boolean saveXmlPrefs(String tag, XmlDocument doc) {
        Preferences prefs = getPreferences();
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            doc.write(out);
            String text = out.toString("UTF-8");
            prefs.put(tag, text);
            return true;
        }
        catch (IOException e) {
            System.err.print("Error saving preferences: ");
            System.err.print(e.getClass().getName() + " ");
View Full Code Here

            return false;
        }
    }

    private static void restorePrefs() {
        Preferences prefs = getPreferences();
        try {
            // Restore default frame bounds:
            int x = prefs.getInt(FrameBoundsTag + "X", - Integer.MAX_VALUE);
            int y = prefs.getInt(FrameBoundsTag + "Y", - Integer.MAX_VALUE);
            int w = prefs.getInt(FrameBoundsTag + "W", -1);
            int h = prefs.getInt(FrameBoundsTag + "H", -1);
            if ((x > - Integer.MAX_VALUE) &&
                (y > - Integer.MAX_VALUE) &&
                (w > 0) &&
                (h > 0))
            {
                InitialFrameBounds = new Rectangle(x, y, w, h);
            }
            int state = prefs.getInt(FrameStateTag, Frame.NORMAL);
            if (state != Frame.ICONIFIED) {
                InitialFrameState = state;
            }
            else {
                InitialFrameState = Frame.NORMAL;
            }
            // Restore the RecentFile list:
            String[] keys = prefs.keys();
            Map<Integer, File> recentMap = new HashMap<Integer, File>();
            for (String key : keys) {
                if (key.startsWith(RecentFileTag)) {
                    String indexString = key.substring(RecentFileTag.length());
                    try {
                        Integer index = Integer.decode(indexString);
                        String value = prefs.get(key, null);
                        File file = new File(value);
                        recentMap.put(index, file);
                    }
                    catch (NumberFormatException e) {
                        // Bad recent-file pref, just drop it.
                    }
                }
            }
            for (int n=recentMap.size()-1; n>=0; n--) {
                File file = recentMap.get(n);
                if (file != null) {
                    addToRecentFiles(file);
                }
            }
            // Restore the RecentFolder list:
            keys = prefs.keys();
            recentMap = new HashMap<Integer, File>();
            for (String key : keys) {
                if (key.startsWith(RecentFolderTag)) {
                    String indexString =
                        key.substring(RecentFolderTag.length());
                    try {
                        Integer index = Integer.decode(indexString);
                        String value = prefs.get(key, null);
                        File file = new File(value);
                        recentMap.put(index, file);
                    }
                    catch (NumberFormatException e) {
                        // Bad recent-file pref, just drop it.
                    }
                }
            }
            for (int n=recentMap.size()-1; n>=0; n--) {
                File file = recentMap.get(n);
                if (file != null) {
                    addToRecentFolders(file);
                }
            }
            // Restore the last open path:
            String path;
            path = prefs.get(OpenTag, null);
            if (path != null) {
                LastOpenPath = new File(path);
            }
            // Restore default save options:
            XmlDocument doc;
View Full Code Here

            showError(LOCALE.get("PrefsReadError"), e, null);
        }
    }

    private static XmlDocument restoreXmlPrefs(String tag) {
        Preferences prefs = getPreferences();
        String text = prefs.get(tag, null);
        if (text != null) {
            try {
                InputStream in = new ByteArrayInputStream(
                    text.getBytes("UTF-8")
                );
                XmlDocument doc = new XmlDocument(in);
                return doc;
            }
            catch (Exception e) {   // IOException, XMLException
                System.err.print("Error reading preferences: ");
                System.err.print(e.getClass().getName() + " ");
                System.err.println(e.getMessage());
                prefs.remove(tag);
            }
        }
        return null;
    }
View Full Code Here

                    }
                    else {
                        options = Application.getSaveOptions(doc);
                    }
                }
                Preferences prefs = Preferences.userRoot().node(
                    "/com/lightcrafts/app"
                );
                boolean autoSave = prefs.getBoolean("AutoSave", true);
                if (autoSave) {
                    doc.setSaveOptions(options);
                    result = Application.save(this) ?
                        SaveResult.Saved : SaveResult.CouldntSave;
                }
                else {
                    JLabel prompt = new JLabel(
                        LOCALE.get(
                            "AutoSaveQuestion", options.getFile().getName()
                        )
                    );
                    boolean defaultAutoSave =
                        prefs.getBoolean("DefaultAutoSave", true);
                    JCheckBox check = new JCheckBox(
                        LOCALE.get("AlwaysAutoSaveLabel")
                    );
                    check.setSelected(defaultAutoSave);

                    Box message = Box.createVerticalBox();
                    message.add(prompt);
                    message.add(check);
                    int dialogOption = UICompliance.showOptionDialog(
                        this,
                        message,
                        LOCALE.get("AutoSaveDialogTitle"),
                        JOptionPane.DEFAULT_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        new Object[] {
                            LOCALE.get("AutoSaveSaveOption"),
                            LOCALE.get("AutoSaveSaveAsOption"),
                            LOCALE.get("AutoSaveCancelOption"),
                            LOCALE.get("AutoSaveDontSaveOption")
                        },
                        LOCALE.get("AutoSaveSaveOption"), 3
                    );
                    if (check.isSelected()) {
                        prefs.putBoolean("AutoSave", true);
                        AlertDialog alert =
                            Platform.getPlatform().getAlertDialog();
                        alert.showAlert(
                            this,
                            LOCALE.get("AutoSaveOnMessageMajor"),
                            LOCALE.get("AutoSaveOnMessageMinor"),
                            AlertDialog.WARNING_ALERT,
                            LOCALE.get("AutoSaveOnButton")
                        );
                    }
                    prefs.putBoolean("DefaultAutoSave", check.isSelected());

                    switch (dialogOption) {
                        case 0:
                            // "save"
                            doc.setSaveOptions(options);
View Full Code Here

TOP

Related Classes of java.util.prefs.Preferences

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.