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

173 lines
6.8 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2011-08-08 17:48:29 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://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:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2017-03-15 19:13:31 +00:00
*
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
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.abel.DisplayPositioned;
import net.sourceforge.plantuml.abel.Entity;
import net.sourceforge.plantuml.abel.EntityPortion;
2020-09-19 15:43:24 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.EntityImageLegend;
2016-09-29 19:51:18 +00:00
import net.sourceforge.plantuml.cucadiagram.PortionShower;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.UStroke;
import net.sourceforge.plantuml.klimt.color.ColorType;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.color.Colors;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.color.HColor;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.font.FontParam;
import net.sourceforge.plantuml.klimt.font.StringBounder;
2023-02-26 18:51:17 +00:00
import net.sourceforge.plantuml.klimt.geom.RectangleArea;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.klimt.shape.TextBlockUtils;
import net.sourceforge.plantuml.skin.AlignmentParam;
import net.sourceforge.plantuml.stereo.Stereotype;
import net.sourceforge.plantuml.style.ISkinParam;
2021-03-22 18:00:32 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
2021-03-22 18:00:32 +00:00
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;
import net.sourceforge.plantuml.svek.ClusterDecoration;
import net.sourceforge.plantuml.svek.ShapeType;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.text.Guillemet;
import net.sourceforge.plantuml.url.Url;
2011-08-08 17:48:29 +00:00
2015-08-05 20:17:01 +00:00
public class EntityImageEmptyPackage extends AbstractEntityImage {
2011-08-08 17:48:29 +00:00
2017-03-12 17:22:02 +00:00
private final TextBlock desc;
private final static int MARGIN = 10;
2021-03-22 18:00:32 +00:00
2017-03-12 17:22:02 +00:00
private final Stereotype stereotype;
private final TextBlock stereoBlock;
private final Url url;
2022-02-12 17:27:51 +00:00
private final SName sname;
2021-03-22 18:00:32 +00:00
private final double shadowing;
private final HColor borderColor;
private final UStroke stroke;
private final double roundCorner;
2022-02-24 18:18:19 +00:00
private final double diagonalCorner;
2021-03-22 18:00:32 +00:00
private final HColor back;
private Style getStyle() {
2022-09-15 17:24:26 +00:00
return StyleSignatureBasic.of(SName.root, SName.element, sname, SName.package_, SName.title)
.withTOBECHANGED(stereotype).getMergedStyle(getSkinParam().getCurrentStyleBuilder());
2021-03-22 18:00:32 +00:00
}
2011-08-08 17:48:29 +00:00
2023-02-06 21:04:53 +00:00
public EntityImageEmptyPackage(Entity entity, ISkinParam skinParam, PortionShower portionShower, SName sname) {
2011-08-08 17:48:29 +00:00
super(entity, skinParam);
2022-02-12 17:27:51 +00:00
this.sname = sname;
2021-03-22 18:00:32 +00:00
2021-11-15 18:27:27 +00:00
final Colors colors = entity.getColors();
2021-04-02 17:26:59 +00:00
final HColor specificBackColor = colors.getColor(ColorType.BACK);
2013-12-10 19:36:50 +00:00
this.stereotype = entity.getStereotype();
2017-03-12 17:22:02 +00:00
this.url = entity.getUrl99();
2016-09-29 19:51:18 +00:00
2022-05-21 09:41:00 +00:00
Style style = getStyle();
style = style.eventuallyOverride(colors);
2022-09-18 17:08:06 +00:00
this.borderColor = style.value(PName.LineColor).asColor(getSkinParam().getIHtmlColorSet());
2022-05-21 09:41:00 +00:00
this.shadowing = style.value(PName.Shadowing).asDouble();
this.stroke = style.getStroke(colors);
this.roundCorner = style.value(PName.RoundCorner).asDouble();
this.diagonalCorner = style.value(PName.DiagonalCorner).asDouble();
if (specificBackColor == null)
2022-09-18 17:08:06 +00:00
this.back = style.value(PName.BackGroundColor).asColor(getSkinParam().getIHtmlColorSet());
2022-05-21 09:41:00 +00:00
else
this.back = specificBackColor;
2022-09-18 17:08:06 +00:00
final FontConfiguration titleFontConfiguration = style.getFontConfiguration(getSkinParam().getIHtmlColorSet());
2022-05-21 09:41:00 +00:00
final HorizontalAlignment titleHorizontalAlignment = style.getHorizontalAlignment();
2021-03-22 18:00:32 +00:00
2021-04-02 17:26:59 +00:00
this.desc = entity.getDisplay().create(titleFontConfiguration, titleHorizontalAlignment, skinParam);
2023-02-06 21:04:53 +00:00
final DisplayPositioned legend = ((Entity) entity).getLegend();
2020-09-19 15:43:24 +00:00
if (legend != null) {
final TextBlock legendBlock = EntityImageLegend.create(legend.getDisplay(), skinParam);
stereoBlock = legendBlock;
2016-09-29 19:51:18 +00:00
} else {
2020-09-19 15:43:24 +00:00
if (stereotype == null || stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR) == null
2022-05-21 09:41:00 +00:00
|| portionShower.showPortion(EntityPortion.STEREOTYPE, entity) == false)
2020-09-19 15:43:24 +00:00
stereoBlock = TextBlockUtils.empty(0, 0);
2022-05-21 09:41:00 +00:00
else
2020-09-19 15:43:24 +00:00
stereoBlock = TextBlockUtils.withMargin(Display.create(stereotype.getLabels(skinParam.guillemet()))
2022-03-19 12:48:23 +00:00
.create(FontConfiguration.create(getSkinParam(), FontParam.PACKAGE_STEREOTYPE, stereotype),
2021-04-02 17:26:59 +00:00
titleHorizontalAlignment, skinParam),
2020-09-19 15:43:24 +00:00
1, 0);
2016-09-29 19:51:18 +00:00
}
2011-08-08 17:48:29 +00:00
}
2022-09-12 20:08:34 +00:00
public XDimension2D calculateDimension(StringBounder stringBounder) {
final XDimension2D dimDesc = desc.calculateDimension(stringBounder);
XDimension2D dim = TextBlockUtils.mergeTB(desc, stereoBlock, HorizontalAlignment.LEFT)
.calculateDimension(stringBounder);
2022-11-04 17:36:03 +00:00
dim = dim.atLeast(0, 2 * dimDesc.getHeight());
return dim.delta(MARGIN * 2, MARGIN * 2);
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
final public void drawU(UGraphic ug) {
2022-05-21 09:41:00 +00:00
if (url != null)
2017-03-12 17:22:02 +00:00
ug.startUrl(url);
2011-08-08 17:48:29 +00:00
final StringBounder stringBounder = ug.getStringBounder();
2022-09-12 20:08:34 +00:00
final XDimension2D dimTotal = calculateDimension(stringBounder);
2011-08-08 17:48:29 +00:00
final double widthTotal = dimTotal.getWidth();
final double heightTotal = dimTotal.getHeight();
2023-02-26 18:51:17 +00:00
final RectangleArea rectangleArea = new RectangleArea(0, 0, widthTotal, heightTotal);
2020-06-21 20:31:45 +00:00
final ClusterDecoration decoration = new ClusterDecoration(getSkinParam().packageStyle(), null, desc,
2023-02-26 18:51:17 +00:00
stereoBlock, rectangleArea, stroke);
2016-09-29 19:51:18 +00:00
2021-03-22 18:00:32 +00:00
final HorizontalAlignment horizontalAlignment = getSkinParam()
2021-06-27 16:50:40 +00:00
.getHorizontalAlignment(AlignmentParam.packageTitleAlignment, null, false, null);
2021-03-22 18:00:32 +00:00
final HorizontalAlignment stereotypeAlignment = getSkinParam().getStereotypeAlignment();
2022-02-24 18:18:19 +00:00
decoration.drawU(ug, back, borderColor, shadowing, roundCorner, horizontalAlignment, stereotypeAlignment,
diagonalCorner);
2011-08-08 17:48:29 +00:00
2022-05-21 09:41:00 +00:00
if (url != null)
2020-05-17 21:15:50 +00:00
ug.closeUrl();
2017-03-12 17:22:02 +00:00
2011-08-08 17:48:29 +00:00
}
public ShapeType getShapeType() {
2013-12-10 19:36:50 +00:00
return ShapeType.RECTANGLE;
2011-08-08 17:48:29 +00:00
}
2011-09-08 10:42:27 +00:00
2011-08-08 17:48:29 +00:00
}