1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-22 10:59:01 +00:00

fix: minor issues about multiples stereotype and improve new shapes action and process

https://github.com/plantuml/plantuml/issues/1538
https://github.com/plantuml/plantuml/issues/1631
This commit is contained in:
Arnaud Roques 2024-01-08 21:11:41 +01:00
parent d07cda5f5f
commit 6c73caa943
7 changed files with 95 additions and 30 deletions

View File

@ -108,11 +108,11 @@ public class ActivityDiagram3 extends UmlDiagram {
return swinlanes.nextLinkRenderer();
}
public CommandExecutionResult addActivity(Display activity, BoxStyle style, Url url, Colors colors,
public CommandExecutionResult addActivity(Display activity, BoxStyle boxStyle, Url url, Colors colors,
Stereotype stereotype) {
manageSwimlaneStrategy();
final InstructionSimple ins = new InstructionSimple(activity, nextLinkRenderer(),
swinlanes.getCurrentSwimlane(), style, url, colors, stereotype);
swinlanes.getCurrentSwimlane(), boxStyle, url, colors, stereotype);
final CommandExecutionResult added = current().add(ins);
if (added.isOk() == false)
return added;
@ -396,7 +396,7 @@ public class ActivityDiagram3 extends UmlDiagram {
}
if (current() instanceof InstructionWhile) {
final InstructionWhile instructionWhile = (InstructionWhile) current();
instructionWhile.setBackward(label, swinlanes.getCurrentSwimlane(), boxStyle, incoming1, incoming2);
instructionWhile.setBackward(label, boxStyle, incoming1, incoming2, stereotype);
return CommandExecutionResult.ok();
}
return CommandExecutionResult.error("Cannot find repeat");
@ -406,7 +406,7 @@ public class ActivityDiagram3 extends UmlDiagram {
public void doWhile(Display test, Display yes, HColor color) {
manageSwimlaneStrategy();
final InstructionWhile instructionWhile = new InstructionWhile(swinlanes.getCurrentSwimlane(), current(), test,
nextLinkRenderer(), yes, color, getSkinParam());
nextLinkRenderer(), yes, color, getSkinParam().getCurrentStyleBuilder());
current().add(instructionWhile);
setCurrent(instructionWhile);
}

View File

@ -62,7 +62,7 @@ public class InstructionSimple extends MonoSwimable implements Instruction {
private final Display label;
private final Colors colors;
private final LinkRendering inlinkRendering;
private final BoxStyle style;
private final BoxStyle boxStyle;
private final Url url;
private final Stereotype stereotype;
@ -71,12 +71,12 @@ public class InstructionSimple extends MonoSwimable implements Instruction {
return false;
}
public InstructionSimple(Display label, LinkRendering inlinkRendering, Swimlane swimlane, BoxStyle style, Url url,
Colors colors, Stereotype stereotype) {
public InstructionSimple(Display label, LinkRendering inlinkRendering, Swimlane swimlane, BoxStyle boxStyle,
Url url, Colors colors, Stereotype stereotype) {
super(swimlane);
this.stereotype = stereotype;
this.url = url;
this.style = style;
this.boxStyle = boxStyle;
this.label = label;
this.inlinkRendering = Objects.requireNonNull(inlinkRendering);
this.colors = Objects.requireNonNull(colors);
@ -85,7 +85,7 @@ public class InstructionSimple extends MonoSwimable implements Instruction {
// ::comment when __CORE__
@Override
public Gtile createGtile(ISkinParam skinParam, StringBounder stringBounder) {
GtileBox result = GtileBox.create(stringBounder, colors.mute(skinParam), label, getSwimlaneIn(), style,
GtileBox result = GtileBox.create(stringBounder, colors.mute(skinParam), label, getSwimlaneIn(), boxStyle,
stereotype);
if (hasNotes()) {
final Collection<PositionedNote> notes = getPositionedNotes();
@ -103,7 +103,7 @@ public class InstructionSimple extends MonoSwimable implements Instruction {
@Override
public Ftile createFtile(FtileFactory factory) {
Ftile result = factory.activity(label, getSwimlaneIn(), style, colors, stereotype);
Ftile result = factory.activity(label, getSwimlaneIn(), boxStyle, colors, stereotype);
if (url != null) {
result = factory.addUrl(result, url);
}

View File

@ -55,6 +55,7 @@ import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.geom.VerticalAlignment;
import net.sourceforge.plantuml.sequencediagram.NotePosition;
import net.sourceforge.plantuml.sequencediagram.NoteType;
import net.sourceforge.plantuml.stereo.Stereotype;
import net.sourceforge.plantuml.style.ISkinParam;
import net.sourceforge.plantuml.style.StyleBuilder;
@ -73,13 +74,14 @@ public class InstructionWhile extends WithNote implements Instruction, Instructi
private LinkRendering outColor = LinkRendering.none();
private final Swimlane swimlane;
private final ISkinParam skinParam;
private Instruction specialOut;
private BoxStyle boxStyle;
private Swimlane swimlaneOut;
private Display backward = Display.NULL;
private Stereotype stereotype;
private LinkRendering incoming1 = LinkRendering.none();
private LinkRendering incoming2 = LinkRendering.none();
private boolean backwardCalled;
@ -90,15 +92,14 @@ public class InstructionWhile extends WithNote implements Instruction, Instructi
}
public InstructionWhile(Swimlane swimlane, Instruction parent, Display test, LinkRendering nextLinkRenderer,
Display yes, HColor color, ISkinParam skinParam) {
Display yes, HColor color, StyleBuilder currentStyleBuilder) {
this.parent = parent;
this.test = Objects.requireNonNull(test);
this.nextLinkRenderer = Objects.requireNonNull(nextLinkRenderer);
this.yes = Objects.requireNonNull(yes);
this.swimlane = swimlane;
this.currentStyleBuilder = skinParam.getCurrentStyleBuilder();
this.currentStyleBuilder = currentStyleBuilder;
this.color = color;
this.skinParam = skinParam;
}
@Override
@ -119,9 +120,10 @@ public class InstructionWhile extends WithNote implements Instruction, Instructi
@Override
public Ftile createFtile(FtileFactory factory) {
final Ftile back = Display.isNull(backward) ? null
: factory.activity(backward, swimlane, boxStyle, Colors.empty(), null);
: factory.activity(backward, swimlane, boxStyle, Colors.empty(), stereotype);
Ftile tmp = repeatList.createFtile(factory);
tmp = factory.createWhile(outColor, swimlane, tmp, test, yes, color, specialOut, back, incoming1, incoming2, currentStyleBuilder);
tmp = factory.createWhile(outColor, swimlane, tmp, test, yes, color, specialOut, back, incoming1, incoming2,
currentStyleBuilder);
if (getPositionedNotes().size() > 0)
tmp = FtileWithNoteOpale.create(tmp, getPositionedNotes(), false, VerticalAlignment.CENTER);
@ -194,14 +196,14 @@ public class InstructionWhile extends WithNote implements Instruction, Instructi
return repeatList.containsBreak();
}
public void setBackward(Display label, Swimlane swimlaneOut, BoxStyle boxStyle, LinkRendering incoming1,
LinkRendering incoming2) {
public void setBackward(Display label, BoxStyle boxStyle, LinkRendering incoming1, LinkRendering incoming2,
Stereotype stereotype) {
this.backward = label;
this.swimlaneOut = swimlaneOut;
this.boxStyle = boxStyle;
this.incoming1 = incoming1;
this.incoming2 = incoming2;
this.backwardCalled = true;
this.stereotype = stereotype;
}
public void incoming(LinkRendering incoming) {

View File

@ -160,11 +160,12 @@ public enum BoxStyle {
if (bs.style == style.charAt(0))
return bs;
style = style.replaceAll("\\W", "");
for (BoxStyle bs : BoxStyle.values())
if (style.equalsIgnoreCase(bs.stereotype))
return bs;
for (String s : style.split("\\s")) {
s = s.replaceAll("\\W", "");
for (BoxStyle bs : BoxStyle.values())
if (s.equalsIgnoreCase(bs.stereotype))
return bs;
}
}
return PLAIN;
}

View File

@ -102,12 +102,44 @@ class USymbolAction extends USymbol {
}
};
}
private double getHTitle(XDimension2D dimTitle) {
final double htitle;
if (dimTitle.getWidth() == 0)
htitle = 10;
else
htitle = dimTitle.getHeight();
return htitle;
}
@Override
public TextBlock asBig(final TextBlock title, final HorizontalAlignment labelAlignment, final TextBlock stereotype,
final double width, final double height, final Fashion symbolContext,
final HorizontalAlignment stereoAlignment) {
throw new UnsupportedOperationException();
return new AbstractTextBlock() {
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final XDimension2D dim = calculateDimension(stringBounder);
ug = symbolContext.apply(ug);
final XDimension2D dimTitle = title.calculateDimension(stringBounder);
drawAction(ug, dim.getWidth(), dim.getHeight(), symbolContext.getDeltaShadow(),
symbolContext.getRoundCorner(), symbolContext.getDiagonalCorner());
final double posTitle = (width - dimTitle.getWidth()) / 2;
title.drawU(ug.apply(new UTranslate(posTitle, 2)));
final XDimension2D dimStereo = stereotype.calculateDimension(stringBounder);
final double posStereo = (width - dimStereo.getWidth()) / 2;
stereotype.drawU(ug.apply(new UTranslate(4 + posStereo, 2 + getHTitle(dimTitle))));
}
public XDimension2D calculateDimension(StringBounder stringBounder) {
return new XDimension2D(width, height);
}
};
}
}

View File

@ -64,7 +64,7 @@ class USymbolProcess extends USymbol {
return sname;
}
private void drawAction(UGraphic ug, double width, double height, double shadowing, double roundCorner,
private void drawProcess(UGraphic ug, double width, double height, double shadowing, double roundCorner,
double diagonalCorner) {
final UPolygon shape = new UPolygon();
shape.addPoint(0, 0);
@ -89,7 +89,7 @@ class USymbolProcess extends USymbol {
final XDimension2D dim = calculateDimension(ug.getStringBounder());
ug = UGraphicStencil.create(ug, dim);
ug = symbolContext.apply(ug);
drawAction(ug, dim.getWidth(), dim.getHeight(), symbolContext.getDeltaShadow(),
drawProcess(ug, dim.getWidth(), dim.getHeight(), symbolContext.getDeltaShadow(),
symbolContext.getRoundCorner(), symbolContext.getDiagonalCorner());
final Margin margin = getMargin();
final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, stereoAlignment);
@ -104,11 +104,41 @@ class USymbolProcess extends USymbol {
};
}
private double getHTitle(XDimension2D dimTitle) {
final double htitle;
if (dimTitle.getWidth() == 0)
htitle = 10;
else
htitle = dimTitle.getHeight();
return htitle;
}
@Override
public TextBlock asBig(final TextBlock title, final HorizontalAlignment labelAlignment, final TextBlock stereotype,
final double width, final double height, final Fashion symbolContext,
final HorizontalAlignment stereoAlignment) {
throw new UnsupportedOperationException();
return new AbstractTextBlock() {
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final XDimension2D dim = calculateDimension(stringBounder);
ug = symbolContext.apply(ug);
final XDimension2D dimTitle = title.calculateDimension(stringBounder);
drawProcess(ug, dim.getWidth(), dim.getHeight(), symbolContext.getDeltaShadow(),
symbolContext.getRoundCorner(), symbolContext.getDiagonalCorner());
final double posTitle = (width - dimTitle.getWidth()) / 2;
title.drawU(ug.apply(new UTranslate(posTitle, 2)));
final XDimension2D dimStereo = stereotype.calculateDimension(stringBounder);
final double posStereo = (width - dimStereo.getWidth()) / 2;
stereotype.drawU(ug.apply(new UTranslate(4 + posStereo, 2 + getHTitle(dimTitle))));
}
public XDimension2D calculateDimension(StringBounder stringBounder) {
return new XDimension2D(width, height);
}
};
}
}

View File

@ -72,7 +72,7 @@ public class CommandPackageWithUSymbol extends SingleLineCommand2<AbstractEntity
private static IRegex getRegexConcat() {
return RegexConcat.build(CommandPackageWithUSymbol.class.getName(), RegexLeaf.start(), //
new RegexLeaf("SYMBOL",
"(package|rectangle|hexagon|node|artifact|folder|file|frame|cloud|database|storage|component|card|queue|stack)"), //
"(package|rectangle|hexagon|node|artifact|folder|file|frame|cloud|action|process|database|storage|component|card|queue|stack)"), //
RegexLeaf.spaceOneOrMore(), //
new RegexOr(//
new RegexConcat( //