mirror of https://github.com/dspinellis/UMLGraph
Add support for six new shapes.
This commit is contained in:
parent
747ffd0b16
commit
249c2633fb
|
|
@ -8,6 +8,10 @@
|
||||||
<li> All code now lives under <code>org.umlgraph</code>.
|
<li> All code now lives under <code>org.umlgraph</code>.
|
||||||
This change requires corresponding modifications to the UMLGraph
|
This change requires corresponding modifications to the UMLGraph
|
||||||
callers.</li>
|
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>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,24 @@ class ClassGraph {
|
||||||
return s;
|
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 < and > characters in the string to the respective guillemot characters.
|
* Convert < and > characters in the string to the respective guillemot characters.
|
||||||
|
|
@ -349,6 +367,8 @@ class ClassGraph {
|
||||||
w.print(", fontname=\"" + opt.nodeFontName + "\"");
|
w.print(", fontname=\"" + opt.nodeFontName + "\"");
|
||||||
w.print(", fontcolor=\"" + opt.nodeFontColor + "\"");
|
w.print(", fontcolor=\"" + opt.nodeFontColor + "\"");
|
||||||
w.print(", fontsize=" + opt.nodeFontSize);
|
w.print(", fontsize=" + opt.nodeFontSize);
|
||||||
|
if (opt.shape != null)
|
||||||
|
w.print(", shape=" + Options.graphvizShape(opt.shape));
|
||||||
w.println("];");
|
w.println("];");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -467,7 +487,9 @@ class ClassGraph {
|
||||||
idx = qualifiedName.lastIndexOf('.');
|
idx = qualifiedName.lastIndexOf('.');
|
||||||
else
|
else
|
||||||
idx = qualifiedName.lastIndexOf('.', startTemplate);
|
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 packageName = qualifiedName.substring(0, idx);
|
||||||
String cn = className.substring(idx + 1);
|
String cn = className.substring(idx + 1);
|
||||||
tableLine(Align.CENTER, escape(cn), opt, font);
|
tableLine(Align.CENTER, escape(cn), opt, font);
|
||||||
|
|
@ -1033,8 +1055,9 @@ class ClassGraph {
|
||||||
String href = "";
|
String href = "";
|
||||||
if (url != null)
|
if (url != null)
|
||||||
href = " href=\"" + url + "\"";
|
href = " href=\"" + url + "\"";
|
||||||
w.print("<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" "
|
w.print("<<table border=\"0\" cellborder=\"" +
|
||||||
+ "cellpadding=\"2\" port=\"p\"" + bgcolor + href + ">" + linePostfix);
|
(opt.shape == null ? "1" : "0") + "\" cellspacing=\"0\" " +
|
||||||
|
"cellpadding=\"2\" port=\"p\"" + bgcolor + href + ">" + linePostfix);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void externalTableEnd() {
|
private void externalTableEnd() {
|
||||||
|
|
@ -1058,16 +1081,19 @@ class ClassGraph {
|
||||||
String open;
|
String open;
|
||||||
String close = "</td></tr>";
|
String close = "</td></tr>";
|
||||||
String prefix = linePrefix + linePrefix + linePrefix;
|
String prefix = linePrefix + linePrefix + linePrefix;
|
||||||
|
String alignText;
|
||||||
|
|
||||||
if(align == Align.CENTER)
|
if(align == Align.CENTER)
|
||||||
open = prefix + "<tr><td>";
|
alignText = "center";
|
||||||
else if(align == Align.LEFT)
|
else if(align == Align.LEFT)
|
||||||
open = prefix + "<tr><td align=\"left\">";
|
alignText = "left";
|
||||||
else if(align == Align.RIGHT)
|
else if(align == Align.RIGHT)
|
||||||
open = prefix + "<tr><td align=\"right\">";
|
alignText = "right";
|
||||||
else
|
else
|
||||||
throw new RuntimeException("Unknown alignement type " + align);
|
throw new RuntimeException("Unknown alignement type " + align);
|
||||||
|
|
||||||
text = fontWrap(" " + text + " ", opt, font);
|
text = fontWrap(" " + text + " ", opt, font);
|
||||||
|
open = "<tr><td align=\"" + alignText + "\" balign=\"" + alignText + "\">";
|
||||||
w.print(open + text + close + linePostfix);
|
w.print(open + text + close + linePostfix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
boolean showVisibility;
|
boolean showVisibility;
|
||||||
boolean horizontal;
|
boolean horizontal;
|
||||||
boolean showType;
|
boolean showType;
|
||||||
|
boolean showComment;
|
||||||
String edgeFontName;
|
String edgeFontName;
|
||||||
String edgeFontColor;
|
String edgeFontColor;
|
||||||
String edgeColor;
|
String edgeColor;
|
||||||
|
|
@ -93,6 +94,7 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
String nodeFontTagName;
|
String nodeFontTagName;
|
||||||
double nodeFontPackageSize;
|
double nodeFontPackageSize;
|
||||||
String nodeFontPackageName;
|
String nodeFontPackageName;
|
||||||
|
String shape;
|
||||||
String bgColor;
|
String bgColor;
|
||||||
public String outputFileName;
|
public String outputFileName;
|
||||||
String outputEncoding;
|
String outputEncoding;
|
||||||
|
|
@ -134,6 +136,7 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
showEnumerations = false;
|
showEnumerations = false;
|
||||||
showConstructors = false;
|
showConstructors = false;
|
||||||
showType = false;
|
showType = false;
|
||||||
|
showComment = false;
|
||||||
edgeFontName = defaultFont;
|
edgeFontName = defaultFont;
|
||||||
edgeFontColor = "black";
|
edgeFontColor = "black";
|
||||||
edgeColor = "black";
|
edgeColor = "black";
|
||||||
|
|
@ -151,6 +154,7 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
nodeFontPackageName = null;
|
nodeFontPackageName = null;
|
||||||
nodeFillColor = null;
|
nodeFillColor = null;
|
||||||
bgColor = null;
|
bgColor = null;
|
||||||
|
shape = null;
|
||||||
outputFileName = "graph.dot";
|
outputFileName = "graph.dot";
|
||||||
outputDirectory= null;
|
outputDirectory= null;
|
||||||
outputEncoding = "ISO-8859-1";
|
outputEncoding = "ISO-8859-1";
|
||||||
|
|
@ -211,6 +215,7 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
option.equals("-constructors") ||
|
option.equals("-constructors") ||
|
||||||
option.equals("-visibility") ||
|
option.equals("-visibility") ||
|
||||||
option.equals("-types") ||
|
option.equals("-types") ||
|
||||||
|
option.equals("-commentname") ||
|
||||||
option.equals("-all") ||
|
option.equals("-all") ||
|
||||||
option.equals("-postfixpackage") ||
|
option.equals("-postfixpackage") ||
|
||||||
option.equals("-noguillemot") ||
|
option.equals("-noguillemot") ||
|
||||||
|
|
@ -240,6 +245,7 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
option.equals("-edgecolor") ||
|
option.equals("-edgecolor") ||
|
||||||
option.equals("-edgefontsize") ||
|
option.equals("-edgefontsize") ||
|
||||||
option.equals("-edgefontname") ||
|
option.equals("-edgefontname") ||
|
||||||
|
option.equals("-shape") ||
|
||||||
option.equals("-output") ||
|
option.equals("-output") ||
|
||||||
option.equals("-outputencoding") ||
|
option.equals("-outputencoding") ||
|
||||||
option.equals("-bgcolor") ||
|
option.equals("-bgcolor") ||
|
||||||
|
|
@ -302,6 +308,10 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
showType = true;
|
showType = true;
|
||||||
} else if (opt[0].equals("-!types")) {
|
} else if (opt[0].equals("-!types")) {
|
||||||
showType = false;
|
showType = false;
|
||||||
|
} else if(opt[0].equals("-commentname")) {
|
||||||
|
showComment = true;
|
||||||
|
} else if (opt[0].equals("-!commentname")) {
|
||||||
|
showComment = false;
|
||||||
} else if(opt[0].equals("-all")) {
|
} else if(opt[0].equals("-all")) {
|
||||||
setAll();
|
setAll();
|
||||||
} else if(opt[0].equals("-bgcolor")) {
|
} else if(opt[0].equals("-bgcolor")) {
|
||||||
|
|
@ -372,6 +382,15 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
nodeFillColor = opt[1];
|
nodeFillColor = opt[1];
|
||||||
} else if (opt[0].equals("-!nodefillcolor")) {
|
} else if (opt[0].equals("-!nodefillcolor")) {
|
||||||
nodeFillColor = null;
|
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")) {
|
} else if(opt[0].equals("-output")) {
|
||||||
outputFileName = opt[1];
|
outputFileName = opt[1];
|
||||||
} else if (opt[0].equals("-!output")) {
|
} else if (opt[0].equals("-!output")) {
|
||||||
|
|
@ -695,5 +714,26 @@ public class Options implements Cloneable, OptionProvider {
|
||||||
return sb.toString();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue