Search in sources :

Example 51 with Text

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

the class SlipTurnoutIconXml method loadTurnoutIcon.

private void loadTurnoutIcon(String state, int rotation, SlipTurnoutIcon l, Element element, Editor ed) {
    NamedIcon icon = loadIcon(l, state, element, "SlipTurnout \"" + l.getNameString() + "\" icon \"" + state + "\" ", ed);
    String textValue = null;
    if (icon != null) {
        if (state.equals("lowerWestToUpperEast")) {
            l.setLowerWestToUpperEastIcon(icon);
        } else if (state.equals("upperWestToLowerEast")) {
            l.setUpperWestToLowerEastIcon(icon);
        } else if (state.equals("lowerWestToLowerEast")) {
            l.setLowerWestToLowerEastIcon(icon);
        } else if (state.equals("upperWestToUpperEast")) {
            l.setUpperWestToUpperEastIcon(icon);
        } else if (state.equals("unknown")) {
            l.setUnknownIcon(icon);
        } else if (state.equals("inconsistent")) {
            l.setInconsistentIcon(icon);
        }
    } else {
        return;
    }
    Element elem = element.getChild(state);
    if (elem != null) {
        Element e = elem.getChild("text");
        if (e != null) {
            textValue = e.getText();
        }
    }
    if (textValue != null) {
        if (state.equals("lowerWestToUpperEast")) {
            l.setLWUEText(textValue);
        } else if (state.equals("upperWestToLowerEast")) {
            l.setUWLEText(textValue);
        } else if (state.equals("lowerWestToLowerEast")) {
            l.setLWLEText(textValue);
        } else if (state.equals("upperWestToUpperEast")) {
            l.setUWUEText(textValue);
        }
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Element(org.jdom2.Element)

Example 52 with Text

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

the class SensorIconXml method loadSensorTextState.

private void loadSensorTextState(String state, SensorIcon l, Element element) {
    String name = null;
    Color clrText = null;
    Color clrBackground = null;
    List<Element> textList = element.getChildren(state.toLowerCase() + "Text");
    if (log.isDebugEnabled()) {
        log.debug("Found " + textList.size() + " " + state + "Text objects");
    }
    if (textList.size() > 0) {
        Element elem = textList.get(0);
        try {
            name = elem.getAttribute("text").getValue();
        } catch (NullPointerException e) {
        // considered normal if the attributes are not present
        }
        try {
            int red = elem.getAttribute("red").getIntValue();
            int blue = elem.getAttribute("blue").getIntValue();
            int green = elem.getAttribute("green").getIntValue();
            clrText = 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
        }
        try {
            int red = elem.getAttribute("redBack").getIntValue();
            int blue = elem.getAttribute("blueBack").getIntValue();
            int green = elem.getAttribute("greenBack").getIntValue();
            clrBackground = 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
        }
    } else {
        if (element.getAttribute(state.toLowerCase()) != null) {
            name = element.getAttribute(state.toLowerCase()).getValue();
        }
        try {
            int red = element.getAttribute("red" + state).getIntValue();
            int blue = element.getAttribute("blue" + state).getIntValue();
            int green = element.getAttribute("green" + state).getIntValue();
            clrText = 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
        }
        try {
            int red = element.getAttribute("red" + state + "Back").getIntValue();
            int blue = element.getAttribute("blue" + state + "Back").getIntValue();
            int green = element.getAttribute("green" + state + "Back").getIntValue();
            clrBackground = 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
        }
    }
    if (state.equals("Active")) {
        if (name != null) {
            l.setActiveText(name);
        }
        if (clrText != null) {
            l.setTextActive(clrText);
        }
        if (clrBackground != null) {
            l.setBackgroundActive(clrBackground);
        }
    } else if (state.equals("InActive")) {
        if (name != null) {
            l.setInactiveText(name);
        }
        if (clrText != null) {
            l.setTextInActive(clrText);
        }
        if (clrBackground != null) {
            l.setBackgroundInActive(clrBackground);
        }
    } else if (state.equals("Unknown")) {
        if (name != null) {
            l.setUnknownText(name);
        }
        if (clrText != null) {
            l.setTextUnknown(clrText);
        }
        if (clrBackground != null) {
            l.setBackgroundUnknown(clrBackground);
        }
    } else if (state.equals("Inconsistent")) {
        if (name != null) {
            l.setInconsistentText(name);
        }
        if (clrText != null) {
            l.setTextInconsistent(clrText);
        }
        if (clrBackground != null) {
            l.setBackgroundInconsistent(clrBackground);
        }
    }
}
Also used : Color(java.awt.Color) Element(org.jdom2.Element)

Example 53 with Text

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

the class SensorIconXml method storeTextInfo.

protected void storeTextInfo(SensorIcon p, Element element) {
    if (p.getText() == null) {
        String s = p.getOriginalText();
        if (s != null && s.length() > 0) {
            element.setAttribute("text", s);
        } else if (p.isText()) {
            element.setAttribute("text", "");
        } else {
            return;
        }
    } else {
        element.setAttribute("text", p.getText());
    }
    // get iconic overlay text info
    super.storeTextInfo(p, element);
    // get state textual info
    Element textElement = new Element("activeText");
    if (p.getActiveText() != null) {
        textElement.setAttribute("text", p.getActiveText());
    }
    // always write text color
    textElement.setAttribute("red", "" + p.getTextActive().getRed());
    textElement.setAttribute("green", "" + p.getTextActive().getGreen());
    textElement.setAttribute("blue", "" + p.getTextActive().getBlue());
    if (p.getBackgroundActive() != null) {
        textElement.setAttribute("redBack", "" + p.getBackgroundActive().getRed());
        textElement.setAttribute("greenBack", "" + p.getBackgroundActive().getGreen());
        textElement.setAttribute("blueBack", "" + p.getBackgroundActive().getBlue());
    }
    element.addContent(textElement);
    textElement = new Element("inactiveText");
    if (p.getInactiveText() != null) {
        textElement.setAttribute("text", p.getInactiveText());
    }
    // always write text color
    textElement.setAttribute("red", "" + p.getTextInActive().getRed());
    textElement.setAttribute("green", "" + p.getTextInActive().getGreen());
    textElement.setAttribute("blue", "" + p.getTextInActive().getBlue());
    if (p.getBackgroundInActive() != null) {
        textElement.setAttribute("redBack", "" + p.getBackgroundInActive().getRed());
        textElement.setAttribute("greenBack", "" + p.getBackgroundInActive().getGreen());
        textElement.setAttribute("blueBack", "" + p.getBackgroundInActive().getBlue());
    }
    element.addContent(textElement);
    textElement = new Element("unknownText");
    if (p.getUnknownText() != null) {
        textElement.setAttribute("text", p.getUnknownText());
    }
    // always write text color
    textElement.setAttribute("red", "" + p.getTextUnknown().getRed());
    textElement.setAttribute("green", "" + p.getTextUnknown().getGreen());
    textElement.setAttribute("blue", "" + p.getTextUnknown().getBlue());
    if (p.getBackgroundUnknown() != null) {
        textElement.setAttribute("redBack", "" + p.getBackgroundUnknown().getRed());
        textElement.setAttribute("greenBack", "" + p.getBackgroundUnknown().getGreen());
        textElement.setAttribute("blueBack", "" + p.getBackgroundUnknown().getBlue());
    }
    element.addContent(textElement);
    textElement = new Element("inconsistentText");
    if (p.getInconsistentText() != null) {
        textElement.setAttribute("text", p.getInconsistentText());
    }
    // always write text color
    textElement.setAttribute("red", "" + p.getTextInconsistent().getRed());
    textElement.setAttribute("green", "" + p.getTextInconsistent().getGreen());
    textElement.setAttribute("blue", "" + p.getTextInconsistent().getBlue());
    if (p.getBackgroundInconsistent() != null) {
        textElement.setAttribute("redBack", "" + p.getBackgroundInconsistent().getRed());
        textElement.setAttribute("greenBack", "" + p.getBackgroundInconsistent().getGreen());
        textElement.setAttribute("blueBack", "" + p.getBackgroundInconsistent().getBlue());
    }
    element.addContent(textElement);
}
Also used : Element(org.jdom2.Element)

Example 54 with Text

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

the class LocationManagerXml method writeFile.

@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    log.debug("writeFile {}", name);
    // This is taken in large part from "Java and XML" page 368
    File file = findFile(name);
    if (file == null) {
        file = new File(name);
    }
    // create root element
    // NOI18N
    Element root = new Element("operations-config");
    // NOI18N
    Document doc = newDocument(root, dtdLocation + "operations-locations.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    // NOI18N
    m.put("type", "text/xsl");
    // NOI18N
    m.put("href", xsltLocation + "operations-locations.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    LocationManager.instance().store(root);
    ScheduleManager.instance().store(root);
    writeXML(file, doc);
    // done - location file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 55 with Text

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

the class CarManagerXml method writeFile.

@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    log.debug("writeFile {}", name);
    // This is taken in large part from "Java and XML" page 368
    File file = findFile(name);
    if (file == null) {
        file = new File(name);
    }
    // create root element
    // NOI18N
    Element root = new Element("operations-config");
    // NOI18N
    Document doc = newDocument(root, dtdLocation + "operations-cars.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    // NOI18N
    m.put("type", "text/xsl");
    // NOI18N
    m.put("href", xsltLocation + "operations-cars.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    // note all comments line feeds have been changed to processor directives
    CarRoads.instance().store(root);
    CarTypes.instance().store(root);
    CarColors.instance().store(root);
    CarLengths.instance().store(root);
    CarOwners.instance().store(root);
    CarLoads.instance().store(root);
    CarManager.instance().store(root);
    writeXML(file, doc);
    // done - car file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Aggregations

Element (org.jdom2.Element)83 Document (org.jdom2.Document)36 File (java.io.File)21 ProcessingInstruction (org.jdom2.ProcessingInstruction)17 IOException (java.io.IOException)14 Text (org.jdom2.Text)12 Attribute (org.jdom2.Attribute)11 XMLOutputter (org.jdom2.output.XMLOutputter)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 XmlFile (jmri.jmrit.XmlFile)9 ArrayList (java.util.ArrayList)6 JDOMException (org.jdom2.JDOMException)6 StringWriter (java.io.StringWriter)5 NamedIcon (jmri.jmrit.catalog.NamedIcon)5 FileOutputStream (java.io.FileOutputStream)4 LinkedHashMap (java.util.LinkedHashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)3 Locale (java.util.Locale)3