1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-17 15:42:44 +00:00
plantuml/src/net/sourceforge/plantuml/svek/image/EntityImageClass.java

268 lines
10 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, 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
*
*
*/
package net.sourceforge.plantuml.svek.image;
import java.awt.geom.Dimension2D;
2015-06-07 10:23:10 +00:00
import java.awt.geom.Rectangle2D;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ColorParam;
2019-01-16 18:34:41 +00:00
import net.sourceforge.plantuml.CornerParam;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.LineConfigurable;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.LineParam;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.SkinParamUtils;
import net.sourceforge.plantuml.Url;
2020-12-01 21:39:27 +00:00
import net.sourceforge.plantuml.UseStyle;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.creole.Stencil;
2015-06-07 10:23:10 +00:00
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.ILeaf;
2019-01-16 18:34:41 +00:00
import net.sourceforge.plantuml.cucadiagram.LeafType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.PortionShower;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.graphic.InnerStrategy;
2013-12-10 19:36:50 +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;
2020-06-21 20:31:45 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleSignature;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.AbstractEntityImage;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.svek.Margins;
2016-07-04 19:06:50 +00:00
import net.sourceforge.plantuml.svek.Ports;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.ShapeType;
2016-07-04 19:06:50 +00:00
import net.sourceforge.plantuml.svek.WithPorts;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.Shadowable;
2016-07-25 19:25:28 +00:00
import net.sourceforge.plantuml.ugraphic.UComment;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UGraphicStencil;
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.UGroupType;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2020-04-19 16:04:39 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColorNone;
2013-12-10 19:36:50 +00:00
2016-07-04 19:06:50 +00:00
public class EntityImageClass extends AbstractEntityImage implements Stencil, WithPorts {
2013-12-10 19:36:50 +00:00
final private TextBlock body;
2017-04-05 17:37:42 +00:00
final private Margins shield;
2020-04-19 16:04:39 +00:00
final private EntityImageClassHeader header;
2013-12-10 19:36:50 +00:00
final private Url url;
final private double roundCorner;
2019-01-16 18:34:41 +00:00
final private LeafType leafType;
2013-12-10 19:36:50 +00:00
final private LineConfigurable lineConfig;
2015-04-07 18:18:37 +00:00
public EntityImageClass(GraphvizVersion version, ILeaf entity, ISkinParam skinParam, PortionShower portionShower) {
2015-09-28 20:42:17 +00:00
super(entity, entity.getColors(skinParam).mute(skinParam));
2019-01-16 18:34:41 +00:00
this.leafType = entity.getLeafType();
2013-12-10 19:36:50 +00:00
this.lineConfig = entity;
2018-04-06 20:36:30 +00:00
this.roundCorner = getSkinParam().getRoundCorner(CornerParam.DEFAULT, null);
2017-04-05 17:37:42 +00:00
this.shield = version != null && version.useShield() && entity.hasNearDecoration() ? Margins.uniform(16)
: Margins.NONE;
2015-06-07 10:23:10 +00:00
final boolean showMethods = portionShower.showPortion(EntityPortion.METHOD, entity);
final boolean showFields = portionShower.showPortion(EntityPortion.FIELD, entity);
2016-07-04 19:06:50 +00:00
this.body = entity.getBodier().getBody(FontParam.CLASS_ATTRIBUTE, getSkinParam(), showMethods, showFields,
2020-12-01 21:39:27 +00:00
entity.getStereotype(), getStyle());
2013-12-10 19:36:50 +00:00
2020-04-19 16:04:39 +00:00
header = new EntityImageClassHeader(entity, getSkinParam(), portionShower);
2013-12-10 19:36:50 +00:00
this.url = entity.getUrl99();
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
final Dimension2D dimBody = body == null ? new Dimension2DDouble(0, 0) : body.calculateDimension(stringBounder);
double width = Math.max(dimBody.getWidth(), dimHeader.getWidth());
if (width < getSkinParam().minClassWidth()) {
width = getSkinParam().minClassWidth();
}
final double height = dimBody.getHeight() + dimHeader.getHeight();
return new Dimension2DDouble(width, height);
}
2015-06-07 10:23:10 +00:00
@Override
2017-04-05 17:37:42 +00:00
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
final Rectangle2D result = body.getInnerPosition(member, stringBounder, strategy);
2015-06-07 10:23:10 +00:00
if (result == null) {
return result;
}
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
2020-03-18 10:50:02 +00:00
final UTranslate translate = UTranslate.dy(dimHeader.getHeight());
2015-06-07 10:23:10 +00:00
return translate.apply(result);
}
2013-12-10 19:36:50 +00:00
final public void drawU(UGraphic ug) {
2019-12-10 21:45:49 +00:00
ug.draw(new UComment("class " + getEntity().getCodeGetName()));
2013-12-10 19:36:50 +00:00
if (url != null) {
ug.startUrl(url);
}
ug.startGroup(UGroupType.CLASS, "elem " + getEntity().getCode() + " selected");
2013-12-10 19:36:50 +00:00
drawInternal(ug);
ug.closeGroup();
2013-12-10 19:36:50 +00:00
if (url != null) {
2020-05-17 21:15:50 +00:00
ug.closeUrl();
2013-12-10 19:36:50 +00:00
}
}
2020-06-21 20:31:45 +00:00
private Style getStyle() {
2020-11-21 17:33:24 +00:00
return getDefaultStyleDefinition().with(getEntity().getStereotype())
.getMergedStyle(getSkinParam().getCurrentStyleBuilder());
2020-06-21 20:31:45 +00:00
}
private StyleSignature getDefaultStyleDefinition() {
return StyleSignature.of(SName.root, SName.element, SName.classDiagram, SName.class_);
}
2013-12-10 19:36:50 +00:00
private void drawInternal(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final Dimension2D dimTotal = calculateDimension(stringBounder);
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
final double widthTotal = dimTotal.getWidth();
final double heightTotal = dimTotal.getHeight();
2020-03-18 10:50:02 +00:00
final Shadowable rect = new URectangle(widthTotal, heightTotal).rounded(roundCorner)
2020-08-25 17:24:17 +00:00
.withCommentAndCodeLine(getEntity().getCodeGetName(), getEntity().getCodeLine());
2018-09-23 12:15:14 +00:00
if (getSkinParam().shadowing(getEntity().getStereotype())) {
2013-12-10 19:36:50 +00:00
rect.setDeltaShadow(4);
}
2020-03-18 10:50:02 +00:00
HColor classBorder = lineConfig.getColors(getSkinParam()).getColor(ColorType.LINE);
2020-06-21 20:31:45 +00:00
HColor headerBackcolor = getEntity().getColors(getSkinParam()).getColor(ColorType.HEADER);
2013-12-10 19:36:50 +00:00
if (classBorder == null) {
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle())
2020-06-21 20:31:45 +00:00
classBorder = getStyle().value(PName.LineColor).asColor(getSkinParam().getIHtmlColorSet());
else
classBorder = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.classBorder);
2013-12-10 19:36:50 +00:00
}
2020-03-18 10:50:02 +00:00
HColor backcolor = getEntity().getColors(getSkinParam()).getColor(ColorType.BACK);
2013-12-10 19:36:50 +00:00
if (backcolor == null) {
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle())
2020-06-21 20:31:45 +00:00
backcolor = getStyle().value(PName.BackGroundColor).asColor(getSkinParam().getIHtmlColorSet());
else {
if (leafType == LeafType.ENUM) {
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.enumBackground,
ColorParam.classBackground);
} else {
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.classBackground);
}
2019-01-16 18:34:41 +00:00
}
2013-12-10 19:36:50 +00:00
}
2020-06-21 20:31:45 +00:00
ug = ug.apply(classBorder);
2020-04-19 16:04:39 +00:00
ug = ug.apply(backcolor.bg());
2013-12-10 19:36:50 +00:00
final UStroke stroke = getStroke();
2015-09-28 20:42:17 +00:00
if (headerBackcolor == null) {
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle())
2020-06-21 20:31:45 +00:00
headerBackcolor = getStyle().value(PName.BackGroundColor).asColor(getSkinParam().getIHtmlColorSet());
else
headerBackcolor = getSkinParam().getHtmlColor(ColorParam.classHeaderBackground, getStereo(), false);
2015-09-28 20:42:17 +00:00
}
2018-03-09 21:37:34 +00:00
UGraphic ugHeader = ug;
2020-04-19 16:04:39 +00:00
if (roundCorner == 0 && headerBackcolor != null && backcolor.equals(headerBackcolor) == false) {
ug.apply(stroke).draw(rect);
final Shadowable rect2 = new URectangle(widthTotal, dimHeader.getHeight());
rect2.setDeltaShadow(0);
ugHeader = ugHeader.apply(headerBackcolor.bg());
ugHeader.apply(stroke).draw(rect2);
} else if (roundCorner != 0 && headerBackcolor != null && backcolor.equals(headerBackcolor) == false) {
ug.apply(stroke).draw(rect);
2020-03-18 10:50:02 +00:00
final Shadowable rect2 = new URectangle(widthTotal, dimHeader.getHeight()).rounded(roundCorner);
2020-04-19 16:04:39 +00:00
final URectangle rect3 = new URectangle(widthTotal, roundCorner / 2);
rect2.setDeltaShadow(0);
rect3.setDeltaShadow(0);
ugHeader = ugHeader.apply(headerBackcolor.bg()).apply(headerBackcolor);
2018-03-09 21:37:34 +00:00
ugHeader.apply(stroke).draw(rect2);
2020-04-19 16:04:39 +00:00
ugHeader.apply(stroke).apply(UTranslate.dy(dimHeader.getHeight() - rect3.getHeight())).draw(rect3);
rect.setDeltaShadow(0);
ug.apply(stroke).apply(new HColorNone().bg()).draw(rect);
} else {
ug.apply(stroke).draw(rect);
2015-04-20 19:45:13 +00:00
}
2018-03-09 21:37:34 +00:00
header.drawU(ugHeader, dimTotal.getWidth(), dimHeader.getHeight());
2013-12-10 19:36:50 +00:00
if (body != null) {
2016-12-01 20:29:25 +00:00
final UGraphic ug2 = UGraphicStencil.create(ug, this, stroke);
2020-03-18 10:50:02 +00:00
final UTranslate translate = UTranslate.dy(dimHeader.getHeight());
2015-06-07 10:23:10 +00:00
body.drawU(ug2.apply(translate));
2013-12-10 19:36:50 +00:00
}
}
2016-07-04 19:06:50 +00:00
public Ports getPorts(StringBounder stringBounder) {
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
return ((WithPorts) body).getPorts(stringBounder).translateY(dimHeader.getHeight());
}
2013-12-10 19:36:50 +00:00
private UStroke getStroke() {
2015-09-28 20:42:17 +00:00
UStroke stroke = lineConfig.getColors(getSkinParam()).getSpecificLineStroke();
2015-04-07 18:18:37 +00:00
if (stroke == null) {
stroke = getSkinParam().getThickness(LineParam.classBorder, getStereo());
}
2013-12-10 19:36:50 +00:00
if (stroke == null) {
stroke = new UStroke(1.5);
}
return stroke;
}
public ShapeType getShapeType() {
2016-12-14 21:01:03 +00:00
if (((ILeaf) getEntity()).getPortShortNames().size() > 0) {
2016-07-04 19:06:50 +00:00
return ShapeType.RECTANGLE_HTML_FOR_PORTS;
}
2013-12-10 19:36:50 +00:00
return ShapeType.RECTANGLE;
}
2017-04-05 17:37:42 +00:00
@Override
public Margins getShield(StringBounder stringBounder) {
2013-12-10 19:36:50 +00:00
return shield;
}
public double getStartingX(StringBounder stringBounder, double y) {
return 0;
}
public double getEndingX(StringBounder stringBounder, double y) {
return calculateDimension(stringBounder).getWidth();
}
}