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.ReporterIcon objects.
010 *
011 * @author Bob Jacobsen Copyright: Copyright (c) 2004
012 */
013public class ReporterIconXml extends PositionableLabelXml {
014
015    public ReporterIconXml() {
016    }
017
018    /**
019     * Default implementation for storing the contents of a ReporterIcon
020     *
021     * @param o Object to store, of type ReporterIcon
022     * @return Element containing the complete info
023     */
024    @Override
025    public Element store(Object o) {
026
027        ReporterIcon p = (ReporterIcon) o;
028
029        Element element = new Element("reportericon");
030
031        // include contents
032        element.setAttribute("reporter", p.getReporter().getSystemName());
033        storeCommonAttributes(p, element);
034
035        storeTextInfo(p, element);
036
037        storeLogixNG_Data(p, element);
038
039        element.setAttribute("class", "jmri.jmrit.display.configurexml.ReporterIconXml");
040
041        return element;
042    }
043
044    /**
045     * Create a PositionableLabel, then add to a target JLayeredPane
046     *
047     * @param element Top level Element to unpack.
048     * @param o       an Editor as an Object
049     * @throws JmriConfigureXmlException when a error prevents creating the objects as as
050     *                   required by the input XML
051     */
052    @Override
053    public void load(Element element, Object o) throws JmriConfigureXmlException {
054        Editor ed = (Editor) o;
055        ReporterIcon l = new ReporterIcon(ed);
056
057        loadTextInfo(l, element);
058
059        l.setReporter(jmri.InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(
060                element.getAttribute("reporter").getValue()));
061
062        l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
063        try {
064            ed.putItem(l);
065        } catch (Positionable.DuplicateIdException e) {
066            throw new JmriConfigureXmlException("Positionable id is not unique", e);
067        }
068
069        loadLogixNG_Data(l, element);
070
071        // load individual item's option settings after editor has set its global settings
072        loadCommonAttributes(l, Editor.REPORTERS, element);
073    }
074}