plantuml/src/net/sourceforge/plantuml/svek/ConcurrentStateImage.java

164 lines
4.8 KiB
Java
Raw Normal View History

2016-07-25 19:25:28 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2016-07-25 19:25:28 +00:00
*
* Project Info: http://plantuml.com
*
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-07-25 19:25:28 +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.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.ISkinParam;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.awt.geom.Dimension2D;
2016-07-25 19:25:28 +00:00
import net.sourceforge.plantuml.graphic.AbstractTextBlock;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.rose.Rose;
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;
2016-07-25 19:25:28 +00:00
public final class ConcurrentStateImage extends AbstractTextBlock implements IEntityImage {
2021-05-14 08:42:57 +00:00
private final List<IEntityImage> inners = new ArrayList<>();
2016-07-25 19:25:28 +00:00
private final Separator separator;
private final ISkinParam skinParam;
2020-03-18 10:50:02 +00:00
private final HColor backColor;
2016-07-25 19:25:28 +00:00
static enum Separator {
VERTICAL, HORIZONTAL;
static Separator fromChar(char sep) {
if (sep == '|') {
return VERTICAL;
}
if (sep == '-') {
return HORIZONTAL;
}
throw new IllegalArgumentException();
}
UTranslate move(Dimension2D dim) {
if (this == VERTICAL) {
2020-03-18 10:50:02 +00:00
return UTranslate.dx(dim.getWidth());
2016-07-25 19:25:28 +00:00
}
2020-03-18 10:50:02 +00:00
return UTranslate.dy(dim.getHeight());
2016-07-25 19:25:28 +00:00
}
Dimension2D add(Dimension2D orig, Dimension2D other) {
if (this == VERTICAL) {
2021-12-14 21:38:22 +00:00
return new Dimension2DDouble(orig.getWidth() + other.getWidth(),
Math.max(orig.getHeight(), other.getHeight()));
2016-07-25 19:25:28 +00:00
}
2021-12-14 21:38:22 +00:00
return new Dimension2DDouble(Math.max(orig.getWidth(), other.getWidth()),
orig.getHeight() + other.getHeight());
2016-07-25 19:25:28 +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));
if (this == VERTICAL) {
2020-03-18 10:50:02 +00:00
ug.draw(ULine.vline(dimTotal.getHeight() + DASH));
2016-07-25 19:25:28 +00:00
} else {
2020-03-18 10:50:02 +00:00
ug.draw(ULine.hline(dimTotal.getWidth() + DASH));
2016-07-25 19:25:28 +00:00
}
}
}
2020-03-18 10:50:02 +00:00
private HColor getColor(ColorParam colorParam) {
2016-07-25 19:25:28 +00:00
return new Rose().getHtmlColor(skinParam, colorParam);
}
public ConcurrentStateImage(Collection<IEntityImage> images, char concurrentSeparator, ISkinParam skinParam,
2020-03-18 10:50:02 +00:00
HColor backColor) {
2016-07-25 19:25:28 +00:00
this.separator = Separator.fromChar(concurrentSeparator);
this.skinParam = skinParam;
this.backColor = skinParam.getBackgroundColor();
2016-07-25 19:25:28 +00:00
this.inners.addAll(images);
}
public void drawU(UGraphic ug) {
System.err.println("drawing " + inners.size());
2020-03-18 10:50:02 +00:00
final HColor dotColor = getColor(ColorParam.stateBorder);
2016-07-25 19:25:28 +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));
if (i < inners.size() - 1) {
2020-04-19 16:04:39 +00:00
separator.drawSeparator(ug.apply(dotColor), dimTotal);
2016-07-25 19:25:28 +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() {
2016-07-25 19:25:28 +00:00
return backColor;
}
public boolean isHidden() {
return false;
}
2017-04-05 17:37:42 +00:00
public Margins getShield(StringBounder stringBounder) {
return Margins.NONE;
2016-07-25 19:25:28 +00:00
}
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
2021-12-14 21:38:22 +00:00
2018-12-22 11:11:40 +00:00
public double getOverscanX(StringBounder stringBounder) {
return 0;
}
2016-07-25 19:25:28 +00:00
}