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

228 lines
8.1 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
*
*
*/
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.ColorParam;
import net.sourceforge.plantuml.FontParam;
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;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.TextBlockEmpty;
import net.sourceforge.plantuml.graphic.TextBlockWidth;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.graphic.TextBlockWidthAdapter;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.style.SName;
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) {
if (EntityUtils.groupRoot(parent)) {
2011-08-08 17:48:29 +00:00
return diagram.getChildrenGroups(group);
}
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;
2013-12-10 19:36:50 +00:00
if (group.isGroup() == false) {
throw new IllegalArgumentException();
}
2011-08-08 17:48:29 +00:00
}
private List<Link> getPureInnerLinks() {
final List<Link> result = new ArrayList<Link>();
for (Link link : diagram.getLinks()) {
2013-12-10 19:36:50 +00:00
if (EntityUtils.isPureInnerLink12(group, link)) {
2011-08-08 17:48:29 +00:00
result.add(link);
}
}
return result;
}
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();
2020-02-18 21:24:31 +00:00
final TextBlock title = display.create(new FontConfiguration(skinParam, FontParam.STATE, group.getStereotype()),
HorizontalAlignment.CENTER, diagram.getSkinParam());
2011-08-08 17:48:29 +00:00
2015-11-01 18:37:20 +00:00
if (group.size() == 0 && group.getChildren().size() == 0) {
2013-12-10 19:36:50 +00:00
return new EntityImageState(group, diagram.getSkinParam());
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
2016-07-25 19:25:28 +00:00
if (group.getGroupType() == GroupType.CONCURRENT_STATE) {
// return new InnerStateConcurrent(svek2.createFile());
return svek2.buildImage(null, new String[0]);
}
if (group.getGroupType() != GroupType.STATE) {
throw new UnsupportedOperationException(group.getGroupType().toString());
}
2020-03-18 10:50:02 +00:00
HColor borderColor = group.getColors(skinParam).getColor(ColorType.LINE);
2016-07-25 19:25:28 +00:00
if (borderColor == null) {
borderColor = getColor(ColorParam.stateBorder, group.getStereotype());
}
final Stereotype stereo = group.getStereotype();
2020-03-18 10:50:02 +00:00
final HColor backColor = group.getColors(skinParam).getColor(ColorType.BACK) == null
2020-02-18 21:24:31 +00:00
? getColor(ColorParam.stateBackground, stereo)
: group.getColors(skinParam).getColor(ColorType.BACK);
2017-06-05 11:27:21 +00:00
final TextBlockWidth attribute = getAttributes(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]);
2015-09-28 20:42:17 +00:00
UStroke stroke = group.getColors(skinParam).getSpecificLineStroke();
2015-04-07 18:18:37 +00:00
if (stroke == null) {
stroke = new UStroke(1.5);
}
2020-02-18 21:24:31 +00:00
return new InnerStateAutonom(image, title, attribute, borderColor, backColor,
skinParam.shadowing(group.getStereotype()), group.getUrl99(), withSymbol, stroke);
2013-12-10 19:36:50 +00:00
2016-07-25 19:25:28 +00:00
}
2013-12-10 19:36:50 +00:00
2017-06-05 11:27:21 +00:00
private TextBlockWidth getAttributes(final ISkinParam skinParam) {
final List<String> details = ((IEntity) group).getBodier().getRawBody();
if (details.size() == 0) {
return new TextBlockEmpty();
}
final FontConfiguration fontConfiguration = new FontConfiguration(skinParam, FontParam.STATE_ATTRIBUTE, null);
2018-09-23 12:15:14 +00:00
Display display = null;
for (String s : details) {
if (display == null) {
display = Display.getWithNewlines(s);
} else {
display = display.addAll(Display.getWithNewlines(s));
}
}
2017-06-05 11:27:21 +00:00
final TextBlock result = display.create(fontConfiguration, HorizontalAlignment.LEFT, skinParam);
return new TextBlockWidthAdapter(result, 0);
}
2016-07-25 19:25:28 +00:00
private IEntityImage buildImageForConcurrentState(DotData dotData) {
final List<IEntityImage> inners = new ArrayList<IEntityImage>();
for (ILeaf inner : dotData.getLeafs()) {
inners.add(inner.getSvekImage());
2011-08-08 17:48:29 +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()) {
if (leaf instanceof IGroup == false) {
return false;
}
2017-04-05 17:37:42 +00:00
if (((IGroup) leaf).getLeafType() != LeafType.STATE_CONCURRENT) {
2015-04-07 18:18:37 +00:00
return false;
}
}
return true;
}
2011-08-08 17:48:29 +00:00
private final Rose rose = new Rose();
2020-03-18 10:50:02 +00:00
private HColor getColor(ColorParam colorParam, Stereotype stereo) {
2011-08-08 17:48:29 +00:00
final ISkinParam skinParam = diagram.getSkinParam();
2019-01-16 18:34:41 +00:00
return rose.getHtmlColor(skinParam, stereo, colorParam);
2011-08-08 17:48:29 +00:00
}
}