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

183 lines
8.1 KiB
Java
Raw Normal View History

2015-04-07 18:26:58 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2015-04-07 18:26:58 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2015-04-07 18:26:58 +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
*
2015-04-07 18:26:58 +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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* 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.teoz;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.graphic.StringBounder;
2015-05-31 18:56:03 +00:00
import net.sourceforge.plantuml.real.Real;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.sequencediagram.Delay;
import net.sourceforge.plantuml.sequencediagram.Divider;
import net.sourceforge.plantuml.sequencediagram.Event;
import net.sourceforge.plantuml.sequencediagram.GroupingLeaf;
import net.sourceforge.plantuml.sequencediagram.GroupingStart;
import net.sourceforge.plantuml.sequencediagram.GroupingType;
2015-11-01 18:37:20 +00:00
import net.sourceforge.plantuml.sequencediagram.HSpace;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.sequencediagram.LifeEvent;
import net.sourceforge.plantuml.sequencediagram.Message;
import net.sourceforge.plantuml.sequencediagram.MessageExo;
2019-04-21 20:40:01 +00:00
import net.sourceforge.plantuml.sequencediagram.Newpage;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.sequencediagram.Note;
import net.sourceforge.plantuml.sequencediagram.NotePosition;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.sequencediagram.Notes;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.sequencediagram.Reference;
2019-03-01 22:16:29 +00:00
import net.sourceforge.plantuml.skin.rose.Rose;
2015-04-07 18:26:58 +00:00
public class TileBuilder {
public static List<Tile> buildSeveral(Iterator<Event> it, TileArguments tileArguments, Tile parent) {
final List<Tile> tiles = new ArrayList<Tile>();
while (it.hasNext()) {
final Event ev = it.next();
2015-09-28 20:42:17 +00:00
for (Tile tile : TileBuilder.buildOne(it, tileArguments, ev, parent)) {
2015-04-07 18:26:58 +00:00
tiles.add(tile);
2015-05-31 18:56:03 +00:00
final Real tmpMax = tile.getMaxX(tileArguments.getStringBounder());
2015-04-07 18:26:58 +00:00
}
}
return Collections.unmodifiableList(tiles);
}
2015-09-28 20:42:17 +00:00
public static List<Tile> buildOne(Iterator<Event> it, TileArguments tileArguments, final Event ev, Tile parent) {
2015-04-07 18:26:58 +00:00
final StringBounder stringBounder = tileArguments.getStringBounder();
2019-03-01 22:16:29 +00:00
final Rose skin = tileArguments.getSkin();
2015-04-07 18:26:58 +00:00
final ISkinParam skinParam = tileArguments.getSkinParam();
final LivingSpaces livingSpaces = tileArguments.getLivingSpaces();
2015-09-28 20:42:17 +00:00
final List<Tile> tiles = new ArrayList<Tile>();
2015-04-07 18:26:58 +00:00
// System.err.println("TileBuilder::buildOne " + ev);
if (ev instanceof Message) {
final Message msg = (Message) ev;
final LivingSpace livingSpace1 = livingSpaces.get(msg.getParticipant1());
final LivingSpace livingSpace2 = livingSpaces.get(msg.getParticipant2());
boolean reverse = false;
2015-09-28 20:42:17 +00:00
Tile result = null;
2015-04-07 18:26:58 +00:00
if (msg.isSelfMessage()) {
2015-09-28 20:42:17 +00:00
result = new CommunicationTileSelf(livingSpace1, msg, skin, skinParam, livingSpaces);
2015-04-07 18:26:58 +00:00
} else {
// System.err.println("msg=" + msg);
2015-09-28 20:42:17 +00:00
result = new CommunicationTile(livingSpace1, livingSpace2, msg, skin, skinParam);
reverse = ((CommunicationTile) result).isReverse(stringBounder);
2015-04-07 18:26:58 +00:00
}
2018-06-25 19:05:58 +00:00
for (Note noteOnMessage : msg.getNoteOnMessages()) {
final NotePosition notePosition = noteOnMessage.getPosition();
2015-04-07 18:26:58 +00:00
if (notePosition == NotePosition.LEFT) {
2015-09-28 20:42:17 +00:00
result = new CommunicationTileNoteLeft((TileWithUpdateStairs) result, msg, skin, skinParam,
2016-11-04 21:39:29 +00:00
reverse ? livingSpace2 : livingSpace1, noteOnMessage);
2015-04-07 18:26:58 +00:00
} else if (notePosition == NotePosition.RIGHT && msg.isSelfMessage()) {
2016-11-04 21:39:29 +00:00
result = new CommunicationTileSelfNoteRight((CommunicationTileSelf) result, msg, skin, skinParam,
noteOnMessage);
2015-04-07 18:26:58 +00:00
} else if (notePosition == NotePosition.RIGHT) {
2015-09-28 20:42:17 +00:00
result = new CommunicationTileNoteRight((TileWithUpdateStairs) result, msg, skin, skinParam,
2016-11-04 21:39:29 +00:00
reverse ? livingSpace1 : livingSpace2, noteOnMessage);
2019-09-22 17:20:16 +00:00
} else if (notePosition == NotePosition.BOTTOM) {
result = new CommunicationTileNoteBottom((TileWithUpdateStairs) result, msg, skin, skinParam,
noteOnMessage);
} else if (notePosition == NotePosition.TOP) {
result = new CommunicationTileNoteTop((TileWithUpdateStairs) result, msg, skin, skinParam,
noteOnMessage);
2015-04-07 18:26:58 +00:00
}
}
2015-09-28 20:42:17 +00:00
tiles.add(result);
2015-05-03 15:36:36 +00:00
} else if (ev instanceof MessageExo) {
final MessageExo exo = (MessageExo) ev;
final LivingSpace livingSpace1 = livingSpaces.get(exo.getParticipant());
2015-09-28 20:42:17 +00:00
Tile result = null;
result = new CommunicationExoTile(livingSpace1, exo, skin, skinParam, tileArguments);
2018-06-25 19:05:58 +00:00
for (Note noteOnMessage : exo.getNoteOnMessages()) {
final NotePosition notePosition = exo.getNoteOnMessages().get(0).getPosition();
2015-05-03 15:36:36 +00:00
if (notePosition == NotePosition.LEFT) {
2015-09-28 20:42:17 +00:00
result = new CommunicationTileNoteLeft((TileWithUpdateStairs) result, exo, skin, skinParam,
2016-11-04 21:39:29 +00:00
livingSpace1, noteOnMessage);
2015-05-03 15:36:36 +00:00
} else if (notePosition == NotePosition.RIGHT) {
2015-09-28 20:42:17 +00:00
result = new CommunicationTileNoteRight((TileWithUpdateStairs) result, exo, skin, skinParam,
2016-11-04 21:39:29 +00:00
livingSpace1, noteOnMessage);
2015-05-03 15:36:36 +00:00
}
}
2015-09-28 20:42:17 +00:00
tiles.add(result);
2015-04-07 18:26:58 +00:00
} else if (ev instanceof Note) {
final Note note = (Note) ev;
2019-06-26 19:24:49 +00:00
LivingSpace livingSpace1 = livingSpaces.get(note.getParticipant());
LivingSpace livingSpace2 = note.getParticipant2() == null ? null : livingSpaces.get(note.getParticipant2());
if (livingSpace1 == null && livingSpace2 == null) {
livingSpace1 = tileArguments.getFirstLivingSpace();
livingSpace2 = tileArguments.getLastLivingSpace();
}
2015-09-28 20:42:17 +00:00
tiles.add(new NoteTile(livingSpace1, livingSpace2, note, skin, skinParam));
} else if (ev instanceof Notes) {
final Notes notes = (Notes) ev;
2015-11-01 18:37:20 +00:00
tiles.add(new NotesTile(livingSpaces, notes, skin, skinParam));
2015-04-07 18:26:58 +00:00
} else if (ev instanceof Divider) {
final Divider divider = (Divider) ev;
2015-09-28 20:42:17 +00:00
tiles.add(new DividerTile(divider, tileArguments));
2015-04-07 18:26:58 +00:00
} else if (ev instanceof GroupingStart) {
final GroupingStart start = (GroupingStart) ev;
2018-08-26 12:09:50 +00:00
final GroupingTile groupingTile = new GroupingTile(it, start, tileArguments.withBackColorGeneral(
start.getBackColorElement(), start.getBackColorGeneral()), tileArguments);
tiles.add(new EmptyTile(4, groupingTile));
tiles.add(groupingTile);
tiles.add(new EmptyTile(4, groupingTile));
2015-09-28 20:42:17 +00:00
// tiles.add(TileUtils.withMargin(tile, 0, 0, 4, 4);
2015-04-07 18:26:58 +00:00
} else if (ev instanceof GroupingLeaf && ((GroupingLeaf) ev).getType() == GroupingType.ELSE) {
final GroupingLeaf anElse = (GroupingLeaf) ev;
2015-09-28 20:42:17 +00:00
tiles.add(new ElseTile(anElse, skin, skinParam, parent));
2015-04-07 18:26:58 +00:00
} else if (ev instanceof Reference) {
final Reference ref = (Reference) ev;
2015-09-28 20:42:17 +00:00
tiles.add(new ReferenceTile(ref, tileArguments.withBackColor(ref)));
2015-04-07 18:26:58 +00:00
} else if (ev instanceof Delay) {
final Delay delay = (Delay) ev;
2015-09-28 20:42:17 +00:00
tiles.add(new DelayTile(delay, tileArguments));
2015-11-01 18:37:20 +00:00
} else if (ev instanceof HSpace) {
final HSpace hspace = (HSpace) ev;
tiles.add(new HSpaceTile(hspace, tileArguments));
2015-04-07 18:26:58 +00:00
} else if (ev instanceof LifeEvent) {
final LifeEvent lifeEvent = (LifeEvent) ev;
final LivingSpace livingSpace = livingSpaces.get(lifeEvent.getParticipant());
2015-09-28 20:42:17 +00:00
tiles.add(new LifeEventTile(lifeEvent, tileArguments, livingSpace, skin, skinParam));
2019-04-21 20:40:01 +00:00
} else if (ev instanceof Newpage) {
final Newpage newpage = (Newpage) ev;
tiles.add(new NewpageTile(newpage, tileArguments));
2015-04-07 18:26:58 +00:00
} else {
System.err.println("TileBuilder::Ignoring " + ev.getClass());
}
2015-09-28 20:42:17 +00:00
return tiles;
2015-04-07 18:26:58 +00:00
}
}