Search in sources :

Example 56 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class SlipTurnoutIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@SuppressWarnings("null")
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    SlipTurnoutIcon l = new SlipTurnoutIcon(p);
    int rotation = 0;
    try {
        Attribute a = element.getAttribute("rotate");
        rotation = a.getIntValue();
    } catch (org.jdom2.DataConversionException e) {
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    String nameEast = loadTurnout(element, "turnoutEast");
    /*try {
         nameEast=element.getAttribute("turnoutEast").getValue();
         } catch ( NullPointerException e) { 
         log.error("incorrect information for turnout; must use turnout name");
         return;
         }*/
    String nameWest = loadTurnout(element, "turnoutWest");
    /*try {
         nameWest=element.getAttribute("turnoutWest").getValue();
         } catch ( NullPointerException e) { 
         log.error("incorrect information for turnout; must use turnout name");
         return;
         }*/
    Attribute a = element.getAttribute("turnoutType");
    if (a != null) {
        if (a.getValue().equals("doubleSlip")) {
            l.setTurnoutType(SlipTurnoutIcon.DOUBLESLIP);
        } else if (a.getValue().equals("singleSlip")) {
            l.setTurnoutType(SlipTurnoutIcon.SINGLESLIP);
            a = element.getAttribute("singleSlipRoute");
            if ((a == null) || a.getValue().equals("upperWestToUpperEast")) {
                l.setSingleSlipRoute(true);
            } else {
                l.setSingleSlipRoute(false);
            }
        } else if (a.getValue().equals("threeWay")) {
            l.setTurnoutType(SlipTurnoutIcon.THREEWAY);
            a = element.getAttribute("firstTurnoutExit");
            if ((a == null) || a.getValue().equals("lower")) {
                l.setSingleSlipRoute(false);
            } else {
                l.setSingleSlipRoute(true);
            }
        } else if (a.getValue().equals("scissor")) {
            l.setTurnoutType(SlipTurnoutIcon.SCISSOR);
            if (loadTurnout(element, "turnoutLowerWest") == null) {
                l.setSingleSlipRoute(true);
            } else {
                //loadTurnout(element, "turnoutLowerEast");
                l.setSingleSlipRoute(false);
                l.setTurnout(loadTurnout(element, "turnoutLowerEast"), SlipTurnoutIcon.LOWEREAST);
                l.setTurnout(loadTurnout(element, "turnoutLowerWest"), SlipTurnoutIcon.LOWERWEST);
            }
        }
    }
    loadTurnoutIcon("lowerWestToUpperEast", rotation, l, element, p);
    loadTurnoutIcon("upperWestToLowerEast", rotation, l, element, p);
    switch(l.getTurnoutType()) {
        case SlipTurnoutIcon.DOUBLESLIP:
            loadTurnoutIcon("lowerWestToLowerEast", rotation, l, element, p);
            loadTurnoutIcon("upperWestToUpperEast", rotation, l, element, p);
            break;
        default:
            loadTurnoutIcon("lowerWestToLowerEast", rotation, l, element, p);
            break;
    }
    loadTurnoutIcon("unknown", rotation, l, element, p);
    loadTurnoutIcon("inconsistent", rotation, l, element, p);
    a = element.getAttribute("tristate");
    if ((a == null) || a.getValue().equals("true")) {
        l.setTristate(true);
    } else {
        l.setTristate(false);
    }
    l.setTurnout(nameEast, SlipTurnoutIcon.EAST);
    l.setTurnout(nameWest, SlipTurnoutIcon.WEST);
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : Attribute(org.jdom2.Attribute) SlipTurnoutIcon(jmri.jmrit.display.SlipTurnoutIcon) Editor(jmri.jmrit.display.Editor)

Example 57 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class TurnoutIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@SuppressWarnings("null")
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    TurnoutIcon l = new TurnoutIcon(p);
    String name;
    try {
        name = element.getAttribute("turnout").getValue();
    } catch (NullPointerException e) {
        log.error("incorrect information for turnout; must use turnout name");
        p.loadFailed();
        return;
    }
    l.setTurnout(name);
    Attribute a = element.getAttribute("tristate");
    if ((a == null) || a.getValue().equals("true")) {
        l.setTristate(true);
    } else {
        l.setTristate(false);
    }
    a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
        l.setMomentary(true);
    } else {
        l.setMomentary(false);
    }
    a = element.getAttribute("directControl");
    if ((a != null) && a.getValue().equals("true")) {
        l.setDirectControl(true);
    } else {
        l.setDirectControl(false);
    }
    List<Element> states = element.getChildren();
    if (states.size() > 0) {
        if (log.isDebugEnabled()) {
            log.debug("Main element has" + states.size() + " items");
        }
        // the element containing the icons
        Element elem = element;
        Element icons = element.getChild("icons");
        if (icons != null) {
            List<Element> s = icons.getChildren();
            states = s;
            // the element containing the icons
            elem = icons;
            if (log.isDebugEnabled()) {
                log.debug("icons element has" + states.size() + " items");
            }
        }
        for (int i = 0; i < states.size(); i++) {
            String state = states.get(i).getName();
            if (log.isDebugEnabled()) {
                log.debug("setIcon for state \"" + state + "\" and " + _nameMap.get(state));
            }
            NamedIcon icon = loadIcon(l, state, elem, "TurnoutIcon \"" + name + "\": icon \"" + state + "\" ", p);
            if (icon != null) {
                l.setIcon(_nameMap.get(state), icon);
            } else {
                log.info("TurnoutIcon \"" + name + "\": icon \"" + state + "\" removed");
                return;
            }
        }
        log.debug(states.size() + " icons loaded for " + l.getNameString());
    } else {
        // case when everything was attributes
        int rotation = 0;
        try {
            rotation = element.getAttribute("rotate").getIntValue();
        } catch (org.jdom2.DataConversionException e) {
        } catch (NullPointerException e) {
        // considered normal if the attributes are not present
        }
        if (loadTurnoutIcon("thrown", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("closed", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("unknown", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("inconsistent", rotation, l, element, name, p) == null) {
            return;
        }
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) TurnoutIcon(jmri.jmrit.display.TurnoutIcon)

Example 58 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class SignalMastIconXml method store.

/**
     * Default implementation for storing the contents of a SignalMastIcon
     *
     * @param o Object to store, of type SignalMastIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SignalMastIcon p = (SignalMastIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("signalmasticon");
    element.setAttribute("signalmast", "" + p.getNamedSignalMast().getName());
    storeCommonAttributes(p, element);
    element.setAttribute("clickmode", "" + p.getClickMode());
    element.setAttribute("litmode", "" + p.getLitMode());
    element.setAttribute("degrees", String.valueOf(p.getDegrees()));
    element.setAttribute("scale", String.valueOf(p.getScale()));
    element.setAttribute("imageset", p.useIconSet());
    element.setAttribute("class", "jmri.jmrit.display.configurexml.SignalMastIconXml");
    //storeIconInfo(p, element);
    return element;
}
Also used : SignalMastIcon(jmri.jmrit.display.SignalMastIcon) Element(org.jdom2.Element)

Example 59 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class SlipTurnoutIconXml method storeIcon.

Element storeIcon(String elemName, NamedIcon icon, String text) {
    Element element = super.storeIcon(elemName, icon);
    element.addContent(new Element("text").addContent(text));
    return element;
}
Also used : Element(org.jdom2.Element)

Example 60 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class AutomationItem method store.

/**
     * Create an XML element to represent this Entry. This member has to remain
     * synchronized with the detailed DTD in operations-trains.dtd.
     *
     * @return Contents in a JDOM Element
     */
public Element store() {
    Element e = new Element(Xml.ITEM);
    e.setAttribute(Xml.ID, getId());
    e.setAttribute(Xml.SEQUENCE_ID, Integer.toString(getSequenceId()));
    e.setAttribute(Xml.NAME, getActionName());
    // NOI18N
    e.setAttribute(Xml.ACTION_CODE, "0x" + Integer.toHexString(getActionCode()));
    e.setAttribute(Xml.HALT_FAIL, isHaltFailureEnabled() ? Xml.TRUE : Xml.FALSE);
    e.setAttribute(Xml.ACTION_RAN, isActionRan() ? Xml.TRUE : Xml.FALSE);
    e.setAttribute(Xml.ACTION_SUCCESSFUL, isActionSuccessful() ? Xml.TRUE : Xml.FALSE);
    if (getTrain() != null) {
        e.setAttribute(Xml.TRAIN_ID, getTrain().getId());
        if (getRouteLocation() != null) {
            e.setAttribute(Xml.ROUTE_LOCATION_ID, getRouteLocation().getId());
        }
    }
    if (getAutomationToRun() != null) {
        e.setAttribute(Xml.AUTOMATION_ID, getAutomationToRun().getId());
    }
    if (getGotoAutomationItem() != null) {
        e.setAttribute(Xml.GOTO_AUTOMATION_ID, getGotoAutomationItem().getId());
    }
    if (getTrainSchedule() != null) {
        e.setAttribute(Xml.TRAIN_SCHEDULE_ID, getTrainSchedule().getId());
    }
    if (!getMessage().equals(NONE) || !getMessageFail().equals(NONE)) {
        Element eMessages = new Element(Xml.MESSAGES);
        e.addContent(eMessages);
        Element eMessageOk = new Element(Xml.MESSAGE_OK);
        eMessageOk.setAttribute(Xml.MESSAGE, getMessage());
        Element eMessageFail = new Element(Xml.MESSAGE_FAIL);
        eMessageFail.setAttribute(Xml.MESSAGE, getMessageFail());
        eMessages.addContent(eMessageOk);
        eMessages.addContent(eMessageFail);
    }
    return e;
}
Also used : Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)673 Attribute (org.jdom2.Attribute)103 Document (org.jdom2.Document)64 File (java.io.File)49 ArrayList (java.util.ArrayList)36 NamedIcon (jmri.jmrit.catalog.NamedIcon)28 IOException (java.io.IOException)27 DataConversionException (org.jdom2.DataConversionException)26 JDOMException (org.jdom2.JDOMException)26 XmlFile (jmri.jmrit.XmlFile)24 Test (org.junit.Test)24 Editor (jmri.jmrit.display.Editor)22 DocType (org.jdom2.DocType)21 Turnout (jmri.Turnout)20 ProcessingInstruction (org.jdom2.ProcessingInstruction)16 Point (java.awt.Point)15 HashMap (java.util.HashMap)15 SignalHead (jmri.SignalHead)15 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)15 Dimension (java.awt.Dimension)14