1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 00:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/activitydiagram3/Branch.java

271 lines
7.9 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2013-12-10 19:36:50 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2013-12-10 19:36:50 +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:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2017-03-15 19:13:31 +00:00
*
2013-12-10 19:36:50 +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.Collection;
2021-05-09 21:14:40 +00:00
import java.util.Objects;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile;
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;
2021-10-29 16:48:50 +00:00
import net.sourceforge.plantuml.activitydiagram3.gtile.Gtile;
2021-07-25 10:41:36 +00:00
import net.sourceforge.plantuml.command.CommandExecutionResult;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.decoration.Rainbow;
import net.sourceforge.plantuml.klimt.LineBreakStrategy;
import net.sourceforge.plantuml.klimt.color.Colors;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.color.HColor;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.creole.CreoleMode;
import net.sourceforge.plantuml.klimt.creole.Display;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.klimt.shape.TextBlockUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.sequencediagram.NotePosition;
2016-05-19 18:41:37 +00:00
import net.sourceforge.plantuml.sequencediagram.NoteType;
2023-12-11 17:34:23 +00:00
import net.sourceforge.plantuml.stereo.Stereotype;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.style.ISkinParam;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.style.StyleSignatureBasic;
2013-12-10 19:36:50 +00:00
public class Branch {
private final InstructionList list;
private final Display labelTest;
2020-11-21 17:33:24 +00:00
private final LinkRendering labelPositive;
2016-05-11 21:31:47 +00:00
private LinkRendering inlinkRendering = LinkRendering.none();
2020-11-21 17:33:24 +00:00
private final LinkRendering inlabel;
private LinkRendering special;
private final HColor color;
2013-12-10 19:36:50 +00:00
private Ftile ftile;
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2021-10-29 16:48:50 +00:00
private Gtile gtile;
2023-02-02 17:59:43 +00:00
// ::done
2013-12-10 19:36:50 +00:00
2022-03-01 18:11:51 +00:00
public StyleSignatureBasic getDefaultStyleDefinitionArrow() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.activityDiagram, SName.arrow);
2019-08-26 17:07:21 +00:00
}
2022-03-01 18:11:51 +00:00
public StyleSignatureBasic getDefaultStyleDefinitionDiamond() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.activityDiagram, SName.activity, SName.diamond);
2019-08-26 17:07:21 +00:00
}
2019-03-29 22:14:07 +00:00
public boolean containsBreak() {
return list.containsBreak();
}
2020-11-21 17:33:24 +00:00
public Branch(StyleBuilder styleBuilder, Swimlane swimlane, LinkRendering labelPositive, Display labelTest,
2023-12-11 17:34:23 +00:00
HColor color, LinkRendering inlabel, Stereotype stereotype) {
2021-05-09 21:14:40 +00:00
this.inlabel = Objects.requireNonNull(inlabel);
this.labelTest = Objects.requireNonNull(labelTest);
this.labelPositive = Objects.requireNonNull(labelPositive);
2022-04-10 19:24:55 +00:00
2023-12-11 17:34:23 +00:00
final Style style = getDefaultStyleDefinitionDiamond().withTOBECHANGED(stereotype).getMergedStyle(styleBuilder);
2023-02-22 18:43:48 +00:00
this.color = color == null
? style.value(PName.BackGroundColor).asColor(styleBuilder.getSkinParam().getIHtmlColorSet())
: color;
2019-08-26 17:07:21 +00:00
2013-12-10 19:36:50 +00:00
this.list = new InstructionList(swimlane);
}
2018-09-23 12:15:14 +00:00
2016-12-01 20:29:25 +00:00
public Collection<WeldingPoint> getWeldingPoints() {
return ftile.getWeldingPoints();
}
2021-07-25 10:41:36 +00:00
public CommandExecutionResult add(Instruction ins) {
2013-12-10 19:36:50 +00:00
list.add(ins);
2021-07-25 10:41:36 +00:00
return CommandExecutionResult.ok();
2013-12-10 19:36:50 +00:00
}
public boolean kill() {
return list.kill();
}
2017-05-10 19:51:15 +00:00
public boolean addNote(Display note, NotePosition position, NoteType type, Colors colors, Swimlane swimlaneNote) {
return list.addNote(note, position, type, colors, swimlaneNote);
2013-12-10 19:36:50 +00:00
}
public final void setInlinkRendering(LinkRendering inlinkRendering) {
2021-05-09 21:14:40 +00:00
this.inlinkRendering = Objects.requireNonNull(inlinkRendering);
2013-12-10 19:36:50 +00:00
}
public void updateFtile(FtileFactory factory) {
this.ftile = factory.decorateOut(list.createFtile(factory), inlinkRendering);
}
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2021-10-29 16:48:50 +00:00
public void updateGtile(ISkinParam skinParam, StringBounder stringBounder) {
this.gtile = list.createGtile(skinParam, stringBounder);
}
2023-02-02 17:59:43 +00:00
// ::done
2021-10-29 16:48:50 +00:00
2013-12-10 19:36:50 +00:00
public Collection<? extends Swimlane> getSwimlanes() {
return list.getSwimlanes();
}
public final Display getLabelTest() {
return labelTest;
}
2020-11-21 17:33:24 +00:00
public final Rainbow getOut() {
if (special != null)
2020-11-21 17:33:24 +00:00
return special.getRainbow();
// if (labelPositive.getRainbow().size() > 0)
2020-11-21 17:33:24 +00:00
// return labelPositive.getRainbow();
if (inlinkRendering == null)
2020-11-21 17:33:24 +00:00
return null;
2020-11-21 17:33:24 +00:00
return inlinkRendering.getRainbow();
}
public Rainbow getInColor(Rainbow arrowColor) {
if (isEmpty())
2020-11-21 17:33:24 +00:00
return getFtile().getOutLinkRendering().getRainbow(arrowColor);
if (labelPositive.getRainbow().size() > 0)
2020-11-21 17:33:24 +00:00
return labelPositive.getRainbow();
2020-11-21 17:33:24 +00:00
final LinkRendering linkIn = getFtile().getInLinkRendering();
final Rainbow color = linkIn.getRainbow(arrowColor);
if (color.size() == 0)
2020-11-21 17:33:24 +00:00
return arrowColor;
2020-11-21 17:33:24 +00:00
return color;
2013-12-10 19:36:50 +00:00
}
2016-09-29 19:51:18 +00:00
public Display getInlabel() {
2020-11-21 17:33:24 +00:00
return inlabel.getDisplay();
}
public Rainbow getInRainbow(Rainbow defaultColor) {
return inlabel.getRainbow(defaultColor);
}
public Rainbow getLabelPositiveRainbow(Rainbow defaultColor) {
return labelPositive.getRainbow(defaultColor);
2016-09-29 19:51:18 +00:00
}
2013-12-10 19:36:50 +00:00
public final Ftile getFtile() {
return ftile;
}
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2021-10-29 16:48:50 +00:00
public Gtile getGtile() {
return gtile;
}
2023-02-02 17:59:43 +00:00
// ::done
2023-02-22 18:43:48 +00:00
2016-06-19 14:16:41 +00:00
public ISkinParam skinParam() {
2023-02-28 21:22:51 +00:00
// ::comment when __CORE__
2021-11-07 18:21:14 +00:00
if (gtile != null)
return gtile.skinParam();
2023-02-02 17:59:43 +00:00
// ::done
2016-06-19 14:16:41 +00:00
return ftile.skinParam();
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
2020-03-18 10:50:02 +00:00
public final HColor getColor() {
2015-04-07 18:18:37 +00:00
return color;
}
public boolean isEmpty() {
return list.isEmpty();
}
2015-09-06 17:28:59 +00:00
public Instruction getLast() {
return list.getLast();
}
2018-03-09 21:37:34 +00:00
public boolean isOnlySingleStopOrSpot() {
return list.isOnlySingleStopOrSpot();
2016-08-25 20:45:37 +00:00
}
2018-09-23 12:15:14 +00:00
public void setSpecial(LinkRendering link) {
this.special = link;
}
public final LinkRendering getSpecial() {
return special;
}
2021-10-27 16:43:04 +00:00
2021-10-20 16:33:09 +00:00
public final Display getDisplayPositive() {
2021-11-07 18:21:14 +00:00
if (ftile != null) {
final LinkRendering in = ftile.getInLinkRendering();
if (in != null && Display.isNull(in.getDisplay()) == false)
2021-11-07 18:21:14 +00:00
return in.getDisplay();
2021-10-20 16:33:09 +00:00
}
return labelPositive.getDisplay();
}
2021-10-27 16:43:04 +00:00
public Display getSpecialDisplay() {
if (special != null && Display.isNull(special.getDisplay()) == false)
2021-10-27 16:43:04 +00:00
return special.getDisplay();
2021-10-27 16:43:04 +00:00
return null;
}
private TextBlock getTextBlock(Display display) {
if (display == null)
return TextBlockUtils.EMPTY_TEXT_BLOCK;
2022-04-10 19:24:55 +00:00
final Style style = getDefaultStyleDefinitionArrow().getMergedStyle(skinParam().getCurrentStyleBuilder());
final LineBreakStrategy lineBreak = style.wrapWidth();
2022-09-18 17:08:06 +00:00
final FontConfiguration fcArrow = style.getFontConfiguration(skinParam().getIHtmlColorSet());
2021-10-20 16:33:09 +00:00
2021-10-27 16:43:04 +00:00
return display.create0(fcArrow, HorizontalAlignment.LEFT, skinParam(), lineBreak, CreoleMode.SIMPLE_LINE, null,
null);
2021-10-20 16:33:09 +00:00
}
2021-10-27 16:43:04 +00:00
public final TextBlock getTextBlockPositive() {
return getTextBlock(getDisplayPositive());
}
2021-10-20 16:33:09 +00:00
2021-10-27 16:43:04 +00:00
public final TextBlock getTextBlockSpecial() {
return getTextBlock(getSpecialDisplay());
}
2018-09-23 12:15:14 +00:00
2013-12-10 19:36:50 +00:00
}