net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.AbstractParallelFtilesBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-epl Show documentation
Show all versions of plantuml-epl Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
/* +=======================================================================
* |
* | PlantUML : a free UML diagram generator
* |
* +=======================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/liberapay (only 1€ per month!)
* https://plantuml.com/paypal
*
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the Eclipse Public License.
*
* THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
* LICENSE ("AGREEMENT"). [Eclipse Public License - v 1.0]
*
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
*
* You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PlantUML can occasionally display sponsored or advertising messages. Those
* messages are usually generated on welcome or error images and never on
* functional diagrams.
* See https://plantuml.com/professional if you want to remove them
*
* Images (whatever their format : PNG, SVG, EPS...) generated by running PlantUML
* are owned by the author of their corresponding sources code (that is, their
* textual description in PlantUML language). Those images are not covered by
* this EPL license.
*
* The generated images can then be used without any reference to the EPL license.
* It is not even necessary to stipulate that they have been generated with PlantUML,
* although this will be appreciated by the PlantUML team.
*
* There is an exception : if the textual description in PlantUML language is also covered
* by any license, then the generated images are logically covered
* by the very same license.
*
* This is the IGY distribution (Install GraphViz by Yourself).
* You have to install GraphViz and to setup the GRAPHVIZ_DOT environment variable
* (see https://plantuml.com/graphviz-dot )
*
* Icons provided by OpenIconic : https://useiconic.com/open
* Archimate sprites provided by Archi : http://www.archimatetool.com
* Stdlib AWS provided by https://github.com/milo-minderbinder/AWS-PlantUML
* Stdlib Icons provided https://github.com/tupadr3/plantuml-icon-font-sprites
* ASCIIMathML (c) Peter Jipsen http://www.chapman.edu/~jipsen
* ASCIIMathML (c) David Lippman http://www.pierce.ctc.edu/dlippman
* CafeUndZopfli ported by Eugene Klyuchnikov https://github.com/eustas/CafeUndZopfli
* Brotli (c) by the Brotli Authors https://github.com/google/brotli
* Themes (c) by Brett Schwarz https://github.com/bschwarz/puml-themes
* Twemoji (c) by Twitter at https://twemoji.twitter.com/
*
*/
package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.activitydiagram3.LinkRendering;
import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile;
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileGeometry;
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileHeightFixedCentered;
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileHeightFixedMarged;
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils;
import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
import net.sourceforge.plantuml.klimt.creole.CreoleMode;
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.style.ISkinParam;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleSignatureBasic;
public abstract class AbstractParallelFtilesBuilder {
protected final double barHeight = 6;
private final Rose rose = new Rose();
private final ISkinParam skinParam;
private final StringBounder stringBounder;
protected final List list99 = new ArrayList<>();
public StyleSignatureBasic getStyleSignature() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.activityDiagram, SName.activity);
}
final public StyleSignatureBasic getStyleSignatureArrow() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.activityDiagram, SName.arrow);
}
public AbstractParallelFtilesBuilder(ISkinParam skinParam, StringBounder stringBounder, List all) {
this.skinParam = skinParam;
this.stringBounder = stringBounder;
this.list99.addAll(decorateAllTiles(all));
}
private List decorateAllTiles(List all) {
final double maxHeight = computeMaxHeight(all);
final double ymargin1 = getSuppSpace1(all, getStringBounder());
final double ymargin2 = getSuppSpace2(all, getStringBounder());
final List result = new ArrayList<>();
for (Ftile ftile : all) {
final Ftile newFtile = computeNewFtile(ftile, maxHeight, ymargin1, ymargin2);
result.add(newFtile);
}
return result;
}
private double getSuppSpace1(List all, StringBounder stringBounder) {
double result = 0;
for (Ftile child : all) {
final TextBlock text = getTextBlock(child.getInLinkRendering().getDisplay());
if (text == null)
continue;
final XDimension2D dim = text.calculateDimension(stringBounder);
result = Math.max(result, dim.getHeight());
}
return result;
}
private double getSuppSpace2(List all, StringBounder stringBounder) {
double result = 0;
for (Ftile child : all) {
final TextBlock text = getTextBlock(child.getOutLinkRendering().getDisplay());
if (text == null)
continue;
final XDimension2D dim = text.calculateDimension(stringBounder);
result = Math.max(result, dim.getHeight());
}
return result;
}
private Ftile computeNewFtile(Ftile ftile, double maxHeight, double ymargin1, double ymargin2) {
final double spaceArroundBlackBar = 20;
final double xMargin = 14;
Ftile tmp;
tmp = FtileUtils.addHorizontalMargin(ftile, xMargin, xMargin + getSuppForIncomingArrow(ftile));
tmp = new FtileHeightFixedCentered(tmp, maxHeight + 2 * spaceArroundBlackBar);
tmp = new FtileHeightFixedMarged(ymargin1, tmp, ymargin2);
return tmp;
}
private double getSuppForIncomingArrow(Ftile ftile) {
final double x1 = getXSuppForDisplay(ftile, ftile.getInLinkRendering().getDisplay());
final double x2 = getXSuppForDisplay(ftile, ftile.getOutLinkRendering().getDisplay());
return Math.max(x1, x2);
}
private double getXSuppForDisplay(Ftile ftile, Display label) {
final TextBlock text = getTextBlock(label);
if (text == null)
return 0;
final double textWidth = text.calculateDimension(getStringBounder()).getWidth();
final FtileGeometry ftileDim = ftile.calculateDimension(getStringBounder());
final double pos2 = ftileDim.getLeft() + textWidth;
if (pos2 > ftileDim.getWidth())
return pos2 - ftileDim.getWidth();
return 0;
}
final protected double computeMaxHeight(List all) {
double height = 0;
for (Ftile tmp : all)
height = Math.max(height, tmp.calculateDimension(getStringBounder()).getHeight());
return height;
}
public final Ftile build(Ftile inner) {
final Ftile step1 = doStep1(inner);
return doStep2(inner, step1);
}
protected abstract Ftile doStep1(Ftile inner);
protected abstract Ftile doStep2(Ftile inner, Ftile step1);
protected StringBounder getStringBounder() {
return stringBounder;
}
protected Rose getRose() {
return rose;
}
protected ISkinParam skinParam() {
return skinParam;
}
protected final TextBlock getTextBlock(Display display) {
// DUP3945
if (Display.isNull(display))
return null;
final Style style = getStyleSignatureArrow().getMergedStyle(skinParam().getCurrentStyleBuilder());
final FontConfiguration fontConfiguration = style.getFontConfiguration(skinParam().getIHtmlColorSet());
return display.create7(fontConfiguration, HorizontalAlignment.LEFT, skinParam(), CreoleMode.SIMPLE_LINE);
}
protected TextBlock getTextBlock(LinkRendering linkRendering) {
// DUP1433
final Display display = linkRendering.getDisplay();
return getTextBlock(display);
}
protected final double getHeightOfMiddle(Ftile middle) {
return middle.calculateDimension(getStringBounder()).getHeight();
}
protected Swimlane swimlaneOutForStep2() {
return list99.get(list99.size() - 1).getSwimlaneOut();
}
}