1 package org.antlr.xjlib.appkit.gview.utils; 2 3 import org.antlr.xjlib.appkit.gview.base.Vector2D; 4 import org.antlr.xjlib.appkit.gview.object.GElement; 5 import org.antlr.xjlib.appkit.gview.object.GElementCircle; 6 import org.antlr.xjlib.appkit.gview.object.GLink; 7 8 import java.io.IOException ; 9 39 40 public class GDOTImporterPlain extends GDOTImporter { 41 42 public static int factor = 80; 43 44 public GElement parseLine(String line) throws IOException { 45 48 49 String [] tokens = parseTokens(line); 50 if(tokens[0].equals("graph")) 51 height = Float.parseFloat(tokens[3]); 52 else if(tokens[0].equals("node")) 53 return createGraphNode(tokens); 54 else if(tokens[0].equals("edge")) 55 return createGraphEdge(tokens); 56 58 return null; 59 } 60 61 public GElement createGraphNode(String [] tokens) { 62 66 67 float x = Float.parseFloat(tokens[2])*factor; 68 float y = (height - Float.parseFloat(tokens[3]))*factor; 69 float w = Float.parseFloat(tokens[4])*factor; 70 float h = Float.parseFloat(tokens[5])*factor; 71 72 Node node = new Node(); 73 node.setDraggable(true); 74 node.setPosition(x, y); 75 node.setSize(w, h); 76 node.setRadius(w/2); 77 node.setLabel(tokens[6]); 78 node.setDouble(tokens[8].equals("doublecircle")); 79 80 return node; 81 } 82 83 public GElement createGraphEdge(String [] tokens) { 84 89 int controlCount = (int) Float.parseFloat(tokens[3]); 90 Vector2D points[] = new Vector2D[controlCount]; 91 for(int index=0; index<controlCount; index++) { 92 points[index] = new Vector2D(Float.parseFloat(tokens[4+index*2])*factor, 93 (height-Float.parseFloat(tokens[4+index*2+1]))*factor); 94 } 95 96 int labelIndex = 3+2*controlCount+1; 97 String label = null; 98 Vector2D labelPosition = null; 99 if(isFloatString(tokens[labelIndex+1])) { 100 label = tokens[labelIndex]; 102 labelPosition = new Vector2D(Float.parseFloat(tokens[labelIndex+1])*factor, 103 (height-Float.parseFloat(tokens[labelIndex+2]))*factor); 104 } 105 106 GElement source = graph.findElementWithLabel(tokens[1]); 107 GElement target = graph.findElementWithLabel(tokens[2]); 108 109 GLink link = new GLink(source, GElementCircle.ANCHOR_CENTER, 110 target, GElementCircle.ANCHOR_CENTER, 111 GLink.SHAPE_BEZIER, label, 0); 112 113 link.setBezierControlPoints(points); 114 link.setBezierLabelPosition(labelPosition); 115 116 return link; 117 } 118 119 } 120 | Popular Tags |