001package jmri.configurexml; 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 Load and store tables and panel files. 012 * 013 * @author Dave Sand Copyright 2022 014 * @author Daniel Bergqvist Copyright 2025 015 */ 016public final class LoadAndStorePreferences extends PreferencesBean implements InstanceManagerAutoDefault { 017 018 public static final String EXCLUDE_FILE_HISTORY = "excludeFileHistory"; 019 public static final String EXCLUDE_MEMORY_IMCURRENTTIME = "excludeMemoryIMCURRENTTIME"; 020 public static final String EXCLUDE_JMRI_VERSION = "excludeJmriVersion"; 021 022 private boolean _excludeFileHistory = false; 023 private boolean _excludeMemoryIMCURRENTTIME = false; 024 private boolean _excludeJmriVersion = false; 025 026 027 public LoadAndStorePreferences() { 028 super(ProfileManager.getDefault().getActiveProfile()); 029 Preferences sharedPreferences = ProfileUtils.getPreferences( 030 super.getProfile(), this.getClass(), true); 031 this.readPreferences(sharedPreferences); 032 } 033 034 private void readPreferences(Preferences sharedPreferences) { 035 _excludeFileHistory = sharedPreferences.getBoolean(EXCLUDE_FILE_HISTORY, false); 036 _excludeMemoryIMCURRENTTIME = sharedPreferences.getBoolean(EXCLUDE_MEMORY_IMCURRENTTIME, false); 037 _excludeJmriVersion = sharedPreferences.getBoolean(EXCLUDE_JMRI_VERSION, false); 038 setIsDirty(false); 039 } 040 041 public boolean compareValuesDifferent(LoadAndStorePreferences prefs) { 042 if (isExcludeFileHistory() != prefs.isExcludeFileHistory()) { 043 return true; 044 } 045 if (isExcludeMemoryIMCURRENTTIME() != prefs.isExcludeMemoryIMCURRENTTIME()) { 046 return true; 047 } 048 if (isExcludeJmriVersion() != prefs.isExcludeJmriVersion()) { 049 return true; 050 } 051 return false; 052 } 053 054 public void apply(LoadAndStorePreferences prefs) { 055 setExcludeFileHistory(prefs.isExcludeFileHistory()); 056 setExcludeMemoryIMCURRENTTIME(prefs.isExcludeMemoryIMCURRENTTIME()); 057 setExcludeJmriVersion(prefs.isExcludeJmriVersion()); 058 } 059 060 public void save() { 061 Preferences sharedPreferences = ProfileUtils.getPreferences(this.getProfile(), this.getClass(), true); 062 sharedPreferences.putBoolean(EXCLUDE_FILE_HISTORY, this.isExcludeFileHistory()); 063 sharedPreferences.putBoolean(EXCLUDE_MEMORY_IMCURRENTTIME, this.isExcludeMemoryIMCURRENTTIME()); 064 sharedPreferences.putBoolean(EXCLUDE_JMRI_VERSION, this.isExcludeJmriVersion()); 065 setIsDirty(false); 066 } 067 068 public void setExcludeFileHistory(boolean value) { 069 _excludeFileHistory = value; 070 setIsDirty(true); 071 } 072 073 public boolean isExcludeFileHistory() { 074 return _excludeFileHistory; 075 } 076 077 public void setExcludeMemoryIMCURRENTTIME(boolean value) { 078 _excludeMemoryIMCURRENTTIME = value; 079 setIsDirty(true); 080 } 081 082 public boolean isExcludeMemoryIMCURRENTTIME() { 083 return _excludeMemoryIMCURRENTTIME; 084 } 085 086 public void setExcludeJmriVersion(boolean value) { 087 _excludeJmriVersion = value; 088 setIsDirty(true); 089 } 090 091 public boolean isExcludeJmriVersion() { 092 return _excludeJmriVersion; 093 } 094 095 096// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(StoreAndComparePreferences.class); 097}