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;
|
String nodeFontTagName = null;
|
||||||
double nodeFontPackageSize = -1;
|
double nodeFontPackageSize = -1;
|
||||||
String nodeFontPackageName = null;
|
String nodeFontPackageName = null;
|
||||||
Shape shape = new Shape();
|
Shape shape = Shape.CLASS;
|
||||||
String bgColor = null;
|
String bgColor = null;
|
||||||
public String outputFileName = "graph.dot";
|
public String outputFileName = "graph.dot";
|
||||||
String outputEncoding = "ISO-8859-1"; // TODO: default to UTF-8 now?
|
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")) {
|
} else if (opt[0].equals("-!nodefillcolor")) {
|
||||||
nodeFillColor = null;
|
nodeFillColor = null;
|
||||||
} else if(opt[0].equals("-shape")) {
|
} else if(opt[0].equals("-shape")) {
|
||||||
shape = new Shape(opt[1]);
|
shape = Shape.of(opt[1]);
|
||||||
} else if (opt[0].equals("-!shape")) {
|
} else if (opt[0].equals("-!shape")) {
|
||||||
shape = new Shape();
|
shape = Shape.CLASS;
|
||||||
} 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")) {
|
||||||
|
|
|
||||||
|
|
@ -18,67 +18,71 @@
|
||||||
|
|
||||||
package org.umlgraph.doclet;
|
package org.umlgraph.doclet;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties of node shapes
|
* Properties of node shapes
|
||||||
*
|
*
|
||||||
* @version $Revision$
|
* @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 */
|
/** Graphviz style */
|
||||||
private String name;
|
public final String style;
|
||||||
|
|
||||||
/** Construct a default (class) Shape */
|
/** Map for valid shape names */
|
||||||
public Shape() {
|
private static final HashMap<String, Shape> index = new HashMap<String, Shape>(16);
|
||||||
name = "class";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Construct a Shape through the specified UMLGraph name */
|
/** Initialize the lookup index */
|
||||||
public Shape(String n) {
|
static {
|
||||||
name = n;
|
for (Shape s : Shape.values()) {
|
||||||
if (graphvizAttribute() == null) {
|
index.put(s.name(), s);
|
||||||
System.err.println("Ignoring invalid shape " + n);
|
index.put(s.name().toLowerCase(Locale.ROOT), s);
|
||||||
name = "class";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
public static Shape of(String s) {
|
||||||
if (name.equals("class"))
|
Shape shp = index.get(s);
|
||||||
return ""; // Default; plaintext
|
if (shp != null)
|
||||||
else if (name.equals("note"))
|
return shp;
|
||||||
return ", shape=note";
|
System.err.println("Ignoring invalid shape: " + s);
|
||||||
else if (name.equals("node"))
|
return CLASS;
|
||||||
return ", shape=box3d";
|
}
|
||||||
else if (name.equals("component"))
|
|
||||||
return ", shape=component";
|
/** Enum constructor, must be private! */
|
||||||
else if (name.equals("package"))
|
private Shape(String style) {
|
||||||
return ", shape=tab";
|
this.style = style;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the shape's GraphViz landing port */
|
/** Return the shape's GraphViz landing port */
|
||||||
String landingPort() {
|
public String landingPort() {
|
||||||
return (name.equals("class") || name.equals("activeclass")) ? ":p" : "";
|
return this == CLASS || this == ACTIVECLASS ? ":p" : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the table border required for the shape */
|
/** Return the table border required for the shape */
|
||||||
String extraColumn() {
|
public String extraColumn() {
|
||||||
return name.equals("activeclass") ? ("<td rowspan=\"10\"></td>") : "";
|
return this == Shape.ACTIVECLASS ? ("<td rowspan=\"10\"></td>") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the cell border required for the shape */
|
/** Return the cell border required for the shape */
|
||||||
String cellBorder() {
|
public String cellBorder() {
|
||||||
return (name.equals("class") || name.equals("activeclass")) ? "1" : "0";
|
return this == CLASS || this == ACTIVECLASS ? "1" : "0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ public class UmlGraph {
|
||||||
commentOptions = new Options();
|
commentOptions = new Options();
|
||||||
commentOptions.setOptions(root.options());
|
commentOptions.setOptions(root.options());
|
||||||
commentOptions.setOptions(findClass(root, "UMLNoteOptions"));
|
commentOptions.setOptions(findClass(root, "UMLNoteOptions"));
|
||||||
commentOptions.shape = new Shape("note");
|
commentOptions.shape = Shape.NOTE;
|
||||||
|
|
||||||
Options opt = new Options();
|
Options opt = new Options();
|
||||||
opt.setOptions(root.options());
|
opt.setOptions(root.options());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue