1 19 20 25 26 27 28 29 package soot.util.dot; 30 31 import java.io.*; 32 import java.util.*; 33 34 37 public class DotGraphNode implements Renderable{ 38 private String name; 39 private List attributes; 40 41 public DotGraphNode(String name) { 42 this.name = "\""+DotGraphUtility.replaceQuotes(name)+"\""; 43 } 44 45 public String getName(){ 47 return this.name; 48 } 49 50 public void setLabel(String label) { 51 label = DotGraphUtility.replaceQuotes(label); 52 label = DotGraphUtility.replaceReturns(label); 53 this.setAttribute("label", "\""+label+"\""); 54 } 55 56 public void setHTMLLabel(String label){ 57 label = DotGraphUtility.replaceReturns(label); 58 this.setAttribute("label", label); 59 } 60 61 public void setShape(String shape) { 62 this.setAttribute("shape", shape); 63 } 64 65 public void setStyle(String style) { 66 this.setAttribute("style", style); 67 } 68 69 public void setAttribute(String id, String value) { 70 if (this.attributes == null) { 71 this.attributes = new LinkedList(); 72 } 73 74 this.setAttribute(new DotGraphAttribute(id, value)); 75 } 76 77 public void setAttribute(DotGraphAttribute attr) { 78 if (this.attributes == null) { 79 this.attributes = new LinkedList(); 80 } 81 82 this.attributes.add(attr); 83 } 84 85 public void render(OutputStream out, int indent) throws IOException { 86 StringBuffer line = new StringBuffer (this.getName()); 87 if (this.attributes != null) { 88 line.append(" ["); 89 for (Iterator attrIt = this.attributes.iterator(); attrIt.hasNext(); ) { 90 DotGraphAttribute attr = (DotGraphAttribute)attrIt.next(); 91 line.append(attr.toString()); 92 line.append(","); 93 } 94 line.append("];"); 95 } 96 DotGraphUtility.renderLine(out, new String (line), indent); 97 } 98 } 99 | Popular Tags |