Search in sources :

Example 16 with Savable

use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.

the class DOMInputCapsule method readSavableMap.

public Map<? extends Savable, ? extends Savable> readSavableMap(String name, Map<? extends Savable, ? extends Savable> defVal) throws IOException {
    Map<Savable, Savable> ret;
    Element tempEl;
    if (name != null) {
        tempEl = findChildElement(currentElem, name);
    } else {
        tempEl = currentElem;
    }
    ret = new HashMap<Savable, Savable>();
    NodeList nodes = tempEl.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        if (n instanceof Element && n.getNodeName().equals("MapEntry")) {
            Element elem = (Element) n;
            currentElem = elem;
            Savable key = readSavable(XMLExporter.ELEMENT_KEY, null);
            Savable val = readSavable(XMLExporter.ELEMENT_VALUE, null);
            ret.put(key, val);
        }
    }
    currentElem = (Element) tempEl.getParentNode();
    return ret;
}
Also used : Savable(com.jme3.export.Savable)

Example 17 with Savable

use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.

the class J3MExporter method save.

@Override
public void save(Savable object, OutputStream f) throws IOException {
    if (!(object instanceof Material)) {
        throw new IllegalArgumentException("J3MExporter can only save com.jme3.material.Material class");
    }
    OutputStreamWriter out = new OutputStreamWriter(f, Charset.forName("UTF-8"));
    rootCapsule.clear();
    object.write(this);
    rootCapsule.writeToStream(out);
    out.flush();
}
Also used : Material(com.jme3.material.Material) OutputStreamWriter(java.io.OutputStreamWriter)

Example 18 with Savable

use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.

the class DOMInputCapsule method readSavableArrayList.

public ArrayList<Savable> readSavableArrayList(String name, ArrayList defVal) throws IOException {
    try {
        Element tmpEl = findChildElement(currentElem, name);
        if (tmpEl == null) {
            return defVal;
        }
        String sizeString = tmpEl.getAttribute("size");
        ArrayList<Savable> savables = new ArrayList<Savable>();
        for (currentElem = findFirstChildElement(tmpEl); currentElem != null; currentElem = findNextSiblingElement(currentElem)) {
            savables.add(readSavableFromCurrentElem(null));
        }
        if (sizeString.length() > 0) {
            int requiredSize = Integer.parseInt(sizeString);
            if (savables.size() != requiredSize)
                throw new IOException("Wrong number of Savable arrays for '" + name + "'.  size says " + requiredSize + ", data contains " + savables.size());
        }
        currentElem = (Element) tmpEl.getParentNode();
        return savables;
    } catch (IOException ioe) {
        throw ioe;
    } catch (Exception e) {
        IOException io = new IOException(e.toString());
        io.initCause(e);
        throw io;
    }
}
Also used : Savable(com.jme3.export.Savable) IOException(java.io.IOException) IOException(java.io.IOException)

Example 19 with Savable

use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.

the class DOMInputCapsule method readSavableArrayListArray2D.

public ArrayList<Savable>[][] readSavableArrayListArray2D(String name, ArrayList[][] defVal) throws IOException {
    try {
        Element tmpEl = findChildElement(currentElem, name);
        if (tmpEl == null) {
            return defVal;
        }
        currentElem = tmpEl;
        String sizeString = tmpEl.getAttribute("size");
        ArrayList<Savable>[] arr;
        List<ArrayList<Savable>[]> sall = new ArrayList<ArrayList<Savable>[]>();
        int i = -1;
        while ((arr = readSavableArrayListArray("SavableArrayListArray_" + ++i, null)) != null) sall.add(arr);
        if (sizeString.length() > 0) {
            int requiredSize = Integer.parseInt(sizeString);
            if (sall.size() != requiredSize)
                throw new IOException("String array contains wrong element count.  " + "Specified size " + requiredSize + ", data contains " + sall.size());
        }
        currentElem = (Element) tmpEl.getParentNode();
        return sall.toArray(new ArrayList[0][]);
    } catch (IOException ioe) {
        throw ioe;
    } catch (Exception e) {
        IOException io = new IOException(e.toString());
        io.initCause(e);
        throw io;
    }
}
Also used : Savable(com.jme3.export.Savable) IOException(java.io.IOException) IOException(java.io.IOException)

Example 20 with Savable

use of com.jme3.export.Savable in project jmonkeyengine by jMonkeyEngine.

the class DOMInputCapsule method readIntSavableMap.

public IntMap<? extends Savable> readIntSavableMap(String name, IntMap<? extends Savable> defVal) throws IOException {
    IntMap<Savable> ret = null;
    Element tempEl;
    if (name != null) {
        tempEl = findChildElement(currentElem, name);
    } else {
        tempEl = currentElem;
    }
    if (tempEl != null) {
        ret = new IntMap<Savable>();
        NodeList nodes = tempEl.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node n = nodes.item(i);
            if (n instanceof Element && n.getNodeName().equals("MapEntry")) {
                Element elem = (Element) n;
                currentElem = elem;
                int key = Integer.parseInt(currentElem.getAttribute("key"));
                Savable val = readSavable("Savable", null);
                ret.put(key, val);
            }
        }
    } else {
        return defVal;
    }
    currentElem = (Element) tempEl.getParentNode();
    return ret;
}
Also used : Savable(com.jme3.export.Savable)

Aggregations

Savable (com.jme3.export.Savable)22 IOException (java.io.IOException)8 Element (org.w3c.dom.Element)6 MatParamOverride (com.jme3.material.MatParamOverride)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputCapsule (com.jme3.export.InputCapsule)1 BinaryExporter (com.jme3.export.binary.BinaryExporter)1 BinaryImporter (com.jme3.export.binary.BinaryImporter)1 AmbientLight (com.jme3.light.AmbientLight)1 Material (com.jme3.material.Material)1 Bucket (com.jme3.renderer.queue.RenderQueue.Bucket)1 ShadowMode (com.jme3.renderer.queue.RenderQueue.ShadowMode)1 Node (com.jme3.scene.Node)1 Spatial (com.jme3.scene.Spatial)1 Control (com.jme3.scene.control.Control)1 SafeArrayList (com.jme3.util.SafeArrayList)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1