plantuml/src/net/sourceforge/plantuml/svek/image/EntityImageActivity.java

192 lines
7.0 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
*
*
*/
2013-12-10 19:36:50 +00:00
package net.sourceforge.plantuml.svek.image;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
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-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.awt.geom.Dimension2D;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.ILeaf;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.FontConfiguration;
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.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.style.StyleSignature;
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;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.svek.Bibliotekon;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.ShapeType;
2021-04-02 17:26:59 +00:00
import net.sourceforge.plantuml.svek.SvekNode;
2011-09-07 20:41:58 +00:00
import net.sourceforge.plantuml.ugraphic.Shadowable;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UStroke;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2011-08-08 17:48:29 +00:00
public class EntityImageActivity extends AbstractEntityImage {
2019-08-26 17:07:21 +00:00
private double shadowing = 0;
2011-08-08 17:48:29 +00:00
public static final int CORNER = 25;
final private TextBlock desc;
final private static int MARGIN = 10;
2013-12-10 19:36:50 +00:00
final private Url url;
2015-04-07 18:18:37 +00:00
private final Bibliotekon bibliotekon;
2011-08-08 17:48:29 +00:00
2015-04-07 18:18:37 +00:00
public EntityImageActivity(ILeaf entity, ISkinParam skinParam, Bibliotekon bibliotekon) {
2011-08-08 17:48:29 +00:00
super(entity, skinParam);
2015-04-07 18:18:37 +00:00
this.bibliotekon = bibliotekon;
2011-08-08 17:48:29 +00:00
final Stereotype stereotype = entity.getStereotype();
2019-08-26 17:07:21 +00:00
final FontConfiguration fontConfiguration;
final HorizontalAlignment horizontalAlignment;
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle()) {
2019-08-26 17:07:21 +00:00
final Style style = getDefaultStyleDefinition().getMergedStyle(getSkinParam().getCurrentStyleBuilder());
2021-05-06 21:23:05 +00:00
fontConfiguration = style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
2019-08-26 17:07:21 +00:00
horizontalAlignment = style.getHorizontalAlignment();
shadowing = style.value(PName.Shadowing).asDouble();
} else {
2022-03-19 12:48:23 +00:00
fontConfiguration = FontConfiguration.create(getSkinParam(), FontParam.ACTIVITY, stereotype);
2019-08-26 17:07:21 +00:00
horizontalAlignment = HorizontalAlignment.CENTER;
if (getSkinParam().shadowing(getEntity().getStereotype())) {
shadowing = 4;
}
}
this.desc = entity.getDisplay().create(fontConfiguration, horizontalAlignment, skinParam);
2013-12-10 19:36:50 +00:00
this.url = entity.getUrl99();
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
public Dimension2D calculateDimension(StringBounder stringBounder) {
2011-08-08 17:48:29 +00:00
final Dimension2D dim = desc.calculateDimension(stringBounder);
return Dimension2DDouble.delta(dim, MARGIN * 2);
}
2013-12-10 19:36:50 +00:00
final public void drawU(UGraphic ug) {
if (url != null) {
ug.startUrl(url);
}
2015-04-07 18:18:37 +00:00
if (getShapeType() == ShapeType.ROUND_RECTANGLE) {
ug = drawNormal(ug);
} else if (getShapeType() == ShapeType.OCTAGON) {
ug = drawOctagon(ug);
} else {
throw new UnsupportedOperationException();
}
if (url != null) {
2020-05-17 21:15:50 +00:00
ug.closeUrl();
2015-04-07 18:18:37 +00:00
}
}
private UGraphic drawOctagon(UGraphic ug) {
2021-02-02 10:12:15 +00:00
final SvekNode node = bibliotekon.getNode(getEntity());
final Shadowable octagon = node.getPolygon();
2020-11-21 17:33:24 +00:00
if (octagon == null) {
return drawNormal(ug);
}
2019-08-26 17:07:21 +00:00
octagon.setDeltaShadow(shadowing);
2015-04-07 18:18:37 +00:00
ug = applyColors(ug);
ug.apply(new UStroke(1.5)).draw(octagon);
desc.drawU(ug.apply(new UTranslate(MARGIN, MARGIN)));
return ug;
}
private UGraphic drawNormal(UGraphic ug) {
2011-08-08 17:48:29 +00:00
final StringBounder stringBounder = ug.getStringBounder();
2013-12-10 19:36:50 +00:00
final Dimension2D dimTotal = calculateDimension(stringBounder);
2011-08-08 17:48:29 +00:00
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(CORNER);
2019-08-26 17:07:21 +00:00
rect.setDeltaShadow(shadowing);
2011-08-08 17:48:29 +00:00
2015-04-07 18:18:37 +00:00
ug = applyColors(ug);
2019-08-26 17:07:21 +00:00
UStroke stroke = new UStroke(1.5);
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle()) {
2019-08-26 17:07:21 +00:00
final Style style = getDefaultStyleDefinition().getMergedStyle(getSkinParam().getCurrentStyleBuilder());
stroke = style.getStroke();
}
ug.apply(stroke).draw(rect);
2015-04-07 18:18:37 +00:00
desc.drawU(ug.apply(new UTranslate(MARGIN, MARGIN)));
return ug;
}
2019-08-26 17:07:21 +00:00
public StyleSignature getDefaultStyleDefinition() {
2022-03-01 18:11:51 +00:00
return StyleSignatureBasic.of(SName.root, SName.element, SName.activityDiagram, SName.activity).withTOBECHANGED(getStereo());
2019-08-26 17:07:21 +00:00
}
2015-04-07 18:18:37 +00:00
private UGraphic applyColors(UGraphic ug) {
2020-03-18 10:50:02 +00:00
HColor borderColor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.activityBorder);
2021-11-15 18:27:27 +00:00
HColor backcolor = getEntity().getColors().getColor(ColorType.BACK);
2011-08-08 17:48:29 +00:00
if (backcolor == null) {
2019-01-16 18:34:41 +00:00
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.activityBackground);
2011-08-08 17:48:29 +00:00
}
2019-08-26 17:07:21 +00:00
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle()) {
2019-08-26 17:07:21 +00:00
final Style style = getDefaultStyleDefinition().getMergedStyle(getSkinParam().getCurrentStyleBuilder());
2021-05-06 21:23:05 +00:00
borderColor = style.value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
2021-11-15 18:27:27 +00:00
backcolor = getEntity().getColors().getColor(ColorType.BACK);
2019-08-26 17:07:21 +00:00
if (backcolor == null) {
2021-05-06 21:23:05 +00:00
backcolor = style.value(PName.BackGroundColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
2019-08-26 17:07:21 +00:00
}
}
2020-04-19 16:04:39 +00:00
ug = ug.apply(borderColor);
ug = ug.apply(backcolor.bg());
2015-04-07 18:18:37 +00:00
return ug;
2011-08-08 17:48:29 +00:00
}
public ShapeType getShapeType() {
2015-04-07 18:18:37 +00:00
final Stereotype stereotype = getStereo();
if (getSkinParam().useOctagonForActivity(stereotype)) {
return ShapeType.OCTAGON;
}
2011-08-08 17:48:29 +00:00
return ShapeType.ROUND_RECTANGLE;
}
2011-09-08 10:42:27 +00:00
2011-08-08 17:48:29 +00:00
}