001package jmri.jmrit.consisttool; 002 003import java.util.prefs.BackingStoreException; 004import java.util.prefs.Preferences; 005import jmri.profile.Profile; 006import jmri.profile.ProfileUtils; 007import jmri.spi.PreferencesManager; 008import jmri.util.prefs.AbstractPreferencesManager; 009import jmri.util.prefs.InitializationException; 010import org.openide.util.lookup.ServiceProvider; 011import org.slf4j.Logger; 012import org.slf4j.LoggerFactory; 013 014/** 015 * 016 * @author Paul Bender (C) 2019 017 */ 018@ServiceProvider(service = PreferencesManager.class) 019public class ConsistPreferencesManager extends AbstractPreferencesManager { 020 021 private static final Logger log = LoggerFactory.getLogger(ConsistPreferencesManager.class); 022 public static final String UPDATE_CV19 = "updateCV19"; 023 private boolean updateCV19 = false; 024 025 @Override 026 public void initialize(Profile profile) throws InitializationException { 027 if (!this.isInitialized(profile)) { 028 Preferences preferences = ProfileUtils.getPreferences(profile, this.getClass(), true); 029 this.setUpdateCV19(preferences.getBoolean(UPDATE_CV19, this.isUpdateCV19())); 030 this.setInitialized(profile, true); 031 } 032 } 033 034 @Override 035 public void savePreferences(Profile profile) { 036 Preferences preferences = ProfileUtils.getPreferences(profile, this.getClass(), true); 037 preferences.putBoolean(UPDATE_CV19, this.updateCV19); 038 try { 039 preferences.sync(); 040 } catch (BackingStoreException ex) { 041 log.error("Unable to save preferences.", ex); 042 } 043 } 044 045 /** 046 * @return updateCV19 047 */ 048 public boolean isUpdateCV19() { 049 return updateCV19; 050 } 051 052 /** 053 * @param update the value to set updateCV19 to. 054 */ 055 public void setUpdateCV19(boolean update) { 056 boolean oldUpdateCV19 = this.updateCV19; 057 updateCV19 = update; 058 firePropertyChange(UPDATE_CV19, oldUpdateCV19, updateCV19); 059 } 060 061}