001package jmri.jmrit.display.configurexml;
002
003import jmri.configurexml.JmriConfigureXmlException;
004import jmri.jmrit.display.*;
005
006import org.jdom2.Element;
007
008/**
009 * Handle configuration for display.MemorySpinnerIcon objects.
010 *
011 * @author Bob Jacobsen Copyright: Copyright (c) 2009
012 */
013public class MemorySpinnerIconXml extends PositionableLabelXml {
014
015    public MemorySpinnerIconXml() {
016    }
017
018    /**
019     * Default implementation for storing the contents of a MemorySpinnerIcon
020     *
021     * @param o Object to store, of type MemorySpinnerIcon
022     * @return Element containing the complete info
023     */
024    @Override
025    public Element store(Object o) {
026
027        MemorySpinnerIcon p = (MemorySpinnerIcon) o;
028
029        Element element = new Element("memoryicon");
030
031        // include attributes
032        element.setAttribute("memory", p.getNamedMemory().getName());
033        storeCommonAttributes(p, element);
034        storeTextInfo(p, element);
035
036        storeLogixNG_Data(p, element);
037
038        element.setAttribute("class", "jmri.jmrit.display.configurexml.MemorySpinnerIconXml");
039        return element;
040    }
041
042    /**
043     * Load, starting with the memoryicon element, then all the value-icon pairs
044     *
045     * @param element Top level Element to unpack.
046     * @param o       Editor as an Object
047     * @throws JmriConfigureXmlException when a error prevents creating the objects as as
048     *                   required by the input XML
049     */
050    @Override
051    public void load(Element element, Object o) throws JmriConfigureXmlException {
052        // create the objects
053        Editor p = (Editor) o;
054        MemorySpinnerIcon l = new MemorySpinnerIcon(p);
055
056        l.setMemory(element.getAttribute("memory").getValue());
057
058        loadTextInfo(l, element);
059        try {
060            p.putItem(l);
061        } catch (Positionable.DuplicateIdException e) {
062            throw new JmriConfigureXmlException("Positionable id is not unique", e);
063        }
064
065        loadLogixNG_Data(l, element);
066
067        // load individual item's option settings after editor has set its global settings
068        loadCommonAttributes(l, Editor.MEMORIES, element);
069    }
070}