1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-25 19:32:35 +00:00

Change leaf style based on stereotype

This commit is contained in:
Benjamin Davies 2023-11-16 13:24:12 +13:00
parent c6bd537509
commit de74e7fae9
No known key found for this signature in database
GPG Key ID: 9FFDE0674336C460
5 changed files with 75 additions and 28 deletions

View File

@ -50,8 +50,8 @@ import net.sourceforge.plantuml.plasma.Quark;
import net.sourceforge.plantuml.regex.IRegex;
import net.sourceforge.plantuml.regex.RegexConcat;
import net.sourceforge.plantuml.regex.RegexLeaf;
import net.sourceforge.plantuml.regex.RegexOptional;
import net.sourceforge.plantuml.regex.RegexResult;
import net.sourceforge.plantuml.stereo.Stereotype;
import net.sourceforge.plantuml.utils.LineLocation;
public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
@ -63,15 +63,11 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
private static IRegex getRegexConcat() {
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
RegexLeaf.spaceZeroOrMore(),
new RegexLeaf("NAME", "([^<>{}-]+)"), //
new RegexOptional(//
new RegexConcat(
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREOTYPE", "(<<.+>>)"))), //
new RegexOptional(//
new RegexConcat( //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("COMPOSITE", "(\\{)"))), //
new RegexLeaf("NAME", "([^<>{}=-]+)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREO", "(<<.*>>)?"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("COMPOSITE", "(\\{)?"), //
RegexLeaf.end());
}
@ -86,10 +82,9 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
final LeafType type = LeafType.CHEN_ATTRIBUTE;
final String name = diagram.cleanId(arg.get("NAME", 0).trim());
final String id = owner.getName() + "/" + name;
final String stereo = arg.get("STEREO", 0);
final boolean composite = arg.get("COMPOSITE", 0) != null;
// TODO: stereotypes: multi, derived, key, partial key
final Quark<Entity> quark = diagram.quarkInContext(true, id);
Entity entity = quark.getData();
@ -100,6 +95,11 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
return CommandExecutionResult.error("Attribute already exists");
}
if (stereo != null) {
entity.setStereotype(Stereotype.build(stereo));
entity.setStereostyle(stereo);
}
final LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity, owner, linkType,
LinkArg.build(Display.NULL, 2));

View File

@ -46,8 +46,8 @@ import net.sourceforge.plantuml.plasma.Quark;
import net.sourceforge.plantuml.regex.IRegex;
import net.sourceforge.plantuml.regex.RegexConcat;
import net.sourceforge.plantuml.regex.RegexLeaf;
import net.sourceforge.plantuml.regex.RegexOptional;
import net.sourceforge.plantuml.regex.RegexResult;
import net.sourceforge.plantuml.stereo.Stereotype;
import net.sourceforge.plantuml.utils.LineLocation;
public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
@ -61,10 +61,8 @@ public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
new RegexLeaf("TYPE", "(entity|relationship)"), //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("NAME", "([^<>{}]+)"), //
new RegexOptional(//
new RegexConcat(
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREOTYPE", "(<<.+>>)"))), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREO", "(<<.+>>)?"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\{"), //
RegexLeaf.end());
@ -75,17 +73,18 @@ public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
throws NoSuchColorException {
LeafType type;
switch (arg.get("TYPE", 0)) {
case "entity":
type = LeafType.CHEN_ENTITY;
break;
case "relationship":
type = LeafType.CHEN_RELATIONSHIP;
break;
default:
throw new IllegalStateException();
case "entity":
type = LeafType.CHEN_ENTITY;
break;
case "relationship":
type = LeafType.CHEN_RELATIONSHIP;
break;
default:
throw new IllegalStateException();
}
final String name = diagram.cleanId(arg.get("NAME", 0).trim());
final String stereo = arg.get("STEREO", 0);
final Quark<Entity> quark = diagram.quarkInContext(true, name);
Entity entity = quark.getData();
@ -98,6 +97,11 @@ public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
return CommandExecutionResult.error("Bad name");
}
if (stereo != null) {
entity.setStereotype(Stereotype.build(stereo));
entity.setStereostyle(stereo);
}
diagram.pushOwner(entity);
return CommandExecutionResult.ok();

View File

@ -67,14 +67,25 @@ public class EntityImageChenAttribute extends AbstractEntityImage {
final static private int MARGIN = 6;
final private boolean isKey;
final private boolean isMulti;
final private boolean isDerived;
final private TextBlock title;
final private Url url;
public EntityImageChenAttribute(Entity entity, ISkinParam skinParam) {
super(entity, skinParam);
final FontConfiguration titleFontConfiguration = getStyleTitle(entity, skinParam)
isKey = hasStereotype("<<key>>");
isMulti = hasStereotype("<<multi>>");
isDerived = hasStereotype("<<derived>>");
FontConfiguration titleFontConfiguration = getStyleTitle(entity, skinParam)
.getFontConfiguration(getSkinParam().getIHtmlColorSet(), entity.getColors());
if (isKey) {
titleFontConfiguration = titleFontConfiguration.underline();
}
title = entity.getDisplay().create8(titleFontConfiguration, HorizontalAlignment.CENTER, skinParam, CreoleMode.FULL,
getStyle().wrapWidth());
@ -82,6 +93,10 @@ public class EntityImageChenAttribute extends AbstractEntityImage {
url = entity.getUrl99();
}
private boolean hasStereotype(String stereotype) {
return getEntity().getStereotype() != null && getEntity().getStereotype().toString().contains(stereotype);
}
private Style getStyle() {
return getStyle(getEntity(), getSkinParam());
}
@ -117,10 +132,17 @@ public class EntityImageChenAttribute extends AbstractEntityImage {
final XDimension2D dimTotal = calculateDimension(ug.getStringBounder());
final XDimension2D dimTitle = title.calculateDimension(ug.getStringBounder());
final UStroke stroke = getStyle().getStroke(getEntity().getColors());
UStroke stroke = getStyle().getStroke(getEntity().getColors());
if (isDerived) {
stroke = new UStroke(10, 10, stroke.getThickness());
}
ug = applyColor(ug);
ug = ug.apply(stroke);
ug.draw(getShape(dimTotal));
if (isMulti) {
ug.apply(new UTranslate(3, 3)).draw(getShape(dimTotal.delta(-6)));
}
final double xTitle = (dimTotal.getWidth() - dimTitle.getWidth()) / 2;
final double yTitle = MARGIN;

View File

@ -63,12 +63,16 @@ import net.sourceforge.plantuml.url.Url;
public class EntityImageChenEntity extends AbstractEntityImage {
final private boolean isWeak;
final private TextBlock title;
final private Url url;
public EntityImageChenEntity(Entity entity, ISkinParam skinParam) {
super(entity, skinParam);
isWeak = hasStereotype("<<weak>>");
final FontConfiguration titleFontConfiguration = getStyleStateTitle(entity, skinParam)
.getFontConfiguration(getSkinParam().getIHtmlColorSet(), entity.getColors());
@ -78,6 +82,10 @@ public class EntityImageChenEntity extends AbstractEntityImage {
url = entity.getUrl99();
}
private boolean hasStereotype(String stereotype) {
return getEntity().getStereotype() != null && getEntity().getStereotype().toString().contains(stereotype);
}
private Style getStyleState() {
return getStyleState(getEntity(), getSkinParam());
}
@ -117,6 +125,9 @@ public class EntityImageChenEntity extends AbstractEntityImage {
ug = applyColor(ug);
ug = ug.apply(stroke);
ug.draw(getShape(dimTotal));
if (isWeak) {
ug.apply(new UTranslate(3, 3)).draw(getShape(dimTotal.delta(-6)));
}
final double xTitle = (dimTotal.getWidth() - dimTitle.getWidth()) / 2;
final double yTitle = MARGIN + MARGIN_LINE;

View File

@ -54,7 +54,6 @@ import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.geom.XPoint2D;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.klimt.shape.TextBlockInEllipse;
import net.sourceforge.plantuml.klimt.shape.UPolygon;
import net.sourceforge.plantuml.style.ISkinParam;
import net.sourceforge.plantuml.style.PName;
@ -67,12 +66,16 @@ import net.sourceforge.plantuml.url.Url;
public class EntityImageChenRelationship extends AbstractEntityImage {
final private boolean isIdentifying;
final private TextBlock title;
final private Url url;
public EntityImageChenRelationship(Entity entity, ISkinParam skinParam) {
super(entity, skinParam);
isIdentifying = hasStereotype("<<identifying>>");
final FontConfiguration titleFontConfiguration = getStyleTitle(entity, skinParam)
.getFontConfiguration(getSkinParam().getIHtmlColorSet(), entity.getColors());
@ -82,6 +85,10 @@ public class EntityImageChenRelationship extends AbstractEntityImage {
url = entity.getUrl99();
}
private boolean hasStereotype(String stereotype) {
return getEntity().getStereotype() != null && getEntity().getStereotype().toString().contains(stereotype);
}
private Style getStyle() {
return getStyle(getEntity(), getSkinParam());
}
@ -126,6 +133,9 @@ public class EntityImageChenRelationship extends AbstractEntityImage {
ug = applyColor(ug);
ug = ug.apply(stroke);
ug.draw(getShape(dimTotal));
if (isIdentifying) {
ug.apply(new UTranslate(10, 5)).draw(getShape(dimTotal.delta(-20, -10)));
}
final double xTitle = (dimTotal.getWidth() - dimTitle.getWidth()) / 2;
final double yTitle = (dimTotal.getHeight() - dimTitle.getHeight()) / 2;