Search in sources :

Example 1 with SlipTurnoutIcon

use of jmri.jmrit.display.SlipTurnoutIcon 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 2 with SlipTurnoutIcon

use of jmri.jmrit.display.SlipTurnoutIcon in project JMRI by JMRI.

the class SlipTurnoutIconXml method store.

/**
     * Default implementation for storing the contents of a TurnoutIcon
     *
     * @param o Object to store, of type TurnoutIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SlipTurnoutIcon p = (SlipTurnoutIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("slipturnouticon");
    element.addContent(new Element("turnoutEast").addContent(p.getNamedTurnout(SlipTurnoutIcon.EAST).getName()));
    element.addContent(new Element("turnoutWest").addContent(p.getNamedTurnout(SlipTurnoutIcon.WEST).getName()));
    switch(p.getTurnoutType()) {
        case SlipTurnoutIcon.DOUBLESLIP:
            element.addContent(storeIcon("lowerWestToLowerEast", p.getLowerWestToLowerEastIcon(), p.getLWLEText()));
            element.addContent(storeIcon("upperWestToUpperEast", p.getUpperWestToUpperEastIcon(), p.getUWUEText()));
            element.setAttribute("turnoutType", "doubleSlip");
            break;
        case SlipTurnoutIcon.SINGLESLIP:
            element.addContent(storeIcon("lowerWestToLowerEast", p.getLowerWestToLowerEastIcon(), p.getLWLEText()));
            element.setAttribute("turnoutType", "singleSlip");
            element.setAttribute("singleSlipRoute", p.getSingleSlipRoute() ? "upperWestToUpperEast" : "lowerWestToLowerEast");
            break;
        case SlipTurnoutIcon.THREEWAY:
            element.addContent(storeIcon("lowerWestToLowerEast", p.getLowerWestToLowerEastIcon(), p.getLWLEText()));
            element.setAttribute("turnoutType", "threeWay");
            element.setAttribute("firstTurnoutExit", p.getSingleSlipRoute() ? "upper" : "lower");
            break;
        case SlipTurnoutIcon.SCISSOR:
            if (!p.getSingleSlipRoute()) {
                element.addContent(new Element("turnoutLowerEast").addContent(p.getNamedTurnout(SlipTurnoutIcon.LOWEREAST).getName()));
                element.addContent(new Element("turnoutLowerWest").addContent(p.getNamedTurnout(SlipTurnoutIcon.LOWERWEST).getName()));
            }
            element.addContent(storeIcon("lowerWestToLowerEast", p.getLowerWestToLowerEastIcon(), p.getLWLEText()));
            element.setAttribute("turnoutType", "scissor");
        default:
            log.warn("Unhandled turnout type: {}", p.getTurnoutType());
            break;
    }
    storeCommonAttributes(p, element);
    // include contents
    element.setAttribute("tristate", p.getTristate() ? "true" : "false");
    //element.setAttribute("turnoutType", p.getTurnoutType()?"double":"single");
    // new style
    element.addContent(storeIcon("lowerWestToUpperEast", p.getLowerWestToUpperEastIcon(), p.getLWUEText()));
    element.addContent(storeIcon("upperWestToLowerEast", p.getUpperWestToLowerEastIcon(), p.getUWLEText()));
    element.addContent(super.storeIcon("unknown", p.getUnknownIcon()));
    element.addContent(super.storeIcon("inconsistent", p.getInconsistentIcon()));
    element.setAttribute("class", "jmri.jmrit.display.configurexml.SlipTurnoutIconXml");
    return element;
}
Also used : Element(org.jdom2.Element) SlipTurnoutIcon(jmri.jmrit.display.SlipTurnoutIcon)

Aggregations

SlipTurnoutIcon (jmri.jmrit.display.SlipTurnoutIcon)2 Editor (jmri.jmrit.display.Editor)1 Attribute (org.jdom2.Attribute)1 Element (org.jdom2.Element)1