1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-28 22:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/sequencediagram/AbstractMessage.java

259 lines
6.7 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;
2016-11-04 21:39:29 +00:00
import java.util.ArrayList;
2015-04-07 18:18:37 +00:00
import java.util.EnumSet;
2013-12-10 19:36:50 +00:00
import java.util.HashSet;
2016-11-04 21:39:29 +00:00
import java.util.List;
2013-12-10 19:36:50 +00:00
import java.util.Set;
2010-11-15 20:35:36 +00:00
2011-04-19 16:50:40 +00:00
import net.sourceforge.plantuml.Url;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2011-01-11 07:42:49 +00:00
import net.sourceforge.plantuml.skin.ArrowConfiguration;
2019-09-22 17:20:16 +00:00
import net.sourceforge.plantuml.style.PName;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.style.StyleSignature;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.WithStyle;
2010-11-15 20:35:36 +00:00
2019-07-14 20:09:26 +00:00
public abstract class AbstractMessage implements EventWithDeactivate, WithStyle {
public Style[] getUsedStyles() {
2019-09-22 17:20:16 +00:00
Style style = getDefaultStyleDefinition().getMergedStyle(styleBuilder);
if (style != null && arrowConfiguration.getColor() != null) {
style = style.eventuallyOverride(PName.LineColor, arrowConfiguration.getColor());
}
return new Style[] { style };
2019-07-14 20:09:26 +00:00
}
2019-08-26 17:07:21 +00:00
public StyleSignature getDefaultStyleDefinition() {
2019-09-22 17:20:16 +00:00
return StyleSignature.of(SName.root, SName.element, SName.sequenceDiagram, SName.arrow);
2019-07-14 20:09:26 +00:00
}
2010-11-15 20:35:36 +00:00
2016-11-04 21:39:29 +00:00
private final Display label;
private final ArrowConfiguration arrowConfiguration;
private final Set<LifeEventType> lifeEventsType = EnumSet.noneOf(LifeEventType.class);
2015-04-07 18:18:37 +00:00
2017-03-12 17:22:02 +00:00
private Url url;
2010-11-15 20:35:36 +00:00
private final String messageNumber;
2015-04-07 18:18:37 +00:00
private boolean parallel = false;
2019-07-14 20:09:26 +00:00
private final StyleBuilder styleBuilder;
2010-11-15 20:35:36 +00:00
2018-06-25 19:05:58 +00:00
private List<Note> noteOnMessages = new ArrayList<Note>();
2016-11-04 21:39:29 +00:00
2019-07-14 20:09:26 +00:00
public AbstractMessage(StyleBuilder styleBuilder, Display label, ArrowConfiguration arrowConfiguration,
String messageNumber) {
this.styleBuilder = styleBuilder;
2017-03-12 17:22:02 +00:00
this.url = null;
this.label = label;
2011-01-11 07:42:49 +00:00
this.arrowConfiguration = arrowConfiguration;
2010-11-15 20:35:36 +00:00
this.messageNumber = messageNumber;
}
2018-06-25 19:05:58 +00:00
2017-03-12 17:22:02 +00:00
public final void setUrl(Url url) {
this.url = url;
}
2010-11-15 20:35:36 +00:00
2015-04-07 18:18:37 +00:00
public void goParallel() {
this.parallel = true;
}
2015-05-03 15:36:36 +00:00
2015-04-07 18:18:37 +00:00
public boolean isParallel() {
return parallel;
}
2013-12-10 19:36:50 +00:00
final public Url getUrl() {
if (url == null) {
2018-06-25 19:05:58 +00:00
for (Note n : noteOnMessages) {
if (n.getUrl() != null) {
return n.getUrl();
2016-11-04 21:39:29 +00:00
}
}
2013-12-10 19:36:50 +00:00
}
return url;
}
public boolean hasUrl() {
2018-06-25 19:05:58 +00:00
for (Note n : noteOnMessages) {
2016-11-04 21:39:29 +00:00
if (n.hasUrl()) {
return true;
}
2013-12-10 19:36:50 +00:00
}
if (label != null && label.hasUrl()) {
return true;
}
return getUrl() != null;
}
2015-04-07 18:18:37 +00:00
private boolean firstIsActivate = false;
private final Set<Participant> noActivationAuthorized2 = new HashSet<Participant>();
2013-12-10 19:36:50 +00:00
public final boolean addLifeEvent(LifeEvent lifeEvent) {
2015-04-07 18:18:37 +00:00
lifeEvent.setMessage(this);
lifeEventsType.add(lifeEvent.getType());
if (lifeEventsType.size() == 1 && isActivate()) {
firstIsActivate = true;
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
2013-12-10 19:36:50 +00:00
if (lifeEvent.getType() == LifeEventType.ACTIVATE
2015-04-07 18:18:37 +00:00
&& noActivationAuthorized2.contains(lifeEvent.getParticipant())) {
2013-12-10 19:36:50 +00:00
return false;
}
2015-04-07 18:18:37 +00:00
if (lifeEvent.getType() == LifeEventType.DEACTIVATE || lifeEvent.getType() == LifeEventType.DESTROY) {
noActivationAuthorized2.add(lifeEvent.getParticipant());
}
2013-12-10 19:36:50 +00:00
return true;
2010-11-15 20:35:36 +00:00
}
public final boolean isCreate() {
2015-04-07 18:18:37 +00:00
return lifeEventsType.contains(LifeEventType.CREATE);
2010-11-15 20:35:36 +00:00
}
2015-04-07 18:18:37 +00:00
public boolean isActivate() {
return lifeEventsType.contains(LifeEventType.ACTIVATE);
}
public boolean isDeactivate() {
return lifeEventsType.contains(LifeEventType.DEACTIVATE);
}
private boolean isDeactivateOrDestroy() {
return lifeEventsType.contains(LifeEventType.DEACTIVATE) || lifeEventsType.contains(LifeEventType.DESTROY);
2010-11-15 20:35:36 +00:00
}
2015-04-07 18:18:37 +00:00
public final boolean isActivateAndDeactive() {
return firstIsActivate && isDeactivateOrDestroy();
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
public final Display getLabel() {
return label;
2010-11-15 20:35:36 +00:00
}
2016-04-22 20:36:08 +00:00
2015-05-31 18:56:03 +00:00
public final Display getLabelNumbered() {
if (getMessageNumber() == null) {
return getLabel();
}
Display result = Display.empty();
result = result.add(new MessageNumber(getMessageNumber()));
result = result.addAll(getLabel());
return result;
}
2011-01-11 07:42:49 +00:00
public final ArrowConfiguration getArrowConfiguration() {
return arrowConfiguration;
2010-11-15 20:35:36 +00:00
}
2018-06-25 19:05:58 +00:00
public final List<Note> getNoteOnMessages() {
2016-11-04 21:39:29 +00:00
return noteOnMessages;
2011-04-19 16:50:40 +00:00
}
2018-06-25 19:05:58 +00:00
public final void setNote(Note note) {
2019-09-22 17:20:16 +00:00
if (note.getPosition() != NotePosition.LEFT && note.getPosition() != NotePosition.RIGHT
&& note.getPosition() != NotePosition.BOTTOM && note.getPosition() != NotePosition.TOP) {
2010-11-15 20:35:36 +00:00
throw new IllegalArgumentException();
}
2018-06-25 19:05:58 +00:00
note = note.withPosition(overideNotePosition(note.getPosition()));
this.noteOnMessages.add(note);
2013-12-10 19:36:50 +00:00
}
protected NotePosition overideNotePosition(NotePosition notePosition) {
return notePosition;
2010-11-15 20:35:36 +00:00
}
public final String getMessageNumber() {
return messageNumber;
}
2015-04-07 18:18:37 +00:00
public abstract boolean compatibleForCreate(Participant p);
public abstract boolean isSelfMessage();
private double posYendLevel;
private double posYstartLevel;
public double getPosYstartLevel() {
return posYstartLevel;
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
public void setPosYstartLevel(double posYstartLevel) {
this.posYstartLevel = posYstartLevel;
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
public void setPosYendLevel(double posYendLevel) {
this.posYendLevel = posYendLevel;
}
2013-12-10 19:36:50 +00:00
2015-04-07 18:18:37 +00:00
public double getPosYendLevel() {
return posYendLevel;
}
2019-02-09 21:56:24 +00:00
private String anchor;
2019-03-29 22:14:07 +00:00
private String anchor1;
private String anchor2;
2019-02-09 21:56:24 +00:00
public void setAnchor(String anchor) {
this.anchor = anchor;
if (anchor != null && anchor.startsWith("{")) {
throw new IllegalArgumentException(anchor);
}
}
2019-07-14 20:09:26 +00:00
2019-03-29 22:14:07 +00:00
public void setPart1Anchor(String anchor) {
this.anchor1 = anchor;
}
public void setPart2Anchor(String anchor) {
this.anchor2 = anchor;
}
2019-02-09 21:56:24 +00:00
public String getAnchor() {
return anchor;
}
2019-07-14 20:09:26 +00:00
2019-03-29 22:14:07 +00:00
public String getPart1Anchor() {
return this.anchor1;
}
public String getPart2Anchor() {
return this.anchor2;
}
2010-11-15 20:35:36 +00:00
}