1
0
mirror of https://github.com/octoleo/plantuml.git synced 2025-04-10 12:11:50 +00:00

Add nested box in sequence diagram

This commit is contained in:
Arnaud Roques 2022-01-04 18:21:17 +01:00
parent 16fd392308
commit d36de19c99
7 changed files with 181 additions and 88 deletions

View File

@ -37,56 +37,57 @@ package net.sourceforge.plantuml.sequencediagram;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.PaddingParam; import net.sourceforge.plantuml.PaddingParam;
import net.sourceforge.plantuml.SkinParamBackcolored;
import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.real.Real;
import net.sourceforge.plantuml.real.RealUtils; import net.sourceforge.plantuml.real.RealUtils;
import net.sourceforge.plantuml.sequencediagram.teoz.LivingSpace; import net.sourceforge.plantuml.sequencediagram.teoz.LivingSpace;
import net.sourceforge.plantuml.sequencediagram.teoz.TileArguments; import net.sourceforge.plantuml.sequencediagram.teoz.TileArguments;
import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D; import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.style.StyleBuilder; import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.UTranslate;
public class DollLeaf extends DollAbstract { public class Doll extends DollAbstract {
final private List<Participant> participants = new ArrayList<>(); final private List<Participant> participants = new ArrayList<>();
final private TileArguments tileArguments; private final List<Doll> leafs = new ArrayList<>();
final private Real core1; final private Real core1;
final private Real core2; final private Real core2;
private double marginX = 0; private double marginX = 0;
public static DollLeaf createPuma(ParticipantEnglober englober, Participant first, ISkinParam skinParam, Rose skin, public static Doll createGroup(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder,
StringBounder stringBounder, StyleBuilder styleBuilder) { boolean isTeoz) {
return new DollLeaf(englober, styleBuilder, false, first, return new Doll(englober, tileArguments, styleBuilder, isTeoz);
convertFunctionToBeRemoved(skinParam, skin, stringBounder));
} }
public static DollLeaf createTeoz(ParticipantEnglober englober, Participant first, TileArguments tileArguments, public static Doll createPuma(ParticipantEnglober englober, Participant first, ISkinParam skinParam, Rose skin,
StringBounder stringBounder, StyleBuilder styleBuilder) {
return new Doll(englober, convertFunctionToBeRemoved(skinParam, skin, stringBounder), styleBuilder, false,
first);
}
public static Doll createTeoz(ParticipantEnglober englober, Participant first, TileArguments tileArguments,
StyleBuilder styleBuilder) { StyleBuilder styleBuilder) {
return new DollLeaf(englober, styleBuilder, true, first, tileArguments); final Doll result = new Doll(englober, tileArguments, styleBuilder, true, first);
return result;
} }
private static TileArguments convertFunctionToBeRemoved(ISkinParam skinParam, Rose skin, private static TileArguments convertFunctionToBeRemoved(ISkinParam skinParam, Rose skin,
StringBounder stringBounder) { StringBounder stringBounder) {
final TileArguments result = new TileArguments(stringBounder, null, skin, skinParam, null); return new TileArguments(stringBounder, null, skin, skinParam, null);
return result;
} }
private DollLeaf(ParticipantEnglober englober, StyleBuilder styleBuilder, boolean isTeoz, Participant first, private Doll(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz,
TileArguments tileArguments) { Participant first) {
super(englober, styleBuilder, isTeoz); super(englober, tileArguments, styleBuilder, isTeoz);
this.participants.add(first); this.participants.add(first);
this.tileArguments = Objects.requireNonNull(tileArguments);
final double preferredWidth = getPreferredWidth(); final double preferredWidth = getPreferredWidth();
if (tileArguments.getLivingSpaces() == null) { if (tileArguments.getLivingSpaces() == null) {
this.core1 = null; this.core1 = null;
@ -97,6 +98,12 @@ public class DollLeaf extends DollAbstract {
} }
} }
private Doll(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz) {
super(englober, tileArguments, styleBuilder, isTeoz);
this.core1 = null;
this.core2 = null;
}
public final Participant getFirst2TOBEPRIVATE() { public final Participant getFirst2TOBEPRIVATE() {
return participants.get(0); return participants.get(0);
} }
@ -142,28 +149,24 @@ public class DollLeaf extends DollAbstract {
return tileArguments.getLivingSpace(getLast2TOBEPRIVATE()); return tileArguments.getLivingSpace(getLast2TOBEPRIVATE());
} }
private Component getComponent() {
final ParticipantEnglober englober = getParticipantEnglober();
final ISkinParam s = englober.getBoxColor() == null ? tileArguments.getSkinParam()
: new SkinParamBackcolored(tileArguments.getSkinParam(), englober.getBoxColor());
return tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, s,
englober.getTitle());
}
public boolean contains(Participant p) { public boolean contains(Participant p) {
return participants.contains(p); return participants.contains(p);
} }
public void add(Participant p) { public void addParticipant(Participant p) {
if (participants.contains(p)) { if (participants.contains(p))
throw new IllegalArgumentException(); throw new IllegalArgumentException();
}
participants.add(p); participants.add(p);
} }
public void addDoll(Doll doll) {
this.leafs.add(doll);
}
@Override @Override
public String toString() { public String toString() {
return "ParticipantEngloberContexted:" + englober.getTitle().toString() + " " + participants; return "DollLeaf:" + englober.getTitle().toString() + " " + participants;
} }
private double getPreferredWidth() { private double getPreferredWidth() {
@ -177,26 +180,53 @@ public class DollLeaf extends DollAbstract {
return getComponent().getPreferredWidth(tileArguments.getStringBounder()); return getComponent().getPreferredWidth(tileArguments.getStringBounder());
} }
public double getPreferredHeight() { public void drawGroup(UGraphic ug, double height, Context2D context) {
final Component comp = tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, if (leafs.size() == 0)
tileArguments.getSkinParam(), getParticipantEnglober().getTitle()); throw new IllegalArgumentException();
return comp.getPreferredHeight(tileArguments.getStringBounder()); final double x1 = getGroupX1();
final double x2 = getGroupX2();
final Dimension2DDouble dim = new Dimension2DDouble(x2 - x1, height);
getComponent().drawU(ug.apply(new UTranslate(x1, 1)), new Area(dim), context);
} }
public void drawMe(UGraphic ug, double height, Context2D context) { private double getGroupX1() {
double result = leafs.get(0).getX1().getCurrentValue() - 6;
if (participants.size() > 0)
result = Math.min(result, getX1().getCurrentValue() - 6);
return result;
}
private double getGroupX2() {
double result = leafs.get(leafs.size() - 1).getX2().getCurrentValue() + 6;
if (participants.size() > 0)
result = Math.max(result, getX2().getCurrentValue() + 6);
return result;
}
public void drawMe(UGraphic ug, double height, Context2D context, Doll group) {
final double x1 = getX1().getCurrentValue() - 4; final double x1 = getX1().getCurrentValue() - 4;
final double x2 = getX2().getCurrentValue() + 4; final double x2 = getX2().getCurrentValue() + 4;
if (group != null) {
final double titlePreferredHeight = group.getTitlePreferredHeight();
ug = ug.apply(UTranslate.dy(titlePreferredHeight));
height -= titlePreferredHeight;
}
final Dimension2DDouble dim = new Dimension2DDouble(x2 - x1, height); final Dimension2DDouble dim = new Dimension2DDouble(x2 - x1, height);
getComponent().drawU(ug.apply(new UTranslate(x1, 1)), new Area(dim), context); getComponent().drawU(ug.apply(new UTranslate(x1, 1)), new Area(dim), context);
} }
private Real getX2() { private Real getX1() {
return RealUtils.max(getPosD(), core2).addFixed(marginX); if (core1 == null)
return getPosB().addFixed(-marginX);
return RealUtils.min(getPosB(), core1).addFixed(-marginX);
} }
private Real getX1() { private Real getX2() {
return RealUtils.min(getPosB(), core1).addFixed(-marginX); if (core2 == null)
return getPosD().addFixed(marginX);
return RealUtils.max(getPosD(), core2).addFixed(marginX);
} }
public void addInternalConstraints() { public void addInternalConstraints() {
@ -205,22 +235,22 @@ public class DollLeaf extends DollAbstract {
final double x1 = getX1().getCurrentValue(); final double x1 = getX1().getCurrentValue();
final double x2 = getX2().getCurrentValue(); final double x2 = getX2().getCurrentValue();
final double actualWidth = x2 - x1; final double actualWidth = x2 - x1;
if (titleWidth > actualWidth + 20) { if (titleWidth > actualWidth + 20)
this.marginX = (titleWidth - actualWidth - 20) / 2; this.marginX = (titleWidth - actualWidth - 20) / 2;
}
getX1().ensureBiggerThan(getPosAA().addFixed(10 + padding())); getX1().ensureBiggerThan(getPosAA().addFixed(10 + padding()));
final Real posZZ = getPosZZ(); final Real posZZ = getPosZZ();
final Real limit = getX2().addFixed(10 + padding()); final Real limit = getX2().addFixed(10 + padding());
if (posZZ != null) { if (posZZ != null)
posZZ.ensureBiggerThan(limit); posZZ.ensureBiggerThan(limit);
}
} }
private double padding() { private double padding() {
return tileArguments.getSkinParam().getPadding(PaddingParam.BOX); return tileArguments.getSkinParam().getPadding(PaddingParam.BOX);
} }
public void addConstraintAfter(DollLeaf current) { public void addConstraintAfter(Doll current) {
current.getX1().ensureBiggerThan(getX2().addFixed(10 + 2 * padding())); current.getX1().ensureBiggerThan(getX2().addFixed(10 + 2 * padding()));
} }

View File

@ -35,11 +35,13 @@
*/ */
package net.sourceforge.plantuml.sequencediagram; package net.sourceforge.plantuml.sequencediagram;
import java.util.Objects;
import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.SkinParamBackcolored;
import net.sourceforge.plantuml.sequencediagram.teoz.TileArguments; import net.sourceforge.plantuml.sequencediagram.teoz.TileArguments;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder; import net.sourceforge.plantuml.style.StyleBuilder;
@ -52,11 +54,13 @@ public abstract class DollAbstract implements WithStyle {
final protected ParticipantEnglober englober; final protected ParticipantEnglober englober;
final protected StyleBuilder styleBuilder; final protected StyleBuilder styleBuilder;
final protected boolean isTeoz; final protected boolean isTeoz;
final protected TileArguments tileArguments;
DollAbstract(ParticipantEnglober englober, StyleBuilder styleBuilder, boolean isTeoz) { DollAbstract(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz) {
this.englober = englober; this.englober = Objects.requireNonNull(englober);
this.styleBuilder = styleBuilder; this.styleBuilder = styleBuilder;
this.isTeoz = isTeoz; this.isTeoz = isTeoz;
this.tileArguments = Objects.requireNonNull(tileArguments);
} }
final public StyleSignature getDefaultStyleDefinition() { final public StyleSignature getDefaultStyleDefinition() {
@ -66,20 +70,29 @@ public abstract class DollAbstract implements WithStyle {
final public Style[] getUsedStyles() { final public Style[] getUsedStyles() {
Style tmp = getDefaultStyleDefinition().with(englober.getStereotype()).getMergedStyle(styleBuilder); Style tmp = getDefaultStyleDefinition().with(englober.getStereotype()).getMergedStyle(styleBuilder);
final HColor backColor = englober.getBoxColor(); final HColor backColor = englober.getBoxColor();
if (tmp != null) { if (tmp != null)
tmp = tmp.eventuallyOverride(PName.BackGroundColor, backColor); tmp = tmp.eventuallyOverride(PName.BackGroundColor, backColor);
}
return new Style[] { tmp };
}
private static TileArguments convertFunctionToBeRemoved(ISkinParam skinParam, Rose skin, return new Style[] { tmp };
StringBounder stringBounder) {
final TileArguments result = new TileArguments(stringBounder, null, skin, skinParam, null);
return result;
} }
final public ParticipantEnglober getParticipantEnglober() { final public ParticipantEnglober getParticipantEnglober() {
return englober; return englober;
} }
final protected Component getComponent() {
final ParticipantEnglober englober = getParticipantEnglober();
final ISkinParam s = englober.getBoxColor() == null ? tileArguments.getSkinParam()
: new SkinParamBackcolored(tileArguments.getSkinParam(), englober.getBoxColor());
return tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, s,
englober.getTitle());
}
public double getTitlePreferredHeight() {
final Component comp = tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null,
tileArguments.getSkinParam(), getParticipantEnglober().getTitle());
return comp.getPreferredHeight(tileArguments.getStringBounder());
}
} }

View File

@ -46,6 +46,11 @@ public class ParticipantEnglober {
final private HColor boxColor; final private HColor boxColor;
final private Stereotype stereotype; final private Stereotype stereotype;
@Override
public String toString() {
return title.toString();
}
public static ParticipantEnglober build(Display title, HColor boxColor, Stereotype stereotype) { public static ParticipantEnglober build(Display title, HColor boxColor, Stereotype stereotype) {
return new ParticipantEnglober(null, title, boxColor, stereotype); return new ParticipantEnglober(null, title, boxColor, stereotype);
} }

View File

@ -55,7 +55,7 @@ import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.graphic.InnerStrategy; import net.sourceforge.plantuml.graphic.InnerStrategy;
import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.sequencediagram.DollLeaf; import net.sourceforge.plantuml.sequencediagram.Doll;
import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.sequencediagram.Event;
import net.sourceforge.plantuml.sequencediagram.Newpage; import net.sourceforge.plantuml.sequencediagram.Newpage;
import net.sourceforge.plantuml.sequencediagram.Participant; import net.sourceforge.plantuml.sequencediagram.Participant;
@ -142,7 +142,7 @@ public class DrawableSet {
public double getHeadAndEngloberHeight(Participant p, StringBounder stringBounder) { public double getHeadAndEngloberHeight(Participant p, StringBounder stringBounder) {
final LivingParticipantBox box = participants.get(p); final LivingParticipantBox box = participants.get(p);
final double height = box.getParticipantBox().getHeadHeight(stringBounder); final double height = box.getParticipantBox().getHeadHeight(stringBounder);
final DollLeaf doll = getParticipantEnglober(p, stringBounder); final Doll doll = getParticipantEnglober(p, stringBounder);
if (doll == null) if (doll == null)
return height; return height;
@ -152,9 +152,9 @@ public class DrawableSet {
return height + heightEnglober; return height + heightEnglober;
} }
public List<DollLeaf> getExistingParticipantEnglober(StringBounder stringBounder) { public List<Doll> getExistingParticipantEnglober(StringBounder stringBounder) {
final List<DollLeaf> result = new ArrayList<>(); final List<Doll> result = new ArrayList<>();
DollLeaf pending = null; Doll pending = null;
for (Map.Entry<Participant, ParticipantEnglober> ent : participantEnglobers2.entrySet()) { for (Map.Entry<Participant, ParticipantEnglober> ent : participantEnglobers2.entrySet()) {
final ParticipantEnglober englober = ent.getValue(); final ParticipantEnglober englober = ent.getValue();
if (englober == null) { if (englober == null) {
@ -163,10 +163,10 @@ public class DrawableSet {
} }
assert englober != null; assert englober != null;
if (pending != null && englober == pending.getParticipantEnglober()) { if (pending != null && englober == pending.getParticipantEnglober()) {
pending.add(ent.getKey()); pending.addParticipant(ent.getKey());
continue; continue;
} }
pending = DollLeaf.createPuma(englober, ent.getKey(), getSkinParam(), skin, stringBounder, pending = Doll.createPuma(englober, ent.getKey(), getSkinParam(), skin, stringBounder,
skinParam.getCurrentStyleBuilder()); skinParam.getCurrentStyleBuilder());
result.add(pending); result.add(pending);
} }
@ -175,7 +175,7 @@ public class DrawableSet {
public double getOffsetForEnglobers(StringBounder stringBounder) { public double getOffsetForEnglobers(StringBounder stringBounder) {
double result = 0; double result = 0;
for (DollLeaf englober : getExistingParticipantEnglober(stringBounder)) { for (Doll englober : getExistingParticipantEnglober(stringBounder)) {
final Component comp = skin.createComponent(null, ComponentType.ENGLOBER, null, skinParam, final Component comp = skin.createComponent(null, ComponentType.ENGLOBER, null, skinParam,
englober.getParticipantEnglober().getTitle()); englober.getParticipantEnglober().getTitle());
final double height = comp.getPreferredHeight(stringBounder); final double height = comp.getPreferredHeight(stringBounder);
@ -363,7 +363,7 @@ public class DrawableSet {
} }
private void drawDolls(UGraphic ug, double height, Context2D context) { private void drawDolls(UGraphic ug, double height, Context2D context) {
for (DollLeaf doll : getExistingParticipantEnglober(ug.getStringBounder())) { for (Doll doll : getExistingParticipantEnglober(ug.getStringBounder())) {
double x1 = getX1(doll); double x1 = getX1(doll);
final double x2 = getX2(ug.getStringBounder(), doll); final double x2 = getX2(ug.getStringBounder(), doll);
@ -384,11 +384,11 @@ public class DrawableSet {
} }
} }
public double getEngloberPreferedWidth(StringBounder stringBounder, DollLeaf doll) { public double getEngloberPreferedWidth(StringBounder stringBounder, Doll doll) {
return getEngloberComponent(doll).getPreferredWidth(stringBounder); return getEngloberComponent(doll).getPreferredWidth(stringBounder);
} }
private Component getEngloberComponent(DollLeaf doll) { private Component getEngloberComponent(Doll doll) {
final ParticipantEnglober participantEnglober = doll.getParticipantEnglober(); final ParticipantEnglober participantEnglober = doll.getParticipantEnglober();
final ISkinParam s = participantEnglober.getBoxColor() == null ? skinParam final ISkinParam s = participantEnglober.getBoxColor() == null ? skinParam
: new SkinParamBackcolored(skinParam, participantEnglober.getBoxColor()); : new SkinParamBackcolored(skinParam, participantEnglober.getBoxColor());
@ -396,13 +396,13 @@ public class DrawableSet {
participantEnglober.getTitle()); participantEnglober.getTitle());
} }
public double getX1(DollLeaf doll) { public double getX1(Doll doll) {
final Participant first = doll.getFirst2TOBEPRIVATE(); final Participant first = doll.getFirst2TOBEPRIVATE();
final ParticipantBox firstBox = participants.get(first).getParticipantBox(); final ParticipantBox firstBox = participants.get(first).getParticipantBox();
return firstBox.getStartingX() + 1; return firstBox.getStartingX() + 1;
} }
public double getX2(StringBounder stringBounder, DollLeaf doll) { public double getX2(StringBounder stringBounder, Doll doll) {
final Participant last = doll.getLast2TOBEPRIVATE(); final Participant last = doll.getLast2TOBEPRIVATE();
final ParticipantBox lastBox = participants.get(last).getParticipantBox(); final ParticipantBox lastBox = participants.get(last).getParticipantBox();
return lastBox.getMaxX(stringBounder) - 1; return lastBox.getMaxX(stringBounder) - 1;
@ -415,8 +415,8 @@ public class DrawableSet {
line.drawU(ug, getSkin(), skinParam); line.drawU(ug, getSkin(), skinParam);
} }
private DollLeaf getParticipantEnglober(Participant p, StringBounder stringBounder) { private Doll getParticipantEnglober(Participant p, StringBounder stringBounder) {
for (DollLeaf pe : getExistingParticipantEnglober(stringBounder)) for (Doll pe : getExistingParticipantEnglober(stringBounder))
if (pe.contains(p)) if (pe.contains(p))
return pe; return pe;

View File

@ -52,7 +52,7 @@ import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.sequencediagram.AbstractMessage; import net.sourceforge.plantuml.sequencediagram.AbstractMessage;
import net.sourceforge.plantuml.sequencediagram.Delay; import net.sourceforge.plantuml.sequencediagram.Delay;
import net.sourceforge.plantuml.sequencediagram.Divider; import net.sourceforge.plantuml.sequencediagram.Divider;
import net.sourceforge.plantuml.sequencediagram.DollLeaf; import net.sourceforge.plantuml.sequencediagram.Doll;
import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.sequencediagram.Event;
import net.sourceforge.plantuml.sequencediagram.GroupingLeaf; import net.sourceforge.plantuml.sequencediagram.GroupingLeaf;
import net.sourceforge.plantuml.sequencediagram.GroupingStart; import net.sourceforge.plantuml.sequencediagram.GroupingStart;
@ -214,7 +214,7 @@ class DrawableSetInitializer {
if (padding == 0) if (padding == 0)
return; return;
for (DollLeaf pe : drawableSet.getExistingParticipantEnglober(stringBounder)) { for (Doll pe : drawableSet.getExistingParticipantEnglober(stringBounder)) {
final ParticipantBox first = drawableSet.getLivingParticipantBox(pe.getFirst2TOBEPRIVATE()) final ParticipantBox first = drawableSet.getLivingParticipantBox(pe.getFirst2TOBEPRIVATE())
.getParticipantBox(); .getParticipantBox();
final ParticipantBox last = drawableSet.getLivingParticipantBox(pe.getLast2TOBEPRIVATE()) final ParticipantBox last = drawableSet.getLivingParticipantBox(pe.getLast2TOBEPRIVATE())
@ -225,7 +225,7 @@ class DrawableSetInitializer {
} }
private void takeParticipantEngloberTitleWidth(StringBounder stringBounder) { private void takeParticipantEngloberTitleWidth(StringBounder stringBounder) {
for (DollLeaf doll : drawableSet.getExistingParticipantEnglober(stringBounder)) { for (Doll doll : drawableSet.getExistingParticipantEnglober(stringBounder)) {
final double preferredWidth = drawableSet.getEngloberPreferedWidth(stringBounder, doll); final double preferredWidth = drawableSet.getEngloberPreferedWidth(stringBounder, doll);
final ParticipantBox first = drawableSet.getLivingParticipantBox(doll.getFirst2TOBEPRIVATE()) final ParticipantBox first = drawableSet.getLivingParticipantBox(doll.getFirst2TOBEPRIVATE())
.getParticipantBox(); .getParticipantBox();

View File

@ -36,12 +36,14 @@
package net.sourceforge.plantuml.sequencediagram.teoz; package net.sourceforge.plantuml.sequencediagram.teoz;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.real.Real;
import net.sourceforge.plantuml.real.RealUtils; import net.sourceforge.plantuml.real.RealUtils;
import net.sourceforge.plantuml.sequencediagram.DollLeaf; import net.sourceforge.plantuml.sequencediagram.Doll;
import net.sourceforge.plantuml.sequencediagram.Participant; import net.sourceforge.plantuml.sequencediagram.Participant;
import net.sourceforge.plantuml.sequencediagram.ParticipantEnglober; import net.sourceforge.plantuml.sequencediagram.ParticipantEnglober;
import net.sourceforge.plantuml.skin.Context2D; import net.sourceforge.plantuml.skin.Context2D;
@ -49,10 +51,12 @@ import net.sourceforge.plantuml.ugraphic.UGraphic;
public class Dolls { public class Dolls {
private final List<DollLeaf> dolls = new ArrayList<>(); private final List<Doll> dolls = new ArrayList<>();
private final Map<ParticipantEnglober, Doll> groups = new HashMap<>();
public Dolls(TileArguments tileArguments) { public Dolls(TileArguments tileArguments) {
DollLeaf pending = null; Doll pending = null;
for (Participant p : tileArguments.getLivingSpaces().participants()) { for (Participant p : tileArguments.getLivingSpaces().participants()) {
final ParticipantEnglober englober = tileArguments.getLivingSpaces().get(p).getEnglober(); final ParticipantEnglober englober = tileArguments.getLivingSpaces().get(p).getEnglober();
if (englober == null) { if (englober == null) {
@ -61,11 +65,25 @@ public class Dolls {
} }
assert englober != null; assert englober != null;
if (pending != null && englober == pending.getParticipantEnglober()) { if (pending != null && englober == pending.getParticipantEnglober()) {
pending.add(p); pending.addParticipant(p);
continue; continue;
} }
pending = DollLeaf.createTeoz(englober, p, tileArguments,
if (groups.containsKey(englober)) {
groups.get(englober).addParticipant(p);
continue;
}
final ParticipantEnglober parent = englober.getParent();
pending = Doll.createTeoz(englober, p, tileArguments,
tileArguments.getSkinParam().getCurrentStyleBuilder()); tileArguments.getSkinParam().getCurrentStyleBuilder());
if (parent != null && groups.containsKey(parent) == false)
groups.put(parent, Doll.createGroup(parent, tileArguments,
tileArguments.getSkinParam().getCurrentStyleBuilder(), true));
if (parent != null)
getParent(pending).addDoll(pending);
dolls.add(pending); dolls.add(pending);
} }
} }
@ -76,8 +94,12 @@ public class Dolls {
public double getOffsetForEnglobers(StringBounder stringBounder) { public double getOffsetForEnglobers(StringBounder stringBounder) {
double result = 0; double result = 0;
for (DollLeaf doll : dolls) { for (Doll doll : dolls) {
final double height = doll.getPreferredHeight(); double height = doll.getTitlePreferredHeight();
final Doll group = getParent(doll);
if (group != null)
height += group.getTitlePreferredHeight();
if (height > result) if (height > result)
result = height; result = height;
@ -86,8 +108,8 @@ public class Dolls {
} }
public void addConstraints(StringBounder stringBounder) { public void addConstraints(StringBounder stringBounder) {
DollLeaf last = null; Doll last = null;
for (DollLeaf doll : dolls) { for (Doll doll : dolls) {
doll.addInternalConstraints(); doll.addInternalConstraints();
if (last != null) if (last != null)
last.addConstraintAfter(doll); last.addConstraintAfter(doll);
@ -96,9 +118,32 @@ public class Dolls {
} }
} }
private Doll getParent(Doll doll) {
final ParticipantEnglober parent = doll.getParticipantEnglober().getParent();
if (parent == null)
return null;
return groups.get(parent);
}
public void drawEnglobers(UGraphic ug, double height, Context2D context) { public void drawEnglobers(UGraphic ug, double height, Context2D context) {
for (DollLeaf doll : dolls) for (Doll group : groups.values()) {
doll.drawMe(ug, height, context); group.drawGroup(ug, height, context);
}
// DollGroup pending = null;
// for (DollLeaf doll : dolls) {
// final DollGroup group = doll.getGroup();
// if (group==null) {
//
// }
// // if (pending==null || pending.equals(group))
// if (group != null) {
// // group.drawMe(ug, height, context, doll.getX1().getCurrentValue(), doll.getX2().getCurrentValue());
// }
// }
for (Doll doll : dolls)
doll.drawMe(ug, height, context, getParent(doll));
} }
@ -107,7 +152,7 @@ public class Dolls {
throw new IllegalStateException(); throw new IllegalStateException();
final List<Real> result = new ArrayList<>(); final List<Real> result = new ArrayList<>();
for (DollLeaf doll : dolls) for (Doll doll : dolls)
result.add(doll.getMinX(stringBounder)); result.add(doll.getMinX(stringBounder));
return RealUtils.min(result); return RealUtils.min(result);
@ -118,7 +163,7 @@ public class Dolls {
throw new IllegalStateException(); throw new IllegalStateException();
final List<Real> result = new ArrayList<>(); final List<Real> result = new ArrayList<>();
for (DollLeaf doll : dolls) for (Doll doll : dolls)
result.add(doll.getMaxX(stringBounder)); result.add(doll.getMaxX(stringBounder));
return RealUtils.max(result); return RealUtils.max(result);

View File

@ -80,7 +80,7 @@ public class Version {
} }
public static int beta() { public static int beta() {
final int beta = 8; final int beta = 9;
return beta; return beta;
} }