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;
|
|
|
|
|
2022-02-17 18:27:32 +00:00
|
|
|
import net.sourceforge.plantuml.awt.geom.Dimension2D;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
import net.sourceforge.plantuml.ColorParam;
|
|
|
|
import net.sourceforge.plantuml.FontParam;
|
2019-03-29 22:14:07 +00:00
|
|
|
import net.sourceforge.plantuml.Guillemet;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
|
|
|
import net.sourceforge.plantuml.SkinParamUtils;
|
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.cucadiagram.Display;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.ILeaf;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.LeafType;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.PortionShower;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Stereotype;
|
|
|
|
import net.sourceforge.plantuml.graphic.CircledCharacter;
|
|
|
|
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.graphic.TextBlockGeneric;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlockUtils;
|
2016-07-25 19:25:28 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.VerticalAlignment;
|
|
|
|
import net.sourceforge.plantuml.skin.VisibilityModifier;
|
|
|
|
import net.sourceforge.plantuml.skin.rose.Rose;
|
2022-02-01 20:21:45 +00:00
|
|
|
import net.sourceforge.plantuml.style.PName;
|
2020-06-21 20:31:45 +00:00
|
|
|
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.HeaderLayout;
|
|
|
|
import net.sourceforge.plantuml.svek.ShapeType;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UFont;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2020-04-19 16:04:39 +00:00
|
|
|
public class EntityImageClassHeader extends AbstractEntityImage {
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
final private HeaderLayout headerLayout;
|
|
|
|
|
2020-04-19 16:04:39 +00:00
|
|
|
public EntityImageClassHeader(ILeaf entity, ISkinParam skinParam, PortionShower portionShower) {
|
2013-12-10 19:36:50 +00:00
|
|
|
super(entity, skinParam);
|
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
final boolean italic = entity.getLeafType() == LeafType.ABSTRACT_CLASS
|
|
|
|
|| entity.getLeafType() == LeafType.INTERFACE;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
final Stereotype stereotype = entity.getStereotype();
|
2017-09-03 16:59:24 +00:00
|
|
|
final boolean displayGenericWithOldFashion = skinParam.displayGenericWithOldFashion();
|
|
|
|
final String generic = displayGenericWithOldFashion ? null : entity.getGeneric();
|
2020-06-21 20:31:45 +00:00
|
|
|
FontConfiguration fontConfigurationName;
|
|
|
|
|
2020-12-01 21:39:27 +00:00
|
|
|
if (UseStyle.useBetaStyle()) {
|
2022-03-01 18:11:51 +00:00
|
|
|
final Style style = StyleSignatureBasic
|
2021-10-17 09:02:33 +00:00
|
|
|
.of(SName.root, SName.element, SName.classDiagram, SName.class_, SName.header) //
|
2022-03-01 18:11:51 +00:00
|
|
|
.withTOBECHANGED(stereotype) //
|
2021-10-17 09:02:33 +00:00
|
|
|
.with(entity.getStereostyles()) //
|
2020-06-21 20:31:45 +00:00
|
|
|
.getMergedStyle(skinParam.getCurrentStyleBuilder());
|
2020-11-21 17:33:24 +00:00
|
|
|
fontConfigurationName = new FontConfiguration(skinParam, style);
|
2020-06-21 20:31:45 +00:00
|
|
|
} else {
|
|
|
|
fontConfigurationName = new FontConfiguration(getSkinParam(), FontParam.CLASS, stereotype);
|
|
|
|
}
|
2022-02-01 20:21:45 +00:00
|
|
|
|
|
|
|
if (italic)
|
2013-12-10 19:36:50 +00:00
|
|
|
fontConfigurationName = fontConfigurationName.italic();
|
2022-02-01 20:21:45 +00:00
|
|
|
|
2017-09-03 16:59:24 +00:00
|
|
|
Display display = entity.getDisplay();
|
2022-02-01 20:21:45 +00:00
|
|
|
if (displayGenericWithOldFashion && entity.getGeneric() != null)
|
2017-09-03 16:59:24 +00:00
|
|
|
display = display.addGeneric(entity.getGeneric());
|
2022-02-01 20:21:45 +00:00
|
|
|
|
2017-09-03 16:59:24 +00:00
|
|
|
TextBlock name = display.createWithNiceCreoleMode(fontConfigurationName, HorizontalAlignment.CENTER, skinParam);
|
2016-07-25 19:25:28 +00:00
|
|
|
final VisibilityModifier modifier = entity.getVisibilityModifier();
|
|
|
|
if (modifier == null) {
|
|
|
|
name = TextBlockUtils.withMargin(name, 3, 3, 0, 0);
|
|
|
|
} else {
|
|
|
|
final Rose rose = new Rose();
|
2020-03-18 10:50:02 +00:00
|
|
|
final HColor back = rose.getHtmlColor(skinParam, modifier.getBackground());
|
|
|
|
final HColor fore = rose.getHtmlColor(skinParam, modifier.getForeground());
|
2016-07-25 19:25:28 +00:00
|
|
|
|
2016-11-18 21:12:09 +00:00
|
|
|
final TextBlock uBlock = modifier.getUBlock(skinParam.classAttributeIconSize(), fore, back, false);
|
2016-07-25 19:25:28 +00:00
|
|
|
name = TextBlockUtils.mergeLR(uBlock, name, VerticalAlignment.CENTER);
|
|
|
|
name = TextBlockUtils.withMargin(name, 3, 3, 0, 0);
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
final TextBlock stereo;
|
2019-03-29 22:14:07 +00:00
|
|
|
if (stereotype == null || stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR) == null
|
2022-02-01 20:21:45 +00:00
|
|
|
|| portionShower.showPortion(EntityPortion.STEREOTYPE, entity) == false)
|
2013-12-10 19:36:50 +00:00
|
|
|
stereo = null;
|
2022-02-01 20:21:45 +00:00
|
|
|
else
|
2020-06-21 20:31:45 +00:00
|
|
|
stereo = TextBlockUtils.withMargin(Display.create(stereotype.getLabels(skinParam.guillemet())).create(
|
|
|
|
new FontConfiguration(getSkinParam(), FontParam.CLASS_STEREOTYPE, stereotype),
|
|
|
|
HorizontalAlignment.CENTER, skinParam), 1, 0);
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
TextBlock genericBlock;
|
|
|
|
if (generic == null) {
|
|
|
|
genericBlock = null;
|
|
|
|
} else {
|
2015-07-11 09:32:49 +00:00
|
|
|
genericBlock = Display.getWithNewlines(generic).create(
|
2015-09-28 20:42:17 +00:00
|
|
|
new FontConfiguration(getSkinParam(), FontParam.CLASS_STEREOTYPE, stereotype),
|
2015-07-11 09:32:49 +00:00
|
|
|
HorizontalAlignment.CENTER, skinParam);
|
2013-12-10 19:36:50 +00:00
|
|
|
genericBlock = TextBlockUtils.withMargin(genericBlock, 1, 1);
|
2020-06-21 20:31:45 +00:00
|
|
|
final HColor classBackground = SkinParamUtils.getColor(getSkinParam(), stereotype, ColorParam.background);
|
2017-09-03 16:59:24 +00:00
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
final HColor classBorder = SkinParamUtils.getFontColor(getSkinParam(), FontParam.CLASS_STEREOTYPE,
|
2013-12-10 19:36:50 +00:00
|
|
|
stereotype);
|
|
|
|
genericBlock = new TextBlockGeneric(genericBlock, classBackground, classBorder);
|
|
|
|
genericBlock = TextBlockUtils.withMargin(genericBlock, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
final TextBlock circledCharacter;
|
2022-02-01 20:21:45 +00:00
|
|
|
if (portionShower.showPortion(EntityPortion.CIRCLED_CHARACTER, (ILeaf) getEntity()))
|
2013-12-10 19:36:50 +00:00
|
|
|
circledCharacter = TextBlockUtils.withMargin(getCircledCharacter(entity, skinParam), 4, 0, 5, 5);
|
2022-02-01 20:21:45 +00:00
|
|
|
else
|
2013-12-10 19:36:50 +00:00
|
|
|
circledCharacter = null;
|
2022-02-01 20:21:45 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
this.headerLayout = new HeaderLayout(circledCharacter, stereo, name, genericBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
private TextBlock getCircledCharacter(ILeaf entity, ISkinParam skinParam) {
|
|
|
|
final Stereotype stereotype = entity.getStereotype();
|
2022-02-01 20:21:45 +00:00
|
|
|
if (stereotype != null && stereotype.getSprite(skinParam) != null)
|
2019-03-01 22:16:29 +00:00
|
|
|
return stereotype.getSprite(skinParam);
|
2022-02-01 20:21:45 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
final UFont font = SkinParamUtils.getFont(getSkinParam(), FontParam.CIRCLED_CHARACTER, null);
|
2022-02-01 20:21:45 +00:00
|
|
|
|
|
|
|
final LeafType leafType = entity.getLeafType();
|
|
|
|
|
|
|
|
final HColor spotBackColor;
|
|
|
|
HColor spotBorder;
|
|
|
|
|
|
|
|
final HColor classBorder;
|
|
|
|
final HColor fontColor;
|
|
|
|
if (UseStyle.useBetaStyle()) {
|
|
|
|
final Style style = spotStyleSignature(leafType).getMergedStyle(skinParam.getCurrentStyleBuilder());
|
|
|
|
spotBorder = style.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
|
|
|
|
spotBackColor = style.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(),
|
|
|
|
skinParam.getIHtmlColorSet());
|
|
|
|
classBorder = SkinParamUtils.getColor(getSkinParam(), stereotype, ColorParam.classBorder);
|
|
|
|
fontColor = style.value(PName.FontColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
|
|
|
|
} else {
|
|
|
|
spotBackColor = SkinParamUtils.getColor(getSkinParam(), stereotype, spotBackground(leafType));
|
|
|
|
spotBorder = SkinParamUtils.getColor(getSkinParam(), stereotype, spotBorder(leafType));
|
|
|
|
classBorder = SkinParamUtils.getColor(getSkinParam(), stereotype, ColorParam.classBorder);
|
|
|
|
fontColor = SkinParamUtils.getFontColor(getSkinParam(), FontParam.CIRCLED_CHARACTER, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stereotype != null && stereotype.getCharacter() != 0)
|
2013-12-10 19:36:50 +00:00
|
|
|
return new CircledCharacter(stereotype.getCharacter(), getSkinParam().getCircledCharacterRadius(), font,
|
2018-03-09 21:37:34 +00:00
|
|
|
stereotype.getHtmlColor(), classBorder, fontColor);
|
2022-02-01 20:21:45 +00:00
|
|
|
|
|
|
|
if (spotBorder == null)
|
2018-03-09 21:37:34 +00:00
|
|
|
spotBorder = classBorder;
|
2022-02-01 20:21:45 +00:00
|
|
|
|
2018-03-09 21:37:34 +00:00
|
|
|
char circledChar = 0;
|
2022-02-01 20:21:45 +00:00
|
|
|
if (stereotype != null)
|
2018-03-09 21:37:34 +00:00
|
|
|
circledChar = getSkinParam().getCircledCharacter(stereotype);
|
2022-02-01 20:21:45 +00:00
|
|
|
|
|
|
|
if (circledChar == 0)
|
2018-03-09 21:37:34 +00:00
|
|
|
circledChar = getCircledChar(leafType);
|
2022-02-01 20:21:45 +00:00
|
|
|
|
2018-03-09 21:37:34 +00:00
|
|
|
return new CircledCharacter(circledChar, getSkinParam().getCircledCharacterRadius(), font, spotBackColor,
|
|
|
|
spotBorder, fontColor);
|
|
|
|
}
|
|
|
|
|
2022-03-01 18:11:51 +00:00
|
|
|
private StyleSignatureBasic spotStyleSignature(LeafType leafType) {
|
2022-02-01 20:21:45 +00:00
|
|
|
switch (leafType) {
|
|
|
|
case ANNOTATION:
|
2022-03-01 18:11:51 +00:00
|
|
|
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotAnnotation);
|
2022-02-01 20:21:45 +00:00
|
|
|
case ABSTRACT_CLASS:
|
2022-03-01 18:11:51 +00:00
|
|
|
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotAbstractClass);
|
2022-02-01 20:21:45 +00:00
|
|
|
case CLASS:
|
2022-03-01 18:11:51 +00:00
|
|
|
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotClass);
|
2022-02-01 20:21:45 +00:00
|
|
|
case INTERFACE:
|
2022-03-01 18:11:51 +00:00
|
|
|
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotInterface);
|
2022-02-01 20:21:45 +00:00
|
|
|
case ENUM:
|
2022-03-01 18:11:51 +00:00
|
|
|
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotEnum);
|
2022-02-01 20:21:45 +00:00
|
|
|
case ENTITY:
|
2022-03-01 18:11:51 +00:00
|
|
|
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotEntity);
|
2022-02-01 20:21:45 +00:00
|
|
|
}
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
|
2018-03-09 21:37:34 +00:00
|
|
|
private ColorParam spotBackground(LeafType leafType) {
|
|
|
|
switch (leafType) {
|
|
|
|
case ANNOTATION:
|
|
|
|
return ColorParam.stereotypeNBackground;
|
|
|
|
case ABSTRACT_CLASS:
|
|
|
|
return ColorParam.stereotypeABackground;
|
|
|
|
case CLASS:
|
|
|
|
return ColorParam.stereotypeCBackground;
|
|
|
|
case INTERFACE:
|
|
|
|
return ColorParam.stereotypeIBackground;
|
|
|
|
case ENUM:
|
|
|
|
return ColorParam.stereotypeEBackground;
|
|
|
|
case ENTITY:
|
|
|
|
return ColorParam.stereotypeCBackground;
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2018-03-09 21:37:34 +00:00
|
|
|
assert false;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ColorParam spotBorder(LeafType leafType) {
|
|
|
|
switch (leafType) {
|
|
|
|
case ANNOTATION:
|
|
|
|
return ColorParam.stereotypeNBorder;
|
|
|
|
case ABSTRACT_CLASS:
|
|
|
|
return ColorParam.stereotypeABorder;
|
|
|
|
case CLASS:
|
|
|
|
return ColorParam.stereotypeCBorder;
|
|
|
|
case INTERFACE:
|
|
|
|
return ColorParam.stereotypeIBorder;
|
|
|
|
case ENUM:
|
|
|
|
return ColorParam.stereotypeEBorder;
|
|
|
|
case ENTITY:
|
|
|
|
return ColorParam.stereotypeCBorder;
|
2017-01-21 22:25:28 +00:00
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
assert false;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-03-09 21:37:34 +00:00
|
|
|
private char getCircledChar(LeafType leafType) {
|
|
|
|
switch (leafType) {
|
|
|
|
case ANNOTATION:
|
|
|
|
return '@';
|
|
|
|
case ABSTRACT_CLASS:
|
|
|
|
return 'A';
|
|
|
|
case CLASS:
|
|
|
|
return 'C';
|
|
|
|
case INTERFACE:
|
|
|
|
return 'I';
|
|
|
|
case ENUM:
|
|
|
|
return 'E';
|
|
|
|
case ENTITY:
|
|
|
|
return 'E';
|
|
|
|
}
|
|
|
|
assert false;
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
return headerLayout.getDimension(stringBounder);
|
|
|
|
}
|
|
|
|
|
|
|
|
final public void drawU(UGraphic ug) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void drawU(UGraphic ug, double width, double height) {
|
|
|
|
headerLayout.drawU(ug, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ShapeType getShapeType() {
|
|
|
|
return ShapeType.RECTANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|