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

213 lines
7.6 KiB
Java
Raw Normal View History

2015-05-31 18:56:03 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2015-05-31 18:56:03 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2015-05-31 18:56:03 +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
*
2015-05-31 18:56:03 +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
*
*
*/
package net.sourceforge.plantuml.svek.image;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Map;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.Dimension2DDouble;
2017-02-26 16:26:11 +00:00
import net.sourceforge.plantuml.Direction;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
2018-03-09 21:37:34 +00:00
import net.sourceforge.plantuml.LineBreakStrategy;
2021-09-19 17:05:24 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.UseStyle;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.awt.geom.Dimension2D;
2015-06-07 10:23:10 +00:00
import net.sourceforge.plantuml.command.Position;
2020-12-14 18:31:06 +00:00
import net.sourceforge.plantuml.cucadiagram.BodyFactory;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.ILeaf;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.graphic.InnerStrategy;
2015-05-31 18:56:03 +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;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.skin.rose.Rose;
2021-09-19 17:05:24 +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;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.svek.AbstractEntityImage;
import net.sourceforge.plantuml.svek.Bibliotekon;
import net.sourceforge.plantuml.svek.ShapeType;
2021-04-02 17:26:59 +00:00
import net.sourceforge.plantuml.svek.SvekNode;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
2022-02-12 17:27:51 +00:00
import net.sourceforge.plantuml.ugraphic.UStroke;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2015-05-31 18:56:03 +00:00
public class EntityImageTips extends AbstractEntityImage {
final private Rose rose = new Rose();
private final ISkinParam skinParam;
2020-03-18 10:50:02 +00:00
private final HColor noteBackgroundColor;
private final HColor borderColor;
2015-05-31 18:56:03 +00:00
private final Bibliotekon bibliotekon;
2022-02-10 18:16:18 +00:00
private final Style style;
2015-05-31 18:56:03 +00:00
private final double ySpacing = 10;
2021-09-19 17:05:24 +00:00
public EntityImageTips(ILeaf entity, ISkinParam skinParam, Bibliotekon bibliotekon, UmlDiagramType type) {
2015-05-31 18:56:03 +00:00
super(entity, EntityImageNote.getSkin(skinParam, entity));
this.skinParam = skinParam;
this.bibliotekon = bibliotekon;
2021-09-19 17:05:24 +00:00
if (UseStyle.useBetaStyle()) {
2022-02-10 18:16:18 +00:00
style = getDefaultStyleDefinition(type.getStyleName()).getMergedStyle(skinParam.getCurrentStyleBuilder());
2021-09-19 17:05:24 +00:00
2022-02-10 18:16:18 +00:00
if (entity.getColors().getColor(ColorType.BACK) == null)
2021-09-19 17:05:24 +00:00
this.noteBackgroundColor = style.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(),
skinParam.getIHtmlColorSet());
2022-02-10 18:16:18 +00:00
else
2021-11-15 18:27:27 +00:00
this.noteBackgroundColor = entity.getColors().getColor(ColorType.BACK);
2021-09-19 17:05:24 +00:00
this.borderColor = style.value(PName.LineColor).asColor(skinParam.getThemeStyle(),
skinParam.getIHtmlColorSet());
2015-05-31 18:56:03 +00:00
} else {
2022-02-10 18:16:18 +00:00
style = null;
2021-09-19 17:05:24 +00:00
2022-02-10 18:16:18 +00:00
if (entity.getColors().getColor(ColorType.BACK) == null)
2021-09-19 17:05:24 +00:00
this.noteBackgroundColor = rose.getHtmlColor(skinParam, ColorParam.noteBackground);
2022-02-10 18:16:18 +00:00
else
2021-11-15 18:27:27 +00:00
this.noteBackgroundColor = entity.getColors().getColor(ColorType.BACK);
2021-09-19 17:05:24 +00:00
this.borderColor = rose.getHtmlColor(skinParam, ColorParam.noteBorder);
2015-05-31 18:56:03 +00:00
}
2021-09-19 17:05:24 +00:00
}
2022-03-01 18:11:51 +00:00
private StyleSignatureBasic getDefaultStyleDefinition(SName sname) {
return StyleSignatureBasic.of(SName.root, SName.element, sname, SName.note);
2015-05-31 18:56:03 +00:00
}
2015-06-07 10:23:10 +00:00
private Position getPosition() {
2022-02-10 18:16:18 +00:00
if (getEntity().getCodeGetName().endsWith(Position.RIGHT.name()))
2015-06-07 10:23:10 +00:00
return Position.RIGHT;
2022-02-10 18:16:18 +00:00
2015-06-07 10:23:10 +00:00
return Position.LEFT;
}
2015-05-31 18:56:03 +00:00
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
double width = 0;
double height = 0;
for (Map.Entry<String, Display> ent : getEntity().getTips().entrySet()) {
final Display display = ent.getValue();
final Dimension2D dim = getOpale(display).calculateDimension(stringBounder);
height += dim.getHeight();
height += ySpacing;
width = Math.max(width, dim.getWidth());
}
return new Dimension2DDouble(width, height);
}
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final IEntity other = bibliotekon.getOnlyOther(getEntity());
2021-02-02 10:12:15 +00:00
final SvekNode nodeMe = bibliotekon.getNode(getEntity());
final SvekNode nodeOther = bibliotekon.getNode(other);
2020-02-18 21:24:31 +00:00
final Point2D positionMe = nodeMe.getPosition();
2020-11-21 17:33:24 +00:00
if (nodeOther == null) {
System.err.println("Error in EntityImageTips");
return;
}
2020-02-18 21:24:31 +00:00
final Point2D positionOther = nodeOther.getPosition();
bibliotekon.getNode(getEntity());
2015-06-07 10:23:10 +00:00
final Position position = getPosition();
2017-02-26 16:26:11 +00:00
Direction direction = position.reverseDirection();
2015-06-07 10:23:10 +00:00
double height = 0;
2015-05-31 18:56:03 +00:00
for (Map.Entry<String, Display> ent : getEntity().getTips().entrySet()) {
final Display display = ent.getValue();
2020-02-18 21:24:31 +00:00
final Rectangle2D memberPosition = nodeOther.getImage().getInnerPosition(ent.getKey(), stringBounder,
2018-03-09 21:37:34 +00:00
InnerStrategy.STRICT);
2022-02-10 18:16:18 +00:00
if (memberPosition == null)
2016-05-31 19:41:55 +00:00
return;
2022-02-10 18:16:18 +00:00
2015-05-31 18:56:03 +00:00
final Opale opale = getOpale(display);
final Dimension2D dim = opale.calculateDimension(stringBounder);
2015-06-07 10:23:10 +00:00
final Point2D pp1 = new Point2D.Double(0, dim.getHeight() / 2);
double x = positionOther.getX() - positionMe.getX();
2022-02-10 18:16:18 +00:00
if (direction == Direction.RIGHT && x < 0)
2017-02-26 16:26:11 +00:00
direction = direction.getInv();
2022-02-10 18:16:18 +00:00
if (direction == Direction.LEFT)
2015-06-07 10:23:10 +00:00
x += memberPosition.getMaxX();
2022-02-10 18:16:18 +00:00
else
2015-06-07 10:23:10 +00:00
x += 4;
2022-02-10 18:16:18 +00:00
2015-06-07 10:23:10 +00:00
final double y = positionOther.getY() - positionMe.getY() - height + memberPosition.getCenterY();
final Point2D pp2 = new Point2D.Double(x, y);
2017-02-26 16:26:11 +00:00
opale.setOpale(direction, pp1, pp2);
2015-05-31 18:56:03 +00:00
opale.drawU(ug);
2020-03-18 10:50:02 +00:00
ug = ug.apply(UTranslate.dy(dim.getHeight() + ySpacing));
2015-06-07 10:23:10 +00:00
height += dim.getHeight();
height += ySpacing;
2015-05-31 18:56:03 +00:00
}
}
private Opale getOpale(final Display display) {
2022-02-10 18:16:18 +00:00
final FontConfiguration fc;
final double shadowing;
2022-02-12 17:27:51 +00:00
UStroke stroke = new UStroke();
2022-02-10 18:16:18 +00:00
if (UseStyle.useBetaStyle()) {
shadowing = style.value(PName.Shadowing).asDouble();
fc = style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
2022-02-12 17:27:51 +00:00
stroke = style.getStroke();
2022-02-10 18:16:18 +00:00
} else {
shadowing = skinParam.shadowing(getEntity().getStereotype()) ? 4 : 0;
2022-03-19 12:48:23 +00:00
fc = FontConfiguration.create(skinParam, FontParam.NOTE, null);
2022-02-10 18:16:18 +00:00
}
2020-12-14 18:31:06 +00:00
final TextBlock textBlock = BodyFactory.create3(display, FontParam.NOTE, skinParam, HorizontalAlignment.LEFT,
2022-02-12 17:27:51 +00:00
fc, LineBreakStrategy.NONE, style);
return new Opale(shadowing, borderColor, noteBackgroundColor, textBlock, true, stroke);
2015-05-31 18:56:03 +00:00
}
}