Search in sources :

Example 56 with Attribute

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

the class LayoutTurntableXml method load.

/**
     * Load, starting with the layoutturntable element, then all the other data
     *
     * @param element Top level Element to unpack.
     * @param o       LayoutEditor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    LayoutEditor p = (LayoutEditor) o;
    // get center point
    String name = element.getAttribute("ident").getValue();
    double x = 0.0;
    double y = 0.0;
    double radius = 25.0;
    try {
        x = element.getAttribute("xcen").getFloatValue();
        y = element.getAttribute("ycen").getFloatValue();
        radius = element.getAttribute("radius").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutturntable center or radius attributes");
    }
    // create the new LayoutTurntable
    LayoutTurntable l = new LayoutTurntable(name, new Point2D.Double(x, y), p);
    l.setRadius(radius);
    boolean turnoutControl = false;
    if (element.getAttribute("turnoutControlled") != null) {
        if (element.getAttribute("turnoutControlled").getValue().equals("yes")) {
            turnoutControl = true;
        }
    }
    l.setTurnoutControlled(turnoutControl);
    // load ray tracks 
    List<Element> rayTrackList = element.getChildren("raytrack");
    if (rayTrackList.size() > 0) {
        for (int i = 0; i < rayTrackList.size(); i++) {
            double angle = 0.0;
            int index = 0;
            Element relem = rayTrackList.get(i);
            try {
                angle = (relem.getAttribute("angle")).getFloatValue();
                index = (relem.getAttribute("index")).getIntValue();
            } catch (org.jdom2.DataConversionException e) {
                log.error("failed to convert ray track angle or index attributes");
            }
            String connectName = "";
            Attribute a = relem.getAttribute("connectname");
            if (a != null) {
                connectName = a.getValue();
            }
            l.addRayTrack(angle, index, connectName);
            if (turnoutControl && relem.getAttribute("turnout") != null) {
                //Turnout t = jmri.InstanceManager.turnoutManagerInstance().getTurnout();
                if (relem.getAttribute("turnoutstate").getValue().equals("thrown")) {
                    l.setRayTurnout(index, relem.getAttribute("turnout").getValue(), Turnout.THROWN);
                } else {
                    l.setRayTurnout(index, relem.getAttribute("turnout").getValue(), Turnout.CLOSED);
                }
            }
        }
    }
    p.turntableList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Point2D(java.awt.geom.Point2D) LayoutTurntable(jmri.jmrit.display.layoutEditor.LayoutTurntable)

Example 57 with Attribute

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

the class PositionablePointXml method load.

/**
     * Load, starting with the layoutblock element, then all the value-icon
     * pairs
     *
     * @param element Top level Element to unpack.
     * @param o       LayoutEditor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    LayoutEditor p = (LayoutEditor) o;
    // get attributes
    String name = element.getAttribute("ident").getValue();
    int type = PositionablePoint.ANCHOR;
    double x = 0.0;
    double y = 0.0;
    try {
        x = element.getAttribute("x").getFloatValue();
        y = element.getAttribute("y").getFloatValue();
        type = element.getAttribute("type").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positionablepoint attribute");
    }
    // create the new PositionablePoint
    PositionablePoint l = new PositionablePoint(name, type, new Point2D.Double(x, y), p);
    // get remaining attributes
    Attribute a = element.getAttribute("connect1name");
    if (a != null) {
        l.trackSegment1Name = a.getValue();
    }
    a = element.getAttribute("connect2name");
    if (a != null) {
        l.trackSegment2Name = a.getValue();
    }
    a = element.getAttribute("eastboundsignal");
    if (a != null) {
        l.setEastBoundSignal(a.getValue());
    }
    a = element.getAttribute("westboundsignal");
    if (a != null) {
        l.setWestBoundSignal(a.getValue());
    }
    a = element.getAttribute("eastboundsignalmast");
    if (a != null) {
        l.setEastBoundSignalMast(a.getValue());
    }
    a = element.getAttribute("westboundsignalmast");
    if (a != null) {
        l.setWestBoundSignalMast(a.getValue());
    }
    a = element.getAttribute("eastboundsensor");
    if (a != null) {
        l.setEastBoundSensor(a.getValue());
    }
    a = element.getAttribute("westboundsensor");
    if (a != null) {
        l.setWestBoundSensor(a.getValue());
    }
    if (type == PositionablePoint.EDGE_CONNECTOR && element.getAttribute("linkedpanel") != null && element.getAttribute("linkpointid") != null) {
        String linkedEditorName = element.getAttribute("linkedpanel").getValue();
        LayoutEditor linkedEditor = (LayoutEditor) jmri.jmrit.display.PanelMenu.instance().getEditorByName(linkedEditorName);
        if (linkedEditor != null) {
            String linkedPoint = element.getAttribute("linkpointid").getValue();
            for (PositionablePoint point : linkedEditor.pointList) {
                if (point.getType() == PositionablePoint.EDGE_CONNECTOR && point.getID().equals(linkedPoint)) {
                    point.setLinkedPoint(l);
                    l.setLinkedPoint(point);
                    break;
                }
            }
        }
    }
    p.pointList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Point2D(java.awt.geom.Point2D) Attribute(org.jdom2.Attribute) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint) PositionablePoint(jmri.jmrit.display.layoutEditor.PositionablePoint)

Example 58 with Attribute

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

the class LayoutBlockManagerXml method loadLayoutBlocks.

/**
     * Utility method to load the individual LayoutBlock objects. If there's no
     * additional info needed for a specific layoutblock type, invoke this with
     * the parent of the set of layoutblock elements.
     *
     * @param layoutblocks Element containing the layoutblock elements to load.
     */
public void loadLayoutBlocks(Element layoutblocks) {
    LayoutBlockManager tm = InstanceManager.getDefault(LayoutBlockManager.class);
    if (layoutblocks.getAttribute("blockrouting") != null) {
        if (layoutblocks.getAttribute("blockrouting").getValue().equals("yes")) {
            tm.enableAdvancedRouting(true);
        }
    }
    if (layoutblocks.getAttribute("routingStablisedSensor") != null) {
        try {
            tm.setStabilisedSensor(layoutblocks.getAttribute("routingStablisedSensor").getValue());
        } catch (jmri.JmriException e) {
        }
    }
    List<Element> layoutblockList = layoutblocks.getChildren("layoutblock");
    if (log.isDebugEnabled()) {
        log.debug("Found " + layoutblockList.size() + " layoutblocks");
    }
    for (int i = 0; i < layoutblockList.size(); i++) {
        String sysName = getSystemName(layoutblockList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + ((layoutblockList.get(i))) + " " + ((layoutblockList.get(i))).getAttributes());
            break;
        }
        String userName = getUserName(layoutblockList.get(i));
        LayoutBlock b = tm.createNewLayoutBlock(sysName, userName);
        // load common parts
        loadCommon(b, layoutblockList.get(i));
        if (b != null) {
            // set attributes
            Color color = ColorUtil.stringToColor(((layoutblockList.get(i))).getAttribute("trackcolor").getValue());
            b.setBlockTrackColor(color);
            color = ColorUtil.stringToColor(((layoutblockList.get(i))).getAttribute("occupiedcolor").getValue());
            b.setBlockOccupiedColor(color);
            Attribute a = ((layoutblockList.get(i))).getAttribute("extracolor");
            if (a != null) {
                b.setBlockExtraColor(ColorUtil.stringToColor(a.getValue()));
            }
            a = ((layoutblockList.get(i))).getAttribute("occupancysensor");
            if (a != null) {
                b.setOccupancySensorName(a.getValue());
            }
            a = ((layoutblockList.get(i))).getAttribute("memory");
            if (a != null) {
                b.setMemoryName(a.getValue());
            }
            a = ((layoutblockList.get(i))).getAttribute("occupancysensorsense");
            int sense = Sensor.ACTIVE;
            try {
                sense = ((layoutblockList.get(i))).getAttribute("occupiedsense").getIntValue();
            } catch (org.jdom2.DataConversionException e) {
                log.error("failed to convert occupiedsense attribute");
            }
            b.setOccupiedSense(sense);
            if (((layoutblockList.get(i))).getChild("metric") != null) {
                String stMetric = ((layoutblockList.get(i))).getChild("metric").getText();
                try {
                    b.setBlockMetric(Integer.valueOf(stMetric));
                } catch (java.lang.NumberFormatException e) {
                    log.error("failed to convert metric attribute for block " + b.getDisplayName());
                }
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Color(java.awt.Color) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager)

Example 59 with Attribute

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

the class WarrantManagerXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    WarrantManager manager = InstanceManager.getDefault(WarrantManager.class);
    if (shared.getChildren().isEmpty()) {
        return true;
    }
    List<Element> warrantList = shared.getChildren("warrant");
    if (log.isDebugEnabled())
        log.debug("Found {} Warrant objects", warrantList.size());
    for (int i = 0; i < warrantList.size(); i++) {
        Element elem = warrantList.get(i);
        if (elem.getAttribute("systemName") == null) {
            log.warn("unexpected null for systemName in elem {}", elem);
            break;
        }
        String sysName = null;
        if (elem.getAttribute("systemName") != null)
            sysName = elem.getAttribute("systemName").getValue();
        String userName = null;
        if (elem.getAttribute("userName") != null)
            userName = elem.getAttribute("userName").getValue();
        boolean SCWa = true;
        log.debug("loading warrant {}", sysName);
        Attribute wType = elem.getAttribute("wtype");
        if (wType == null) {
            log.debug("wtype is null for {}", sysName);
            SCWa = false;
        } else if (!wType.getValue().equals("SC")) {
            log.debug("wtype is {} for {}", wType.getValue(), sysName);
            SCWa = false;
        }
        long timeToPlatform = 500;
        Attribute TTP = elem.getAttribute("timeToPlatform");
        if (TTP != null) {
            try {
                timeToPlatform = TTP.getLongValue();
            } catch (DataConversionException e) {
                log.debug("ignoring DataConversionException (and reverting to default value): " + e.toString());
            }
        }
        Warrant warrant = manager.createNewWarrant(sysName, userName, SCWa, timeToPlatform);
        if (warrant == null) {
            log.info("Warrant \"{}\" (userName={}) previously loaded. This version not loaded.", sysName, userName);
            continue;
        }
        if (SCWa) {
            if (elem.getAttribute("forward") != null) {
                ((SCWarrant) warrant).setForward(elem.getAttribute("forward").getValue().equals("true"));
            }
            warrant.setNoRamp(SCWa);
            warrant.setShareRoute(SCWa);
        }
        List<Element> orders = elem.getChildren("blockOrder");
        for (int k = 0; k < orders.size(); k++) {
            BlockOrder bo = loadBlockOrder(orders.get(k));
            if (bo == null) {
                break;
            }
            warrant.addBlockOrder(bo);
        }
        String c = elem.getChildText("comment");
        if (c != null) {
            warrant.setComment(c);
        }
        Element order = elem.getChild("viaOrder");
        if (order != null) {
            warrant.setViaOrder(loadBlockOrder(order));
        }
        order = elem.getChild("avoidOrder");
        if (order != null) {
            warrant.setAvoidOrder(loadBlockOrder(order));
        }
        boolean forward = true;
        List<Element> throttleCmds = elem.getChildren("throttleCommand");
        if (throttleCmds != null) {
            for (int k = 0; k < throttleCmds.size(); k++) {
                ThrottleSetting ts = loadThrottleCommand(throttleCmds.get(k));
                warrant.addThrottleCommand(ts);
                if (ts.getCommand().toUpperCase().equals("FORWARD")) {
                    forward = ts.getValue().toUpperCase().equals("TRUE");
                }
            }
        }
        if (SCWa) {
            if (elem.getAttribute("forward") != null) {
                forward = elem.getAttribute("forward").getValue().equals("true");
            }
            ((SCWarrant) warrant).setForward(forward);
            warrant.setNoRamp(SCWa);
            warrant.setShareRoute(SCWa);
        }
        Element train = elem.getChild("train");
        if (train != null) {
            loadTrain(train, warrant);
        }
    }
    return true;
}
Also used : SCWarrant(jmri.jmrit.logix.SCWarrant) Warrant(jmri.jmrit.logix.Warrant) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ThrottleSetting(jmri.jmrit.logix.ThrottleSetting) WarrantManager(jmri.jmrit.logix.WarrantManager) SCWarrant(jmri.jmrit.logix.SCWarrant) DataConversionException(org.jdom2.DataConversionException) BlockOrder(jmri.jmrit.logix.BlockOrder)

Example 60 with Attribute

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

the class WarrantManagerXml method loadBlockOrder.

static BlockOrder loadBlockOrder(Element elem) {
    OBlock block = null;
    List<Element> blocks = elem.getChildren("block");
    if (blocks.size() > 1)
        log.error("More than one block present: {}", blocks.size());
    if (blocks.size() > 0) {
        // sensor
        String name = blocks.get(0).getAttribute("systemName").getValue();
        try {
            block = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).provideOBlock(name);
        } catch (IllegalArgumentException ex) {
            log.error("Unknown Block \"{}\" is null in BlockOrder.", name);
            return null;
        }
        if (log.isDebugEnabled())
            log.debug("Load Block {}.", name);
    } else {
        log.error("Null BlockOrder element");
        return null;
    }
    Attribute attr = elem.getAttribute("pathName");
    String pathName = null;
    if (attr != null)
        pathName = attr.getValue();
    attr = elem.getAttribute("entryName");
    String entryName = null;
    if (attr != null)
        entryName = attr.getValue();
    attr = elem.getAttribute("exitName");
    String exitName = null;
    if (attr != null)
        exitName = attr.getValue();
    return new BlockOrder(block, pathName, entryName, exitName);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) OBlock(jmri.jmrit.logix.OBlock) BlockOrder(jmri.jmrit.logix.BlockOrder)

Aggregations

Attribute (org.jdom2.Attribute)104 Element (org.jdom2.Element)96 DataConversionException (org.jdom2.DataConversionException)17 Editor (jmri.jmrit.display.Editor)15 ArrayList (java.util.ArrayList)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)10 File (java.io.File)8 Color (java.awt.Color)7 List (java.util.List)7 HashMap (java.util.HashMap)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 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)5