Search in sources :

Example 51 with Attribute

use of ucar.nc2.Attribute 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 52 with Attribute

use of ucar.nc2.Attribute 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 53 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class RollingStockAttribute method store.

/**
     * Create an XML element to represent this Entry. This member has to remain
     * synchronized with the detailed DTD in operations-cars.dtd and operations-engines.dtd.
     * @param root Common Element for storage.
     * @param eNames New format Element group name
     * @param eName New format Element name
     * @param oldName Backwards compatibility Element name
     *
     */
public void store(Element root, String eNames, String eName, String oldName) {
    if (Control.backwardCompatible) {
        Element values = new Element(oldName);
        for (String name : getNames()) {
            // NOI18N
            values.addContent(name + "%%");
        }
        root.addContent(values);
    }
    // new format using elements
    Element names = new Element(eNames);
    for (String name : getNames()) {
        Element e = new Element(eName);
        if (eName.equals(Xml.LENGTH)) {
            e.setAttribute(new Attribute(Xml.VALUE, name));
        } else {
            e.setAttribute(new Attribute(Xml.NAME, name));
        }
        names.addContent(e);
    }
    root.addContent(names);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 54 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class RollingStockAttribute method load.

public void load(Element root, String eNames, String eName, String oldName) {
    // new format using elements starting version 3.3.1
    if (root.getChild(eNames) != null) {
        @SuppressWarnings("unchecked") List<Element> l = root.getChild(eNames).getChildren(eName);
        Attribute a;
        String[] names = new String[l.size()];
        for (int i = 0; i < l.size(); i++) {
            Element name = l.get(i);
            if ((a = name.getAttribute(Xml.NAME)) != null) {
                names[i] = a.getValue();
            }
            // lengths use "VALUE"
            if ((a = name.getAttribute(Xml.VALUE)) != null) {
                names[i] = a.getValue();
            }
        }
        setNames(names);
    } else // try old format
    if (root.getChild(oldName) != null) {
        // NOI18N
        String[] names = root.getChildText(oldName).split("%%");
        setNames(names);
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 55 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class EngineManager method load.

public void load(Element root) {
    // new format using elements starting version 3.3.1
    if (root.getChild(Xml.NEW_CONSISTS) != null) {
        @SuppressWarnings("unchecked") List<Element> consists = root.getChild(Xml.NEW_CONSISTS).getChildren(Xml.CONSIST);
        log.debug("Engine manager sees {} consists", consists.size());
        Attribute a;
        for (Element consist : consists) {
            if ((a = consist.getAttribute(Xml.NAME)) != null) {
                newConsist(a.getValue());
            }
        }
    } else // old format
    if (root.getChild(Xml.CONSISTS) != null) {
        String names = root.getChildText(Xml.CONSISTS);
        if (!names.equals(NONE)) {
            // NOI18N
            String[] consistNames = names.split("%%");
            log.debug("consists: {}", names);
            for (String name : consistNames) {
                newConsist(name);
            }
        }
    }
    if (root.getChild(Xml.ENGINES) != null) {
        @SuppressWarnings("unchecked") List<Element> engines = root.getChild(Xml.ENGINES).getChildren(Xml.ENGINE);
        log.debug("readFile sees {} engines", engines.size());
        for (Element e : engines) {
            register(new Engine(e));
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Aggregations

Attribute (org.jdom2.Attribute)106 Element (org.jdom2.Element)75 Editor (jmri.jmrit.display.Editor)15 DataConversionException (org.jdom2.DataConversionException)14 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)9 List (java.util.List)7 Color (java.awt.Color)6 File (java.io.File)6 HashMap (java.util.HashMap)6 ConfigureManager (jmri.ConfigureManager)6 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5 Asn1Object (com.android.hotspot2.asn1.Asn1Object)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5 ASN1Encodable (com.android.org.bouncycastle.asn1.ASN1Encodable)5 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)5 ASN1Set (com.android.org.bouncycastle.asn1.ASN1Set)5