1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-25 22:37:33 +00:00

Version 5911

This commit is contained in:
Arnaud Roques 2011-01-09 20:00:05 +01:00
parent 9005abef50
commit a8bf09d279
22 changed files with 783 additions and 537 deletions

View File

@ -39,6 +39,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory; import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory;
import net.sourceforge.plantuml.activitydiagram2.ActivityDiagramFactory2;
import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory; import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory;
import net.sourceforge.plantuml.componentdiagram.ComponentDiagramFactory; import net.sourceforge.plantuml.componentdiagram.ComponentDiagramFactory;
import net.sourceforge.plantuml.compositediagram.CompositeDiagramFactory; import net.sourceforge.plantuml.compositediagram.CompositeDiagramFactory;
@ -63,9 +64,11 @@ public class PSystemBuilder {
factories.add(new SequenceDiagramFactory()); factories.add(new SequenceDiagramFactory());
factories.add(new ClassDiagramFactory()); factories.add(new ClassDiagramFactory());
factories.add(new ActivityDiagramFactory()); factories.add(new ActivityDiagramFactory());
factories.add(new ActivityDiagramFactory2());
factories.add(new UsecaseDiagramFactory()); factories.add(new UsecaseDiagramFactory());
factories.add(new ComponentDiagramFactory()); factories.add(new ComponentDiagramFactory());
factories.add(new StateDiagramFactory()); factories.add(new StateDiagramFactory());
factories.add(new ActivityDiagramFactory2());
factories.add(new CompositeDiagramFactory()); factories.add(new CompositeDiagramFactory());
factories.add(new ObjectDiagramFactory()); factories.add(new ObjectDiagramFactory());
factories.add(new PrintSkinFactory()); factories.add(new PrintSkinFactory());

View File

@ -28,7 +28,7 @@
* *
* Original Author: Arnaud Roques * Original Author: Arnaud Roques
* *
* Revision $Revision: 5794 $ * Revision $Revision: 5898 $
*/ */
package net.sourceforge.plantuml; package net.sourceforge.plantuml;
@ -59,20 +59,39 @@ public class PSystemError extends AbstractPSystem {
this.errorsUml.addAll(errorUml); this.errorsUml.addAll(errorUml);
this.setSource(source); this.setSource(source);
final Collection<ErrorUml> executions = getErrors(ErrorUmlType.EXECUTION_ERROR); final int higherErrorPositionExecution = getHigherErrorPosition(ErrorUmlType.EXECUTION_ERROR);
if (executions.size() > 0) { final int higherErrorPositionSyntax = getHigherErrorPosition(ErrorUmlType.SYNTAX_ERROR);
higherErrorPosition = getHigherErrorPosition(ErrorUmlType.EXECUTION_ERROR);
errs = getErrorsAt(higherErrorPosition, ErrorUmlType.EXECUTION_ERROR); if (higherErrorPositionExecution == Integer.MIN_VALUE && higherErrorPositionSyntax == Integer.MIN_VALUE) {
appendSource(higherErrorPosition, errs); throw new IllegalStateException();
} else {
higherErrorPosition = getHigherErrorPosition(ErrorUmlType.SYNTAX_ERROR);
errs = getErrorsAt(higherErrorPosition, ErrorUmlType.SYNTAX_ERROR);
if (errs.size() != 1) {
throw new UnsupportedOperationException(errs.toString());
}
appendSource(higherErrorPosition, errs);
} }
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<ErrorUml> 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) { public PSystemError(UmlSource source, ErrorUml... errorUml) {
@ -154,9 +173,9 @@ public class PSystemError extends AbstractPSystem {
max = error.getPosition(); max = error.getPosition();
} }
} }
if (max == Integer.MIN_VALUE) { // if (max == Integer.MIN_VALUE) {
throw new IllegalStateException(); // throw new IllegalStateException();
} // }
return max; return max;
} }

View File

@ -28,7 +28,7 @@
* *
* Original Author: Arnaud Roques * Original Author: Arnaud Roques
* *
* Revision $Revision: 5847 $ * Revision $Revision: 5890 $
* *
*/ */
package net.sourceforge.plantuml.activitydiagram; 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.CommandEndPartition;
import net.sourceforge.plantuml.activitydiagram.command.CommandEndif; import net.sourceforge.plantuml.activitydiagram.command.CommandEndif;
import net.sourceforge.plantuml.activitydiagram.command.CommandIf; 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.CommandLinkActivity;
import net.sourceforge.plantuml.activitydiagram.command.CommandLinkLongActivity; import net.sourceforge.plantuml.activitydiagram.command.CommandLinkLongActivity;
import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivity; import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivity;

View File

@ -54,42 +54,32 @@ import net.sourceforge.plantuml.cucadiagram.Stereotype;
public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> { public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
public CommandLinkActivity(ActivityDiagram diagram) { public CommandLinkActivity(ActivityDiagram diagram) {
super( super(diagram, getRegexConcat());
diagram, getRegexConcat());
} }
static RegexConcat getRegexConcat() { static RegexConcat getRegexConcat() {
return new RegexConcat(new RegexLeaf("^"), return new RegexConcat(new RegexLeaf("^"), new RegexOr("FIRST", true, new RegexLeaf("STAR", "(\\(\\*\\))"),
new RegexOr("FIRST", true, new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), new RegexLeaf("BAR",
new RegexLeaf("STAR", "(\\(\\*\\))"), "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), new RegexLeaf("QUOTED",
new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), new RegexLeaf("\\s*"), new RegexLeaf(
new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), "STEREOTYPE", "(\\<\\<.*\\>\\>)?"), new RegexLeaf("\\s*"), new RegexLeaf("BACKCOLOR", "(#\\w+)?"),
new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), new RegexLeaf("\\s*"),
new RegexLeaf("\\s*"), new RegexLeaf("ARROW", "([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)"),
new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), new RegexLeaf("\\s*"), new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), new RegexLeaf("\\s*"),
new RegexLeaf("\\s*"), new RegexOr("FIRST2", new RegexLeaf("STAR2", "(\\(\\*\\))"), new RegexLeaf("OPENBRACKET2", "(\\{)"),
new RegexLeaf("BACKCOLOR", "(#\\w+)?"), new RegexLeaf("CODE2", "([\\p{L}0-9_.]+)"), new RegexLeaf("BAR2",
new RegexLeaf("\\s*"), "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), new RegexLeaf("QUOTED2",
new RegexLeaf("ARROW", "([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)"), "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), new RegexLeaf("\\s*"), new RegexLeaf(
new RegexLeaf("\\s*"), "STEREOTYPE2", "(\\<\\<.*\\>\\>)?"), new RegexLeaf("\\s*"), new RegexLeaf("BACKCOLOR2",
new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), "(#\\w+)?"), new RegexLeaf("$"));
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 @Override
protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg2) { protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg2) {
final IEntity entity1 = getEntity(getSystem(), arg2, true); final IEntity entity1 = getEntity(getSystem(), arg2, true);
if (entity1 == null) {
return CommandExecutionResult.error("No such activity");
}
if (arg2.get("STEREOTYPE").get(0) != null) { if (arg2.get("STEREOTYPE").get(0) != null) {
entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0))); entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0)));
} }
@ -98,6 +88,9 @@ public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
} }
final IEntity entity2 = getEntity(getSystem(), arg2, false); final IEntity entity2 = getEntity(getSystem(), arg2, false);
if (entity2 == null) {
return CommandExecutionResult.error("No such activity");
}
if (arg2.get("BACKCOLOR2").get(0) != null) { if (arg2.get("BACKCOLOR2").get(0) != null) {
entity2.setSpecificBackcolor(arg2.get("BACKCOLOR2").get(0)); entity2.setSpecificBackcolor(arg2.get("BACKCOLOR2").get(0));
} }
@ -122,14 +115,11 @@ public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
} }
static IEntity getEntity(ActivityDiagram system, Map<String, RegexPartialMatch> arg, final boolean start) { static IEntity getEntity(ActivityDiagram system, Map<String, RegexPartialMatch> arg, final boolean start) {
final String suf = start ? "" : "2"; final String suf = start ? "" : "2";
final RegexPartialMatch openBracket = arg.get("OPENBRACKET" + suf); final RegexPartialMatch openBracket = arg.get("OPENBRACKET" + suf);
if (openBracket!=null && openBracket.get(0) != null) { if (openBracket != null && openBracket.get(0) != null) {
return system.createInnerActivity(); return system.createInnerActivity();
} }
if (arg.get("STAR" + suf).get(0) != null) { if (arg.get("STAR" + suf).get(0) != null) {
@ -149,8 +139,7 @@ public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
final RegexPartialMatch quoted = arg.get("QUOTED" + suf); final RegexPartialMatch quoted = arg.get("QUOTED" + suf);
if (quoted.get(0) != null) { if (quoted.get(0) != null) {
final String quotedCode = quoted.get(1) == null ? quoted.get(0) : quoted.get(1); final String quotedCode = quoted.get(1) == null ? quoted.get(0) : quoted.get(1);
return system.getOrCreate(quotedCode, quoted.get(0), getTypeIfExisting(system, return system.getOrCreate(quotedCode, quoted.get(0), getTypeIfExisting(system, quotedCode));
quotedCode));
} }
final String first = arg.get("FIRST" + suf).get(0); final String first = arg.get("FIRST" + suf).get(0);
if (first == null) { if (first == null) {
@ -159,7 +148,6 @@ public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
static EntityType getTypeIfExisting(ActivityDiagram system, String code) { static EntityType getTypeIfExisting(ActivityDiagram system, String code) {
if (system.entityExist(code)) { if (system.entityExist(code)) {
final IEntity ent = system.entities().get(code); final IEntity ent = system.entities().get(code);
@ -183,5 +171,4 @@ public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
} }

View File

@ -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<String> 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();
}
}

View File

@ -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));
}
}

View File

@ -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<ActivityDiagram2> {
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<String, RegexPartialMatch> arg) {
if (getSystem().getLastEntityConsulted() == null) {
return CommandExecutionResult.error("No if for this endif");
}
getSystem().endif();
return CommandExecutionResult.ok();
}
}

View File

@ -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<ActivityDiagram2> {
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<String, RegexPartialMatch> 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();
}
}

View File

@ -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<ActivityDiagram2> {
public CommandNewActivity(ActivityDiagram2 diagram) {
super(diagram, "(?i)^\"([^\"]+)\"$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (getSystem().entities().size() == 0) {
return CommandExecutionResult.error("Missing start keyword");
}
getSystem().newActivity(arg.get(0));
return CommandExecutionResult.ok();
}
}

View File

@ -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<ActivityDiagram2> {
public CommandStart(ActivityDiagram2 diagram) {
super(diagram, "(?i)^start$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (getSystem().entities().size() > 0) {
return CommandExecutionResult.error("Cannot start this here");
}
getSystem().start();
return CommandExecutionResult.ok();
}
}

View File

@ -28,7 +28,7 @@
* *
* Original Author: Arnaud Roques * Original Author: Arnaud Roques
* *
* Revision $Revision: 5616 $ * Revision $Revision: 5895 $
* *
*/ */
package net.sourceforge.plantuml.classdiagram; package net.sourceforge.plantuml.classdiagram;
@ -48,7 +48,7 @@ public class ClassDiagram extends AbstractClassOrObjectDiagram {
public IEntity getOrCreateEntity(String code, EntityType defaultType) { public IEntity getOrCreateEntity(String code, EntityType defaultType) {
assert defaultType == EntityType.ABSTRACT_CLASS || defaultType == EntityType.CLASS assert defaultType == EntityType.ABSTRACT_CLASS || defaultType == EntityType.CLASS
|| defaultType == EntityType.INTERFACE || defaultType == EntityType.ENUM || defaultType == EntityType.INTERFACE || defaultType == EntityType.ENUM
|| defaultType == EntityType.LOLLIPOP; || defaultType == EntityType.LOLLIPOP || defaultType == EntityType.POINT_FOR_ASSOCIATION;
code = getFullyQualifiedCode(code); code = getFullyQualifiedCode(code);
if (super.entityExist(code)) { if (super.entityExist(code)) {
return super.getOrCreateEntity(code, defaultType); return super.getOrCreateEntity(code, defaultType);

View File

@ -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<AbstractClassOrObjectDiagram> {
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*+]|\\|[>\\]])?)|(([\\[<o*+]|[<\\[]\\|)?([-=.]+))|(\\<([-=.]+)([o*]))|(([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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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);
}
}

View File

@ -39,6 +39,7 @@ import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexConcat;
@ -136,12 +137,16 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
} }
} }
if (arg.get("ENT1").get(2) != null) { if (arg.get("ENT1").get(2) != null) {
cl1.setStereotype(new Stereotype(arg.get("ENT1").get(2), getSystem().getSkinParam().getCircledCharacterRadius(), cl1
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); .setStereotype(new Stereotype(arg.get("ENT1").get(2), getSystem().getSkinParam()
.getCircledCharacterRadius(), getSystem().getSkinParam().getFont(
FontParam.CIRCLED_CHARACTER, null)));
} }
if (arg.get("ENT2").get(2) != null) { if (arg.get("ENT2").get(2) != null) {
cl2.setStereotype(new Stereotype(arg.get("ENT2").get(2), getSystem().getSkinParam().getCircledCharacterRadius(), cl2
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); .setStereotype(new Stereotype(arg.get("ENT2").get(2), getSystem().getSkinParam()
.getCircledCharacterRadius(), getSystem().getSkinParam().getFont(
FontParam.CIRCLED_CHARACTER, null)));
} }
final LinkType linkType = getLinkType(arg); final LinkType linkType = getLinkType(arg);
@ -163,15 +168,15 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
link = link.getInv(); link = link.getInv();
} }
// getSystem().resetPragmaLabel(); // getSystem().resetPragmaLabel();
addLink(link, arg.get("HEADER").get(0)); addLink(link, arg.get("HEADER").get(0));
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();
} }
private void addLink(Link link, String arg0) { private void addLink(Link link, String weight) {
getSystem().addLink(link); getSystem().addLink(link);
if (arg0 == null) { if (weight == null) {
final LinkType type = link.getType(); final LinkType type = link.getType();
// --|> highest // --|> highest
// --*, -->, --o normal // --*, -->, --o normal
@ -187,7 +192,7 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
// } // }
// } // }
} else { } else {
link.setWeight(Double.parseDouble(arg0)); link.setWeight(Double.parseDouble(weight));
} }
} }
@ -206,9 +211,9 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
queue = getQueue(arg); queue = getQueue(arg);
} }
Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get("LABEL_LINK").get( Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get("LABEL_LINK").get(0),
0), queue.length(), arg.get("FIRST_LABEL").get(0), arg.get("SECOND_LABEL").get(0), getSystem() queue.length(), arg.get("FIRST_LABEL").get(0), arg.get("SECOND_LABEL").get(0), getSystem()
.getLabeldistance(), getSystem().getLabelangle()); .getLabeldistance(), getSystem().getLabelangle());
if (dir == Direction.LEFT || dir == Direction.UP) { if (dir == Direction.LEFT || dir == Direction.UP) {
link = link.getInv(); link = link.getInv();
} }
@ -227,16 +232,19 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
if (getSystem().entityExist(clName2) == false) { if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2); return CommandExecutionResult.error("No class " + clName2);
} }
final Entity node = createAssociationPoint(clName1, clName2);
final String ent2 = arg.get("ENT2").get(1); final String ent2 = arg.get("ENT2").get(1);
final IEntity cl2 = getSystem().getOrCreateClass(ent2); final IEntity cl2 = getSystem().getOrCreateClass(ent2);
final LinkType linkType = getLinkType(arg); final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg); final String label = arg.get("LABEL_LINK").get(0);
final int length = getQueue(arg).length();
final String weight = arg.get("HEADER").get(0);
final Link link = new Link(node, cl2, linkType, arg.get("LABEL_LINK").get(0), queue.length()); final boolean result = getSystem().associationClass(1, clName1, clName2, cl2, linkType, label);
addLink(link, arg.get("HEADER").get(0)); if (result == false) {
return CommandExecutionResult.error("Cannot have more than 2 assocications");
}
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();
} }
@ -250,30 +258,23 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
if (getSystem().entityExist(clName2) == false) { if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2); return CommandExecutionResult.error("No class " + clName2);
} }
final Entity node = createAssociationPoint(clName1, clName2);
final String ent1 = arg.get("ENT1").get(1); final String ent1 = arg.get("ENT1").get(1);
final IEntity cl1 = getSystem().getOrCreateClass(ent1); final IEntity cl1 = getSystem().getOrCreateClass(ent1);
final LinkType linkType = getLinkType(arg); final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg); final String label = arg.get("LABEL_LINK").get(0);
final int length = getQueue(arg).length();
final String weight = arg.get("HEADER").get(0);
final Link link = new Link(cl1, node, linkType, arg.get("LABEL_LINK").get(0), queue.length()); final boolean result = getSystem().associationClass(2, clName1, clName2, cl1, linkType, label);
addLink(link, arg.get("HEADER").get(0)); if (result == false) {
return CommandExecutionResult.error("Cannot have more than 2 assocications");
}
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();
} }
private Entity createAssociationPoint(final String clName1, final String clName2) {
final IEntity entity1 = getSystem().getOrCreateClass(clName1);
final IEntity entity2 = getSystem().getOrCreateClass(clName2);
final Entity node = getSystem().createEntity(clName1 + "," + clName2, "node", EntityType.POINT_FOR_ASSOCIATION);
getSystem().insertBetween(entity1, entity2, node);
return node;
}
private LinkType getLinkTypeNormal(RegexPartialMatch regexPartialMatch) { private LinkType getLinkTypeNormal(RegexPartialMatch regexPartialMatch) {
final String queue = regexPartialMatch.get(1).trim() + regexPartialMatch.get(3).trim(); final String queue = regexPartialMatch.get(1).trim() + regexPartialMatch.get(3).trim();
final String key = regexPartialMatch.get(4); final String key = regexPartialMatch.get(4);

View File

@ -28,7 +28,7 @@
* *
* Original Author: Arnaud Roques * Original Author: Arnaud Roques
* *
* Revision $Revision: 5848 $ * Revision $Revision: 5908 $
* *
*/ */
package net.sourceforge.plantuml.cucadiagram; package net.sourceforge.plantuml.cucadiagram;
@ -52,7 +52,7 @@ public class Link implements Imaged {
final private LinkType type; final private LinkType type;
final private String label; final private String label;
final private int length; private int length;
final private String qualifier1; final private String qualifier1;
final private String qualifier2; final private String qualifier2;
final private String uid = "LNK" + UniqueSequence.getValue(); final private String uid = "LNK" + UniqueSequence.getValue();
@ -169,6 +169,10 @@ public class Link implements Imaged {
return length; return length;
} }
public final void setLength(int length) {
this.length = length;
}
public String getQualifier1() { public String getQualifier1() {
return qualifier1; return qualifier1;
} }

View File

@ -147,4 +147,12 @@ public class LinkType {
|| decor2 == LinkDecor.COMPOSITION; || decor2 == LinkDecor.COMPOSITION;
} }
public LinkType getPart1() {
return new LinkType(decor1, style, LinkDecor.NONE);
}
public LinkType getPart2() {
return new LinkType(LinkDecor.NONE, style, decor2);
}
} }

View File

@ -33,15 +33,22 @@
*/ */
package net.sourceforge.plantuml.objectdiagram; package net.sourceforge.plantuml.objectdiagram;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
import net.sourceforge.plantuml.cucadiagram.EntityType; import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public abstract class AbstractClassOrObjectDiagram extends AbstractEntityDiagram { public abstract class AbstractClassOrObjectDiagram extends AbstractEntityDiagram {
// private Link last = null;
// private IEntity lastNode = null;
final public boolean insertBetween(IEntity entity1, IEntity entity2, IEntity node) { final public boolean insertBetween(IEntity entity1, IEntity entity2, IEntity node) {
final Link link = foundLink(entity1, entity2); final Link link = foundLink(entity1, entity2);
if (link == null) { if (link == null) {
@ -85,4 +92,158 @@ public abstract class AbstractClassOrObjectDiagram extends AbstractEntityDiagram
} }
return result; return result;
} }
// final public void insertBetweenNew(IEntity entity1, IEntity entity2,
// IEntity node) {
// Link link = foundLink(entity1, entity2);
// if (link == null) {
// link = last;
// }
// final Link l1 = new Link(entity1, node, link.getType(), link.getLabel(),
// link.getLength(),
// link.getQualifier1(), null, link.getLabeldistance(),
// link.getLabelangle());
// final Link l2 = new Link(node, entity2, link.getType(), link.getLabel(),
// link.getLength(), null, link
// .getQualifier2(), link.getLabeldistance(), link.getLabelangle());
// addLink(l1);
// addLink(l2);
// if (last == null) {
// removeLink(link);
// } else {
// final Link lnode = new Link(lastNode, node, link.getType(),
// link.getLabel(), 1);
// lnode.setInvis(true);
// // lnode.setWeight(100);
// addLink(lnode);
// }
// last = link;
// lastNode = node;
// // return true;
// }
private final List<Association> assocations = new ArrayList<Association>();
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<Association> same = new ArrayList<Association>();
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;
}
}
} }

View File

@ -76,20 +76,22 @@ abstract class CommandExoArrowAny extends SingleLineCommand<SequenceDiagram> {
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();
} }
final MessageExoType getMessageExoType(String arrow) { abstract MessageExoType getMessageExoType(String arrow);
if (arrow.startsWith("[") && arrow.endsWith(">")) {
return MessageExoType.FROM_LEFT; // final MessageExoType getMessageExoType(String arrow) {
} // if (arrow.startsWith("[") && arrow.endsWith(">")) {
if (arrow.startsWith("[<")) { // return MessageExoType.FROM_LEFT;
return MessageExoType.TO_LEFT; // }
} // if (arrow.startsWith("[<")) {
if (arrow.startsWith("<") && arrow.endsWith("]")) { // return MessageExoType.TO_LEFT;
return MessageExoType.FROM_RIGHT; // }
} // if (arrow.startsWith("<") && arrow.endsWith("]")) {
if (arrow.endsWith(">]")) { // return MessageExoType.FROM_RIGHT;
return MessageExoType.TO_RIGHT; // }
} // if (arrow.endsWith(">]")) {
throw new IllegalArgumentException(arrow); // return MessageExoType.TO_RIGHT;
} // }
// throw new IllegalArgumentException(arrow);
// }
} }

View File

@ -33,15 +33,25 @@
*/ */
package net.sourceforge.plantuml.sequencediagram.command; package net.sourceforge.plantuml.sequencediagram.command;
import net.sourceforge.plantuml.sequencediagram.MessageExoType;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; import net.sourceforge.plantuml.sequencediagram.SequenceDiagram;
public class CommandExoArrowLeft extends CommandExoArrowAny { public class CommandExoArrowLeft extends CommandExoArrowAny {
public CommandExoArrowLeft(SequenceDiagram sequenceDiagram) { public CommandExoArrowLeft(SequenceDiagram sequenceDiagram) {
super( super(sequenceDiagram,
sequenceDiagram, "(?i)^(\\[?[=-]+>{1,2}|\\[?\\<{1,2}[=-]+)\\s*([\\p{L}0-9_.]+|\"[^\"]+\")\\s*(?::\\s*(.*))?$", 0, 1);
"(?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);
} }
} }

View File

@ -33,6 +33,7 @@
*/ */
package net.sourceforge.plantuml.sequencediagram.command; package net.sourceforge.plantuml.sequencediagram.command;
import net.sourceforge.plantuml.sequencediagram.MessageExoType;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; import net.sourceforge.plantuml.sequencediagram.SequenceDiagram;
public class CommandExoArrowRight extends CommandExoArrowAny { public class CommandExoArrowRight extends CommandExoArrowAny {
@ -40,8 +41,19 @@ public class CommandExoArrowRight extends CommandExoArrowAny {
public CommandExoArrowRight(SequenceDiagram sequenceDiagram) { public CommandExoArrowRight(SequenceDiagram sequenceDiagram) {
super( super(
sequenceDiagram, 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); 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);
}
} }

View File

@ -28,7 +28,7 @@
* *
* Original Author: Arnaud Roques * Original Author: Arnaud Roques
* *
* Revision $Revision: 4258 $ * Revision $Revision: 5889 $
* *
*/ */
package net.sourceforge.plantuml.skin.bluemodern; package net.sourceforge.plantuml.skin.bluemodern;
@ -128,8 +128,11 @@ public class ComponentBlueModernGroupingHeader extends AbstractTextualComponent
ug.getParam().setColor(borderColor); ug.getParam().setColor(borderColor);
ug.draw(0, 0, polygon); ug.draw(0, 0, polygon);
ug.draw(0, 0, new ULine(dimensionToUse.getWidth(), 0)); 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()); ug.getParam().setStroke(new UStroke());
getTextBlock().drawU(ug, getMarginX1(), getMarginY()); getTextBlock().drawU(ug, getMarginX1(), getMarginY());

View File

@ -28,7 +28,7 @@
* *
* Original Author: Arnaud Roques * Original Author: Arnaud Roques
* *
* Revision $Revision: 4258 $ * Revision $Revision: 5889 $
* *
*/ */
package net.sourceforge.plantuml.skin.rose; package net.sourceforge.plantuml.skin.rose;
@ -133,9 +133,11 @@ public class ComponentRoseGroupingHeader extends AbstractTextualComponent {
ug.getParam().setBackcolor(this.groupBackground); ug.getParam().setBackcolor(this.groupBackground);
ug.draw(0, 0, polygon); ug.draw(0, 0, polygon);
final double heightWithoutPadding = dimensionToUse.getHeight() - getPaddingY();
ug.draw(0, 0, new ULine(dimensionToUse.getWidth(), 0)); ug.draw(0, 0, new ULine(dimensionToUse.getWidth(), 0));
ug.draw(dimensionToUse.getWidth(), 0, new ULine(0, dimensionToUse.getHeight())); ug.draw(dimensionToUse.getWidth(), 0, new ULine(0, heightWithoutPadding));
ug.draw(0, textHeight, new ULine(0, dimensionToUse.getHeight()-textHeight)); ug.draw(0, textHeight, new ULine(0, heightWithoutPadding-textHeight));
ug.getParam().setStroke(new UStroke()); ug.getParam().setStroke(new UStroke());
getTextBlock().drawU(ug, getMarginX1(), getMarginY()); getTextBlock().drawU(ug, getMarginX1(), getMarginY());

View File

@ -28,7 +28,7 @@
* *
* Original Author: Arnaud Roques * Original Author: Arnaud Roques
* *
* Revision $Revision: 5879 $ * Revision $Revision: 5912 $
* *
*/ */
package net.sourceforge.plantuml.version; package net.sourceforge.plantuml.version;
@ -36,11 +36,11 @@ package net.sourceforge.plantuml.version;
public class Version { public class Version {
public static int version() { public static int version() {
return 5878; return 5911;
} }
public static long compileTime() { public static long compileTime() {
return 1294177111625L; return 1294598580421L;
} }
} }