plantuml/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java

654 lines
27 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2010-11-15 20:35:36 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.sequencediagram.graphic;
import java.util.ArrayList;
import java.util.List;
2021-05-09 21:14:40 +00:00
import java.util.Objects;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ISkinParam;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.OptionFlags;
2017-02-26 16:26:11 +00:00
import net.sourceforge.plantuml.PaddingParam;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.SkinParamBackcolored;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.SkinParamBackcoloredReference;
2022-09-12 20:08:34 +00:00
import net.sourceforge.plantuml.awt.geom.XDimension2D;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.sequencediagram.AbstractMessage;
2011-01-12 19:06:53 +00:00
import net.sourceforge.plantuml.sequencediagram.Delay;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.sequencediagram.Divider;
2022-01-04 17:21:17 +00:00
import net.sourceforge.plantuml.sequencediagram.Doll;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.sequencediagram.Event;
import net.sourceforge.plantuml.sequencediagram.GroupingLeaf;
import net.sourceforge.plantuml.sequencediagram.GroupingStart;
import net.sourceforge.plantuml.sequencediagram.GroupingType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.sequencediagram.HSpace;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.sequencediagram.InGroupableList;
import net.sourceforge.plantuml.sequencediagram.LifeEvent;
import net.sourceforge.plantuml.sequencediagram.LifeEventType;
import net.sourceforge.plantuml.sequencediagram.Message;
import net.sourceforge.plantuml.sequencediagram.MessageExo;
import net.sourceforge.plantuml.sequencediagram.Newpage;
import net.sourceforge.plantuml.sequencediagram.Note;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.sequencediagram.Notes;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.sequencediagram.Participant;
import net.sourceforge.plantuml.sequencediagram.ParticipantEnglober;
import net.sourceforge.plantuml.sequencediagram.ParticipantType;
2011-04-19 16:50:40 +00:00
import net.sourceforge.plantuml.sequencediagram.Reference;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
2019-03-01 22:16:29 +00:00
import net.sourceforge.plantuml.skin.rose.Rose;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.Style;
2010-11-15 20:35:36 +00:00
class DrawableSetInitializer {
2011-01-23 19:36:52 +00:00
private ComponentType defaultLineType;
2010-11-15 20:35:36 +00:00
private final DrawableSet drawableSet;
private final boolean showTail;
private double freeX = 0;
2013-12-10 19:36:50 +00:00
private Frontier freeY2 = null;
private Frontier lastFreeY2 = null;
2010-11-15 20:35:36 +00:00
private final double autonewpage;
private ConstraintSet constraintSet;
2019-03-01 22:16:29 +00:00
public DrawableSetInitializer(Rose skin, ISkinParam skinParam, boolean showTail, double autonewpage) {
2010-11-15 20:35:36 +00:00
this.drawableSet = new DrawableSet(skin, skinParam);
this.showTail = showTail;
this.autonewpage = autonewpage;
}
2013-12-10 19:36:50 +00:00
private boolean useContinueLineBecauseOfDelay() {
final String strategy = drawableSet.getSkinParam().getValue("lifelineStrategy");
if ("nosolid".equalsIgnoreCase(strategy))
2013-12-10 19:36:50 +00:00
return false;
if ("solid".equalsIgnoreCase(strategy))
2015-04-07 18:18:37 +00:00
return true;
for (Event ev : drawableSet.getAllEvents())
if (ev instanceof Delay)
2011-01-23 19:36:52 +00:00
return true;
2011-01-23 19:36:52 +00:00
return false;
}
2013-12-10 19:36:50 +00:00
private ParticipantRange getFullParticipantRange() {
return new ParticipantRange(0, drawableSet.getAllParticipants().size());
}
private ParticipantRange getParticipantRange(Event ev) {
return getFullParticipantRange();
}
2015-04-07 18:18:37 +00:00
// private int getParticipantRangeIndex(Participant participant) {
// int r = 0;
// for (Participant p : drawableSet.getAllParticipants()) {
// r++;
// if (p == participant) {
// return r;
// }
// }
// throw new IllegalArgumentException();
// }
2013-12-10 19:36:50 +00:00
2010-11-15 20:35:36 +00:00
public DrawableSet createDrawableSet(StringBounder stringBounder) {
if (freeY2 != null)
2010-11-15 20:35:36 +00:00
throw new IllegalStateException();
2013-12-10 19:36:50 +00:00
this.defaultLineType = useContinueLineBecauseOfDelay() ? ComponentType.CONTINUE_LINE
: ComponentType.PARTICIPANT_LINE;
2011-01-23 19:36:52 +00:00
for (Participant p : drawableSet.getAllParticipants())
2010-11-15 20:35:36 +00:00
prepareParticipant(stringBounder, p);
2021-06-27 16:50:40 +00:00
this.freeY2 = new FrontierStackImpl(drawableSet.getHeadHeight(stringBounder),
drawableSet.getAllParticipants().size());
2011-01-05 18:23:06 +00:00
2013-12-10 19:36:50 +00:00
this.lastFreeY2 = this.freeY2;
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
drawableSet.setTopStartingY(this.freeY2.getFreeY(getFullParticipantRange()));
2010-11-15 20:35:36 +00:00
for (Participant p : drawableSet.getAllParticipants()) {
final LivingParticipantBox living = drawableSet.getLivingParticipantBox(p);
for (int i = 0; i < p.getInitialLife(); i++)
2013-12-10 19:36:50 +00:00
living.getLifeLine().addSegmentVariation(LifeSegmentVariation.LARGER,
2015-09-06 17:28:59 +00:00
freeY2.getFreeY(getFullParticipantRange()), p.getLiveSpecificBackColors());
2010-11-15 20:35:36 +00:00
}
2021-05-14 08:42:57 +00:00
final List<ParticipantBox> col = new ArrayList<>();
for (LivingParticipantBox livingParticipantBox : drawableSet.getAllLivingParticipantBox())
2010-11-15 20:35:36 +00:00
col.add(livingParticipantBox.getParticipantBox());
constraintSet = new ConstraintSet(col, freeX);
2021-05-14 08:42:57 +00:00
for (Event ev : new ArrayList<>(drawableSet.getAllEvents())) {
2013-12-10 19:36:50 +00:00
final ParticipantRange range = getParticipantRange(ev);
final double diffY = freeY2.getFreeY(range) - lastFreeY2.getFreeY(range);
// final double diffY = freeY2.diff(lastFreeY2);
if (autonewpage > 0 && diffY > 0 && diffY + getTotalHeight(0, stringBounder) > autonewpage)
2013-12-10 19:36:50 +00:00
prepareNewpageSpecial(stringBounder, new Newpage(null), ev, range);
if (ev instanceof MessageExo)
2013-12-10 19:36:50 +00:00
prepareMessageExo(stringBounder, (MessageExo) ev, range);
else if (ev instanceof Message)
2013-12-10 19:36:50 +00:00
prepareMessage(stringBounder, (Message) ev, range);
else if (ev instanceof Note)
2013-12-10 19:36:50 +00:00
prepareNote(stringBounder, (Note) ev, range);
else if (ev instanceof Notes)
2013-12-10 19:36:50 +00:00
prepareNotes(stringBounder, (Notes) ev, range);
else if (ev instanceof LifeEvent)
2015-04-07 18:18:37 +00:00
prepareLiveEvent(stringBounder, (LifeEvent) ev, range);
else if (ev instanceof GroupingLeaf)
2013-12-10 19:36:50 +00:00
prepareGroupingLeaf(stringBounder, (GroupingLeaf) ev, range);
else if (ev instanceof GroupingStart)
2013-12-10 19:36:50 +00:00
prepareGroupingStart(stringBounder, (GroupingStart) ev, range);
else if (ev instanceof Newpage)
2013-12-10 19:36:50 +00:00
prepareNewpage(stringBounder, (Newpage) ev, range);
else if (ev instanceof Divider)
2013-12-10 19:36:50 +00:00
prepareDivider(stringBounder, (Divider) ev, range);
else if (ev instanceof HSpace)
2013-12-10 19:36:50 +00:00
prepareHSpace(stringBounder, (HSpace) ev, range);
else if (ev instanceof Delay)
2013-12-10 19:36:50 +00:00
prepareDelay(stringBounder, (Delay) ev, col, range);
else if (ev instanceof Reference)
2013-12-10 19:36:50 +00:00
prepareReference(stringBounder, (Reference) ev, range);
else
2010-11-15 20:35:36 +00:00
throw new IllegalStateException();
2010-11-15 20:35:36 +00:00
}
2017-02-26 16:26:11 +00:00
takeParticipantEngloberPadding(stringBounder);
2010-11-15 20:35:36 +00:00
constraintSet.takeConstraintIntoAccount(stringBounder);
2017-02-26 16:26:11 +00:00
takeParticipantEngloberTitleWidth(stringBounder);
2010-11-15 20:35:36 +00:00
prepareMissingSpace(stringBounder);
2022-09-12 20:08:34 +00:00
drawableSet.setDimension(new XDimension2D(freeX,
2021-06-27 16:50:40 +00:00
getTotalHeight(freeY2.getFreeY(getFullParticipantRange()), stringBounder)));
2010-11-15 20:35:36 +00:00
return drawableSet;
}
2017-02-26 16:26:11 +00:00
private void takeParticipantEngloberPadding(StringBounder stringBounder) {
final double padding = drawableSet.getSkinParam().getPadding(PaddingParam.BOX);
if (padding == 0)
2017-02-26 16:26:11 +00:00
return;
2022-01-04 17:21:17 +00:00
for (Doll pe : drawableSet.getExistingParticipantEnglober(stringBounder)) {
2017-02-26 16:26:11 +00:00
final ParticipantBox first = drawableSet.getLivingParticipantBox(pe.getFirst2TOBEPRIVATE())
.getParticipantBox();
final ParticipantBox last = drawableSet.getLivingParticipantBox(pe.getLast2TOBEPRIVATE())
.getParticipantBox();
constraintSet.pushToLeftParticipantBox(padding, first, true);
constraintSet.pushToLeftParticipantBox(padding, last, false);
}
}
private void takeParticipantEngloberTitleWidth(StringBounder stringBounder) {
2022-01-04 17:21:17 +00:00
for (Doll doll : drawableSet.getExistingParticipantEnglober(stringBounder)) {
final double preferredWidth = drawableSet.getEngloberPreferedWidth(stringBounder, doll);
final ParticipantBox first = drawableSet.getLivingParticipantBox(doll.getFirst2TOBEPRIVATE())
2015-07-11 09:32:49 +00:00
.getParticipantBox();
final ParticipantBox last = drawableSet.getLivingParticipantBox(doll.getLast2TOBEPRIVATE())
2015-07-11 09:32:49 +00:00
.getParticipantBox();
final double x1 = drawableSet.getX1(doll);
final double x2 = drawableSet.getX2(stringBounder, doll);
2011-03-20 21:40:07 +00:00
final double missing = preferredWidth - (x2 - x1);
2011-04-19 16:50:40 +00:00
if (missing > 0) {
constraintSet.pushToLeftParticipantBox(missing / 2, first, true);
constraintSet.pushToLeftParticipantBox(missing / 2, last, false);
2011-03-20 21:40:07 +00:00
}
}
}
2010-11-15 20:35:36 +00:00
private double getTotalHeight(double y, StringBounder stringBounder) {
final double signature = 0;
return y + drawableSet.getTailHeight(stringBounder, showTail) + signature;
}
public double getYposition(StringBounder stringBounder, Newpage newpage) {
2021-06-27 16:50:40 +00:00
final GraphicalNewpage graphicalNewpage = (GraphicalNewpage) drawableSet
.getEvent(Objects.requireNonNull(newpage));
2010-11-15 20:35:36 +00:00
return graphicalNewpage.getStartingY();
}
private void prepareMissingSpace(StringBounder stringBounder) {
freeX = constraintSet.getMaxX();
double missingSpace1 = 0;
double missingSpace2 = 0;
for (GraphicalElement ev : drawableSet.getAllGraphicalElements()) {
2013-12-10 19:36:50 +00:00
if (ev instanceof GraphicalDelayText) {
final double missing = ev.getPreferredWidth(stringBounder) - freeX;
if (missing > 0) {
missingSpace1 = Math.max(missingSpace1, missing / 2);
missingSpace2 = Math.max(missingSpace2, missing / 2);
}
continue;
}
2010-11-15 20:35:36 +00:00
final double startX = ev.getStartingX(stringBounder);
final double delta1 = -startX;
if (delta1 > missingSpace1)
2010-11-15 20:35:36 +00:00
missingSpace1 = delta1;
2010-11-15 20:35:36 +00:00
if (ev instanceof Arrow) {
final Arrow a = (Arrow) ev;
a.setMaxX(freeX);
}
double width = ev.getPreferredWidth(stringBounder);
if (ev instanceof Arrow) {
final Arrow a = (Arrow) ev;
if (width < a.getActualWidth(stringBounder))
2010-11-15 20:35:36 +00:00
width = a.getActualWidth(stringBounder);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
if (ev instanceof GroupingGraphicalElementHeader) {
final GroupingGraphicalElementHeader gh = (GroupingGraphicalElementHeader) ev;
if (width < gh.getActualWidth(stringBounder))
2011-01-05 18:23:06 +00:00
width = gh.getActualWidth(stringBounder);
2011-01-05 18:23:06 +00:00
}
2010-11-15 20:35:36 +00:00
final double endX = startX + width;
final double delta2 = endX - freeX;
if (delta2 > missingSpace2)
2010-11-15 20:35:36 +00:00
missingSpace2 = delta2;
}
2011-01-05 18:23:06 +00:00
if (missingSpace1 > 0)
2010-11-15 20:35:36 +00:00
constraintSet.pushToLeft(missingSpace1);
2010-11-15 20:35:36 +00:00
freeX = constraintSet.getMaxX() + missingSpace2;
}
2013-12-10 19:36:50 +00:00
private void prepareNewpage(StringBounder stringBounder, Newpage newpage, ParticipantRange range) {
2021-06-27 16:50:40 +00:00
final GraphicalNewpage graphicalNewpage = new GraphicalNewpage(freeY2.getFreeY(range),
drawableSet.getSkin().createComponentNewPage(drawableSet.getSkinParam()));
2013-12-10 19:36:50 +00:00
this.lastFreeY2 = freeY2;
freeY2 = freeY2.add(graphicalNewpage.getPreferredHeight(stringBounder), range);
2010-11-15 20:35:36 +00:00
drawableSet.addEvent(newpage, graphicalNewpage);
}
2013-12-10 19:36:50 +00:00
private void prepareNewpageSpecial(StringBounder stringBounder, Newpage newpage, Event justBefore,
ParticipantRange range) {
2021-06-27 16:50:40 +00:00
final GraphicalNewpage graphicalNewpage = new GraphicalNewpage(freeY2.getFreeY(range),
drawableSet.getSkin().createComponentNewPage(drawableSet.getSkinParam()));
2013-12-10 19:36:50 +00:00
this.lastFreeY2 = freeY2;
freeY2 = freeY2.add(graphicalNewpage.getPreferredHeight(stringBounder), range);
2010-11-15 20:35:36 +00:00
drawableSet.addEvent(newpage, graphicalNewpage, justBefore);
}
2013-12-10 19:36:50 +00:00
private void prepareDivider(StringBounder stringBounder, Divider divider, ParticipantRange range) {
2021-06-27 16:50:40 +00:00
final GraphicalDivider graphicalDivider = new GraphicalDivider(freeY2.getFreeY(range),
drawableSet.getSkin().createComponent(divider.getUsedStyles(), ComponentType.DIVIDER, null,
drawableSet.getSkinParam(), divider.getText()));
2013-12-10 19:36:50 +00:00
freeY2 = freeY2.add(graphicalDivider.getPreferredHeight(stringBounder), range);
2010-11-15 20:35:36 +00:00
drawableSet.addEvent(divider, graphicalDivider);
}
2013-12-10 19:36:50 +00:00
private void prepareHSpace(StringBounder stringBounder, HSpace hspace, ParticipantRange range) {
final GraphicalHSpace graphicalHSpace = new GraphicalHSpace(freeY2.getFreeY(range), hspace.getPixel());
freeY2 = freeY2.add(graphicalHSpace.getPreferredHeight(stringBounder), range);
drawableSet.addEvent(hspace, graphicalHSpace);
}
private void prepareDelay(StringBounder stringBounder, Delay delay, List<ParticipantBox> participants,
ParticipantRange range) {
2019-07-14 20:09:26 +00:00
final Component compText = drawableSet.getSkin().createComponent(delay.getUsedStyles(),
ComponentType.DELAY_TEXT, null, drawableSet.getSkinParam(), delay.getText());
2013-12-10 19:36:50 +00:00
final ParticipantBox first = participants.get(0);
final ParticipantBox last = participants.get(participants.size() - 1);
final GraphicalDelayText graphicalDivider = new GraphicalDelayText(freeY2.getFreeY(range), compText, first,
last);
for (ParticipantBox p : participants)
2011-01-12 19:06:53 +00:00
p.addDelay(graphicalDivider);
2013-12-10 19:36:50 +00:00
freeY2 = freeY2.add(graphicalDivider.getPreferredHeight(stringBounder), range);
2011-01-12 19:06:53 +00:00
drawableSet.addEvent(delay, graphicalDivider);
}
2013-12-10 19:36:50 +00:00
final private InGroupablesStack inGroupableStack = new InGroupablesStack();
2010-11-15 20:35:36 +00:00
2019-07-14 20:09:26 +00:00
private void prepareGroupingStart(StringBounder stringBounder, GroupingStart start, ParticipantRange range) {
if (start.getType() != GroupingType.START)
2010-11-15 20:35:36 +00:00
throw new IllegalStateException();
2019-07-14 20:09:26 +00:00
final ISkinParam skinParam = new SkinParamBackcolored(drawableSet.getSkinParam(), start.getBackColorElement(),
start.getBackColorGeneral());
2013-12-10 19:36:50 +00:00
2019-07-14 20:09:26 +00:00
final Component comp = drawableSet.getSkin().createComponent(null, ComponentType.GROUPING_SPACE, null,
skinParam, Display.create(start.getComment()));
2013-12-10 19:36:50 +00:00
final double preferredHeight = comp.getPreferredHeight(stringBounder);
freeY2 = freeY2.add(preferredHeight, range);
2021-06-27 16:50:40 +00:00
final Display strings = start.getTitle().equals("group") ? Display.create(start.getComment())
: Display.create(start.getTitle(), start.getComment());
2019-07-14 20:09:26 +00:00
final Component header = drawableSet.getSkin().createComponent(start.getUsedStyles(),
ComponentType.GROUPING_HEADER, null, skinParam, strings);
2013-12-10 19:36:50 +00:00
final ParticipantBox veryfirst = drawableSet.getVeryfirst();
2019-07-14 20:09:26 +00:00
final InGroupableList inGroupableList = new InGroupableList(veryfirst, start, freeY2.getFreeY(range));
2013-12-10 19:36:50 +00:00
inGroupableStack.addList(inGroupableList);
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
final GraphicalElement element = new GroupingGraphicalElementHeader(freeY2.getFreeY(range), header,
2019-07-14 20:09:26 +00:00
inGroupableList, start.isParallel());
2010-11-15 20:35:36 +00:00
inGroupableList.setMinWidth(element.getPreferredWidth(stringBounder));
2013-12-10 19:36:50 +00:00
freeY2 = freeY2.add(element.getPreferredHeight(stringBounder), range);
2019-07-14 20:09:26 +00:00
drawableSet.addEvent(start, element);
if (start.isParallel())
2013-12-10 19:36:50 +00:00
freeY2 = ((FrontierStack) freeY2).openBar();
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private void prepareGroupingLeaf(StringBounder stringBounder, final GroupingLeaf m, ParticipantRange range) {
2010-11-15 20:35:36 +00:00
final GraphicalElement element;
2021-06-27 16:50:40 +00:00
final ISkinParam skinParam = new SkinParamBackcolored(drawableSet.getSkinParam(), null,
m.getBackColorGeneral());
2010-11-15 20:35:36 +00:00
if (m.getType() == GroupingType.ELSE) {
if (m.isParallel())
2013-12-10 19:36:50 +00:00
freeY2 = ((FrontierStack) freeY2).restore();
2019-07-14 20:09:26 +00:00
final Component compElse = drawableSet.getSkin().createComponent(m.getUsedStyles(),
2022-10-05 20:32:57 +00:00
ComponentType.GROUPING_ELSE_LEGACY, null, skinParam, Display.create(m.getComment()));
2013-12-10 19:36:50 +00:00
final Lazy lazy = new Lazy() {
public double getNow() {
final GraphicalElement after = drawableSet.getEvent(m.getJustAfter());
if (after == null)
2013-12-10 19:36:50 +00:00
return 0;
2013-12-10 19:36:50 +00:00
return after.getStartingY();
}
};
element = new GroupingGraphicalElementElse(freeY2.getFreeY(range), compElse,
inGroupableStack.getTopGroupingStructure(), m.isParallel(), lazy);
final double preferredHeight = element.getPreferredHeight(stringBounder);
freeY2 = freeY2.add(preferredHeight, range);
2015-04-07 18:18:37 +00:00
// MODIF42
inGroupableStack.addElement((GroupingGraphicalElementElse) element);
2010-11-15 20:35:36 +00:00
} else if (m.getType() == GroupingType.END) {
2021-05-14 08:42:57 +00:00
final List<Component> notes = new ArrayList<>();
2018-06-25 19:05:58 +00:00
for (Note noteOnMessage : m.getNoteOnMessages()) {
final ISkinParam sk = noteOnMessage.getSkinParamBackcolored(drawableSet.getSkinParam());
2021-06-27 16:50:40 +00:00
final Component note = drawableSet.getSkin().createComponentNote(noteOnMessage.getUsedStyles(),
2022-08-30 19:15:53 +00:00
noteOnMessage.getNoteStyle().getNoteComponentType(), sk, noteOnMessage.getStrings(),
noteOnMessage.getColors());
2017-03-12 17:22:02 +00:00
notes.add(note);
}
if (m.isParallel())
2013-12-10 19:36:50 +00:00
freeY2 = ((FrontierStack) freeY2).closeBar();
2013-12-10 19:36:50 +00:00
final GroupingGraphicalElementHeader groupingHeaderStart = (GroupingGraphicalElementHeader) drawableSet
.getEvent(m.getGroupingStart());
if (groupingHeaderStart != null) {
groupingHeaderStart.setEndY(freeY2.getFreeY(range));
2017-03-12 17:22:02 +00:00
groupingHeaderStart.addNotes(stringBounder, notes);
2013-12-10 19:36:50 +00:00
}
element = new GroupingGraphicalElementTail(freeY2.getFreeY(range),
inGroupableStack.getTopGroupingStructure(), m.isParallel());
2019-07-14 20:09:26 +00:00
final Component comp = drawableSet.getSkin().createComponent(null, ComponentType.GROUPING_SPACE, null,
skinParam, Display.create(m.getComment()));
2013-12-10 19:36:50 +00:00
final double preferredHeight = comp.getPreferredHeight(stringBounder);
freeY2 = freeY2.add(preferredHeight, range);
inGroupableStack.pop();
} else
2010-11-15 20:35:36 +00:00
throw new IllegalStateException();
2010-11-15 20:35:36 +00:00
drawableSet.addEvent(m, element);
2013-12-10 19:36:50 +00:00
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private void prepareNote(StringBounder stringBounder, Note n, ParticipantRange range) {
final NoteBox noteBox = createNoteBox(stringBounder, n, range);
inGroupableStack.addElement(noteBox);
drawableSet.addEvent(n, noteBox);
freeY2 = freeY2.add(noteBox.getPreferredHeight(stringBounder), range);
}
private NoteBox createNoteBox(StringBounder stringBounder, Note n, ParticipantRange range) {
2010-11-15 20:35:36 +00:00
LivingParticipantBox p1 = drawableSet.getLivingParticipantBox(n.getParticipant());
LivingParticipantBox p2;
if (n.getParticipant2() == null)
2010-11-15 20:35:36 +00:00
p2 = null;
else {
2010-11-15 20:35:36 +00:00
p2 = drawableSet.getLivingParticipantBox(n.getParticipant2());
if (p1.getParticipantBox().getCenterX(stringBounder) > p2.getParticipantBox().getCenterX(stringBounder)) {
final LivingParticipantBox tmp = p1;
p1 = p2;
p2 = tmp;
}
}
2015-05-03 15:36:36 +00:00
final ISkinParam skinParam = n.getSkinParamBackcolored(drawableSet.getSkinParam());
2019-07-14 20:09:26 +00:00
final ComponentType type = n.getNoteStyle().getNoteComponentType();
if (p1 == null && p2 == null)
2019-06-26 19:24:49 +00:00
for (LivingParticipantBox p : drawableSet.getAllLivingParticipantBox()) {
if (p1 == null)
2019-06-26 19:24:49 +00:00
p1 = p;
2019-06-26 19:24:49 +00:00
p2 = p;
}
2021-06-27 16:50:40 +00:00
final Component component = drawableSet.getSkin().createComponentNote(n.getUsedStyles(), type, skinParam,
2022-08-30 19:15:53 +00:00
n.getStrings(), n.getColors(), n.getPosition());
2021-06-27 16:50:40 +00:00
final NoteBox noteBox = new NoteBox(freeY2.getFreeY(range), component, p1, p2, n.getPosition(), n.getUrl());
2013-12-10 19:36:50 +00:00
return noteBox;
}
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
private void prepareNotes(StringBounder stringBounder, Notes notes, ParticipantRange range) {
final NotesBoxes notesBoxes = new NotesBoxes(freeY2.getFreeY(range));
for (Note n : notes) {
final NoteBox noteBox = createNoteBox(stringBounder, n, range);
final ParticipantBox p1 = drawableSet.getLivingParticipantBox(n.getParticipant()).getParticipantBox();
2021-06-27 16:50:40 +00:00
final ParticipantBox p2 = n.getParticipant2() == null ? null
: drawableSet.getLivingParticipantBox(n.getParticipant2()).getParticipantBox();
2013-12-10 19:36:50 +00:00
notesBoxes.add(noteBox, p1, p2);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
notesBoxes.ensureConstraints(stringBounder, constraintSet);
inGroupableStack.addElement(notesBoxes);
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
drawableSet.addEvent(notes, notesBoxes);
freeY2 = freeY2.add(notesBoxes.getPreferredHeight(stringBounder), range);
2010-11-15 20:35:36 +00:00
}
2015-04-07 18:18:37 +00:00
private void prepareLiveEvent(StringBounder stringBounder, LifeEvent lifeEvent, ParticipantRange range) {
final double y = freeY2.getFreeY(range);
final AbstractMessage message = lifeEvent.getMessage();
if (lifeEvent.getType() == LifeEventType.ACTIVATE) {
double pos = 0;
if (message != null) {
int delta1 = 0;
if (message.isCreate())
2015-04-07 18:18:37 +00:00
delta1 += 10;
else if (OptionFlags.STRICT_SELFMESSAGE_POSITION && message.isSelfMessage())
2015-04-07 18:18:37 +00:00
delta1 += 8;
2015-04-07 18:18:37 +00:00
pos = message.getPosYstartLevel() + delta1;
}
final LifeLine line1 = drawableSet.getLivingParticipantBox(lifeEvent.getParticipant()).getLifeLine();
2015-09-06 17:28:59 +00:00
line1.addSegmentVariation(LifeSegmentVariation.LARGER, pos, lifeEvent.getSpecificColors());
2015-04-07 18:18:37 +00:00
} else if (lifeEvent.getType() == LifeEventType.DESTROY || lifeEvent.getType() == LifeEventType.DEACTIVATE) {
double delta = 0;
if (OptionFlags.STRICT_SELFMESSAGE_POSITION && message != null && message.isSelfMessage())
2015-04-07 18:18:37 +00:00
delta += 7;
2015-04-07 18:18:37 +00:00
final Participant p = lifeEvent.getParticipant();
final LifeLine line = drawableSet.getLivingParticipantBox(p).getLifeLine();
double pos2 = y;
if (message != null)
2015-04-07 18:18:37 +00:00
pos2 = message.getPosYendLevel() - delta;
2015-09-06 17:28:59 +00:00
line.addSegmentVariation(LifeSegmentVariation.SMALLER, pos2, lifeEvent.getSpecificColors());
2015-04-07 18:18:37 +00:00
}
if (lifeEvent.getType() == LifeEventType.DESTROY) {
2019-07-14 20:09:26 +00:00
final Component comp = drawableSet.getSkin().createComponent(null, ComponentType.DESTROY, null,
2015-04-07 18:18:37 +00:00
drawableSet.getSkinParam(), null);
final double delta = comp.getPreferredHeight(stringBounder) / 2;
2021-06-27 16:50:40 +00:00
final LivingParticipantBox livingParticipantBox = drawableSet
.getLivingParticipantBox(lifeEvent.getParticipant());
2015-07-11 09:32:49 +00:00
double pos2 = y;
if (message == null) {
pos2 = y;
freeY2 = freeY2.add(comp.getPreferredHeight(stringBounder), range);
} else
2015-07-11 09:32:49 +00:00
pos2 = message.getPosYendLevel() - delta;
2015-07-11 09:32:49 +00:00
final LifeDestroy destroy = new LifeDestroy(pos2, livingParticipantBox.getParticipantBox(), comp);
2015-04-07 18:18:37 +00:00
drawableSet.addEvent(lifeEvent, destroy);
} else
2015-04-07 18:18:37 +00:00
drawableSet.addEvent(lifeEvent, new GraphicalElementLiveEvent(y));
}
private void prepareMessageExo(StringBounder stringBounder, MessageExo m, ParticipantRange range) {
final Step1MessageExo step1Message = new Step1MessageExo(range, stringBounder, m, drawableSet, freeY2);
freeY2 = step1Message.prepareMessage(constraintSet, inGroupableStack);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private void prepareMessage(StringBounder stringBounder, Message m, ParticipantRange range) {
final Step1Message step1Message = new Step1Message(range, stringBounder, m, drawableSet, freeY2);
freeY2 = step1Message.prepareMessage(constraintSet, inGroupableStack);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private void prepareReference(StringBounder stringBounder, Reference reference, ParticipantRange range) {
2021-06-27 16:50:40 +00:00
final LivingParticipantBox p1 = drawableSet
.getLivingParticipantBox(drawableSet.getFirst(reference.getParticipant()));
final LivingParticipantBox p2 = drawableSet
.getLivingParticipantBox(drawableSet.getLast(reference.getParticipant()));
2013-12-10 19:36:50 +00:00
final ISkinParam skinParam = new SkinParamBackcoloredReference(drawableSet.getSkinParam(),
reference.getBackColorElement(), reference.getBackColorGeneral());
2011-08-08 17:48:29 +00:00
2015-04-07 18:18:37 +00:00
Display strings = Display.empty();
2013-12-10 19:36:50 +00:00
strings = strings.add("ref");
strings = strings.addAll(reference.getStrings());
2021-06-27 16:50:40 +00:00
final Component comp = drawableSet.getSkin().createComponent(reference.getUsedStyles(), ComponentType.REFERENCE,
null, skinParam, strings);
2013-12-10 19:36:50 +00:00
final GraphicalReference graphicalReference = new GraphicalReference(freeY2.getFreeY(range), comp, p1, p2,
reference.getUrl());
2011-08-08 17:48:29 +00:00
final ParticipantBox pbox1 = p1.getParticipantBox();
final ParticipantBox pbox2 = p2.getParticipantBox();
2011-04-19 16:50:40 +00:00
final double width = graphicalReference.getPreferredWidth(stringBounder)
2011-08-08 17:48:29 +00:00
- pbox1.getPreferredWidth(stringBounder) / 2 - pbox2.getPreferredWidth(stringBounder) / 2;
2011-04-19 16:50:40 +00:00
2011-08-08 17:48:29 +00:00
final Constraint constraint;
if (p1 == p2)
2011-08-08 17:48:29 +00:00
constraint = constraintSet.getConstraintAfter(pbox1);
else
2011-08-08 17:48:29 +00:00
constraint = constraintSet.getConstraint(pbox1, pbox2);
2011-08-08 17:48:29 +00:00
constraint.ensureValue(width);
2013-12-10 19:36:50 +00:00
inGroupableStack.addElement(graphicalReference);
inGroupableStack.addElement(p1);
if (p1 != p2)
2013-12-10 19:36:50 +00:00
inGroupableStack.addElement(p2);
2011-04-19 16:50:40 +00:00
2013-12-10 19:36:50 +00:00
freeY2 = freeY2.add(graphicalReference.getPreferredHeight(stringBounder), range);
2011-04-19 16:50:40 +00:00
drawableSet.addEvent(reference, graphicalReference);
}
2010-11-15 20:35:36 +00:00
private void prepareParticipant(StringBounder stringBounder, Participant p) {
2013-12-10 19:36:50 +00:00
final ComponentType headType;
final ComponentType tailType;
2010-11-15 20:35:36 +00:00
if (p.getType() == ParticipantType.PARTICIPANT) {
2013-12-10 19:36:50 +00:00
headType = ComponentType.PARTICIPANT_HEAD;
tailType = ComponentType.PARTICIPANT_TAIL;
2010-11-15 20:35:36 +00:00
} else if (p.getType() == ParticipantType.ACTOR) {
2013-12-10 19:36:50 +00:00
headType = ComponentType.ACTOR_HEAD;
tailType = ComponentType.ACTOR_TAIL;
} else if (p.getType() == ParticipantType.BOUNDARY) {
headType = ComponentType.BOUNDARY_HEAD;
tailType = ComponentType.BOUNDARY_TAIL;
} else if (p.getType() == ParticipantType.CONTROL) {
headType = ComponentType.CONTROL_HEAD;
tailType = ComponentType.CONTROL_TAIL;
} else if (p.getType() == ParticipantType.ENTITY) {
headType = ComponentType.ENTITY_HEAD;
tailType = ComponentType.ENTITY_TAIL;
2017-06-05 11:27:21 +00:00
} else if (p.getType() == ParticipantType.QUEUE) {
headType = ComponentType.QUEUE_HEAD;
tailType = ComponentType.QUEUE_TAIL;
2013-12-10 19:36:50 +00:00
} else if (p.getType() == ParticipantType.DATABASE) {
headType = ComponentType.DATABASE_HEAD;
tailType = ComponentType.DATABASE_TAIL;
2016-06-19 14:16:41 +00:00
} else if (p.getType() == ParticipantType.COLLECTIONS) {
headType = ComponentType.COLLECTIONS_HEAD;
tailType = ComponentType.COLLECTIONS_TAIL;
2010-11-15 20:35:36 +00:00
} else {
throw new IllegalArgumentException();
}
2015-04-07 18:18:37 +00:00
2022-05-21 09:41:00 +00:00
final ISkinParam skinParam = drawableSet.getSkinParam();
2013-12-10 19:36:50 +00:00
final Display participantDisplay = p.getDisplay(skinParam.forceSequenceParticipantUnderlined());
2019-07-14 20:09:26 +00:00
final Component head = drawableSet.getSkin().createComponent(p.getUsedStyles(), headType, null, skinParam,
participantDisplay);
final Component tail = drawableSet.getSkin().createComponent(p.getUsedStyles(), tailType, null, skinParam,
participantDisplay);
2022-03-01 18:11:51 +00:00
final Style style = this.defaultLineType.getStyleSignature().withTOBECHANGED(p.getStereotype())
2021-06-27 16:50:40 +00:00
.getMergedStyle(skinParam.getCurrentStyleBuilder());
2019-07-14 20:09:26 +00:00
final Component line = drawableSet.getSkin().createComponent(new Style[] { style }, this.defaultLineType, null,
2013-12-10 19:36:50 +00:00
drawableSet.getSkinParam(), participantDisplay);
2019-07-14 20:09:26 +00:00
final Component delayLine = drawableSet.getSkin().createComponent(null, ComponentType.DELAY_LINE, null,
2013-12-10 19:36:50 +00:00
drawableSet.getSkinParam(), participantDisplay);
2016-02-07 21:13:01 +00:00
final ParticipantBox box = new ParticipantBox(head, line, tail, delayLine, this.freeX,
skinParam.maxAsciiMessageLength() > 0 ? 1 : 5);
2013-12-10 19:36:50 +00:00
2019-07-14 20:09:26 +00:00
final Component comp = drawableSet.getSkin().createComponent(
2022-02-12 17:27:51 +00:00
new Style[] { ComponentType.ALIVE_BOX_CLOSE_CLOSE.getStyleSignature()
2021-06-27 16:50:40 +00:00
.getMergedStyle(drawableSet.getSkinParam().getCurrentStyleBuilder()) },
ComponentType.ALIVE_BOX_CLOSE_CLOSE, null, drawableSet.getSkinParam(), null);
2010-11-15 20:35:36 +00:00
2021-06-27 16:50:40 +00:00
final LifeLine lifeLine = new LifeLine(box, comp.getPreferredWidth(stringBounder),
drawableSet.getSkinParam().shadowing(p.getStereotype()));
2011-02-14 11:56:34 +00:00
drawableSet.setLivingParticipantBox(p, new LivingParticipantBox(box, lifeLine));
2010-11-15 20:35:36 +00:00
this.freeX = box.getMaxX(stringBounder);
}
2011-02-14 11:56:34 +00:00
public void addParticipant(Participant p, ParticipantEnglober participantEnglober) {
drawableSet.addParticipant(p, participantEnglober);
2010-11-15 20:35:36 +00:00
}
public void addEvent(Event event) {
drawableSet.addEvent(event, null);
}
}