Add support for six new shapes.

This commit is contained in:
Diomidis Spinellis 2007-11-29 07:00:25 +00:00
parent 747ffd0b16
commit 249c2633fb
3 changed files with 78 additions and 8 deletions

View File

@ -8,6 +8,10 @@
<li> All code now lives under <code>org.umlgraph</code>.
This change requires corresponding modifications to the UMLGraph
callers.</li>
<li> Add support for six new shapes: node, component, package, collaboration,
usecase, and activeclass.
These shapes require GraphViz 1.16 or newer.
</li>
</ul>
</dd>

View File

@ -177,6 +177,24 @@ class ClassGraph {
return s;
}
/**
* Convert embedded newlines into HTML line breaks
*/
private String htmlNewline(String s) {
if (s.indexOf('\n') == -1)
return (s);
StringBuffer sb = new StringBuffer(s);
for (int i = 0; i < sb.length();) {
if (sb.charAt(i) == '\n') {
sb.replace(i, i + 1, "<br/>");
i += "<br/>".length();
} else
i++;
}
return sb.toString();
}
/**
* Convert &lt; and &gt; characters in the string to the respective guillemot characters.
@ -349,6 +367,8 @@ class ClassGraph {
w.print(", fontname=\"" + opt.nodeFontName + "\"");
w.print(", fontcolor=\"" + opt.nodeFontColor + "\"");
w.print(", fontsize=" + opt.nodeFontSize);
if (opt.shape != null)
w.print(", shape=" + Options.graphvizShape(opt.shape));
w.println("];");
}
@ -467,7 +487,9 @@ class ClassGraph {
idx = qualifiedName.lastIndexOf('.');
else
idx = qualifiedName.lastIndexOf('.', startTemplate);
if(opt.postfixPackage && idx > 0 && idx < (qualifiedName.length() - 1)) {
if (opt.showComment)
tableLine(Align.LEFT, htmlNewline(escape(c.commentText())), opt, Font.CLASS);
else if(opt.postfixPackage && idx > 0 && idx < (qualifiedName.length() - 1)) {
String packageName = qualifiedName.substring(0, idx);
String cn = className.substring(idx + 1);
tableLine(Align.CENTER, escape(cn), opt, font);
@ -1033,8 +1055,9 @@ class ClassGraph {
String href = "";
if (url != null)
href = " href=\"" + url + "\"";
w.print("<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" "
+ "cellpadding=\"2\" port=\"p\"" + bgcolor + href + ">" + linePostfix);
w.print("<<table border=\"0\" cellborder=\"" +
(opt.shape == null ? "1" : "0") + "\" cellspacing=\"0\" " +
"cellpadding=\"2\" port=\"p\"" + bgcolor + href + ">" + linePostfix);
}
private void externalTableEnd() {
@ -1058,16 +1081,19 @@ class ClassGraph {
String open;
String close = "</td></tr>";
String prefix = linePrefix + linePrefix + linePrefix;
String alignText;
if(align == Align.CENTER)
open = prefix + "<tr><td>";
alignText = "center";
else if(align == Align.LEFT)
open = prefix + "<tr><td align=\"left\">";
alignText = "left";
else if(align == Align.RIGHT)
open = prefix + "<tr><td align=\"right\">";
alignText = "right";
else
throw new RuntimeException("Unknown alignement type " + align);
text = fontWrap(" " + text + " ", opt, font);
open = "<tr><td align=\"" + alignText + "\" balign=\"" + alignText + "\">";
w.print(open + text + close + linePostfix);
}

View File

@ -77,6 +77,7 @@ public class Options implements Cloneable, OptionProvider {
boolean showVisibility;
boolean horizontal;
boolean showType;
boolean showComment;
String edgeFontName;
String edgeFontColor;
String edgeColor;
@ -93,6 +94,7 @@ public class Options implements Cloneable, OptionProvider {
String nodeFontTagName;
double nodeFontPackageSize;
String nodeFontPackageName;
String shape;
String bgColor;
public String outputFileName;
String outputEncoding;
@ -134,6 +136,7 @@ public class Options implements Cloneable, OptionProvider {
showEnumerations = false;
showConstructors = false;
showType = false;
showComment = false;
edgeFontName = defaultFont;
edgeFontColor = "black";
edgeColor = "black";
@ -151,6 +154,7 @@ public class Options implements Cloneable, OptionProvider {
nodeFontPackageName = null;
nodeFillColor = null;
bgColor = null;
shape = null;
outputFileName = "graph.dot";
outputDirectory= null;
outputEncoding = "ISO-8859-1";
@ -211,6 +215,7 @@ public class Options implements Cloneable, OptionProvider {
option.equals("-constructors") ||
option.equals("-visibility") ||
option.equals("-types") ||
option.equals("-commentname") ||
option.equals("-all") ||
option.equals("-postfixpackage") ||
option.equals("-noguillemot") ||
@ -240,6 +245,7 @@ public class Options implements Cloneable, OptionProvider {
option.equals("-edgecolor") ||
option.equals("-edgefontsize") ||
option.equals("-edgefontname") ||
option.equals("-shape") ||
option.equals("-output") ||
option.equals("-outputencoding") ||
option.equals("-bgcolor") ||
@ -302,6 +308,10 @@ public class Options implements Cloneable, OptionProvider {
showType = true;
} else if (opt[0].equals("-!types")) {
showType = false;
} else if(opt[0].equals("-commentname")) {
showComment = true;
} else if (opt[0].equals("-!commentname")) {
showComment = false;
} else if(opt[0].equals("-all")) {
setAll();
} else if(opt[0].equals("-bgcolor")) {
@ -372,6 +382,15 @@ public class Options implements Cloneable, OptionProvider {
nodeFillColor = opt[1];
} else if (opt[0].equals("-!nodefillcolor")) {
nodeFillColor = null;
} else if(opt[0].equals("-shape")) {
if (graphvizShape(opt[1]) != null)
shape = opt[1];
else {
System.err.println("Ignoring invalid shape " + opt[1]);
shape = null;
}
} else if (opt[0].equals("-!shape")) {
shape = null;
} else if(opt[0].equals("-output")) {
outputFileName = opt[1];
} else if (opt[0].equals("-!output")) {
@ -694,6 +713,27 @@ public class Options implements Cloneable, OptionProvider {
}
return sb.toString();
}
}
/**
* Return the Graphviz shape corresponding to the specified UML shape
* If the shape is return null.
*/
public static String graphvizShape(String s) {
if (s.equals("node"))
return "box3d";
else if (s.equals("component"))
return "component";
else if (s.equals("package"))
return "tab";
else if (s.equals("collaboration"))
return "ellipse, style=dashed";
else if (s.equals("note"))
return "note";
else if (s.equals("usecase"))
return "ellipse";
else if (s.equals("activeclass"))
return "box, style=bold";
else
return null;
}
}