plantuml/src/net/sourceforge/plantuml/AnnotatedWorker.java

95 lines
3.1 KiB
Java
Raw Normal View History

2016-01-30 12:20:07 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2016-01-30 12:20:07 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2016-01-30 12:20:07 +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:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2017-03-15 19:13:31 +00:00
*
2016-01-30 12:20:07 +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;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.abel.DisplayPositioned;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.style.ISkinParam;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.svek.DecorateEntityImage;
public class AnnotatedWorker {
private final Annotated annotated;
private final ISkinParam skinParam;
2018-11-26 18:46:22 +00:00
private final StringBounder stringBounder;
2022-10-05 20:32:57 +00:00
private final AnnotatedBuilder builder;
2016-01-30 12:20:07 +00:00
2022-10-05 20:32:57 +00:00
public AnnotatedWorker(Annotated annotated, ISkinParam skinParam, StringBounder stringBounder,
AnnotatedBuilder builder) {
2016-01-30 12:20:07 +00:00
this.annotated = annotated;
this.skinParam = skinParam;
2018-11-26 18:46:22 +00:00
this.stringBounder = stringBounder;
2022-10-05 20:32:57 +00:00
this.builder = builder;
2016-01-30 12:20:07 +00:00
}
2023-02-26 18:51:17 +00:00
public TextBlock addAdd(TextBlock result) {
2022-10-05 20:32:57 +00:00
result = builder.decoreWithFrame(result);
2018-11-26 18:46:22 +00:00
result = addLegend(result);
2019-02-09 21:56:24 +00:00
result = addTitle(result);
2016-01-30 12:20:07 +00:00
result = addCaption(result);
2022-10-05 20:32:57 +00:00
result = builder.addHeaderAndFooter(result);
2023-02-26 18:51:17 +00:00
return (TextBlock) result;
2016-01-30 12:20:07 +00:00
}
2022-10-05 20:32:57 +00:00
public TextBlock addLegend(TextBlock original) {
2021-11-09 17:47:19 +00:00
final DisplayPositioned legend = annotated.getLegend();
2022-02-10 18:16:18 +00:00
if (legend.isNull())
2016-01-30 12:20:07 +00:00
return original;
2022-02-10 18:16:18 +00:00
2022-10-05 20:32:57 +00:00
return DecorateEntityImage.add(original, builder.getLegend(), legend.getHorizontalAlignment(),
legend.getVerticalAlignment());
2016-01-30 12:20:07 +00:00
}
2022-10-05 20:32:57 +00:00
public TextBlock addTitle(TextBlock original) {
final DisplayPositioned title = (DisplayPositioned) annotated.getTitle();
if (title.isNull())
2016-01-30 12:20:07 +00:00
return original;
2022-02-10 18:16:18 +00:00
2022-10-05 20:32:57 +00:00
return DecorateEntityImage.addTop(original, builder.getTitle(), HorizontalAlignment.CENTER);
2016-01-30 12:20:07 +00:00
}
2022-10-05 20:32:57 +00:00
private TextBlock addCaption(TextBlock original) {
2021-11-09 17:47:19 +00:00
final DisplayPositioned caption = annotated.getCaption();
2022-02-10 18:16:18 +00:00
if (caption.isNull())
2016-01-30 12:20:07 +00:00
return original;
2022-10-05 20:32:57 +00:00
return DecorateEntityImage.addBottom(original, builder.getCaption(), HorizontalAlignment.CENTER);
2016-01-30 12:20:07 +00:00
}
}