diff options
Diffstat (limited to 'src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java')
-rw-r--r-- | src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java | 125 |
1 files changed, 53 insertions, 72 deletions
diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java index 6084f22..b4a2652 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java @@ -35,8 +35,6 @@ */ package net.sourceforge.plantuml.classdiagram.command; -import java.util.StringTokenizer; - import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagramType; @@ -59,7 +57,7 @@ import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.LinkArrow; import net.sourceforge.plantuml.cucadiagram.LinkDecor; import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.graphic.HtmlColorSet; +import net.sourceforge.plantuml.descdiagram.command.CommandLinkElement; import net.sourceforge.plantuml.graphic.color.ColorParser; import net.sourceforge.plantuml.graphic.color.ColorType; import net.sourceforge.plantuml.graphic.color.Colors; @@ -75,25 +73,21 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb } static private RegexConcat getRegexConcat(UmlDiagramType umlDiagramType) { - return new RegexConcat( - new RegexLeaf("HEADER", "^(?:@([\\d.]+)[%s]+)?"), // + return new RegexConcat(new RegexLeaf("HEADER", "^(?:@([\\d.]+)[%s]+)?"), // new RegexOr( // new RegexLeaf("ENT1", getClassIdentifier()),// - new RegexLeaf("COUPLE1", COUPLE)), - new RegexLeaf("[%s]*"), // + new RegexLeaf("COUPLE1", COUPLE)), new RegexLeaf("[%s]*"), // new RegexLeaf("FIRST_LABEL", "(?:[%g]([^%g]+)[%g])?"), // new RegexLeaf("[%s]*"), // new RegexConcat( - // + // new RegexLeaf("ARROW_HEAD1", "([%s]+[ox]|[)#\\[<*+^}]|[<\\[]\\||\\}o|\\}\\||\\|o|\\|\\|)?"), // new RegexLeaf("ARROW_BODY1", "([-=.]+)"), // - new RegexLeaf("ARROW_STYLE1", - "(?:\\[((?:#\\w+|dotted|dashed|plain|bold|hidden|norank)(?:,#\\w+|,dotted|,dashed|,plain|,bold|,hidden|,norank)*)\\])?"), + new RegexLeaf("ARROW_STYLE1", "(?:\\[(" + CommandLinkElement.LINE_STYLE + ")\\])?"), // new RegexLeaf("ARROW_DIRECTION", "(left|right|up|down|le?|ri?|up?|do?)?"), // new RegexLeaf("INSIDE", "(?:(0|\\(0\\)|\\(0|0\\))(?=[-=.~]))?"), // - new RegexLeaf("ARROW_STYLE2", - "(?:\\[((?:#\\w+|dotted|dashed|plain|bold|hidden|norank)(?:,#\\w+|,dotted|,dashed|,plain|,bold|,hidden|,norank)*)\\])?"), + new RegexLeaf("ARROW_STYLE2", "(?:\\[(" + CommandLinkElement.LINE_STYLE + ")\\])?"), // new RegexLeaf("ARROW_BODY2", "([-=.]*)"), // new RegexLeaf("ARROW_HEAD2", "([ox][%s]+|[(#\\]>*+^\\{]|\\|[>\\]]|o\\{|\\|\\{|o\\||\\|\\|)?")), // @@ -144,6 +138,9 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb Code ent1 = Code.of(arg.get("ENT1", 0)); Code ent2 = Code.of(arg.get("ENT2", 0)); + if (ent1 == null && ent2 == null) { + return executeArgSpecial3(diagram, arg); + } if (ent1 == null) { return executeArgSpecial1(diagram, arg); @@ -177,7 +174,7 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb .eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 0), "\""))) : diagram.getOrCreateLeaf( ent2, null, null); - Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()); + // Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()); final LinkType linkType = getLinkType(arg); final Direction dir = getDirection(arg); @@ -260,8 +257,8 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb link = link.getInv(); } link.setLinkArrow(linkArrow); - colors = applyStyle(arg.getLazzy("ARROW_STYLE", 0), link, colors); - link.setColors(colors); + link.setColors(color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet())); + link.applyStyle(arg.getLazzy("ARROW_STYLE", 0)); addLink(diagram, link, arg.get("HEADER", 0)); @@ -332,31 +329,29 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb queue = getQueueLength(arg); } - Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()); - final Display labelLink = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); final String firstLabel = arg.get("FIRST_LABEL", 0); final String secondLabel = arg.get("SECOND_LABEL", 0); final Link link = new Link(cl1, cl2, linkType, labelLink, queue, firstLabel, secondLabel, diagram.getLabeldistance(), diagram.getLabelangle()); + link.setColors(color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet())); diagram.resetPragmaLabel(); - colors = applyStyle(arg.getLazzy("ARROW_STYLE", 0), link, colors); - link.setColors(colors); + link.applyStyle(arg.getLazzy("ARROW_STYLE", 0)); addLink(diagram, link, arg.get("HEADER", 0)); return CommandExecutionResult.ok(); } private CommandExecutionResult executeArgSpecial1(AbstractClassOrObjectDiagram diagram, RegexResult arg) { - final Code clName1 = Code.of(arg.get("COUPLE1", 0)); - final Code clName2 = Code.of(arg.get("COUPLE1", 1)); - if (diagram.leafExist(clName1) == false) { - return CommandExecutionResult.error("No class " + clName1); + final Code clName1A = Code.of(arg.get("COUPLE1", 0)); + final Code clName1B = Code.of(arg.get("COUPLE1", 1)); + if (diagram.leafExist(clName1A) == false) { + return CommandExecutionResult.error("No class " + clName1A); } - if (diagram.leafExist(clName2) == false) { - return CommandExecutionResult.error("No class " + clName2); + if (diagram.leafExist(clName1B) == false) { + return CommandExecutionResult.error("No class " + clName1B); } final Code ent2 = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 0), "\"")); @@ -364,10 +359,8 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb final LinkType linkType = getLinkType(arg); final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); - // final int length = getQueueLength(arg); - // final String weight = arg.get("HEADER").get(0); - final boolean result = diagram.associationClass(1, clName1, clName2, cl2, linkType, label); + final boolean result = diagram.associationClass(1, clName1A, clName1B, cl2, linkType, label); if (result == false) { return CommandExecutionResult.error("Cannot have more than 2 assocications"); } @@ -375,14 +368,38 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb return CommandExecutionResult.ok(); } + private CommandExecutionResult executeArgSpecial3(AbstractClassOrObjectDiagram diagram, RegexResult arg) { + final Code clName1A = Code.of(arg.get("COUPLE1", 0)); + final Code clName1B = Code.of(arg.get("COUPLE1", 1)); + final Code clName2A = Code.of(arg.get("COUPLE2", 0)); + final Code clName2B = Code.of(arg.get("COUPLE2", 1)); + if (diagram.leafExist(clName1A) == false) { + return CommandExecutionResult.error("No class " + clName1A); + } + if (diagram.leafExist(clName1B) == false) { + return CommandExecutionResult.error("No class " + clName1B); + } + if (diagram.leafExist(clName2A) == false) { + return CommandExecutionResult.error("No class " + clName2A); + } + if (diagram.leafExist(clName2B) == false) { + return CommandExecutionResult.error("No class " + clName2B); + } + + final LinkType linkType = getLinkType(arg); + final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); + + return diagram.associationClass(clName1A, clName1B, clName2A, clName2B, linkType, label); + } + private CommandExecutionResult executeArgSpecial2(AbstractClassOrObjectDiagram diagram, RegexResult arg) { - final Code clName1 = Code.of(arg.get("COUPLE2", 0)); - final Code clName2 = Code.of(arg.get("COUPLE2", 1)); - if (diagram.leafExist(clName1) == false) { - return CommandExecutionResult.error("No class " + clName1); + final Code clName2A = Code.of(arg.get("COUPLE2", 0)); + final Code clName2B = Code.of(arg.get("COUPLE2", 1)); + if (diagram.leafExist(clName2A) == false) { + return CommandExecutionResult.error("No class " + clName2A); } - if (diagram.leafExist(clName2) == false) { - return CommandExecutionResult.error("No class " + clName2); + if (diagram.leafExist(clName2B) == false) { + return CommandExecutionResult.error("No class " + clName2B); } final Code ent1 = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 0), "\"")); @@ -390,10 +407,8 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb final LinkType linkType = getLinkType(arg); final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); - // final int length = getQueueLength(arg); - // final String weight = arg.get("HEADER").get(0); - final boolean result = diagram.associationClass(2, clName1, clName2, cl1, linkType, label); + final boolean result = diagram.associationClass(2, clName2A, clName2B, cl1, linkType, label); if (result == false) { return CommandExecutionResult.error("Cannot have more than 2 assocications"); } @@ -507,7 +522,7 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb LinkType result = new LinkType(decors2, decors1); if (arg.get("ARROW_BODY1", 0).contains(".") || arg.get("ARROW_BODY2", 0).contains(".")) { - result = result.getDashed(); + result = result.goDashed(); } final String middle = arg.get("INSIDE", 0); if ("0".equals(middle)) { @@ -562,40 +577,6 @@ final public class CommandLinkClass extends SingleLineCommand2<AbstractClassOrOb return s; } - @Deprecated - public static Colors applyStyle(String arrowStyle, Link link) { - return applyStyle(arrowStyle, link, null); - } - - public static Colors applyStyle(String arrowStyle, Link link, Colors colors) { - if (arrowStyle == null) { - return colors; - } - final StringTokenizer st = new StringTokenizer(arrowStyle, ","); - while (st.hasMoreTokens()) { - final String s = st.nextToken(); - if (s.equalsIgnoreCase("dashed")) { - link.goDashed(); - } else if (s.equalsIgnoreCase("bold")) { - link.goBold(); - } else if (s.equalsIgnoreCase("dotted")) { - link.goDotted(); - } else if (s.equalsIgnoreCase("hidden")) { - link.goHidden(); - } else if (s.equalsIgnoreCase("plain")) { - // Do nothing - } else if (s.equalsIgnoreCase("norank")) { - link.goNorank(); - } else { - link.setSpecificColor(s); - if (colors != null) { - colors = colors.add(ColorType.LINE, HtmlColorSet.getInstance().getColorIfValid(s)); - } - } - } - return colors; - } - private boolean isInversed(LinkDecor decors1, LinkDecor decors2) { if (decors1 == LinkDecor.ARROW && decors2 != LinkDecor.ARROW) { return true; |