1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 08:30:49 +00:00
plantuml/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java

644 lines
26 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, 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;
import net.sourceforge.plantuml.Dimension2DDouble;
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;
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;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.sequencediagram.Englober;
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;
import net.sourceforge.plantuml.skin.Skin;
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;
public DrawableSetInitializer(Skin skin, ISkinParam skinParam, boolean showTail, double autonewpage) {
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)) {
return false;
}
2015-04-07 18:18:37 +00:00
if ("solid".equalsIgnoreCase(strategy)) {
return true;
}
2011-01-23 19:36:52 +00:00
for (Event ev : drawableSet.getAllEvents()) {
if (ev instanceof Delay) {
return true;
}
}
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) {
2013-12-10 19:36:50 +00:00
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
2010-11-15 20:35:36 +00:00
for (Participant p : drawableSet.getAllParticipants()) {
prepareParticipant(stringBounder, p);
}
2013-12-10 19:36:50 +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
}
}
2013-12-10 19:36:50 +00:00
final List<ParticipantBox> col = new ArrayList<ParticipantBox>();
2010-11-15 20:35:36 +00:00
for (LivingParticipantBox livingParticipantBox : drawableSet.getAllLivingParticipantBox()) {
col.add(livingParticipantBox.getParticipantBox());
}
constraintSet = new ConstraintSet(col, freeX);
for (Event ev : new ArrayList<Event>(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);
2010-11-15 20:35:36 +00:00
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);
2010-11-15 20:35:36 +00:00
}
if (ev instanceof MessageExo) {
2013-12-10 19:36:50 +00:00
prepareMessageExo(stringBounder, (MessageExo) ev, range);
2010-11-15 20:35:36 +00:00
} else if (ev instanceof Message) {
2013-12-10 19:36:50 +00:00
prepareMessage(stringBounder, (Message) ev, range);
2010-11-15 20:35:36 +00:00
} else if (ev instanceof Note) {
2013-12-10 19:36:50 +00:00
prepareNote(stringBounder, (Note) ev, range);
} else if (ev instanceof Notes) {
prepareNotes(stringBounder, (Notes) ev, range);
2010-11-15 20:35:36 +00:00
} else if (ev instanceof LifeEvent) {
2015-04-07 18:18:37 +00:00
prepareLiveEvent(stringBounder, (LifeEvent) ev, range);
2010-11-15 20:35:36 +00:00
} else if (ev instanceof GroupingLeaf) {
2013-12-10 19:36:50 +00:00
prepareGroupingLeaf(stringBounder, (GroupingLeaf) ev, range);
2010-11-15 20:35:36 +00:00
} else if (ev instanceof GroupingStart) {
2013-12-10 19:36:50 +00:00
prepareGroupingStart(stringBounder, (GroupingStart) ev, range);
2010-11-15 20:35:36 +00:00
} else if (ev instanceof Newpage) {
2013-12-10 19:36:50 +00:00
prepareNewpage(stringBounder, (Newpage) ev, range);
2010-11-15 20:35:36 +00:00
} else if (ev instanceof Divider) {
2013-12-10 19:36:50 +00:00
prepareDivider(stringBounder, (Divider) ev, range);
} else if (ev instanceof HSpace) {
prepareHSpace(stringBounder, (HSpace) ev, range);
2011-01-12 19:06:53 +00:00
} else if (ev instanceof Delay) {
2013-12-10 19:36:50 +00:00
prepareDelay(stringBounder, (Delay) ev, col, range);
2011-04-19 16:50:40 +00:00
} else if (ev instanceof Reference) {
2013-12-10 19:36:50 +00:00
prepareReference(stringBounder, (Reference) ev, range);
2010-11-15 20:35:36 +00:00
} else {
throw new IllegalStateException();
}
}
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);
2013-12-10 19:36:50 +00:00
drawableSet.setDimension(new Dimension2DDouble(freeX, 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) {
return;
}
for (Englober pe : drawableSet.getExistingParticipantEnglober(stringBounder)) {
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) {
2016-08-25 20:45:37 +00:00
for (Englober pe : drawableSet.getExistingParticipantEnglober(stringBounder)) {
2013-12-10 19:36:50 +00:00
final double preferredWidth = drawableSet.getEngloberPreferedWidth(stringBounder,
pe.getParticipantEnglober());
2015-07-11 09:32:49 +00:00
final ParticipantBox first = drawableSet.getLivingParticipantBox(pe.getFirst2TOBEPRIVATE())
.getParticipantBox();
final ParticipantBox last = drawableSet.getLivingParticipantBox(pe.getLast2TOBEPRIVATE())
.getParticipantBox();
2011-03-20 21:40:07 +00:00
final double x1 = drawableSet.getX1(pe);
final double x2 = drawableSet.getX2(stringBounder, pe);
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) {
if (newpage == null) {
throw new IllegalArgumentException();
}
final GraphicalNewpage graphicalNewpage = (GraphicalNewpage) drawableSet.getEvent(newpage);
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) {
missingSpace1 = delta1;
}
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)) {
width = a.getActualWidth(stringBounder);
}
}
2013-12-10 19:36:50 +00:00
if (ev instanceof GroupingGraphicalElementHeader) {
final GroupingGraphicalElementHeader gh = (GroupingGraphicalElementHeader) ev;
2011-01-05 18:23:06 +00:00
if (width < gh.getActualWidth(stringBounder)) {
width = gh.getActualWidth(stringBounder);
}
}
2010-11-15 20:35:36 +00:00
final double endX = startX + width;
final double delta2 = endX - freeX;
if (delta2 > missingSpace2) {
missingSpace2 = delta2;
}
}
2011-01-05 18:23:06 +00:00
2010-11-15 20:35:36 +00:00
if (missingSpace1 > 0) {
constraintSet.pushToLeft(missingSpace1);
}
freeX = constraintSet.getMaxX() + missingSpace2;
}
2013-12-10 19:36:50 +00:00
private void prepareNewpage(StringBounder stringBounder, Newpage newpage, ParticipantRange range) {
final GraphicalNewpage graphicalNewpage = new GraphicalNewpage(freeY2.getFreeY(range), drawableSet.getSkin()
.createComponent(ComponentType.NEWPAGE, null, drawableSet.getSkinParam(), null));
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) {
final GraphicalNewpage graphicalNewpage = new GraphicalNewpage(freeY2.getFreeY(range), drawableSet.getSkin()
.createComponent(ComponentType.NEWPAGE, null, drawableSet.getSkinParam(), null));
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) {
final GraphicalDivider graphicalDivider = new GraphicalDivider(freeY2.getFreeY(range), drawableSet.getSkin()
.createComponent(ComponentType.DIVIDER, null, drawableSet.getSkinParam(), divider.getText()));
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) {
final Component compText = drawableSet.getSkin().createComponent(ComponentType.DELAY_TEXT, null,
2011-01-12 19:06:53 +00:00
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);
2011-01-12 19:06:53 +00:00
for (ParticipantBox p : participants) {
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
2013-12-10 19:36:50 +00:00
private void prepareGroupingStart(StringBounder stringBounder, GroupingStart m, ParticipantRange range) {
2010-11-15 20:35:36 +00:00
if (m.getType() != GroupingType.START) {
throw new IllegalStateException();
}
2013-12-10 19:36:50 +00:00
final ISkinParam skinParam = new SkinParamBackcolored(drawableSet.getSkinParam(), m.getBackColorElement(),
m.getBackColorGeneral());
final Component comp = drawableSet.getSkin().createComponent(ComponentType.GROUPING_SPACE, null, skinParam,
2015-04-07 18:18:37 +00:00
Display.create(m.getComment()));
2013-12-10 19:36:50 +00:00
final double preferredHeight = comp.getPreferredHeight(stringBounder);
freeY2 = freeY2.add(preferredHeight, range);
2015-04-07 18:18:37 +00:00
final Display strings = m.getTitle().equals("group") ? Display.create(m.getComment()) : Display.create(
2013-12-10 19:36:50 +00:00
m.getTitle(), m.getComment());
final Component header = drawableSet.getSkin().createComponent(ComponentType.GROUPING_HEADER, null, skinParam,
2010-11-15 20:35:36 +00:00
strings);
2013-12-10 19:36:50 +00:00
final ParticipantBox veryfirst = drawableSet.getVeryfirst();
final InGroupableList inGroupableList = new InGroupableList(veryfirst, m, freeY2.getFreeY(range));
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,
inGroupableList, m.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);
2010-11-15 20:35:36 +00:00
drawableSet.addEvent(m, element);
2013-12-10 19:36:50 +00:00
if (m.isParallel()) {
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;
2013-12-10 19:36:50 +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) {
2013-12-10 19:36:50 +00:00
if (m.isParallel()) {
freeY2 = ((FrontierStack) freeY2).restore();
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
final Component compElse = drawableSet.getSkin().createComponent(ComponentType.GROUPING_ELSE, null,
2015-04-07 18:18:37 +00:00
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) {
return 0;
}
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) {
2017-03-12 17:22:02 +00:00
final List<Component> notes = new ArrayList<Component>();
2018-06-25 19:05:58 +00:00
for (Note noteOnMessage : m.getNoteOnMessages()) {
final ISkinParam sk = noteOnMessage.getSkinParamBackcolored(drawableSet.getSkinParam());
2017-03-12 17:22:02 +00:00
final Component note = drawableSet.getSkin().createComponent(
2018-06-25 19:05:58 +00:00
noteOnMessage.getStyle().getNoteComponentType(), null, sk, noteOnMessage.getStrings());
2017-03-12 17:22:02 +00:00
notes.add(note);
}
2013-12-10 19:36:50 +00:00
if (m.isParallel()) {
freeY2 = ((FrontierStack) freeY2).closeBar();
2010-11-15 20:35:36 +00:00
}
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());
final Component comp = drawableSet.getSkin().createComponent(ComponentType.GROUPING_SPACE, null, skinParam,
2015-04-07 18:18:37 +00:00
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();
2010-11-15 20:35:36 +00:00
} else {
throw new IllegalStateException();
}
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) {
p2 = null;
} else {
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());
2016-04-22 20:36:08 +00:00
final ComponentType type = n.getStyle().getNoteComponentType();
2013-12-10 19:36:50 +00:00
final NoteBox noteBox = new NoteBox(freeY2.getFreeY(range), drawableSet.getSkin().createComponent(type, null,
skinParam, n.getStrings()), p1, p2, n.getPosition(), n.getUrl());
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();
final ParticipantBox p2 = n.getParticipant2() == null ? null : drawableSet.getLivingParticipantBox(
n.getParticipant2()).getParticipantBox();
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()) {
delta1 += 10;
} else if (OptionFlags.STRICT_SELFMESSAGE_POSITION && message.isSelfMessage()) {
delta1 += 8;
}
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()) {
delta += 7;
}
final Participant p = lifeEvent.getParticipant();
final LifeLine line = drawableSet.getLivingParticipantBox(p).getLifeLine();
double pos2 = y;
if (message != null) {
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) {
final Component comp = drawableSet.getSkin().createComponent(ComponentType.DESTROY, null,
drawableSet.getSkinParam(), null);
final double delta = comp.getPreferredHeight(stringBounder) / 2;
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 {
pos2 = message.getPosYendLevel() - delta;
}
final LifeDestroy destroy = new LifeDestroy(pos2, livingParticipantBox.getParticipantBox(), comp);
2015-04-07 18:18:37 +00:00
drawableSet.addEvent(lifeEvent, destroy);
} else {
drawableSet.addEvent(lifeEvent, new GraphicalElementLiveEvent(y));
2010-11-15 20:35:36 +00:00
}
2015-04-07 18:18:37 +00:00
}
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) {
2011-08-08 17:48:29 +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());
final Component comp = drawableSet.getSkin().createComponent(ComponentType.REFERENCE, null, skinParam, strings);
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) {
constraint = constraintSet.getConstraintAfter(pbox1);
} else {
constraint = constraintSet.getConstraint(pbox1, pbox2);
}
constraint.ensureValue(width);
2013-12-10 19:36:50 +00:00
inGroupableStack.addElement(graphicalReference);
inGroupableStack.addElement(p1);
if (p1 != p2) {
inGroupableStack.addElement(p2);
2011-08-08 17:48:29 +00:00
}
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
2015-05-03 15:36:36 +00:00
final ISkinParam skinParam = p.getSkinParamBackcolored(drawableSet.getSkinParam());
2013-12-10 19:36:50 +00:00
final Display participantDisplay = p.getDisplay(skinParam.forceSequenceParticipantUnderlined());
final Component head = drawableSet.getSkin().createComponent(headType, null, skinParam, participantDisplay);
final Component tail = drawableSet.getSkin().createComponent(tailType, null, skinParam, participantDisplay);
final Component line = drawableSet.getSkin().createComponent(this.defaultLineType, null,
drawableSet.getSkinParam(), participantDisplay);
final Component delayLine = drawableSet.getSkin().createComponent(ComponentType.DELAY_LINE, null,
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
final Component comp = drawableSet.getSkin().createComponent(ComponentType.ALIVE_BOX_CLOSE_CLOSE, null,
2010-11-15 20:35:36 +00:00
drawableSet.getSkinParam(), null);
2013-12-10 19:36:50 +00:00
final LifeLine lifeLine = new LifeLine(box, comp.getPreferredWidth(stringBounder), drawableSet.getSkinParam()
2018-09-23 12:15:14 +00:00
.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);
}
}