plantuml/src/net/sourceforge/plantuml/svek/GroupPngMakerState.java

212 lines
7.7 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, 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
*
*
*/
package net.sourceforge.plantuml.svek;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
2020-02-18 21:24:31 +00:00
import java.util.Set;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.EntityUtils;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.GroupHierarchy;
import net.sourceforge.plantuml.cucadiagram.GroupType;
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.ILeaf;
import net.sourceforge.plantuml.cucadiagram.LeafType;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.cucadiagram.SuperGroup;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.DotData;
import net.sourceforge.plantuml.graphic.FontConfiguration;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2016-08-25 20:45:37 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.TextBlock;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2021-09-19 17:05:24 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
2021-09-19 17:05:24 +00:00
import net.sourceforge.plantuml.style.Style;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.style.StyleSignatureBasic;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageState;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ugraphic.UStroke;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
public final class GroupPngMakerState {
2011-08-08 17:48:29 +00:00
private final CucaDiagram diagram;
2013-12-10 19:36:50 +00:00
private final IGroup group;
2016-08-25 20:45:37 +00:00
private final StringBounder stringBounder;
2011-08-08 17:48:29 +00:00
class InnerGroupHierarchy implements GroupHierarchy {
2020-02-18 21:24:31 +00:00
public Set<SuperGroup> getAllSuperGroups() {
throw new UnsupportedOperationException();
}
2020-02-18 21:24:31 +00:00
public IGroup getRootGroup() {
throw new UnsupportedOperationException();
}
public SuperGroup getRootSuperGroup() {
throw new UnsupportedOperationException();
}
2013-12-10 19:36:50 +00:00
public Collection<IGroup> getChildrenGroups(IGroup parent) {
2022-02-12 17:27:51 +00:00
if (EntityUtils.groupRoot(parent))
2011-08-08 17:48:29 +00:00
return diagram.getChildrenGroups(group);
2022-02-12 17:27:51 +00:00
2011-08-08 17:48:29 +00:00
return diagram.getChildrenGroups(parent);
}
2013-12-10 19:36:50 +00:00
public boolean isEmpty(IGroup g) {
2011-08-08 17:48:29 +00:00
return diagram.isEmpty(g);
}
}
2016-08-25 20:45:37 +00:00
public GroupPngMakerState(CucaDiagram diagram, IGroup group, StringBounder stringBounder) {
2011-08-08 17:48:29 +00:00
this.diagram = diagram;
2016-08-25 20:45:37 +00:00
this.stringBounder = stringBounder;
2011-08-08 17:48:29 +00:00
this.group = group;
2022-02-12 17:27:51 +00:00
if (group.isGroup() == false)
2013-12-10 19:36:50 +00:00
throw new IllegalArgumentException();
2022-02-12 17:27:51 +00:00
2011-08-08 17:48:29 +00:00
}
private List<Link> getPureInnerLinks() {
2021-05-14 08:42:57 +00:00
final List<Link> result = new ArrayList<>();
2022-02-12 17:27:51 +00:00
for (Link link : diagram.getLinks())
if (EntityUtils.isPureInnerLink12(group, link))
2011-08-08 17:48:29 +00:00
result.add(link);
2022-02-12 17:27:51 +00:00
2011-08-08 17:48:29 +00:00
return result;
}
2021-10-17 09:02:33 +00:00
private Style getStyleStateHeader() {
2022-03-01 18:11:51 +00:00
return StyleSignatureBasic.of(SName.root, SName.element, SName.stateDiagram, SName.state, SName.header)
.withTOBECHANGED(group.getStereotype()).getMergedStyle(diagram.getSkinParam().getCurrentStyleBuilder());
2021-09-19 17:05:24 +00:00
}
2021-10-17 09:02:33 +00:00
private Style getStyleState() {
2022-05-04 17:52:00 +00:00
return StyleSignatureBasic.of(SName.root, SName.element, SName.stateDiagram, SName.state)
.withTOBECHANGED(group.getStereotype()).getMergedStyle(diagram.getSkinParam().getCurrentStyleBuilder());
2021-09-19 17:05:24 +00:00
}
2015-04-07 18:18:37 +00:00
public IEntityImage getImage() {
2013-12-10 19:36:50 +00:00
final Display display = group.getDisplay();
2015-04-07 18:18:37 +00:00
final ISkinParam skinParam = diagram.getSkinParam();
2021-09-19 17:05:24 +00:00
2022-05-04 17:52:00 +00:00
final double rounded = getStyleState().value(PName.RoundCorner).asDouble();
final double shadowing = getStyleState().value(PName.Shadowing).asDouble();
final FontConfiguration fontConfiguration = getStyleStateHeader()
.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
2021-09-19 17:05:24 +00:00
final TextBlock title = display.create(fontConfiguration, HorizontalAlignment.CENTER, diagram.getSkinParam());
2011-08-08 17:48:29 +00:00
2022-02-12 17:27:51 +00:00
if (group.size() == 0 && group.getChildren().size() == 0)
2013-12-10 19:36:50 +00:00
return new EntityImageState(group, diagram.getSkinParam());
2022-02-12 17:27:51 +00:00
2011-08-08 17:48:29 +00:00
final List<Link> links = getPureInnerLinks();
2013-12-10 19:36:50 +00:00
final DotData dotData = new DotData(group, links, group.getLeafsDirect(), diagram.getUmlDiagramType(),
2015-04-07 18:18:37 +00:00
skinParam, new InnerGroupHierarchy(), diagram.getColorMapper(), diagram.getEntityFactory(),
diagram.isHideEmptyDescriptionForState(), DotMode.NORMAL, diagram.getNamespaceSeparator(),
diagram.getPragma());
2011-08-08 17:48:29 +00:00
2020-02-18 21:24:31 +00:00
final GeneralImageBuilder svek2 = new GeneralImageBuilder(false, dotData, diagram.getEntityFactory(),
diagram.getSource(), diagram.getPragma(), stringBounder, SName.stateDiagram);
2017-04-05 17:37:42 +00:00
2022-02-12 17:27:51 +00:00
if (group.getGroupType() == GroupType.CONCURRENT_STATE)
2016-07-25 19:25:28 +00:00
return svek2.buildImage(null, new String[0]);
2022-02-12 17:27:51 +00:00
if (group.getGroupType() != GroupType.STATE)
2016-07-25 19:25:28 +00:00
throw new UnsupportedOperationException(group.getGroupType().toString());
2021-11-15 18:27:27 +00:00
HColor borderColor = group.getColors().getColor(ColorType.LINE);
2022-02-12 17:27:51 +00:00
if (borderColor == null)
2022-05-04 17:52:00 +00:00
borderColor = getStyleState().value(PName.LineColor).asColor(skinParam.getThemeStyle(),
skinParam.getIHtmlColorSet());
2022-02-12 17:27:51 +00:00
2016-07-25 19:25:28 +00:00
final Stereotype stereo = group.getStereotype();
2022-05-04 17:52:00 +00:00
HColor backColor = group.getColors().getColor(ColorType.BACK);
if (backColor == null)
backColor = getStyleState().value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(),
skinParam.getIHtmlColorSet());
2021-09-19 17:05:24 +00:00
2022-02-12 17:27:51 +00:00
UStroke stroke = group.getColors().getSpecificLineStroke();
if (stroke == null)
2022-05-04 17:52:00 +00:00
stroke = getStyleState().getStroke();
2022-02-12 17:27:51 +00:00
2020-12-14 18:31:06 +00:00
final TextBlock attribute = GeneralImageBuilder.stateHeader((IEntity) group, null, skinParam);
2016-07-25 19:25:28 +00:00
final Stereotype stereotype = group.getStereotype();
final boolean withSymbol = stereotype != null && stereotype.isWithOOSymbol();
final boolean containsOnlyConcurrentStates = containsOnlyConcurrentStates(dotData);
2020-02-18 21:24:31 +00:00
final IEntityImage image = containsOnlyConcurrentStates ? buildImageForConcurrentState(dotData)
: svek2.buildImage(null, new String[0]);
2022-02-12 17:27:51 +00:00
2021-10-17 09:02:33 +00:00
return new InnerStateAutonom(image, title, attribute, borderColor, backColor, group.getUrl99(), withSymbol,
stroke, rounded, shadowing);
2013-12-10 19:36:50 +00:00
2016-07-25 19:25:28 +00:00
}
2013-12-10 19:36:50 +00:00
2016-07-25 19:25:28 +00:00
private IEntityImage buildImageForConcurrentState(DotData dotData) {
2021-05-14 08:42:57 +00:00
final List<IEntityImage> inners = new ArrayList<>();
2022-02-12 17:27:51 +00:00
for (ILeaf inner : dotData.getLeafs())
2016-07-25 19:25:28 +00:00
inners.add(inner.getSvekImage());
2022-02-12 17:27:51 +00:00
2016-07-25 19:25:28 +00:00
return new CucaDiagramFileMakerSvek2InternalImage(inners, dotData.getTopParent().getConcurrentSeparator(),
2018-03-09 21:37:34 +00:00
dotData.getSkinParam(), group.getStereotype());
2011-08-08 17:48:29 +00:00
}
2015-04-07 18:18:37 +00:00
private boolean containsOnlyConcurrentStates(DotData dotData) {
for (ILeaf leaf : dotData.getLeafs()) {
2022-02-12 17:27:51 +00:00
if (leaf instanceof IGroup == false)
2015-04-07 18:18:37 +00:00
return false;
2022-02-12 17:27:51 +00:00
if (((IGroup) leaf).getLeafType() != LeafType.STATE_CONCURRENT)
2015-04-07 18:18:37 +00:00
return false;
2022-02-12 17:27:51 +00:00
2015-04-07 18:18:37 +00:00
}
return true;
}
2011-08-08 17:48:29 +00:00
}