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

205 lines
7.4 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.HtmlColor;
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
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;
import net.sourceforge.plantuml.style.StyleDefinition;
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;
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;
}
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(getSkinParam().getBackgroundColor(), HtmlColorUtils.BLACK)
.withShadow(getSkinParam().shadowing(null));
final TextBlock title = mainFrame.create(new FontConfiguration(getSkinParam(), FontParam.CAPTION, null),
HorizontalAlignment.CENTER, getSkinParam());
final Dimension2D dimTitle = title.calculateDimension(stringBounder);
final Dimension2D dimOriginal = original.calculateDimension(stringBounder);
final double width = x1 + Math.max(dimOriginal.getWidth(), dimTitle.getWidth()) + x2;
final double height = dimTitle.getHeight() + y1 + dimOriginal.getHeight() + y2;
final TextBlock result = USymbol.FRAME.asBig(title, HorizontalAlignment.LEFT, TextBlockUtils.empty(0, 0),
2019-05-24 19:59:31 +00:00
width, height, symbolContext, skinParam.getStereotypeAlignment());
2018-11-26 18:46:22 +00:00
return new TextBlockBackcolored() {
public void drawU(UGraphic ug) {
result.drawU(ug);
original.drawU(ug.apply(new UTranslate(x1, y1 + dimTitle.getHeight())));
}
public MinMax getMinMax(StringBounder stringBounder) {
return TextBlockUtils.getMinMax(result, stringBounder);
}
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
return result.getInnerPosition(member, stringBounder, strategy);
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return result.calculateDimension(stringBounder);
}
public HtmlColor getBackcolor() {
return symbolContext.getBackColor();
}
};
}
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);
}
2019-07-14 20:09:26 +00:00
if (SkinParam.USE_STYLES()) {
final Style style = StyleDefinition.of(SName.root, SName.caption).getMergedStyle(
skinParam.getCurrentStyleBuilder());
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;
}
2016-11-04 21:39:29 +00:00
ISkinParam skinParam = getSkinParam();
2019-07-14 20:09:26 +00:00
// if (SkinParam.USE_STYLES()) {
// throw new UnsupportedOperationException();
// }
2016-11-04 21:39:29 +00:00
final FontConfiguration fontConfiguration = new FontConfiguration(skinParam, FontParam.TITLE, null);
2016-01-30 12:20:07 +00:00
2016-11-04 21:39:29 +00:00
final TextBlock block = TextBlockUtils.title(fontConfiguration, title.getDisplay(), skinParam);
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) {
2018-11-26 18:46:22 +00:00
textFooter = footer.createRibbon(new FontConfiguration(getSkinParam(), FontParam.FOOTER, null),
getSkinParam());
2018-05-01 17:26:04 +00:00
}
TextBlock textHeader = null;
2018-05-06 19:59:19 +00:00
if (header.isNull() == false) {
2018-11-26 18:46:22 +00:00
textHeader = header.createRibbon(new FontConfiguration(getSkinParam(), FontParam.HEADER, null),
getSkinParam());
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
}