mirror of https://github.com/dspinellis/UMLGraph
Refactor shape into enum pattern.
This commit is contained in:
parent
9ddf84129a
commit
7d9f665d07
|
|
@ -98,7 +98,7 @@ public class Options implements Cloneable, OptionProvider {
|
|||
String nodeFontTagName = null;
|
||||
double nodeFontPackageSize = -1;
|
||||
String nodeFontPackageName = null;
|
||||
Shape shape = new Shape();
|
||||
Shape shape = Shape.CLASS;
|
||||
String bgColor = null;
|
||||
public String outputFileName = "graph.dot";
|
||||
String outputEncoding = "ISO-8859-1"; // TODO: default to UTF-8 now?
|
||||
|
|
@ -367,9 +367,9 @@ public class Options implements Cloneable, OptionProvider {
|
|||
} else if (opt[0].equals("-!nodefillcolor")) {
|
||||
nodeFillColor = null;
|
||||
} else if(opt[0].equals("-shape")) {
|
||||
shape = new Shape(opt[1]);
|
||||
shape = Shape.of(opt[1]);
|
||||
} else if (opt[0].equals("-!shape")) {
|
||||
shape = new Shape();
|
||||
shape = Shape.CLASS;
|
||||
} else if(opt[0].equals("-output")) {
|
||||
outputFileName = opt[1];
|
||||
} else if (opt[0].equals("-!output")) {
|
||||
|
|
|
|||
|
|
@ -18,67 +18,71 @@
|
|||
|
||||
package org.umlgraph.doclet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Properties of node shapes
|
||||
*
|
||||
* @version $Revision$
|
||||
* @author <a href="http://www.spinellis.gr">Diomidis Spinellis</a>
|
||||
* @author Erich Schubert
|
||||
*/
|
||||
public class Shape {
|
||||
public enum Shape {
|
||||
CLASS(""), //
|
||||
NOTE(", shape=note"), //
|
||||
NODE(", shape=box3d"), //
|
||||
COMPONENT(", shape=component"), //
|
||||
PACKAGE(", shape=tab"), //
|
||||
COLLABORATION(", shape=ellipse, style=dashed"), //
|
||||
USECASE(", shape=ellipse"), //
|
||||
ACTIVECLASS("");
|
||||
|
||||
/** Shape's UMLGraph name */
|
||||
private String name;
|
||||
/** Graphviz style */
|
||||
public final String style;
|
||||
|
||||
/** Construct a default (class) Shape */
|
||||
public Shape() {
|
||||
name = "class";
|
||||
}
|
||||
/** Map for valid shape names */
|
||||
private static final HashMap<String, Shape> index = new HashMap<String, Shape>(16);
|
||||
|
||||
/** Construct a Shape through the specified UMLGraph name */
|
||||
public Shape(String n) {
|
||||
name = n;
|
||||
if (graphvizAttribute() == null) {
|
||||
System.err.println("Ignoring invalid shape " + n);
|
||||
name = "class";
|
||||
/** Initialize the lookup index */
|
||||
static {
|
||||
for (Shape s : Shape.values()) {
|
||||
index.put(s.name(), s);
|
||||
index.put(s.name().toLowerCase(Locale.ROOT), s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the GraphViz shape name corresponding to the shape
|
||||
* Get the shape from a string. This allows both the uppercase and the lowercase
|
||||
* name. Prefer this to {{@link #valueOf(String)} which only accepts uppercase.
|
||||
*
|
||||
* @param s String
|
||||
* @return Shape
|
||||
*/
|
||||
public String graphvizAttribute() {
|
||||
if (name.equals("class"))
|
||||
return ""; // Default; plaintext
|
||||
else if (name.equals("note"))
|
||||
return ", shape=note";
|
||||
else if (name.equals("node"))
|
||||
return ", shape=box3d";
|
||||
else if (name.equals("component"))
|
||||
return ", shape=component";
|
||||
else if (name.equals("package"))
|
||||
return ", shape=tab";
|
||||
else if (name.equals("collaboration"))
|
||||
return ", shape=ellipse, style=dashed";
|
||||
else if (name.equals("usecase"))
|
||||
return ", shape=ellipse";
|
||||
else if (name.equals("activeclass"))
|
||||
return ""; // Default; plaintext
|
||||
else
|
||||
return null;
|
||||
public static Shape of(String s) {
|
||||
Shape shp = index.get(s);
|
||||
if (shp != null)
|
||||
return shp;
|
||||
System.err.println("Ignoring invalid shape: " + s);
|
||||
return CLASS;
|
||||
}
|
||||
|
||||
/** Enum constructor, must be private! */
|
||||
private Shape(String style) {
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
/** Return the shape's GraphViz landing port */
|
||||
String landingPort() {
|
||||
return (name.equals("class") || name.equals("activeclass")) ? ":p" : "";
|
||||
public String landingPort() {
|
||||
return this == CLASS || this == ACTIVECLASS ? ":p" : "";
|
||||
}
|
||||
|
||||
/** Return the table border required for the shape */
|
||||
String extraColumn() {
|
||||
return name.equals("activeclass") ? ("<td rowspan=\"10\"></td>") : "";
|
||||
public String extraColumn() {
|
||||
return this == Shape.ACTIVECLASS ? ("<td rowspan=\"10\"></td>") : "";
|
||||
}
|
||||
|
||||
/** Return the cell border required for the shape */
|
||||
String cellBorder() {
|
||||
return (name.equals("class") || name.equals("activeclass")) ? "1" : "0";
|
||||
public String cellBorder() {
|
||||
return this == CLASS || this == ACTIVECLASS ? "1" : "0";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public class UmlGraph {
|
|||
commentOptions = new Options();
|
||||
commentOptions.setOptions(root.options());
|
||||
commentOptions.setOptions(findClass(root, "UMLNoteOptions"));
|
||||
commentOptions.shape = new Shape("note");
|
||||
commentOptions.shape = Shape.NOTE;
|
||||
|
||||
Options opt = new Options();
|
||||
opt.setOptions(root.options());
|
||||
|
|
|
|||
Loading…
Reference in New Issue