2013-12-10 19:36:50 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2022-03-07 19:33:46 +00:00
|
|
|
* (C) Copyright 2009-2023, Arnaud Roques
|
2013-12-10 19:36:50 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2022-02-15 18:11:51 +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:
|
2022-02-15 18:11:51 +00:00
|
|
|
*
|
2017-03-15 19:13:31 +00:00
|
|
|
* http://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* http://plantuml.com/paypal
|
2022-02-15 18:11:51 +00:00
|
|
|
*
|
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
|
2022-02-15 18:11:51 +00:00
|
|
|
*
|
2013-12-10 19:36:50 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.svek.image;
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
import java.awt.geom.Rectangle2D;
|
2022-02-15 19:55:21 +00:00
|
|
|
import java.util.EnumMap;
|
2022-02-15 18:11:51 +00:00
|
|
|
import java.util.Map;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
import net.sourceforge.plantuml.ColorParam;
|
2019-01-16 18:34:41 +00:00
|
|
|
import net.sourceforge.plantuml.CornerParam;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
|
|
|
import net.sourceforge.plantuml.FontParam;
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
|
|
|
import net.sourceforge.plantuml.LineConfigurable;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.LineParam;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.SkinParamUtils;
|
|
|
|
import net.sourceforge.plantuml.Url;
|
2020-12-01 21:39:27 +00:00
|
|
|
import net.sourceforge.plantuml.UseStyle;
|
2022-05-04 17:52:00 +00:00
|
|
|
import net.sourceforge.plantuml.awt.geom.Dimension2D;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.creole.Stencil;
|
2015-06-07 10:23:10 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.ILeaf;
|
2019-01-16 18:34:41 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.LeafType;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.PortionShower;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
|
2017-04-05 17:37:42 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.InnerStrategy;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
2015-09-28 20:42:17 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.color.ColorType;
|
2020-06-21 20:31:45 +00:00
|
|
|
import net.sourceforge.plantuml.style.PName;
|
|
|
|
import net.sourceforge.plantuml.style.SName;
|
|
|
|
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.AbstractEntityImage;
|
2017-04-05 17:37:42 +00:00
|
|
|
import net.sourceforge.plantuml.svek.Margins;
|
2016-07-04 19:06:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.Ports;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.ShapeType;
|
2016-07-04 19:06:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.WithPorts;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.Shadowable;
|
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.UGraphicStencil;
|
2021-04-02 17:26:59 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UGroupType;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.URectangle;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UStroke;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
2020-04-19 16:04:39 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColorNone;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2016-07-04 19:06:50 +00:00
|
|
|
public class EntityImageClass extends AbstractEntityImage implements Stencil, WithPorts {
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
final private TextBlock body;
|
2017-04-05 17:37:42 +00:00
|
|
|
final private Margins shield;
|
2020-04-19 16:04:39 +00:00
|
|
|
final private EntityImageClassHeader header;
|
2013-12-10 19:36:50 +00:00
|
|
|
final private Url url;
|
|
|
|
final private double roundCorner;
|
2019-01-16 18:34:41 +00:00
|
|
|
final private LeafType leafType;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
final private LineConfigurable lineConfig;
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
public EntityImageClass(GraphvizVersion version, ILeaf entity, ISkinParam skinParam, PortionShower portionShower) {
|
2021-11-15 18:27:27 +00:00
|
|
|
super(entity, entity.getColors().mute(skinParam));
|
2019-01-16 18:34:41 +00:00
|
|
|
this.leafType = entity.getLeafType();
|
2013-12-10 19:36:50 +00:00
|
|
|
this.lineConfig = entity;
|
2021-10-17 09:02:33 +00:00
|
|
|
if (UseStyle.useBetaStyle())
|
|
|
|
this.roundCorner = getStyle().value(PName.RoundCorner).asDouble();
|
|
|
|
else
|
|
|
|
this.roundCorner = getSkinParam().getRoundCorner(CornerParam.DEFAULT, null);
|
2017-04-05 17:37:42 +00:00
|
|
|
this.shield = version != null && version.useShield() && entity.hasNearDecoration() ? Margins.uniform(16)
|
|
|
|
: Margins.NONE;
|
2015-06-07 10:23:10 +00:00
|
|
|
final boolean showMethods = portionShower.showPortion(EntityPortion.METHOD, entity);
|
|
|
|
final boolean showFields = portionShower.showPortion(EntityPortion.FIELD, entity);
|
2016-07-04 19:06:50 +00:00
|
|
|
this.body = entity.getBodier().getBody(FontParam.CLASS_ATTRIBUTE, getSkinParam(), showMethods, showFields,
|
2021-10-20 16:33:09 +00:00
|
|
|
entity.getStereotype(), getStyle(), null);
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2021-10-17 09:02:33 +00:00
|
|
|
this.header = new EntityImageClassHeader(entity, getSkinParam(), portionShower);
|
2013-12-10 19:36:50 +00:00
|
|
|
this.url = entity.getUrl99();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
|
|
|
|
final Dimension2D dimBody = body == null ? new Dimension2DDouble(0, 0) : body.calculateDimension(stringBounder);
|
|
|
|
double width = Math.max(dimBody.getWidth(), dimHeader.getWidth());
|
2022-02-12 17:27:51 +00:00
|
|
|
if (width < getSkinParam().minClassWidth())
|
2013-12-10 19:36:50 +00:00
|
|
|
width = getSkinParam().minClassWidth();
|
2022-02-12 17:27:51 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
final double height = dimBody.getHeight() + dimHeader.getHeight();
|
|
|
|
return new Dimension2DDouble(width, height);
|
|
|
|
}
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
@Override
|
2017-04-05 17:37:42 +00:00
|
|
|
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
|
|
|
|
final Rectangle2D result = body.getInnerPosition(member, stringBounder, strategy);
|
2022-02-12 17:27:51 +00:00
|
|
|
if (result == null)
|
2015-06-07 10:23:10 +00:00
|
|
|
return result;
|
2022-02-12 17:27:51 +00:00
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
|
2020-03-18 10:50:02 +00:00
|
|
|
final UTranslate translate = UTranslate.dy(dimHeader.getHeight());
|
2015-06-07 10:23:10 +00:00
|
|
|
return translate.apply(result);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
final public void drawU(UGraphic ug) {
|
2019-12-10 21:45:49 +00:00
|
|
|
ug.draw(new UComment("class " + getEntity().getCodeGetName()));
|
2022-02-12 17:27:51 +00:00
|
|
|
if (url != null)
|
2013-12-10 19:36:50 +00:00
|
|
|
ug.startUrl(url);
|
2021-03-14 11:56:57 +00:00
|
|
|
|
2022-02-16 18:59:44 +00:00
|
|
|
final Map<UGroupType, String> typeIDent = new EnumMap<>(UGroupType.class);
|
2022-02-15 18:11:51 +00:00
|
|
|
typeIDent.put(UGroupType.CLASS, "elem " + getEntity().getCode() + " selected");
|
|
|
|
typeIDent.put(UGroupType.ID, "elem_" + getEntity().getCode());
|
|
|
|
ug.startGroup(typeIDent);
|
2013-12-10 19:36:50 +00:00
|
|
|
drawInternal(ug);
|
2021-03-14 11:56:57 +00:00
|
|
|
ug.closeGroup();
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2022-02-12 17:27:51 +00:00
|
|
|
if (url != null)
|
2020-05-17 21:15:50 +00:00
|
|
|
ug.closeUrl();
|
2022-02-12 17:27:51 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 20:31:45 +00:00
|
|
|
private Style getStyle() {
|
2022-03-01 18:11:51 +00:00
|
|
|
return StyleSignatureBasic.of(SName.root, SName.element, SName.classDiagram, SName.class_) //
|
|
|
|
.withTOBECHANGED(getEntity().getStereotype()) //
|
2021-10-17 09:02:33 +00:00
|
|
|
.with(getEntity().getStereostyles()) //
|
|
|
|
.getMergedStyle(getSkinParam().getCurrentStyleBuilder());
|
2020-06-21 20:31:45 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 12:18:33 +00:00
|
|
|
private Style getStyleHeader() {
|
|
|
|
return StyleSignatureBasic.of(SName.root, SName.element, SName.classDiagram, SName.class_, SName.header) //
|
|
|
|
.withTOBECHANGED(getEntity().getStereotype()) //
|
|
|
|
.with(getEntity().getStereostyles()) //
|
|
|
|
.getMergedStyle(getSkinParam().getCurrentStyleBuilder());
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private void drawInternal(UGraphic ug) {
|
|
|
|
final StringBounder stringBounder = ug.getStringBounder();
|
|
|
|
final Dimension2D dimTotal = calculateDimension(stringBounder);
|
|
|
|
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
|
|
|
|
|
|
|
|
final double widthTotal = dimTotal.getWidth();
|
|
|
|
final double heightTotal = dimTotal.getHeight();
|
2020-03-18 10:50:02 +00:00
|
|
|
final Shadowable rect = new URectangle(widthTotal, heightTotal).rounded(roundCorner)
|
2020-08-25 17:24:17 +00:00
|
|
|
.withCommentAndCodeLine(getEntity().getCodeGetName(), getEntity().getCodeLine());
|
2022-02-12 17:27:51 +00:00
|
|
|
|
|
|
|
double shadow = 0;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2021-11-15 18:27:27 +00:00
|
|
|
HColor classBorder = lineConfig.getColors().getColor(ColorType.LINE);
|
|
|
|
HColor headerBackcolor = getEntity().getColors().getColor(ColorType.HEADER);
|
2022-02-12 17:27:51 +00:00
|
|
|
HColor backcolor = getEntity().getColors().getColor(ColorType.BACK);
|
2020-06-21 20:31:45 +00:00
|
|
|
|
2022-02-12 17:27:51 +00:00
|
|
|
if (UseStyle.useBetaStyle()) {
|
|
|
|
shadow = getStyle().value(PName.Shadowing).asDouble();
|
|
|
|
|
|
|
|
if (classBorder == null)
|
2021-05-06 21:23:05 +00:00
|
|
|
classBorder = getStyle().value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
|
|
|
|
getSkinParam().getIHtmlColorSet());
|
2022-02-12 17:27:51 +00:00
|
|
|
|
2022-04-03 12:18:33 +00:00
|
|
|
if (headerBackcolor == null)
|
|
|
|
headerBackcolor = backcolor == null ? getStyleHeader().value(PName.BackGroundColor)
|
|
|
|
.asColor(getSkinParam().getThemeStyle(), getSkinParam().getIHtmlColorSet()) : backcolor;
|
|
|
|
|
2022-02-12 17:27:51 +00:00
|
|
|
if (backcolor == null)
|
2021-05-06 21:23:05 +00:00
|
|
|
backcolor = getStyle().value(PName.BackGroundColor).asColor(getSkinParam().getThemeStyle(),
|
|
|
|
getSkinParam().getIHtmlColorSet());
|
2022-02-12 17:27:51 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
if (getSkinParam().shadowing(getEntity().getStereotype()))
|
|
|
|
shadow = 4;
|
|
|
|
|
|
|
|
if (classBorder == null)
|
|
|
|
classBorder = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.classBorder);
|
|
|
|
|
|
|
|
if (backcolor == null)
|
|
|
|
if (leafType == LeafType.ENUM)
|
2020-06-21 20:31:45 +00:00
|
|
|
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.enumBackground,
|
|
|
|
ColorParam.classBackground);
|
2022-02-12 17:27:51 +00:00
|
|
|
else
|
2020-06-21 20:31:45 +00:00
|
|
|
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.classBackground);
|
2022-02-12 17:27:51 +00:00
|
|
|
|
|
|
|
if (headerBackcolor == null)
|
|
|
|
headerBackcolor = getSkinParam().getHtmlColor(ColorParam.classHeaderBackground, getStereo(), false);
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2020-06-21 20:31:45 +00:00
|
|
|
|
2022-02-12 17:27:51 +00:00
|
|
|
rect.setDeltaShadow(shadow);
|
|
|
|
|
2020-06-21 20:31:45 +00:00
|
|
|
ug = ug.apply(classBorder);
|
2020-04-19 16:04:39 +00:00
|
|
|
ug = ug.apply(backcolor.bg());
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
final UStroke stroke = getStroke();
|
|
|
|
|
2018-03-09 21:37:34 +00:00
|
|
|
UGraphic ugHeader = ug;
|
2020-04-19 16:04:39 +00:00
|
|
|
if (roundCorner == 0 && headerBackcolor != null && backcolor.equals(headerBackcolor) == false) {
|
|
|
|
ug.apply(stroke).draw(rect);
|
|
|
|
final Shadowable rect2 = new URectangle(widthTotal, dimHeader.getHeight());
|
|
|
|
rect2.setDeltaShadow(0);
|
|
|
|
ugHeader = ugHeader.apply(headerBackcolor.bg());
|
|
|
|
ugHeader.apply(stroke).draw(rect2);
|
|
|
|
} else if (roundCorner != 0 && headerBackcolor != null && backcolor.equals(headerBackcolor) == false) {
|
|
|
|
ug.apply(stroke).draw(rect);
|
2020-03-18 10:50:02 +00:00
|
|
|
final Shadowable rect2 = new URectangle(widthTotal, dimHeader.getHeight()).rounded(roundCorner);
|
2020-04-19 16:04:39 +00:00
|
|
|
final URectangle rect3 = new URectangle(widthTotal, roundCorner / 2);
|
|
|
|
rect2.setDeltaShadow(0);
|
|
|
|
rect3.setDeltaShadow(0);
|
|
|
|
ugHeader = ugHeader.apply(headerBackcolor.bg()).apply(headerBackcolor);
|
2018-03-09 21:37:34 +00:00
|
|
|
ugHeader.apply(stroke).draw(rect2);
|
2020-04-19 16:04:39 +00:00
|
|
|
ugHeader.apply(stroke).apply(UTranslate.dy(dimHeader.getHeight() - rect3.getHeight())).draw(rect3);
|
|
|
|
rect.setDeltaShadow(0);
|
|
|
|
ug.apply(stroke).apply(new HColorNone().bg()).draw(rect);
|
|
|
|
} else {
|
|
|
|
ug.apply(stroke).draw(rect);
|
2015-04-20 19:45:13 +00:00
|
|
|
}
|
2018-03-09 21:37:34 +00:00
|
|
|
header.drawU(ugHeader, dimTotal.getWidth(), dimHeader.getHeight());
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
if (body != null) {
|
2016-12-01 20:29:25 +00:00
|
|
|
final UGraphic ug2 = UGraphicStencil.create(ug, this, stroke);
|
2020-03-18 10:50:02 +00:00
|
|
|
final UTranslate translate = UTranslate.dy(dimHeader.getHeight());
|
2015-06-07 10:23:10 +00:00
|
|
|
body.drawU(ug2.apply(translate));
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 21:38:22 +00:00
|
|
|
@Override
|
2016-07-04 19:06:50 +00:00
|
|
|
public Ports getPorts(StringBounder stringBounder) {
|
|
|
|
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
|
2021-06-27 16:50:40 +00:00
|
|
|
if (body instanceof WithPorts)
|
|
|
|
return ((WithPorts) body).getPorts(stringBounder).translateY(dimHeader.getHeight());
|
|
|
|
return new Ports();
|
2016-07-04 19:06:50 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private UStroke getStroke() {
|
2022-02-12 17:27:51 +00:00
|
|
|
|
|
|
|
if (UseStyle.useBetaStyle())
|
|
|
|
return getStyle().getStroke();
|
|
|
|
|
2021-11-15 18:27:27 +00:00
|
|
|
UStroke stroke = lineConfig.getColors().getSpecificLineStroke();
|
2022-02-12 17:27:51 +00:00
|
|
|
if (stroke == null)
|
2015-04-07 18:18:37 +00:00
|
|
|
stroke = getSkinParam().getThickness(LineParam.classBorder, getStereo());
|
2022-02-12 17:27:51 +00:00
|
|
|
|
|
|
|
if (stroke == null)
|
2013-12-10 19:36:50 +00:00
|
|
|
stroke = new UStroke(1.5);
|
2022-02-12 17:27:51 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
return stroke;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ShapeType getShapeType() {
|
2016-12-14 21:01:03 +00:00
|
|
|
if (((ILeaf) getEntity()).getPortShortNames().size() > 0) {
|
2016-07-04 19:06:50 +00:00
|
|
|
return ShapeType.RECTANGLE_HTML_FOR_PORTS;
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
return ShapeType.RECTANGLE;
|
|
|
|
}
|
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
@Override
|
|
|
|
public Margins getShield(StringBounder stringBounder) {
|
2013-12-10 19:36:50 +00:00
|
|
|
return shield;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getStartingX(StringBounder stringBounder, double y) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getEndingX(StringBounder stringBounder, double y) {
|
|
|
|
return calculateDimension(stringBounder).getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|