2013-12-10 19:36:50 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2019-01-16 18:34:41 +00:00
|
|
|
* (C) Copyright 2009-2020, Arnaud Roques
|
2013-12-10 19:36:50 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2013-12-10 19:36:50 +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
|
|
|
|
*
|
2013-12-10 19:36:50 +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
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
* 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
|
|
|
|
* Modified by : Arno Peterson
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.svek.image;
|
|
|
|
|
|
|
|
import java.awt.geom.Dimension2D;
|
2017-05-10 19:51:15 +00:00
|
|
|
import java.util.Collection;
|
2018-05-01 17:26:04 +00:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
|
|
|
import net.sourceforge.plantuml.SkinParamUtils;
|
|
|
|
import net.sourceforge.plantuml.Url;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.BodyEnhanced;
|
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;
|
2018-05-01 17:26:04 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.IEntity;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.ILeaf;
|
2017-05-10 19:51:15 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.Link;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.PortionShower;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.Stereotype;
|
|
|
|
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
|
|
|
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
|
|
|
|
import net.sourceforge.plantuml.graphic.HtmlColor;
|
2018-11-26 18:46:22 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.SkinParameter;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.SymbolContext;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlockUtils;
|
|
|
|
import net.sourceforge.plantuml.graphic.USymbol;
|
2015-07-11 09:32:49 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.USymbolFolder;
|
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;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.AbstractEntityImage;
|
2017-04-05 17:37:42 +00:00
|
|
|
import net.sourceforge.plantuml.svek.Margins;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.ShapeType;
|
2016-07-25 19:25:28 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UComment;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UStroke;
|
2017-04-05 17:37:42 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
|
|
|
import net.sourceforge.plantuml.utils.MathUtils;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2015-07-11 09:32:49 +00:00
|
|
|
public class EntityImageDescription extends AbstractEntityImage {
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
private final ShapeType shapeType;
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
final private Url url;
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
private final TextBlock asSmall;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
private final TextBlock name;
|
2017-04-05 17:37:42 +00:00
|
|
|
private final TextBlock desc;
|
|
|
|
|
|
|
|
private TextBlock stereo;
|
|
|
|
|
|
|
|
private final boolean hideText;
|
2017-05-10 19:51:15 +00:00
|
|
|
private final Collection<Link> links;
|
2017-06-05 11:27:21 +00:00
|
|
|
private final boolean useRankSame;
|
2018-10-21 19:44:14 +00:00
|
|
|
private final boolean fixCircleLabelOverlapping;
|
2015-09-28 20:42:17 +00:00
|
|
|
|
2017-05-10 19:51:15 +00:00
|
|
|
public EntityImageDescription(ILeaf entity, ISkinParam skinParam, PortionShower portionShower,
|
|
|
|
Collection<Link> links) {
|
2015-09-28 20:42:17 +00:00
|
|
|
super(entity, entity.getColors(skinParam).mute(skinParam));
|
2017-06-05 11:27:21 +00:00
|
|
|
this.useRankSame = skinParam.useRankSame();
|
2018-10-21 19:44:14 +00:00
|
|
|
this.fixCircleLabelOverlapping = skinParam.fixCircleLabelOverlapping();
|
2018-01-28 22:08:15 +00:00
|
|
|
|
2017-05-10 19:51:15 +00:00
|
|
|
this.links = links;
|
2013-12-10 19:36:50 +00:00
|
|
|
final Stereotype stereotype = entity.getStereotype();
|
2017-04-05 17:37:42 +00:00
|
|
|
USymbol symbol = getUSymbol(entity);
|
2018-05-06 19:59:19 +00:00
|
|
|
if (symbol == USymbol.FOLDER) {
|
|
|
|
this.shapeType = ShapeType.FOLDER;
|
|
|
|
} else if (symbol == USymbol.INTERFACE) {
|
2018-08-26 12:09:50 +00:00
|
|
|
this.shapeType = skinParam.fixCircleLabelOverlapping() ? ShapeType.RECTANGLE_WITH_CIRCLE_INSIDE
|
|
|
|
: ShapeType.RECTANGLE;
|
2018-05-06 19:59:19 +00:00
|
|
|
} else {
|
|
|
|
this.shapeType = ShapeType.RECTANGLE;
|
|
|
|
}
|
2017-04-05 17:37:42 +00:00
|
|
|
this.hideText = symbol == USymbol.INTERFACE;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2015-07-11 09:32:49 +00:00
|
|
|
final Display codeDisplay = Display.getWithNewlines(entity.getCode());
|
2018-11-26 18:46:22 +00:00
|
|
|
desc = (entity.getDisplay().equals(codeDisplay) && symbol.getSkinParameter() == SkinParameter.PACKAGE)
|
2015-07-11 09:32:49 +00:00
|
|
|
|| entity.getDisplay().isWhite() ? TextBlockUtils.empty(0, 0) : new BodyEnhanced(entity.getDisplay(),
|
2017-02-15 21:34:36 +00:00
|
|
|
symbol.getFontParam(), getSkinParam(), HorizontalAlignment.LEFT, stereotype,
|
2017-03-12 17:22:02 +00:00
|
|
|
symbol.manageHorizontalLine(), false, entity);
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
this.url = entity.getUrl99();
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2017-12-11 21:02:10 +00:00
|
|
|
final Colors colors = entity.getColors(skinParam);
|
|
|
|
HtmlColor backcolor = colors.getColor(ColorType.BACK);
|
2015-04-07 18:18:37 +00:00
|
|
|
if (backcolor == null) {
|
2019-01-16 18:34:41 +00:00
|
|
|
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), symbol.getColorParamBack());
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2017-04-05 17:37:42 +00:00
|
|
|
|
2016-12-21 22:10:29 +00:00
|
|
|
assert getStereo() == stereotype;
|
2019-01-16 18:34:41 +00:00
|
|
|
final HtmlColor forecolor = SkinParamUtils.getColor(getSkinParam(), stereotype, symbol.getColorParamBorder());
|
2016-12-14 21:01:03 +00:00
|
|
|
final double roundCorner = symbol.getSkinParameter().getRoundCorner(getSkinParam(), stereotype);
|
2018-04-06 20:36:30 +00:00
|
|
|
final double diagonalCorner = symbol.getSkinParameter().getDiagonalCorner(getSkinParam(), stereotype);
|
2017-12-11 21:02:10 +00:00
|
|
|
final UStroke stroke = colors.muteStroke(symbol.getSkinParameter().getStroke(getSkinParam(), stereotype));
|
|
|
|
|
2016-12-21 22:10:29 +00:00
|
|
|
final SymbolContext ctx = new SymbolContext(backcolor, forecolor).withStroke(stroke)
|
2018-09-23 12:15:14 +00:00
|
|
|
.withShadow(getSkinParam().shadowing2(getEntity().getStereotype(), symbol.getSkinParameter()))
|
2018-04-06 20:36:30 +00:00
|
|
|
.withCorner(roundCorner, diagonalCorner);
|
2015-04-07 18:18:37 +00:00
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
stereo = TextBlockUtils.empty(0, 0);
|
2015-04-07 18:18:37 +00:00
|
|
|
|
2016-01-09 12:15:40 +00:00
|
|
|
if (stereotype != null && stereotype.getSprite() != null
|
|
|
|
&& getSkinParam().getSprite(stereotype.getSprite()) != null) {
|
|
|
|
symbol = symbol.withStereoAlignment(HorizontalAlignment.RIGHT);
|
2016-04-04 19:05:10 +00:00
|
|
|
stereo = getSkinParam().getSprite(stereotype.getSprite()).asTextBlock(stereotype.getHtmlColor(), 1);
|
2016-01-09 12:15:40 +00:00
|
|
|
} else if (stereotype != null && stereotype.getLabel(false) != null
|
2015-04-07 18:18:37 +00:00
|
|
|
&& portionShower.showPortion(EntityPortion.STEREOTYPE, entity)) {
|
2015-07-11 09:32:49 +00:00
|
|
|
stereo = Display.getWithNewlines(stereotype.getLabel(getSkinParam().useGuillemet())).create(
|
2015-09-28 20:42:17 +00:00
|
|
|
new FontConfiguration(getSkinParam(), symbol.getFontParamStereotype(), stereotype),
|
|
|
|
HorizontalAlignment.CENTER, getSkinParam());
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
name = new BodyEnhanced(codeDisplay, symbol.getFontParam(), getSkinParam(), HorizontalAlignment.CENTER,
|
2017-03-12 17:22:02 +00:00
|
|
|
stereotype, symbol.manageHorizontalLine(), false, entity);
|
2015-07-11 09:32:49 +00:00
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
if (hideText) {
|
|
|
|
asSmall = symbol.asSmall(TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0),
|
|
|
|
TextBlockUtils.empty(0, 0), ctx);
|
|
|
|
} else {
|
|
|
|
asSmall = symbol.asSmall(name, desc, stereo, ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private USymbol getUSymbol(ILeaf entity) {
|
|
|
|
final USymbol result = entity.getUSymbol() == null ? (getSkinParam().useUml2ForComponent() ? USymbol.COMPONENT2
|
|
|
|
: USymbol.COMPONENT1) : entity.getUSymbol();
|
|
|
|
if (result == null) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
return result;
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
public Dimension2D getNameDimension(StringBounder stringBounder) {
|
2017-04-05 17:37:42 +00:00
|
|
|
if (hideText) {
|
|
|
|
return new Dimension2DDouble(0, 0);
|
|
|
|
}
|
2015-09-28 20:42:17 +00:00
|
|
|
return name.calculateDimension(stringBounder);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
2015-04-07 18:18:37 +00:00
|
|
|
return asSmall.calculateDimension(stringBounder);
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
@Override
|
|
|
|
public Margins getShield(StringBounder stringBounder) {
|
2017-12-11 21:02:10 +00:00
|
|
|
if (hideText == false) {
|
|
|
|
return Margins.NONE;
|
|
|
|
}
|
2018-05-01 17:26:04 +00:00
|
|
|
// if (useRankSame && hasSomeHorizontalLink((ILeaf) getEntity(), links)) {
|
|
|
|
// return Margins.NONE;
|
|
|
|
// }
|
|
|
|
if (isThereADoubleLink((ILeaf) getEntity(), links)) {
|
|
|
|
return Margins.NONE;
|
|
|
|
}
|
2018-10-21 19:44:14 +00:00
|
|
|
if (fixCircleLabelOverlapping == false && hasSomeHorizontalLinkVisible((ILeaf) getEntity(), links)) {
|
2017-12-11 21:02:10 +00:00
|
|
|
return Margins.NONE;
|
2017-04-05 17:37:42 +00:00
|
|
|
}
|
2017-12-11 21:02:10 +00:00
|
|
|
if (hasSomeHorizontalLinkDoubleDecorated((ILeaf) getEntity(), links)) {
|
|
|
|
return Margins.NONE;
|
|
|
|
}
|
|
|
|
final Dimension2D dimStereo = stereo.calculateDimension(stringBounder);
|
|
|
|
final Dimension2D dimDesc = desc.calculateDimension(stringBounder);
|
|
|
|
final Dimension2D dimSmall = asSmall.calculateDimension(stringBounder);
|
|
|
|
final double x = Math.max(dimStereo.getWidth(), dimDesc.getWidth());
|
|
|
|
double suppX = x - dimSmall.getWidth();
|
|
|
|
if (suppX < 1) {
|
|
|
|
suppX = 1;
|
|
|
|
}
|
|
|
|
final double y = MathUtils.max(1, dimDesc.getHeight(), dimStereo.getHeight());
|
|
|
|
return new Margins(suppX / 2, suppX / 2, y, y);
|
2017-04-05 17:37:42 +00:00
|
|
|
}
|
2017-06-05 11:27:21 +00:00
|
|
|
|
2018-05-01 17:26:04 +00:00
|
|
|
private boolean hasSomeHorizontalLinkVisible(ILeaf leaf, Collection<Link> links) {
|
2017-05-10 19:51:15 +00:00
|
|
|
for (Link link : links) {
|
2018-05-01 17:26:04 +00:00
|
|
|
if (link.getLength() == 1 && link.contains(leaf) && link.isInvis() == false) {
|
2017-05-10 19:51:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:26:04 +00:00
|
|
|
private boolean isThereADoubleLink(ILeaf leaf, Collection<Link> links) {
|
|
|
|
final Set<IEntity> others = new HashSet<IEntity>();
|
|
|
|
for (Link link : links) {
|
|
|
|
if (link.contains(leaf)) {
|
|
|
|
final IEntity other = link.getOther(leaf);
|
|
|
|
final boolean changed = others.add(other);
|
|
|
|
if (changed == false) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-11 21:02:10 +00:00
|
|
|
private boolean hasSomeHorizontalLinkDoubleDecorated(ILeaf leaf, Collection<Link> links) {
|
|
|
|
for (Link link : links) {
|
|
|
|
if (link.getLength() == 1 && link.contains(leaf) && link.getType().isDoubleDecorated()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
final public void drawU(UGraphic ug) {
|
2016-07-25 19:25:28 +00:00
|
|
|
ug.draw(new UComment("entity " + getEntity().getCode().getFullName()));
|
2013-12-10 19:36:50 +00:00
|
|
|
if (url != null) {
|
|
|
|
ug.startUrl(url);
|
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
asSmall.drawU(ug);
|
2017-04-05 17:37:42 +00:00
|
|
|
if (hideText) {
|
|
|
|
final double space = 8;
|
|
|
|
final Dimension2D dimSmall = asSmall.calculateDimension(ug.getStringBounder());
|
|
|
|
final Dimension2D dimDesc = desc.calculateDimension(ug.getStringBounder());
|
2018-12-22 11:11:40 +00:00
|
|
|
final double posx1 = (dimSmall.getWidth() - dimDesc.getWidth()) / 2;
|
|
|
|
desc.drawU(ug.apply(new UTranslate(posx1, space + dimSmall.getHeight())));
|
2017-04-05 17:37:42 +00:00
|
|
|
final Dimension2D dimStereo = stereo.calculateDimension(ug.getStringBounder());
|
2018-12-22 11:11:40 +00:00
|
|
|
final double posx2 = (dimSmall.getWidth() - dimStereo.getWidth()) / 2;
|
|
|
|
stereo.drawU(ug.apply(new UTranslate(posx2, -space - dimStereo.getHeight())));
|
2017-04-05 17:37:42 +00:00
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
if (url != null) {
|
|
|
|
ug.closeAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ShapeType getShapeType() {
|
2015-09-28 20:42:17 +00:00
|
|
|
return shapeType;
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 11:11:40 +00:00
|
|
|
@Override
|
|
|
|
public double getOverscanX(StringBounder stringBounder) {
|
|
|
|
if (hideText) {
|
|
|
|
final Dimension2D dimSmall = asSmall.calculateDimension(stringBounder);
|
|
|
|
final Dimension2D dimDesc = desc.calculateDimension(stringBounder);
|
|
|
|
final Dimension2D dimStereo = stereo.calculateDimension(stringBounder);
|
|
|
|
final double posx1 = (dimSmall.getWidth() - dimDesc.getWidth()) / 2;
|
|
|
|
final double posx2 = (dimSmall.getWidth() - dimStereo.getWidth()) / 2;
|
|
|
|
return MathUtils.max(-posx1, -posx2, 0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|