KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > util > dot > DotGraphNode


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2002 Sable Research Group
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27 /* @author Feng Qian */
28
29 package soot.util.dot;
30
31 import java.io.*;
32 import java.util.*;
33
34 /**
35  * A Dot graph node with various attributes.
36  */

37 public class DotGraphNode implements Renderable{
38   private String JavaDoc name;
39   private List attributes;
40
41   public DotGraphNode(String JavaDoc name) {
42     this.name = "\""+DotGraphUtility.replaceQuotes(name)+"\"";
43   }
44
45   // make any illegal name to be legal
46
public String JavaDoc getName(){
47     return this.name;
48   }
49
50   public void setLabel(String JavaDoc label) {
51     label = DotGraphUtility.replaceQuotes(label);
52     label = DotGraphUtility.replaceReturns(label);
53     this.setAttribute("label", "\""+label+"\"");
54   }
55
56   public void setHTMLLabel(String JavaDoc label){
57     label = DotGraphUtility.replaceReturns(label);
58     this.setAttribute("label", label);
59   }
60   
61   public void setShape(String JavaDoc shape) {
62     this.setAttribute("shape", shape);
63   }
64
65   public void setStyle(String JavaDoc style) {
66     this.setAttribute("style", style);
67   }
68
69   public void setAttribute(String JavaDoc id, String JavaDoc 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 JavaDoc line = new StringBuffer JavaDoc(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 JavaDoc(line), indent);
97   }
98 }
99
Popular Tags