plantuml/src/net/sourceforge/plantuml/sequencediagram/Reference.java

136 lines
4.0 KiB
Java
Raw Normal View History

2011-04-19 16:50:40 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2011-04-19 16:50:40 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2011-04-19 16:50:40 +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
*
2011-04-19 16:50:40 +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
2011-04-19 16:50:40 +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;
2022-10-05 20:32:57 +00:00
import java.util.ArrayList;
2011-08-08 17:48:29 +00:00
import java.util.Collections;
import java.util.Iterator;
2011-04-19 16:50:40 +00:00
import java.util.List;
import net.sourceforge.plantuml.Url;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.style.StyleSignatureBasic;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2011-04-19 16:50:40 +00:00
2015-04-07 18:18:37 +00:00
public class Reference extends AbstractEvent implements Event {
2011-04-19 16:50:40 +00:00
2011-08-08 17:48:29 +00:00
private final List<Participant> participants;
2011-04-19 16:50:40 +00:00
private final Url url;
2020-03-18 10:50:02 +00:00
private final HColor backColorGeneral;
private final HColor backColorElement;
2011-04-19 16:50:40 +00:00
2013-12-10 19:36:50 +00:00
private final Display strings;
2011-04-19 16:50:40 +00:00
2019-07-14 20:09:26 +00:00
final private Style style;
2019-08-26 17:07:21 +00:00
final private Style styleHeader;
2019-07-14 20:09:26 +00:00
2022-03-01 18:11:51 +00:00
public StyleSignatureBasic getDefaultStyleDefinition() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.sequenceDiagram, SName.reference);
2019-08-26 17:07:21 +00:00
}
2022-03-01 18:11:51 +00:00
private StyleSignatureBasic getHeaderStyleDefinition() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.sequenceDiagram, SName.referenceHeader);
2019-07-14 20:09:26 +00:00
}
public Style[] getUsedStyles() {
2022-02-10 18:16:18 +00:00
return new Style[] { style, styleHeader == null ? styleHeader
: styleHeader.eventuallyOverride(PName.BackGroundColor, backColorElement) };
2019-07-14 20:09:26 +00:00
}
2020-03-18 10:50:02 +00:00
public Reference(List<Participant> participants, Url url, Display strings, HColor backColorGeneral,
HColor backColorElement, StyleBuilder styleBuilder) {
2022-10-05 20:32:57 +00:00
this.participants = uniq(participants);
2011-04-19 16:50:40 +00:00
this.url = url;
this.strings = strings;
2011-08-08 17:48:29 +00:00
this.backColorGeneral = backColorGeneral;
this.backColorElement = backColorElement;
2019-07-14 20:09:26 +00:00
this.style = getDefaultStyleDefinition().getMergedStyle(styleBuilder);
2019-08-26 17:07:21 +00:00
this.styleHeader = getHeaderStyleDefinition().getMergedStyle(styleBuilder);
2011-04-19 16:50:40 +00:00
}
2022-10-05 20:32:57 +00:00
static private List<Participant> uniq(List<Participant> all) {
final List<Participant> result = new ArrayList<Participant>();
for (Participant p : all)
if (result.contains(p) == false)
result.add(p);
return Collections.unmodifiableList(result);
}
2011-08-08 17:48:29 +00:00
public List<Participant> getParticipant() {
2022-10-05 20:32:57 +00:00
return participants;
2011-04-19 16:50:40 +00:00
}
2013-12-10 19:36:50 +00:00
public Display getStrings() {
2011-04-19 16:50:40 +00:00
return strings;
}
public boolean dealWith(Participant someone) {
2011-08-08 17:48:29 +00:00
return participants.contains(someone);
2011-04-19 16:50:40 +00:00
}
public final Url getUrl() {
return url;
}
2013-12-10 19:36:50 +00:00
public boolean hasUrl() {
return url != null;
}
2011-04-19 16:50:40 +00:00
@Override
public String toString() {
2011-08-08 17:48:29 +00:00
final StringBuilder sb = new StringBuilder();
for (final Iterator<Participant> it = participants.iterator(); it.hasNext();) {
sb.append(it.next().getCode());
2022-02-10 18:16:18 +00:00
if (it.hasNext())
2011-08-08 17:48:29 +00:00
sb.append("-");
}
return sb.toString();
}
2020-03-18 10:50:02 +00:00
public final HColor getBackColorGeneral() {
2011-08-08 17:48:29 +00:00
return backColorGeneral;
}
2020-03-18 10:50:02 +00:00
public final HColor getBackColorElement() {
2011-08-08 17:48:29 +00:00
return backColorElement;
2011-04-19 16:50:40 +00:00
}
}