1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-03 09:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/AnnotatedWorker.java

232 lines
8.5 KiB
Java
Raw Normal View History

2016-01-30 12:20:07 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2016-01-30 12:20:07 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://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:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
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;
2018-11-26 18:46:22 +00:00
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.EntityImageLegend;
2018-11-26 18:46:22 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.cucadiagram.DisplayPositionned;
2018-05-06 19:59:19 +00:00
import net.sourceforge.plantuml.cucadiagram.DisplaySection;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2018-11-26 18:46:22 +00:00
import net.sourceforge.plantuml.graphic.InnerStrategy;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.SymbolContext;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
2018-11-26 18:46:22 +00:00
import net.sourceforge.plantuml.graphic.USymbol;
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;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.svek.DecorateEntityImage;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
2018-11-26 18:46:22 +00:00
import net.sourceforge.plantuml.ugraphic.MinMax;
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;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
2016-01-30 12:20:07 +00:00
public class AnnotatedWorker {
private final Annotated annotated;
private final ISkinParam skinParam;
2018-11-26 18:46:22 +00:00
private final StringBounder stringBounder;
2016-01-30 12:20:07 +00:00
2018-11-26 18:46:22 +00:00
public AnnotatedWorker(Annotated annotated, ISkinParam skinParam, StringBounder stringBounder) {
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;
2016-01-30 12:20:07 +00:00
}
public TextBlockBackcolored addAdd(TextBlock result) {
2018-11-26 18:46:22 +00:00
result = addFrame(result);
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);
result = addHeaderAndFooter(result);
return (TextBlockBackcolored) result;
}
2019-08-26 17:07:21 +00:00
public boolean hasMainFrame() {
return annotated.getMainFrame() != null;
}
2018-11-26 18:46:22 +00:00
public TextBlock addFrame(final TextBlock original) {
final Display mainFrame = annotated.getMainFrame();
if (mainFrame == null) {
return original;
}
final double x1 = 5;
final double x2 = 7;
final double y1 = 10;
final double y2 = 10;
final SymbolContext symbolContext = new SymbolContext(getBackgroundColor(), HColorUtils.BLACK)
2019-08-26 17:07:21 +00:00
.withShadow(getSkinParam().shadowing(null) ? 3 : 0);
2020-04-26 18:31:41 +00:00
final MinMax originalMinMax = TextBlockUtils.getMinMax(original, stringBounder, false);
2018-11-26 18:46:22 +00:00
final TextBlock title = mainFrame.create(new FontConfiguration(getSkinParam(), FontParam.CAPTION, null),
HorizontalAlignment.CENTER, getSkinParam());
final Dimension2D dimTitle = title.calculateDimension(stringBounder);
2019-08-26 17:07:21 +00:00
// final Dimension2D dimOriginal = original.calculateDimension(stringBounder);
final double width = x1 + Math.max(originalMinMax.getWidth(), dimTitle.getWidth()) + x2;
final double height = dimTitle.getHeight() + y1 + originalMinMax.getHeight() + y2;
final TextBlock frame = USymbol.FRAME.asBig(title, HorizontalAlignment.LEFT, TextBlockUtils.empty(0, 0), width,
height, symbolContext, skinParam.getStereotypeAlignment());
2018-11-26 18:46:22 +00:00
return new TextBlockBackcolored() {
public void drawU(UGraphic ug) {
2020-03-18 10:50:02 +00:00
frame.drawU(ug.apply(UTranslate.dx(originalMinMax.getMinX())));
2018-11-26 18:46:22 +00:00
original.drawU(ug.apply(new UTranslate(x1, y1 + dimTitle.getHeight())));
2019-08-26 17:07:21 +00:00
// original.drawU(ug);
2018-11-26 18:46:22 +00:00
}
public MinMax getMinMax(StringBounder stringBounder) {
2020-04-26 18:31:41 +00:00
return TextBlockUtils.getMinMax(this, stringBounder, false);
2018-11-26 18:46:22 +00:00
}
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
2019-08-26 17:07:21 +00:00
final Rectangle2D rect = original.getInnerPosition(member, stringBounder, strategy);
return new Rectangle2D.Double(rect.getX() + x1, rect.getY() + y1 + dimTitle.getHeight(),
rect.getWidth(), rect.getHeight());
2018-11-26 18:46:22 +00:00
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
2019-08-26 17:07:21 +00:00
return original.calculateDimension(stringBounder);
2018-11-26 18:46:22 +00:00
}
2020-03-18 10:50:02 +00:00
public HColor getBackcolor() {
2018-11-26 18:46:22 +00:00
return symbolContext.getBackColor();
}
};
}
private HColor getBackgroundColor() {
return getSkinParam().getBackgroundColor();
}
2016-01-30 12:20:07 +00:00
private TextBlock addLegend(TextBlock original) {
2018-05-01 17:26:04 +00:00
final DisplayPositionned legend = annotated.getLegend();
2018-05-06 19:59:19 +00:00
if (legend.isNull()) {
2016-01-30 12:20:07 +00:00
return original;
}
2018-05-01 17:26:04 +00:00
final TextBlock text = EntityImageLegend.create(legend.getDisplay(), getSkinParam());
2016-01-30 12:20:07 +00:00
2018-05-01 17:26:04 +00:00
return DecorateEntityImage.add(original, text, legend.getHorizontalAlignment(), legend.getVerticalAlignment());
2016-01-30 12:20:07 +00:00
}
private ISkinParam getSkinParam() {
return skinParam;
}
private TextBlock addCaption(TextBlock original) {
2018-05-01 17:26:04 +00:00
final DisplayPositionned caption = annotated.getCaption();
2018-05-06 19:59:19 +00:00
if (caption.isNull()) {
2016-01-30 12:20:07 +00:00
return original;
}
final TextBlock text = getCaption();
return DecorateEntityImage.addBottom(original, text, HorizontalAlignment.CENTER);
}
public TextBlock getCaption() {
2018-05-01 17:26:04 +00:00
final DisplayPositionned caption = annotated.getCaption();
2018-05-06 19:59:19 +00:00
if (caption.isNull()) {
2016-01-30 12:20:07 +00:00
return TextBlockUtils.empty(0, 0);
}
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.caption)
.getMergedStyle(skinParam.getCurrentStyleBuilder());
2019-07-14 20:09:26 +00:00
return style.createTextBlockBordered(caption.getDisplay(), skinParam.getIHtmlColorSet(), skinParam);
}
2018-05-01 17:26:04 +00:00
return caption.getDisplay().create(new FontConfiguration(getSkinParam(), FontParam.CAPTION, null),
HorizontalAlignment.CENTER, getSkinParam());
2016-01-30 12:20:07 +00:00
}
private TextBlock addTitle(TextBlock original) {
2016-11-04 21:39:29 +00:00
final DisplayPositionned title = annotated.getTitle();
2018-05-06 19:59:19 +00:00
if (title.isNull()) {
2016-01-30 12:20:07 +00:00
return original;
}
2019-08-26 17:07:21 +00:00
final TextBlock block;
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)
.getMergedStyle(skinParam.getCurrentStyleBuilder());
2019-08-26 17:07:21 +00:00
block = style.createTextBlockBordered(title.getDisplay(), skinParam.getIHtmlColorSet(), skinParam);
} else {
final ISkinParam skinParam = getSkinParam();
final FontConfiguration fontConfiguration = new FontConfiguration(skinParam, FontParam.TITLE, null);
block = TextBlockUtils.title(fontConfiguration, title.getDisplay(), skinParam);
}
2016-11-04 21:39:29 +00:00
return DecorateEntityImage.addTop(original, block, HorizontalAlignment.CENTER);
2016-01-30 12:20:07 +00:00
}
private TextBlock addHeaderAndFooter(TextBlock original) {
2018-05-06 19:59:19 +00:00
final DisplaySection footer = annotated.getFooter();
final DisplaySection header = annotated.getHeader();
if (footer.isNull() && header.isNull()) {
2016-01-30 12:20:07 +00:00
return original;
}
2018-05-01 17:26:04 +00:00
TextBlock textFooter = null;
2018-05-06 19:59:19 +00:00
if (footer.isNull() == false) {
2021-03-30 21:19:28 +00:00
Style style = null;
if (UseStyle.useBetaStyle()) {
style = StyleSignature.of(SName.root, SName.document, SName.footer)
.getMergedStyle(skinParam.getCurrentStyleBuilder());
}
2018-11-26 18:46:22 +00:00
textFooter = footer.createRibbon(new FontConfiguration(getSkinParam(), FontParam.FOOTER, null),
2021-03-30 21:19:28 +00:00
getSkinParam(), style);
2018-05-01 17:26:04 +00:00
}
TextBlock textHeader = null;
2018-05-06 19:59:19 +00:00
if (header.isNull() == false) {
2021-03-30 21:19:28 +00:00
Style style = null;
if (UseStyle.useBetaStyle()) {
style = StyleSignature.of(SName.root, SName.document, SName.header)
.getMergedStyle(skinParam.getCurrentStyleBuilder());
}
2018-11-26 18:46:22 +00:00
textHeader = header.createRibbon(new FontConfiguration(getSkinParam(), FontParam.HEADER, null),
2021-03-30 21:19:28 +00:00
getSkinParam(), style);
2018-05-01 17:26:04 +00:00
}
2016-01-30 12:20:07 +00:00
2018-05-01 17:26:04 +00:00
return DecorateEntityImage.addTopAndBottom(original, textHeader, header.getHorizontalAlignment(), textFooter,
footer.getHorizontalAlignment());
}
2016-01-30 12:20:07 +00:00
}