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

142 lines
5.2 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;
2022-02-12 17:27:51 +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.cucadiagram.Display;
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;
2022-02-12 17:27:51 +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;
import net.sourceforge.plantuml.svek.ShapeType;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UStroke;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
2022-02-12 17:27:51 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
public class EntityImagePseudoState extends AbstractEntityImage {
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
private static final int SIZE = 22;
2011-08-08 17:48:29 +00:00
private final TextBlock desc;
2022-02-12 17:27:51 +00:00
private final SName sname;
2011-08-08 17:48:29 +00:00
2022-02-12 17:27:51 +00:00
public EntityImagePseudoState(ILeaf entity, ISkinParam skinParam, SName sname) {
this(entity, skinParam, "H", sname);
2020-05-18 20:01:37 +00:00
}
2020-05-30 15:20:23 +00:00
2022-02-12 17:27:51 +00:00
private Style getStyle() {
return getStyleSignature().getMergedStyle(getSkinParam().getCurrentStyleBuilder());
}
2022-03-01 18:11:51 +00:00
private StyleSignatureBasic getStyleSignature() {
return StyleSignatureBasic.of(SName.root, SName.element, sname, SName.diamond);
2022-02-12 17:27:51 +00:00
}
public EntityImagePseudoState(ILeaf entity, ISkinParam skinParam, String historyText, SName sname) {
2011-08-08 17:48:29 +00:00
super(entity, skinParam);
2022-02-12 17:27:51 +00:00
this.sname = sname;
2011-08-08 17:48:29 +00:00
final Stereotype stereotype = entity.getStereotype();
2022-02-12 17:27:51 +00:00
final FontConfiguration fontConfiguration;
if (UseStyle.useBetaStyle())
2022-03-19 12:48:23 +00:00
fontConfiguration = FontConfiguration.create(getSkinParam(), FontParam.STATE, stereotype);
2022-02-12 17:27:51 +00:00
else
2022-03-19 12:48:23 +00:00
fontConfiguration = FontConfiguration.create(getSkinParam(), getStyle());
2022-02-12 17:27:51 +00:00
this.desc = Display.create(historyText).create(fontConfiguration, HorizontalAlignment.CENTER, skinParam);
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
return new Dimension2DDouble(SIZE, SIZE);
}
2013-12-10 19:36:50 +00:00
final public void drawU(UGraphic ug) {
2011-09-07 20:41:58 +00:00
final UEllipse circle = new UEllipse(SIZE, SIZE);
2022-02-12 17:27:51 +00:00
double shadow = 0;
UStroke stroke = new UStroke(1.5);
final HColor backgroundColor;
final HColor borderColor;
if (UseStyle.useBetaStyle()) {
final Style style = getStyle();
borderColor = style.value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
backgroundColor = style.value(PName.BackGroundColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
shadow = style.value(PName.Shadowing).asDouble();
stroke = style.getStroke();
} else {
backgroundColor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.stateBackground);
borderColor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.stateBorder);
if (getSkinParam().shadowing(getEntity().getStereotype()))
shadow = 4;
2011-09-08 10:42:27 +00:00
}
2022-02-12 17:27:51 +00:00
circle.setDeltaShadow(shadow);
ug = ug.apply(stroke);
ug = ug.apply(backgroundColor.bg()).apply(borderColor);
2013-12-10 19:36:50 +00:00
ug.draw(circle);
2022-02-12 17:27:51 +00:00
// ug = ug.apply(new UStroke());
2011-08-08 17:48:29 +00:00
final Dimension2D dimDesc = desc.calculateDimension(ug.getStringBounder());
final double widthDesc = dimDesc.getWidth();
2013-12-10 19:36:50 +00:00
final double heightDesc = dimDesc.getHeight();
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
final double x = (SIZE - widthDesc) / 2;
final double y = (SIZE - heightDesc) / 2;
desc.drawU(ug.apply(new UTranslate(x, y)));
2011-08-08 17:48:29 +00:00
}
public ShapeType getShapeType() {
2013-12-10 19:36:50 +00:00
return ShapeType.CIRCLE;
2011-08-08 17:48:29 +00:00
}
2011-09-08 10:42:27 +00:00
2011-08-08 17:48:29 +00:00
}