1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-24 13:57:33 +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.IRegex;
import net.sourceforge.plantuml.regex.RegexConcat; import net.sourceforge.plantuml.regex.RegexConcat;
import net.sourceforge.plantuml.regex.RegexLeaf; import net.sourceforge.plantuml.regex.RegexLeaf;
import net.sourceforge.plantuml.regex.RegexOptional;
import net.sourceforge.plantuml.regex.RegexResult; import net.sourceforge.plantuml.regex.RegexResult;
import net.sourceforge.plantuml.stereo.Stereotype;
import net.sourceforge.plantuml.utils.LineLocation; import net.sourceforge.plantuml.utils.LineLocation;
public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> { public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
@ -63,15 +63,11 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
private static IRegex getRegexConcat() { private static IRegex getRegexConcat() {
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), // return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
RegexLeaf.spaceZeroOrMore(), RegexLeaf.spaceZeroOrMore(),
new RegexLeaf("NAME", "([^<>{}-]+)"), // new RegexLeaf("NAME", "([^<>{}=-]+)"), //
new RegexOptional(// RegexLeaf.spaceZeroOrMore(), //
new RegexConcat( new RegexLeaf("STEREO", "(<<.*>>)?"), //
RegexLeaf.spaceZeroOrMore(), // RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREOTYPE", "(<<.+>>)"))), // new RegexLeaf("COMPOSITE", "(\\{)?"), //
new RegexOptional(//
new RegexConcat( //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("COMPOSITE", "(\\{)"))), //
RegexLeaf.end()); RegexLeaf.end());
} }
@ -86,10 +82,9 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
final LeafType type = LeafType.CHEN_ATTRIBUTE; final LeafType type = LeafType.CHEN_ATTRIBUTE;
final String name = diagram.cleanId(arg.get("NAME", 0).trim()); final String name = diagram.cleanId(arg.get("NAME", 0).trim());
final String id = owner.getName() + "/" + name; final String id = owner.getName() + "/" + name;
final String stereo = arg.get("STEREO", 0);
final boolean composite = arg.get("COMPOSITE", 0) != null; final boolean composite = arg.get("COMPOSITE", 0) != null;
// TODO: stereotypes: multi, derived, key, partial key
final Quark<Entity> quark = diagram.quarkInContext(true, id); final Quark<Entity> quark = diagram.quarkInContext(true, id);
Entity entity = quark.getData(); Entity entity = quark.getData();
@ -100,6 +95,11 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
return CommandExecutionResult.error("Attribute already exists"); 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 LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity, owner, linkType, final Link link = new Link(diagram.getEntityFactory(), diagram.getCurrentStyleBuilder(), entity, owner, linkType,
LinkArg.build(Display.NULL, 2)); 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.IRegex;
import net.sourceforge.plantuml.regex.RegexConcat; import net.sourceforge.plantuml.regex.RegexConcat;
import net.sourceforge.plantuml.regex.RegexLeaf; import net.sourceforge.plantuml.regex.RegexLeaf;
import net.sourceforge.plantuml.regex.RegexOptional;
import net.sourceforge.plantuml.regex.RegexResult; import net.sourceforge.plantuml.regex.RegexResult;
import net.sourceforge.plantuml.stereo.Stereotype;
import net.sourceforge.plantuml.utils.LineLocation; import net.sourceforge.plantuml.utils.LineLocation;
public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> { public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
@ -61,10 +61,8 @@ public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
new RegexLeaf("TYPE", "(entity|relationship)"), // new RegexLeaf("TYPE", "(entity|relationship)"), //
RegexLeaf.spaceOneOrMore(), // RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("NAME", "([^<>{}]+)"), // new RegexLeaf("NAME", "([^<>{}]+)"), //
new RegexOptional(// RegexLeaf.spaceZeroOrMore(), //
new RegexConcat( new RegexLeaf("STEREO", "(<<.+>>)?"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREOTYPE", "(<<.+>>)"))), //
RegexLeaf.spaceZeroOrMore(), // RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\{"), // new RegexLeaf("\\{"), //
RegexLeaf.end()); RegexLeaf.end());
@ -75,17 +73,18 @@ public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
throws NoSuchColorException { throws NoSuchColorException {
LeafType type; LeafType type;
switch (arg.get("TYPE", 0)) { switch (arg.get("TYPE", 0)) {
case "entity": case "entity":
type = LeafType.CHEN_ENTITY; type = LeafType.CHEN_ENTITY;
break; break;
case "relationship": case "relationship":
type = LeafType.CHEN_RELATIONSHIP; type = LeafType.CHEN_RELATIONSHIP;
break; break;
default: default:
throw new IllegalStateException(); throw new IllegalStateException();
} }
final String name = diagram.cleanId(arg.get("NAME", 0).trim()); 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); final Quark<Entity> quark = diagram.quarkInContext(true, name);
Entity entity = quark.getData(); Entity entity = quark.getData();
@ -98,6 +97,11 @@ public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
return CommandExecutionResult.error("Bad name"); return CommandExecutionResult.error("Bad name");
} }
if (stereo != null) {
entity.setStereotype(Stereotype.build(stereo));
entity.setStereostyle(stereo);
}
diagram.pushOwner(entity); diagram.pushOwner(entity);
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();

View File

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

View File

@ -63,12 +63,16 @@ import net.sourceforge.plantuml.url.Url;
public class EntityImageChenEntity extends AbstractEntityImage { public class EntityImageChenEntity extends AbstractEntityImage {
final private boolean isWeak;
final private TextBlock title; final private TextBlock title;
final private Url url; final private Url url;
public EntityImageChenEntity(Entity entity, ISkinParam skinParam) { public EntityImageChenEntity(Entity entity, ISkinParam skinParam) {
super(entity, skinParam); super(entity, skinParam);
isWeak = hasStereotype("<<weak>>");
final FontConfiguration titleFontConfiguration = getStyleStateTitle(entity, skinParam) final FontConfiguration titleFontConfiguration = getStyleStateTitle(entity, skinParam)
.getFontConfiguration(getSkinParam().getIHtmlColorSet(), entity.getColors()); .getFontConfiguration(getSkinParam().getIHtmlColorSet(), entity.getColors());
@ -78,6 +82,10 @@ public class EntityImageChenEntity extends AbstractEntityImage {
url = entity.getUrl99(); url = entity.getUrl99();
} }
private boolean hasStereotype(String stereotype) {
return getEntity().getStereotype() != null && getEntity().getStereotype().toString().contains(stereotype);
}
private Style getStyleState() { private Style getStyleState() {
return getStyleState(getEntity(), getSkinParam()); return getStyleState(getEntity(), getSkinParam());
} }
@ -117,6 +125,9 @@ public class EntityImageChenEntity extends AbstractEntityImage {
ug = applyColor(ug); ug = applyColor(ug);
ug = ug.apply(stroke); ug = ug.apply(stroke);
ug.draw(getShape(dimTotal)); 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 xTitle = (dimTotal.getWidth() - dimTitle.getWidth()) / 2;
final double yTitle = MARGIN + MARGIN_LINE; 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.XDimension2D;
import net.sourceforge.plantuml.klimt.geom.XPoint2D; import net.sourceforge.plantuml.klimt.geom.XPoint2D;
import net.sourceforge.plantuml.klimt.shape.TextBlock; 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.klimt.shape.UPolygon;
import net.sourceforge.plantuml.style.ISkinParam; import net.sourceforge.plantuml.style.ISkinParam;
import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.PName;
@ -67,12 +66,16 @@ import net.sourceforge.plantuml.url.Url;
public class EntityImageChenRelationship extends AbstractEntityImage { public class EntityImageChenRelationship extends AbstractEntityImage {
final private boolean isIdentifying;
final private TextBlock title; final private TextBlock title;
final private Url url; final private Url url;
public EntityImageChenRelationship(Entity entity, ISkinParam skinParam) { public EntityImageChenRelationship(Entity entity, ISkinParam skinParam) {
super(entity, skinParam); super(entity, skinParam);
isIdentifying = hasStereotype("<<identifying>>");
final FontConfiguration titleFontConfiguration = getStyleTitle(entity, skinParam) final FontConfiguration titleFontConfiguration = getStyleTitle(entity, skinParam)
.getFontConfiguration(getSkinParam().getIHtmlColorSet(), entity.getColors()); .getFontConfiguration(getSkinParam().getIHtmlColorSet(), entity.getColors());
@ -82,6 +85,10 @@ public class EntityImageChenRelationship extends AbstractEntityImage {
url = entity.getUrl99(); url = entity.getUrl99();
} }
private boolean hasStereotype(String stereotype) {
return getEntity().getStereotype() != null && getEntity().getStereotype().toString().contains(stereotype);
}
private Style getStyle() { private Style getStyle() {
return getStyle(getEntity(), getSkinParam()); return getStyle(getEntity(), getSkinParam());
} }
@ -126,6 +133,9 @@ public class EntityImageChenRelationship extends AbstractEntityImage {
ug = applyColor(ug); ug = applyColor(ug);
ug = ug.apply(stroke); ug = ug.apply(stroke);
ug.draw(getShape(dimTotal)); 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 xTitle = (dimTotal.getWidth() - dimTitle.getWidth()) / 2;
final double yTitle = (dimTotal.getHeight() - dimTitle.getHeight()) / 2; final double yTitle = (dimTotal.getHeight() - dimTitle.getHeight()) / 2;