From 85a6b1dada9319ca9b68d48d26e6a802dbad0b4d Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Sat, 22 Jul 2023 11:42:32 +0200 Subject: [PATCH] fix: improve notes on conditional https://forum.plantuml.net/4696/notes-on-conditionnal-elements?show=18077#c18077 --- .../activitydiagram3/InstructionFork.java | 34 ++++---- .../activitydiagram3/InstructionGroup.java | 2 +- .../activitydiagram3/InstructionIf.java | 23 +++-- .../activitydiagram3/InstructionWhile.java | 2 +- .../activitydiagram3/ftile/FtileFactory.java | 2 +- .../ftile/FtileFactoryDelegator.java | 22 ++++- .../activitydiagram3/ftile/FtileGeometry.java | 43 ++++----- .../FtileFactoryDelegatorAddNote.java | 5 +- .../FtileFactoryDelegatorCreateGroup.java | 2 +- .../vcompact/FtileFactoryDelegatorIf.java | 6 +- .../ftile/vcompact/FtileIfDown.java | 56 ++++++++++-- .../ftile/vcompact/FtileWithNoteOpale.java | 23 +++-- .../ftile/vcompact/FtileWithNotes.java | 13 ++- .../ftile/vcompact/VCompactFactory.java | 2 +- .../vcompact/cond/ConditionalBuilder.java | 25 ++++-- .../vcompact/cond/FtileDimensionMemoize.java | 10 ++- .../ftile/vcompact/cond/FtileIfNude.java | 45 +++++----- .../vcompact/cond/FtileIfWithDiamonds.java | 87 +++++++++++++++++-- .../ftile/vcompact/cond/FtileIfWithLinks.java | 22 ++--- .../ftile/vcompact/cond/FtileSwitchNude.java | 2 +- .../plantuml/klimt/shape/TextBlockUtils.java | 4 +- .../plantuml/syntax/LanguageDescriptor.java | 1 + .../sourceforge/plantuml/version/Version.java | 2 +- 23 files changed, 284 insertions(+), 149 deletions(-) diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionFork.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionFork.java index 0360e926b..861881a1f 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionFork.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionFork.java @@ -72,11 +72,10 @@ public class InstructionFork extends WithNote implements Instruction { @Override public boolean containsBreak() { - for (InstructionList fork : forks) { - if (fork.containsBreak()) { + for (InstructionList fork : forks) + if (fork.containsBreak()) return true; - } - } + return false; } @@ -122,14 +121,13 @@ public class InstructionFork extends WithNote implements Instruction { @Override public Ftile createFtile(FtileFactory factory) { final List all = new ArrayList<>(); - for (InstructionList list : forks) { + for (InstructionList list : forks) all.add(list.createFtile(factory)); - } + Ftile result = factory.createParallel(all, style, label, swimlaneIn, swimlaneOut); - if (getPositionedNotes().size() > 0) { - result = FtileWithNoteOpale.create(result, getPositionedNotes(), skinParam, false, - VerticalAlignment.CENTER); - } + if (getPositionedNotes().size() > 0) + result = FtileWithNoteOpale.create(result, getPositionedNotes(), false, VerticalAlignment.CENTER); + return result; } @@ -154,12 +152,12 @@ public class InstructionFork extends WithNote implements Instruction { @Override public boolean addNote(Display note, NotePosition position, NoteType type, Colors colors, Swimlane swimlaneNote) { - if (finished) { + if (finished) return super.addNote(note, position, type, colors, swimlaneNote); - } - if (getLastList().getLast() == null) { + + if (getLastList().getLast() == null) return getLastList().addNote(note, position, type, colors, swimlaneNote); - } + return getLastList().addNote(note, position, type, colors, swimlaneNote); } @@ -182,12 +180,12 @@ public class InstructionFork extends WithNote implements Instruction { } public void manageOutRendering(LinkRendering nextLinkRenderer, boolean endFork) { - if (endFork) { + if (endFork) this.finished = true; - } - if (nextLinkRenderer == null) { + + if (nextLinkRenderer == null) return; - } + getLastList().setOutRendering(nextLinkRenderer); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java index 3188e4d43..ad64d9540 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java @@ -102,7 +102,7 @@ public class InstructionGroup extends AbstractInstruction implements Instruction public Ftile createFtile(FtileFactory factory) { Ftile tmp = list.createFtile(factory); if (note != null) - tmp = new FtileWithNotes(tmp, Collections.singleton(note), factory.skinParam(), VerticalAlignment.CENTER); + tmp = new FtileWithNotes(tmp, Collections.singleton(note), VerticalAlignment.CENTER); return factory.createGroup(tmp, title, backColor, null, type, style); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf.java index 16dc50c1f..c97f0627b 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf.java @@ -80,14 +80,13 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC @Override public boolean containsBreak() { - for (Branch branch : thens) { - if (branch.containsBreak()) { + for (Branch branch : thens) + if (branch.containsBreak()) return true; - } - } - if (elseBranch != null) { + + if (elseBranch != null) return elseBranch.containsBreak(); - } + return false; } @@ -142,10 +141,10 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC Display.NULL, null, LinkRendering.none()); elseBranch.updateFtile(factory); - Ftile result = factory.createIf(swimlane, thens, elseBranch, outColor, topInlinkRendering, url); - if (getPositionedNotes().size() > 0) - result = FtileWithNoteOpale.create(result, getPositionedNotes(), skinParam, false, - VerticalAlignment.CENTER); + Ftile result = factory.createIf(swimlane, thens, elseBranch, outColor, topInlinkRendering, url, + getPositionedNotes()); +// if (getPositionedNotes().size() > 0) +// result = FtileWithNoteOpale.create(result, getPositionedNotes(), false, VerticalAlignment.CENTER); final List weldingPoints = new ArrayList<>(); for (Branch branch : thens) @@ -198,7 +197,7 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC @Override final public boolean kill() { - if (endifCalled) { + if (endifCalled) for (Branch branch : thens) { if (branch.getLast() != null && branch.getLast().kill() == false) return false; @@ -208,7 +207,7 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC return true; } - } + return current.kill(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java index 9c0f7b135..554510da7 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java @@ -120,7 +120,7 @@ public class InstructionWhile extends WithNote implements Instruction, Instructi Ftile tmp = repeatList.createFtile(factory); tmp = factory.createWhile(outColor, swimlane, tmp, test, yes, color, specialOut, back, incoming1, incoming2); if (getPositionedNotes().size() > 0) - tmp = FtileWithNoteOpale.create(tmp, getPositionedNotes(), skinParam, false, VerticalAlignment.CENTER); + tmp = FtileWithNoteOpale.create(tmp, getPositionedNotes(), false, VerticalAlignment.CENTER); if (killed || specialOut != null) return new FtileKilled(tmp); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactory.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactory.java index 5f9f46f69..897491f1b 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactory.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactory.java @@ -89,7 +89,7 @@ public interface FtileFactory { HColor color, Instruction specialOut, Ftile backward, LinkRendering incoming1, LinkRendering incoming2); public Ftile createIf(Swimlane swimlane, List thens, Branch elseBranch, LinkRendering outColor, - LinkRendering topInlinkRendering, Url url); + LinkRendering topInlinkRendering, Url url, Collection notes); public Ftile createSwitch(Swimlane swimlane, List branches, LinkRendering afterEndwhile, LinkRendering topInlinkRendering, Display labelTest); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactoryDelegator.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactoryDelegator.java index 01ec5f091..5969966ce 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactoryDelegator.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactoryDelegator.java @@ -120,47 +120,58 @@ public class FtileFactoryDelegator implements FtileFactory { this.factory = factory; } + @Override public Ftile start(Swimlane swimlane) { return factory.start(swimlane); } + @Override public Ftile end(Swimlane swimlane) { return factory.end(swimlane); } + @Override public Ftile stop(Swimlane swimlane) { return factory.stop(swimlane); } + @Override public Ftile spot(Swimlane swimlane, String spot, HColor color) { return factory.spot(swimlane, spot, color); } + @Override public Ftile activity(Display label, Swimlane swimlane, BoxStyle style, Colors colors, Stereotype stereotype) { return factory.activity(label, swimlane, style, colors, stereotype); } + @Override public Ftile addNote(Ftile ftile, Swimlane swimlane, Collection notes, VerticalAlignment verticalAlignment) { return factory.addNote(ftile, swimlane, notes, verticalAlignment); } + @Override public Ftile addUrl(Ftile ftile, Url url) { return factory.addUrl(ftile, url); } + @Override public Ftile decorateIn(Ftile ftile, LinkRendering linkRendering) { return factory.decorateIn(ftile, Objects.requireNonNull(linkRendering)); } + @Override public Ftile decorateOut(Ftile ftile, LinkRendering linkRendering) { return factory.decorateOut(ftile, Objects.requireNonNull(linkRendering)); } + @Override public Ftile assembly(Ftile tile1, Ftile tile2) { return factory.assembly(tile1, tile2); } + @Override public Ftile repeat(BoxStyle boxStyleIn, Swimlane swimlane, Swimlane swimlaneOut, Display startLabel, Ftile repeat, Display test, Display yes, Display out, Colors colors, Ftile backward, boolean noOut, LinkRendering incoming1, LinkRendering incoming2) { @@ -168,31 +179,37 @@ public class FtileFactoryDelegator implements FtileFactory { noOut, incoming1, incoming2); } + @Override public Ftile createWhile(LinkRendering outColor, Swimlane swimlane, Ftile whileBlock, Display test, Display yes, HColor color, Instruction specialOut, Ftile back, LinkRendering incoming1, LinkRendering incoming2) { return factory.createWhile(outColor, swimlane, whileBlock, test, yes, color, specialOut, back, incoming1, incoming2); } + @Override public Ftile createIf(Swimlane swimlane, List thens, Branch elseBranch, LinkRendering afterEndwhile, - LinkRendering topInlinkRendering, Url url) { - return factory.createIf(swimlane, thens, elseBranch, afterEndwhile, topInlinkRendering, url); + LinkRendering topInlinkRendering, Url url, Collection notes) { + return factory.createIf(swimlane, thens, elseBranch, afterEndwhile, topInlinkRendering, url, notes); } + @Override public Ftile createSwitch(Swimlane swimlane, List branches, LinkRendering afterEndwhile, LinkRendering topInlinkRendering, Display labelTest) { return factory.createSwitch(swimlane, branches, afterEndwhile, topInlinkRendering, labelTest); } + @Override public Ftile createParallel(List all, ForkStyle style, String label, Swimlane in, Swimlane out) { return factory.createParallel(all, style, label, in, out); } + @Override public Ftile createGroup(Ftile list, Display name, HColor backColor, PositionedNote note, USymbol type, Style style) { return factory.createGroup(list, name, backColor, note, type, style); } + @Override public StringBounder getStringBounder() { return factory.getStringBounder(); } @@ -201,6 +218,7 @@ public class FtileFactoryDelegator implements FtileFactory { return rose; } + @Override public final ISkinParam skinParam() { return factory.skinParam(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileGeometry.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileGeometry.java index cccbfaef6..a0b6c5e06 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileGeometry.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileGeometry.java @@ -56,30 +56,30 @@ public class FtileGeometry extends XDimension2D { } public XPoint2D getPointB() { - if (outY == Double.MIN_NORMAL) { + if (outY == Double.MIN_NORMAL) throw new UnsupportedOperationException(); - } + return new XPoint2D(width, (inY + outY) / 2); } public XPoint2D getPointC() { - if (outY == Double.MIN_NORMAL) { + if (outY == Double.MIN_NORMAL) throw new UnsupportedOperationException(); - } + return new XPoint2D(left, outY); } public XPoint2D getPointD() { - if (outY == Double.MIN_NORMAL) { + if (outY == Double.MIN_NORMAL) throw new UnsupportedOperationException(); - } + return new XPoint2D(0, (inY + outY) / 2); } public XPoint2D getPointOut() { - if (outY == Double.MIN_NORMAL) { + if (outY == Double.MIN_NORMAL) throw new UnsupportedOperationException(); - } + return new XPoint2D(left, outY); } @@ -134,6 +134,10 @@ public class FtileGeometry extends XDimension2D { hasPointOut() ? outY + missing1 : outY); } + public FtileGeometry incInY(double missing) { + return new FtileGeometry(width, height, left, inY + missing, outY); + } + public FtileGeometry(XDimension2D dim, double left, double inY, double outY) { this(dim.getWidth(), dim.getHeight(), left, inY, outY); } @@ -149,9 +153,9 @@ public class FtileGeometry extends XDimension2D { public FtileGeometry translate(UTranslate translate) { final double dx = translate.getDx(); final double dy = translate.getDy(); - if (this.outY == Double.MIN_NORMAL) { + if (this.outY == Double.MIN_NORMAL) return new FtileGeometry(width, height, left + dx, inY + dy); - } + return new FtileGeometry(width, height, left + dx, inY + dy, outY + dy); } @@ -200,19 +204,18 @@ public class FtileGeometry extends XDimension2D { } public FtileGeometry ensureHeight(double newHeight) { - if (this.height > newHeight) { + if (this.height > newHeight) return this; - } + return fixedHeight(newHeight); } - private FtileGeometry ensureRightStrange(double newRight) { - final double right = this.width - this.left; - if (right > newRight) { - return this; - } - // return addMarginX(0, newRight - right); - return addMarginX(0, newRight); - } +// private FtileGeometry ensureRightStrange(double newRight) { +// final double right = this.width - this.left; +// if (right > newRight) +// return this; +// +// return addMarginX(0, newRight); +// } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAddNote.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAddNote.java index 4e1572232..74260ca8e 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAddNote.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAddNote.java @@ -58,9 +58,6 @@ public class FtileFactoryDelegatorAddNote extends FtileFactoryDelegator { if (notes.size() == 0) throw new IllegalArgumentException(); - // if (notes.size() > 1) - // throw new IllegalArgumentException(); - ISkinParam skinParam = skinParam(); if (ftile == null) { final PositionedNote note = notes.iterator().next(); @@ -70,6 +67,6 @@ public class FtileFactoryDelegatorAddNote extends FtileFactoryDelegator { return new FtileNoteAlone(skinParam.shadowing(null), note.getDisplay(), skinParam, note.getType() == NoteType.NOTE, swimlane); } - return FtileWithNoteOpale.create(ftile, notes, skinParam, true, verticalAlignment); + return FtileWithNoteOpale.create(ftile, notes, true, verticalAlignment); } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateGroup.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateGroup.java index f05ccf107..8d0d1a4e0 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateGroup.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateGroup.java @@ -58,7 +58,7 @@ public class FtileFactoryDelegatorCreateGroup extends FtileFactoryDelegator { Style style) { Ftile result = new FtileGroup(list, name, backColor, skinParam(), type, style); if (note != null) - result = new FtileWithNotes(result, Collections.singleton(note), skinParam(), VerticalAlignment.CENTER); + result = new FtileWithNotes(result, Collections.singleton(note), VerticalAlignment.CENTER); return result; } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorIf.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorIf.java index 7939f9379..4330e476b 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorIf.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorIf.java @@ -35,10 +35,12 @@ */ package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; +import java.util.Collection; import java.util.List; import net.sourceforge.plantuml.activitydiagram3.Branch; import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.PositionedNote; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; @@ -63,7 +65,7 @@ public class FtileFactoryDelegatorIf extends FtileFactoryDelegator { @Override public Ftile createIf(Swimlane swimlane, List thens, Branch elseBranch, LinkRendering afterEndwhile, - LinkRendering topInlinkRendering, Url url) { + LinkRendering topInlinkRendering, Url url, Collection notes) { final ConditionStyle conditionStyle = skinParam().getConditionStyle(); final ConditionEndStyle conditionEndStyle = skinParam().getConditionEndStyle(); @@ -84,7 +86,7 @@ public class FtileFactoryDelegatorIf extends FtileFactoryDelegator { topInlinkRendering, afterEndwhile, styleArrow, styleDiamond); } return ConditionalBuilder.create(swimlane, backColor, getFactory(), conditionStyle, conditionEndStyle, - thens.get(0), elseBranch, skinParam(), getStringBounder(), url, styleArrow, styleDiamond); + thens.get(0), elseBranch, skinParam(), getStringBounder(), url, styleArrow, styleDiamond, notes); } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfDown.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfDown.java index 60af86e6d..485dfe4fd 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfDown.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIfDown.java @@ -42,6 +42,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import net.sourceforge.plantuml.activitydiagram3.PositionedNote; import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; @@ -55,6 +56,7 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.Hexagon; import net.sourceforge.plantuml.activitydiagram3.ftile.MergeStrategy; import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.cond.FtileIfWithDiamonds; import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond; import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside; import net.sourceforge.plantuml.decoration.Rainbow; @@ -63,6 +65,8 @@ import net.sourceforge.plantuml.klimt.drawing.UGraphic; import net.sourceforge.plantuml.klimt.font.StringBounder; 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.TextBlockUtils; import net.sourceforge.plantuml.klimt.shape.UEmpty; import net.sourceforge.plantuml.svek.ConditionEndStyle; import net.sourceforge.plantuml.utils.Direction; @@ -74,6 +78,7 @@ public class FtileIfDown extends AbstractFtile { private final Ftile diamond2; private final Ftile optionalStop; private final ConditionEndStyle conditionEndStyle; + final private TextBlock opale; @Override public Collection getMyChildren() { @@ -101,23 +106,30 @@ public class FtileIfDown extends AbstractFtile { } private FtileIfDown(Ftile thenBlock, Ftile diamond1, Ftile diamond2, Ftile optionalStop, - ConditionEndStyle conditionEndStyle) { + ConditionEndStyle conditionEndStyle, Collection notes) { super(thenBlock.skinParam()); this.thenBlock = thenBlock; this.diamond1 = diamond1; this.diamond2 = diamond2; this.optionalStop = optionalStop; this.conditionEndStyle = conditionEndStyle; + if (notes.size() == 1) { + final PositionedNote first = notes.iterator().next(); + this.opale = FtileIfWithDiamonds.createOpale(first, skinParam()); + } else { + this.opale = TextBlockUtils.EMPTY_TEXT_BLOCK; + } } public static Ftile create(Ftile diamond1, Ftile diamond2, Swimlane swimlane, Ftile thenBlock, Rainbow arrowColor, - ConditionEndStyle conditionEndStyle, FtileFactory ftileFactory, Ftile optionalStop, Rainbow elseColor) { + ConditionEndStyle conditionEndStyle, FtileFactory ftileFactory, Ftile optionalStop, Rainbow elseColor, + Collection notes) { elseColor = elseColor.withDefault(arrowColor); final FtileIfDown result = new FtileIfDown(thenBlock, diamond1, optionalStop == null ? diamond2 : new FtileEmpty(ftileFactory.skinParam()), optionalStop, - conditionEndStyle); + conditionEndStyle, notes); final List conns = new ArrayList<>(); conns.add(result.new ConnectionIn(thenBlock.getInLinkRendering().getRainbow(arrowColor))); @@ -511,6 +523,13 @@ public class FtileIfDown extends AbstractFtile { public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); + + if (TextBlockUtils.isEmpty(opale, stringBounder) == false) { + final double xOpale = getTranslateDiamond1(stringBounder).getDx() + - opale.calculateDimension(stringBounder).getWidth(); + opale.drawU(ug.apply(UTranslate.dx(xOpale))); + } + ug.apply(getTranslateForThen(stringBounder)).draw(thenBlock); ug.apply(getTranslateDiamond1(stringBounder)).draw(diamond1); if (optionalStop == null) @@ -522,17 +541,35 @@ public class FtileIfDown extends AbstractFtile { @Override protected FtileGeometry calculateDimensionFtile(StringBounder stringBounder) { + + final XDimension2D dimOpale = opale.calculateDimension(stringBounder); + final FtileGeometry geoDiamond1 = diamond1.calculateDimension(stringBounder); final FtileGeometry geoThen = thenBlock.calculateDimension(stringBounder); final FtileGeometry geoDiamond2 = diamond2.calculateDimension(stringBounder); final FtileGeometry geo = geoDiamond1.appendBottom(geoThen).appendBottom(geoDiamond2); + + final double opaleWidth = dimOpale.getWidth(); + final double opaleHeight = dimOpale.getHeight(); + final double height = geo.getHeight() + 3 * Hexagon.hexagonHalfSize - + Math.max(Hexagon.hexagonHalfSize * 1, getSouthLabelHeight(stringBounder)); - double width = geo.getWidth() + Hexagon.hexagonHalfSize; + + Math.max(Hexagon.hexagonHalfSize * 1, getSouthLabelHeight(stringBounder)) + opaleHeight; + + double supp = 0; + if (opaleWidth > geo.getLeft()) + supp = opaleWidth - geo.getLeft(); + + double width = supp + geo.getWidth() + Hexagon.hexagonHalfSize; if (optionalStop != null) width += optionalStop.calculateDimension(stringBounder).getWidth() + getAdditionalWidth(stringBounder); - final FtileGeometry result = new FtileGeometry(width, height, geo.getLeft(), geoDiamond1.getInY(), height); + final FtileGeometry result; + if (supp > 0) + result = new FtileGeometry(width, height, opaleWidth + geoDiamond1.getLeft(), + geoDiamond1.getInY() + opaleHeight, height); + else + result = new FtileGeometry(width, height, geo.getLeft(), geoDiamond1.getInY() + opaleHeight, height); + if (geoThen.hasPointOut() == false && optionalStop != null) return result.withoutPointOut(); @@ -591,8 +628,9 @@ public class FtileIfDown extends AbstractFtile { final FtileGeometry dimTotal = calculateDimension(stringBounder); final FtileGeometry dimThen = thenBlock.calculateDimension(stringBounder); - final double y = dimDiamond1.getHeight() - + (dimTotal.getHeight() - dimDiamond1.getHeight() - dimDiamond2.getHeight() - dimThen.getHeight()) / 2; + final double opaleHeight = opale.calculateDimension(stringBounder).getHeight(); + final double y = opaleHeight + dimDiamond1.getHeight() + (dimTotal.getHeight() - opaleHeight + - dimDiamond1.getHeight() - dimDiamond2.getHeight() - dimThen.getHeight()) / 2; final double x = dimTotal.getLeft() - dimThen.getLeft(); return new UTranslate(x, y); @@ -602,7 +640,7 @@ public class FtileIfDown extends AbstractFtile { private UTranslate getTranslateDiamond1(StringBounder stringBounder) { final FtileGeometry dimTotal = calculateDimension(stringBounder); final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - final double y1 = 0; + final double y1 = opale.calculateDimension(stringBounder).getHeight(); final double x1 = dimTotal.getLeft() - dimDiamond1.getLeft(); return new UTranslate(x1, y1); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNoteOpale.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNoteOpale.java index 2f20d5164..3041b892b 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNoteOpale.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNoteOpale.java @@ -66,7 +66,6 @@ import net.sourceforge.plantuml.klimt.shape.TextBlock; import net.sourceforge.plantuml.sequencediagram.NotePosition; import net.sourceforge.plantuml.sequencediagram.NoteType; import net.sourceforge.plantuml.skin.AlignmentParam; -import net.sourceforge.plantuml.style.ISkinParam; import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.SName; import net.sourceforge.plantuml.style.Style; @@ -111,31 +110,28 @@ public class FtileWithNoteOpale extends AbstractFtile implements Stencil, Stylea return Collections.singleton(tile); } - public static Ftile create(Ftile tile, Collection notes, ISkinParam skinParam, boolean withLink, + public static Ftile create(Ftile tile, Collection notes, boolean withLink, VerticalAlignment verticalAlignment) { if (notes.size() > 1) - return new FtileWithNotes(tile, notes, skinParam, verticalAlignment); + return new FtileWithNotes(tile, notes, verticalAlignment); if (notes.size() == 0) throw new IllegalArgumentException(); - return new FtileWithNoteOpale(tile, notes.iterator().next(), skinParam, withLink, verticalAlignment); + return new FtileWithNoteOpale(tile, notes.iterator().next(), withLink, verticalAlignment); } - private FtileWithNoteOpale(Ftile tile, PositionedNote note, ISkinParam skinParam, boolean withLink, - VerticalAlignment verticalAlignment) { - super(tile.skinParam()); + private FtileWithNoteOpale(Ftile tile, PositionedNote note, boolean withLink, VerticalAlignment verticalAlignment) { + super(note.getColors() == null ? tile.skinParam() : note.getColors().mute(tile.skinParam())); this.verticalAlignment = verticalAlignment; this.swimlaneNote = note.getSwimlaneNote(); - if (note.getColors() != null) - skinParam = note.getColors().mute(skinParam); this.tile = tile; this.notePosition = note.getNotePosition(); if (note.getType() == NoteType.FLOATING_NOTE) withLink = false; - final Style style = getStyleSignature().getMergedStyle(skinParam.getCurrentStyleBuilder()) + final Style style = getStyleSignature().getMergedStyle(skinParam().getCurrentStyleBuilder()) .eventuallyOverride(note.getColors()); final HColor noteBackgroundColor = style.value(PName.BackGroundColor).asColor(getIHtmlColorSet()); final HColor borderColor = style.value(PName.LineColor).asColor(getIHtmlColorSet()); @@ -144,10 +140,11 @@ public class FtileWithNoteOpale extends AbstractFtile implements Stencil, Stylea final LineBreakStrategy wrapWidth = style.wrapWidth(); final UStroke stroke = style.getStroke(); - final HorizontalAlignment align = skinParam.getHorizontalAlignment(AlignmentParam.noteTextAlignment, null, + final HorizontalAlignment align = skinParam().getHorizontalAlignment(AlignmentParam.noteTextAlignment, null, false, null); - final Sheet sheet = skinParam.sheet(fc, align, CreoleMode.FULL).createSheet(note.getDisplay()); - final TextBlock text = new SheetBlock2(new SheetBlock1(sheet, wrapWidth, skinParam.getPadding()), this, stroke); + final Sheet sheet = skinParam().sheet(fc, align, CreoleMode.FULL).createSheet(note.getDisplay()); + final TextBlock text = new SheetBlock2(new SheetBlock1(sheet, wrapWidth, skinParam().getPadding()), this, + stroke); opale = new Opale(shadowing, borderColor, noteBackgroundColor, text, withLink, stroke); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNotes.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNotes.java index a4587937e..adade0f01 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNotes.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNotes.java @@ -96,18 +96,17 @@ public class FtileWithNotes extends AbstractFtile { return tile.getSwimlaneOut(); } - public FtileWithNotes(Ftile tile, Collection notes, ISkinParam skinParam, - VerticalAlignment verticalAlignment) { + public FtileWithNotes(Ftile tile, Collection notes, VerticalAlignment verticalAlignment) { super(tile.skinParam()); this.verticalAlignment = verticalAlignment; this.tile = tile; for (PositionedNote note : notes) { - ISkinParam skinParam2 = skinParam; + ISkinParam skinParam2 = skinParam(); if (note.getColors() != null) skinParam2 = note.getColors().mute(skinParam2); - final Style style = getStyleSignature().getMergedStyle(skinParam.getCurrentStyleBuilder()) + final Style style = getStyleSignature().getMergedStyle(skinParam().getCurrentStyleBuilder()) .eventuallyOverride(note.getColors()); final HColor noteBackgroundColor = style.value(PName.BackGroundColor).asColor(getIHtmlColorSet()); final HColor borderColor = style.value(PName.LineColor).asColor(getIHtmlColorSet()); @@ -116,10 +115,10 @@ public class FtileWithNotes extends AbstractFtile { final LineBreakStrategy wrapWidth = style.wrapWidth(); final UStroke stroke = style.getStroke(); - final Sheet sheet = skinParam - .sheet(fc, skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), CreoleMode.FULL) + final Sheet sheet = skinParam() + .sheet(fc, skinParam().getDefaultTextAlignment(HorizontalAlignment.LEFT), CreoleMode.FULL) .createSheet(note.getDisplay()); - final SheetBlock1 sheet1 = new SheetBlock1(sheet, wrapWidth, skinParam.getPadding()); + final SheetBlock1 sheet1 = new SheetBlock1(sheet, wrapWidth, skinParam().getPadding()); final SheetBlock2 sheet2 = new SheetBlock2(sheet1, new Stencil() { // -6 and 15 value comes from Opale: this is very ugly! public double getStartingX(StringBounder stringBounder, double y) { diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/VCompactFactory.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/VCompactFactory.java index 57560ccaa..5de156079 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/VCompactFactory.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/VCompactFactory.java @@ -177,7 +177,7 @@ public class VCompactFactory implements FtileFactory { @Override public Ftile createIf(Swimlane swimlane, List thens, Branch elseBranch, LinkRendering afterEndwhile, - LinkRendering topInlinkRendering, Url url) { + LinkRendering topInlinkRendering, Url url, Collection notes) { final List ftiles = new ArrayList<>(); for (Branch branch : thens) ftiles.add(branch.getFtile()); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java index 433e17eda..22a85d305 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java @@ -35,7 +35,10 @@ */ package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.cond; +import java.util.Collection; + import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.PositionedNote; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileEmpty; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; @@ -92,6 +95,7 @@ public class ConditionalBuilder { private final Ftile tile1; private final Ftile tile2; private final Url url; + private final Collection notes; private StyleSignatureBasic getStyleSignatureDiamond() { return StyleSignatureBasic.of(SName.root, SName.element, SName.activityDiagram, SName.activity, SName.diamond); @@ -103,7 +107,8 @@ public class ConditionalBuilder { public ConditionalBuilder(Swimlane swimlane, HColor backColor, FtileFactory ftileFactory, ConditionStyle conditionStyle, ConditionEndStyle conditionEndStyle, Branch branch1, Branch branch2, - ISkinParam skinParam, StringBounder stringBounder, Url url, Style styleArrow, Style styleDiamond) { + ISkinParam skinParam, StringBounder stringBounder, Url url, Style styleArrow, Style styleDiamond, + Collection notes) { if (backColor == null) throw new IllegalArgumentException(); @@ -113,6 +118,7 @@ public class ConditionalBuilder { this.diamondLineBreak = styleDiamond.wrapWidth(); this.labelLineBreak = styleArrow.wrapWidth(); this.backColor = backColor; + this.notes = notes; this.borderColor = styleDiamond.value(PName.LineColor).asColor(skinParam.getIHtmlColorSet()); this.arrowColor = Rainbow.build(styleArrow, skinParam.getIHtmlColorSet()); @@ -134,9 +140,10 @@ public class ConditionalBuilder { static public Ftile create(Swimlane swimlane, HColor backColor, FtileFactory ftileFactory, ConditionStyle conditionStyle, ConditionEndStyle conditionEndStyle, Branch branch1, Branch branch2, - ISkinParam skinParam, StringBounder stringBounder, Url url, Style styleArrow, Style styleDiamond) { + ISkinParam skinParam, StringBounder stringBounder, Url url, Style styleArrow, Style styleDiamond, + Collection notes) { final ConditionalBuilder builder = new ConditionalBuilder(swimlane, backColor, ftileFactory, conditionStyle, - conditionEndStyle, branch1, branch2, skinParam, stringBounder, url, styleArrow, styleDiamond); + conditionEndStyle, branch1, branch2, skinParam, stringBounder, url, styleArrow, styleDiamond, notes); if (isEmptyOrOnlySingleStopOrSpot(branch2) && isEmptyOrOnlySingleStopOrSpot(branch1) == false) return builder.createDown(builder.branch1, builder.branch2); @@ -167,18 +174,18 @@ public class ConditionalBuilder { final Ftile diamond2 = getShape2(branch1, branch2, true); if (branch2.isOnlySingleStopOrSpot()) return FtileIfDown.create(diamond1, diamond2, swimlane, FtileUtils.addHorizontalMargin(tile1, 10), - arrowColor, conditionEndStyle, ftileFactory, branch2.getFtile(), branch2.getOut()); + arrowColor, conditionEndStyle, ftileFactory, branch2.getFtile(), branch2.getOut(), notes); if (branch1.isOnlySingleStopOrSpot()) return FtileIfDown.create(diamond1, diamond2, swimlane, FtileUtils.addHorizontalMargin(tile2, 10), - arrowColor, conditionEndStyle, ftileFactory, branch1.getFtile(), branch1.getOut()); + arrowColor, conditionEndStyle, ftileFactory, branch1.getFtile(), branch1.getOut(), notes); if (branch1.isEmpty()) return FtileIfDown.create(diamond1, diamond2, swimlane, FtileUtils.addHorizontalMargin(tile2, 10), - arrowColor, conditionEndStyle, ftileFactory, null, null); + arrowColor, conditionEndStyle, ftileFactory, null, null, notes); return FtileIfDown.create(diamond1, diamond2, swimlane, FtileUtils.addHorizontalMargin(tile1, 10), arrowColor, - conditionEndStyle, ftileFactory, null, branch2.getOut()); + conditionEndStyle, ftileFactory, null, branch2.getOut(), notes); } private Ftile createNude() { @@ -190,7 +197,7 @@ public class ConditionalBuilder { final Ftile diamond1 = getDiamond1(true); final Ftile diamond2 = getShape2(branch1, branch2, false); final FtileIfWithDiamonds ftile = new FtileIfWithDiamonds(diamond1, tile1, tile2, diamond2, swimlane, - stringBounder); + stringBounder, notes); final XDimension2D label1 = getLabelPositive(branch1).calculateDimension(stringBounder); final XDimension2D label2 = getLabelPositive(branch2).calculateDimension(stringBounder); final double diff1 = ftile.computeMarginNeedForBranchLabe1(stringBounder, label1); @@ -210,7 +217,7 @@ public class ConditionalBuilder { final Ftile tmp1 = FtileUtils.addHorizontalMargin(tile1, 10); final Ftile tmp2 = FtileUtils.addHorizontalMargin(tile2, 10); final FtileIfWithLinks ftile = new FtileIfWithLinks(diamond1, tmp1, tmp2, diamond2, swimlane, arrowColor, - conditionEndStyle, stringBounder); + conditionEndStyle, stringBounder, notes); final XDimension2D label1 = getLabelPositive(branch1).calculateDimension(stringBounder); final XDimension2D label2 = getLabelPositive(branch2).calculateDimension(stringBounder); final double diff1 = ftile.computeMarginNeedForBranchLabe1(stringBounder, label1); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileDimensionMemoize.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileDimensionMemoize.java index b41942e54..d95d07ae4 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileDimensionMemoize.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileDimensionMemoize.java @@ -41,7 +41,7 @@ import net.sourceforge.plantuml.klimt.font.StringBounder; import net.sourceforge.plantuml.style.ISkinParam; public abstract class FtileDimensionMemoize extends AbstractFtile { - // ::remove folder when __HAXE__ + // ::remove folder when __HAXE__ public FtileDimensionMemoize(ISkinParam skinParam) { super(skinParam); @@ -50,11 +50,15 @@ public abstract class FtileDimensionMemoize extends AbstractFtile { private FtileGeometry calculateDimensionInternal; protected final FtileGeometry calculateDimensionInternal(StringBounder stringBounder) { - if (calculateDimensionInternal == null) { + if (calculateDimensionInternal == null) calculateDimensionInternal = calculateDimensionInternalSlow(stringBounder); - } + return calculateDimensionInternal; } + protected final void clearCacheDimensionInternal() { + calculateDimensionInternal = null; + } + abstract protected FtileGeometry calculateDimensionInternalSlow(StringBounder stringBounder); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfNude.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfNude.java index 961310df2..cce546d81 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfNude.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfNude.java @@ -55,6 +55,9 @@ public class FtileIfNude extends FtileDimensionMemoize { protected final Ftile tile2; private final Swimlane in; + protected double xDeltaNote = 0; + protected double yDeltaNote = 0; + FtileIfNude(Ftile tile1, Ftile tile2, Swimlane in) { super(tile1.skinParam()); this.tile1 = tile1; @@ -74,9 +77,9 @@ public class FtileIfNude extends FtileDimensionMemoize { public Set getSwimlanes() { final Set result = new HashSet<>(); - if (getSwimlaneIn() != null) { + if (getSwimlaneIn() != null) result.add(getSwimlaneIn()); - } + result.addAll(tile1.getSwimlanes()); result.addAll(tile2.getSwimlanes()); return Collections.unmodifiableSet(result); @@ -90,50 +93,47 @@ public class FtileIfNude extends FtileDimensionMemoize { return getSwimlaneIn(); } - protected UTranslate getTranslate1(StringBounder stringBounder) { -// final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); -// final Dimension2D dim1 = tile1.calculateDimension(stringBounder); - - final double x1 = 0; - final double y1 = 0; + protected UTranslate getTranslateBranch1(StringBounder stringBounder) { + final double x1 = xDeltaNote; + final double y1 = yDeltaNote; return new UTranslate(x1, y1); } - protected UTranslate getTranslate2(StringBounder stringBounder) { + protected UTranslate getTranslateBranch2(StringBounder stringBounder) { final XDimension2D dimTotal = calculateDimensionInternal(stringBounder); final XDimension2D dim2 = tile2.calculateDimension(stringBounder); final double x2 = dimTotal.getWidth() - dim2.getWidth(); - final double y2 = 0; + final double y2 = yDeltaNote; return new UTranslate(x2, y2); } @Override public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { - if (child == tile1) { - return getTranslate1(stringBounder); - } - if (child == tile2) { - return getTranslate2(stringBounder); - } + if (child == tile1) + return getTranslateBranch1(stringBounder); + + if (child == tile2) + return getTranslateBranch2(stringBounder); + throw new UnsupportedOperationException(); } public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); - ug.apply(getTranslate1(stringBounder)).draw(tile1); - ug.apply(getTranslate2(stringBounder)).draw(tile2); + ug.apply(getTranslateBranch1(stringBounder)).draw(tile1); + ug.apply(getTranslateBranch2(stringBounder)).draw(tile2); } @Override protected FtileGeometry calculateDimensionFtile(StringBounder stringBounder) { final FtileGeometry dimTotal = calculateDimensionInternal(stringBounder); if (tile1.calculateDimension(stringBounder).hasPointOut() - || tile2.calculateDimension(stringBounder).hasPointOut()) { + || tile2.calculateDimension(stringBounder).hasPointOut()) return dimTotal; - } + return dimTotal.withoutPointOut(); } @@ -143,11 +143,12 @@ public class FtileIfNude extends FtileDimensionMemoize { final FtileGeometry dim2 = tile2.calculateDimension(stringBounder); final double innerMargin = widthInner(stringBounder); - final double width = dim1.getLeft() + innerMargin + (dim2.getWidth() - dim2.getLeft()); + final double width = xDeltaNote + dim1.getLeft() + innerMargin + (dim2.getWidth() - dim2.getLeft()); final XDimension2D dim12 = dim1.mergeLR(dim2); - return new FtileGeometry(width, dim12.getHeight(), dim1.getLeft() + innerMargin / 2, 0); + final double height = yDeltaNote + dim12.getHeight(); + return new FtileGeometry(width, height, xDeltaNote + dim1.getLeft() + innerMargin / 2, yDeltaNote, height); } protected double widthInner(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java index 1e5c15a6a..041645cb5 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java @@ -38,25 +38,81 @@ package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.cond; import java.util.Arrays; import java.util.Collection; +import net.sourceforge.plantuml.activitydiagram3.PositionedNote; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileGeometry; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.klimt.LineBreakStrategy; +import net.sourceforge.plantuml.klimt.UStroke; import net.sourceforge.plantuml.klimt.UTranslate; +import net.sourceforge.plantuml.klimt.color.HColor; +import net.sourceforge.plantuml.klimt.creole.CreoleMode; +import net.sourceforge.plantuml.klimt.creole.Sheet; +import net.sourceforge.plantuml.klimt.creole.SheetBlock1; import net.sourceforge.plantuml.klimt.drawing.UGraphic; +import net.sourceforge.plantuml.klimt.font.FontConfiguration; import net.sourceforge.plantuml.klimt.font.StringBounder; +import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment; import net.sourceforge.plantuml.klimt.geom.XDimension2D; +import net.sourceforge.plantuml.klimt.shape.TextBlock; +import net.sourceforge.plantuml.klimt.shape.TextBlockUtils; +import net.sourceforge.plantuml.skin.AlignmentParam; +import net.sourceforge.plantuml.style.ISkinParam; +import net.sourceforge.plantuml.style.PName; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.style.StyleSignatureBasic; +import net.sourceforge.plantuml.svek.image.Opale; public class FtileIfWithDiamonds extends FtileIfNude { private static final double SUPP_WIDTH = 20; protected final Ftile diamond1; protected final Ftile diamond2; + final private TextBlock opale; public FtileIfWithDiamonds(Ftile diamond1, Ftile tile1, Ftile tile2, Ftile diamond2, Swimlane in, - StringBounder stringBounder) { + StringBounder stringBounder, Collection notes) { super(tile1, tile2, in); this.diamond1 = diamond1; this.diamond2 = diamond2; + if (notes.size() == 1) { + final PositionedNote first = notes.iterator().next(); + this.opale = createOpale(first, skinParam()); + final double pos1 = getTranslateDiamond1(stringBounder).getDx(); + final XDimension2D dimOpale = opale.calculateDimension(stringBounder); + final double opaleWith = dimOpale.getWidth(); + if (opaleWith > pos1) + xDeltaNote = opaleWith - pos1; + + yDeltaNote = dimOpale.getHeight(); + clearCacheDimensionInternal(); + } else { + this.opale = TextBlockUtils.EMPTY_TEXT_BLOCK; + } + + } + + public static Opale createOpale(final PositionedNote first, ISkinParam skinParam) { + final Style style = getStyleSignature().getMergedStyle(skinParam.getCurrentStyleBuilder()) + .eventuallyOverride(first.getColors()); + final HColor noteBackgroundColor = style.value(PName.BackGroundColor).asColor(skinParam.getIHtmlColorSet()); + final HColor borderColor = style.value(PName.LineColor).asColor(skinParam.getIHtmlColorSet()); + final FontConfiguration fc = style.getFontConfiguration(skinParam.getIHtmlColorSet()); + final double shadowing = style.value(PName.Shadowing).asDouble(); + final LineBreakStrategy wrapWidth = style.wrapWidth(); + final UStroke stroke = style.getStroke(); + + final HorizontalAlignment align = skinParam.getHorizontalAlignment(AlignmentParam.noteTextAlignment, null, + false, null); + final Sheet sheet = skinParam.sheet(fc, align, CreoleMode.FULL).createSheet(first.getDisplay()); + final SheetBlock1 tmp1 = new SheetBlock1(sheet, wrapWidth, skinParam.getPadding()); + // final TextBlock text = new SheetBlock2(tmp1, this, stroke); + return new Opale(shadowing, borderColor, noteBackgroundColor, tmp1, false, stroke); + } + + private static StyleSignatureBasic getStyleSignature() { + return StyleSignatureBasic.of(SName.root, SName.element, SName.activityDiagram, SName.note); } @Override @@ -95,36 +151,49 @@ public class FtileIfWithDiamonds extends FtileIfNude { final FtileGeometry all = dim1.appendBottom(dimNude).appendBottom(dim2); - return all.addDim(0, - getYdelta1a(stringBounder) + getYdelta1b(stringBounder) + getYdeltaForLabels(stringBounder)); + final double deltaHeight = getYdelta1a(stringBounder) + getYdelta1b(stringBounder) + + getYdeltaForLabels(stringBounder); + + final FtileGeometry result = all.addDim(0, deltaHeight).incInY(yDeltaNote); + return result; } +// protected double getSuppWidthForNotes(StringBounder stringBounder) { +// return opale.calculateDimension(stringBounder).getWidth(); +// } + @Override public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); + if (TextBlockUtils.isEmpty(opale, stringBounder) == false) { + final double xOpale = getTranslateDiamond1(stringBounder).getDx() + - opale.calculateDimension(stringBounder).getWidth(); + opale.drawU(ug.apply(UTranslate.dx(xOpale))); + } + ug.apply(getTranslateDiamond1(stringBounder)).draw(diamond1); super.drawU(ug); ug.apply(getTranslateDiamond2(stringBounder)).draw(diamond2); } @Override - protected UTranslate getTranslate1(StringBounder stringBounder) { + protected UTranslate getTranslateBranch1(StringBounder stringBounder) { final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - return super.getTranslate1(stringBounder) + return super.getTranslateBranch1(stringBounder) .compose(UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); } @Override - protected UTranslate getTranslate2(StringBounder stringBounder) { + protected UTranslate getTranslateBranch2(StringBounder stringBounder) { final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - return super.getTranslate2(stringBounder) + return super.getTranslateBranch2(stringBounder) .compose(UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); } protected UTranslate getTranslateDiamond1(StringBounder stringBounder) { - final double y1 = 0; + final double y1 = yDeltaNote; final FtileGeometry dimTotal = calculateDimensionInternal(stringBounder); final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); final double x1 = dimTotal.getLeft() - dimDiamond1.getLeft(); @@ -134,8 +203,8 @@ public class FtileIfWithDiamonds extends FtileIfNude { protected UTranslate getTranslateDiamond2(StringBounder stringBounder) { final FtileGeometry dimTotal = calculateDimensionInternal(stringBounder); final FtileGeometry dimDiamond2 = diamond2.calculateDimension(stringBounder); - final double y2 = dimTotal.getHeight() - dimDiamond2.getHeight(); final double x2 = dimTotal.getLeft() - dimDiamond2.getWidth() / 2; + final double y2 = dimTotal.getHeight() - dimDiamond2.getHeight(); return new UTranslate(x2, y2); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java index 93fd36c37..1e01b6fe1 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithLinks.java @@ -36,9 +36,11 @@ package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.cond; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.PositionedNote; import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; import net.sourceforge.plantuml.activitydiagram3.ftile.ConnectionTranslatable; @@ -68,8 +70,8 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { private final Rainbow arrowColor; public FtileIfWithLinks(Ftile diamond1, Ftile tile1, Ftile tile2, Ftile diamond2, Swimlane in, Rainbow arrowColor, - ConditionEndStyle conditionEndStyle, StringBounder stringBounder) { - super(diamond1, tile1, tile2, diamond2, in, stringBounder); + ConditionEndStyle conditionEndStyle, StringBounder stringBounder, Collection notes) { + super(diamond1, tile1, tile2, diamond2, in, stringBounder, notes); this.arrowColor = arrowColor; this.conditionEndStyle = conditionEndStyle; if (arrowColor.size() == 0) @@ -135,10 +137,10 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { private UTranslate translate(StringBounder stringBounder) { if (getFtile2() == tile1) - return getTranslate1(stringBounder); + return getTranslateBranch1(stringBounder); if (getFtile2() == tile2) - return getTranslate2(stringBounder); + return getTranslateBranch2(stringBounder); throw new IllegalStateException(); } @@ -224,10 +226,10 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { private UTranslate translate(StringBounder stringBounder) { if (getFtile1() == tile1) - return getTranslate1(stringBounder); + return getTranslateBranch1(stringBounder); if (getFtile1() == tile2) - return getTranslate2(stringBounder); + return getTranslateBranch2(stringBounder); throw new IllegalStateException(); } @@ -353,10 +355,10 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { private UTranslate translate(StringBounder stringBounder) { if (getFtile1() == tile1) - return getTranslate1(stringBounder); + return getTranslateBranch1(stringBounder); if (getFtile1() == tile2) - return getTranslate2(stringBounder); + return getTranslateBranch2(stringBounder); throw new IllegalStateException(); } @@ -399,10 +401,10 @@ public class FtileIfWithLinks extends FtileIfWithDiamonds { private UTranslate translate(StringBounder stringBounder) { if (getFtile1() == tile1) - return getTranslate1(stringBounder); + return getTranslateBranch1(stringBounder); if (getFtile1() == tile2) - return getTranslate2(stringBounder); + return getTranslateBranch2(stringBounder); throw new IllegalStateException(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchNude.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchNude.java index 48ecaa316..42bdce0e6 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchNude.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileSwitchNude.java @@ -131,7 +131,7 @@ public class FtileSwitchNude extends FtileDimensionMemoize { result = result.delta(xSeparation * (tiles.size() - 1), 100); - return new FtileGeometry(result, result.getWidth() / 2, 0); + return new FtileGeometry(result.getWidth(), result.getHeight(), result.getWidth() / 2, 0); } } diff --git a/src/net/sourceforge/plantuml/klimt/shape/TextBlockUtils.java b/src/net/sourceforge/plantuml/klimt/shape/TextBlockUtils.java index 2f1020d82..df9ff3465 100644 --- a/src/net/sourceforge/plantuml/klimt/shape/TextBlockUtils.java +++ b/src/net/sourceforge/plantuml/klimt/shape/TextBlockUtils.java @@ -147,9 +147,9 @@ public class TextBlockUtils { } public static boolean isEmpty(TextBlock text, StringBounder dummyStringBounder) { - if (text == null) { + if (text == null || text == EMPTY_TEXT_BLOCK) return true; - } + final XDimension2D dim = text.calculateDimension(dummyStringBounder); return dim.getHeight() == 0 && dim.getWidth() == 0; } diff --git a/src/net/sourceforge/plantuml/syntax/LanguageDescriptor.java b/src/net/sourceforge/plantuml/syntax/LanguageDescriptor.java index feba17b8c..5133a8a71 100644 --- a/src/net/sourceforge/plantuml/syntax/LanguageDescriptor.java +++ b/src/net/sourceforge/plantuml/syntax/LanguageDescriptor.java @@ -152,6 +152,7 @@ public class LanguageDescriptor { keyword.add("rnote"); keyword.add("hnote"); keyword.add("legend"); + keyword.add("endlegend"); keyword.add("group"); keyword.add("left"); keyword.add("right"); diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 0de327b2b..b5ad2e5e1 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -46,7 +46,7 @@ public class Version { // Warning, "version" should be the same in gradle.properties and Version.java // Any idea anyone how to magically synchronize those :-) ? - private static final String version = "1.2023.10"; + private static final String version = "1.2023.11beta1"; public static String versionString() { return version;