Package org.earth3d.jearth.model

Examples of org.earth3d.jearth.model.PartsObject


   
    new URLDownload(source, this, null).startDownload();
  }

  public void parse(byte result[], MapTileTreeNodeCore core) throws SAXException, IOException, ParserConfigurationException {
    PartsObject po = new PartsObject(result);
   
    String documentTest = new String(po.getParts().get(0));
    ByteArrayInputStream sr = new ByteArrayInputStream(po.getParts().get(0));
   
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(sr);
    Element docElem = doc.getDocumentElement();
   
    // get the response tag
    if (docElem.getNodeName().equalsIgnoreCase("response")) {
      // get the maptile tag
      NodeList maptileNodeList = docElem.getChildNodes();
      for(int i2=0; i2<maptileNodeList.getLength(); i2++) {
        Node maptileNode = maptileNodeList.item(i2);
        if (maptileNode.getNodeType() == Node.ELEMENT_NODE) {
          Element elemMapTile = (Element) maptileNode;
          if (elemMapTile.getTagName().equalsIgnoreCase("maptile")) {
     
            int attachment = Integer.parseInt(elemMapTile.getAttribute("attachment"));
           
            if (elemMapTile.hasAttribute("byteorder")) {
              core.setByteOrderNormal(elemMapTile.getAttribute("byteorder").equalsIgnoreCase("normal") ? true : false);
            }
           
            BufferedImage img = ImageIO.read(new ByteArrayInputStream(po.getParts().get(attachment)));
            core.setDownloadedImage(img);

            // find all submaptile tags and add them to the list
            NodeList nodes = elemMapTile.getChildNodes();
            for(int i=0; i<nodes.getLength(); i++) {
View Full Code Here


  /**
   * Writes this MapTile to the disk using the currently set filename.
   * @throws IOException
   */
  public void write(String directory) throws IOException {
    PartsObject po = new PartsObject();
   
    String xmltype, imgtype, attrs;
    if (img.getType() == BufferedImage.TYPE_USHORT_GRAY) {
      xmltype = "PNG";
      imgtype = "png";
      attrs = "byteorder=\"normal\""; // to allow the java client to differ between the old C++ generated maps and the new format
    } else {
      xmltype = "JPG";
      imgtype = "jpeg";
      attrs = "";
    }
   
    // create XML string
    String xmldocument = createXMLDocument(xmltype, attrs);
   
    // write the XML document and the attachment to the file
    po.addPart(xmldocument.getBytes());
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(img, imgtype, baos);
    po.addPart(baos.toByteArray());
   
    // write it to a file
//    System.out.println("Write "+new File(directory, getFilename()).getAbsolutePath());
    po.writeTo(new File(directory, getFilename()));
  }
View Full Code Here

   *
   * @param filename
   * @throws IOException
   */
  public void writeXML(String filename, String mapname) throws IOException {
    PartsObject po = new PartsObject();
   
    // create xml
    StringBuffer xml = new StringBuffer("<?xml version=\"1.0\"?><response><geometry type=\"maptree\" base=\"sphere\" name=\""+mapname+"\" identifier=\"planet\">");
    xml.append("<texture>");
    xml.append("<connections>");
    for(Connection conn : getTextureConnections().getConnections()) {
      xml.append(conn.getXML());
    }
    xml.append("</connections>");
    xml.append("</texture>");
    xml.append("<heightfield>");
    xml.append("<connections>");
    for(Connection conn : getHeightfieldConnections().getConnections()) {
      xml.append(conn.getXML());
    }
    xml.append("</connections>");
    xml.append("</heightfield></geometry></response>");
   
    po.addPart(xml.toString().getBytes());
    po.writeTo(new File(filename));
  }
View Full Code Here

TOP

Related Classes of org.earth3d.jearth.model.PartsObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.