diff --git a/src/net/sourceforge/plantuml/PSystemBuilder.java b/src/net/sourceforge/plantuml/PSystemBuilder.java index 612bbb10e..8025cbcae 100644 --- a/src/net/sourceforge/plantuml/PSystemBuilder.java +++ b/src/net/sourceforge/plantuml/PSystemBuilder.java @@ -39,6 +39,7 @@ import java.util.Collection; import java.util.List; import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory; +import net.sourceforge.plantuml.activitydiagram2.ActivityDiagramFactory2; import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory; import net.sourceforge.plantuml.componentdiagram.ComponentDiagramFactory; import net.sourceforge.plantuml.compositediagram.CompositeDiagramFactory; @@ -63,9 +64,11 @@ public class PSystemBuilder { factories.add(new SequenceDiagramFactory()); factories.add(new ClassDiagramFactory()); factories.add(new ActivityDiagramFactory()); + factories.add(new ActivityDiagramFactory2()); factories.add(new UsecaseDiagramFactory()); factories.add(new ComponentDiagramFactory()); factories.add(new StateDiagramFactory()); + factories.add(new ActivityDiagramFactory2()); factories.add(new CompositeDiagramFactory()); factories.add(new ObjectDiagramFactory()); factories.add(new PrintSkinFactory()); diff --git a/src/net/sourceforge/plantuml/PSystemError.java b/src/net/sourceforge/plantuml/PSystemError.java index 71878b2cb..585e96bee 100644 --- a/src/net/sourceforge/plantuml/PSystemError.java +++ b/src/net/sourceforge/plantuml/PSystemError.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5794 $ + * Revision $Revision: 5898 $ */ package net.sourceforge.plantuml; @@ -59,20 +59,39 @@ public class PSystemError extends AbstractPSystem { this.errorsUml.addAll(errorUml); this.setSource(source); - final Collection executions = getErrors(ErrorUmlType.EXECUTION_ERROR); - if (executions.size() > 0) { - higherErrorPosition = getHigherErrorPosition(ErrorUmlType.EXECUTION_ERROR); - errs = getErrorsAt(higherErrorPosition, ErrorUmlType.EXECUTION_ERROR); - appendSource(higherErrorPosition, errs); - } else { - higherErrorPosition = getHigherErrorPosition(ErrorUmlType.SYNTAX_ERROR); - errs = getErrorsAt(higherErrorPosition, ErrorUmlType.SYNTAX_ERROR); - if (errs.size() != 1) { - throw new UnsupportedOperationException(errs.toString()); - } - appendSource(higherErrorPosition, errs); + final int higherErrorPositionExecution = getHigherErrorPosition(ErrorUmlType.EXECUTION_ERROR); + final int higherErrorPositionSyntax = getHigherErrorPosition(ErrorUmlType.SYNTAX_ERROR); + + if (higherErrorPositionExecution == Integer.MIN_VALUE && higherErrorPositionSyntax == Integer.MIN_VALUE) { + throw new IllegalStateException(); } + if (higherErrorPositionExecution >= higherErrorPositionSyntax) { + higherErrorPosition = higherErrorPositionExecution; + errs = getErrorsAt(higherErrorPositionExecution, ErrorUmlType.EXECUTION_ERROR); + } else { + assert higherErrorPositionSyntax > higherErrorPositionExecution; + higherErrorPosition = higherErrorPositionSyntax; + errs = getErrorsAt(higherErrorPositionSyntax, ErrorUmlType.SYNTAX_ERROR); + } + appendSource(higherErrorPosition, errs); + + + +// final Collection executions = getErrors(ErrorUmlType.EXECUTION_ERROR); +// if (executions.size() > 0) { +// higherErrorPosition = getHigherErrorPosition(ErrorUmlType.EXECUTION_ERROR); +// errs = getErrorsAt(higherErrorPosition, ErrorUmlType.EXECUTION_ERROR); +// appendSource(higherErrorPosition, errs); +// } else { +// higherErrorPosition = getHigherErrorPosition(ErrorUmlType.SYNTAX_ERROR); +// errs = getErrorsAt(higherErrorPosition, ErrorUmlType.SYNTAX_ERROR); +// if (errs.size() != 1) { +// throw new UnsupportedOperationException(errs.toString()); +// } +// appendSource(higherErrorPosition, errs); +// } + } public PSystemError(UmlSource source, ErrorUml... errorUml) { @@ -154,9 +173,9 @@ public class PSystemError extends AbstractPSystem { max = error.getPosition(); } } - if (max == Integer.MIN_VALUE) { - throw new IllegalStateException(); - } +// if (max == Integer.MIN_VALUE) { +// throw new IllegalStateException(); +// } return max; } diff --git a/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagramFactory.java b/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagramFactory.java index 52865774e..8a9057728 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagramFactory.java +++ b/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagramFactory.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5847 $ + * Revision $Revision: 5890 $ * */ package net.sourceforge.plantuml.activitydiagram; @@ -37,7 +37,6 @@ import net.sourceforge.plantuml.activitydiagram.command.CommandElse; import net.sourceforge.plantuml.activitydiagram.command.CommandEndPartition; import net.sourceforge.plantuml.activitydiagram.command.CommandEndif; import net.sourceforge.plantuml.activitydiagram.command.CommandIf; -import net.sourceforge.plantuml.activitydiagram.command.CommandInnerConcurrent; import net.sourceforge.plantuml.activitydiagram.command.CommandLinkActivity; import net.sourceforge.plantuml.activitydiagram.command.CommandLinkLongActivity; import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivity; diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java index 6411b15f9..d91b7f8c5 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java @@ -54,42 +54,32 @@ import net.sourceforge.plantuml.cucadiagram.Stereotype; public class CommandLinkActivity extends SingleLineCommand2 { public CommandLinkActivity(ActivityDiagram diagram) { - super( - diagram, getRegexConcat()); + super(diagram, getRegexConcat()); } - + static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), - new RegexOr("FIRST", true, - new RegexLeaf("STAR", "(\\(\\*\\))"), - new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), - new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), - new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), - new RegexLeaf("\\s*"), - new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), - new RegexLeaf("\\s*"), - new RegexLeaf("BACKCOLOR", "(#\\w+)?"), - new RegexLeaf("\\s*"), - new RegexLeaf("ARROW", "([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)"), - new RegexLeaf("\\s*"), - new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), - new RegexLeaf("\\s*"), - new RegexOr("FIRST2", - new RegexLeaf("STAR2", "(\\(\\*\\))"), - new RegexLeaf("OPENBRACKET2", "(\\{)"), - new RegexLeaf("CODE2", "([\\p{L}0-9_.]+)"), - new RegexLeaf("BAR2", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), - new RegexLeaf("QUOTED2", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), - new RegexLeaf("\\s*"), - new RegexLeaf("STEREOTYPE2", "(\\<\\<.*\\>\\>)?"), - new RegexLeaf("\\s*"), - new RegexLeaf("BACKCOLOR2", "(#\\w+)?"), - new RegexLeaf("$")); + return new RegexConcat(new RegexLeaf("^"), new RegexOr("FIRST", true, new RegexLeaf("STAR", "(\\(\\*\\))"), + new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), new RegexLeaf("BAR", + "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), new RegexLeaf("QUOTED", + "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), new RegexLeaf("\\s*"), new RegexLeaf( + "STEREOTYPE", "(\\<\\<.*\\>\\>)?"), new RegexLeaf("\\s*"), new RegexLeaf("BACKCOLOR", "(#\\w+)?"), + new RegexLeaf("\\s*"), + new RegexLeaf("ARROW", "([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)"), + new RegexLeaf("\\s*"), new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), new RegexLeaf("\\s*"), + new RegexOr("FIRST2", new RegexLeaf("STAR2", "(\\(\\*\\))"), new RegexLeaf("OPENBRACKET2", "(\\{)"), + new RegexLeaf("CODE2", "([\\p{L}0-9_.]+)"), new RegexLeaf("BAR2", + "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), new RegexLeaf("QUOTED2", + "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), new RegexLeaf("\\s*"), new RegexLeaf( + "STEREOTYPE2", "(\\<\\<.*\\>\\>)?"), new RegexLeaf("\\s*"), new RegexLeaf("BACKCOLOR2", + "(#\\w+)?"), new RegexLeaf("$")); } - + @Override protected CommandExecutionResult executeArg(Map arg2) { final IEntity entity1 = getEntity(getSystem(), arg2, true); + if (entity1 == null) { + return CommandExecutionResult.error("No such activity"); + } if (arg2.get("STEREOTYPE").get(0) != null) { entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0))); } @@ -98,6 +88,9 @@ public class CommandLinkActivity extends SingleLineCommand2 { } final IEntity entity2 = getEntity(getSystem(), arg2, false); + if (entity2 == null) { + return CommandExecutionResult.error("No such activity"); + } if (arg2.get("BACKCOLOR2").get(0) != null) { entity2.setSpecificBackcolor(arg2.get("BACKCOLOR2").get(0)); } @@ -122,14 +115,11 @@ public class CommandLinkActivity extends SingleLineCommand2 { } - - - static IEntity getEntity(ActivityDiagram system, Map arg, final boolean start) { final String suf = start ? "" : "2"; final RegexPartialMatch openBracket = arg.get("OPENBRACKET" + suf); - if (openBracket!=null && openBracket.get(0) != null) { + if (openBracket != null && openBracket.get(0) != null) { return system.createInnerActivity(); } if (arg.get("STAR" + suf).get(0) != null) { @@ -149,8 +139,7 @@ public class CommandLinkActivity extends SingleLineCommand2 { final RegexPartialMatch quoted = arg.get("QUOTED" + suf); if (quoted.get(0) != null) { final String quotedCode = quoted.get(1) == null ? quoted.get(0) : quoted.get(1); - return system.getOrCreate(quotedCode, quoted.get(0), getTypeIfExisting(system, - quotedCode)); + return system.getOrCreate(quotedCode, quoted.get(0), getTypeIfExisting(system, quotedCode)); } final String first = arg.get("FIRST" + suf).get(0); if (first == null) { @@ -158,7 +147,6 @@ public class CommandLinkActivity extends SingleLineCommand2 { } throw new UnsupportedOperationException(); } - static EntityType getTypeIfExisting(ActivityDiagram system, String code) { if (system.entityExist(code)) { @@ -169,7 +157,7 @@ public class CommandLinkActivity extends SingleLineCommand2 { } return EntityType.ACTIVITY; } - + static EntityType getTypeFromString(String type, final EntityType circle) { if (type == null) { return EntityType.ACTIVITY; @@ -183,5 +171,4 @@ public class CommandLinkActivity extends SingleLineCommand2 { throw new IllegalArgumentException(); } - } diff --git a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java new file mode 100644 index 000000000..ee2d6417b --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java @@ -0,0 +1,106 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5721 $ + * + */ +package net.sourceforge.plantuml.activitydiagram2; + +import java.util.Arrays; +import java.util.List; + +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.activitydiagram.ConditionalContext; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkType; + +public class ActivityDiagram2 extends CucaDiagram { + + private IEntity last; + private ConditionalContext currentContext; + + final protected List getDotStrings() { + return Arrays.asList("nodesep=.20;", "ranksep=0.4;", "edge [fontsize=11,labelfontsize=11];", + "node [fontsize=11];"); + } + + public String getDescription() { + return "(" + entities().size() + " activities)"; + } + + @Override + public UmlDiagramType getUmlDiagramType() { + return UmlDiagramType.ACTIVITY; + } + + public void newActivity(String display) { + if (last == null) { + throw new IllegalStateException(); + } + final Entity act = createEntity(getAutoCode(), display, EntityType.ACTIVITY); + this.addLink(new Link(last, act, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), null, 2)); + last = act; + + } + + private String getAutoCode() { + return "ac" + UniqueSequence.getValue(); + } + + public void start() { + if (last != null) { + throw new IllegalStateException(); + } + last = createEntity("start", "start", EntityType.CIRCLE_START); + } + + public void startIf(String test) { + final IEntity br = createEntity(getAutoCode(), "", EntityType.BRANCH); + currentContext = new ConditionalContext(currentContext, br, Direction.DOWN); + this.addLink(new Link(last, br, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), null, 2)); + last = br; + } + + public IEntity getLastEntityConsulted() { + return last; + } + + public void endif() { + currentContext = currentContext.getParent(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java new file mode 100644 index 000000000..d127e276b --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java @@ -0,0 +1,75 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5847 $ + * + */ +package net.sourceforge.plantuml.activitydiagram2; + +import net.sourceforge.plantuml.activitydiagram2.command.CommandIf2; +import net.sourceforge.plantuml.activitydiagram2.command.CommandNewActivity; +import net.sourceforge.plantuml.activitydiagram2.command.CommandStart; +import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; + +public class ActivityDiagramFactory2 extends AbstractUmlSystemCommandFactory { + + private ActivityDiagram2 system; + + public ActivityDiagram2 getSystem() { + return system; + } + + @Override + protected void initCommands() { + system = new ActivityDiagram2(); + + addCommonCommands(system); + addCommand(new CommandStart(system)); + addCommand(new CommandNewActivity(system)); + addCommand(new CommandIf2(system)); + +// addCommand(new CommandLinkActivity(system)); +// addCommand(new CommandPartition(system)); +// addCommand(new CommandEndPartition(system)); +// addCommand(new CommandLinkLongActivity(system)); +// +// addCommand(new CommandNoteActivity(system)); +// addCommand(new CommandMultilinesNoteActivity(system)); +// +// addCommand(new CommandNoteOnActivityLink(system)); +// addCommand(new CommandMultilinesNoteActivityLink(system)); +// +// addCommand(new CommandIf(system)); +// addCommand(new CommandElse(system)); +// addCommand(new CommandEndif(system)); + // addCommand(new CommandInnerConcurrent(system)); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEndif2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEndif2.java new file mode 100644 index 000000000..ef31f5cff --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEndif2.java @@ -0,0 +1,68 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4762 $ + * + */ +package net.sourceforge.plantuml.activitydiagram2.command; + +import java.util.Map; + +import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexPartialMatch; + +public class CommandEndif2 extends SingleLineCommand2 { + + public CommandEndif2(ActivityDiagram2 diagram) { + super(diagram, getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), + new RegexLeaf("endif"), + new RegexLeaf("$")); + } + + + @Override + protected CommandExecutionResult executeArg(Map arg) { + if (getSystem().getLastEntityConsulted() == null) { + return CommandExecutionResult.error("No if for this endif"); + } + getSystem().endif(); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandIf2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandIf2.java new file mode 100644 index 000000000..3348ec370 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandIf2.java @@ -0,0 +1,90 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4762 $ + * + */ +package net.sourceforge.plantuml.activitydiagram2.command; + +import java.util.Map; + +import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexPartialMatch; + +public class CommandIf2 extends SingleLineCommand2 { + + public CommandIf2(ActivityDiagram2 diagram) { + super(diagram, getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), + new RegexLeaf("if"), + new RegexLeaf("\\s*"), + new RegexLeaf("TEST", "\"([^\"]+)\""), + new RegexLeaf("\\s*"), + new RegexLeaf("then"), + new RegexLeaf("$")); + } + + + @Override + protected CommandExecutionResult executeArg(Map arg) { +// + getSystem().startIf(arg.get("TEST").get(0)); +// +// int lenght = 2; +// +// if (arg.get("ARROW").get(0) != null) { +// final String arrow = StringUtils.manageArrowForCuca(arg.get("ARROW").get(0)); +// lenght = arrow.length() - 1; +// } +// +// final IEntity branch = getSystem().getCurrentContext().getBranch(); +// +// Link link = new Link(entity1, branch, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), arg.get("BRACKET").get(0), +// lenght, null, arg.get("IF").get(0), getSystem().getLabeldistance(), getSystem().getLabelangle()); +// if (arg.get("ARROW").get(0) != null) { +// final Direction direction = StringUtils.getArrowDirection(arg.get("ARROW").get(0)); +// if (direction == Direction.LEFT || direction == Direction.UP) { +// link = link.getInv(); +// } +// } +// +// getSystem().addLink(link); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity.java new file mode 100644 index 000000000..b05d11e8f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity.java @@ -0,0 +1,57 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4762 $ + * + */ +package net.sourceforge.plantuml.activitydiagram2.command; + +import java.util.List; + +import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand; + +public class CommandNewActivity extends SingleLineCommand { + + public CommandNewActivity(ActivityDiagram2 diagram) { + super(diagram, "(?i)^\"([^\"]+)\"$"); + } + + @Override + protected CommandExecutionResult executeArg(List arg) { + if (getSystem().entities().size() == 0) { + return CommandExecutionResult.error("Missing start keyword"); + } + getSystem().newActivity(arg.get(0)); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandStart.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandStart.java new file mode 100644 index 000000000..59ee8f750 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandStart.java @@ -0,0 +1,57 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4762 $ + * + */ +package net.sourceforge.plantuml.activitydiagram2.command; + +import java.util.List; + +import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand; + +public class CommandStart extends SingleLineCommand { + + public CommandStart(ActivityDiagram2 diagram) { + super(diagram, "(?i)^start$"); + } + + @Override + protected CommandExecutionResult executeArg(List arg) { + if (getSystem().entities().size() > 0) { + return CommandExecutionResult.error("Cannot start this here"); + } + getSystem().start(); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java b/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java index e73705e7e..00f7cbb81 100644 --- a/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java +++ b/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5616 $ + * Revision $Revision: 5895 $ * */ package net.sourceforge.plantuml.classdiagram; @@ -48,7 +48,7 @@ public class ClassDiagram extends AbstractClassOrObjectDiagram { public IEntity getOrCreateEntity(String code, EntityType defaultType) { assert defaultType == EntityType.ABSTRACT_CLASS || defaultType == EntityType.CLASS || defaultType == EntityType.INTERFACE || defaultType == EntityType.ENUM - || defaultType == EntityType.LOLLIPOP; + || defaultType == EntityType.LOLLIPOP || defaultType == EntityType.POINT_FOR_ASSOCIATION; code = getFullyQualifiedCode(code); if (super.entityExist(code)) { return super.getOrCreateEntity(code, defaultType); diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java deleted file mode 100644 index 7b373414a..000000000 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java +++ /dev/null @@ -1,418 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5848 $ - * - */ -package net.sourceforge.plantuml.classdiagram.command; - -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import net.sourceforge.plantuml.Direction; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Group; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.cucadiagram.LinkDecor; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram; - -final public class CommandLinkClass extends SingleLineCommand { - - private static final int OFFSET = 1; - - private static final int FIRST_TYPE_AND_CLASS = 0 + OFFSET; - private static final int FIRST_TYPE = 1 + OFFSET; - private static final int FIRST_CLASS = 2 + OFFSET; - private static final int FIRST_LABEL = 3 + OFFSET; - private static final int LEFT_TO_RIGHT = 4 + OFFSET; - private static final int LEFT_TO_RIGHT_QUEUE = 5 + OFFSET; - private static final int LEFT_TO_RIGHT_HEAD = 6 + OFFSET; - private static final int RIGHT_TO_LEFT = 7 + OFFSET; - private static final int RIGHT_TO_LEFT_HEAD = 8 + OFFSET; - private static final int RIGHT_TO_LEFT_QUEUE = 9 + OFFSET; - private static final int NAV_AGREG_OR_COMPO_INV = 10 + OFFSET; - private static final int NAV_AGREG_OR_COMPO_INV_QUEUE = 11 + OFFSET; - private static final int NAV_AGREG_OR_COMPO_INV_HEAD = 12 + OFFSET; - private static final int NAV_AGREG_OR_COMPO = 13 + OFFSET; - private static final int NAV_AGREG_OR_COMPO_HEAD = 14 + OFFSET; - private static final int NAV_AGREG_OR_COMPO_QUEUE = 15 + OFFSET; - private static final int SECOND_LABEL = 16 + OFFSET; - private static final int SECOND_TYPE_AND_CLASS = 17 + OFFSET; - private static final int SECOND_TYPE = 18 + OFFSET; - private static final int SECOND_CLASS = 19 + OFFSET; - private static final int LINK_LABEL = 20 + OFFSET; - - private final Pattern patternAssociationPoint = Pattern - .compile("\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)"); - - // [\\p{L}0-9_.]+ - // \\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)* - - public CommandLinkClass(AbstractClassOrObjectDiagram diagram) { - super( - diagram, - "(?i)^(?:@([\\d.]+)\\s+)?((?:" - + optionalKeywords(diagram.getUmlDiagramType()) - + "\\s+)?" - + "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\)" - + ")\\s*(?:\"([^\"]+)\")?\\s*" - // split here - + "(?:" - + "(([-=.]+(?:left|right|up|down|le?|ri?|up?|do?)?[-=.]*)(o +|[\\]>*+]|\\|[>\\]])?)" - + "|" - + "(( +o|[\\[<*+]|[<\\[]\\|)?([-=.]*(?:left|right|up|down|le?|ri?|up?|do?)?[-=.]+))" - + "|" - + "(\\<([-=.]*(?:left|right|up|down|le?|ri?|up?|do?[-=.]+)?[-=.]+)(o +|\\*))" - + "|" - + "(( +o|\\*)([-=.]+(?:left|right|up|down|le?|ri?|up?|do?)?[-=.]*)\\>)" - + ")" - // split here - + "\\s*(?:\"([^\"]+)\")?\\s*((?:" - + optionalKeywords(diagram.getUmlDiagramType()) - + "\\s+)?" - + "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\)" - + ")\\s*(?::\\s*([^\"]+))?$"); - // "(?i)^(?:@(\\d+)\\s+)?((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?:\"([^\"]+)\")?\\s*" - // + - // "(?:(([-=.]+)([\\]>o*+]|\\|[>\\]])?)|(([\\[))" - // + - // "\\s*(?:\"([^\"]+)\")?\\s*((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?::\\s*([^\"]+))?$"); - } - - private static String optionalKeywords(UmlDiagramType type) { - if (type == UmlDiagramType.CLASS) { - return "(interface|enum|abstract\\s+class|abstract|class)"; - } - if (type == UmlDiagramType.OBJECT) { - return "(object)"; - } - throw new IllegalArgumentException(); - } - - @Override - protected CommandExecutionResult executeArg(List arg) { - if (arg.get(FIRST_TYPE_AND_CLASS).startsWith("(")) { - return executeArgSpecial1(arg); - } - if (arg.get(SECOND_TYPE_AND_CLASS).startsWith("(")) { - return executeArgSpecial2(arg); - } - if (getSystem().isGroup(arg.get(FIRST_CLASS)) && getSystem().isGroup(arg.get(SECOND_CLASS))) { - return executePackageLink(arg); - } - if (getSystem().isGroup(arg.get(FIRST_CLASS)) || getSystem().isGroup(arg.get(SECOND_CLASS))) { - return CommandExecutionResult.error("Package can be only linked to other package"); - } - - final Entity cl1 = (Entity) getSystem().getOrCreateClass(arg.get(FIRST_CLASS)); - final Entity cl2 = (Entity) getSystem().getOrCreateClass(arg.get(SECOND_CLASS)); - - if (arg.get(FIRST_TYPE) != null) { - final EntityType type = EntityType.getEntityType(arg.get(FIRST_TYPE)); - if (type != EntityType.OBJECT) { - cl1.muteToType(type); - } - } - if (arg.get(SECOND_TYPE) != null) { - final EntityType type = EntityType.getEntityType(arg.get(SECOND_TYPE)); - if (type != EntityType.OBJECT) { - cl2.muteToType(type); - } - } - - final LinkType linkType = getLinkType(arg); - final String queueRaw = getQueue(arg); - final String queue = StringUtils.manageQueueForCuca(queueRaw); - - Link link = new Link(cl1, cl2, linkType, arg.get(LINK_LABEL), queue.length(), arg.get(FIRST_LABEL), arg - .get(SECOND_LABEL), getSystem().getLabeldistance(), getSystem().getLabelangle()); - - if (queueRaw.matches(".*\\w.*")) { - if (arg.get(LEFT_TO_RIGHT) != null) { - Direction direction = StringUtils.getQueueDirection(arg.get(LEFT_TO_RIGHT_QUEUE)); - if (linkType.isExtendsOrAgregationOrCompositionOrPlus()) { - direction = direction.getInv(); - } - if (direction == Direction.LEFT || direction == Direction.UP) { - link = link.getInv(); - } - } - if (arg.get(RIGHT_TO_LEFT) != null) { - Direction direction = StringUtils.getQueueDirection(arg.get(RIGHT_TO_LEFT_QUEUE)); - if (linkType.isExtendsOrAgregationOrCompositionOrPlus()) { - direction = direction.getInv(); - } - if (direction == Direction.RIGHT || direction == Direction.DOWN) { - link = link.getInv(); - } - } - if (arg.get(NAV_AGREG_OR_COMPO) != null) { - Direction direction = StringUtils.getQueueDirection(arg.get(NAV_AGREG_OR_COMPO_QUEUE)); - if (linkType.isExtendsOrAgregationOrCompositionOrPlus()) { - direction = direction.getInv(); - } - if (direction == Direction.RIGHT || direction == Direction.DOWN) { - link = link.getInv(); - } - } - if (arg.get(NAV_AGREG_OR_COMPO_INV) != null) { - Direction direction = StringUtils.getQueueDirection(arg.get(NAV_AGREG_OR_COMPO_INV_QUEUE)); - if (linkType.isExtendsOrAgregationOrCompositionOrPlus()) { - direction = direction.getInv(); - } - if (direction == Direction.LEFT || direction == Direction.UP) { - link = link.getInv(); - } - } - } - - getSystem().resetPragmaLabel(); - addLink(link, arg.get(0)); - - return CommandExecutionResult.ok(); - } - - private void addLink(Link link, String arg0) { - getSystem().addLink(link); - if (arg0 == null) { - final LinkType type = link.getType(); - // --|> highest - // --*, -->, --o normal - // ..*, ..>, ..o lowest - // if (type.isDashed() == false) { - // if (type.contains(LinkDecor.EXTENDS)) { - // link.setWeight(3); - // } - // if (type.contains(LinkDecor.ARROW) || - // type.contains(LinkDecor.COMPOSITION) - // || type.contains(LinkDecor.AGREGATION)) { - // link.setWeight(2); - // } - // } - } else { - link.setWeight(Double.parseDouble(arg0)); - } - } - - private CommandExecutionResult executePackageLink(List arg) { - final Group cl1 = getSystem().getGroup(arg.get(FIRST_CLASS)); - final Group cl2 = getSystem().getGroup(arg.get(SECOND_CLASS)); - - final LinkType linkType = getLinkType(arg); - final String queue = getQueue(arg); - - final Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get(LINK_LABEL), queue - .length(), arg.get(FIRST_LABEL), arg.get(SECOND_LABEL), getSystem().getLabeldistance(), getSystem() - .getLabelangle()); - getSystem().resetPragmaLabel(); - addLink(link, arg.get(0)); - return CommandExecutionResult.ok(); - } - - private CommandExecutionResult executeArgSpecial1(List arg) { - final Matcher m = patternAssociationPoint.matcher(arg.get(FIRST_TYPE_AND_CLASS)); - if (m.matches() == false) { - throw new IllegalStateException(); - } - final String clName1 = m.group(1); - final String clName2 = m.group(2); - if (getSystem().entityExist(clName1) == false) { - return CommandExecutionResult.error("No class " + clName1); - } - if (getSystem().entityExist(clName2) == false) { - return CommandExecutionResult.error("No class " + clName2); - } - final IEntity entity1 = getSystem().getOrCreateClass(clName1); - final IEntity entity2 = getSystem().getOrCreateClass(clName2); - - final Entity node = getSystem().createEntity(arg.get(FIRST_TYPE_AND_CLASS), "node", - EntityType.POINT_FOR_ASSOCIATION); - - getSystem().insertBetween(entity1, entity2, node); - final IEntity cl2 = getSystem().getOrCreateClass(arg.get(SECOND_CLASS)); - - final LinkType linkType = getLinkType(arg); - final String queue = getQueue(arg); - - final Link link = new Link(node, cl2, linkType, arg.get(LINK_LABEL), queue.length()); - addLink(link, arg.get(0)); - - return CommandExecutionResult.ok(); - } - - private CommandExecutionResult executeArgSpecial2(List arg) { - final Matcher m = patternAssociationPoint.matcher(arg.get(SECOND_TYPE_AND_CLASS)); - if (m.matches() == false) { - throw new IllegalStateException(); - } - final String clName1 = m.group(1); - final String clName2 = m.group(2); - if (getSystem().entityExist(clName1) == false) { - return CommandExecutionResult.error("No class " + clName1); - } - if (getSystem().entityExist(clName2) == false) { - return CommandExecutionResult.error("No class " + clName2); - } - final IEntity entity1 = getSystem().getOrCreateClass(clName1); - final IEntity entity2 = getSystem().getOrCreateClass(clName2); - - final IEntity node = getSystem().createEntity(arg.get(SECOND_TYPE_AND_CLASS), "node", - EntityType.POINT_FOR_ASSOCIATION); - - getSystem().insertBetween(entity1, entity2, node); - final IEntity cl1 = getSystem().getOrCreateClass(arg.get(FIRST_TYPE_AND_CLASS)); - - final LinkType linkType = getLinkType(arg); - final String queue = getQueue(arg); - - final Link link = new Link(cl1, node, linkType, arg.get(LINK_LABEL), queue.length()); - addLink(link, arg.get(0)); - - return CommandExecutionResult.ok(); - } - - private LinkType getLinkTypeNormal(List arg) { - final String queue = arg.get(LEFT_TO_RIGHT_QUEUE).trim(); - String key = arg.get(LEFT_TO_RIGHT_HEAD); - if (key != null) { - key = key.trim(); - } - LinkType linkType = getLinkTypeFromKey(key); - - if (queue.startsWith(".")) { - linkType = linkType.getDashed(); - } - return linkType; - } - - private LinkType getLinkTypeInv(List arg) { - final String queue = arg.get(RIGHT_TO_LEFT_QUEUE).trim(); - String key = arg.get(RIGHT_TO_LEFT_HEAD); - if (key != null) { - key = key.trim(); - } - LinkType linkType = getLinkTypeFromKey(key); - - if (queue.startsWith(".")) { - linkType = linkType.getDashed(); - } - return linkType.getInv(); - } - - private LinkType getLinkType(List arg) { - if (arg.get(LEFT_TO_RIGHT) != null) { - return getLinkTypeNormal(arg); - } - if (arg.get(RIGHT_TO_LEFT) != null) { - return getLinkTypeInv(arg); - } - if (arg.get(NAV_AGREG_OR_COMPO_INV) != null) { - final String type = arg.get(NAV_AGREG_OR_COMPO_INV_HEAD).trim(); - final String queue = arg.get(NAV_AGREG_OR_COMPO_INV_QUEUE).trim(); - LinkType result; - if (type.equals("*")) { - result = new LinkType(LinkDecor.COMPOSITION, LinkDecor.ARROW); - } else if (type.equals("o")) { - result = new LinkType(LinkDecor.AGREGATION, LinkDecor.ARROW); - } else { - throw new IllegalArgumentException(); - } - if (queue.startsWith(".")) { - result = result.getDashed(); - } - return result; - } - if (arg.get(NAV_AGREG_OR_COMPO) != null) { - final String type = arg.get(NAV_AGREG_OR_COMPO_HEAD).trim(); - final String queue = arg.get(NAV_AGREG_OR_COMPO_QUEUE).trim(); - LinkType result; - if (type.equals("*")) { - result = new LinkType(LinkDecor.ARROW, LinkDecor.COMPOSITION); - } else if (type.equals("o")) { - result = new LinkType(LinkDecor.ARROW, LinkDecor.AGREGATION); - } else { - throw new IllegalArgumentException(); - } - if (queue.startsWith(".")) { - result = result.getDashed(); - } - return result; - } - throw new IllegalArgumentException(); - } - - private String getQueue(List arg) { - if (arg.get(LEFT_TO_RIGHT) != null) { - return arg.get(LEFT_TO_RIGHT_QUEUE).trim(); - } - if (arg.get(RIGHT_TO_LEFT) != null) { - return arg.get(RIGHT_TO_LEFT_QUEUE).trim(); - } - if (arg.get(NAV_AGREG_OR_COMPO_INV) != null) { - return arg.get(NAV_AGREG_OR_COMPO_INV_QUEUE).trim(); - } - if (arg.get(NAV_AGREG_OR_COMPO) != null) { - return arg.get(NAV_AGREG_OR_COMPO_QUEUE).trim(); - } - throw new IllegalArgumentException(); - } - - private LinkType getLinkTypeFromKey(String k) { - if (k == null) { - return new LinkType(LinkDecor.NONE, LinkDecor.NONE); - } - if (k.equals("+")) { - return new LinkType(LinkDecor.PLUS, LinkDecor.NONE); - } - if (k.equals("*")) { - return new LinkType(LinkDecor.COMPOSITION, LinkDecor.NONE); - } - if (k.equalsIgnoreCase("o")) { - return new LinkType(LinkDecor.AGREGATION, LinkDecor.NONE); - } - if (k.equals("<") || k.equals(">")) { - return new LinkType(LinkDecor.ARROW, LinkDecor.NONE); - } - if (k.equals("<|") || k.equals("|>")) { - return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); - } - // return null; - throw new IllegalArgumentException(k); - } - -} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java index 878baea8e..b3b207fc7 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java @@ -39,6 +39,7 @@ import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.UniqueSequence; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; @@ -136,12 +137,16 @@ final public class CommandLinkClass2 extends SingleLineCommand2 highest // --*, -->, --o normal @@ -187,7 +192,7 @@ final public class CommandLinkClass2 extends SingleLineCommand2 assocations = new ArrayList(); + + public boolean associationClass(int mode, String clName1, String clName2, IEntity associed, LinkType linkType, + String label) { + final IEntity entity1 = getOrCreateClass(clName1); + final IEntity entity2 = getOrCreateClass(clName2); + final List same = new ArrayList(); + for (Association existing : assocations) { + if (existing.sameCouple(entity1, entity2)) { + same.add(existing); + } + } + if (same.size() > 1) { + return false; + } else if (same.size() == 0) { + final Association association = new Association(mode, entity1, entity2, associed); + association.createNew(mode, linkType, label); + + this.assocations.add(association); + return true; + } + assert same.size() == 1; + final Association association = same.get(0).createSecondAssociation(mode, associed, label); + association.createInSecond(linkType, label); + + this.assocations.add(association); + return true; + } + + class Association { + private IEntity entity1; + private IEntity entity2; + private IEntity associed; + private IEntity point; + + private Link existingLink; + + private Link entity1ToPoint; + private Link pointToEntity2; + private Link pointToAssocied; + + private Association other; + + public Association(int mode, IEntity entity1, IEntity entity2, IEntity associed) { + this.entity1 = entity1; + this.entity2 = entity2; + this.associed = associed; + point = getOrCreateEntity("apoint" + UniqueSequence.getValue(), EntityType.POINT_FOR_ASSOCIATION); + + } + + public Association createSecondAssociation(int mode2, IEntity associed2, String label) { + final Association result = new Association(mode2, entity1, entity2, associed2); + result.existingLink = this.existingLink; + result.other = this; + + if (this.existingLink.getLength() == 1) { + this.entity1ToPoint.setLength(2); + this.pointToEntity2.setLength(2); + this.pointToAssocied.setLength(1); + } + return result; + } + + void createNew(int mode, LinkType linkType, String label) { + existingLink = foundLink(entity1, entity2); + if (existingLink == null) { + existingLink = new Link(entity1, entity2, new LinkType(LinkDecor.NONE, LinkDecor.NONE), null, 2); + } else { + removeLink(existingLink); + } + + entity1ToPoint = new Link(entity1, point, existingLink.getType().getPart2(), existingLink.getLabel(), existingLink + .getLength(), existingLink.getQualifier1(), null, existingLink.getLabeldistance(), existingLink + .getLabelangle()); + pointToEntity2 = new Link(point, entity2, existingLink.getType().getPart1(), existingLink.getLabel(), existingLink + .getLength(), null, existingLink.getQualifier2(), existingLink.getLabeldistance(), existingLink + .getLabelangle()); + addLink(entity1ToPoint); + addLink(pointToEntity2); + + int length = 1; + if (existingLink.getLength() == 1) { + length = 2; + } + + if (mode == 1) { + pointToAssocied = new Link(point, associed, linkType, label, length); + } else { + pointToAssocied = new Link(associed, point, linkType, label, length); + } + addLink(pointToAssocied); + } + + void createInSecond(LinkType linkType, String label) { + entity1ToPoint = new Link(entity1, point, existingLink.getType(), null, 2); + pointToEntity2 = new Link(point, entity2, existingLink.getType(), null, 2); + addLink(entity1ToPoint); + addLink(pointToEntity2); + if (other.pointToAssocied.getEntity1().getType() == EntityType.POINT_FOR_ASSOCIATION) { + removeLink(other.pointToAssocied); + other.pointToAssocied = other.pointToAssocied.getInv(); + addLink(other.pointToAssocied); + } + pointToAssocied = new Link(point, associed, linkType, label, 1); + addLink(pointToAssocied); + + final Link lnode = new Link(other.point, this.point, new LinkType(LinkDecor.NONE, LinkDecor.NONE), null, 1); + lnode.setInvis(true); + addLink(lnode); + + } + + boolean sameCouple(IEntity entity1, IEntity entity2) { + if (this.entity1 == entity1 && this.entity2 == entity2) { + return true; + } + if (this.entity1 == entity2 && this.entity2 == entity1) { + return true; + } + return false; + } + } + } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowAny.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowAny.java index 5350a91d5..7c678be7c 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowAny.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowAny.java @@ -76,20 +76,22 @@ abstract class CommandExoArrowAny extends SingleLineCommand { return CommandExecutionResult.ok(); } - final MessageExoType getMessageExoType(String arrow) { - if (arrow.startsWith("[") && arrow.endsWith(">")) { - return MessageExoType.FROM_LEFT; - } - if (arrow.startsWith("[<")) { - return MessageExoType.TO_LEFT; - } - if (arrow.startsWith("<") && arrow.endsWith("]")) { - return MessageExoType.FROM_RIGHT; - } - if (arrow.endsWith(">]")) { - return MessageExoType.TO_RIGHT; - } - throw new IllegalArgumentException(arrow); - } + abstract MessageExoType getMessageExoType(String arrow); + +// final MessageExoType getMessageExoType(String arrow) { +// if (arrow.startsWith("[") && arrow.endsWith(">")) { +// return MessageExoType.FROM_LEFT; +// } +// if (arrow.startsWith("[<")) { +// return MessageExoType.TO_LEFT; +// } +// if (arrow.startsWith("<") && arrow.endsWith("]")) { +// return MessageExoType.FROM_RIGHT; +// } +// if (arrow.endsWith(">]")) { +// return MessageExoType.TO_RIGHT; +// } +// throw new IllegalArgumentException(arrow); +// } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowLeft.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowLeft.java index be3feb2bf..28c56dae2 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowLeft.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowLeft.java @@ -33,15 +33,25 @@ */ package net.sourceforge.plantuml.sequencediagram.command; +import net.sourceforge.plantuml.sequencediagram.MessageExoType; import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; public class CommandExoArrowLeft extends CommandExoArrowAny { public CommandExoArrowLeft(SequenceDiagram sequenceDiagram) { - super( - sequenceDiagram, - "(?i)^(\\[[=-]+>{1,2}|\\[\\<{1,2}[=-]+)\\s*([\\p{L}0-9_.]+|\"[^\"]+\")\\s*(?::\\s*(.*))?$", - 0, 1); + super(sequenceDiagram, + "(?i)^(\\[?[=-]+>{1,2}|\\[?\\<{1,2}[=-]+)\\s*([\\p{L}0-9_.]+|\"[^\"]+\")\\s*(?::\\s*(.*))?$", 0, 1); + } + + @Override + MessageExoType getMessageExoType(String arrow) { + if (arrow.contains(">")) { + return MessageExoType.FROM_LEFT; + } + if (arrow.contains("<")) { + return MessageExoType.TO_LEFT; + } + throw new IllegalArgumentException(arrow); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowRight.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowRight.java index 835904f94..a36283e31 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowRight.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandExoArrowRight.java @@ -33,6 +33,7 @@ */ package net.sourceforge.plantuml.sequencediagram.command; +import net.sourceforge.plantuml.sequencediagram.MessageExoType; import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; public class CommandExoArrowRight extends CommandExoArrowAny { @@ -40,8 +41,19 @@ public class CommandExoArrowRight extends CommandExoArrowAny { public CommandExoArrowRight(SequenceDiagram sequenceDiagram) { super( sequenceDiagram, - "(?i)^([\\p{L}0-9_.]+|\"[^\"]+\")\\s*([=-]+>{1,2}\\]|\\<{1,2}[=-]+\\])\\s*(?::\\s*(.*))?$", + "(?i)^([\\p{L}0-9_.]+|\"[^\"]+\")\\s*([=-]+>{1,2}\\]?|\\<{1,2}[=-]+\\]?)\\s*(?::\\s*(.*))?$", 1, 0); } + @Override + MessageExoType getMessageExoType(String arrow) { + if (arrow.contains("<")) { + return MessageExoType.FROM_RIGHT; + } + if (arrow.contains(">")) { + return MessageExoType.TO_RIGHT; + } + throw new IllegalArgumentException(arrow); + } + } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingHeader.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingHeader.java index 80db5db35..e058374c8 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingHeader.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingHeader.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4258 $ + * Revision $Revision: 5889 $ * */ package net.sourceforge.plantuml.skin.bluemodern; @@ -128,8 +128,11 @@ public class ComponentBlueModernGroupingHeader extends AbstractTextualComponent ug.getParam().setColor(borderColor); ug.draw(0, 0, polygon); ug.draw(0, 0, new ULine(dimensionToUse.getWidth(), 0)); - ug.draw(dimensionToUse.getWidth(), 0, new ULine(0, dimensionToUse.getHeight())); - ug.draw(0, textHeight, new ULine(0, dimensionToUse.getHeight()-textHeight)); + + final double heightWithoutPadding = dimensionToUse.getHeight() - getPaddingY(); + + ug.draw(dimensionToUse.getWidth(), 0, new ULine(0, heightWithoutPadding)); + ug.draw(0, textHeight, new ULine(0, heightWithoutPadding - textHeight)); ug.getParam().setStroke(new UStroke()); getTextBlock().drawU(ug, getMarginX1(), getMarginY()); diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingHeader.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingHeader.java index 58ee2e0c1..232b65784 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingHeader.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingHeader.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4258 $ + * Revision $Revision: 5889 $ * */ package net.sourceforge.plantuml.skin.rose; @@ -133,9 +133,11 @@ public class ComponentRoseGroupingHeader extends AbstractTextualComponent { ug.getParam().setBackcolor(this.groupBackground); ug.draw(0, 0, polygon); + final double heightWithoutPadding = dimensionToUse.getHeight() - getPaddingY(); + ug.draw(0, 0, new ULine(dimensionToUse.getWidth(), 0)); - ug.draw(dimensionToUse.getWidth(), 0, new ULine(0, dimensionToUse.getHeight())); - ug.draw(0, textHeight, new ULine(0, dimensionToUse.getHeight()-textHeight)); + ug.draw(dimensionToUse.getWidth(), 0, new ULine(0, heightWithoutPadding)); + ug.draw(0, textHeight, new ULine(0, heightWithoutPadding-textHeight)); ug.getParam().setStroke(new UStroke()); getTextBlock().drawU(ug, getMarginX1(), getMarginY()); diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 74b6de0ef..15c01403d 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5879 $ + * Revision $Revision: 5912 $ * */ package net.sourceforge.plantuml.version; @@ -36,11 +36,11 @@ package net.sourceforge.plantuml.version; public class Version { public static int version() { - return 5878; + return 5911; } public static long compileTime() { - return 1294177111625L; + return 1294598580421L; } }