001package jmri.util;
002
003import java.util.prefs.Preferences;
004
005import jmri.InstanceManagerAutoDefault;
006import jmri.beans.PreferencesBean;
007import jmri.profile.ProfileManager;
008import jmri.profile.ProfileUtils;
009
010/**
011 * Preferences for HelpUtil
012 *
013 * @author Daniel Bergqvist Copyright 2021
014 */
015public final class HelpUtilPreferences extends PreferencesBean implements InstanceManagerAutoDefault {
016
017    public static final String OPEN_HELP_ONLINE = "openHelpOnline";
018    public static final String OPEN_HELP_ON_FILE = "openHelpOnFile";
019    public static final String OPEN_HELP_ON_JMRI_WEB_SERVER = "openHelpOnJMRIWebServer";
020
021    private boolean _openHelpOnline = false;
022    private boolean _openHelpOnFile = true;
023    private boolean _openHelpOnJMRIWebServer = false;
024
025
026    public HelpUtilPreferences() {
027        super(ProfileManager.getDefault().getActiveProfile());
028        Preferences sharedPreferences = ProfileUtils.getPreferences(
029                super.getProfile(), this.getClass(), true);
030        this.readPreferences(sharedPreferences);
031    }
032
033    private void readPreferences(Preferences sharedPreferences) {
034        _openHelpOnline = sharedPreferences.getBoolean(OPEN_HELP_ONLINE, _openHelpOnline);
035        _openHelpOnFile = sharedPreferences.getBoolean(OPEN_HELP_ON_FILE, _openHelpOnFile);
036        _openHelpOnJMRIWebServer = sharedPreferences.getBoolean(OPEN_HELP_ON_JMRI_WEB_SERVER, _openHelpOnJMRIWebServer);
037        setIsDirty(false);
038    }
039
040    public boolean compareValuesDifferent(HelpUtilPreferences prefs) {
041        if (getOpenHelpOnline() != prefs.getOpenHelpOnline()) {
042            return true;
043        }
044        if (getOpenHelpOnFile() != prefs.getOpenHelpOnFile()) {
045            return true;
046        }
047        return (getOpenHelpOnJMRIWebServer() != prefs.getOpenHelpOnJMRIWebServer());
048    }
049
050    public void apply(HelpUtilPreferences prefs) {
051        setOpenHelpOnline(prefs.getOpenHelpOnline());
052        setOpenHelpOnFile(prefs.getOpenHelpOnFile());
053        setOpenHelpOnJMRIWebServer(prefs.getOpenHelpOnJMRIWebServer());
054    }
055
056    public void save() {
057        Preferences sharedPreferences = ProfileUtils.getPreferences(this.getProfile(), this.getClass(), true);
058        sharedPreferences.putBoolean(OPEN_HELP_ONLINE, this.getOpenHelpOnline());
059        sharedPreferences.putBoolean(OPEN_HELP_ON_FILE, this.getOpenHelpOnFile());
060        sharedPreferences.putBoolean(OPEN_HELP_ON_JMRI_WEB_SERVER, this.getOpenHelpOnJMRIWebServer());
061        setIsDirty(false);
062    }
063
064    public void setOpenHelpOnline(boolean value) {
065        _openHelpOnline = value;
066        setIsDirty(true);
067    }
068
069    public boolean getOpenHelpOnline() {
070        return _openHelpOnline;
071    }
072
073    public void setOpenHelpOnFile(boolean value) {
074        _openHelpOnFile = value;
075        setIsDirty(true);
076    }
077
078    public boolean getOpenHelpOnFile() {
079        return _openHelpOnFile;
080    }
081
082    public void setOpenHelpOnJMRIWebServer(boolean value) {
083        _openHelpOnJMRIWebServer = value;
084        setIsDirty(true);
085    }
086
087    public boolean getOpenHelpOnJMRIWebServer() {
088        return _openHelpOnJMRIWebServer;
089    }
090//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(HelpUtilPreferences.class);
091}