01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2002 Sable Research Group
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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: /* @author Feng Qian */
27:
28: package soot.util.dot;
29:
30: import java.io.*;
31: import java.util.*;
32:
33: /**
34: * A Dot graph node with various attributes.
35: */
36: public class DotGraphNode implements Renderable {
37: private String name;
38: private List<DotGraphAttribute> attributes;
39:
40: public DotGraphNode(String name) {
41: this .name = "\"" + DotGraphUtility.replaceQuotes(name) + "\"";
42: }
43:
44: // make any illegal name to be legal
45: public String getName() {
46: return this .name;
47: }
48:
49: public void setLabel(String label) {
50: label = DotGraphUtility.replaceQuotes(label);
51: label = DotGraphUtility.replaceReturns(label);
52: this .setAttribute("label", "\"" + label + "\"");
53: }
54:
55: public void setHTMLLabel(String label) {
56: label = DotGraphUtility.replaceReturns(label);
57: this .setAttribute("label", label);
58: }
59:
60: public void setShape(String shape) {
61: this .setAttribute("shape", shape);
62: }
63:
64: public void setStyle(String style) {
65: this .setAttribute("style", style);
66: }
67:
68: public void setAttribute(String id, String value) {
69: if (this .attributes == null) {
70: this .attributes = new LinkedList<DotGraphAttribute>();
71: }
72:
73: this .setAttribute(new DotGraphAttribute(id, value));
74: }
75:
76: public void setAttribute(DotGraphAttribute attr) {
77: if (this .attributes == null) {
78: this .attributes = new LinkedList<DotGraphAttribute>();
79: }
80:
81: this .attributes.add(attr);
82: }
83:
84: public void render(OutputStream out, int indent) throws IOException {
85: StringBuffer line = new StringBuffer(this .getName());
86: if (this .attributes != null) {
87: line.append(" [");
88: for (DotGraphAttribute attr : this .attributes) {
89: line.append(attr.toString());
90: line.append(",");
91: }
92: line.append("];");
93: }
94: DotGraphUtility.renderLine(out, new String(line), indent);
95: }
96: }
|