1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 08:30:49 +00:00
plantuml/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfLongHorizontal.java

706 lines
24 KiB
Java
Raw Normal View History

2015-04-07 18:26:58 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, 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.ftile.vcompact;
import java.util.ArrayList;
2017-02-15 21:34:36 +00:00
import java.util.Collection;
2015-04-07 18:26:58 +00:00
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
2021-05-09 21:14:40 +00:00
import java.util.Objects;
2015-04-07 18:26:58 +00:00
import java.util.Set;
import net.sourceforge.plantuml.activitydiagram3.Branch;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.activitydiagram3.LinkRendering;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection;
import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile;
import net.sourceforge.plantuml.activitydiagram3.ftile.Connection;
2016-02-07 21:13:01 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.ConnectionTranslatable;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile;
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple;
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory;
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileGeometry;
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileMinWidthCentered;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils;
2016-08-25 20:45:37 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.MergeStrategy;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.Snake;
import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside2;
2022-09-12 20:08:34 +00:00
import net.sourceforge.plantuml.awt.geom.XDimension2D;
import net.sourceforge.plantuml.awt.geom.XPoint2D;
2016-09-29 19:51:18 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2016-05-11 21:31:47 +00:00
import net.sourceforge.plantuml.graphic.Rainbow;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.svek.ConditionStyle;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2015-04-07 18:26:58 +00:00
2016-01-09 12:15:40 +00:00
class FtileIfLongHorizontal extends AbstractFtile {
2015-04-07 18:26:58 +00:00
private final double xSeparation = 20;
private final List<Ftile> tiles;
private final Ftile tile2;
private final List<Ftile> diamonds;
2021-05-14 08:42:57 +00:00
private final List<Ftile> couples = new ArrayList<>();
2015-04-07 18:26:58 +00:00
2016-05-11 21:31:47 +00:00
private final Rainbow arrowColor;
2015-04-07 18:26:58 +00:00
2016-09-29 19:51:18 +00:00
private FtileIfLongHorizontal(List<Ftile> diamonds, List<Double> inlabelSizes, List<Ftile> tiles, Ftile tile2,
Rainbow arrowColor) {
2016-06-19 14:16:41 +00:00
super(tiles.get(0).skinParam());
2022-11-30 17:41:17 +00:00
if (diamonds.size() != tiles.size())
2015-04-07 18:26:58 +00:00
throw new IllegalArgumentException();
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
for (int i = 0; i < diamonds.size(); i++) {
2016-09-29 19:51:18 +00:00
final Ftile diamond = diamonds.get(i);
final FtileAssemblySimple tmp = new FtileAssemblySimple(diamond, tiles.get(i));
couples.add(FtileUtils.addHorizontalMargin(tmp, inlabelSizes.get(i), 0));
2015-04-07 18:26:58 +00:00
}
this.tile2 = tile2;
2021-05-14 08:42:57 +00:00
this.diamonds = new ArrayList<>(diamonds);
this.tiles = new ArrayList<>(tiles);
2015-04-07 18:26:58 +00:00
this.arrowColor = arrowColor;
}
private static List<Ftile> alignDiamonds(List<Ftile> diamonds, StringBounder stringBounder) {
2022-12-16 16:20:14 +00:00
final double maxOutY = getMaxOutY(diamonds, stringBounder);
2022-11-30 17:41:17 +00:00
2021-05-14 08:42:57 +00:00
final List<Ftile> result = new ArrayList<>();
2015-04-07 18:26:58 +00:00
for (int i = 0; i < diamonds.size(); i++) {
Ftile diamond = diamonds.get(i);
final double missing = maxOutY - diamond.calculateDimension(stringBounder).getOutY();
assert missing >= 0;
diamond = FtileUtils.addVerticalMargin(diamond, missing / 2, 20);
result.add(diamond);
}
return result;
}
2022-12-16 16:20:14 +00:00
private static double getMaxOutY(List<Ftile> diamonds, StringBounder stringBounder) {
double maxOutY = 0;
for (Ftile diamond : diamonds)
maxOutY = Math.max(maxOutY, diamond.calculateDimension(stringBounder).getOutY());
return maxOutY;
}
2015-04-07 18:26:58 +00:00
public Set<Swimlane> getSwimlanes() {
2021-05-14 08:42:57 +00:00
final Set<Swimlane> result = new HashSet<>();
2022-11-30 17:41:17 +00:00
if (getSwimlaneIn() != null)
2015-04-07 18:26:58 +00:00
result.add(getSwimlaneIn());
2022-11-30 17:41:17 +00:00
for (Ftile tile : couples)
2015-04-07 18:26:58 +00:00
result.addAll(tile.getSwimlanes());
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
result.addAll(tile2.getSwimlanes());
return Collections.unmodifiableSet(result);
}
public Swimlane getSwimlaneIn() {
return couples.get(0).getSwimlaneIn();
}
public Swimlane getSwimlaneOut() {
return getSwimlaneIn();
}
2020-03-18 10:50:02 +00:00
static Ftile create(Swimlane swimlane, HColor borderColor, HColor backColor, Rainbow arrowColor,
2015-09-28 20:42:17 +00:00
FtileFactory ftileFactory, ConditionStyle conditionStyle, List<Branch> thens, Branch branch2,
2018-08-26 12:09:50 +00:00
FontConfiguration fcArrow, LinkRendering topInlinkRendering, LinkRendering afterEndwhile,
FontConfiguration fcTest) {
2021-05-09 21:14:40 +00:00
Objects.requireNonNull(afterEndwhile);
2021-05-14 08:42:57 +00:00
final List<Ftile> tiles = new ArrayList<>();
2015-04-07 18:26:58 +00:00
2022-11-30 17:41:17 +00:00
for (Branch branch : thens)
tiles.add(new FtileMinWidthCentered(branch.getFtile(), 30));
2015-04-07 18:26:58 +00:00
final Ftile tile2 = new FtileMinWidthCentered(branch2.getFtile(), 30);
2015-04-07 18:26:58 +00:00
2021-05-14 08:42:57 +00:00
List<Ftile> diamonds = new ArrayList<>();
List<Double> inlabelSizes = new ArrayList<>();
2015-04-07 18:26:58 +00:00
for (Branch branch : thens) {
2021-10-20 16:33:09 +00:00
final TextBlock tb1 = branch.getDisplayPositive().create(fcArrow, HorizontalAlignment.LEFT,
2016-09-29 19:51:18 +00:00
ftileFactory.skinParam());
2018-12-22 11:11:40 +00:00
final TextBlock tbTest = branch.getLabelTest().create(fcTest,
2019-03-29 22:14:07 +00:00
ftileFactory.skinParam().getDefaultTextAlignment(HorizontalAlignment.LEFT),
ftileFactory.skinParam());
2020-03-18 10:50:02 +00:00
final HColor diamondColor = branch.getColor() == null ? backColor : branch.getColor();
2016-09-29 19:51:18 +00:00
2022-11-30 17:41:17 +00:00
FtileDiamondInside2 diamond = new FtileDiamondInside2(tbTest, branch.skinParam(), diamondColor, borderColor,
swimlane);
2016-09-29 19:51:18 +00:00
TextBlock tbInlabel = null;
if (Display.isNull(branch.getInlabel())) {
inlabelSizes.add(0.0);
} else {
2018-08-26 12:09:50 +00:00
tbInlabel = branch.getInlabel().create(fcArrow, HorizontalAlignment.LEFT, ftileFactory.skinParam());
2016-09-29 19:51:18 +00:00
inlabelSizes.add(tbInlabel.calculateDimension(ftileFactory.getStringBounder()).getWidth());
diamond = diamond.withWest(tbInlabel);
}
2015-04-07 18:26:58 +00:00
diamond = diamond.withNorth(tb1);
diamonds.add(diamond);
}
2021-10-20 16:33:09 +00:00
final TextBlock tb2 = branch2.getDisplayPositive().create(fcArrow, HorizontalAlignment.LEFT,
2018-08-26 12:09:50 +00:00
ftileFactory.skinParam());
2015-04-07 18:26:58 +00:00
final int last = diamonds.size() - 1;
diamonds.set(last, ((FtileDiamondInside2) diamonds.get(last)).withEast(tb2));
diamonds = alignDiamonds(diamonds, ftileFactory.getStringBounder());
2020-04-19 16:04:39 +00:00
final FtileIfLongHorizontal result = new FtileIfLongHorizontal(diamonds, inlabelSizes, tiles, tile2,
arrowColor);
2021-05-14 08:42:57 +00:00
final List<Connection> conns = new ArrayList<>();
2015-04-07 18:26:58 +00:00
2019-03-29 22:14:07 +00:00
int nbOut = 0;
2015-04-07 18:26:58 +00:00
for (int i = 0; i < thens.size(); i++) {
final Ftile ftile = tiles.get(i);
final Ftile diam = diamonds.get(i);
2020-11-21 17:33:24 +00:00
final Rainbow rainbowIn = thens.get(i).getInColor(arrowColor);
2016-05-31 19:41:55 +00:00
final Branch branch = thens.get(i);
2019-03-29 22:14:07 +00:00
2022-11-30 17:41:17 +00:00
if (branch.getFtile().calculateDimension(ftileFactory.getStringBounder()).hasPointOut())
2019-03-29 22:14:07 +00:00
nbOut++;
2022-11-30 17:41:17 +00:00
2020-11-21 17:33:24 +00:00
final Rainbow rainbowOut = branch.getOut();
2018-09-23 12:15:14 +00:00
TextBlock out2 = null;
2022-11-30 17:41:17 +00:00
if (branch.getSpecial() != null)
2020-04-19 16:04:39 +00:00
out2 = branch.getSpecial().getDisplay().create(fcTest, HorizontalAlignment.LEFT,
ftileFactory.skinParam());
2022-11-30 17:41:17 +00:00
2020-11-21 17:33:24 +00:00
final Rainbow rainbow1 = rainbowIn.size() == 0 ? arrowColor : rainbowIn;
final Rainbow rainbow2 = rainbowOut.size() == 0 ? arrowColor : rainbowOut;
conns.add(result.new ConnectionVerticalIn(diam, ftile, rainbow1));
conns.add(result.new ConnectionVerticalOut(ftile, rainbow2, out2));
2015-04-07 18:26:58 +00:00
}
2016-05-11 21:31:47 +00:00
final Rainbow topInColor = topInlinkRendering.getRainbow(arrowColor);
2015-04-07 18:26:58 +00:00
for (int i = 0; i < diamonds.size() - 1; i++) {
final Ftile diam1 = diamonds.get(i);
final Ftile diam2 = diamonds.get(i + 1);
2020-11-21 17:33:24 +00:00
final Branch branch = thens.get(i + 1);
conns.add(result.new ConnectionHorizontal(diam1, diam2, branch.getInRainbow(arrowColor)));
2015-04-07 18:26:58 +00:00
}
2015-09-28 20:42:17 +00:00
conns.add(result.new ConnectionIn(topInColor));
2018-09-23 12:15:14 +00:00
TextBlock out2 = null;
2022-11-30 17:41:17 +00:00
if (branch2.getSpecial() != null)
2018-09-23 12:15:14 +00:00
out2 = branch2.getSpecial().getDisplay().create(fcTest, HorizontalAlignment.LEFT, ftileFactory.skinParam());
2020-11-21 17:33:24 +00:00
final Rainbow rainbowOut = branch2.getOut();
final Rainbow rainbowIn = branch2.getInColor(arrowColor);
final Rainbow rainbow1 = rainbowIn.size() == 0 ? arrowColor : rainbowIn;
final Rainbow rainbow2 = rainbowOut.size() == 0 ? arrowColor : rainbowOut;
conns.add(result.new ConnectionLastElseIn(rainbow1));
conns.add(result.new ConnectionLastElseOut(rainbow2, out2, nbOut));
2019-03-29 22:14:07 +00:00
final boolean horizontalOut = nbOut > 0;
if (horizontalOut) {
final Rainbow horizontalOutColor = afterEndwhile.getRainbow(arrowColor);
conns.add(result.new ConnectionHline(horizontalOutColor));
}
2015-04-07 18:26:58 +00:00
return FtileUtils.addConnection(result, conns);
}
class ConnectionHorizontal extends AbstractConnection {
2016-05-11 21:31:47 +00:00
private final Rainbow color;
2015-04-07 18:26:58 +00:00
2016-05-11 21:31:47 +00:00
public ConnectionHorizontal(Ftile diam1, Ftile diam2, Rainbow color) {
2015-04-07 18:26:58 +00:00
super(diam1, diam2);
this.color = color;
}
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
2022-09-12 20:08:34 +00:00
final XPoint2D p1 = getP1(stringBounder);
final XPoint2D p2 = getP2(stringBounder);
2015-04-07 18:26:58 +00:00
2022-11-30 17:41:17 +00:00
final Snake snake = Snake.create(skinParam(), color, skinParam().arrows().asToRight());
2015-04-07 18:26:58 +00:00
snake.addPoint(p1);
snake.addPoint(p2);
ug.draw(snake);
}
2022-09-12 20:08:34 +00:00
private XPoint2D getP1(StringBounder stringBounder) {
2015-04-07 18:26:58 +00:00
final FtileGeometry dimDiamond1 = getFtile1().calculateDimension(stringBounder);
2022-09-12 20:08:34 +00:00
final XPoint2D p = new XPoint2D(dimDiamond1.getLeft() * 2,
2020-04-19 16:04:39 +00:00
getYdiamontOutToLeft(dimDiamond1, stringBounder));
2015-04-07 18:26:58 +00:00
return getTranslateDiamond1(getFtile1(), stringBounder).getTranslated(p);
}
2022-09-12 20:08:34 +00:00
private XPoint2D getP2(StringBounder stringBounder) {
2015-04-07 18:26:58 +00:00
final FtileGeometry dimDiamond1 = getFtile2().calculateDimension(stringBounder);
2022-09-12 20:08:34 +00:00
final XPoint2D p = new XPoint2D(0, getYdiamontOutToLeft(dimDiamond1, stringBounder));
2015-04-07 18:26:58 +00:00
return getTranslateDiamond1(getFtile2(), stringBounder).getTranslated(p);
}
}
static private double getYdiamontOutToLeft(FtileGeometry dimDiamond1, StringBounder stringBounder) {
return (dimDiamond1.getInY() + dimDiamond1.getOutY()) / 2;
}
class ConnectionIn extends AbstractConnection {
2016-05-11 21:31:47 +00:00
private final Rainbow arrowColor;
2015-04-07 18:26:58 +00:00
2016-05-11 21:31:47 +00:00
public ConnectionIn(Rainbow arrowColor) {
2015-04-07 18:26:58 +00:00
super(null, diamonds.get(0));
this.arrowColor = arrowColor;
}
public void drawU(UGraphic ug) {
final UTranslate tr = getTranslateDiamond1(getFtile2(), ug.getStringBounder());
2022-09-12 20:08:34 +00:00
final XPoint2D p2 = tr.getTranslated(getFtile2().calculateDimension(ug.getStringBounder()).getPointIn());
2022-11-30 17:41:17 +00:00
final Snake snake = Snake.create(skinParam(), arrowColor, skinParam().arrows().asToDown());
2022-09-12 20:08:34 +00:00
final XPoint2D p1 = calculateDimensionInternal(ug.getStringBounder()).getPointIn();
2015-04-07 18:26:58 +00:00
snake.addPoint(p1);
snake.addPoint(p2.getX(), p1.getY());
snake.addPoint(p2);
ug.draw(snake);
}
}
class ConnectionLastElseIn extends AbstractConnection {
2016-05-11 21:31:47 +00:00
private final Rainbow arrowColor;
2015-04-07 18:26:58 +00:00
2016-05-11 21:31:47 +00:00
public ConnectionLastElseIn(Rainbow arrowColor) {
2015-04-07 18:26:58 +00:00
super(diamonds.get(diamonds.size() - 1), tile2);
this.arrowColor = arrowColor;
}
public void drawU(UGraphic ug) {
2022-09-12 20:08:34 +00:00
final XPoint2D p1 = getP1(ug.getStringBounder());
2015-04-07 18:26:58 +00:00
final UTranslate tr2 = getTranslate2(ug.getStringBounder());
2022-09-12 20:08:34 +00:00
final XPoint2D p2 = tr2.getTranslated(getFtile2().calculateDimension(ug.getStringBounder()).getPointIn());
2022-11-30 17:41:17 +00:00
final Snake snake = Snake.create(skinParam(), arrowColor, skinParam().arrows().asToDown());
2015-04-07 18:26:58 +00:00
snake.addPoint(p1);
snake.addPoint(p2.getX(), p1.getY());
snake.addPoint(p2);
ug.draw(snake);
}
2022-09-12 20:08:34 +00:00
private XPoint2D getP1(StringBounder stringBounder) {
2015-04-07 18:26:58 +00:00
final FtileGeometry dimDiamond1 = getFtile1().calculateDimension(stringBounder);
2022-09-12 20:08:34 +00:00
final XPoint2D p = new XPoint2D(dimDiamond1.getLeft() * 2,
2020-04-19 16:04:39 +00:00
getYdiamontOutToLeft(dimDiamond1, stringBounder));
2015-04-07 18:26:58 +00:00
return getTranslateDiamond1(getFtile1(), stringBounder).getTranslated(p);
}
}
class ConnectionLastElseOut extends AbstractConnection {
2016-05-11 21:31:47 +00:00
private final Rainbow arrowColor;
2018-09-23 12:15:14 +00:00
private final TextBlock out2;
2019-03-29 22:14:07 +00:00
private final int nbOut;
2015-04-07 18:26:58 +00:00
2019-03-29 22:14:07 +00:00
public ConnectionLastElseOut(Rainbow arrowColor, TextBlock out2, int nbOut) {
2015-04-07 18:26:58 +00:00
super(tile2, null);
this.arrowColor = arrowColor;
2018-09-23 12:15:14 +00:00
this.out2 = out2;
2019-03-29 22:14:07 +00:00
this.nbOut = nbOut;
2015-04-07 18:26:58 +00:00
}
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final UTranslate tr1 = getTranslate2(stringBounder);
final FtileGeometry dim = getFtile1().calculateDimension(stringBounder);
2022-11-30 17:41:17 +00:00
if (dim.hasPointOut() == false)
2015-04-07 18:26:58 +00:00
return;
2022-11-30 17:41:17 +00:00
2022-09-12 20:08:34 +00:00
final XPoint2D p1 = tr1.getTranslated(dim.getPointOut());
2019-03-29 22:14:07 +00:00
final FtileGeometry full = calculateDimensionInternal(stringBounder);
final double totalHeight = full.getHeight();
2022-09-12 20:08:34 +00:00
final XPoint2D p2 = new XPoint2D(p1.getX(), totalHeight);
2015-04-07 18:26:58 +00:00
2022-11-30 17:41:17 +00:00
final Snake snake = Snake.create(skinParam(), arrowColor, skinParam().arrows().asToDown()).withLabel(out2,
arrowHorizontalAlignment());
2015-04-07 18:26:58 +00:00
snake.addPoint(p1);
snake.addPoint(p2);
2022-11-30 17:41:17 +00:00
if (nbOut == 0)
2022-09-12 20:08:34 +00:00
snake.addPoint(new XPoint2D(full.getLeft(), totalHeight));
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
ug.draw(snake);
}
}
2016-02-07 21:13:01 +00:00
class ConnectionVerticalIn extends AbstractConnection implements ConnectionTranslatable {
2015-04-07 18:26:58 +00:00
2016-05-11 21:31:47 +00:00
private final Rainbow color;
2015-04-07 18:26:58 +00:00
2016-05-11 21:31:47 +00:00
public ConnectionVerticalIn(Ftile diamond, Ftile tile, Rainbow color) {
2015-04-07 18:26:58 +00:00
super(diamond, tile);
this.color = color;
}
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
2022-09-12 20:08:34 +00:00
final XPoint2D p1 = getP1(stringBounder);
final XPoint2D p2 = getP2(stringBounder);
2015-04-07 18:26:58 +00:00
2022-11-30 17:41:17 +00:00
final Snake snake = Snake.create(skinParam(), color, skinParam().arrows().asToDown());
2015-04-07 18:26:58 +00:00
snake.addPoint(p1);
snake.addPoint(p2);
ug.draw(snake);
}
2022-09-12 20:08:34 +00:00
private XPoint2D getP1(StringBounder stringBounder) {
final XPoint2D p = getFtile1().calculateDimension(stringBounder).getPointOut();
2015-04-07 18:26:58 +00:00
return getTranslateDiamond1(getFtile1(), stringBounder).getTranslated(p);
}
2022-09-12 20:08:34 +00:00
private XPoint2D getP2(StringBounder stringBounder) {
final XPoint2D p = getFtile2().calculateDimension(stringBounder).getPointIn();
2015-04-07 18:26:58 +00:00
return getTranslate1(getFtile2(), stringBounder).getTranslated(p);
}
2021-10-03 21:01:18 +00:00
@Override
2016-02-07 21:13:01 +00:00
public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) {
2022-09-12 20:08:34 +00:00
final XPoint2D p1 = getP1(ug.getStringBounder());
final XPoint2D p2 = getP2(ug.getStringBounder());
2016-02-07 21:13:01 +00:00
2022-11-30 17:41:17 +00:00
final Snake snake = Snake.create(skinParam(), color, skinParam().arrows().asToDown());
2016-02-07 21:13:01 +00:00
2022-09-12 20:08:34 +00:00
final XPoint2D mp1a = translate1.getTranslated(p1);
final XPoint2D mp2b = translate2.getTranslated(p2);
2016-02-07 21:13:01 +00:00
final double middle = mp1a.getY() + 4;
snake.addPoint(mp1a);
snake.addPoint(mp1a.getX(), middle);
snake.addPoint(mp2b.getX(), middle);
snake.addPoint(mp2b);
ug.draw(snake);
}
2015-04-07 18:26:58 +00:00
}
class ConnectionVerticalOut extends AbstractConnection {
2016-05-11 21:31:47 +00:00
private final Rainbow color;
2018-09-23 12:15:14 +00:00
private final TextBlock out2;
2015-04-07 18:26:58 +00:00
2018-09-23 12:15:14 +00:00
public ConnectionVerticalOut(Ftile tile, Rainbow color, TextBlock out2) {
2015-04-07 18:26:58 +00:00
super(tile, null);
this.color = color;
2018-09-23 12:15:14 +00:00
this.out2 = out2;
2015-04-07 18:26:58 +00:00
}
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final double totalHeight = calculateDimensionInternal(stringBounder).getHeight();
2022-09-12 20:08:34 +00:00
final XPoint2D p1 = getP1(stringBounder);
2022-11-30 17:41:17 +00:00
if (p1 == null)
2015-04-07 18:26:58 +00:00
return;
2022-11-30 17:41:17 +00:00
2022-09-12 20:08:34 +00:00
final XPoint2D p2 = new XPoint2D(p1.getX(), totalHeight);
2015-04-07 18:26:58 +00:00
2022-11-30 17:41:17 +00:00
final Snake snake = Snake.create(skinParam(), color, skinParam().arrows().asToDown()).withLabel(out2,
arrowHorizontalAlignment());
2015-04-07 18:26:58 +00:00
snake.addPoint(p1);
snake.addPoint(p2);
ug.draw(snake);
}
2022-09-12 20:08:34 +00:00
private XPoint2D getP1(StringBounder stringBounder) {
2015-04-07 18:26:58 +00:00
final FtileGeometry geo = getFtile1().calculateDimension(stringBounder);
2022-11-30 17:41:17 +00:00
if (geo.hasPointOut() == false)
2015-04-07 18:26:58 +00:00
return null;
2022-11-30 17:41:17 +00:00
2022-09-12 20:08:34 +00:00
final XPoint2D p = geo.getPointOut();
2015-04-07 18:26:58 +00:00
return getTranslate1(getFtile1(), stringBounder).getTranslated(p);
}
}
class ConnectionHline extends AbstractConnection {
2016-05-11 21:31:47 +00:00
private final Rainbow arrowColor;
2015-04-07 18:26:58 +00:00
2016-05-11 21:31:47 +00:00
public ConnectionHline(Rainbow arrowColor) {
2015-04-07 18:26:58 +00:00
super(null, null);
this.arrowColor = arrowColor;
}
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
2022-09-12 20:08:34 +00:00
final XDimension2D totalDim = calculateDimensionInternal(stringBounder);
2015-04-07 18:26:58 +00:00
2021-05-14 08:42:57 +00:00
final List<Ftile> allTiles = new ArrayList<>(couples);
2020-04-19 16:04:39 +00:00
allTiles.add(tile2);
final double[] minmax;
2016-02-07 21:13:01 +00:00
if (ug instanceof UGraphicInterceptorOneSwimlane) {
2020-04-19 16:04:39 +00:00
final UGraphicInterceptorOneSwimlane interceptor = (UGraphicInterceptorOneSwimlane) ug;
final List<Swimlane> allSwimlanes = interceptor.getOrderedListOfAllSwimlanes();
minmax = getMinmax(stringBounder, totalDim.getWidth(), allTiles, interceptor.getSwimlane(),
allSwimlanes);
2016-02-07 21:13:01 +00:00
} else {
2020-04-19 16:04:39 +00:00
minmax = getMinmaxSimple(stringBounder, totalDim.getWidth(), allTiles);
2016-02-07 21:13:01 +00:00
}
2020-04-19 16:04:39 +00:00
final double minX = minmax[0];
final double maxX = minmax[1];
2022-11-30 17:41:17 +00:00
if (Double.isNaN(minX) || Double.isNaN(maxX))
2020-04-19 16:04:39 +00:00
return;
2022-02-12 17:27:51 +00:00
final Snake s = Snake.create(skinParam(), arrowColor).withMerge(MergeStrategy.NONE);
2020-04-19 16:04:39 +00:00
s.addPoint(minX, totalDim.getHeight());
s.addPoint(maxX, totalDim.getHeight());
ug.draw(s);
}
private Double getLeftOut(final StringBounder stringBounder) {
final FtileGeometry dim = calculateDimension(stringBounder);
2022-11-30 17:41:17 +00:00
if (dim.hasPointOut())
return dim.getLeft();
2022-11-30 17:41:17 +00:00
return null;
}
2020-04-19 16:04:39 +00:00
private double[] getMinmax(StringBounder stringBounder, double width, List<Ftile> allTiles, Swimlane intoSw,
List<Swimlane> allSwimlanes) {
final int current = allSwimlanes.indexOf(intoSw);
final Double leftOut = getLeftOut(stringBounder);
if (leftOut == null)
return new double[] { Double.NaN, Double.NaN };
2022-12-16 16:20:14 +00:00
if (current == -1)
2020-04-19 16:04:39 +00:00
throw new IllegalStateException();
2022-12-16 16:20:14 +00:00
2020-04-19 16:04:39 +00:00
final int first = getFirstSwimlane(stringBounder, allTiles, allSwimlanes);
final int last = getLastSwimlane(stringBounder, allTiles, allSwimlanes);
if (current < first || current > last)
return new double[] { Double.NaN, Double.NaN };
double minX = current != first ? 0 : width;
double maxX = current != last ? width : 0;
minX = Math.min(minX, leftOut);
maxX = Math.max(maxX, leftOut);
2020-04-19 16:04:39 +00:00
for (Ftile tmp : allTiles) {
2022-11-30 17:41:17 +00:00
if (tmp.calculateDimension(stringBounder).hasPointOut() == false)
2015-04-07 18:26:58 +00:00
continue;
2022-11-30 17:41:17 +00:00
if (ftileDoesOutcomeInThatSwimlane(tmp, intoSw) == false)
2016-02-07 21:13:01 +00:00
continue;
2022-11-30 17:41:17 +00:00
2020-04-19 16:04:39 +00:00
final UTranslate ut = getTranslateFor(tmp, stringBounder);
final double out = tmp.calculateDimension(stringBounder).translate(ut).getLeft();
minX = Math.min(minX, out);
maxX = Math.max(maxX, out);
}
return new double[] { minX, maxX };
}
private double[] getMinmaxSimple(StringBounder stringBounder, double width, List<Ftile> allTiles) {
final Double leftOut = getLeftOut(stringBounder);
if (leftOut == null)
return new double[] { Double.NaN, Double.NaN };
2020-04-19 16:04:39 +00:00
double minX = width / 2;
double maxX = width / 2;
minX = Math.min(minX, leftOut);
maxX = Math.max(maxX, leftOut);
2020-04-19 16:04:39 +00:00
for (Ftile tmp : allTiles) {
2022-11-30 17:41:17 +00:00
if (tmp.calculateDimension(stringBounder).hasPointOut() == false)
2016-02-07 21:13:01 +00:00
continue;
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
final UTranslate ut = getTranslateFor(tmp, stringBounder);
final double out = tmp.calculateDimension(stringBounder).translate(ut).getLeft();
minX = Math.min(minX, out);
maxX = Math.max(maxX, out);
}
2020-04-19 16:04:39 +00:00
return new double[] { minX, maxX };
}
private int getFirstSwimlane(StringBounder stringBounder, List<Ftile> allTiles, List<Swimlane> allSwimlanes) {
2022-11-30 17:41:17 +00:00
for (int i = 0; i < allSwimlanes.size(); i++)
if (atLeastOne(stringBounder, allSwimlanes.get(i), allTiles))
2020-04-19 16:04:39 +00:00
return i;
2022-11-30 17:41:17 +00:00
2020-04-19 16:04:39 +00:00
throw new IllegalStateException();
}
2015-04-07 18:26:58 +00:00
2020-04-19 16:04:39 +00:00
private int getLastSwimlane(StringBounder stringBounder, List<Ftile> allTiles, List<Swimlane> allSwimlanes) {
2022-11-30 17:41:17 +00:00
for (int i = allSwimlanes.size() - 1; i >= 0; i--)
if (atLeastOne(stringBounder, allSwimlanes.get(i), allTiles))
2020-04-19 16:04:39 +00:00
return i;
2022-11-30 17:41:17 +00:00
2020-04-19 16:04:39 +00:00
throw new IllegalStateException();
}
private boolean atLeastOne(StringBounder stringBounder, Swimlane intoSw, List<Ftile> allTiles) {
for (Ftile tmp : allTiles)
if (tmp.calculateDimension(stringBounder).hasPointOut() && ftileDoesOutcomeInThatSwimlane(tmp, intoSw))
return true;
return false;
}
private boolean ftileDoesOutcomeInThatSwimlane(Ftile ftile, Swimlane swimlane) {
return ftile.getSwimlaneOut() == swimlane && ftile.getSwimlanes().contains(swimlane);
2015-04-07 18:26:58 +00:00
}
2020-04-19 16:04:39 +00:00
2015-04-07 18:26:58 +00:00
}
2017-02-15 21:34:36 +00:00
@Override
public Collection<Ftile> getMyChildren() {
2021-05-14 08:42:57 +00:00
final List<Ftile> result = new ArrayList<>(tiles);
2017-02-15 21:34:36 +00:00
result.add(tile2);
return Collections.unmodifiableList(result);
}
2015-04-07 18:26:58 +00:00
@Override
public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) {
2022-11-30 17:41:17 +00:00
if (child == tile2)
2015-04-07 18:26:58 +00:00
return getTranslate2(stringBounder);
2022-11-30 17:41:17 +00:00
if (couples.contains(child))
2015-04-07 18:26:58 +00:00
return getTranslateCouple1(child, stringBounder);
2022-11-30 17:41:17 +00:00
if (tiles.contains(child))
2017-02-15 21:34:36 +00:00
return getTranslate1(child, stringBounder);
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
throw new UnsupportedOperationException();
}
private UTranslate getTranslate2(StringBounder stringBounder) {
2022-09-12 20:08:34 +00:00
final XDimension2D dimTotal = calculateDimensionInternal(stringBounder);
final XDimension2D dim2 = tile2.calculateDimension(stringBounder);
2015-04-07 18:26:58 +00:00
final double x2 = dimTotal.getWidth() - dim2.getWidth();
final double h = 0; // getAllDiamondsHeight(stringBounder);
final double y2 = (dimTotal.getHeight() - h * 2 - dim2.getHeight()) / 2 + h;
return new UTranslate(x2, y2);
}
private UTranslate getTranslateDiamond1(Ftile diamond, StringBounder stringBounder) {
final int idx = diamonds.indexOf(diamond);
2022-11-30 17:41:17 +00:00
if (idx == -1)
2015-04-07 18:26:58 +00:00
throw new IllegalArgumentException();
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
final UTranslate trCouple = getTranslateCouple1(couples.get(idx), stringBounder);
final UTranslate in = couples.get(idx).getTranslateFor(diamond, stringBounder);
return trCouple.compose(in);
}
2019-04-21 20:40:01 +00:00
private UTranslate getTranslate1(Ftile tile, StringBounder stringBounder) {
2015-04-07 18:26:58 +00:00
final int idx = tiles.indexOf(tile);
2022-11-30 17:41:17 +00:00
if (idx == -1)
2015-04-07 18:26:58 +00:00
throw new IllegalArgumentException();
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
final UTranslate trCouple = getTranslateCouple1(couples.get(idx), stringBounder);
final UTranslate in = couples.get(idx).getTranslateFor(tile, stringBounder);
return trCouple.compose(in);
}
private UTranslate getTranslateCouple1(Ftile candidat, StringBounder stringBounder) {
double x1 = 0;
for (Ftile couple : couples) {
final FtileGeometry dim1 = couple.calculateDimension(stringBounder);
2022-11-30 17:41:17 +00:00
if (couple == candidat)
2015-04-07 18:26:58 +00:00
return new UTranslate(x1, 25);
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
x1 += dim1.getWidth() + xSeparation;
}
throw new IllegalArgumentException();
}
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
2022-11-30 17:41:17 +00:00
for (Ftile couple : couples)
2015-04-07 18:26:58 +00:00
ug.apply(getTranslateCouple1(couple, stringBounder)).draw(couple);
ug.apply(getTranslate2(stringBounder)).draw(tile2);
}
private FtileGeometry calculateDimensionInternal(StringBounder stringBounder) {
2022-12-16 16:20:14 +00:00
final double maxOutY = getMaxOutY(diamonds, stringBounder);
2022-09-12 20:08:34 +00:00
XDimension2D result = new XDimension2D(0, 0);
2022-12-16 16:20:14 +00:00
for (Ftile couple : couples)
2022-11-04 17:36:03 +00:00
result = result.mergeLR(couple.calculateDimension(stringBounder));
2022-12-16 16:20:14 +00:00
2022-09-12 20:08:34 +00:00
XDimension2D dimTile2 = tile2.calculateDimension(stringBounder);
2022-11-04 17:36:03 +00:00
dimTile2 = dimTile2.delta(0, getDiamondsHeight(stringBounder) / 2);
result = result.mergeLR(dimTile2);
2022-12-16 16:20:14 +00:00
result = result.delta(xSeparation * couples.size(), Math.max(100, maxOutY));
2015-04-07 18:26:58 +00:00
return new FtileGeometry(result, result.getWidth() / 2, 0);
}
2019-05-24 19:59:31 +00:00
private double getDiamondsHeight(StringBounder stringBounder) {
double height = 0;
2022-11-30 17:41:17 +00:00
for (Ftile diamond : diamonds)
2019-05-24 19:59:31 +00:00
height = Math.max(height, diamond.calculateDimension(stringBounder).getHeight());
2022-11-30 17:41:17 +00:00
2019-05-24 19:59:31 +00:00
return height;
}
2017-11-20 16:10:36 +00:00
@Override
protected FtileGeometry calculateDimensionFtile(StringBounder stringBounder) {
2022-09-12 20:08:34 +00:00
final XDimension2D dimTotal = calculateDimensionInternal(stringBounder);
2015-04-07 18:26:58 +00:00
2021-05-14 08:42:57 +00:00
final List<Ftile> all = new ArrayList<>(tiles);
2015-04-07 18:26:58 +00:00
all.add(tile2);
2022-11-30 17:41:17 +00:00
for (Ftile tmp : all)
if (tmp.calculateDimension(stringBounder).hasPointOut())
2015-04-07 18:26:58 +00:00
return new FtileGeometry(dimTotal, dimTotal.getWidth() / 2, 0, dimTotal.getHeight());
2022-11-30 17:41:17 +00:00
2015-04-07 18:26:58 +00:00
return new FtileGeometry(dimTotal, dimTotal.getWidth() / 2, 0);
}
}