00001 package org.hfbk.vis.visnode; 00002 00003 import org.dronus.graph.Node; 00004 import org.lwjgl.util.vector.Vector3f; 00005 00006 public class VisSerializer { 00007 00008 public static Node buildNode(VisNode vn){ 00009 00010 String type=vn.getClass().getSimpleName().substring(3); 00011 type=Character.toLowerCase(type.charAt(0))+type.substring(1); 00012 00013 String text; 00014 if (vn.node!=null) 00015 text=vn.node.text; 00016 else 00017 text="unnamed"; 00018 00019 Node n=new Node((text+type).hashCode(), text, type); 00020 00021 return n; 00022 } 00023 00024 public static String buildScript(VisNode vn){ 00025 Vector3f pos=vn.position; 00026 Node n=buildNode(vn); 00027 String script="node=parent.add(new "+vn.getClass().getSimpleName()+"(new Node('"+n.text+"'), new Vector3f("+pos.x+","+pos.y+","+pos.z+"));\n"; 00028 00029 return script; 00030 } 00031 00032 public static String buildTreeScript(VisNode vn){ 00033 String script=buildScript(vn); 00034 00035 if (vn.children.size()>0){ 00036 script+="parent=node;\n"; 00037 for (VisNode c: vn.children) 00038 script+=buildTreeScript(c); 00039 script+="parent=parent.parent;\n"; 00040 } 00041 return script; 00042 } 00043 00044 public static String vs(VisNode vn){ 00045 return "parent=root;\n"+buildTreeScript(vn); 00046 } 00047 } 00048