From 6c73caa94375b1ec09920de90ad396777dcf459d Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Mon, 8 Jan 2024 21:11:41 +0100 Subject: [PATCH] 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 --- .../activitydiagram3/ActivityDiagram3.java | 8 ++--- .../activitydiagram3/InstructionSimple.java | 12 +++---- .../activitydiagram3/InstructionWhile.java | 22 ++++++------ .../activitydiagram3/ftile/BoxStyle.java | 11 +++--- .../decoration/symbol/USymbolAction.java | 34 +++++++++++++++++- .../decoration/symbol/USymbolProcess.java | 36 +++++++++++++++++-- .../command/CommandPackageWithUSymbol.java | 2 +- 7 files changed, 95 insertions(+), 30 deletions(-) diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java b/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java index 4378abb42..281e6c6ce 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java @@ -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); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionSimple.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionSimple.java index 901b55ce5..d6886bd0b 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionSimple.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionSimple.java @@ -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 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); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java index 8ec637324..721f882d0 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java @@ -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) { diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/BoxStyle.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/BoxStyle.java index d2e6a70a3..f803285e7 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/BoxStyle.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/BoxStyle.java @@ -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; } diff --git a/src/net/sourceforge/plantuml/decoration/symbol/USymbolAction.java b/src/net/sourceforge/plantuml/decoration/symbol/USymbolAction.java index 3326d96c9..7ee042799 100644 --- a/src/net/sourceforge/plantuml/decoration/symbol/USymbolAction.java +++ b/src/net/sourceforge/plantuml/decoration/symbol/USymbolAction.java @@ -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); + } + }; } } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/decoration/symbol/USymbolProcess.java b/src/net/sourceforge/plantuml/decoration/symbol/USymbolProcess.java index 2c566b9f9..e8bcb9315 100644 --- a/src/net/sourceforge/plantuml/decoration/symbol/USymbolProcess.java +++ b/src/net/sourceforge/plantuml/decoration/symbol/USymbolProcess.java @@ -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); + } + }; } } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/descdiagram/command/CommandPackageWithUSymbol.java b/src/net/sourceforge/plantuml/descdiagram/command/CommandPackageWithUSymbol.java index fbbfa15a9..bbe8fc65c 100644 --- a/src/net/sourceforge/plantuml/descdiagram/command/CommandPackageWithUSymbol.java +++ b/src/net/sourceforge/plantuml/descdiagram/command/CommandPackageWithUSymbol.java @@ -72,7 +72,7 @@ public class CommandPackageWithUSymbol extends SingleLineCommand2