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

122 lines
4.3 KiB
Java
Raw Normal View History

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
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
* Contribution : Hisashi Miyashita
2013-12-10 19:36:50 +00:00
*
*/
package net.sourceforge.plantuml.svek.image;
import java.awt.geom.Point2D;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.SkinParamUtils;
2022-02-10 18:16:18 +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.EntityPosition;
import net.sourceforge.plantuml.cucadiagram.ILeaf;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2022-02-10 18:16:18 +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.Bibliotekon;
import net.sourceforge.plantuml.svek.Cluster;
2021-02-02 10:12:15 +00:00
import net.sourceforge.plantuml.svek.SvekNode;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
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;
2013-12-10 19:36:50 +00:00
public class EntityImageStateBorder extends AbstractEntityImageBorder {
2013-12-10 19:36:50 +00:00
2022-02-10 18:16:18 +00:00
private final SName sname;
public EntityImageStateBorder(ILeaf leaf, ISkinParam skinParam, Cluster stateParent, final Bibliotekon bibliotekon,
SName sname) {
super(leaf, skinParam, stateParent, bibliotekon, FontParam.STATE);
2022-02-10 18:16:18 +00:00
this.sname = sname;
}
2022-03-01 18:11:51 +00:00
private StyleSignatureBasic getSignature() {
return StyleSignatureBasic.of(SName.root, SName.element, sname);
2013-12-10 19:36:50 +00:00
}
private boolean upPosition() {
2022-02-10 18:16:18 +00:00
if (parent == null)
2021-06-27 16:50:40 +00:00
return false;
2022-02-10 18:16:18 +00:00
final Point2D clusterCenter = parent.getClusterPosition().getPointCenter();
2021-02-02 10:12:15 +00:00
final SvekNode node = bibliotekon.getNode(getEntity());
2020-02-18 21:24:31 +00:00
return node.getMinY() < clusterCenter.getY();
2013-12-10 19:36:50 +00:00
}
final public void drawU(UGraphic ug) {
double y = 0;
final Dimension2D dimDesc = desc.calculateDimension(ug.getStringBounder());
2016-04-04 19:05:10 +00:00
final double x = 0 - (dimDesc.getWidth() - 2 * EntityPosition.RADIUS) / 2;
2022-02-10 18:16:18 +00:00
if (upPosition())
2016-04-04 19:05:10 +00:00
y -= 2 * EntityPosition.RADIUS + dimDesc.getHeight();
2022-02-10 18:16:18 +00:00
else
2016-04-04 19:05:10 +00:00
y += 2 * EntityPosition.RADIUS;
2022-02-10 18:16:18 +00:00
2013-12-10 19:36:50 +00:00
desc.drawU(ug.apply(new UTranslate(x, y)));
2021-11-15 18:27:27 +00:00
HColor backcolor = getEntity().getColors().getColor(ColorType.BACK);
2022-02-10 18:16:18 +00:00
final HColor borderColor;
if (UseStyle.useBetaStyle()) {
final Style style = getSignature().getMergedStyle(getSkinParam().getCurrentStyleBuilder());
borderColor = style.value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
if (backcolor == null)
backcolor = style.value(PName.BackGroundColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
} else {
borderColor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.stateBorder);
if (backcolor == null)
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.stateBackground);
2013-12-10 19:36:50 +00:00
}
2022-02-10 18:16:18 +00:00
ug = ug.apply(getUStroke()).apply(borderColor);
2020-04-19 16:04:39 +00:00
ug = ug.apply(backcolor.bg());
2013-12-10 19:36:50 +00:00
2016-04-04 19:05:10 +00:00
entityPosition.drawSymbol(ug, rankdir);
2013-12-10 19:36:50 +00:00
}
2022-02-10 18:16:18 +00:00
private UStroke getUStroke() {
return new UStroke(1.5);
}
2013-12-10 19:36:50 +00:00
}