Search in sources :

Example 36 with Attribute

use of com.android.org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.

the class BlockContentsIconXml method load.

/**
     * Load, starting with the BlockContentsIcon element, then all the
     * value-icon pairs
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    Editor ed = null;
    BlockContentsIcon l;
    if (o instanceof LayoutEditor) {
        ed = (LayoutEditor) o;
        l = new jmri.jmrit.display.layoutEditor.BlockContentsIcon("   ", (LayoutEditor) ed);
    } else if (o instanceof jmri.jmrit.display.Editor) {
        ed = (Editor) o;
        l = new BlockContentsIcon("", ed);
    } else {
        log.error("Unrecognizable class - " + o.getClass().getName());
        return;
    }
    String name;
    Attribute attr = element.getAttribute("blockcontents");
    if (attr == null) {
        log.error("incorrect information for a block contents; must use block name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    loadTextInfo(l, element);
    Block m = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
    if (m != null) {
        l.setBlock(name);
    } else {
        log.error("Block named '" + attr.getValue() + "' not found.");
        ed.loadFailed();
    }
    Attribute a = element.getAttribute("selectable");
    if (a != null && a.getValue().equals("yes")) {
        l.setSelectable(true);
    } else {
        l.setSelectable(false);
    }
    // get the icon pairs
    List<Element> items = element.getChildren("blockstate");
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String iconName = item.getAttribute("icon").getValue();
        NamedIcon icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed("Memory " + name, iconName);
            if (icon == null) {
                log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
            }
        }
        if (icon != null) {
            String keyValue = item.getAttribute("value").getValue();
            l.addKeyAndIcon(icon, keyValue);
        }
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setOriginalLocation(x, y);
    l.displayState();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) BlockContentsIcon(jmri.jmrit.display.BlockContentsIcon) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) Block(jmri.Block) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Editor(jmri.jmrit.display.Editor)

Example 37 with Attribute

use of com.android.org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.

the class IndicatorTrackIconXml method load.

/**
     * Create a IndicatorTrackIcon, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    IndicatorTrackIcon l = new IndicatorTrackIcon(p);
    Element elem = element.getChild("iconmap");
    if (elem != null) {
        List<Element> status = elem.getChildren();
        if (status.size() > 0) {
            for (int i = 0; i < status.size(); i++) {
                String msg = "IndicatorTrack \"" + l.getNameString() + "\" icon \"" + status.get(i).getName() + "\" ";
                NamedIcon icon = loadIcon(l, status.get(i).getName(), elem, msg, p);
                if (icon != null) {
                    l.setIcon(status.get(i).getName(), icon);
                } else {
                    log.info(msg + " removed for url= " + status.get(i).getName());
                    return;
                }
            }
        }
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    Element name = element.getChild("occupancyblock");
    if (name != null) {
        l.setOccBlock(name.getText());
    } else {
        // only write sensor if no OBlock, don't write double sensing
        name = element.getChild("occupancysensor");
        if (name != null) {
            l.setOccSensor(name.getText());
        }
    }
    l.setShowTrain(false);
    name = element.getChild("showTrainName");
    if (name != null) {
        if ("yes".equals(name.getText())) {
            l.setShowTrain(true);
        }
    }
    elem = element.getChild("paths");
    if (elem != null) {
        ArrayList<String> paths = new ArrayList<String>();
        List<Element> pth = elem.getChildren();
        for (int i = 0; i < pth.size(); i++) {
            paths.add(pth.get(i).getText());
        }
        l.setPaths(paths);
    }
    l.displayState(l.getStatus());
    l.updateSize();
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Editor(jmri.jmrit.display.Editor)

Example 38 with Attribute

use of com.android.org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.

the class MemoryComboIconXml method load.

/**
     * Load, starting with the memoryComboIcon element, then all the value-icon
     * pairs
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    Element elem = element.getChild("itemList");
    List<Element> list = elem.getChildren("item");
    String[] items = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        Element e = list.get(i);
        String item = e.getText();
        try {
            int idx = e.getAttribute("index").getIntValue();
            items[idx] = item;
        } catch (org.jdom2.DataConversionException ex) {
            log.error("failed to convert ComboBoxIcon index attribute");
            if (items[i] == null) {
                items[i] = item;
            }
        }
    }
    MemoryComboIcon l = new MemoryComboIcon(p, items);
    loadTextInfo(l, element);
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
        log.error("incorrect information for a memory location; must use memory name");
        p.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
    if (m != null) {
        l.setMemory(name);
    } else {
        log.error("Memory named '" + attr.getValue() + "' not found.");
        p.loadFailed();
        return;
    }
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
}
Also used : Attribute(org.jdom2.Attribute) Memory(jmri.Memory) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) MemoryComboIcon(jmri.jmrit.display.MemoryComboIcon)

Example 39 with Attribute

use of com.android.org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.

the class LinkingLabelXml method load.

/**
     * Create LinkingLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    LinkingLabel l = null;
    String url = element.getChild("url").getText();
    // get object class and determine editor being used
    Editor editor = (Editor) o;
    if (element.getAttribute("icon") != null) {
        NamedIcon icon = null;
        String name = element.getAttribute("icon").getValue();
        //            if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
        if (name.equals("yes")) {
            icon = getNamedIcon("icon", element, "LinkingLabel ", editor);
        } else {
            icon = NamedIcon.getIconByName(name);
            if (icon == null) {
                icon = editor.loadFailed("LinkingLabel", name);
                if (icon == null) {
                    log.info("LinkingLabel icon removed for url= " + name);
                    return;
                }
            }
        }
        // abort if name != yes and have null icon
        if (icon == null && !name.equals("yes")) {
            log.info("LinkingLabel icon removed for url= " + name);
            return;
        }
        l = new LinkingLabel(icon, editor, url);
        // no text
        l.setPopupUtility(null);
        try {
            Attribute a = element.getAttribute("rotate");
            if (a != null && icon != null) {
                int rotation = element.getAttribute("rotate").getIntValue();
                icon.setRotation(rotation, l);
            }
        } catch (org.jdom2.DataConversionException e) {
        }
        if (name.equals("yes")) {
            NamedIcon nIcon = loadIcon(l, "icon", element, "LinkingLabel ", editor);
            if (nIcon != null) {
                l.updateIcon(nIcon);
            } else {
                log.info("LinkingLabel icon removed for url= " + name);
                return;
            }
        } else {
            l.updateIcon(icon);
        }
    //l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
    } else if (element.getAttribute("text") != null) {
        l = new LinkingLabel(element.getAttribute("text").getValue(), editor, url);
        loadTextInfo(l, element);
    } else {
        log.error("LinkingLabel is null!");
        if (log.isDebugEnabled()) {
            java.util.List<Attribute> attrs = element.getAttributes();
            log.debug("\tElement Has " + attrs.size() + " Attributes:");
            for (int i = 0; i < attrs.size(); i++) {
                Attribute a = attrs.get(i);
                log.debug("\t\t" + a.getName() + " = " + a.getValue());
            }
            java.util.List<Element> kids = element.getChildren();
            log.debug("\tElementHas " + kids.size() + " children:");
            for (int i = 0; i < kids.size(); i++) {
                Element e = kids.get(i);
                log.debug("\t\t" + e.getName() + " = \"" + e.getValue() + "\"");
            }
        }
        editor.loadFailed();
        return;
    }
    editor.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.LABELS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) LinkingLabel(jmri.jmrit.display.LinkingLabel) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor)

Example 40 with Attribute

use of com.android.org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.

the class ControlPanelEditorXml method load.

/**
     * Create a ControlPanelEditor object, then register and fill it, then pop
     * it in a JFrame
     *
     * @param shared Top level Element to unpack.
     * @return true if successful
     */
@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    // find coordinates
    int x = 0;
    int y = 0;
    int height = 400;
    int width = 300;
    try {
        x = shared.getAttribute("x").getIntValue();
        y = shared.getAttribute("y").getIntValue();
        height = shared.getAttribute("height").getIntValue();
        width = shared.getAttribute("width").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert ControlPanelEditor's attribute");
        result = false;
    }
    // find the name
    String name = "Control Panel";
    if (shared.getAttribute("name") != null) {
        name = shared.getAttribute("name").getValue();
    }
    // confirm that panel hasn't already been loaded
    if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(name)) {
        log.warn("File contains a panel with the same name ({}) as an existing panel", name);
        result = false;
    }
    ControlPanelEditor panel = new ControlPanelEditor(name);
    // save painting until last
    panel.getTargetFrame().setVisible(false);
    jmri.jmrit.display.PanelMenu.instance().addEditorPanel(panel);
    // Load editor option flags. This has to be done before the content 
    // items are loaded, to preserve the individual item settings
    Attribute a;
    boolean value = true;
    if ((a = shared.getAttribute("editable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllEditable(value);
    value = true;
    if ((a = shared.getAttribute("positionable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllPositionable(value);
    /*
         value = false;
         if ((a = element.getAttribute("showcoordinates"))!=null && a.getValue().equals("yes"))
         value = true;
         panel.setShowCoordinates(value);
         */
    value = true;
    if ((a = shared.getAttribute("showtooltips")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllShowTooltip(value);
    value = true;
    if ((a = shared.getAttribute("controlling")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllControlling(value);
    value = false;
    if ((a = shared.getAttribute("hide")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    panel.setShowHidden(value);
    value = true;
    if ((a = shared.getAttribute("panelmenu")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setPanelMenuVisible(value);
    value = true;
    if ((a = shared.getAttribute("shapeSelect")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setShapeSelect(value);
    if ((a = shared.getAttribute("state")) != null) {
        try {
            int xState = a.getIntValue();
            panel.setExtendedState(xState);
        } catch (org.jdom2.DataConversionException e) {
            log.error("failed to convert ControlPanelEditor's extended State");
            result = false;
        }
    }
    String state = "both";
    if ((a = shared.getAttribute("scrollable")) != null) {
        state = a.getValue();
    }
    panel.setScroll(state);
    try {
        int red = shared.getAttribute("redBackground").getIntValue();
        int blue = shared.getAttribute("blueBackground").getIntValue();
        int green = shared.getAttribute("greenBackground").getIntValue();
        panel.setBackgroundColor(new Color(red, green, blue));
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse color attributes!");
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    Element icons = shared.getChild("icons");
    /*        if (icons != null) {
            HashMap<String, NamedIcon> portalIconMap = new HashMap<String, NamedIcon>();
            portalIconMap.put(PortalIcon.VISIBLE, loadIcon("visible", icons, panel));
            portalIconMap.put(PortalIcon.PATH, loadIcon("path_edit", icons, panel));
            portalIconMap.put(PortalIcon.HIDDEN, loadIcon("hidden", icons, panel));
            portalIconMap.put(PortalIcon.TO_ARROW, loadIcon("to_arrow", icons, panel));
            portalIconMap.put(PortalIcon.FROM_ARROW, loadIcon("from_arrow", icons, panel));
            panel.setDefaultPortalIcons(portalIconMap);
        }*/
    shared.removeChild("icons");
    //set the (global) editor display widgets to their flag settings
    panel.initView();
    // load the contents
    List<Element> items = shared.getChildren();
    for (Element item : items) {
        String adapterName = item.getAttribute("class").getValue();
        log.debug("load via {}", adapterName);
        try {
            XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
            // and do it
            adapter.load(item, panel);
            if (!panel.loadOK()) {
                result = false;
            }
        } catch (Exception e) {
            log.error("Exception while loading {}: {}", item.getName(), e.getMessage(), e);
            result = false;
        }
    }
    if (icons != null) {
        HashMap<String, NamedIcon> portalIconMap = new HashMap<String, NamedIcon>();
        portalIconMap.put(PortalIcon.VISIBLE, loadIcon("visible", icons, panel));
        portalIconMap.put(PortalIcon.PATH, loadIcon("path_edit", icons, panel));
        portalIconMap.put(PortalIcon.HIDDEN, loadIcon("hidden", icons, panel));
        portalIconMap.put(PortalIcon.TO_ARROW, loadIcon("to_arrow", icons, panel));
        portalIconMap.put(PortalIcon.FROM_ARROW, loadIcon("from_arrow", icons, panel));
        panel.setDefaultPortalIcons(portalIconMap);
    }
    // dispose of url correction data
    panel.disposeLoadData();
    // display the results, with the editor in back
    panel.pack();
    panel.setAllEditable(panel.isEditable());
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(panel);
    }
    // reset the size and position, in case the display caused it to change
    panel.getTargetFrame().setLocation(x, y);
    panel.getTargetFrame().setSize(width, height);
    panel.setTitle();
    // always show the panel
    panel.getTargetFrame().setVisible(true);
    // do last to set putItem override - unused.
    panel.loadComplete();
    return result;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Attribute(org.jdom2.Attribute) HashMap(java.util.HashMap) Color(java.awt.Color) Element(org.jdom2.Element) Point(java.awt.Point) ConfigureManager(jmri.ConfigureManager) AbstractXmlAdapter(jmri.configurexml.AbstractXmlAdapter) XmlAdapter(jmri.configurexml.XmlAdapter)

Aggregations

Attribute (org.jdom2.Attribute)149 Element (org.jdom2.Element)104 IOException (java.io.IOException)31 ArrayList (java.util.ArrayList)27 Document (org.jdom2.Document)18 DataConversionException (org.jdom2.DataConversionException)16 X509Certificate (java.security.cert.X509Certificate)15 Editor (jmri.jmrit.display.Editor)15 GeneralName (org.bouncycastle.asn1.x509.GeneralName)15 Test (org.junit.Test)14 List (java.util.List)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)12 Attribute (org.bouncycastle.asn1.pkcs.Attribute)12 Extensions (org.bouncycastle.asn1.x509.Extensions)12 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)12 CertificateEncodingException (java.security.cert.CertificateEncodingException)11 Attribute (org.bouncycastle.asn1.x509.Attribute)11 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)9