1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 15:40:48 +00:00
plantuml/src/net/sourceforge/plantuml/svek/DotDataImageBuilder.java

552 lines
21 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, 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
*
* 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.awt.geom.Dimension2D;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
2016-07-25 19:25:28 +00:00
import java.util.Map;
2013-12-10 19:36:50 +00:00
import java.util.regex.Matcher;
import java.util.regex.Pattern;
2011-08-08 17:48:29 +00:00
2016-05-11 21:31:47 +00:00
import net.sourceforge.plantuml.BaseFile;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.FontParam;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.Pragma;
import net.sourceforge.plantuml.SkinParamForecolored;
import net.sourceforge.plantuml.SkinParamSameClassWidth;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.StringUtils;
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.core.UmlSource;
2016-07-25 19:25:28 +00:00
import net.sourceforge.plantuml.cucadiagram.Code;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.EntityPosition;
2011-08-08 17:48:29 +00:00
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;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.cucadiagram.MethodsOrFieldsArea;
import net.sourceforge.plantuml.cucadiagram.PortionShower;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.cucadiagram.UnparsableGraphvizException;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.DotData;
2016-07-25 19:25:28 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.ExeState;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
import net.sourceforge.plantuml.cucadiagram.dot.Neighborhood;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.entity.EntityFactory;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.GraphicStrings;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.HtmlColor;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.TextBlockEmpty;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.TextBlockUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.TextBlockWidth;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.graphic.USymbol;
import net.sourceforge.plantuml.graphic.USymbolInterface;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageActivity;
import net.sourceforge.plantuml.svek.image.EntityImageArcCircle;
import net.sourceforge.plantuml.svek.image.EntityImageAssociation;
import net.sourceforge.plantuml.svek.image.EntityImageAssociationPoint;
import net.sourceforge.plantuml.svek.image.EntityImageBranch;
import net.sourceforge.plantuml.svek.image.EntityImageCircleEnd;
import net.sourceforge.plantuml.svek.image.EntityImageCircleStart;
import net.sourceforge.plantuml.svek.image.EntityImageClass;
2015-07-11 09:32:49 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageDescription;
2015-08-05 20:17:01 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageEmptyPackage;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageGroup;
import net.sourceforge.plantuml.svek.image.EntityImageLollipopInterface;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageLollipopInterfaceEye1;
import net.sourceforge.plantuml.svek.image.EntityImageLollipopInterfaceEye2;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageNote;
import net.sourceforge.plantuml.svek.image.EntityImageObject;
import net.sourceforge.plantuml.svek.image.EntityImagePseudoState;
import net.sourceforge.plantuml.svek.image.EntityImageState;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageState2;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageStateBorder;
import net.sourceforge.plantuml.svek.image.EntityImageStateEmptyDescription;
import net.sourceforge.plantuml.svek.image.EntityImageSynchroBar;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageTips;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.EntityImageUseCase;
2016-03-06 16:47:34 +00:00
import net.sourceforge.plantuml.ugraphic.sprite.Sprite;
2011-08-08 17:48:29 +00:00
2016-07-25 19:25:28 +00:00
public final class DotDataImageBuilder {
2011-08-08 17:48:29 +00:00
private final DotData dotData;
2013-12-10 19:36:50 +00:00
private final EntityFactory entityFactory;
private final UmlSource source;
private final Pragma pragma;
2016-07-25 19:25:28 +00:00
private Map<Code, Double> maxX;
2011-08-08 17:48:29 +00:00
2016-08-25 20:45:37 +00:00
private final StringBounder stringBounder;
2011-08-08 17:48:29 +00:00
2016-08-25 20:45:37 +00:00
public DotDataImageBuilder(DotData dotData, EntityFactory entityFactory, UmlSource source, Pragma pragma,
StringBounder stringBounder) {
2011-08-08 17:48:29 +00:00
this.dotData = dotData;
2013-12-10 19:36:50 +00:00
this.entityFactory = entityFactory;
this.source = source;
this.pragma = pragma;
2016-08-25 20:45:37 +00:00
this.stringBounder = stringBounder;
2011-08-08 17:48:29 +00:00
}
2016-07-25 19:25:28 +00:00
public IEntityImage buildImage(BaseFile basefile, String dotStrings[]) {
2015-04-07 18:18:37 +00:00
dotData.removeIrrelevantSametail();
2016-07-25 19:25:28 +00:00
final DotStringFactory dotStringFactory = new DotStringFactory(stringBounder, dotData);
2011-08-08 17:48:29 +00:00
2016-07-25 19:25:28 +00:00
printGroups(dotStringFactory, dotData.getRootGroup());
printEntities(dotStringFactory, getUnpackagedEntities());
2011-08-08 17:48:29 +00:00
for (Link link : dotData.getLinks()) {
2013-12-10 19:36:50 +00:00
if (link.isRemoved()) {
continue;
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
try {
final ISkinParam skinParam = dotData.getSkinParam();
2017-02-15 21:34:36 +00:00
final FontConfiguration labelFont = new FontConfiguration(skinParam, FontParam.ARROW, null);
2013-12-10 19:36:50 +00:00
2016-07-25 19:25:28 +00:00
final Line line = new Line(link, dotStringFactory.getColorSequence(), skinParam, stringBounder,
labelFont, dotStringFactory.getBibliotekon(), dotData.getPragma());
2013-12-10 19:36:50 +00:00
2016-07-25 19:25:28 +00:00
dotStringFactory.getBibliotekon().addLine(line);
2013-12-10 19:36:50 +00:00
if (link.getEntity1().isGroup() == false && link.getEntity1().getEntityType() == LeafType.NOTE
&& onlyOneLink(link.getEntity1())) {
2016-07-25 19:25:28 +00:00
final Shape shape = dotStringFactory.getBibliotekon().getShape(link.getEntity1());
final Shape other = dotStringFactory.getBibliotekon().getShape(link.getEntity2());
2016-01-09 12:15:40 +00:00
if (other != null) {
((EntityImageNote) shape.getImage()).setOpaleLine(line, shape, other);
line.setOpale(true);
}
2013-12-10 19:36:50 +00:00
} else if (link.getEntity2().isGroup() == false && link.getEntity2().getEntityType() == LeafType.NOTE
&& onlyOneLink(link.getEntity2())) {
2016-07-25 19:25:28 +00:00
final Shape shape = dotStringFactory.getBibliotekon().getShape(link.getEntity2());
final Shape other = dotStringFactory.getBibliotekon().getShape(link.getEntity1());
2016-01-09 12:15:40 +00:00
if (other != null) {
((EntityImageNote) shape.getImage()).setOpaleLine(line, shape, other);
line.setOpale(true);
}
2013-12-10 19:36:50 +00:00
}
} catch (IllegalStateException e) {
e.printStackTrace();
2011-09-08 10:42:27 +00:00
}
2011-08-08 17:48:29 +00:00
}
if (dotStringFactory.illegalDotExe()) {
return error(dotStringFactory.getDotExe());
}
2016-05-11 21:31:47 +00:00
// final boolean trace = OptionFlags.getInstance().isKeepTmpFiles() || OptionFlags.TRACE_DOT || isSvekTrace();
// option.isDebugSvek
// System.err.println("FOO11 svekDebug=" + svekDebug);
if (basefile == null && isSvekTrace()) {
basefile = new BaseFile();
}
// System.err.println("FOO11 basefile=" + basefile);
2015-04-07 18:18:37 +00:00
final String svg;
try {
2016-05-11 21:31:47 +00:00
svg = dotStringFactory.getSvg(basefile, dotStrings);
2015-04-07 18:18:37 +00:00
} catch (IOException e) {
return new GraphvizCrash(source.getPlainString());
}
2013-12-10 19:36:50 +00:00
if (svg.length() == 0) {
2015-04-07 18:18:37 +00:00
return new GraphvizCrash(source.getPlainString());
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
final String graphvizVersion = extractGraphvizVersion(svg);
try {
final ClusterPosition position = dotStringFactory.solve(svg).delta(10, 10);
final double minY = position.getMinY();
final double minX = position.getMinX();
if (minX > 0 || minY > 0) {
throw new IllegalStateException();
}
2015-04-07 18:18:37 +00:00
final SvekResult result = new SvekResult(position, dotData, dotStringFactory);
2013-12-10 19:36:50 +00:00
result.moveSvek(6 - minX, -minY);
2016-07-25 19:25:28 +00:00
this.maxX = dotStringFactory.getBibliotekon().getMaxX();
2013-12-10 19:36:50 +00:00
return result;
} catch (Exception e) {
Log.error("Exception " + e);
throw new UnparsableGraphvizException(e, graphvizVersion, svg, source.getPlainString());
}
}
2011-09-08 10:42:27 +00:00
2013-12-10 19:36:50 +00:00
private boolean isSvekTrace() {
final String value = pragma.getValue("svek_trace");
return "true".equalsIgnoreCase(value) || "on".equalsIgnoreCase(value);
}
private String extractGraphvizVersion(String svg) {
final Pattern pGraph = Pattern.compile("(?mi)!-- generated by graphviz(.*)");
final Matcher mGraph = pGraph.matcher(svg);
if (mGraph.find()) {
2015-05-31 18:56:03 +00:00
return StringUtils.trin(mGraph.group(1));
2013-12-10 19:36:50 +00:00
}
return null;
2011-09-08 10:42:27 +00:00
}
2011-08-08 17:48:29 +00:00
2011-09-08 10:42:27 +00:00
private boolean onlyOneLink(IEntity ent) {
2013-12-10 19:36:50 +00:00
int nb = 0;
for (Link link : dotData.getLinks()) {
if (link.isInvis()) {
continue;
}
if (link.contains(ent)) {
nb++;
}
if (nb > 1) {
return false;
}
}
return nb == 1;
2011-08-08 17:48:29 +00:00
}
private IEntityImage error(File dotExe) {
final List<String> msg = new ArrayList<String>();
msg.add("Dot Executable: " + dotExe);
2016-07-25 19:25:28 +00:00
final ExeState exeState = ExeState.checkFile(dotExe);
msg.add(exeState.getTextMessage());
2011-08-08 17:48:29 +00:00
msg.add("Cannot find Graphviz. You should try");
msg.add(" ");
msg.add("@startuml");
msg.add("testdot");
msg.add("@enduml");
msg.add(" ");
msg.add(" or ");
msg.add(" ");
msg.add("java -jar plantuml.jar -testdot");
2013-12-10 19:36:50 +00:00
msg.add(" ");
2016-11-18 21:12:09 +00:00
return GraphicStrings.createForError(msg, false);
2011-08-08 17:48:29 +00:00
}
2016-07-25 19:25:28 +00:00
private void printEntities(DotStringFactory dotStringFactory, Collection<ILeaf> entities2) {
2013-12-10 19:36:50 +00:00
for (ILeaf ent : entities2) {
if (ent.isRemoved()) {
continue;
}
2016-07-25 19:25:28 +00:00
printEntity(dotStringFactory, ent);
2011-08-08 17:48:29 +00:00
}
}
2016-07-25 19:25:28 +00:00
private void printEntity(DotStringFactory dotStringFactory, ILeaf ent) {
2013-12-10 19:36:50 +00:00
if (ent.isRemoved()) {
throw new IllegalStateException();
}
2016-07-25 19:25:28 +00:00
final IEntityImage image = printEntityInternal(dotStringFactory, ent);
2013-12-10 19:36:50 +00:00
final Dimension2D dim = image.calculateDimension(stringBounder);
2016-07-25 19:25:28 +00:00
final Shape shape = new Shape(image, image.getShapeType(), dim.getWidth(), dim.getHeight(),
dotStringFactory.getColorSequence(), ent.isTop(), image.getShield(), ent.getEntityPosition());
2011-08-08 17:48:29 +00:00
dotStringFactory.addShape(shape);
2016-07-25 19:25:28 +00:00
dotStringFactory.getBibliotekon().putShape(ent, shape);
2013-12-10 19:36:50 +00:00
}
2016-07-25 19:25:28 +00:00
private IEntityImage printEntityInternal(DotStringFactory dotStringFactory, ILeaf ent) {
2013-12-10 19:36:50 +00:00
if (ent.isRemoved()) {
throw new IllegalStateException();
}
if (ent.getSvekImage() == null) {
ISkinParam skinParam = dotData.getSkinParam();
2016-03-06 16:47:34 +00:00
if (skinParam.sameClassWidth()) {
2016-07-25 19:25:28 +00:00
final double width = getMaxWidth(dotStringFactory);
2016-03-06 16:47:34 +00:00
skinParam = new SkinParamSameClassWidth(skinParam, width);
2013-12-10 19:36:50 +00:00
}
return createEntityImageBlock(ent, skinParam, dotData.isHideEmptyDescriptionForState(), dotData,
2016-07-25 19:25:28 +00:00
dotStringFactory.getBibliotekon(), dotStringFactory.getGraphvizVersion(),
dotData.getUmlDiagramType());
2013-12-10 19:36:50 +00:00
}
return ent.getSvekImage();
}
2016-07-25 19:25:28 +00:00
private double getMaxWidth(DotStringFactory dotStringFactory) {
2013-12-10 19:36:50 +00:00
double result = 0;
for (ILeaf ent : dotData.getLeafs()) {
if (ent.getEntityType().isLikeClass() == false) {
continue;
}
2015-04-07 18:18:37 +00:00
final IEntityImage im = new EntityImageClass(dotStringFactory.getGraphvizVersion(), ent,
dotData.getSkinParam(), dotData);
2013-12-10 19:36:50 +00:00
final double w = im.calculateDimension(stringBounder).getWidth();
if (w > result) {
result = w;
}
}
return result;
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
public static IEntityImage createEntityImageBlock(ILeaf leaf, ISkinParam skinParam,
2015-04-07 18:18:37 +00:00
boolean isHideEmptyDescriptionForState, PortionShower portionShower, Bibliotekon bibliotekon,
GraphvizVersion graphvizVersion, UmlDiagramType umlDiagramType) {
2013-12-10 19:36:50 +00:00
if (leaf.isRemoved()) {
throw new IllegalStateException();
}
if (leaf.getEntityType().isLikeClass()) {
2015-04-07 18:18:37 +00:00
final EntityImageClass entityImageClass = new EntityImageClass(graphvizVersion, (ILeaf) leaf, skinParam,
portionShower);
final Neighborhood neighborhood = leaf.getNeighborhood();
if (neighborhood != null) {
return new EntityImageProtected(entityImageClass, 20, neighborhood, bibliotekon);
}
return entityImageClass;
2013-12-10 19:36:50 +00:00
}
if (leaf.getEntityType() == LeafType.NOTE) {
return new EntityImageNote(leaf, skinParam);
}
if (leaf.getEntityType() == LeafType.ACTIVITY) {
2015-04-07 18:18:37 +00:00
return new EntityImageActivity(leaf, skinParam, bibliotekon);
2013-12-10 19:36:50 +00:00
}
if (leaf.getEntityType() == LeafType.STATE) {
if (leaf.getEntityPosition() != EntityPosition.NORMAL) {
final Cluster stateParent = bibliotekon.getCluster(leaf.getParentContainer());
return new EntityImageStateBorder(leaf, skinParam, stateParent, bibliotekon);
}
2015-06-07 10:23:10 +00:00
if (isHideEmptyDescriptionForState && leaf.getBodier().getFieldsToDisplay().size() == 0) {
2013-12-10 19:36:50 +00:00
return new EntityImageStateEmptyDescription(leaf, skinParam);
}
2015-04-07 18:18:37 +00:00
if (leaf.getStereotype() != null && "<<sdlreceive>>".equals(leaf.getStereotype().getLabel(false))) {
return new EntityImageState2(leaf, skinParam);
}
2013-12-10 19:36:50 +00:00
return new EntityImageState(leaf, skinParam);
2015-04-07 18:18:37 +00:00
2013-12-10 19:36:50 +00:00
}
if (leaf.getEntityType() == LeafType.CIRCLE_START) {
2015-04-07 18:18:37 +00:00
ColorParam param = ColorParam.activityStart;
if (umlDiagramType == UmlDiagramType.STATE) {
param = ColorParam.stateStart;
}
return new EntityImageCircleStart(leaf, skinParam, param);
2013-12-10 19:36:50 +00:00
}
if (leaf.getEntityType() == LeafType.CIRCLE_END) {
2015-04-07 18:18:37 +00:00
ColorParam param = ColorParam.activityEnd;
if (umlDiagramType == UmlDiagramType.STATE) {
param = ColorParam.stateEnd;
}
return new EntityImageCircleEnd(leaf, skinParam, param);
2013-12-10 19:36:50 +00:00
}
if (leaf.getEntityType() == LeafType.BRANCH || leaf.getEntityType() == LeafType.STATE_CHOICE) {
return new EntityImageBranch(leaf, skinParam);
}
if (leaf.getEntityType() == LeafType.LOLLIPOP) {
return new EntityImageLollipopInterface(leaf, skinParam);
}
2015-04-07 18:18:37 +00:00
if (leaf.getEntityType() == LeafType.DESCRIPTION) {
if (OptionFlags.USE_INTERFACE_EYE1 && leaf.getUSymbol() instanceof USymbolInterface) {
return new EntityImageLollipopInterfaceEye1(leaf, skinParam, bibliotekon);
} else if (OptionFlags.USE_INTERFACE_EYE2 && leaf.getUSymbol() instanceof USymbolInterface) {
return new EntityImageLollipopInterfaceEye2(leaf, skinParam, portionShower);
} else {
2015-07-11 09:32:49 +00:00
return new EntityImageDescription(leaf, skinParam, portionShower);
2015-04-07 18:18:37 +00:00
}
}
if (leaf.getEntityType() == LeafType.USECASE) {
return new EntityImageUseCase(leaf, skinParam);
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
// if (leaf.getEntityType() == LeafType.CIRCLE_INTERFACE) {
// return new EntityImageCircleInterface(leaf, skinParam);
// }
2013-12-10 19:36:50 +00:00
if (leaf.getEntityType() == LeafType.OBJECT) {
2016-11-04 21:39:29 +00:00
return new EntityImageObject(leaf, skinParam, portionShower);
2013-12-10 19:36:50 +00:00
}
if (leaf.getEntityType() == LeafType.SYNCHRO_BAR || leaf.getEntityType() == LeafType.STATE_FORK_JOIN) {
return new EntityImageSynchroBar(leaf, skinParam);
}
if (leaf.getEntityType() == LeafType.ARC_CIRCLE) {
return new EntityImageArcCircle(leaf, skinParam);
}
if (leaf.getEntityType() == LeafType.POINT_FOR_ASSOCIATION) {
return new EntityImageAssociationPoint(leaf, skinParam);
}
if (leaf.isGroup()) {
return new EntityImageGroup(leaf, skinParam);
}
if (leaf.getEntityType() == LeafType.EMPTY_PACKAGE) {
if (leaf.getUSymbol() != null) {
2015-07-11 09:32:49 +00:00
return new EntityImageDescription(leaf, new SkinParamForecolored(skinParam, HtmlColorUtils.BLACK),
2015-04-07 18:18:37 +00:00
portionShower);
2013-12-10 19:36:50 +00:00
}
2016-09-29 19:51:18 +00:00
return new EntityImageEmptyPackage(leaf, skinParam, portionShower);
2013-12-10 19:36:50 +00:00
}
if (leaf.getEntityType() == LeafType.ASSOCIATION) {
return new EntityImageAssociation(leaf, skinParam);
}
if (leaf.getEntityType() == LeafType.PSEUDO_STATE) {
return new EntityImagePseudoState(leaf, skinParam);
}
2015-05-31 18:56:03 +00:00
if (leaf.getEntityType() == LeafType.TIPS) {
2015-06-07 10:23:10 +00:00
return new EntityImageTips(leaf, skinParam, bibliotekon);
2015-05-31 18:56:03 +00:00
}
2013-12-10 19:36:50 +00:00
throw new UnsupportedOperationException(leaf.getEntityType().toString());
}
private Collection<ILeaf> getUnpackagedEntities() {
final List<ILeaf> result = new ArrayList<ILeaf>();
for (ILeaf ent : dotData.getLeafs()) {
if (dotData.getTopParent() == ent.getParentContainer()) {
2011-08-08 17:48:29 +00:00
result.add(ent);
}
}
return result;
}
2016-07-25 19:25:28 +00:00
private void printGroups(DotStringFactory dotStringFactory, IGroup parent) {
2013-12-10 19:36:50 +00:00
for (IGroup g : dotData.getGroupHierarchy().getChildrenGroups(parent)) {
if (g.isRemoved()) {
continue;
}
if (dotData.isEmpty(g) && g.getGroupType() == GroupType.PACKAGE) {
final ILeaf folder = entityFactory.createLeaf(g.getCode(), g.getDisplay(), LeafType.EMPTY_PACKAGE,
2015-04-07 18:18:37 +00:00
g.getParentContainer(), null, dotData.getNamespaceSeparator());
final USymbol symbol = g.getUSymbol();
folder.setUSymbol(symbol);
2016-01-09 12:15:40 +00:00
folder.setStereotype(g.getStereotype());
2017-03-12 17:22:02 +00:00
if (g.getUrl99() != null) {
folder.addUrl(g.getUrl99());
}
2015-09-28 20:42:17 +00:00
if (g.getColors(dotData.getSkinParam()).getColor(ColorType.BACK) == null) {
2015-04-07 18:18:37 +00:00
final ColorParam param = symbol == null ? ColorParam.packageBackground : symbol.getColorParamBack();
final HtmlColor c1 = dotData.getSkinParam().getHtmlColor(param, g.getStereotype(), false);
2015-09-28 20:42:17 +00:00
folder.setSpecificColorTOBEREMOVED(ColorType.BACK, c1 == null ? dotData.getSkinParam()
.getBackgroundColor() : c1);
2013-12-10 19:36:50 +00:00
} else {
2015-09-28 20:42:17 +00:00
folder.setSpecificColorTOBEREMOVED(ColorType.BACK,
g.getColors(dotData.getSkinParam()).getColor(ColorType.BACK));
2013-12-10 19:36:50 +00:00
}
2016-07-25 19:25:28 +00:00
printEntity(dotStringFactory, folder);
2011-08-08 17:48:29 +00:00
} else {
2016-07-25 19:25:28 +00:00
printGroup(dotStringFactory, g);
2011-08-08 17:48:29 +00:00
}
}
}
2016-07-25 19:25:28 +00:00
private void printGroup(DotStringFactory dotStringFactory, IGroup g) {
2013-12-10 19:36:50 +00:00
if (g.getGroupType() == GroupType.CONCURRENT_STATE) {
2011-08-08 17:48:29 +00:00
return;
}
2013-12-10 19:36:50 +00:00
int titleAndAttributeWidth = 0;
int titleAndAttributeHeight = 0;
final TextBlock title = getTitleBlock(g);
final TextBlock stereo = getStereoBlock(g);
final TextBlock stereoAndTitle = TextBlockUtils.mergeTB(stereo, title, HorizontalAlignment.CENTER);
final Dimension2D dimLabel = stereoAndTitle.calculateDimension(stringBounder);
if (dimLabel.getWidth() > 0) {
2015-06-07 10:23:10 +00:00
final List<Member> members = ((IEntity) g).getBodier().getFieldsToDisplay();
2013-12-10 19:36:50 +00:00
final TextBlockWidth attribute;
if (members.size() == 0) {
attribute = new TextBlockEmpty();
} else {
2016-05-11 21:31:47 +00:00
attribute = new MethodsOrFieldsArea(members, FontParam.STATE_ATTRIBUTE, dotData.getSkinParam(),
2016-12-14 21:01:03 +00:00
g.getStereotype(), null);
2013-12-10 19:36:50 +00:00
}
final Dimension2D dimAttribute = attribute.calculateDimension(stringBounder);
final double attributeHeight = dimAttribute.getHeight();
final double attributeWidth = dimAttribute.getWidth();
final double marginForFields = attributeHeight > 0 ? IEntityImage.MARGIN : 0;
2015-04-07 18:18:37 +00:00
final USymbol uSymbol = g.getUSymbol();
final int suppHeightBecauseOfShape = uSymbol == null ? 0 : uSymbol.suppHeightBecauseOfShape();
final int suppWidthBecauseOfShape = uSymbol == null ? 0 : uSymbol.suppWidthBecauseOfShape();
2013-12-10 19:36:50 +00:00
2015-04-07 18:18:37 +00:00
titleAndAttributeWidth = (int) Math.max(dimLabel.getWidth(), attributeWidth) + suppWidthBecauseOfShape;
titleAndAttributeHeight = (int) (dimLabel.getHeight() + attributeHeight + marginForFields + suppHeightBecauseOfShape);
2013-12-10 19:36:50 +00:00
}
dotStringFactory.openCluster(g, titleAndAttributeWidth, titleAndAttributeHeight, title, stereo);
2016-07-25 19:25:28 +00:00
this.printEntities(dotStringFactory, g.getLeafsDirect());
2013-12-10 19:36:50 +00:00
2016-07-25 19:25:28 +00:00
printGroups(dotStringFactory, g);
2011-08-08 17:48:29 +00:00
dotStringFactory.closeCluster();
}
2013-12-10 19:36:50 +00:00
private TextBlock getTitleBlock(IGroup g) {
final Display label = g.getDisplay();
if (label == null) {
return TextBlockUtils.empty(0, 0);
2011-08-08 17:48:29 +00:00
}
2016-01-09 12:15:40 +00:00
final ISkinParam skinParam = dotData.getSkinParam();
final FontConfiguration fontConfiguration = g.getFontConfigurationForTitle(skinParam);
return label.create(fontConfiguration, HorizontalAlignment.CENTER, skinParam);
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
private TextBlock getStereoBlock(IGroup g) {
2016-01-09 12:15:40 +00:00
final Stereotype stereotype = g.getStereotype();
if (stereotype == null) {
2013-12-10 19:36:50 +00:00
return TextBlockUtils.empty(0, 0);
}
2016-01-09 12:15:40 +00:00
if (stereotype.getSprite() != null) {
2016-03-06 16:47:34 +00:00
final Sprite tmp = dotData.getSkinParam().getSprite(stereotype.getSprite());
if (tmp != null) {
2016-04-04 19:05:10 +00:00
return tmp.asTextBlock(stereotype.getHtmlColor(), 1);
2016-03-06 16:47:34 +00:00
}
2016-01-09 12:15:40 +00:00
}
2015-08-05 20:17:01 +00:00
final List<String> stereos = stereotype.getLabels(dotData.getSkinParam().useGuillemet());
2013-12-10 19:36:50 +00:00
if (stereos == null) {
return TextBlockUtils.empty(0, 0);
2011-08-08 17:48:29 +00:00
}
2015-04-07 18:18:37 +00:00
final boolean show = dotData.showPortion(EntityPortion.STEREOTYPE, g);
if (show == false) {
return TextBlockUtils.empty(0, 0);
}
2015-08-05 20:17:01 +00:00
final FontParam fontParam = FontParam.PACKAGE_STEREOTYPE;
2015-09-28 20:42:17 +00:00
return Display.create(stereos).create(new FontConfiguration(dotData.getSkinParam(), fontParam, stereotype),
2015-08-05 20:17:01 +00:00
HorizontalAlignment.CENTER, dotData.getSkinParam());
2011-08-08 17:48:29 +00:00
}
2016-07-25 19:25:28 +00:00
public String getWarningOrError(int warningOrError) {
if (maxX == null) {
return "";
}
final StringBuilder sb = new StringBuilder();
for (Map.Entry<Code, Double> ent : maxX.entrySet()) {
if (ent.getValue() > warningOrError) {
sb.append(ent.getKey() + " is overpassing the width limit.");
sb.append("\n");
}
}
return sb.length() == 0 ? "" : sb.toString();
}
2011-08-08 17:48:29 +00:00
}