1 19 20 25 26 27 28 package soot.util.dot; 29 30 import java.io.*; 31 import java.util.*; 32 33 36 public class DotGraphEdge implements Renderable { 37 private boolean isDirected; 38 private DotGraphNode start, end; 39 private List attributes; 40 41 46 public DotGraphEdge(DotGraphNode src, DotGraphNode dst){ 47 this.start = src; 48 this.end = dst; 49 this.isDirected = true; 50 } 51 52 58 public DotGraphEdge(DotGraphNode src, DotGraphNode dst, boolean directed){ 59 this.start = src; 60 this.end = dst; 61 this.isDirected = directed; 62 } 63 64 68 public void setLabel(String label){ 69 label = DotGraphUtility.replaceQuotes(label); 70 label = DotGraphUtility.replaceReturns(label); 71 this.setAttribute("label", "\""+label+"\""); 72 } 73 74 79 public void setStyle(String style){ 80 this.setAttribute("style", style); 81 } 82 83 88 public void setAttribute(String id, String value) { 89 this.setAttribute(new DotGraphAttribute(id, value)); 90 } 91 92 97 public void setAttribute(DotGraphAttribute attr) { 98 if (this.attributes == null) { 99 this.attributes = new LinkedList(); 100 } 101 102 this.attributes.add(attr); 103 } 104 105 public void render(OutputStream out, int indent) throws IOException { 106 StringBuffer line = new StringBuffer (start.getName()); 107 line.append((this.isDirected)?"->":"--"); 108 line.append(end.getName()); 109 110 if (this.attributes != null) { 111 112 line.append(" ["); 113 Iterator attrIt = this.attributes.iterator(); 114 while (attrIt.hasNext()) { 115 DotGraphAttribute attr = (DotGraphAttribute)attrIt.next(); 116 line.append(attr.toString()); 117 line.append(","); 118 } 119 line.append("]"); 120 } 121 122 line.append(";"); 123 124 DotGraphUtility.renderLine(out, new String (line), indent); 125 } 126 } 127 128 | Popular Tags |