From 6901d69a6cb16fb916cc90d1efd14f19bb4bc129 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Thu, 29 Nov 2007 10:39:26 +0000 Subject: [PATCH] Add support for adding notes to elements as comments. --- TODO | 11 ----------- doc/ver.xml | 3 +++ src/org/umlgraph/doclet/ClassGraph.java | 16 ++++++++++++++++ src/org/umlgraph/doclet/UmlGraph.java | 23 +++++++++++++++++++---- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index 5c69b51..a1f73db 100644 --- a/TODO +++ b/TODO @@ -1,16 +1,10 @@ $Id$ -Support for comments (once dds's patch gets into Graphviz). -Suggested by S\'ebastien_Pierre - Add link to MoinMoin sequence to deriv.xml Yves Bossel: If I may do some suggestions: - + I would appreciate to be able to add UML comments to both diagram types. - + Adding patterns (collaborations ellipse with roles bound to classes) would be welcome into class diagrams. + Self-adjusting box size and placement on sequence diagrams would help (I use lots of inner classes whose names are long and descriptive). - Try the http://prefuse.sourceforge.net/ back end for large graphs. Provide a parameter to say how (untagged) data members relate to other @@ -25,17 +19,12 @@ public class A { } Requires special care for containers and arrays. -Add package, note, interface and node icons to graphviz - (folder) dog-ear =[] 3D box - Support for all UML diagrams: state, use-case, etc. command-line (and global) options for setting all graph attributes Class options for setting edge attributes fillcolor fontcolor etc per edge -@active tag to render a class as active - Use doclet error reporting functions A class can specify its rank, or its cluster. diff --git a/doc/ver.xml b/doc/ver.xml index edd8e01..d086388 100644 --- a/doc/ver.xml +++ b/doc/ver.xml @@ -12,6 +12,9 @@ callers. usecase, and activeclass. These shapes require GraphViz 1.16 or newer. +
  • A new @note tag allows the annotation of elements with comments. +(Suggested by Sébastien Pierre.) +
  • diff --git a/src/org/umlgraph/doclet/ClassGraph.java b/src/org/umlgraph/doclet/ClassGraph.java index b42fd30..dfa6560 100644 --- a/src/org/umlgraph/doclet/ClassGraph.java +++ b/src/org/umlgraph/doclet/ClassGraph.java @@ -554,6 +554,22 @@ class ClassGraph { } externalTableEnd(); nodeProperties(opt); + + // If needed, add a note for this node + int ni = 0; + for (Tag t : c.tags("note")) { + String noteName = "n" + ni + "c" + ci.name; + w.print("\t// Note annotation\n"); + w.print("\t" + noteName + " [label="); + externalTableStart(UmlGraph.getCommentOptions(), c.qualifiedName(), classToUrl(c, rootClass)); + innerTableStart(); + tableLine(Align.LEFT, htmlNewline(escape(t.text())), UmlGraph.getCommentOptions(), Font.CLASS); + innerTableEnd(); + externalTableEnd(); + nodeProperties(UmlGraph.getCommentOptions()); + w.print("\t" + noteName + " -> " + relationNode(c) + "[arrowhead=none];\n"); + ni++; + } ci.nodePrinted = true; } return ci.name; diff --git a/src/org/umlgraph/doclet/UmlGraph.java b/src/org/umlgraph/doclet/UmlGraph.java index 6cf70ec..24d5fa7 100644 --- a/src/org/umlgraph/doclet/UmlGraph.java +++ b/src/org/umlgraph/doclet/UmlGraph.java @@ -46,6 +46,9 @@ public class UmlGraph { private static final String programName = "UmlGraph"; private static final String docletName = "org.umlgraph.doclet.UmlGraph"; + /** Options used for commenting nodes */ + private static Options commentOptions; + /** Entry point through javadoc */ public static boolean start(RootDoc root) throws IOException { Options opt = buildOptions(root); @@ -68,21 +71,33 @@ public class UmlGraph { err, err, err, docletName, args); } + public static Options getCommentOptions() { + return commentOptions; + } + /** - * Creates the base Options object, that contains both the options specified on the command + * Creates the base Options object. + * This contains both the options specified on the command * line and the ones specified in the UMLOptions class, if available. + * Also create the globally accessible commentOptions object. */ public static Options buildOptions(RootDoc root) { + commentOptions = new Options(); + commentOptions.setOptions(root.options()); + commentOptions.setOptions(findClass(root, "UMLCommentOptions")); + commentOptions.shape = "note"; + Options opt = new Options(); opt.setOptions(root.options()); - opt.setOptions(findUMLOptions(root)); + opt.setOptions(findClass(root, "UMLOptions")); return opt; } - private static ClassDoc findUMLOptions(RootDoc root) { + /** Return the ClassDoc for the specified class; null if not found. */ + private static ClassDoc findClass(RootDoc root, String name) { ClassDoc[] classes = root.classes(); for (ClassDoc cd : classes) - if(cd.name().equals("UMLOptions")) + if(cd.name().equals(name)) return cd; return null; }