Search in sources :

Example 1 with DefaultTemplateSettings

use of uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplateSettings in project GDSC-SMLM by aherbert.

the class ConfigurationTemplate method restoreLoadedTemplates.

/**
 * Restore the templates that were loaded.
 *
 * <p>Given the list of standard templates is manipulated only by this plugin this should be the
 * same set of templates used last time by the user.
 *
 * @param inlineTemplates the inline templates
 * @return the templates
 */
private static Map<String, Template> restoreLoadedTemplates(Map<String, Template> inlineTemplates) {
    Map<String, Template> map = new LinkedHashMap<>();
    // Allow this to fail silently
    final DefaultTemplateSettings settings = SettingsManager.readDefaultTemplateSettings(SettingsManager.FLAG_SILENT);
    if (settings.getDefaultTemplatesCount() == 0) {
        return map;
    }
    HashMap<String, TemplateResource> templateResources = null;
    // Process in order so that the order is preserved, i.e. do not bulk load each type
    for (final DefaultTemplate d : settings.getDefaultTemplatesList()) {
        switch(d.getTemplateType()) {
            case CUSTOM_TEMPLATE:
                loadCustomTemplate(map, d.getName(), d.getFilename(), d.getTifFilename());
                break;
            case INLINE_TEMPLATE:
                final Template t = inlineTemplates.get(d.getName());
                if (t != null) {
                    map.put(d.getName(), t);
                }
                break;
            case RESOURCE_TEMPLATE:
                if (templateResources == null) {
                    final TemplateResource[] list = listTemplateResources();
                    templateResources = new HashMap<>(list.length);
                    for (final TemplateResource r : list) {
                        templateResources.put(r.name, r);
                    }
                }
                loadTemplateResource(map, templateResources.get(d.getName()));
                break;
            default:
                break;
        }
    }
    if (map.size() != settings.getDefaultTemplatesCount()) {
        // This occurs if we cannot reload some of the templates.
        // Prevent this from happening again.
        saveLoadedTemplates(map);
    }
    return map;
}
Also used : DefaultTemplateSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplateSettings) DefaultTemplate(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplate) DefaultTemplate(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplate) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 DefaultTemplate (uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplate)1 DefaultTemplateSettings (uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.DefaultTemplateSettings)1