use of de.unijena.cheminf.mortar.preference.BooleanPreference in project MORTAR by FelixBaensch.
the class FragmentationService method updatePropertiesFromPreferences.
/**
* Sets the values of the given properties according to the preferences in the given container with the same name.
* If no matching preference for a given property is found, the value will remain in its default setting.
*/
private void updatePropertiesFromPreferences(List<Property> aPropertiesList, PreferenceContainer aPreferenceContainer) {
for (Property tmpSettingProperty : aPropertiesList) {
String tmpPropertyName = tmpSettingProperty.getName();
if (aPreferenceContainer.containsPreferenceName(tmpPropertyName)) {
IPreference[] tmpPreferences = aPreferenceContainer.getPreferences(tmpPropertyName);
try {
if (tmpSettingProperty instanceof SimpleBooleanProperty) {
BooleanPreference tmpBooleanPreference = (BooleanPreference) tmpPreferences[0];
tmpSettingProperty.setValue(tmpBooleanPreference.getContent());
} else if (tmpSettingProperty instanceof SimpleIntegerProperty) {
SingleIntegerPreference tmpIntPreference = (SingleIntegerPreference) tmpPreferences[0];
tmpSettingProperty.setValue(tmpIntPreference.getContent());
} else if (tmpSettingProperty instanceof SimpleDoubleProperty) {
SingleNumberPreference tmpDoublePreference = (SingleNumberPreference) tmpPreferences[0];
tmpSettingProperty.setValue(tmpDoublePreference.getContent());
} else if (tmpSettingProperty instanceof SimpleEnumConstantNameProperty || tmpSettingProperty instanceof SimpleStringProperty) {
SingleTermPreference tmpStringPreference = (SingleTermPreference) tmpPreferences[0];
tmpSettingProperty.setValue(tmpStringPreference.getContent());
} else {
// setting will remain in default
FragmentationService.LOGGER.log(Level.WARNING, "Setting " + tmpPropertyName + " is of unknown type.");
}
} catch (ClassCastException | IllegalArgumentException anException) {
// setting will remain in default
FragmentationService.LOGGER.log(Level.WARNING, anException.toString(), anException);
}
} else {
// setting will remain in default
FragmentationService.LOGGER.log(Level.WARNING, "No persisted settings for " + tmpPropertyName + " available.");
}
}
}
use of de.unijena.cheminf.mortar.preference.BooleanPreference in project MORTAR by FelixBaensch.
the class SettingsContainer method reloadGlobalSettings.
/**
* Reloads the setting values from a previous MORTAR session via the persisted preference container.
*/
public void reloadGlobalSettings() {
String tmpSettingsDirectoryPathName = FileUtil.getSettingsDirPath();
File tmpSettingsDirectoryFile = new File(tmpSettingsDirectoryPathName);
String tmpPreferenceContainerFilePathName = tmpSettingsDirectoryPathName + BasicDefinitions.SETTINGS_CONTAINER_FILE_NAME + BasicDefinitions.PREFERENCE_CONTAINER_FILE_EXTENSION;
File tmpPreferenceContainerFile = new File(tmpPreferenceContainerFilePathName);
if (!tmpSettingsDirectoryFile.exists()) {
FileUtil.createDirectory(tmpSettingsDirectoryFile.getAbsolutePath());
SettingsContainer.LOGGER.info("No persisted global settings could be found, all set to default.");
return;
} else {
boolean tmpExists = tmpPreferenceContainerFile.exists();
boolean tmpIsFile = tmpPreferenceContainerFile.isFile();
boolean tmpCanRead = tmpPreferenceContainerFile.canRead();
if (!tmpExists || !tmpIsFile || !tmpCanRead) {
SettingsContainer.LOGGER.warning("Preference container file does not exist or cannot be read. " + "A new one is initialised.");
return;
} else {
PreferenceContainer tmpContainer;
try {
tmpContainer = new PreferenceContainer(tmpPreferenceContainerFile);
} catch (IOException | SecurityException anException) {
SettingsContainer.LOGGER.log(Level.SEVERE, "Unable to reload global settings: " + anException.toString(), anException);
return;
}
List<Property> tmpSettings = new ArrayList<>(6);
tmpSettings.addAll(this.settings);
tmpSettings.add(this.recentDirectoryPathSetting);
for (Property tmpSettingProperty : tmpSettings) {
String tmpPropertyName = tmpSettingProperty.getName();
if (tmpContainer.containsPreferenceName(tmpPropertyName)) {
IPreference[] tmpPreferences = tmpContainer.getPreferences(tmpPropertyName);
try {
if (tmpSettingProperty instanceof SimpleBooleanProperty) {
BooleanPreference tmpBooleanPreference = (BooleanPreference) tmpPreferences[0];
tmpSettingProperty.setValue(tmpBooleanPreference.getContent());
} else if (tmpSettingProperty instanceof SimpleIntegerProperty) {
SingleIntegerPreference tmpIntPreference = (SingleIntegerPreference) tmpPreferences[0];
tmpSettingProperty.setValue(tmpIntPreference.getContent());
} else if (tmpSettingProperty instanceof SimpleDoubleProperty) {
SingleNumberPreference tmpDoublePreference = (SingleNumberPreference) tmpPreferences[0];
tmpSettingProperty.setValue(tmpDoublePreference.getContent());
} else if (tmpSettingProperty instanceof SimpleEnumConstantNameProperty || tmpSettingProperty instanceof SimpleStringProperty) {
SingleTermPreference tmpStringPreference = (SingleTermPreference) tmpPreferences[0];
tmpSettingProperty.setValue(tmpStringPreference.getContent());
} else {
// setting will remain in default
SettingsContainer.LOGGER.log(Level.WARNING, "Setting " + tmpPropertyName + " is of unknown type.");
}
} catch (ClassCastException | IllegalArgumentException anException) {
// setting will remain in default
SettingsContainer.LOGGER.log(Level.WARNING, anException.toString(), anException);
}
} else {
// setting will remain in default
SettingsContainer.LOGGER.log(Level.WARNING, "No persisted settings for " + tmpPropertyName + " available.");
}
}
}
}
}
Aggregations