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

145 lines
5.2 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
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
2017-03-15 19:13:31 +00:00
* 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
*
2013-12-10 19:36:50 +00:00
*
*/
package net.sourceforge.plantuml.svek.image;
import java.util.Collections;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ISkinParam;
2022-09-12 20:08:34 +00:00
import net.sourceforge.plantuml.awt.geom.XDimension2D;
2022-11-07 19:27:11 +00:00
import net.sourceforge.plantuml.baraye.IEntity;
2018-11-26 18:46:22 +00:00
import net.sourceforge.plantuml.creole.CreoleMode;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic;
2021-03-07 12:23:24 +00:00
import net.sourceforge.plantuml.ugraphic.UGroupType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate;
2021-04-25 20:59:17 +00:00
public class EntityImageState extends EntityImageStateCommon {
2013-12-10 19:36:50 +00:00
final private TextBlock fields;
final private static int MIN_WIDTH = 50;
final private static int MIN_HEIGHT = 50;
final private boolean withSymbol;
final static private double smallRadius = 3;
final static private double smallLine = 3;
final static private double smallMarginX = 7;
final static private double smallMarginY = 4;
public EntityImageState(IEntity entity, ISkinParam skinParam) {
super(entity, skinParam);
2021-04-25 20:59:17 +00:00
final Stereotype stereotype = entity.getStereotype();
2013-12-10 19:36:50 +00:00
2021-04-25 20:59:17 +00:00
this.withSymbol = stereotype != null && stereotype.isWithOOSymbol();
2020-12-14 18:31:06 +00:00
final Display list = Display.create(entity.getBodier().getRawBody());
2021-09-19 17:05:24 +00:00
2022-09-15 17:24:26 +00:00
final FontConfiguration fieldsFontConfiguration = getStyleStateHeader()
2022-09-18 17:08:06 +00:00
.getFontConfiguration(getSkinParam().getIHtmlColorSet());
2022-09-15 17:24:26 +00:00
this.fields = list.create8(fieldsFontConfiguration, HorizontalAlignment.LEFT, skinParam, CreoleMode.FULL,
2023-01-09 19:13:37 +00:00
getStyleState().wrapWidth());
2013-12-10 19:36:50 +00:00
2021-09-19 17:05:24 +00:00
}
2022-02-12 17:27:51 +00:00
2022-09-12 20:08:34 +00:00
public XDimension2D calculateDimension(StringBounder stringBounder) {
2022-11-04 17:36:03 +00:00
final XDimension2D dim = title.calculateDimension(stringBounder).mergeTB(fields.calculateDimension(stringBounder));
2013-12-10 19:36:50 +00:00
double heightSymbol = 0;
2022-02-12 17:27:51 +00:00
if (withSymbol)
2013-12-10 19:36:50 +00:00
heightSymbol += 2 * smallRadius + smallMarginY;
2022-02-12 17:27:51 +00:00
2022-11-04 17:36:03 +00:00
final XDimension2D result = dim.delta(MARGIN * 2 + 2 * MARGIN_LINE + heightSymbol);
return result.atLeast(MIN_WIDTH, MIN_HEIGHT);
2013-12-10 19:36:50 +00:00
}
final public void drawU(UGraphic ug) {
ug.startGroup(Collections.singletonMap(UGroupType.ID, getEntity().getIdent().toString(".")));
2022-02-12 17:27:51 +00:00
if (url != null)
2013-12-10 19:36:50 +00:00
ug.startUrl(url);
2022-02-12 17:27:51 +00:00
2013-12-10 19:36:50 +00:00
final StringBounder stringBounder = ug.getStringBounder();
2022-09-12 20:08:34 +00:00
final XDimension2D dimTotal = calculateDimension(stringBounder);
2022-09-15 17:24:26 +00:00
final XDimension2D dimDesc = title.calculateDimension(stringBounder);
2013-12-10 19:36:50 +00:00
2022-05-31 16:31:10 +00:00
final UStroke stroke = getStyleState().getStroke(lineConfig.getColors());
2022-02-12 17:27:51 +00:00
2022-05-31 16:31:10 +00:00
ug = applyColor(ug);
2022-02-12 17:27:51 +00:00
ug = ug.apply(stroke);
2021-04-25 20:59:17 +00:00
ug.draw(getShape(dimTotal));
2013-12-10 19:36:50 +00:00
final double yLine = MARGIN + dimDesc.getHeight() + MARGIN_LINE;
2021-04-25 20:59:17 +00:00
ug.apply(UTranslate.dy(yLine)).draw(ULine.hline(dimTotal.getWidth()));
2013-12-10 19:36:50 +00:00
if (withSymbol) {
final double xSymbol = dimTotal.getWidth();
final double ySymbol = dimTotal.getHeight();
drawSymbol(ug, xSymbol, ySymbol);
}
2021-04-25 20:59:17 +00:00
final double xDesc = (dimTotal.getWidth() - dimDesc.getWidth()) / 2;
2013-12-10 19:36:50 +00:00
final double yDesc = MARGIN;
2022-09-15 17:24:26 +00:00
title.drawU(ug.apply(new UTranslate(xDesc, yDesc)));
2013-12-10 19:36:50 +00:00
final double xFields = MARGIN;
final double yFields = yLine + MARGIN_LINE;
fields.drawU(ug.apply(new UTranslate(xFields, yFields)));
2022-02-12 17:27:51 +00:00
if (url != null)
2020-05-17 21:15:50 +00:00
ug.closeUrl();
2022-02-12 17:27:51 +00:00
2020-05-17 21:15:50 +00:00
ug.closeGroup();
2013-12-10 19:36:50 +00:00
}
public static void drawSymbol(UGraphic ug, double xSymbol, double ySymbol) {
xSymbol -= 4 * smallRadius + smallLine + smallMarginX;
ySymbol -= 2 * smallRadius + smallMarginY;
final UEllipse small = new UEllipse(2 * smallRadius, 2 * smallRadius);
ug.apply(new UTranslate(xSymbol, ySymbol)).draw(small);
ug.apply(new UTranslate(xSymbol + smallLine + 2 * smallRadius, ySymbol)).draw(small);
2020-03-18 10:50:02 +00:00
ug.apply(new UTranslate(xSymbol + 2 * smallRadius, ySymbol + smallLine)).draw(ULine.hline(smallLine));
2013-12-10 19:36:50 +00:00
}
}