Search in sources :

Example 56 with DataConversionException

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

the class PanelEditorXml method load.

/**
     * Create a PanelEditor 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 PanelEditor's attribute");
        result = false;
    }
    // find the name
    String name = "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 (" + name + ") as an existing panel");
        result = false;
    }
    PanelEditor panel = new PanelEditor(name);
    //panel.makeFrame(name);
    jmri.jmrit.display.PanelMenu.instance().addEditorPanel(panel);
    panel.getTargetFrame().setLocation(x, y);
    panel.getTargetFrame().setSize(width, height);
    panel.setTitle();
    // 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);
    String state = "both";
    if ((a = shared.getAttribute("scrollable")) != null) {
        state = a.getValue();
    }
    panel.setScroll(state);
    // set color if needed
    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
    }
    //set the (global) editor display widgets to their flag settings
    panel.initView();
    // load the contents with their individual option settings
    List<Element> items = shared.getChildren();
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        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);
            result = false;
            e.printStackTrace();
        }
    }
    // dispose of url correction data
    panel.disposeLoadData();
    // display the results, with the editor in back
    panel.pack();
    panel.setAllEditable(panel.isEditable());
    // we don't pack the target frame here, because size was specified
    // TODO: Work out why, when calling this method, panel size is increased
    // vertically (at least on MS Windows)
    // always show the panel
    panel.getTargetFrame().setVisible(true);
    // 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);
    return result;
}
Also used : Attribute(org.jdom2.Attribute) Color(java.awt.Color) Element(org.jdom2.Element) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor) Point(java.awt.Point) ConfigureManager(jmri.ConfigureManager) AbstractXmlAdapter(jmri.configurexml.AbstractXmlAdapter) XmlAdapter(jmri.configurexml.XmlAdapter)

Example 57 with DataConversionException

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

the class Control method load.

public static void load(Element e) {
    Element eControl = e.getChild(Xml.CONTROL);
    if (eControl == null) {
        return;
    }
    Element backwardCompatibility = eControl.getChild(Xml.BACKWARD_COMPATIBILITY);
    if (backwardCompatibility != null) {
        Attribute format;
        if ((format = backwardCompatibility.getAttribute(Xml.SAVE_USING_PRE_2013_FORMAT)) != null) {
            backwardCompatible = format.getValue().equals(Xml.TRUE);
        }
    }
    Element maximumStringLengths = eControl.getChild(Xml.MAXIMUM_STRING_LENGTHS);
    if (maximumStringLengths != null) {
        Attribute length;
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ATTRIBUTE) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ATTRIBUTE).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_attibute = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ROAD_NUMBER) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ROAD_NUMBER).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_road_number = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_PRINT_ROAD_NUMBER) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_PRINT_ROAD_NUMBER).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_print_road_number = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_LOCATION_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_LOCATION_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_location_name = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRACK_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRACK_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_track_name = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRACK_LENGTH_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRACK_LENGTH_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_track_length_name = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_LENGTH_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_LENGTH_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_length_name = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_WEIGHT_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_WEIGHT_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_weight_name = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_BUILT_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_BUILT_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_built_name = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRAIN_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_TRAIN_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_train_name = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ROUTE_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_ROUTE_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_route_name = Integer.parseInt(length.getValue());
        }
        if ((maximumStringLengths.getChild(Xml.MAX_LEN_STRING_AUTOMATION_NAME) != null) && (length = maximumStringLengths.getChild(Xml.MAX_LEN_STRING_AUTOMATION_NAME).getAttribute(Xml.LENGTH)) != null) {
            max_len_string_automation_name = Integer.parseInt(length.getValue());
        }
    }
    Element eReports = eControl.getChild(Xml.REPORTS);
    if (eReports != null) {
        Attribute a;
        if ((a = eReports.getAttribute(Xml.FONT_SIZE)) != null) {
            try {
                reportFontSize = a.getIntValue();
            } catch (DataConversionException e1) {
                log.error("Report font size ({}) isn't a number", a.getValue());
            }
        }
        if ((a = eReports.getAttribute(Xml.FONT_NAME)) != null) {
            reportFontName = a.getValue();
        }
    }
    Element eActions = eControl.getChild(Xml.ACTIONS);
    if (eActions != null) {
        Attribute a;
        if ((a = eActions.getAttribute(Xml.EXCEL_WAIT_TIME)) != null) {
            try {
                excelWaitTime = a.getIntValue();
            } catch (DataConversionException e1) {
                log.error("Excel wait time ({}) isn't a number", a.getValue());
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) DataConversionException(org.jdom2.DataConversionException)

Example 58 with DataConversionException

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

the class BlockBossLogicXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    List<Element> l = shared.getChildren("signalelement");
    // this is for backward compatibility only
    if (l.size() == 0) {
        l = shared.getChildren("block");
    }
    // process each item
    for (int i = 0; i < l.size(); i++) {
        Element block = l.get(i);
        BlockBossLogic bb = null;
        try {
            bb = BlockBossLogic.getStoppedObject(block.getAttributeValue("signal"));
        } catch (java.lang.Exception e) {
            log.error("An error occured trying to find the signal for the signal elements for " + block.getAttributeValue("signal"));
            result = false;
        }
        if (bb != null) {
            if (block.getAttribute("approachsensor1") != null) {
                try {
                    bb.setApproachSensor1(block.getAttributeValue("approachsensor1"));
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured loading the approach sensor for the signal elements for " + bb.getDrivenSignal());
                    result = false;
                }
            }
            if (block.getAttribute("watchedsensor") != null) {
                // for older XML files
                try {
                    bb.setSensor1(block.getAttributeValue("watchedsensor"));
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured loading the watched sensor in the SSL for " + bb.getDrivenSignal());
                    result = false;
                }
            }
            // old form of sensors with system names
            List<Element> sl = block.getChildren("sensor");
            try {
                if (sl.size() >= 1 && sl.get(0) != null) {
                    bb.setSensor1(sl.get(0).getAttributeValue("systemName"));
                }
                if (sl.size() >= 2 && sl.get(1) != null) {
                    bb.setSensor2(sl.get(1).getAttributeValue("systemName"));
                }
                if (sl.size() >= 3 && sl.get(2) != null) {
                    bb.setSensor3(sl.get(2).getAttributeValue("systemName"));
                }
                if (sl.size() >= 4 && sl.get(3) != null) {
                    bb.setSensor4(sl.get(3).getAttributeValue("systemName"));
                }
                if (sl.size() >= 5 && sl.get(4) != null) {
                    bb.setSensor5(sl.get(4).getAttributeValue("systemName"));
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensors list in the SSL");
                result = false;
            }
            // new form of sensors with system names
            sl = block.getChildren("sensorname");
            try {
                if (sl.size() >= 1 && sl.get(0) != null) {
                    bb.setSensor1(sl.get(0).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor1 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                if (sl.size() >= 2 && sl.get(1) != null) {
                    bb.setSensor2(sl.get(1).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor2 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                if (sl.size() >= 3 && sl.get(2) != null) {
                    bb.setSensor3(sl.get(2).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor3 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                if (sl.size() >= 4 && sl.get(3) != null) {
                    bb.setSensor4(sl.get(3).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor4 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                if (sl.size() >= 5 && sl.get(4) != null) {
                    bb.setSensor5(sl.get(4).getText());
                }
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured loading the sensor5 list in the SSL for " + bb.getDrivenSignal());
                result = false;
            }
            try {
                bb.setMode(block.getAttribute("mode").getIntValue());
                if (block.getAttribute("distantsignal") != null) {
                    bb.setDistantSignal(block.getAttribute("distantsignal").getBooleanValue());
                }
                if (block.getAttribute("limitspeed1") != null) {
                    bb.setLimitSpeed1(block.getAttribute("limitspeed1").getBooleanValue());
                }
                if (block.getAttribute("limitspeed2") != null) {
                    bb.setLimitSpeed2(block.getAttribute("limitspeed2").getBooleanValue());
                }
                try {
                    if (block.getAttribute("watchedturnout") != null) {
                        bb.setTurnout(block.getAttributeValue("watchedturnout"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched turnout (" + block.getAttributeValue("watchedturnout") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsignal1") != null) {
                        bb.setWatchedSignal1(block.getAttributeValue("watchedsignal1"), block.getAttribute("useflashyellow").getBooleanValue());
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched signal 1 (" + block.getAttributeValue("watchedsignal1") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsignal1alt") != null) {
                        bb.setWatchedSignal1Alt(block.getAttributeValue("watchedsignal1alt"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched signal 1 alt (" + block.getAttributeValue("watchedsignal1alt") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsignal2") != null) {
                        bb.setWatchedSignal2(block.getAttributeValue("watchedsignal2"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched signal 2 (" + block.getAttributeValue("watchedsignal2") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsignal2alt") != null) {
                        bb.setWatchedSignal2Alt(block.getAttributeValue("watchedsignal2alt"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched signal 2 alt (" + block.getAttributeValue("watchedsignal2alt") + ") element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsensor1") != null) {
                        bb.setWatchedSensor1(block.getAttributeValue("watchedsensor1"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched sensor 1 (" + block.getAttributeValue("watchedsensor1") + ") element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsensor1alt") != null) {
                        bb.setWatchedSensor1Alt(block.getAttributeValue("watchedsensor1alt"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched sensor 1 alt (" + block.getAttributeValue("watchedsensor1alt") + ") element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsensor2") != null) {
                        bb.setWatchedSensor2(block.getAttributeValue("watchedsensor2"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched sensor 2 (" + block.getAttributeValue("watchedsensor2") + ") element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                try {
                    if (block.getAttribute("watchedsensor2alt") != null) {
                        bb.setWatchedSensor2Alt(block.getAttributeValue("watchedsensor2alt"));
                    }
                } catch (java.lang.IllegalArgumentException e) {
                    log.error("An error occured in retrieving the watched sensor 2 alt (" + block.getAttributeValue("watchedsensor2alt") + ")element attribute list for " + bb.getDrivenSignal());
                    result = false;
                }
                // load comment, if present
                String c = block.getChildText("comment");
                if (c != null) {
                    bb.setComment(c);
                }
            } catch (org.jdom2.DataConversionException e) {
                log.warn("error reading blocks from file" + e);
                result = false;
            } catch (java.lang.IllegalArgumentException e) {
                log.error("An error occured in the signal element attribute list");
                result = false;
            }
            try {
                bb.retain();
                bb.start();
            } catch (java.lang.NullPointerException e) {
                log.error("An error occured trying to start the signal logic " + bb.getDrivenSignal());
                result = false;
            }
        }
    }
    return result;
}
Also used : BlockBossLogic(jmri.jmrit.blockboss.BlockBossLogic) Element(org.jdom2.Element)

Example 59 with DataConversionException

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

the class VariableTableModel method processSpeedTableVal.

protected VariableValue processSpeedTableVal(Element child, String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, String name, String comment, boolean opsOnly, String mask, String item) throws NumberFormatException {
    VariableValue v;
    Attribute a;
    int minVal = 0;
    int maxVal = 255;
    if ((a = child.getAttribute("min")) != null) {
        minVal = Integer.valueOf(a.getValue()).intValue();
    }
    if ((a = child.getAttribute("max")) != null) {
        maxVal = Integer.valueOf(a.getValue()).intValue();
    }
    Attribute entriesAttr = child.getAttribute("entries");
    int entries = 28;
    try {
        if (entriesAttr != null) {
            entries = entriesAttr.getIntValue();
        }
    } catch (org.jdom2.DataConversionException e1) {
    }
    Attribute ESUAttr = child.getAttribute("mfx");
    boolean mfxFlag = false;
    try {
        if (ESUAttr != null) {
            mfxFlag = ESUAttr.getBooleanValue();
        }
    } catch (org.jdom2.DataConversionException e1) {
    }
    // ensure all CVs exist
    for (int i = 0; i < entries; i++) {
        _cvModel.addCV(Integer.toString(Integer.parseInt(CV) + i), readOnly, infoOnly, writeOnly);
    }
    if (mfxFlag) {
        _cvModel.addCV("2", readOnly, infoOnly, writeOnly);
        _cvModel.addCV("5", readOnly, infoOnly, writeOnly);
    }
    v = new SpeedTableVarValue(name, comment, "", readOnly, infoOnly, writeOnly, opsOnly, CV, mask, minVal, maxVal, _cvModel.allCvMap(), _status, item, entries, mfxFlag);
    return v;
}
Also used : Attribute(org.jdom2.Attribute)

Example 60 with DataConversionException

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

the class PositionFile method maxReceiver.

/**
     * FInd the highest numbered receiver in the file
     */
public int maxReceiver() {
    List<Element> kids = root.getChildren("receiver");
    int max = -1;
    for (int i = 0; i < kids.size(); i++) {
        Attribute a = kids.get(i).getAttribute("number");
        if (a == null) {
            continue;
        }
        int n = -1;
        try {
            n = a.getIntValue();
        } catch (org.jdom2.DataConversionException e) {
            log.error("in maxReceiver", e);
        }
        max = Math.max(max, n);
    }
    return max;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)49 Attribute (org.jdom2.Attribute)48 DataConversionException (org.jdom2.DataConversionException)18 Editor (jmri.jmrit.display.Editor)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)11 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)9 Color (java.awt.Color)7 Point2D (java.awt.geom.Point2D)6 Point (java.awt.Point)5 ConfigureManager (jmri.ConfigureManager)4 AbstractXmlAdapter (jmri.configurexml.AbstractXmlAdapter)4 XmlAdapter (jmri.configurexml.XmlAdapter)4 DataElement (pcgen.core.doomsdaybook.DataElement)4 Block (jmri.Block)3 Memory (jmri.Memory)3 SignalHead (jmri.SignalHead)3 Turnout (jmri.Turnout)3 Portal (jmri.jmrit.logix.Portal)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SortOrder (javax.swing.SortOrder)2