Search in sources :

Example 66 with Attribute

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

the class PaneProgFrame method pickProgrammerMode.

protected void pickProgrammerMode(@Nonnull Element programming) {
    log.debug("pickProgrammerMode starts");
    boolean paged = true;
    boolean directbit = true;
    boolean directbyte = true;
    boolean register = true;
    Attribute a;
    // set the programming attributes for DCC
    if ((a = programming.getAttribute("paged")) != null) {
        if (a.getValue().equals("no")) {
            paged = false;
        }
    }
    if ((a = programming.getAttribute("direct")) != null) {
        if (a.getValue().equals("no")) {
            directbit = false;
            directbyte = false;
        } else if (a.getValue().equals("bitOnly")) {
            directbit = true;
            directbyte = false;
        } else if (a.getValue().equals("byteOnly")) {
            directbit = false;
            directbyte = true;
        } else {
            directbit = true;
            directbyte = true;
        }
    }
    if ((a = programming.getAttribute("register")) != null) {
        if (a.getValue().equals("no")) {
            register = false;
        }
    }
    // find an accepted mode to set it to
    List<ProgrammingMode> modes = mProgrammer.getSupportedModes();
    if (log.isDebugEnabled()) {
        log.debug("XML specifies modes: P " + paged + " DBi " + directbit + " Dby " + directbyte + " R " + register + " now " + mProgrammer.getMode());
        log.debug("Programmer supports:");
        for (ProgrammingMode m : modes) {
            log.debug("   {} {}", m.getStandardName(), m.toString());
        }
    }
    // first try specified modes
    for (Element el1 : programming.getChildren("mode")) {
        String name = el1.getText();
        if (log.isDebugEnabled())
            log.debug(" mode {} was specified", name);
        for (ProgrammingMode m : modes) {
            if (name.equals(m.getStandardName())) {
                log.info("Programming mode selected: {} ({})", m.toString(), m.getStandardName());
                mProgrammer.setMode(m);
                return;
            }
        }
    }
    if (modes.contains(DefaultProgrammerManager.DIRECTMODE) && directbit && directbyte) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTMODE);
        log.debug("Set to DIRECTMODE");
    } else if (modes.contains(DefaultProgrammerManager.DIRECTBITMODE) && directbit) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTBITMODE);
        log.debug("Set to DIRECTBITMODE");
    } else if (modes.contains(DefaultProgrammerManager.DIRECTBYTEMODE) && directbyte) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTBYTEMODE);
        log.debug("Set to DIRECTBYTEMODE");
    } else if (modes.contains(DefaultProgrammerManager.PAGEMODE) && paged) {
        mProgrammer.setMode(DefaultProgrammerManager.PAGEMODE);
        log.debug("Set to PAGEMODE");
    } else if (modes.contains(DefaultProgrammerManager.REGISTERMODE) && register) {
        mProgrammer.setMode(DefaultProgrammerManager.REGISTERMODE);
        log.debug("Set to REGISTERMODE");
    } else {
        log.warn("No acceptable mode found, leave as found");
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ProgrammingMode(jmri.ProgrammingMode)

Example 67 with Attribute

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

the class PaneProgFrame method loadProgrammerFile.

protected void loadProgrammerFile(RosterEntry r) {
    // Open and parse programmer file
    XmlFile pf = new XmlFile() {
    };
    // XmlFile is abstract
    try {
        programmerRoot = pf.rootFromName(filename);
        // get the showEmptyPanes attribute, if yes/no update our state
        if (programmerRoot.getChild("programmer").getAttribute("showEmptyPanes") != null) {
            if (log.isDebugEnabled()) {
                log.debug("Found in programmer " + programmerRoot.getChild("programmer").getAttribute("showEmptyPanes").getValue());
            }
            programmerShowEmptyPanes = programmerRoot.getChild("programmer").getAttribute("showEmptyPanes").getValue();
        } else {
            programmerShowEmptyPanes = "";
        }
        if (log.isDebugEnabled()) {
            log.debug("programmerShowEmptyPanes=" + programmerShowEmptyPanes);
        }
        // get extra any panes from the decoder file
        Attribute a;
        if ((a = programmerRoot.getChild("programmer").getAttribute("decoderFilePanes")) != null && a.getValue().equals("yes")) {
            if (decoderRoot != null) {
                decoderPaneList = decoderRoot.getChildren("pane");
            }
        }
        // load programmer config from programmer tree
        readConfig(programmerRoot, r);
    } catch (org.jdom2.JDOMException e) {
        log.error("exception parsing programmer file: " + filename, e);
        // provide traceback too
        e.printStackTrace();
    } catch (java.io.IOException e) {
        log.error("exception reading programmer file: " + filename, e);
        // provide traceback too
        e.printStackTrace();
    }
}
Also used : XmlFile(jmri.jmrit.XmlFile) Attribute(org.jdom2.Attribute)

Example 68 with Attribute

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

the class DefaultSignalGroupManagerXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // loop over contained signalgroup elements
    List<Element> list = shared.getChildren("signalgroup");
    SignalGroupManager sgm = InstanceManager.getDefault(jmri.SignalGroupManager.class);
    for (int i = 0; i < list.size(); i++) {
        SignalGroup m;
        Element e = list.get(i);
        String primary;
        String yesno;
        boolean inverse = false;
        int state = 0x00;
        String sys = getSystemName(e);
        m = sgm.newSignalGroup(sys);
        if (getUserName(e) != null) {
            m.setUserName(getUserName(e));
        }
        //loadCommon(m, e); // would store comment, now a separate element
        loadComment(m, e);
        primary = e.getAttribute("signalMast").getValue();
        m.setSignalMast(primary);
        // deprecated 4.7.2 for aspect
        List<Element> appList = e.getChildren("appearance");
        for (int y = 0; y < appList.size(); y++) {
            String value = appList.get(y).getAttribute("valid").getValue();
            m.addSignalMastAspect(value);
        }
        List<Element> aspList = e.getChildren("aspect");
        for (int y = 0; y < aspList.size(); y++) {
            String value = aspList.get(y).getAttribute("valid").getValue();
            m.addSignalMastAspect(value);
        }
        List<Element> signalHeadList = list.get(i).getChildren("signalHead");
        if (signalHeadList.size() > 0) {
            for (int y = 0; y < signalHeadList.size(); y++) {
                String head = signalHeadList.get(y).getAttribute("name").getValue();
                SignalHead sigHead = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(head);
                m.addSignalHead(sigHead);
                yesno = signalHeadList.get(y).getAttribute("sensorTurnoutLogic").getValue();
                inverse = false;
                if ((yesno != null) && (!yesno.equals(""))) {
                    if (yesno.equals("AND")) {
                        inverse = true;
                    } else if (yesno.equals("OR")) {
                        inverse = false;
                    }
                }
                m.setSensorTurnoutOper(sigHead, inverse);
                try {
                    m.setHeadOnState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("onAppearance").getValue()));
                } catch (NullPointerException ex) {
                // considered normal if the attributes are not present
                }
                try {
                    m.setHeadOffState(sigHead, getIntFromColour(signalHeadList.get(y).getAttribute("offAppearance").getValue()));
                } catch (NullPointerException ex) {
                // considered normal if the attributes are not present
                }
                List<Element> signalTurnoutList = signalHeadList.get(y).getChildren("turnout");
                if (signalTurnoutList.size() > 0) {
                    for (int k = 0; k < signalTurnoutList.size(); k++) {
                        String tName = signalTurnoutList.get(k).getAttribute("name").getValue();
                        jmri.Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().getTurnout(tName);
                        state = 0;
                        try {
                            state = signalTurnoutList.get(k).getAttribute("state").getIntValue();
                        } catch (org.jdom2.DataConversionException ex) {
                            log.warn("invalid state attribute value");
                        }
                        m.setHeadAlignTurnout(sigHead, turnout, state);
                    }
                }
                List<Element> signalSensorList = signalHeadList.get(y).getChildren("sensor");
                if (signalSensorList.size() > 0) {
                    for (int k = 0; k < signalSensorList.size(); k++) {
                        String sName = signalSensorList.get(k).getAttribute("name").getValue();
                        jmri.Sensor sensor = jmri.InstanceManager.sensorManagerInstance().getSensor(sName);
                        state = 0;
                        try {
                            state = signalSensorList.get(k).getAttribute("state").getIntValue();
                        } catch (org.jdom2.DataConversionException ex) {
                            log.warn("invalid style attribute value");
                        }
                        m.setHeadAlignSensor(sigHead, sensor, state);
                    }
                }
            }
        }
    }
    return true;
}
Also used : SignalGroup(jmri.SignalGroup) Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SignalGroupManager(jmri.SignalGroupManager)

Example 69 with Attribute

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

the class DefaultUserMessagePreferencesXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    // ensure the master object exists
    jmri.UserPreferencesManager p = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
    p.setLoading();
    List<Element> settingList = shared.getChildren("setting");
    for (int i = 0; i < settingList.size(); i++) {
        String name = settingList.get(i).getText();
        p.setSimplePreferenceState(name, true);
    }
    List<Element> comboList = shared.getChildren("comboBoxLastValue");
    for (int i = 0; i < comboList.size(); i++) {
        List<Element> comboItem = comboList.get(i).getChildren("comboBox");
        for (int x = 0; x < comboItem.size(); x++) {
            String combo = comboItem.get(x).getAttribute("name").getValue();
            String setting = comboItem.get(x).getAttribute("lastSelected").getValue();
            p.addComboBoxLastSelection(combo, setting);
        }
    }
    List<Element> classList = shared.getChildren("classPreferences");
    for (int k = 0; k < classList.size(); k++) {
        List<Element> multipleList = classList.get(k).getChildren("multipleChoice");
        String strClass = classList.get(k).getAttribute("class").getValue();
        for (int i = 0; i < multipleList.size(); i++) {
            List<Element> multiItem = multipleList.get(i).getChildren("option");
            for (int x = 0; x < multiItem.size(); x++) {
                String item = multiItem.get(x).getAttribute("item").getValue();
                int value = 0x00;
                try {
                    value = multiItem.get(x).getAttribute("value").getIntValue();
                } catch (org.jdom2.DataConversionException e) {
                    log.error("failed to convert positional attribute");
                }
                p.setMultipleChoiceOption(strClass, item, value);
            }
        }
        List<Element> preferenceList = classList.get(k).getChildren("reminderPrompts");
        for (int i = 0; i < preferenceList.size(); i++) {
            List<Element> reminderBoxes = preferenceList.get(i).getChildren("reminder");
            for (int j = 0; j < reminderBoxes.size(); j++) {
                String name = reminderBoxes.get(j).getText();
                p.setPreferenceState(strClass, name, true);
            }
        }
    }
    List<Element> windowList = shared.getChildren("windowDetails");
    for (int k = 0; k < windowList.size(); k++) {
        String strClass = windowList.get(k).getAttribute("class").getValue();
        List<Element> locListX = windowList.get(k).getChildren("locX");
        double x = 0.0;
        for (int i = 0; i < locListX.size(); i++) {
            try {
                x = Double.parseDouble(locListX.get(i).getText());
            } catch (NumberFormatException e) {
                log.error("failed to convert positional attribute");
            }
        }
        List<Element> locListY = windowList.get(k).getChildren("locY");
        double y = 0.0;
        for (int i = 0; i < locListY.size(); i++) {
            try {
                y = Double.parseDouble(locListY.get(i).getText());
            } catch (NumberFormatException e) {
                log.error("failed to convert positional attribute");
            }
        }
        p.setWindowLocation(strClass, new java.awt.Point((int) x, (int) y));
        List<Element> sizeWidth = windowList.get(k).getChildren("width");
        double width = 0.0;
        for (int i = 0; i < sizeWidth.size(); i++) {
            try {
                width = Double.parseDouble(sizeWidth.get(i).getText());
            } catch (NumberFormatException e) {
                log.error("failed to convert positional attribute");
            }
        }
        List<Element> heightList = windowList.get(k).getChildren("height");
        double height = 0.0;
        for (int i = 0; i < heightList.size(); i++) {
            try {
                height = Double.parseDouble(heightList.get(i).getText());
            } catch (NumberFormatException e) {
                log.error("failed to convert positional attribute");
            }
        }
        p.setWindowSize(strClass, new java.awt.Dimension((int) width, (int) height));
        Element prop = windowList.get(k).getChild("properties");
        if (prop != null) {
            for (Object next : prop.getChildren("property")) {
                Element e = (Element) next;
                try {
                    Class<?> cl;
                    Constructor<?> ctor;
                    // create key object
                    String key = e.getChild("key").getText();
                    // create value object
                    Object value = null;
                    if (e.getChild("value") != null) {
                        cl = Class.forName(e.getChild("value").getAttributeValue("class"));
                        ctor = cl.getConstructor(new Class<?>[] { String.class });
                        value = ctor.newInstance(new Object[] { e.getChild("value").getText() });
                    }
                    // store
                    p.setProperty(strClass, key, value);
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                    log.error("Error loading properties", ex);
                }
            }
        }
    }
    List<Element> tablesList = shared.getChildren("tableDetails");
    for (Element tables : tablesList) {
        List<Element> tableList = tables.getChildren("table");
        for (Element table : tableList) {
            List<Element> columnList = table.getChildren("column");
            String strTableName = table.getAttribute("name").getValue();
            for (Element column : columnList) {
                String strColumnName = column.getAttribute("name").getValue();
                int order = -1;
                int width = -1;
                SortOrder sort = SortOrder.UNSORTED;
                boolean hidden = false;
                if (column.getChild("order") != null) {
                    order = Integer.parseInt(column.getChild("order").getText());
                }
                if (column.getChild("width") != null) {
                    width = Integer.parseInt(column.getChild("width").getText());
                }
                if (column.getChild("sortOrder") != null) {
                    sort = SortOrder.valueOf(column.getChild("sortOrder").getText());
                // before 4.3.5 we used "sort" save column sort state
                } else if (column.getChild("sort") != null) {
                    switch(Integer.parseInt(column.getChild("sort").getText())) {
                        case TableSorter.ASCENDING:
                            sort = SortOrder.ASCENDING;
                            break;
                        case TableSorter.DESCENDING:
                            sort = SortOrder.DESCENDING;
                            break;
                        default:
                            break;
                    }
                }
                if (column.getChild("hidden") != null && column.getChild("hidden").getText().equals("yes")) {
                    hidden = true;
                }
                p.setTableColumnPreferences(strTableName, strColumnName, order, width, sort, hidden);
            }
        }
    }
    p.finishLoading();
    return true;
}
Also used : Element(org.jdom2.Element) SortOrder(javax.swing.SortOrder) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 70 with Attribute

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

the class DefaultLogixManagerXml method loadLogixs.

/**
     * Utility method to load the individual Logix objects. If there's no
     * additional info needed for a specific logix type, invoke this with the
     * parent of the set of Logix elements.
     *
     * @param logixs Element containing the Logix elements to load.
     */
public void loadLogixs(Element logixs) {
    List<Element> logixList = logixs.getChildren("logix");
    if (log.isDebugEnabled()) {
        log.debug("Found " + logixList.size() + " logixs");
    }
    LogixManager tm = InstanceManager.getDefault(jmri.LogixManager.class);
    for (int i = 0; i < logixList.size(); i++) {
        String sysName = getSystemName(logixList.get(i));
        if (sysName == null) {
            log.warn("unexpected null in systemName " + logixList.get(i));
            break;
        }
        String userName = getUserName(logixList.get(i));
        String yesno = "";
        if (logixList.get(i).getAttribute("enabled") != null) {
            yesno = logixList.get(i).getAttribute("enabled").getValue();
        }
        if (log.isDebugEnabled()) {
            log.debug("create logix: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
        }
        Logix x = tm.createNewLogix(sysName, userName);
        if (x != null) {
            // load common part
            loadCommon(x, logixList.get(i));
            // set enabled/disabled if attribute was present
            if ((yesno != null) && (!yesno.equals(""))) {
                if (yesno.equals("yes")) {
                    x.setEnabled(true);
                } else if (yesno.equals("no")) {
                    x.setEnabled(false);
                }
            }
            // load conditionals, if there are any
            List<Element> logixConditionalList = logixList.get(i).getChildren("logixConditional");
            if (logixConditionalList.size() > 0) {
                // add conditionals
                for (int n = 0; n < logixConditionalList.size(); n++) {
                    if (logixConditionalList.get(n).getAttribute("systemName") == null) {
                        log.warn("unexpected null in systemName " + logixConditionalList.get(n) + " " + logixConditionalList.get(n).getAttributes());
                        break;
                    }
                    String cSysName = logixConditionalList.get(n).getAttribute("systemName").getValue();
                    int cOrder = Integer.parseInt(logixConditionalList.get(n).getAttribute("order").getValue());
                    // add conditional to logix
                    x.addConditional(cSysName, cOrder);
                }
            }
        }
    }
}
Also used : Logix(jmri.Logix) Element(org.jdom2.Element) LogixManager(jmri.LogixManager) DefaultLogixManager(jmri.managers.DefaultLogixManager)

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