Search in sources :

Example 91 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class SwitchboardEditorXml method store.

/**
     * Default implementation for storing the contents of a SwitchboardEditor.
     * Storing of beanswitch properties for use on web panel {@link SwitchboardEditor$BeanSwitchXml}
     *
     * @param o Object to store, of type SwitchboardEditor
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SwitchboardEditor p = (SwitchboardEditor) o;
    Element panel = new Element("switchboardeditor");
    JFrame frame = p.getTargetFrame();
    Dimension size = frame.getSize();
    Point posn = frame.getLocation();
    panel.setAttribute("class", "jmri.jmrit.display.switchboardEditor.configurexml.SwitchboardEditorXml");
    panel.setAttribute("name", "" + frame.getTitle());
    panel.setAttribute("x", "" + posn.x);
    panel.setAttribute("y", "" + posn.y);
    panel.setAttribute("height", "" + size.height);
    panel.setAttribute("width", "" + size.width);
    panel.setAttribute("editable", "" + (p.isEditable() ? "yes" : "no"));
    panel.setAttribute("showtooltips", "" + (p.showTooltip() ? "yes" : "no"));
    panel.setAttribute("controlling", "" + (p.allControlling() ? "yes" : "no"));
    panel.setAttribute("hide", p.isVisible() ? "no" : "yes");
    panel.setAttribute("panelmenu", p.isPanelMenuVisible() ? "yes" : "no");
    panel.setAttribute("scrollable", p.getScrollable());
    panel.setAttribute("hideunconnected", "" + (p.hideUnconnected() ? "yes" : "no"));
    panel.setAttribute("rangemin", "" + p.getPanelMenuRangeMin());
    panel.setAttribute("rangemax", "" + p.getPanelMenuRangeMax());
    panel.setAttribute("type", p.getSwitchType());
    panel.setAttribute("connection", p.getSwitchManu());
    panel.setAttribute("shape", p.getSwitchShape());
    panel.setAttribute("columns", "" + p.getColumns());
    panel.setAttribute("defaulttextcolor", p.getDefaultTextColor());
    if (p.getBackgroundColor() != null) {
        panel.setAttribute("redBackground", "" + p.getBackgroundColor().getRed());
        panel.setAttribute("greenBackground", "" + p.getBackgroundColor().getGreen());
        panel.setAttribute("blueBackground", "" + p.getBackgroundColor().getBlue());
    }
    return panel;
}
Also used : SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) JFrame(javax.swing.JFrame) Element(org.jdom2.Element) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 92 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class WarrantPreferences method openFile.

public void openFile(String name) {
    _fileName = name;
    WarrantPreferencesXml prefsXml = new WarrantPreferencesXml();
    File file = new File(_fileName);
    Element root;
    try {
        root = prefsXml.rootFromFile(file);
    } catch (java.io.FileNotFoundException ea) {
        log.debug("Could not find Warrant preferences file.  Normal if preferences have not been saved before.");
        root = null;
    } catch (IOException | JDOMException eb) {
        log.error("Exception while loading warrant preferences: " + eb);
        root = null;
    }
    if (root != null) {
        //            log.info("Found Warrant preferences file: {}", _fileName);
        loadLayoutParams(root.getChild(LAYOUT_PARAMS));
        if (!loadSpeedMap(root.getChild(SPEED_MAP_PARAMS))) {
            loadSpeedMapFromOldXml();
            log.error("Unable to read ramp parameters. Setting to default values.");
        }
    } else {
        loadSpeedMapFromOldXml();
    }
}
Also used : Element(org.jdom2.Element) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 93 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class WarrantPreferences method loadSpeedMap.

// Avoid firePropertyChange until SignalSpeedMap is completely loaded
private boolean loadSpeedMap(Element child) {
    if (child == null) {
        return false;
    }
    Element rampParms = child.getChild(STEP_INCREMENTS);
    if (rampParms == null) {
        return false;
    }
    Attribute a;
    if ((a = rampParms.getAttribute(TIME_INCREMENT)) != null) {
        try {
            this._msIncrTime = a.getIntValue();
        } catch (DataConversionException ex) {
            this._msIncrTime = 500;
            log.error("Unable to read ramp time increment. Setting to default value (500ms).", ex);
        }
    }
    if ((a = rampParms.getAttribute(RAMP_INCREMENT)) != null) {
        try {
            this._throttleIncr = a.getFloatValue();
        } catch (DataConversionException ex) {
            this._throttleIncr = 0.03f;
            log.error("Unable to read ramp throttle increment. Setting to default value (0.03).", ex);
        }
    }
    if ((a = rampParms.getAttribute(THROTTLE_SCALE)) != null) {
        try {
            _throttleScale = a.getFloatValue();
        } catch (DataConversionException ex) {
            _throttleScale = .90f;
            log.error("Unable to read throttle scale. Setting to default value (0.90f).", ex);
        }
    }
    rampParms = child.getChild(SPEED_NAME_PREFS);
    if (rampParms == null) {
        return false;
    }
    if ((a = rampParms.getAttribute("percentNormal")) != null) {
        if (a.getValue().equals("yes")) {
            _interpretation = 1;
        } else {
            _interpretation = 2;
        }
    }
    if ((a = rampParms.getAttribute(INTERPRETATION)) != null) {
        try {
            _interpretation = a.getIntValue();
        } catch (DataConversionException ex) {
            _interpretation = 1;
            log.error("Unable to read interpetation of Speed Map. Setting to default value % normal.", ex);
        }
    }
    HashMap<String, Float> map = new LinkedHashMap<>();
    List<Element> list = rampParms.getChildren();
    for (int i = 0; i < list.size(); i++) {
        String name = list.get(i).getName();
        Float speed = 0f;
        try {
            speed = Float.valueOf(list.get(i).getText());
        } catch (NumberFormatException nfe) {
            log.error("Speed names has invalid content for {} = ", name, list.get(i).getText());
        }
        log.debug("Add {}, {} to AspectSpeed Table", name, speed);
        map.put(name, speed);
    }
    // no firePropertyChange
    this.setSpeedNames(map);
    rampParms = child.getChild(APPEARANCE_PREFS);
    if (rampParms == null) {
        return false;
    }
    LinkedHashMap<String, String> heads = new LinkedHashMap<>();
    list = rampParms.getChildren();
    for (int i = 0; i < list.size(); i++) {
        String name = Bundle.getMessage(list.get(i).getName());
        String speed = list.get(i).getText();
        heads.put(name, speed);
    }
    // no firePropertyChange
    this.setAppearances(heads);
    // Now set SignalSpeedMap members.
    SignalSpeedMap speedMap = jmri.InstanceManager.getDefault(SignalSpeedMap.class);
    speedMap.setRampParams(_msIncrTime, _msIncrTime);
    speedMap.setDefaultThrottleFactor(_throttleScale);
    speedMap.setLayoutScale(_scale);
    speedMap.setAspects(new HashMap<>(this._speedNames), _interpretation);
    speedMap.setAppearances(new HashMap<>(this._headAppearances));
    return true;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) LinkedHashMap(java.util.LinkedHashMap) SignalSpeedMap(jmri.implementation.SignalSpeedMap) DataConversionException(org.jdom2.DataConversionException)

Example 94 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class TrainSwitchListText method load.

public static void load(Element e) {
    Element emts = e.getChild(Xml.SWITCH_LIST_TEXT_STRINGS);
    if (emts == null) {
        return;
    }
    Attribute a;
    if (emts.getChild(Xml.SWICH_LIST_FOR) != null) {
        if ((a = emts.getChild(Xml.SWICH_LIST_FOR).getAttribute(Xml.TEXT)) != null) {
            setStringSwitchListFor(a.getValue());
        }
    }
    if (emts.getChild(Xml.SCHEDULED_WORK_TRAIN) != null) {
        if ((a = emts.getChild(Xml.SCHEDULED_WORK_TRAIN).getAttribute(Xml.TEXT)) != null) {
            setStringScheduledWork(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPARTS_AT) != null) {
        if ((a = emts.getChild(Xml.DEPARTS_AT).getAttribute(Xml.TEXT)) != null) {
            setStringDepartsAt(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPARTS_EXPECTED_ARRIVAL) != null) {
        if ((a = emts.getChild(Xml.DEPARTS_EXPECTED_ARRIVAL).getAttribute(Xml.TEXT)) != null) {
            setStringDepartsAtExpectedArrival(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPARTED_EXPECTED) != null) {
        if ((a = emts.getChild(Xml.DEPARTED_EXPECTED).getAttribute(Xml.TEXT)) != null) {
            setStringDepartedExpected(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumber(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER_DEPARTED) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER_DEPARTED).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumberDeparted(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER_TERMINATES) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER_TERMINATES).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumberTerminates(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER_TERMINATES_DEPARTED) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER_TERMINATES_DEPARTED).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumberTerminatesDeparted(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER_DONE) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER_DONE).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumberDone(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DIRECTION_CHANGE) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DIRECTION_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDirectionChange(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_CAR_PICK_UPS) != null) {
        if ((a = emts.getChild(Xml.NO_CAR_PICK_UPS).getAttribute(Xml.TEXT)) != null) {
            setStringNoCarPickUps(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_CAR_SET_OUTS) != null) {
        if ((a = emts.getChild(Xml.NO_CAR_SET_OUTS).getAttribute(Xml.TEXT)) != null) {
            setStringNoCarDrops(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DONE) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DONE).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDone(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_CARS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_CARS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsCars(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_LOADS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_LOADS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsLoads(a.getValue());
        }
    }
    if (emts.getChild(Xml.SWITCH_LIST_TRACK) != null) {
        if ((a = emts.getChild(Xml.SWITCH_LIST_TRACK).getAttribute(Xml.TEXT)) != null) {
            setStringSwitchListByTrack(a.getValue());
        }
    }
    if (emts.getChild(Xml.HOLD_CAR) != null) {
        if ((a = emts.getChild(Xml.HOLD_CAR).getAttribute(Xml.TEXT)) != null) {
            setStringHoldCar(a.getValue());
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 95 with Element

use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.

the class TrainSwitchListText method store.

// must synchronize changes with operation-config.dtd
public static Element store() {
    Element values;
    Element e = new Element(Xml.SWITCH_LIST_TEXT_STRINGS);
    // only save strings that have been modified
    if (!getStringSwitchListFor().equals(Bundle.getMessage("SwitchListFor"))) {
        e.addContent(values = new Element(Xml.SWICH_LIST_FOR));
        values.setAttribute(Xml.TEXT, getStringSwitchListFor());
    }
    if (!getStringScheduledWork().equals(Bundle.getMessage("ScheduledWork"))) {
        e.addContent(values = new Element(Xml.SCHEDULED_WORK_TRAIN));
        values.setAttribute(Xml.TEXT, getStringScheduledWork());
    }
    if (!getStringDepartsAt().equals(Bundle.getMessage("DepartsAt"))) {
        e.addContent(values = new Element(Xml.DEPARTS_AT));
        values.setAttribute(Xml.TEXT, getStringDepartsAt());
    }
    if (!getStringDepartsAtExpectedArrival().equals(Bundle.getMessage("DepartsAtExpectedArrival"))) {
        e.addContent(values = new Element(Xml.DEPARTS_EXPECTED_ARRIVAL));
        values.setAttribute(Xml.TEXT, getStringDepartsAtExpectedArrival());
    }
    if (!getStringDepartedExpected().equals(Bundle.getMessage("DepartedExpected"))) {
        e.addContent(values = new Element(Xml.DEPARTED_EXPECTED));
        values.setAttribute(Xml.TEXT, getStringDepartedExpected());
    }
    if (!getStringVisitNumber().equals(Bundle.getMessage("VisitNumber"))) {
        e.addContent(values = new Element(Xml.VISIT_NUMBER));
        values.setAttribute(Xml.TEXT, getStringVisitNumber());
    }
    if (!getStringVisitNumberDeparted().equals(Bundle.getMessage("VisitNumberDeparted"))) {
        e.addContent(values = new Element(Xml.VISIT_NUMBER_DEPARTED));
        values.setAttribute(Xml.TEXT, getStringVisitNumberDeparted());
    }
    if (!getStringVisitNumberTerminates().equals(Bundle.getMessage("VisitNumberTerminates"))) {
        e.addContent(values = new Element(Xml.VISIT_NUMBER_TERMINATES));
        values.setAttribute(Xml.TEXT, getStringVisitNumberTerminates());
    }
    if (!getStringVisitNumberTerminatesDeparted().equals(Bundle.getMessage("VisitNumberTerminatesDeparted"))) {
        e.addContent(values = new Element(Xml.VISIT_NUMBER_TERMINATES_DEPARTED));
        values.setAttribute(Xml.TEXT, getStringVisitNumberTerminatesDeparted());
    }
    if (!getStringVisitNumberDone().equals(Bundle.getMessage("VisitNumberDone"))) {
        e.addContent(values = new Element(Xml.VISIT_NUMBER_DONE));
        values.setAttribute(Xml.TEXT, getStringVisitNumberDone());
    }
    if (!getStringTrainDirectionChange().equals(Bundle.getMessage("TrainDirectionChange"))) {
        e.addContent(values = new Element(Xml.TRAIN_DIRECTION_CHANGE));
        values.setAttribute(Xml.TEXT, getStringTrainDirectionChange());
    }
    if (!getStringNoCarPickUps().equals(Bundle.getMessage("NoCarPickUps"))) {
        e.addContent(values = new Element(Xml.NO_CAR_PICK_UPS));
        values.setAttribute(Xml.TEXT, getStringNoCarPickUps());
    }
    if (!getStringNoCarDrops().equals(Bundle.getMessage("NoCarDrops"))) {
        e.addContent(values = new Element(Xml.NO_CAR_SET_OUTS));
        values.setAttribute(Xml.TEXT, getStringNoCarDrops());
    }
    if (!getStringTrainDone().equals(Bundle.getMessage("TrainDone"))) {
        e.addContent(values = new Element(Xml.TRAIN_DONE));
        values.setAttribute(Xml.TEXT, getStringTrainDone());
    }
    if (!getStringTrainDepartsCars().equals(Bundle.getMessage("TrainDepartsCars"))) {
        e.addContent(values = new Element(Xml.TRAIN_DEPARTS_CARS));
        values.setAttribute(Xml.TEXT, getStringTrainDepartsCars());
    }
    if (!getStringTrainDepartsLoads().equals(Bundle.getMessage("TrainDepartsLoads"))) {
        e.addContent(values = new Element(Xml.TRAIN_DEPARTS_LOADS));
        values.setAttribute(Xml.TEXT, getStringTrainDepartsLoads());
    }
    if (!getStringSwitchListByTrack().equals(Bundle.getMessage("SwitchListByTrack"))) {
        e.addContent(values = new Element(Xml.SWITCH_LIST_TRACK));
        values.setAttribute(Xml.TEXT, getStringSwitchListByTrack());
    }
    if (!getStringHoldCar().equals(Bundle.getMessage("HoldCar"))) {
        e.addContent(values = new Element(Xml.HOLD_CAR));
        values.setAttribute(Xml.TEXT, getStringHoldCar());
    }
    return e;
}
Also used : Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)3327 Document (org.jdom2.Document)502 Test (org.junit.Test)457 ArrayList (java.util.ArrayList)327 IOException (java.io.IOException)268 Attribute (org.jdom2.Attribute)207 JDOMException (org.jdom2.JDOMException)202 Element (org.osate.aadl2.Element)143 Namespace (org.jdom2.Namespace)136 Test (org.junit.jupiter.api.Test)131 List (java.util.List)130 SAXBuilder (org.jdom2.input.SAXBuilder)125 File (java.io.File)124 HashMap (java.util.HashMap)117 XMLOutputter (org.jdom2.output.XMLOutputter)103 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 NamedElement (org.osate.aadl2.NamedElement)77 StringReader (java.io.StringReader)67 Iterator (java.util.Iterator)63