2015-04-07 18:26:58 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2019-01-16 18:34:41 +00:00
|
|
|
* (C) Copyright 2009-2020, Arnaud Roques
|
2015-04-07 18:26:58 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2015-04-07 18:26:58 +00:00
|
|
|
*
|
2017-03-15 19:13:31 +00:00
|
|
|
* If you like this project or if you find it useful, you can support us at:
|
|
|
|
*
|
|
|
|
* http://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* http://plantuml.com/paypal
|
|
|
|
*
|
2015-04-07 18:26:58 +00:00
|
|
|
* 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 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.activitydiagram3;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
2019-06-26 19:24:49 +00:00
|
|
|
import net.sourceforge.plantuml.Url;
|
2015-04-07 18:26:58 +00:00
|
|
|
import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile;
|
2016-12-01 20:29:25 +00:00
|
|
|
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileDecorateWelding;
|
2015-04-07 18:26:58 +00:00
|
|
|
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory;
|
|
|
|
import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
|
2016-12-01 20:29:25 +00:00
|
|
|
import net.sourceforge.plantuml.activitydiagram3.ftile.WeldingPoint;
|
2015-04-07 18:26:58 +00:00
|
|
|
import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileWithNoteOpale;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Display;
|
|
|
|
import net.sourceforge.plantuml.graphic.HtmlColor;
|
2016-07-04 19:06:50 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.color.Colors;
|
2015-04-07 18:26:58 +00:00
|
|
|
import net.sourceforge.plantuml.sequencediagram.NotePosition;
|
2016-05-19 18:41:37 +00:00
|
|
|
import net.sourceforge.plantuml.sequencediagram.NoteType;
|
2015-04-07 18:26:58 +00:00
|
|
|
|
2016-07-04 19:06:50 +00:00
|
|
|
public class InstructionIf extends WithNote implements Instruction, InstructionCollection {
|
2015-04-07 18:26:58 +00:00
|
|
|
|
|
|
|
private final List<Branch> thens = new ArrayList<Branch>();
|
|
|
|
private Branch elseBranch;
|
2016-05-11 21:31:47 +00:00
|
|
|
private boolean endifCalled = false;
|
2015-04-07 18:26:58 +00:00
|
|
|
private final ISkinParam skinParam;
|
2019-06-26 19:24:49 +00:00
|
|
|
private final Url url;
|
2015-04-07 18:26:58 +00:00
|
|
|
|
|
|
|
private final Instruction parent;
|
|
|
|
|
|
|
|
private Branch current;
|
2015-09-28 20:42:17 +00:00
|
|
|
private final LinkRendering topInlinkRendering;
|
2016-05-11 21:31:47 +00:00
|
|
|
private LinkRendering afterEndwhile = LinkRendering.none();
|
2015-04-07 18:26:58 +00:00
|
|
|
|
|
|
|
private final Swimlane swimlane;
|
|
|
|
|
2019-03-29 22:14:07 +00:00
|
|
|
public boolean containsBreak() {
|
|
|
|
for (Branch branch : thens) {
|
|
|
|
if (branch.containsBreak()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (elseBranch != null) {
|
|
|
|
return elseBranch.containsBreak();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-07 18:26:58 +00:00
|
|
|
public InstructionIf(Swimlane swimlane, Instruction parent, Display labelTest, Display whenThen,
|
2019-06-26 19:24:49 +00:00
|
|
|
LinkRendering inlinkRendering, HtmlColor color, ISkinParam skinParam, Url url) {
|
|
|
|
this.url = url;
|
2015-04-07 18:26:58 +00:00
|
|
|
this.parent = parent;
|
|
|
|
this.skinParam = skinParam;
|
2015-09-28 20:42:17 +00:00
|
|
|
this.topInlinkRendering = inlinkRendering;
|
2016-05-11 21:31:47 +00:00
|
|
|
if (inlinkRendering == null) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
2015-04-07 18:26:58 +00:00
|
|
|
this.swimlane = swimlane;
|
2016-09-29 19:51:18 +00:00
|
|
|
this.thens.add(new Branch(swimlane, whenThen, labelTest, color, Display.NULL));
|
2015-04-07 18:26:58 +00:00
|
|
|
this.current = this.thens.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void add(Instruction ins) {
|
|
|
|
current.add(ins);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Ftile createFtile(FtileFactory factory) {
|
|
|
|
for (Branch branch : thens) {
|
|
|
|
branch.updateFtile(factory);
|
|
|
|
}
|
|
|
|
if (elseBranch == null) {
|
2016-09-29 19:51:18 +00:00
|
|
|
this.elseBranch = new Branch(swimlane, Display.NULL, Display.NULL, null, Display.NULL);
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
|
|
|
elseBranch.updateFtile(factory);
|
2019-06-26 19:24:49 +00:00
|
|
|
Ftile result = factory.createIf(swimlane, thens, elseBranch, afterEndwhile, topInlinkRendering, url);
|
2016-07-04 19:06:50 +00:00
|
|
|
if (getPositionedNotes().size() > 0) {
|
|
|
|
result = FtileWithNoteOpale.create(result, getPositionedNotes(), skinParam, false);
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
2016-12-01 20:29:25 +00:00
|
|
|
final List<WeldingPoint> weldingPoints = new ArrayList<WeldingPoint>();
|
|
|
|
for (Branch branch : thens) {
|
|
|
|
weldingPoints.addAll(branch.getWeldingPoints());
|
|
|
|
}
|
|
|
|
weldingPoints.addAll(elseBranch.getWeldingPoints());
|
|
|
|
if (weldingPoints.size() > 0) {
|
|
|
|
result = new FtileDecorateWelding(result, weldingPoints);
|
|
|
|
}
|
2015-04-07 18:26:58 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Instruction getParent() {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean swithToElse2(Display whenElse, LinkRendering nextLinkRenderer) {
|
|
|
|
if (elseBranch != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.current.setInlinkRendering(nextLinkRenderer);
|
2016-09-29 19:51:18 +00:00
|
|
|
this.elseBranch = new Branch(swimlane, whenElse, Display.NULL, null, Display.NULL);
|
2015-04-07 18:26:58 +00:00
|
|
|
this.current = elseBranch;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-29 19:51:18 +00:00
|
|
|
public boolean elseIf(Display inlabel, Display test, Display whenThen, LinkRendering nextLinkRenderer,
|
|
|
|
HtmlColor color) {
|
2015-04-07 18:26:58 +00:00
|
|
|
if (elseBranch != null) {
|
2016-01-30 12:20:07 +00:00
|
|
|
return false;
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
2018-09-23 12:15:14 +00:00
|
|
|
// this.current.setInlinkRendering(nextLinkRenderer);
|
|
|
|
this.current.setSpecial(nextLinkRenderer);
|
2016-09-29 19:51:18 +00:00
|
|
|
this.current = new Branch(swimlane, whenThen, test, color, inlabel);
|
2015-04-07 18:26:58 +00:00
|
|
|
this.thens.add(current);
|
2016-01-30 12:20:07 +00:00
|
|
|
return true;
|
2015-04-07 18:26:58 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void endif(LinkRendering nextLinkRenderer) {
|
2016-05-11 21:31:47 +00:00
|
|
|
endifCalled = true;
|
2015-04-07 18:26:58 +00:00
|
|
|
if (elseBranch == null) {
|
2016-09-29 19:51:18 +00:00
|
|
|
this.elseBranch = new Branch(swimlane, Display.NULL, Display.NULL, null, Display.NULL);
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
2018-09-23 12:15:14 +00:00
|
|
|
this.elseBranch.setSpecial(nextLinkRenderer);
|
2015-04-07 18:26:58 +00:00
|
|
|
this.current.setInlinkRendering(nextLinkRenderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
final public boolean kill() {
|
2016-05-11 21:31:47 +00:00
|
|
|
if (endifCalled) {
|
|
|
|
for (Branch branch : thens) {
|
2019-07-14 20:09:26 +00:00
|
|
|
if (branch.getLast() != null && branch.getLast().kill() == false) {
|
2016-05-11 21:31:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-23 12:15:14 +00:00
|
|
|
if (elseBranch != null && elseBranch.getLast() != null && elseBranch.getLast().kill() == false) {
|
2016-05-11 21:31:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-04-07 18:26:58 +00:00
|
|
|
return current.kill();
|
|
|
|
}
|
|
|
|
|
|
|
|
public LinkRendering getInLinkRendering() {
|
2015-09-28 20:42:17 +00:00
|
|
|
return topInlinkRendering;
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 19:06:50 +00:00
|
|
|
@Override
|
2017-05-10 19:51:15 +00:00
|
|
|
public boolean addNote(Display note, NotePosition position, NoteType type, Colors colors, Swimlane swimlaneNote) {
|
2016-07-04 19:06:50 +00:00
|
|
|
if (endifCalled || current.isEmpty()) {
|
2017-05-10 19:51:15 +00:00
|
|
|
return super.addNote(note, position, type, colors, swimlaneNote);
|
2015-04-07 18:26:58 +00:00
|
|
|
} else {
|
2017-05-10 19:51:15 +00:00
|
|
|
return current.addNote(note, position, type, colors, swimlaneNote);
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Set<Swimlane> getSwimlanes() {
|
|
|
|
final Set<Swimlane> result = new HashSet<Swimlane>();
|
|
|
|
if (swimlane != null) {
|
|
|
|
result.add(swimlane);
|
|
|
|
}
|
|
|
|
for (Branch branch : thens) {
|
|
|
|
result.addAll(branch.getSwimlanes());
|
|
|
|
}
|
2016-05-19 18:41:37 +00:00
|
|
|
if (elseBranch != null) {
|
|
|
|
result.addAll(elseBranch.getSwimlanes());
|
|
|
|
}
|
2015-04-07 18:26:58 +00:00
|
|
|
return Collections.unmodifiableSet(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Swimlane getSwimlaneIn() {
|
|
|
|
return swimlane;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Swimlane getSwimlaneOut() {
|
|
|
|
return swimlane;
|
|
|
|
}
|
|
|
|
|
2015-09-06 17:28:59 +00:00
|
|
|
public Instruction getLast() {
|
|
|
|
if (elseBranch == null) {
|
2015-09-28 20:42:17 +00:00
|
|
|
return thens.get(thens.size() - 1).getLast();
|
2015-09-06 17:28:59 +00:00
|
|
|
}
|
|
|
|
return elseBranch.getLast();
|
|
|
|
}
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
public void afterEndwhile(LinkRendering linkRenderer) {
|
|
|
|
this.afterEndwhile = linkRenderer;
|
|
|
|
}
|
|
|
|
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|