package uk.ac.reload.editor.style;

import java.awt.Color;
import java.awt.Font;
import java.io.File;
import org.jdom.Element;

public final class StyleXMLUtils {

    private StyleXMLUtils() {
    }

    public static Element getFileElement(Value filevalue, Element styleelement) {

        Element e = new Element(filevalue.getXMLTag()).setText(((File) (filevalue.getValue())).getName());
        e.setNamespace(styleelement.getNamespace());
        return e;
    }

    public static Element getFontElement(Value fontvalue, Element styleelement) {

        Element e = new Element(fontvalue.getXMLTag());
        Font font = (Font) fontvalue.getValue();
        Element ename = new Element("name").setText(font.getFontName());
         ename.setNamespace(styleelement.getNamespace());
        Element efontstyle = new Element("fontstyle").setText(new Integer(font.getStyle()).toString());
         efontstyle.setNamespace(styleelement.getNamespace());
         Element esize = new Element("size").setText(new Integer(font.getSize()).toString());
         esize.setNamespace(styleelement.getNamespace());
         e.addContent(ename);
        e.addContent(efontstyle);
        e.addContent(esize);
        e.setNamespace(styleelement.getNamespace());
        return e;

    }

    public static Element getColorElement(Value colorvalue, Element styleelement) {
        Element e = new Element(colorvalue.getXMLTag());
        Color color = (Color) colorvalue.getValue();
        Element er = new Element("r").setText(new Integer(color.getRed()).toString());
         er.setNamespace(styleelement.getNamespace());
        Element eg = new Element("g").setText(new Integer(color.getGreen()).toString());
         eg.setNamespace(styleelement.getNamespace());
        Element eb = new Element("b").setText(new Integer(color.getBlue()).toString());
         eb.setNamespace(styleelement.getNamespace());
        e.addContent(er);
        e.addContent(eg);
        e.addContent(eb);
 e.setNamespace(styleelement.getNamespace());
        return e;
    }
}
