Search in sources :

Example 1 with BooleanPreference

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.");
        }
    }
}
Also used : SingleNumberPreference(de.unijena.cheminf.mortar.preference.SingleNumberPreference) IPreference(de.unijena.cheminf.mortar.preference.IPreference) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SingleIntegerPreference(de.unijena.cheminf.mortar.preference.SingleIntegerPreference) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) BooleanPreference(de.unijena.cheminf.mortar.preference.BooleanPreference) SingleTermPreference(de.unijena.cheminf.mortar.preference.SingleTermPreference) SimpleEnumConstantNameProperty(de.unijena.cheminf.mortar.model.util.SimpleEnumConstantNameProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) SimpleEnumConstantNameProperty(de.unijena.cheminf.mortar.model.util.SimpleEnumConstantNameProperty) Property(javafx.beans.property.Property) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty)

Example 2 with BooleanPreference

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.");
                }
            }
        }
    }
}
Also used : SingleNumberPreference(de.unijena.cheminf.mortar.preference.SingleNumberPreference) IPreference(de.unijena.cheminf.mortar.preference.IPreference) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SingleIntegerPreference(de.unijena.cheminf.mortar.preference.SingleIntegerPreference) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) BooleanPreference(de.unijena.cheminf.mortar.preference.BooleanPreference) SingleTermPreference(de.unijena.cheminf.mortar.preference.SingleTermPreference) SimpleEnumConstantNameProperty(de.unijena.cheminf.mortar.model.util.SimpleEnumConstantNameProperty) PreferenceContainer(de.unijena.cheminf.mortar.preference.PreferenceContainer) File(java.io.File) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) SimpleEnumConstantNameProperty(de.unijena.cheminf.mortar.model.util.SimpleEnumConstantNameProperty) Property(javafx.beans.property.Property) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty)

Aggregations

SimpleEnumConstantNameProperty (de.unijena.cheminf.mortar.model.util.SimpleEnumConstantNameProperty)2 BooleanPreference (de.unijena.cheminf.mortar.preference.BooleanPreference)2 IPreference (de.unijena.cheminf.mortar.preference.IPreference)2 SingleIntegerPreference (de.unijena.cheminf.mortar.preference.SingleIntegerPreference)2 SingleNumberPreference (de.unijena.cheminf.mortar.preference.SingleNumberPreference)2 SingleTermPreference (de.unijena.cheminf.mortar.preference.SingleTermPreference)2 Property (javafx.beans.property.Property)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)2 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)2 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)2 PreferenceContainer (de.unijena.cheminf.mortar.preference.PreferenceContainer)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1