1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 23:50:49 +00:00
plantuml/src/net/sourceforge/plantuml/svek/image/EntityImageClassHeader2.java

199 lines
8.9 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, 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;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.SkinParamUtils;
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.HtmlColor;
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;
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;
public class EntityImageClassHeader2 extends AbstractEntityImage {
final private HeaderLayout headerLayout;
public EntityImageClassHeader2(ILeaf entity, ISkinParam skinParam, PortionShower portionShower) {
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
2016-09-29 19:51:18 +00:00
// final HtmlColor color = SkinParamUtils.getFontColor(getSkinParam(), FontParam.CLASS, getStereo());
2013-12-10 19:36:50 +00:00
final Stereotype stereotype = entity.getStereotype();
final String generic = entity.getGeneric();
2015-09-28 20:42:17 +00:00
FontConfiguration fontConfigurationName = new FontConfiguration(getSkinParam(), FontParam.CLASS, stereotype);
2013-12-10 19:36:50 +00:00
if (italic) {
fontConfigurationName = fontConfigurationName.italic();
}
2016-07-25 19:25:28 +00:00
TextBlock name = entity.getDisplay().createWithNiceCreoleMode(fontConfigurationName,
HorizontalAlignment.CENTER, skinParam);
final VisibilityModifier modifier = entity.getVisibilityModifier();
if (modifier == null) {
name = TextBlockUtils.withMargin(name, 3, 3, 0, 0);
} else {
final Rose rose = new Rose();
final HtmlColor back = rose.getHtmlColor(skinParam, modifier.getBackground());
final HtmlColor fore = rose.getHtmlColor(skinParam, modifier.getForeground());
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;
2015-04-07 18:18:37 +00:00
if (stereotype == null || stereotype.getLabel(false) == null
2013-12-10 19:36:50 +00:00
|| portionShower.showPortion(EntityPortion.STEREOTYPE, entity) == false) {
stereo = null;
} else {
2015-07-11 09:32:49 +00:00
stereo = TextBlockUtils.withMargin(
Display.create(stereotype.getLabels(skinParam.useGuillemet())).create(
2015-09-28 20:42:17 +00:00
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);
final HtmlColor classBackground = SkinParamUtils
.getColor(getSkinParam(), ColorParam.background, stereotype);
// final HtmlColor classBorder = getColor(ColorParam.classBorder, stereotype);
final HtmlColor classBorder = SkinParamUtils.getFontColor(getSkinParam(), FontParam.CLASS_STEREOTYPE,
stereotype);
genericBlock = new TextBlockGeneric(genericBlock, classBackground, classBorder);
genericBlock = TextBlockUtils.withMargin(genericBlock, 1, 1);
}
final TextBlock circledCharacter;
if (portionShower.showPortion(EntityPortion.CIRCLED_CHARACTER, (ILeaf) getEntity())) {
circledCharacter = TextBlockUtils.withMargin(getCircledCharacter(entity, skinParam), 4, 0, 5, 5);
} else {
circledCharacter = null;
}
this.headerLayout = new HeaderLayout(circledCharacter, stereo, name, genericBlock);
}
private TextBlock getCircledCharacter(ILeaf entity, ISkinParam skinParam) {
final Stereotype stereotype = entity.getStereotype();
if (stereotype != null && stereotype.getSprite() != null) {
2016-04-04 19:05:10 +00:00
return skinParam.getSprite(stereotype.getSprite()).asTextBlock(stereotype.getHtmlColor(), 1);
2013-12-10 19:36:50 +00:00
}
final UFont font = SkinParamUtils.getFont(getSkinParam(), FontParam.CIRCLED_CHARACTER, null);
final HtmlColor classBorder = SkinParamUtils.getColor(getSkinParam(), ColorParam.classBorder, stereotype);
if (stereotype != null && stereotype.getCharacter() != 0) {
return new CircledCharacter(stereotype.getCharacter(), getSkinParam().getCircledCharacterRadius(), font,
stereotype.getHtmlColor(), classBorder, SkinParamUtils.getFontColor(getSkinParam(),
FontParam.CIRCLED_CHARACTER, null));
}
2017-04-05 17:37:42 +00:00
if (entity.getLeafType() == LeafType.ANNOTATION) {
2013-12-10 19:36:50 +00:00
return new CircledCharacter('@', getSkinParam().getCircledCharacterRadius(), font, SkinParamUtils.getColor(
2016-09-29 19:51:18 +00:00
getSkinParam(), ColorParam.stereotypeNBackground, stereotype), classBorder,
2013-12-10 19:36:50 +00:00
SkinParamUtils.getFontColor(getSkinParam(), FontParam.CIRCLED_CHARACTER, null));
}
2017-04-05 17:37:42 +00:00
if (entity.getLeafType() == LeafType.ABSTRACT_CLASS) {
2013-12-10 19:36:50 +00:00
return new CircledCharacter('A', getSkinParam().getCircledCharacterRadius(), font, SkinParamUtils.getColor(
getSkinParam(), ColorParam.stereotypeABackground, stereotype), classBorder,
SkinParamUtils.getFontColor(getSkinParam(), FontParam.CIRCLED_CHARACTER, null));
}
2017-04-05 17:37:42 +00:00
if (entity.getLeafType() == LeafType.CLASS) {
2013-12-10 19:36:50 +00:00
return new CircledCharacter('C', getSkinParam().getCircledCharacterRadius(), font, SkinParamUtils.getColor(
getSkinParam(), ColorParam.stereotypeCBackground, stereotype), classBorder,
SkinParamUtils.getFontColor(getSkinParam(), FontParam.CIRCLED_CHARACTER, null));
}
2017-04-05 17:37:42 +00:00
if (entity.getLeafType() == LeafType.INTERFACE) {
2013-12-10 19:36:50 +00:00
return new CircledCharacter('I', getSkinParam().getCircledCharacterRadius(), font, SkinParamUtils.getColor(
getSkinParam(), ColorParam.stereotypeIBackground, stereotype), classBorder,
SkinParamUtils.getFontColor(getSkinParam(), FontParam.CIRCLED_CHARACTER, null));
}
2017-04-05 17:37:42 +00:00
if (entity.getLeafType() == LeafType.ENUM) {
2013-12-10 19:36:50 +00:00
return new CircledCharacter('E', getSkinParam().getCircledCharacterRadius(), font, SkinParamUtils.getColor(
getSkinParam(), ColorParam.stereotypeEBackground, stereotype), classBorder,
SkinParamUtils.getFontColor(getSkinParam(), FontParam.CIRCLED_CHARACTER, null));
}
2017-04-05 17:37:42 +00:00
if (entity.getLeafType() == LeafType.ENTITY) {
2017-01-21 22:25:28 +00:00
return new CircledCharacter('E', getSkinParam().getCircledCharacterRadius(), font, SkinParamUtils.getColor(
getSkinParam(), ColorParam.stereotypeCBackground, stereotype), classBorder,
SkinParamUtils.getFontColor(getSkinParam(), FontParam.CIRCLED_CHARACTER, null));
}
2013-12-10 19:36:50 +00:00
assert false;
return null;
}
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;
}
}