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.graphic;
|
|
|
|
|
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2016-01-30 12:20:07 +00:00
|
|
|
import net.sourceforge.plantuml.AnnotatedWorker;
|
2015-04-07 18:26:58 +00:00
|
|
|
import net.sourceforge.plantuml.FileFormatOption;
|
|
|
|
import net.sourceforge.plantuml.FontParam;
|
2019-07-14 20:09:26 +00:00
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
2020-12-01 21:39:27 +00:00
|
|
|
import net.sourceforge.plantuml.UseStyle;
|
2015-04-07 18:26:58 +00:00
|
|
|
import net.sourceforge.plantuml.activitydiagram3.ftile.EntityImageLegend;
|
|
|
|
import net.sourceforge.plantuml.core.ImageData;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Display;
|
2018-05-06 19:59:19 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.DisplaySection;
|
2016-11-04 21:39:29 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
2015-04-07 18:26:58 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlockUtils;
|
|
|
|
import net.sourceforge.plantuml.graphic.UDrawable;
|
|
|
|
import net.sourceforge.plantuml.graphic.VerticalAlignment;
|
|
|
|
import net.sourceforge.plantuml.png.PngTitler;
|
|
|
|
import net.sourceforge.plantuml.sequencediagram.Event;
|
|
|
|
import net.sourceforge.plantuml.sequencediagram.Newpage;
|
|
|
|
import net.sourceforge.plantuml.sequencediagram.Participant;
|
|
|
|
import net.sourceforge.plantuml.sequencediagram.SequenceDiagram;
|
2019-03-01 22:16:29 +00:00
|
|
|
import net.sourceforge.plantuml.skin.rose.Rose;
|
2019-07-14 20:09:26 +00:00
|
|
|
import net.sourceforge.plantuml.style.SName;
|
|
|
|
import net.sourceforge.plantuml.style.Style;
|
2019-08-26 17:07:21 +00:00
|
|
|
import net.sourceforge.plantuml.style.StyleSignature;
|
2015-04-07 18:26:58 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
2015-04-07 18:26:58 +00:00
|
|
|
|
|
|
|
public class SequenceDiagramFileMakerPuma2 implements FileMaker {
|
|
|
|
|
|
|
|
private final SequenceDiagram diagram;
|
|
|
|
private final DrawableSet drawableSet;
|
|
|
|
private final Dimension2D fullDimension;
|
|
|
|
private final List<Page> pages;
|
|
|
|
private final FileFormatOption fileFormatOption;
|
2016-08-25 20:45:37 +00:00
|
|
|
private final StringBounder stringBounder;
|
2015-04-07 18:26:58 +00:00
|
|
|
|
2020-12-06 21:43:09 +00:00
|
|
|
public SequenceDiagramFileMakerPuma2(SequenceDiagram diagram, Rose skin, FileFormatOption fileFormatOption) {
|
|
|
|
this.diagram = diagram;
|
|
|
|
this.stringBounder = fileFormatOption.getDefaultStringBounder(diagram.getSkinParam());
|
2015-04-07 18:26:58 +00:00
|
|
|
this.fileFormatOption = fileFormatOption;
|
2020-12-06 21:43:09 +00:00
|
|
|
final DrawableSetInitializer initializer = new DrawableSetInitializer(skin, diagram.getSkinParam(),
|
|
|
|
diagram.isShowFootbox(), diagram.getAutonewpage());
|
2015-04-07 18:26:58 +00:00
|
|
|
|
2020-12-06 21:43:09 +00:00
|
|
|
for (Participant p : diagram.participants()) {
|
|
|
|
initializer.addParticipant(p, diagram.getEnglober(p));
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
|
|
|
|
2020-12-06 21:43:09 +00:00
|
|
|
for (Event ev : diagram.events()) {
|
2015-04-07 18:26:58 +00:00
|
|
|
initializer.addEvent(ev);
|
|
|
|
// if (ev instanceof Message) {
|
|
|
|
// // TODO mieux faire
|
|
|
|
// final Message m = (Message) ev;
|
|
|
|
// for (LifeEvent lifeEvent : m.getLiveEvents()) {
|
|
|
|
// if (lifeEvent.getType() == LifeEventType.DESTROY
|
|
|
|
// /*
|
|
|
|
// * || lifeEvent.getType() == LifeEventType.CREATE
|
|
|
|
// */) {
|
|
|
|
// initializer.addEvent(lifeEvent);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
2016-08-25 20:45:37 +00:00
|
|
|
drawableSet = initializer.createDrawableSet(stringBounder);
|
2015-04-07 18:26:58 +00:00
|
|
|
final List<Newpage> newpages = new ArrayList<Newpage>();
|
|
|
|
for (Event ev : drawableSet.getAllEvents()) {
|
|
|
|
if (ev instanceof Newpage) {
|
|
|
|
newpages.add((Newpage) ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fullDimension = drawableSet.getDimension();
|
|
|
|
final Map<Newpage, Double> positions = new LinkedHashMap<Newpage, Double>();
|
|
|
|
for (Newpage n : newpages) {
|
2016-08-25 20:45:37 +00:00
|
|
|
positions.put(n, initializer.getYposition(stringBounder, n));
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
2020-12-06 21:43:09 +00:00
|
|
|
pages = create(drawableSet, positions, diagram.isShowFootbox(), diagram.getTitle().getDisplay()).getPages();
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getNbPages() {
|
|
|
|
return pages.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
private PageSplitter create(DrawableSet drawableSet, Map<Newpage, Double> positions, boolean showFootbox,
|
|
|
|
Display title) {
|
|
|
|
|
2016-08-25 20:45:37 +00:00
|
|
|
final double headerHeight = drawableSet.getHeadHeight(stringBounder);
|
|
|
|
final double tailHeight = drawableSet.getTailHeight(stringBounder, showFootbox);
|
2015-04-07 18:26:58 +00:00
|
|
|
final double signatureHeight = 0;
|
2019-04-21 20:40:01 +00:00
|
|
|
final double newpageHeight = drawableSet.getSkin().createComponentNewPage(drawableSet.getSkinParam())
|
2016-08-25 20:45:37 +00:00
|
|
|
.getPreferredHeight(stringBounder);
|
2015-04-07 18:26:58 +00:00
|
|
|
|
|
|
|
return new PageSplitter(fullDimension.getHeight(), headerHeight, positions, tailHeight, signatureHeight,
|
|
|
|
newpageHeight, title);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ImageData createOne(OutputStream os, final int index, boolean isWithMetadata) throws IOException {
|
|
|
|
|
|
|
|
final Page page = pages.get(index);
|
|
|
|
final SequenceDiagramArea area = new SequenceDiagramArea(fullDimension.getWidth(), page.getHeight());
|
|
|
|
|
2016-11-04 21:39:29 +00:00
|
|
|
final TextBlock compTitle;
|
2018-11-26 18:46:22 +00:00
|
|
|
final AnnotatedWorker annotatedWorker = new AnnotatedWorker(diagram, diagram.getSkinParam(), stringBounder);
|
|
|
|
final TextBlock caption = annotatedWorker.getCaption();
|
2016-08-25 20:45:37 +00:00
|
|
|
area.setCaptionArea(caption.calculateDimension(stringBounder));
|
2016-01-30 12:20:07 +00:00
|
|
|
|
2015-07-11 09:32:49 +00:00
|
|
|
if (Display.isNull(page.getTitle())) {
|
2015-04-07 18:26:58 +00:00
|
|
|
compTitle = null;
|
|
|
|
} else {
|
2020-12-01 21:39:27 +00:00
|
|
|
if (UseStyle.useBetaStyle()) {
|
2021-03-30 21:19:28 +00:00
|
|
|
final Style style = StyleSignature.of(SName.root, SName.document, SName.title)
|
2020-05-07 14:12:08 +00:00
|
|
|
.getMergedStyle(diagram.getSkinParam().getCurrentStyleBuilder());
|
2019-07-14 20:09:26 +00:00
|
|
|
compTitle = style.createTextBlockBordered(page.getTitle(), diagram.getSkinParam().getIHtmlColorSet(),
|
|
|
|
diagram.getSkinParam());
|
|
|
|
} else {
|
2020-05-07 14:12:08 +00:00
|
|
|
compTitle = TextBlockUtils.withMargin(
|
|
|
|
TextBlockUtils.title(new FontConfiguration(drawableSet.getSkinParam(), FontParam.TITLE, null),
|
|
|
|
page.getTitle(), drawableSet.getSkinParam()),
|
|
|
|
7, 7);
|
2019-07-14 20:09:26 +00:00
|
|
|
}
|
2016-11-04 21:39:29 +00:00
|
|
|
final Dimension2D dimTitle = compTitle.calculateDimension(stringBounder);
|
|
|
|
area.setTitleArea(dimTitle.getWidth(), dimTitle.getHeight());
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
2017-11-20 16:10:36 +00:00
|
|
|
area.initFooter(getPngTitler(FontParam.FOOTER, index), stringBounder);
|
|
|
|
area.initHeader(getPngTitler(FontParam.HEADER, index), stringBounder);
|
2015-04-07 18:26:58 +00:00
|
|
|
|
|
|
|
final TextBlock legendBlock;
|
2020-09-19 15:43:24 +00:00
|
|
|
if (diagram.getLegend().isNull()) {
|
2015-04-07 18:26:58 +00:00
|
|
|
legendBlock = TextBlockUtils.empty(0, 0);
|
|
|
|
} else {
|
2020-12-01 21:39:27 +00:00
|
|
|
if (UseStyle.useBetaStyle()) {
|
2021-03-30 21:19:28 +00:00
|
|
|
final Style style = StyleSignature.of(SName.root, SName.document, SName.legend)
|
2020-05-07 14:12:08 +00:00
|
|
|
.getMergedStyle(diagram.getSkinParam().getCurrentStyleBuilder());
|
2020-09-19 15:43:24 +00:00
|
|
|
legendBlock = style.createTextBlockBordered(diagram.getLegend().getDisplay(),
|
2020-05-07 14:12:08 +00:00
|
|
|
diagram.getSkinParam().getIHtmlColorSet(), diagram.getSkinParam());
|
2019-07-14 20:09:26 +00:00
|
|
|
} else {
|
2020-09-19 15:43:24 +00:00
|
|
|
legendBlock = EntityImageLegend.create(diagram.getLegend().getDisplay(), diagram.getSkinParam());
|
2019-07-14 20:09:26 +00:00
|
|
|
}
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
2016-08-25 20:45:37 +00:00
|
|
|
final Dimension2D dimLegend = legendBlock.calculateDimension(stringBounder);
|
2020-09-19 15:43:24 +00:00
|
|
|
area.setLegend(dimLegend, isLegendTop(), diagram.getLegend().getHorizontalAlignment());
|
2015-04-07 18:26:58 +00:00
|
|
|
|
2021-03-23 09:40:50 +00:00
|
|
|
final UDrawable drawable = new UDrawable() {
|
2015-04-07 18:26:58 +00:00
|
|
|
public void drawU(UGraphic ug) {
|
|
|
|
|
|
|
|
double delta = 0;
|
|
|
|
if (index > 0) {
|
|
|
|
delta = page.getNewpage1() - page.getHeaderHeight();
|
|
|
|
}
|
|
|
|
if (delta < 0) {
|
|
|
|
delta = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compTitle != null) {
|
2016-11-04 21:39:29 +00:00
|
|
|
compTitle.drawU(ug.apply(new UTranslate(area.getTitleX(), area.getTitleY())));
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
2016-01-30 12:20:07 +00:00
|
|
|
caption.drawU(ug.apply(new UTranslate(area.getCaptionX(), area.getCaptionY())));
|
2015-04-07 18:26:58 +00:00
|
|
|
|
2020-09-19 15:43:24 +00:00
|
|
|
final double delta1 = Math.max(0, area.getLegendWidth() - area.getWidth());
|
2015-04-07 18:26:58 +00:00
|
|
|
|
2020-09-19 15:43:24 +00:00
|
|
|
final UTranslate forCore = new UTranslate(area.getSequenceAreaX() + delta1 / 2,
|
|
|
|
area.getSequenceAreaY());
|
2020-05-07 14:12:08 +00:00
|
|
|
TextBlock core = drawableSet.asTextBlock(delta, fullDimension.getWidth(), page,
|
|
|
|
diagram.isShowFootbox());
|
2018-11-26 18:46:22 +00:00
|
|
|
core = annotatedWorker.addFrame(core);
|
|
|
|
core.drawU(ug.apply(forCore));
|
2015-04-07 18:26:58 +00:00
|
|
|
|
2017-11-20 16:10:36 +00:00
|
|
|
drawHeader(area, ug, index);
|
2020-09-19 15:43:24 +00:00
|
|
|
drawFooter(area, ug, index);
|
2015-04-07 18:26:58 +00:00
|
|
|
|
2020-09-19 15:43:24 +00:00
|
|
|
if (area.hasLegend()) {
|
|
|
|
legendBlock.drawU(ug.apply(new UTranslate(area.getLegendX(), area.getLegendY())));
|
|
|
|
}
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
2020-09-19 15:43:24 +00:00
|
|
|
|
2021-03-23 09:40:50 +00:00
|
|
|
};
|
2021-04-03 00:49:34 +00:00
|
|
|
return diagram.createImageBuilder(fileFormatOption)
|
|
|
|
.drawable(drawable)
|
2021-03-23 09:40:50 +00:00
|
|
|
.write(os);
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 15:43:24 +00:00
|
|
|
private void drawFooter(SequenceDiagramArea area, UGraphic ug, int page) {
|
2017-11-20 16:10:36 +00:00
|
|
|
final PngTitler pngTitler = getPngTitler(FontParam.FOOTER, page);
|
2018-05-06 19:59:19 +00:00
|
|
|
final TextBlock text = pngTitler.getRibbonBlock();
|
2016-01-30 12:20:07 +00:00
|
|
|
if (text == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-19 15:43:24 +00:00
|
|
|
text.drawU(ug.apply(
|
|
|
|
new UTranslate(area.getFooterX(diagram.getFooter().getHorizontalAlignment()), area.getFooterY())));
|
2016-01-30 12:20:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 16:10:36 +00:00
|
|
|
private void drawHeader(SequenceDiagramArea area, UGraphic ug, int page) {
|
|
|
|
final PngTitler pngTitler = getPngTitler(FontParam.HEADER, page);
|
2018-05-06 19:59:19 +00:00
|
|
|
final TextBlock text = pngTitler.getRibbonBlock();
|
2016-01-30 12:20:07 +00:00
|
|
|
if (text == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-07 14:12:08 +00:00
|
|
|
text.drawU(ug.apply(
|
|
|
|
new UTranslate(area.getHeaderX(diagram.getHeader().getHorizontalAlignment()), area.getHeaderY())));
|
2016-01-30 12:20:07 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 16:10:36 +00:00
|
|
|
private PngTitler getPngTitler(final FontParam fontParam, int page) {
|
2019-07-14 20:09:26 +00:00
|
|
|
final ISkinParam skinParam = diagram.getSkinParam();
|
2020-03-18 10:50:02 +00:00
|
|
|
final HColor hyperlinkColor = skinParam.getHyperlinkColor();
|
|
|
|
final HColor titleColor = skinParam.getFontHtmlColor(null, fontParam);
|
2019-07-14 20:09:26 +00:00
|
|
|
final String fontFamily = skinParam.getFont(null, false, fontParam).getFamily(null);
|
|
|
|
final int fontSize = skinParam.getFont(null, false, fontParam).getSize();
|
2018-05-06 19:59:19 +00:00
|
|
|
final DisplaySection display = diagram.getFooterOrHeaderTeoz(fontParam).withPage(page + 1, pages.size());
|
2019-07-14 20:09:26 +00:00
|
|
|
Style style = null;
|
2020-12-01 21:39:27 +00:00
|
|
|
if (UseStyle.useBetaStyle()) {
|
2020-06-21 20:31:45 +00:00
|
|
|
final StyleSignature def = fontParam.getStyleDefinition(null);
|
2019-07-14 20:09:26 +00:00
|
|
|
style = def.getMergedStyle(skinParam.getCurrentStyleBuilder());
|
|
|
|
}
|
|
|
|
return new PngTitler(titleColor, display, fontSize, fontFamily, hyperlinkColor,
|
|
|
|
skinParam.useUnderlineForHyperlink(), style, skinParam.getIHtmlColorSet(), skinParam);
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 15:43:24 +00:00
|
|
|
private boolean isLegendTop() {
|
|
|
|
return diagram.getLegend().isNull() == false
|
|
|
|
&& diagram.getLegend().getVerticalAlignment() == VerticalAlignment.TOP;
|
|
|
|
}
|
|
|
|
|
2015-04-07 18:26:58 +00:00
|
|
|
}
|