1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-03 09:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/svek/Cluster.java

988 lines
30 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2011-08-08 17:48:29 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2011-08-08 17:48:29 +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
*
2011-08-08 17:48:29 +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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2011-08-08 17:48:29 +00:00
* 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
* Contribution : Hisashi Miyashita
2011-08-08 17:48:29 +00:00
*
*
*/
package net.sourceforge.plantuml.svek;
import java.awt.geom.Dimension2D;
2013-12-10 19:36:50 +00:00
import java.awt.geom.Point2D;
2011-08-08 17:48:29 +00:00
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
2016-04-04 19:05:10 +00:00
import java.util.EnumSet;
2011-08-08 17:48:29 +00:00
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
2018-07-27 21:56:46 +00:00
import net.sourceforge.plantuml.AlignmentParam;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.Dimension2DDouble;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.SkinParamUtils;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.Url;
2020-12-01 21:39:27 +00:00
import net.sourceforge.plantuml.UseStyle;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.EntityPosition;
import net.sourceforge.plantuml.cucadiagram.EntityUtils;
2011-09-08 10:42:27 +00:00
import net.sourceforge.plantuml.cucadiagram.IEntity;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.IGroup;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
2017-12-11 21:02:10 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2011-09-08 10:42:27 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.TextBlock;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.graphic.USymbol;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2017-12-11 21:02:10 +00:00
import net.sourceforge.plantuml.graphic.color.Colors;
2011-09-08 10:42:27 +00:00
import net.sourceforge.plantuml.posimo.Moveable;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.skin.rose.Rose;
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.StyleSignature;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageState;
2016-07-25 19:25:28 +00:00
import net.sourceforge.plantuml.ugraphic.UComment;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
2011-09-08 10:42:27 +00:00
import net.sourceforge.plantuml.ugraphic.ULine;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UStroke;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorBackground;
2020-04-26 18:31:41 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.utils.UniqueSequence;
2011-08-08 17:48:29 +00:00
2011-09-08 10:42:27 +00:00
public class Cluster implements Moveable {
2011-08-08 17:48:29 +00:00
private static final String RANK_SAME = "same";
private static final String RANK_SOURCE = "source";
private static final String RANK_SINK = "sink";
private static final String ID_EE = "ee";
public final static String CENTER_ID = "za";
2020-02-18 21:24:31 +00:00
private final Cluster parentCluster;
2013-12-10 19:36:50 +00:00
private final IGroup group;
2020-02-18 21:24:31 +00:00
private final List<Node> nodes = new ArrayList<Node>();
2011-08-08 17:48:29 +00:00
private final List<Cluster> children = new ArrayList<Cluster>();
private final int color;
private final int colorTitle;
2013-12-10 19:36:50 +00:00
private final ISkinParam skinParam;
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
private int titleAndAttributeWidth;
private int titleAndAttributeHeight;
private TextBlock ztitle;
private TextBlock zstereo;
2011-09-08 10:42:27 +00:00
private double xTitle;
private double yTitle;
private double minX;
private double minY;
private double maxX;
private double maxY;
public void moveSvek(double deltaX, double deltaY) {
this.xTitle += deltaX;
this.minX += deltaX;
this.maxX += deltaX;
this.yTitle += deltaY;
this.minY += deltaY;
this.maxY += deltaY;
}
private Set<EntityPosition> entityPositionsExceptNormal() {
final Set<EntityPosition> result = EnumSet.<EntityPosition>noneOf(EntityPosition.class);
2020-02-18 21:24:31 +00:00
for (Node sh : nodes) {
2013-12-10 19:36:50 +00:00
if (sh.getEntityPosition() != EntityPosition.NORMAL) {
result.add(sh.getEntityPosition());
2013-12-10 19:36:50 +00:00
}
}
return Collections.unmodifiableSet(result);
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
public Cluster(ColorSequence colorSequence, ISkinParam skinParam, IGroup root) {
2020-02-18 21:24:31 +00:00
this(null, colorSequence, skinParam, root);
2011-08-08 17:48:29 +00:00
}
2015-04-07 18:18:37 +00:00
private ColorParam border;
2020-02-18 21:24:31 +00:00
private Cluster(Cluster parentCluster, ColorSequence colorSequence, ISkinParam skinParam, IGroup group) {
2013-12-10 19:36:50 +00:00
if (group == null) {
throw new IllegalStateException();
}
2020-02-18 21:24:31 +00:00
this.parentCluster = parentCluster;
2011-08-08 17:48:29 +00:00
this.group = group;
2015-04-07 18:18:37 +00:00
if (group.getUSymbol() != null) {
border = group.getUSymbol().getColorParamBorder();
}
2011-08-08 17:48:29 +00:00
this.color = colorSequence.getValue();
this.colorTitle = colorSequence.getValue();
2015-09-28 20:42:17 +00:00
this.skinParam = group.getColors(skinParam).mute(skinParam);
2011-08-08 17:48:29 +00:00
}
@Override
public String toString() {
return super.toString() + " " + group;
}
2020-02-18 21:24:31 +00:00
public final Cluster getParentCluster() {
return parentCluster;
2011-08-08 17:48:29 +00:00
}
2020-02-18 21:24:31 +00:00
public void addNode(Node node) {
if (node == null) {
2013-12-10 19:36:50 +00:00
throw new IllegalArgumentException();
}
2020-02-18 21:24:31 +00:00
this.nodes.add(node);
node.setCluster(this);
2011-08-08 17:48:29 +00:00
}
2020-02-18 21:24:31 +00:00
public final List<Node> getNodes() {
return Collections.unmodifiableList(nodes);
2011-08-08 17:48:29 +00:00
}
2020-02-18 21:24:31 +00:00
private List<Node> getNodesOrderedTop(Collection<Line> lines) {
final List<Node> firsts = new ArrayList<Node>();
2011-08-08 17:48:29 +00:00
final Set<String> tops = new HashSet<String>();
2020-02-18 21:24:31 +00:00
final Map<String, Node> shs = new HashMap<String, Node>();
for (final Iterator<Node> it = nodes.iterator(); it.hasNext();) {
final Node node = it.next();
shs.put(node.getUid(), node);
if (node.isTop() && node.getEntityPosition() == EntityPosition.NORMAL) {
firsts.add(node);
tops.add(node.getUid());
2013-12-10 19:36:50 +00:00
}
}
for (Line l : lines) {
2016-07-04 19:06:50 +00:00
if (tops.contains(l.getStartUidPrefix())) {
2020-02-18 21:24:31 +00:00
final Node sh = shs.get(l.getEndUidPrefix());
2013-12-10 19:36:50 +00:00
if (sh != null && sh.getEntityPosition() == EntityPosition.NORMAL) {
firsts.add(0, sh);
}
}
if (l.isInverted()) {
2020-02-18 21:24:31 +00:00
final Node sh = shs.get(l.getStartUidPrefix());
2013-12-10 19:36:50 +00:00
if (sh != null && sh.getEntityPosition() == EntityPosition.NORMAL) {
firsts.add(0, sh);
}
}
}
return firsts;
}
2020-02-18 21:24:31 +00:00
private List<Node> getNodesOrderedWithoutTop(Collection<Line> lines) {
final List<Node> all = new ArrayList<Node>(nodes);
2013-12-10 19:36:50 +00:00
final Set<String> tops = new HashSet<String>();
2020-02-18 21:24:31 +00:00
final Map<String, Node> shs = new HashMap<String, Node>();
2013-12-10 19:36:50 +00:00
2020-02-18 21:24:31 +00:00
for (final Iterator<Node> it = all.iterator(); it.hasNext();) {
final Node sh = it.next();
2013-12-10 19:36:50 +00:00
if (sh.getEntityPosition() != EntityPosition.NORMAL) {
it.remove();
continue;
}
2011-08-08 17:48:29 +00:00
shs.put(sh.getUid(), sh);
if (sh.isTop()) {
tops.add(sh.getUid());
it.remove();
}
}
for (Line l : lines) {
2016-07-04 19:06:50 +00:00
if (tops.contains(l.getStartUidPrefix())) {
2020-02-18 21:24:31 +00:00
final Node sh = shs.get(l.getEndUidPrefix());
2013-12-10 19:36:50 +00:00
if (sh != null) {
all.remove(sh);
}
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
2011-08-08 17:48:29 +00:00
if (l.isInverted()) {
2020-02-18 21:24:31 +00:00
final Node sh = shs.get(l.getStartUidPrefix());
2013-12-10 19:36:50 +00:00
if (sh != null) {
all.remove(sh);
}
2011-08-08 17:48:29 +00:00
}
}
return all;
}
public final List<Cluster> getChildren() {
return Collections.unmodifiableList(children);
}
2020-02-18 21:24:31 +00:00
public Cluster createChild(int titleAndAttributeWidth, int titleAndAttributeHeight, TextBlock title,
TextBlock stereo, ColorSequence colorSequence, ISkinParam skinParam, IGroup g) {
final Cluster child = new Cluster(this, colorSequence, skinParam, g);
2013-12-10 19:36:50 +00:00
child.titleAndAttributeWidth = titleAndAttributeWidth;
child.titleAndAttributeHeight = titleAndAttributeHeight;
child.ztitle = title;
child.zstereo = stereo;
2011-08-08 17:48:29 +00:00
this.children.add(child);
return child;
}
2020-02-18 21:24:31 +00:00
public final Set<IGroup> getGroups() {
return Collections.singleton(group);
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
public final int getTitleAndAttributeWidth() {
return titleAndAttributeWidth;
}
public final int getTitleAndAttributeHeight() {
return titleAndAttributeHeight;
}
public double getWidth() {
return maxX - minX;
}
public double getMinX() {
return minX;
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
public ClusterPosition getClusterPosition() {
return new ClusterPosition(minX, minY, maxX, maxY);
2011-08-08 17:48:29 +00:00
}
public void setTitlePosition(double x, double y) {
this.xTitle = x;
this.yTitle = y;
}
2020-03-18 10:50:02 +00:00
private static HColor getColor(ColorParam colorParam, ISkinParam skinParam, Stereotype stereotype) {
2019-01-16 18:34:41 +00:00
return SkinParamUtils.getColor(skinParam, stereotype, colorParam);
2015-04-07 18:18:37 +00:00
}
static public StyleSignature getDefaultStyleDefinition(SName styleName) {
return StyleSignature.of(SName.root, SName.element, styleName, SName.group);
2019-08-26 17:07:21 +00:00
}
2020-06-14 20:35:42 +00:00
public void drawU(UGraphic ug, UStroke strokeForState, UmlDiagramType umlDiagramType, ISkinParam skinParam2) {
2018-03-09 21:37:34 +00:00
if (group.isHidden()) {
return;
}
2019-12-10 21:45:49 +00:00
final String fullName = group.getCodeGetName();
2017-12-11 21:02:10 +00:00
if (fullName.startsWith("##") == false) {
ug.draw(new UComment("cluster " + fullName));
}
2015-08-05 20:17:01 +00:00
final Stereotype stereotype = group.getStereotype();
2020-03-18 10:50:02 +00:00
HColor borderColor;
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle()) {
final Style style = getDefaultStyleDefinition(umlDiagramType.getStyleName())
.getMergedStyle(skinParam.getCurrentStyleBuilder());
2019-08-26 17:07:21 +00:00
borderColor = style.value(PName.LineColor).asColor(skinParam2.getIHtmlColorSet());
2015-04-07 18:18:37 +00:00
} else {
2019-08-26 17:07:21 +00:00
if (umlDiagramType == UmlDiagramType.STATE) {
borderColor = getColor(ColorParam.stateBorder, skinParam, stereotype);
} else if (umlDiagramType == UmlDiagramType.ACTIVITY) {
borderColor = getColor(ColorParam.packageBorder, skinParam, stereotype);
} else {
borderColor = getColor(ColorParam.packageBorder, skinParam, stereotype);
}
2015-04-07 18:18:37 +00:00
}
2013-12-10 19:36:50 +00:00
final Url url = group.getUrl99();
if (url != null) {
ug.startUrl(url);
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
try {
if (entityPositionsExceptNormal().size() > 0) {
2016-03-06 16:47:34 +00:00
manageEntryExitPoint(ug.getStringBounder());
2013-12-10 19:36:50 +00:00
}
2016-03-06 16:47:34 +00:00
if (skinParam.useSwimlanes(umlDiagramType)) {
drawSwinLinesState(ug, borderColor);
2013-12-10 19:36:50 +00:00
return;
}
2016-03-06 16:47:34 +00:00
final boolean isState = umlDiagramType == UmlDiagramType.STATE;
2013-12-10 19:36:50 +00:00
if (isState) {
2015-09-28 20:42:17 +00:00
if (group.getColors(skinParam).getSpecificLineStroke() != null) {
2020-06-14 20:35:42 +00:00
strokeForState = group.getColors(skinParam).getSpecificLineStroke();
2015-04-07 18:18:37 +00:00
}
2015-09-28 20:42:17 +00:00
if (group.getColors(skinParam).getColor(ColorType.LINE) != null) {
borderColor = group.getColors(skinParam).getColor(ColorType.LINE);
2015-04-07 18:18:37 +00:00
}
2020-06-14 20:35:42 +00:00
drawUState(ug, borderColor, skinParam2, strokeForState, umlDiagramType);
2013-12-10 19:36:50 +00:00
return;
}
2019-08-26 17:07:21 +00:00
PackageStyle packageStyle = group.getPackageStyle();
if (packageStyle == null) {
2020-06-21 20:31:45 +00:00
packageStyle = skinParam2.packageStyle();
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
if (border != null) {
2020-03-18 10:50:02 +00:00
final HColor tmp = skinParam2.getHtmlColor(border, group.getStereotype(), false);
2015-04-07 18:18:37 +00:00
if (tmp != null) {
borderColor = tmp;
}
}
2019-08-26 17:07:21 +00:00
final double shadowing;
2020-06-14 20:35:42 +00:00
final UStroke stroke;
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle()) {
final Style style = getDefaultStyleDefinition(umlDiagramType.getStyleName())
.getMergedStyle(skinParam.getCurrentStyleBuilder());
2019-08-26 17:07:21 +00:00
shadowing = style.value(PName.Shadowing).asDouble();
2020-06-14 20:35:42 +00:00
stroke = style.getStroke();
2019-08-26 17:07:21 +00:00
} else {
if (group.getUSymbol() == null) {
shadowing = skinParam2.shadowing2(group.getStereotype(), USymbol.PACKAGE.getSkinParameter()) ? 3
: 0;
} else {
shadowing = skinParam2.shadowing2(group.getStereotype(), group.getUSymbol().getSkinParameter()) ? 3
: 0;
}
2020-06-14 20:35:42 +00:00
stroke = getStrokeInternal(skinParam2);
2019-08-26 17:07:21 +00:00
}
2020-03-18 10:50:02 +00:00
HColor backColor = getBackColor(umlDiagramType);
backColor = getBackColor(backColor, skinParam2, group.getStereotype(), umlDiagramType.getStyleName());
2013-12-10 19:36:50 +00:00
if (ztitle != null || zstereo != null) {
2020-02-18 21:24:31 +00:00
final double roundCorner = group.getUSymbol() == null ? 0
: group.getUSymbol().getSkinParameter().getRoundCorner(skinParam, stereotype);
2016-12-14 21:01:03 +00:00
2019-08-26 17:07:21 +00:00
final ClusterDecoration decoration = new ClusterDecoration(packageStyle, group.getUSymbol(), ztitle,
2020-06-14 20:35:42 +00:00
zstereo, minX, minY, maxX, maxY, stroke);
2019-08-26 17:07:21 +00:00
decoration.drawU(ug, backColor, borderColor, shadowing, roundCorner,
2019-05-24 19:59:31 +00:00
skinParam2.getHorizontalAlignment(AlignmentParam.packageTitleAlignment, null, false),
skinParam2.getStereotypeAlignment());
2013-12-10 19:36:50 +00:00
return;
}
final URectangle rect = new URectangle(maxX - minX, maxY - minY);
2019-08-26 17:07:21 +00:00
rect.setDeltaShadow(shadowing);
2020-04-19 16:04:39 +00:00
ug = ug.apply(backColor.bg()).apply(borderColor);
2013-12-10 19:36:50 +00:00
ug.apply(new UStroke(2)).apply(new UTranslate(minX, minY)).draw(rect);
} finally {
if (url != null) {
2020-05-17 21:15:50 +00:00
ug.closeUrl();
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
}
2011-09-08 10:42:27 +00:00
2013-12-10 19:36:50 +00:00
}
2011-09-08 10:42:27 +00:00
2017-12-11 21:02:10 +00:00
private UStroke getStrokeInternal(ISkinParam skinParam) {
final Colors colors = group.getColors(skinParam);
if (colors.getSpecificLineStroke() != null) {
return colors.getSpecificLineStroke();
}
2020-06-14 20:35:42 +00:00
if (group.getUSymbol() != null && group.getUSymbol() != USymbol.PACKAGE) {
2017-12-11 21:02:10 +00:00
return group.getUSymbol().getSkinParameter().getStroke(skinParam, group.getStereotype());
}
2020-06-14 20:35:42 +00:00
return GeneralImageBuilder.getForcedStroke(group.getStereotype(), skinParam);
// UStroke stroke = skinParam.getThickness(LineParam.packageBorder, group.getStereotype());
// if (stroke == null) {
// stroke = new UStroke(1.5);
// }
// return stroke;
2015-04-07 18:18:37 +00:00
}
2016-03-06 16:47:34 +00:00
public void manageEntryExitPoint(StringBounder stringBounder) {
2013-12-10 19:36:50 +00:00
final Collection<ClusterPosition> insides = new ArrayList<ClusterPosition>();
final List<Point2D> points = new ArrayList<Point2D>();
2020-02-18 21:24:31 +00:00
for (Node sh : nodes) {
2013-12-10 19:36:50 +00:00
if (sh.getEntityPosition() == EntityPosition.NORMAL) {
insides.add(sh.getClusterPosition());
} else {
points.add(sh.getClusterPosition().getPointCenter());
}
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
for (Cluster in : children) {
insides.add(in.getClusterPosition());
2011-09-08 10:42:27 +00:00
}
2013-12-10 19:36:50 +00:00
final FrontierCalculator frontierCalculator = new FrontierCalculator(getClusterPosition(), insides, points);
if (titleAndAttributeHeight > 0 && titleAndAttributeWidth > 0) {
frontierCalculator.ensureMinWidth(titleAndAttributeWidth + 10);
2011-09-08 10:42:27 +00:00
}
2013-12-10 19:36:50 +00:00
final ClusterPosition forced = frontierCalculator.getSuggestedPosition();
xTitle += ((forced.getMinX() - minX) + (forced.getMaxX() - maxX)) / 2;
minX = forced.getMinX();
minY = forced.getMinY();
maxX = forced.getMaxX();
maxY = forced.getMaxY();
yTitle = minY + IEntityImage.MARGIN;
final double widthTitle = ztitle.calculateDimension(stringBounder).getWidth();
xTitle = minX + ((maxX - minX - widthTitle) / 2);
}
2020-03-18 10:50:02 +00:00
private void drawSwinLinesState(UGraphic ug, HColor borderColor) {
2013-12-10 19:36:50 +00:00
if (ztitle != null) {
2020-03-18 10:50:02 +00:00
ztitle.drawU(ug.apply(UTranslate.dx(xTitle)));
2011-09-08 10:42:27 +00:00
}
2020-03-18 10:50:02 +00:00
final ULine line = ULine.vline(maxY - minY);
2020-04-19 16:04:39 +00:00
ug = ug.apply(borderColor);
2020-03-18 10:50:02 +00:00
ug.apply(UTranslate.dx(minX)).draw(line);
ug.apply(UTranslate.dx(maxX)).draw(line);
2013-12-10 19:36:50 +00:00
2011-08-08 17:48:29 +00:00
}
2020-03-18 10:50:02 +00:00
private HColor getColor(ISkinParam skinParam, ColorParam colorParam, Stereotype stereo) {
2019-01-16 18:34:41 +00:00
return new Rose().getHtmlColor(skinParam, stereo, colorParam);
2011-08-08 17:48:29 +00:00
}
2020-03-18 10:50:02 +00:00
private void drawUState(UGraphic ug, HColor borderColor, ISkinParam skinParam2, UStroke stroke,
2016-07-04 19:06:50 +00:00
UmlDiagramType umlDiagramType) {
2011-08-08 17:48:29 +00:00
final Dimension2D total = new Dimension2DDouble(maxX - minX, maxY - minY);
2013-12-10 19:36:50 +00:00
final double suppY;
if (ztitle == null) {
suppY = 0;
} else {
suppY = ztitle.calculateDimension(ug.getStringBounder()).getHeight() + IEntityImage.MARGIN
+ IEntityImage.MARGIN_LINE;
}
2020-03-18 10:50:02 +00:00
HColor stateBack = getBackColor(umlDiagramType);
2011-08-08 17:48:29 +00:00
if (stateBack == null) {
2016-03-06 16:47:34 +00:00
stateBack = getColor(skinParam2, ColorParam.stateBackground, group.getStereotype());
2011-08-08 17:48:29 +00:00
}
2020-03-18 10:50:02 +00:00
final HColor background = getColor(skinParam2, ColorParam.background, null);
2020-12-14 18:31:06 +00:00
final Style style = getStyle(FontParam.STATE_ATTRIBUTE, skinParam2);
final TextBlock attribute = GeneralImageBuilder.stateHeader(group, style, skinParam2);
2013-12-10 19:36:50 +00:00
final double attributeHeight = attribute.calculateDimension(ug.getStringBounder()).getHeight();
2020-10-12 20:56:58 +00:00
if (total.getWidth() == 0) {
System.err.println("Cluster::drawUState issue");
return;
}
2020-02-18 21:24:31 +00:00
final RoundedContainer r = new RoundedContainer(total, suppY,
attributeHeight + (attributeHeight > 0 ? IEntityImage.MARGIN : 0), borderColor, stateBack, background,
stroke);
2018-09-23 12:15:14 +00:00
r.drawU(ug.apply(new UTranslate(minX, minY)), skinParam2.shadowing(group.getStereotype()));
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
if (ztitle != null) {
ztitle.drawU(ug.apply(new UTranslate(xTitle, yTitle)));
}
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
if (attributeHeight > 0) {
2020-12-14 18:31:06 +00:00
attribute.drawU(
2013-12-10 19:36:50 +00:00
ug.apply(new UTranslate(minX + IEntityImage.MARGIN, minY + suppY + IEntityImage.MARGIN / 2.0)));
}
final Stereotype stereotype = group.getStereotype();
final boolean withSymbol = stereotype != null && stereotype.isWithOOSymbol();
if (withSymbol) {
2020-04-19 16:04:39 +00:00
EntityImageState.drawSymbol(ug.apply(borderColor), maxX, maxY);
2013-12-10 19:36:50 +00:00
}
}
2011-08-08 17:48:29 +00:00
public void setPosition(double minX, double minY, double maxX, double maxY) {
this.minX = minX;
this.maxX = maxX;
this.minY = minY;
this.maxY = maxY;
2020-12-01 21:39:27 +00:00
}
2011-08-08 17:48:29 +00:00
2020-12-01 21:39:27 +00:00
private Style getStyle(FontParam fontParam, ISkinParam skinParam) {
return fontParam.getStyleDefinition(SName.stateDiagram).getMergedStyle(skinParam.getCurrentStyleBuilder());
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
private boolean isThereALinkFromOrToGroup(Collection<Line> lines) {
for (Line line : lines) {
2015-04-07 18:18:37 +00:00
if (line.isLinkFromOrTo(group)) {
2013-12-10 19:36:50 +00:00
return true;
}
}
return false;
2011-08-08 17:48:29 +00:00
}
2016-08-25 20:45:37 +00:00
public void printCluster1(StringBuilder sb, Collection<Line> lines, StringBounder stringBounder) {
2020-02-18 21:24:31 +00:00
for (Node node : getNodesOrderedTop(lines)) {
node.appendShape(sb, stringBounder);
2013-12-10 19:36:50 +00:00
}
}
2011-08-08 17:48:29 +00:00
private List<IShapePseudo> addProtection(List<? extends IShapePseudo> entries, double width) {
2013-12-10 19:36:50 +00:00
final List<IShapePseudo> result = new ArrayList<IShapePseudo>();
result.add(entries.get(0));
for (int i = 1; i < entries.size(); i++) {
// Pseudo space for the label
2013-12-10 19:36:50 +00:00
result.add(new ShapePseudoImpl("psd" + UniqueSequence.getValue(), width, 5));
result.add(entries.get(i));
}
return result;
}
private double getMaxWidthFromLabelForEntryExit(List<? extends IShapePseudo> entries, StringBounder stringBounder) {
2013-12-10 19:36:50 +00:00
double result = -Double.MAX_VALUE;
for (IShapePseudo node : entries) {
2020-02-18 21:24:31 +00:00
final double w = getMaxWidthFromLabelForEntryExit(node, stringBounder);
2013-12-10 19:36:50 +00:00
if (w > result) {
result = w;
}
}
return result;
}
private double getMaxWidthFromLabelForEntryExit(IShapePseudo node, StringBounder stringBounder) {
2020-02-18 21:24:31 +00:00
return node.getMaxWidthFromLabelForEntryExit(stringBounder);
2013-12-10 19:36:50 +00:00
}
private void printRanks(String rank, List<? extends IShapePseudo> entries, StringBuilder sb,
StringBounder stringBounder) {
2013-12-10 19:36:50 +00:00
if (entries.size() > 0) {
sb.append("{rank=" + rank + ";");
for (IShapePseudo sh1 : entries) {
sb.append(sh1.getUid() + ";");
2013-12-10 19:36:50 +00:00
}
sb.append("}");
SvekUtils.println(sb);
for (IShapePseudo sh2 : entries) {
sh2.appendShape(sb, stringBounder);
2011-08-08 17:48:29 +00:00
}
SvekUtils.println(sb);
if (hasPort()) {
boolean arrow = false;
String node = null;
for (IShapePseudo sh : entries) {
if (arrow) {
sb.append("->");
}
arrow = true;
node = sh.getUid();
sb.append(node);
}
sb.append(';');
SvekUtils.println(sb);
sb.append(node + "->" + empty() + ";");
SvekUtils.println(sb);
2013-12-10 19:36:50 +00:00
}
}
}
private List<? extends IShapePseudo> withPositionProtected(StringBounder stringBounder,
Set<EntityPosition> targets) {
final List<Node> result = withPosition(targets);
final double maxWith = getMaxWidthFromLabelForEntryExit(result, stringBounder);
final double naturalSpace = 70;
if (maxWith > naturalSpace) {
return addProtection(result, maxWith - naturalSpace);
}
return result;
}
private List<Node> withPosition(Set<EntityPosition> positions) {
final List<Node> result = new ArrayList<Node>();
for (final Iterator<Node> it = nodes.iterator(); it.hasNext();) {
final Node sh = it.next();
if (positions.contains(sh.getEntityPosition())) {
result.add(sh);
2013-12-10 19:36:50 +00:00
}
}
return result;
}
private void printClusterEntryExit(StringBuilder sb, StringBounder stringBounder) {
printRanks(RANK_SOURCE, withPositionProtected(stringBounder, EntityPosition.getInputs()), sb, stringBounder);
printRanks(RANK_SAME, withPositionProtected(stringBounder, EntityPosition.getSame()), sb, stringBounder);
printRanks(RANK_SINK, withPositionProtected(stringBounder, EntityPosition.getOutputs()), sb, stringBounder);
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
public Node printCluster2(StringBuilder sb, Collection<Line> lines, StringBounder stringBounder, DotMode dotMode,
2020-02-18 21:24:31 +00:00
GraphvizVersion graphvizVersion, UmlDiagramType type) {
2013-12-10 19:36:50 +00:00
Node added = null;
2020-02-18 21:24:31 +00:00
for (Node node : getNodesOrderedWithoutTop(lines)) {
node.appendShape(sb, stringBounder);
added = node;
2013-12-10 19:36:50 +00:00
}
2018-05-01 17:26:04 +00:00
if (skinParam.useRankSame() && dotMode != DotMode.NO_LEFT_RIGHT_AND_XLABEL
&& graphvizVersion.ignoreHorizontalLinks() == false) {
2013-12-10 19:36:50 +00:00
appendRankSame(sb, lines);
}
for (Cluster child : getChildren()) {
2015-04-07 18:18:37 +00:00
child.printInternal(sb, lines, stringBounder, dotMode, graphvizVersion, type);
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
return added;
}
private void appendRankSame(StringBuilder sb, Collection<Line> lines) {
for (String same : getRankSame(lines)) {
2011-08-08 17:48:29 +00:00
sb.append(same);
SvekUtils.println(sb);
}
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
private Set<String> getRankSame(Collection<Line> lines) {
final Set<String> rankSame = new HashSet<String>();
for (Line l : lines) {
if (l.hasEntryPoint()) {
continue;
}
2016-07-04 19:06:50 +00:00
final String startUid = l.getStartUidPrefix();
final String endUid = l.getEndUidPrefix();
2013-12-10 19:36:50 +00:00
if (isInCluster(startUid) && isInCluster(endUid)) {
final String same = l.rankSame();
if (same != null) {
rankSame.add(same);
}
}
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
return rankSame;
2011-08-08 17:48:29 +00:00
}
public void fillRankMin(Set<String> rankMin) {
2020-02-18 21:24:31 +00:00
for (Node sh : getNodes()) {
2011-08-08 17:48:29 +00:00
if (sh.isTop()) {
rankMin.add(sh.getUid());
}
}
for (Cluster child : getChildren()) {
child.fillRankMin(rankMin);
}
}
private boolean isInCluster(String uid) {
2020-02-18 21:24:31 +00:00
for (Node node : nodes) {
if (node.getUid().equals(uid)) {
2011-08-08 17:48:29 +00:00
return true;
}
}
return false;
}
public String getClusterId() {
return "cluster" + color;
}
2013-12-10 19:36:50 +00:00
public static String getSpecialPointId(IEntity group) {
return CENTER_ID + group.getUid();
2011-08-08 17:48:29 +00:00
}
2015-04-07 18:18:37 +00:00
private boolean protection0(UmlDiagramType type) {
if (skinParam.useSwimlanes(type)) {
2013-12-10 19:36:50 +00:00
return false;
}
return true;
}
2011-09-08 10:42:27 +00:00
2015-04-07 18:18:37 +00:00
private boolean protection1(UmlDiagramType type) {
if (group.getUSymbol() == USymbol.NODE) {
return true;
}
if (skinParam.useSwimlanes(type)) {
2013-12-10 19:36:50 +00:00
return false;
}
return true;
}
2015-04-07 18:18:37 +00:00
public String getMinPoint(UmlDiagramType type) {
if (skinParam.useSwimlanes(type)) {
2013-12-10 19:36:50 +00:00
return "minPoint" + color;
}
return null;
}
2015-04-07 18:18:37 +00:00
public String getMaxPoint(UmlDiagramType type) {
if (skinParam.useSwimlanes(type)) {
2013-12-10 19:36:50 +00:00
return "maxPoint" + color;
}
return null;
}
2015-04-07 18:18:37 +00:00
private String getSourceInPoint(UmlDiagramType type) {
if (skinParam.useSwimlanes(type)) {
2013-12-10 19:36:50 +00:00
return "sourceIn" + color;
}
return null;
}
2015-04-07 18:18:37 +00:00
private String getSinkInPoint(UmlDiagramType type) {
if (skinParam.useSwimlanes(type)) {
2013-12-10 19:36:50 +00:00
return "sinkIn" + color;
}
return null;
}
2015-04-07 18:18:37 +00:00
private void printInternal(StringBuilder sb, Collection<Line> lines, StringBounder stringBounder, DotMode dotMode,
GraphvizVersion graphvizVersion, UmlDiagramType type) {
final boolean thereALinkFromOrToGroup2 = isThereALinkFromOrToGroup(lines);
boolean thereALinkFromOrToGroup1 = thereALinkFromOrToGroup2;
final boolean useProtectionWhenThereALinkFromOrToGroup = graphvizVersion
.useProtectionWhenThereALinkFromOrToGroup();
if (useProtectionWhenThereALinkFromOrToGroup == false) {
thereALinkFromOrToGroup1 = false;
}
// final boolean thereALinkFromOrToGroup1 = false;
if (thereALinkFromOrToGroup1) {
subgraphClusterNoLabel(sb, "a");
2011-08-08 17:48:29 +00:00
}
final Set<EntityPosition> entityPositionsExceptNormal = entityPositionsExceptNormal();
if (entityPositionsExceptNormal.size() > 0) {
2013-12-10 19:36:50 +00:00
for (Line line : lines) {
2015-04-07 18:18:37 +00:00
if (line.isLinkFromOrTo(group)) {
2013-12-10 19:36:50 +00:00
line.setProjectionCluster(this);
}
}
}
2015-04-07 18:18:37 +00:00
boolean protection0 = protection0(type);
boolean protection1 = protection1(type);
if (entityPositionsExceptNormal.size() > 0 || useProtectionWhenThereALinkFromOrToGroup == false) {
2013-12-10 19:36:50 +00:00
protection0 = false;
protection1 = false;
}
2016-07-04 19:06:50 +00:00
// if (graphvizVersion.modeSafe()) {
// protection0 = false;
// protection1 = false;
// }
2011-09-08 10:42:27 +00:00
if (protection0) {
subgraphClusterNoLabel(sb, "p0");
2011-09-08 10:42:27 +00:00
}
2011-08-08 17:48:29 +00:00
sb.append("subgraph " + getClusterId() + " {");
sb.append("style=solid;");
2020-04-26 18:31:41 +00:00
sb.append("color=\"" + DotStringFactory.sharp000000(color) + "\";");
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
final String label;
2016-04-04 19:05:10 +00:00
if (isLabel()) {
2013-12-10 19:36:50 +00:00
final StringBuilder sblabel = new StringBuilder("<");
Line.appendTable(sblabel, getTitleAndAttributeWidth(), getTitleAndAttributeHeight() - 5, colorTitle);
sblabel.append(">");
label = sblabel.toString();
2018-09-23 12:15:14 +00:00
final HorizontalAlignment align = skinParam.getHorizontalAlignment(AlignmentParam.packageTitleAlignment,
2018-11-26 18:46:22 +00:00
null, false);
2017-12-11 21:02:10 +00:00
sb.append("labeljust=\"" + align.getGraphVizValue() + "\";");
2013-12-10 19:36:50 +00:00
} else {
label = "\"\"";
}
if (entityPositionsExceptNormal.size() > 0) {
2013-12-10 19:36:50 +00:00
printClusterEntryExit(sb, stringBounder);
if (hasPort()) {
subgraphClusterNoLabel(sb, ID_EE);
} else {
subgraphClusterWithLabel(sb, ID_EE, label);
}
2013-12-10 19:36:50 +00:00
} else {
sb.append("label=" + label + ";");
SvekUtils.println(sb);
2011-08-08 17:48:29 +00:00
}
2015-04-07 18:18:37 +00:00
if (thereALinkFromOrToGroup2) {
2013-12-10 19:36:50 +00:00
sb.append(getSpecialPointId(group) + " [shape=point,width=.01,label=\"\"];");
2015-04-07 18:18:37 +00:00
}
if (thereALinkFromOrToGroup1) {
subgraphClusterNoLabel(sb, "i");
2011-08-08 17:48:29 +00:00
}
2011-09-08 10:42:27 +00:00
if (protection1) {
subgraphClusterNoLabel(sb, "p1");
2011-09-08 10:42:27 +00:00
}
2015-04-07 18:18:37 +00:00
if (skinParam.useSwimlanes(type)) {
2013-12-10 19:36:50 +00:00
sb.append("{rank = source; ");
2015-04-07 18:18:37 +00:00
sb.append(getSourceInPoint(type));
2013-12-10 19:36:50 +00:00
sb.append(" [shape=point,width=.01,label=\"\"];");
2015-04-07 18:18:37 +00:00
sb.append(getMinPoint(type) + "->" + getSourceInPoint(type) + " [weight=999];");
2013-12-10 19:36:50 +00:00
sb.append("}");
SvekUtils.println(sb);
sb.append("{rank = sink; ");
2015-04-07 18:18:37 +00:00
sb.append(getSinkInPoint(type));
2013-12-10 19:36:50 +00:00
sb.append(" [shape=point,width=.01,label=\"\"];");
sb.append("}");
2015-04-07 18:18:37 +00:00
sb.append(getSinkInPoint(type) + "->" + getMaxPoint(type) + " [weight=999];");
2013-12-10 19:36:50 +00:00
SvekUtils.println(sb);
}
SvekUtils.println(sb);
2016-08-25 20:45:37 +00:00
printCluster1(sb, lines, stringBounder);
final Node added = printCluster2(sb, lines, stringBounder, dotMode, graphvizVersion, type);
2020-06-21 20:31:45 +00:00
if (entityPositionsExceptNormal.size() > 0) {
if (hasPort()) {
sb.append(empty() + " [shape=rect,width=.01,height=.01,label=");
sb.append(label);
sb.append("];");
2020-06-21 20:31:45 +00:00
} else if (added == null) {
sb.append(empty() + " [shape=point,width=.01,label=\"\"];");
}
SvekUtils.println(sb);
2013-12-10 19:36:50 +00:00
}
2013-12-10 19:36:50 +00:00
sb.append("}");
2011-09-08 10:42:27 +00:00
if (protection1) {
sb.append("}");
}
2015-04-07 18:18:37 +00:00
if (thereALinkFromOrToGroup1) {
2013-12-10 19:36:50 +00:00
sb.append("}");
2011-08-08 17:48:29 +00:00
sb.append("}");
}
if (entityPositionsExceptNormal.size() > 0) {
2011-09-08 10:42:27 +00:00
sb.append("}");
}
2013-12-10 19:36:50 +00:00
if (protection0) {
2011-08-08 17:48:29 +00:00
sb.append("}");
}
SvekUtils.println(sb);
}
private boolean hasPort() {
for (EntityPosition pos : entityPositionsExceptNormal()) {
if (pos.isPort()) {
return true;
}
}
return false;
}
private String empty() {
2020-06-21 20:31:45 +00:00
// return "empty" + color;
// We use the same node with one for thereALinkFromOrToGroup2 as an empty
// because we cannot put a new node in the nested inside of the cluster
// if thereALinkFromOrToGroup2 is enabled.
return getSpecialPointId(group);
}
2016-04-04 19:05:10 +00:00
public boolean isLabel() {
return getTitleAndAttributeHeight() > 0 && getTitleAndAttributeWidth() > 0;
}
private void subgraphClusterNoLabel(StringBuilder sb, String id) {
subgraphClusterWithLabel(sb, id, "\"\"");
2013-12-10 19:36:50 +00:00
}
private void subgraphClusterWithLabel(StringBuilder sb, String id, String label) {
sb.append("subgraph " + getClusterId() + id + " {");
2013-12-10 19:36:50 +00:00
sb.append("label=" + label + ";");
2011-08-08 17:48:29 +00:00
}
public int getColor() {
return color;
}
public int getTitleColor() {
return colorTitle;
}
2020-03-18 10:50:02 +00:00
private final HColor getBackColor(final UmlDiagramType umlDiagramType) {
2013-12-10 19:36:50 +00:00
if (EntityUtils.groupRoot(group)) {
2011-09-08 10:42:27 +00:00
return null;
}
2020-03-18 10:50:02 +00:00
final HColor result = group.getColors(skinParam).getColor(ColorType.BACK);
2011-09-08 10:42:27 +00:00
if (result != null) {
return result;
}
2015-04-07 18:18:37 +00:00
final Stereotype stereo = group.getStereotype();
final USymbol sym = group.getUSymbol() == null ? USymbol.PACKAGE : group.getUSymbol();
2020-02-18 21:24:31 +00:00
final ColorParam backparam = umlDiagramType == UmlDiagramType.ACTIVITY ? ColorParam.partitionBackground
: sym.getColorParamBack();
2020-03-18 10:50:02 +00:00
final HColor c1 = skinParam.getHtmlColor(backparam, stereo, false);
2015-04-07 18:18:37 +00:00
if (c1 != null) {
return c1;
}
2020-02-18 21:24:31 +00:00
if (parentCluster == null) {
2011-09-08 10:42:27 +00:00
return null;
}
2020-02-18 21:24:31 +00:00
return parentCluster.getBackColor(umlDiagramType);
2011-09-08 10:42:27 +00:00
}
public boolean isClusterOf(IEntity ent) {
2013-12-10 19:36:50 +00:00
if (ent.isGroup() == false) {
2011-09-08 10:42:27 +00:00
return false;
}
2013-12-10 19:36:50 +00:00
return group == ent;
2011-08-08 17:48:29 +00:00
}
public static HColor getBackColor(HColor backColor, ISkinParam skinParam, Stereotype stereotype, SName styleName) {
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle()) {
final Style style = getDefaultStyleDefinition(styleName).getMergedStyle(skinParam.getCurrentStyleBuilder());
2019-08-26 17:07:21 +00:00
if (backColor == null) {
backColor = style.value(PName.BackGroundColor).asColor(skinParam.getIHtmlColorSet());
}
2020-05-30 15:20:23 +00:00
if (backColor == null || backColor.equals(HColorUtils.transparent())) {
backColor = new HColorBackground(skinParam.getBackgroundColor(false));
2019-08-26 17:07:21 +00:00
}
return backColor;
}
2015-08-05 20:17:01 +00:00
if (backColor == null) {
backColor = skinParam.getHtmlColor(ColorParam.packageBackground, stereotype, false);
2013-12-10 19:36:50 +00:00
}
2015-08-05 20:17:01 +00:00
if (backColor == null) {
backColor = skinParam.getHtmlColor(ColorParam.background, stereotype, false);
2013-12-10 19:36:50 +00:00
}
if (backColor == null
|| backColor.equals(HColorUtils.transparent()) /* || stateBack instanceof HtmlColorTransparent */) {
2020-05-30 15:20:23 +00:00
final HColor tmp = skinParam.getBackgroundColor(false);
backColor = new HColorBackground(tmp);
2013-12-10 19:36:50 +00:00
}
2015-08-05 20:17:01 +00:00
return backColor;
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
public double checkFolderPosition(Point2D pt, StringBounder stringBounder) {
if (getClusterPosition().isPointJustUpper(pt)) {
if (ztitle == null) {
return 0;
}
final Dimension2D dimTitle = ztitle.calculateDimension(stringBounder);
if (pt.getX() < getClusterPosition().getMinX() + dimTitle.getWidth()) {
return 0;
}
return getClusterPosition().getMinY() - pt.getY() + dimTitle.getHeight();
}
return 0;
}
2013-12-10 19:36:50 +00:00
// public Point2D projection(double x, double y) {
// final double v1 = Math.abs(minX - x);
// final double v2 = Math.abs(maxX - x);
// final double v3 = Math.abs(minY - y);
// final double v4 = Math.abs(maxY - y);
// if (v1 <= v2 && v1 <= v3 && v1 <= v4) {
// return new Point2D.Double(minX, y);
// }
// if (v2 <= v1 && v2 <= v3 && v2 <= v4) {
// return new Point2D.Double(maxX, y);
// }
// if (v3 <= v1 && v3 <= v2 && v3 <= v4) {
// return new Point2D.Double(x, minY);
// }
// if (v4 <= v1 && v4 <= v1 && v4 <= v3) {
// return new Point2D.Double(x, maxY);
// }
// throw new IllegalStateException();
// }
2011-08-08 17:48:29 +00:00
}