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

252 lines
9.7 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 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;
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.ILeaf;
2023-01-09 19:13:37 +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.EntityPortion;
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();
2022-05-21 09:41:00 +00:00
final Style style = StyleSignatureBasic
.of(SName.root, SName.element, SName.classDiagram, SName.class_, SName.header) //
.withTOBECHANGED(stereotype) //
.with(entity.getStereostyles()) //
.getMergedStyle(skinParam.getCurrentStyleBuilder());
2022-05-27 14:18:47 +00:00
FontConfiguration fontConfigurationName = FontConfiguration.create(skinParam, style, entity.getColors());
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
2023-01-09 19:13:37 +00:00
TextBlock name = display.create8(fontConfigurationName, HorizontalAlignment.CENTER, skinParam,
CreoleMode.FULL_BUT_UNDERSCORE, style.wrapWidth());
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(
2022-03-19 12:48:23 +00:00
FontConfiguration.create(getSkinParam(), FontParam.CLASS_STEREOTYPE, stereotype),
2020-06-21 20:31:45 +00:00
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(
2022-03-19 12:48:23 +00:00
FontConfiguration.create(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);
2017-09-03 16:59:24 +00:00
2022-08-17 17:34:24 +00:00
final HColor classBackground = skinParam.getBackgroundColor();
2022-09-18 17:08:06 +00:00
final HColor classBorder = style.value(PName.LineColor).asColor(skinParam.getIHtmlColorSet());
2022-08-17 17:34:24 +00:00
2013-12-10 19:36:50 +00:00
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();
2022-05-21 09:41:00 +00:00
final Style style = spotStyleSignature(leafType).getMergedStyle(skinParam.getCurrentStyleBuilder());
2022-09-18 17:08:06 +00:00
final HColor spotBorder = style.value(PName.LineColor).asColor(skinParam.getIHtmlColorSet());
final HColor spotBackColor = style.value(PName.BackGroundColor).asColor(skinParam.getIHtmlColorSet());
2022-07-29 12:43:01 +00:00
2022-09-18 17:08:06 +00:00
final HColor fontColor = style.value(PName.FontColor).asColor(skinParam.getIHtmlColorSet());
2022-02-01 20:21:45 +00:00
if (stereotype != null && stereotype.getCharacter() != 0)
2013-12-10 19:36:50 +00:00
return new CircledCharacter(stereotype.getCharacter(), getSkinParam().getCircledCharacterRadius(), font,
2022-07-29 12:43:01 +00:00
stereotype.getHtmlColor(), spotBorder, fontColor);
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);
case PROTOCOL:
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotProtocol);
case STRUCT:
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotStruct);
case EXCEPTION:
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotException);
case METACLASS:
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotMetaClass);
case STEREOTYPE:
return StyleSignatureBasic.of(SName.root, SName.element, SName.spot, SName.spotStereotype);
2022-02-01 20:21:45 +00:00
}
throw new IllegalStateException();
}
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';
case PROTOCOL:
return 'P';
case STRUCT:
return 'S';
case EXCEPTION:
return 'X';
case METACLASS:
return 'M';
case STEREOTYPE:
return 'S';
2018-03-09 21:37:34 +00:00
}
assert false;
return '?';
}
2022-09-12 20:08:34 +00:00
public XDimension2D calculateDimension(StringBounder stringBounder) {
2013-12-10 19:36:50 +00:00
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;
}
}