plantuml/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek2In...

175 lines
5.4 KiB
Java
Raw Normal View History

2015-04-07 18:26:58 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, 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.svek;
import java.util.List;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.ISkinParam;
2022-02-12 17:27:51 +00:00
import net.sourceforge.plantuml.UseStyle;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.awt.geom.Dimension2D;
2018-03-09 21:37:34 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
2015-06-07 10:23:10 +00:00
import net.sourceforge.plantuml.graphic.AbstractTextBlock;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.rose.Rose;
2022-02-12 17:27:51 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.style.StyleSignatureBasic;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UStroke;
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
2015-06-07 10:23:10 +00:00
public final class CucaDiagramFileMakerSvek2InternalImage extends AbstractTextBlock implements IEntityImage {
2015-04-07 18:26:58 +00:00
2016-07-25 19:25:28 +00:00
private final List<IEntityImage> inners;
2015-04-07 18:26:58 +00:00
private final Separator separator;
private final ISkinParam skinParam;
2018-03-09 21:37:34 +00:00
private final Stereotype stereotype;
2015-04-07 18:26:58 +00:00
static enum Separator {
VERTICAL, HORIZONTAL;
static Separator fromChar(char sep) {
2022-02-12 17:27:51 +00:00
if (sep == '|')
2015-04-07 18:26:58 +00:00
return VERTICAL;
2022-02-12 17:27:51 +00:00
if (sep == '-')
2015-04-07 18:26:58 +00:00
return HORIZONTAL;
2022-02-12 17:27:51 +00:00
2015-04-07 18:26:58 +00:00
throw new IllegalArgumentException();
}
UTranslate move(Dimension2D dim) {
2022-02-12 17:27:51 +00:00
if (this == VERTICAL)
2020-03-18 10:50:02 +00:00
return UTranslate.dx(dim.getWidth());
2022-02-12 17:27:51 +00:00
2020-03-18 10:50:02 +00:00
return UTranslate.dy(dim.getHeight());
2015-04-07 18:26:58 +00:00
}
Dimension2D add(Dimension2D orig, Dimension2D other) {
2022-02-12 17:27:51 +00:00
if (this == VERTICAL)
2021-12-14 21:38:22 +00:00
return new Dimension2DDouble(orig.getWidth() + other.getWidth(),
Math.max(orig.getHeight(), other.getHeight()));
2022-02-12 17:27:51 +00:00
2021-12-14 21:38:22 +00:00
return new Dimension2DDouble(Math.max(orig.getWidth(), other.getWidth()),
orig.getHeight() + other.getHeight());
2015-04-07 18:26:58 +00:00
}
void drawSeparator(UGraphic ug, Dimension2D dimTotal) {
final double THICKNESS_BORDER = 1.5;
final int DASH = 8;
ug = ug.apply(new UStroke(DASH, 10, THICKNESS_BORDER));
2022-02-12 17:27:51 +00:00
if (this == VERTICAL)
2020-03-18 10:50:02 +00:00
ug.draw(ULine.vline(dimTotal.getHeight() + DASH));
2022-02-12 17:27:51 +00:00
else
2020-03-18 10:50:02 +00:00
ug.draw(ULine.hline(dimTotal.getWidth() + DASH));
2015-04-07 18:26:58 +00:00
}
}
2016-07-25 19:25:28 +00:00
public CucaDiagramFileMakerSvek2InternalImage(List<IEntityImage> inners, char concurrentSeparator,
2018-03-09 21:37:34 +00:00
ISkinParam skinParam, Stereotype stereotype) {
2015-04-07 18:26:58 +00:00
this.separator = Separator.fromChar(concurrentSeparator);
this.skinParam = skinParam;
2018-03-09 21:37:34 +00:00
this.stereotype = stereotype;
2016-07-25 19:25:28 +00:00
this.inners = inners;
2015-04-07 18:26:58 +00:00
}
2022-02-12 17:27:51 +00:00
private Style getStyle() {
return getStyleSignature().getMergedStyle(skinParam.getCurrentStyleBuilder());
}
2022-03-01 18:11:51 +00:00
private StyleSignatureBasic getStyleSignature() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.stateDiagram, SName.state);
2022-02-12 17:27:51 +00:00
}
2015-04-07 18:26:58 +00:00
public void drawU(UGraphic ug) {
2022-02-12 17:27:51 +00:00
final HColor borderColor;
if (UseStyle.useBetaStyle())
borderColor = getStyle().value(PName.LineColor).asColor(skinParam.getThemeStyle(),
skinParam.getIHtmlColorSet());
else
borderColor = new Rose().getHtmlColor(skinParam, stereotype, ColorParam.stateBorder);
2015-04-07 18:26:58 +00:00
final StringBounder stringBounder = ug.getStringBounder();
final Dimension2D dimTotal = calculateDimension(stringBounder);
for (int i = 0; i < inners.size(); i++) {
final IEntityImage inner = inners.get(i);
inner.drawU(ug);
final Dimension2D dim = inner.calculateDimension(stringBounder);
ug = ug.apply(separator.move(dim));
2022-02-12 17:27:51 +00:00
if (i < inners.size() - 1)
separator.drawSeparator(ug.apply(borderColor), dimTotal);
2015-04-07 18:26:58 +00:00
}
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
Dimension2D result = new Dimension2DDouble(0, 0);
for (IEntityImage inner : inners) {
final Dimension2D dim = inner.calculateDimension(stringBounder);
result = separator.add(result, dim);
}
return result;
}
2020-03-18 10:50:02 +00:00
public HColor getBackcolor() {
return skinParam.getBackgroundColor();
2015-04-07 18:26:58 +00:00
}
2021-12-14 21:38:22 +00:00
2018-12-22 11:11:40 +00:00
public double getOverscanX(StringBounder stringBounder) {
return 0;
}
2015-04-07 18:26:58 +00:00
public boolean isHidden() {
return false;
}
2017-04-05 17:37:42 +00:00
public Margins getShield(StringBounder stringBounder) {
return Margins.NONE;
2015-04-07 18:26:58 +00:00
}
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
2021-12-14 21:38:22 +00:00
2015-04-07 18:26:58 +00:00
}