1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-29 14:40:47 +00:00
plantuml/src/net/sourceforge/plantuml/sequencediagram/graphic/Step1Message.java

289 lines
11 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;
2016-11-04 21:39:29 +00:00
import java.util.ArrayList;
import java.util.List;
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-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.PaddingParam;
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;
import net.sourceforge.plantuml.sequencediagram.InGroupable;
import net.sourceforge.plantuml.sequencediagram.Message;
2018-06-25 19:05:58 +00:00
import net.sourceforge.plantuml.sequencediagram.Note;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.sequencediagram.NotePosition;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.skin.ArrowBody;
2019-04-21 20:40:01 +00:00
import net.sourceforge.plantuml.skin.ArrowComponent;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.skin.ArrowConfiguration;
import net.sourceforge.plantuml.skin.ArrowHead;
import net.sourceforge.plantuml.skin.Component;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.skin.ComponentType;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.Style;
2010-11-15 20:35:36 +00:00
class Step1Message extends Step1Abstract {
private final MessageArrow messageArrow;
2013-12-10 19:36:50 +00:00
Step1Message(ParticipantRange range, StringBounder stringBounder, Message message, DrawableSet drawingSet,
Frontier freeY) {
super(range, stringBounder, message, drawingSet, freeY);
2010-11-15 20:35:36 +00:00
final double x1 = getParticipantBox1().getCenterX(stringBounder);
final double x2 = getParticipantBox2().getCenterX(stringBounder);
2013-12-10 19:36:50 +00:00
this.setConfig(isSelfMessage() ? getSelfArrowType(message) : getArrowType(message, x1, x2));
2010-11-15 20:35:36 +00:00
if (isSelfMessage()) {
this.messageArrow = null;
} else {
2019-07-14 20:09:26 +00:00
final ArrowComponent comp = drawingSet.getSkin().createComponentArrow(message.getUsedStyles(), getConfig(),
2015-05-31 18:56:03 +00:00
drawingSet.getSkinParam(), message.getLabelNumbered());
2019-07-14 20:09:26 +00:00
final Component compAliveBox = drawingSet.getSkin().createComponent(
new Style[] { ComponentType.ALIVE_BOX_OPEN_OPEN.getDefaultStyleDefinition().getMergedStyle(
drawingSet.getSkinParam().getCurrentStyleBuilder()) }, ComponentType.ALIVE_BOX_OPEN_OPEN,
2013-12-10 19:36:50 +00:00
null, drawingSet.getSkinParam(), null);
this.messageArrow = new MessageArrow(freeY.getFreeY(range), drawingSet.getSkin(), comp,
getLivingParticipantBox1(), getLivingParticipantBox2(), message.getUrl(), compAliveBox);
2010-11-15 20:35:36 +00:00
}
2018-06-25 19:05:58 +00:00
final List<Note> noteOnMessages = message.getNoteOnMessages();
for (Note noteOnMessage : noteOnMessages) {
final ISkinParam skinParam = noteOnMessage.getSkinParamBackcolored(drawingSet.getSkinParam());
2019-07-14 20:09:26 +00:00
addNote(drawingSet.getSkin().createComponent(noteOnMessage.getUsedStyles(),
noteOnMessage.getNoteStyle().getNoteComponentType(), null, skinParam, noteOnMessage.getStrings()));
2010-11-15 20:35:36 +00:00
}
}
2013-12-10 19:36:50 +00:00
Frontier prepareMessage(ConstraintSet constraintSet, InGroupablesStack inGroupablesStack) {
2010-11-15 20:35:36 +00:00
final Arrow graphic = createArrow();
final double arrowYStartLevel = graphic.getArrowYStartLevel(getStringBounder());
final double arrowYEndLevel = graphic.getArrowYEndLevel(getStringBounder());
2011-01-11 07:42:49 +00:00
// final double delta1 = isSelfMessage() ? 4 : 0;
2010-11-15 20:35:36 +00:00
final double delta1 = 0;
2015-04-07 18:18:37 +00:00
getMessage().setPosYstartLevel(arrowYStartLevel + delta1);
2010-11-15 20:35:36 +00:00
final double length;
if (isSelfMessage()) {
length = graphic.getArrowOnlyWidth(getStringBounder())
2011-04-19 16:50:40 +00:00
+ getLivingParticipantBox1().getLiveThicknessAt(getStringBounder(), arrowYStartLevel).getSegment()
.getLength();
2010-11-15 20:35:36 +00:00
} else {
length = graphic.getArrowOnlyWidth(getStringBounder())
+ getLivingParticipantBox(NotePosition.LEFT).getLifeLine().getRightShift(arrowYStartLevel)
+ getLivingParticipantBox(NotePosition.RIGHT).getLifeLine().getLeftShift(arrowYStartLevel);
}
incFreeY(graphic.getPreferredHeight(getStringBounder()));
double marginActivateAndDeactive = 0;
if (getMessage().isActivateAndDeactive()) {
marginActivateAndDeactive = 30;
incFreeY(marginActivateAndDeactive);
}
getDrawingSet().addEvent(getMessage(), graphic);
if (isSelfMessage()) {
constraintSet.getConstraintAfter(getParticipantBox1()).ensureValue(length);
} else {
constraintSet.getConstraint(getParticipantBox1(), getParticipantBox2()).ensureValue(length);
}
2015-04-07 18:18:37 +00:00
final double posYendLevel = arrowYEndLevel + marginActivateAndDeactive - delta1;
getMessage().setPosYendLevel(posYendLevel);
2010-11-15 20:35:36 +00:00
2011-08-08 17:48:29 +00:00
assert graphic instanceof InGroupable;
2013-12-10 19:36:50 +00:00
if (graphic instanceof InGroupable) {
inGroupablesStack.addElement((InGroupable) graphic);
inGroupablesStack.addElement(getLivingParticipantBox1());
if (isSelfMessage() == false) {
inGroupablesStack.addElement(getLivingParticipantBox2());
2010-11-15 20:35:36 +00:00
}
}
return getFreeY();
}
private boolean isSelfMessage() {
return getParticipantBox1().equals(getParticipantBox2());
}
private ParticipantBox getParticipantBox1() {
return getLivingParticipantBox1().getParticipantBox();
}
private ParticipantBox getParticipantBox2() {
return getLivingParticipantBox2().getParticipantBox();
}
private LivingParticipantBox getLivingParticipantBox1() {
return getDrawingSet().getLivingParticipantBox(((Message) getMessage()).getParticipant1());
}
private LivingParticipantBox getLivingParticipantBox2() {
return getDrawingSet().getLivingParticipantBox(((Message) getMessage()).getParticipant2());
}
private LivingParticipantBox getLivingParticipantBox(NotePosition position) {
if (isSelfMessage()) {
throw new IllegalStateException();
}
return messageArrow.getParticipantAt(getStringBounder(), position);
}
private Arrow createArrow() {
if (getMessage().isCreate()) {
return createArrowCreate();
}
2016-11-04 21:39:29 +00:00
if (getMessage().getNoteOnMessages().size() > 0 && isSelfMessage()) {
2013-12-10 19:36:50 +00:00
final MessageSelfArrow messageSelfArrow = createMessageSelfArrow();
2016-11-04 21:39:29 +00:00
final List<NoteBox> noteBoxes = new ArrayList<NoteBox>();
for (int i = 0; i < getNotes().size(); i++) {
final Component note = getNotes().get(i);
2018-06-25 19:05:58 +00:00
final Note noteOnMessage = getMessage().getNoteOnMessages().get(i);
2019-09-22 17:20:16 +00:00
noteOnMessage.temporaryProtectedUntilTeozIsStandard();
2016-11-04 21:39:29 +00:00
noteBoxes.add(createNoteBox(getStringBounder(), messageSelfArrow, note, noteOnMessage));
}
return new ArrowAndNoteBox(getStringBounder(), messageSelfArrow, noteBoxes);
} else if (getMessage().getNoteOnMessages().size() > 0) {
final List<NoteBox> noteBoxes = new ArrayList<NoteBox>();
for (int i = 0; i < getNotes().size(); i++) {
final Component note = getNotes().get(i);
2018-06-25 19:05:58 +00:00
final Note noteOnMessage = getMessage().getNoteOnMessages().get(i);
2019-09-22 17:20:16 +00:00
noteOnMessage.temporaryProtectedUntilTeozIsStandard();
2016-11-04 21:39:29 +00:00
noteBoxes.add(createNoteBox(getStringBounder(), messageArrow, note, noteOnMessage));
}
return new ArrowAndNoteBox(getStringBounder(), messageArrow, noteBoxes);
2010-11-15 20:35:36 +00:00
} else if (isSelfMessage()) {
2013-12-10 19:36:50 +00:00
return createMessageSelfArrow();
2010-11-15 20:35:36 +00:00
} else {
return messageArrow;
}
}
2013-12-10 19:36:50 +00:00
private MessageSelfArrow createMessageSelfArrow() {
final double posY = getFreeY().getFreeY(getParticipantRange());
double deltaY = 0;
2015-04-07 18:18:37 +00:00
double deltaX = 0;
2013-12-10 19:36:50 +00:00
if (getMessage().isActivate()) {
deltaY -= getHalfLifeWidth();
2015-04-07 18:18:37 +00:00
if (OptionFlags.STRICT_SELFMESSAGE_POSITION) {
deltaX += 5;
}
2013-12-10 19:36:50 +00:00
}
if (getMessage().isDeactivate()) {
deltaY += getHalfLifeWidth();
}
2019-07-14 20:09:26 +00:00
final Style[] styles = getMessage().getUsedStyles();
final ArrowComponent comp = getDrawingSet().getSkin().createComponentArrow(styles, getConfig(),
getDrawingSet().getSkinParam(), getMessage().getLabelNumbered());
return new MessageSelfArrow(posY, getDrawingSet().getSkin(), comp, getLivingParticipantBox1(), deltaY,
getMessage().getUrl(), deltaX);
2013-12-10 19:36:50 +00:00
}
private double getHalfLifeWidth() {
return getDrawingSet()
.getSkin()
2019-07-14 20:09:26 +00:00
.createComponent(
new Style[] { ComponentType.ALIVE_BOX_OPEN_OPEN.getDefaultStyleDefinition().getMergedStyle(
getDrawingSet().getSkinParam().getCurrentStyleBuilder()) },
ComponentType.ALIVE_BOX_OPEN_OPEN, null, getDrawingSet().getSkinParam(), Display.create(""))
.getPreferredWidth(null) / 2;
2013-12-10 19:36:50 +00:00
}
2010-11-15 20:35:36 +00:00
private Arrow createArrowCreate() {
2013-12-10 19:36:50 +00:00
if (messageArrow == null) {
throw new IllegalStateException();
}
2017-03-15 19:13:31 +00:00
Arrow result = new ArrowAndParticipant(getStringBounder(), messageArrow, getParticipantBox2(), getDrawingSet()
.getSkinParam().getPadding(PaddingParam.PARTICIPANT));
2016-11-04 21:39:29 +00:00
if (getMessage().getNoteOnMessages().size() > 0) {
final List<NoteBox> noteBoxes = new ArrayList<NoteBox>();
for (int i = 0; i < getNotes().size(); i++) {
final Component note = getNotes().get(i);
2018-06-25 19:05:58 +00:00
final Note noteOnMessage = getMessage().getNoteOnMessages().get(i);
2016-11-04 21:39:29 +00:00
final NoteBox noteBox = createNoteBox(getStringBounder(), result, note, noteOnMessage);
2018-06-25 19:05:58 +00:00
if (noteOnMessage.getPosition() == NotePosition.RIGHT) {
2016-11-04 21:39:29 +00:00
noteBox.pushToRight(getParticipantBox2().getPreferredWidth(getStringBounder()) / 2);
}
noteBoxes.add(noteBox);
2010-11-15 20:35:36 +00:00
}
2016-11-04 21:39:29 +00:00
result = new ArrowAndNoteBox(getStringBounder(), result, noteBoxes);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
getLivingParticipantBox2().create(
getFreeY().getFreeY(getParticipantRange()) + result.getPreferredHeight(getStringBounder()) / 2);
2011-04-19 16:50:40 +00:00
return result;
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private ArrowConfiguration getSelfArrowType(Message m) {
// return m.getArrowConfiguration().self();
ArrowConfiguration result = ArrowConfiguration.withDirectionSelf();
2011-01-11 07:42:49 +00:00
if (m.getArrowConfiguration().isDotted()) {
2016-05-31 19:41:55 +00:00
result = result.withBody(ArrowBody.DOTTED);
}
if (m.getArrowConfiguration().isHidden()) {
result = result.withBody(ArrowBody.HIDDEN);
2011-01-11 07:42:49 +00:00
}
2013-12-10 19:36:50 +00:00
if (m.getArrowConfiguration().isAsync()) {
result = result.withHead(ArrowHead.ASYNC);
2011-01-11 07:42:49 +00:00
}
2015-04-07 18:18:37 +00:00
if (m.getArrowConfiguration().getDressing2().getHead() == ArrowHead.CROSSX) {
result = result.withHead2(m.getArrowConfiguration().getDressing2().getHead());
2019-09-14 18:12:04 +00:00
// System.err.println("WARNING : CROSSX");
// Thread.dumpStack();
2015-04-07 18:18:37 +00:00
// assert false;
}
2011-01-11 07:42:49 +00:00
result = result.withPart(m.getArrowConfiguration().getPart());
2013-12-10 19:36:50 +00:00
result = result.withColor(m.getArrowConfiguration().getColor());
2015-04-07 18:18:37 +00:00
result = result.withDecoration1(m.getArrowConfiguration().getDecoration1());
result = result.withDecoration2(m.getArrowConfiguration().getDecoration2());
2011-01-11 07:42:49 +00:00
return result;
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
private ArrowConfiguration getArrowType(Message m, final double x1, final double x2) {
2010-11-15 20:35:36 +00:00
if (x2 > x1) {
2013-12-10 19:36:50 +00:00
return m.getArrowConfiguration();
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
return m.getArrowConfiguration().reverse();
2010-11-15 20:35:36 +00:00
}
}