1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-17 07:32:24 +00:00
plantuml/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileForkInner.java

129 lines
3.8 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.ftile.vcompact;
import java.util.ArrayList;
2020-11-21 17:33:24 +00:00
import java.util.Collection;
2013-12-10 19:36:50 +00:00
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile;
import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileGeometry;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.UTranslate;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.StringBounder;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
2013-12-10 19:36:50 +00:00
class FtileForkInner extends AbstractFtile {
2021-05-14 08:42:57 +00:00
private final List<Ftile> forks = new ArrayList<>();
2013-12-10 19:36:50 +00:00
public FtileForkInner(List<Ftile> forks) {
2016-06-19 14:16:41 +00:00
super(forks.get(0).skinParam());
2013-12-10 19:36:50 +00:00
for (Ftile ftile : forks) {
this.forks.add(ftile);
}
}
2023-02-22 18:43:48 +00:00
2020-11-21 17:33:24 +00:00
@Override
public Collection<Ftile> getMyChildren() {
return Collections.unmodifiableCollection(forks);
}
2013-12-10 19:36:50 +00:00
public Swimlane getSwimlaneIn() {
return forks.get(0).getSwimlaneIn();
}
public Swimlane getSwimlaneOut() {
return getSwimlaneIn();
}
public Set<Swimlane> getSwimlanes() {
return mergeSwimlanes(forks);
}
public static Set<Swimlane> mergeSwimlanes(List<Ftile> tiles) {
2021-05-14 08:42:57 +00:00
final Set<Swimlane> result = new HashSet<>();
2023-12-11 17:34:23 +00:00
for (Ftile tile : tiles)
2013-12-10 19:36:50 +00:00
result.addAll(tile.getSwimlanes());
2023-12-11 17:34:23 +00:00
2013-12-10 19:36:50 +00:00
return Collections.unmodifiableSet(result);
}
2015-04-07 18:18:37 +00:00
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
2013-12-10 19:36:50 +00:00
2015-04-07 18:18:37 +00:00
double xpos = 0;
for (Ftile ftile : forks) {
2020-03-18 10:50:02 +00:00
ug.apply(UTranslate.dx(xpos)).draw(ftile);
2022-09-12 20:08:34 +00:00
final XDimension2D dim = ftile.calculateDimension(stringBounder);
2015-04-07 18:18:37 +00:00
xpos += dim.getWidth();
}
2013-12-10 19:36:50 +00:00
}
2017-11-20 16:10:36 +00:00
@Override
protected FtileGeometry calculateDimensionFtile(StringBounder stringBounder) {
2013-12-10 19:36:50 +00:00
double height = 0;
double width = 0;
for (Ftile ftile : forks) {
2022-09-12 20:08:34 +00:00
final XDimension2D dim = ftile.calculateDimension(stringBounder);
2013-12-10 19:36:50 +00:00
width += dim.getWidth();
2023-12-11 17:34:23 +00:00
if (dim.getHeight() > height)
2013-12-10 19:36:50 +00:00
height = dim.getHeight();
2023-12-11 17:34:23 +00:00
2013-12-10 19:36:50 +00:00
}
2022-09-12 20:08:34 +00:00
final XDimension2D dimTotal = new XDimension2D(width, height);
2015-04-07 18:18:37 +00:00
return new FtileGeometry(dimTotal, dimTotal.getWidth() / 2, 0, dimTotal.getHeight());
2013-12-10 19:36:50 +00:00
}
public UTranslate getTranslateFor(Ftile searched, StringBounder stringBounder) {
double xpos = 0;
for (Ftile ftile : forks) {
2023-12-11 17:34:23 +00:00
if (ftile == searched)
2020-03-18 10:50:02 +00:00
return UTranslate.dx(xpos);
2023-12-11 17:34:23 +00:00
2022-09-12 20:08:34 +00:00
final XDimension2D dim = ftile.calculateDimension(stringBounder);
2013-12-10 19:36:50 +00:00
xpos += dim.getWidth();
}
throw new IllegalArgumentException();
}
}