2019-03-01 22:16:29 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
|
|
|
* (C) Copyright 2009-2020, Arnaud Roques
|
|
|
|
*
|
|
|
|
* Project Info: http://plantuml.com
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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.mindmap;
|
|
|
|
|
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.awt.geom.Point2D;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.Direction;
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
2019-11-03 17:40:03 +00:00
|
|
|
import net.sourceforge.plantuml.SkinParamColors;
|
2021-07-25 10:41:36 +00:00
|
|
|
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileBoxOld;
|
2021-03-07 12:23:24 +00:00
|
|
|
import net.sourceforge.plantuml.creole.CreoleMode;
|
2019-03-01 22:16:29 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.Display;
|
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlockUtils;
|
|
|
|
import net.sourceforge.plantuml.graphic.UDrawable;
|
2019-11-03 17:40:03 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.color.ColorType;
|
2019-03-01 22:16:29 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.color.Colors;
|
2019-08-26 17:07:21 +00:00
|
|
|
import net.sourceforge.plantuml.style.PName;
|
|
|
|
import net.sourceforge.plantuml.style.SName;
|
|
|
|
import net.sourceforge.plantuml.style.Style;
|
|
|
|
import net.sourceforge.plantuml.style.StyleBuilder;
|
|
|
|
import net.sourceforge.plantuml.style.StyleSignature;
|
2019-03-01 22:16:29 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UPath;
|
2019-08-26 17:07:21 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UStroke;
|
2019-03-01 22:16:29 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
2020-03-18 10:50:02 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
2019-03-01 22:16:29 +00:00
|
|
|
|
|
|
|
public class FingerImpl implements Finger, UDrawable {
|
|
|
|
|
|
|
|
private final Display label;
|
2020-03-18 10:50:02 +00:00
|
|
|
private final HColor backColor;
|
2019-09-14 18:12:04 +00:00
|
|
|
private final String stereotype;
|
2019-03-01 22:16:29 +00:00
|
|
|
private final ISkinParam skinParam;
|
2019-08-26 17:07:21 +00:00
|
|
|
private final StyleBuilder styleBuilder;
|
2019-03-01 22:16:29 +00:00
|
|
|
private final IdeaShape shape;
|
|
|
|
private final Direction direction;
|
2019-08-26 17:07:21 +00:00
|
|
|
private final int level;
|
2019-03-01 22:16:29 +00:00
|
|
|
private boolean drawPhalanx = true;
|
2020-05-07 14:12:08 +00:00
|
|
|
private double marginLeft = 10;
|
|
|
|
private double marginRight = 10;
|
|
|
|
private double marginTop = 10;
|
|
|
|
private double marginBottom = 10;
|
2019-03-01 22:16:29 +00:00
|
|
|
|
2021-05-14 08:42:57 +00:00
|
|
|
private final List<FingerImpl> nail = new ArrayList<>();
|
2019-08-26 17:07:21 +00:00
|
|
|
private Tetris tetris = null;
|
|
|
|
|
2019-09-14 18:12:04 +00:00
|
|
|
private StyleSignature getDefaultStyleDefinitionNode() {
|
2019-11-03 17:40:03 +00:00
|
|
|
final String depth = SName.depth(level);
|
2019-08-26 17:07:21 +00:00
|
|
|
if (level == 0) {
|
2019-11-03 17:40:03 +00:00
|
|
|
return StyleSignature.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.rootNode)
|
|
|
|
.add(stereotype).add(depth);
|
2019-08-26 17:07:21 +00:00
|
|
|
}
|
2021-03-07 12:23:24 +00:00
|
|
|
if (shape == IdeaShape.NONE && nail.size() == 0) {
|
|
|
|
return StyleSignature
|
|
|
|
.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode, SName.boxless)
|
|
|
|
.add(stereotype).add(depth);
|
|
|
|
}
|
|
|
|
if (shape == IdeaShape.NONE) {
|
|
|
|
return StyleSignature.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.boxless)
|
|
|
|
.add(stereotype).add(depth);
|
|
|
|
}
|
2019-08-26 17:07:21 +00:00
|
|
|
if (nail.size() == 0) {
|
2019-11-03 17:40:03 +00:00
|
|
|
return StyleSignature.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode)
|
|
|
|
.add(stereotype).add(depth);
|
2019-08-26 17:07:21 +00:00
|
|
|
}
|
2019-11-03 17:40:03 +00:00
|
|
|
return StyleSignature.of(SName.root, SName.element, SName.mindmapDiagram, SName.node).add(stereotype)
|
|
|
|
.add(depth);
|
2019-08-26 17:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public StyleSignature getDefaultStyleDefinitionArrow() {
|
2019-11-03 17:40:03 +00:00
|
|
|
final String depth = SName.depth(level);
|
|
|
|
return StyleSignature.of(SName.root, SName.element, SName.mindmapDiagram, SName.arrow).add(stereotype)
|
|
|
|
.add(depth);
|
2019-08-26 17:07:21 +00:00
|
|
|
}
|
2019-03-01 22:16:29 +00:00
|
|
|
|
|
|
|
public static FingerImpl build(Idea idea, ISkinParam skinParam, Direction direction) {
|
2019-08-26 17:07:21 +00:00
|
|
|
final FingerImpl result = new FingerImpl(idea.getStyleBuilder(), idea.getBackColor(), idea.getLabel(),
|
2019-09-14 18:12:04 +00:00
|
|
|
skinParam, idea.getShape(), direction, idea.getLevel(), idea.getStereotype());
|
2019-03-01 22:16:29 +00:00
|
|
|
for (Idea child : idea.getChildren()) {
|
|
|
|
result.addInNail(build(child, skinParam, direction));
|
|
|
|
}
|
2019-08-26 17:07:21 +00:00
|
|
|
// System.err.println("End of build for " + idea);
|
2019-03-01 22:16:29 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addInNail(FingerImpl child) {
|
|
|
|
nail.add(child);
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
private FingerImpl(StyleBuilder styleBuilder, HColor backColor, Display label, ISkinParam skinParam,
|
2019-09-14 18:12:04 +00:00
|
|
|
IdeaShape shape, Direction direction, int level, String stereotype) {
|
2019-08-26 17:07:21 +00:00
|
|
|
this.backColor = backColor;
|
2019-09-14 18:12:04 +00:00
|
|
|
this.stereotype = stereotype;
|
2019-08-26 17:07:21 +00:00
|
|
|
this.level = level;
|
2019-03-01 22:16:29 +00:00
|
|
|
this.label = label;
|
|
|
|
this.skinParam = skinParam;
|
|
|
|
this.shape = shape;
|
2019-08-26 17:07:21 +00:00
|
|
|
this.styleBuilder = styleBuilder;
|
2019-03-01 22:16:29 +00:00
|
|
|
this.direction = direction;
|
2019-08-26 17:07:21 +00:00
|
|
|
final Style styleNode = getDefaultStyleDefinitionNode().getMergedStyle(styleBuilder);
|
2020-05-07 14:12:08 +00:00
|
|
|
this.marginLeft = styleNode.getMargin().getLeft();
|
|
|
|
this.marginRight = styleNode.getMargin().getRight();
|
|
|
|
this.marginTop = styleNode.getMargin().getTop();
|
|
|
|
this.marginBottom = styleNode.getMargin().getBottom();
|
2019-03-01 22:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void drawU(final UGraphic ug) {
|
|
|
|
final StringBounder stringBounder = ug.getStringBounder();
|
|
|
|
final TextBlock phalanx = getPhalanx();
|
|
|
|
final Dimension2D dimPhalanx = phalanx.calculateDimension(stringBounder);
|
|
|
|
if (drawPhalanx) {
|
|
|
|
final double posY = -getPhalanxThickness(stringBounder) / 2;
|
|
|
|
final double posX = direction == Direction.RIGHT ? 0 : -dimPhalanx.getWidth();
|
|
|
|
phalanx.drawU(ug.apply(new UTranslate(posX, posY)));
|
|
|
|
}
|
2020-05-07 14:12:08 +00:00
|
|
|
final Point2D p1 = new Point2D.Double(
|
|
|
|
direction == Direction.RIGHT ? dimPhalanx.getWidth() : -dimPhalanx.getWidth(), 0);
|
2019-03-01 22:16:29 +00:00
|
|
|
|
2019-08-26 17:07:21 +00:00
|
|
|
for (int i = 0; i < nail.size(); i++) {
|
|
|
|
final FingerImpl child = nail.get(i);
|
|
|
|
final SymetricalTeePositioned stp = tetris(stringBounder).getElements().get(i);
|
2020-05-07 14:12:08 +00:00
|
|
|
final double x = direction == Direction.RIGHT ? dimPhalanx.getWidth() + getX12()
|
|
|
|
: -dimPhalanx.getWidth() - getX12();
|
2019-08-26 17:07:21 +00:00
|
|
|
final Point2D p2 = new Point2D.Double(x, stp.getY());
|
|
|
|
child.drawU(ug.apply(new UTranslate(p2)));
|
2020-04-19 16:04:39 +00:00
|
|
|
drawLine(ug.apply(getLinkColor()).apply(getUStroke()), p1, p2);
|
2019-03-01 22:16:29 +00:00
|
|
|
}
|
2019-08-26 17:07:21 +00:00
|
|
|
|
2019-03-01 22:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
private HColor getLinkColor() {
|
2020-09-19 15:43:24 +00:00
|
|
|
final Style styleArrow = getDefaultStyleDefinitionArrow().getMergedStyle(styleBuilder);
|
2021-05-06 21:23:05 +00:00
|
|
|
return styleArrow.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
|
2019-03-01 22:16:29 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 17:07:21 +00:00
|
|
|
private UStroke getUStroke() {
|
2020-09-19 15:43:24 +00:00
|
|
|
final Style styleArrow = getDefaultStyleDefinitionArrow().getMergedStyle(styleBuilder);
|
|
|
|
return styleArrow.getStroke();
|
2019-08-26 17:07:21 +00:00
|
|
|
}
|
2019-03-01 22:16:29 +00:00
|
|
|
|
|
|
|
private void drawLine(UGraphic ug, Point2D p1, Point2D p2) {
|
|
|
|
// final ULine line = new ULine(p1, p2);
|
|
|
|
// ug.apply(new UTranslate(p1)).draw(line);
|
|
|
|
final UPath path = new UPath();
|
|
|
|
final double delta1 = direction == Direction.RIGHT ? 10 : -10;
|
|
|
|
final double delta2 = direction == Direction.RIGHT ? 25 : -25;
|
|
|
|
path.moveTo(p1);
|
|
|
|
path.lineTo(p1.getX() + delta1, p1.getY());
|
|
|
|
path.cubicTo(p1.getX() + delta2, p1.getY(), p2.getX() - delta2, p2.getY(), p2.getX() - delta1, p2.getY());
|
|
|
|
path.lineTo(p2);
|
|
|
|
ug.draw(path);
|
|
|
|
}
|
|
|
|
|
2019-08-26 17:07:21 +00:00
|
|
|
private Tetris tetris(StringBounder stringBounder) {
|
|
|
|
if (tetris == null) {
|
|
|
|
tetris = new Tetris(label.toString());
|
|
|
|
for (FingerImpl child : nail) {
|
|
|
|
tetris.add(child.asSymetricalTee(stringBounder));
|
|
|
|
}
|
|
|
|
tetris.balance();
|
|
|
|
}
|
|
|
|
return tetris;
|
|
|
|
}
|
|
|
|
|
|
|
|
private SymetricalTee asSymetricalTee(StringBounder stringBounder) {
|
|
|
|
final double thickness1 = getPhalanxThickness(stringBounder);
|
|
|
|
final double elongation1 = getPhalanxElongation(stringBounder);
|
|
|
|
if (nail.size() == 0) {
|
|
|
|
return new SymetricalTee(thickness1, elongation1, 0, 0);
|
|
|
|
}
|
|
|
|
final double thickness2 = getNailThickness(stringBounder);
|
|
|
|
final double elongation2 = getNailElongation(stringBounder);
|
|
|
|
return new SymetricalTee(thickness1, elongation1 + getX1(), thickness2, getX2() + elongation2);
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getX1() {
|
2020-05-07 14:12:08 +00:00
|
|
|
return marginLeft;
|
2019-08-26 17:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private double getX2() {
|
2020-05-07 14:12:08 +00:00
|
|
|
return marginRight + 30;
|
2019-08-26 17:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public double getX12() {
|
|
|
|
return getX1() + getX2();
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getPhalanxThickness(StringBounder stringBounder) {
|
|
|
|
return getPhalanx().calculateDimension(stringBounder).getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getPhalanxElongation(StringBounder stringBounder) {
|
|
|
|
return getPhalanx().calculateDimension(stringBounder).getWidth();
|
|
|
|
}
|
|
|
|
|
2019-03-01 22:16:29 +00:00
|
|
|
private TextBlock getPhalanx() {
|
|
|
|
if (drawPhalanx == false) {
|
|
|
|
return TextBlockUtils.empty(0, 0);
|
|
|
|
}
|
|
|
|
if (shape == IdeaShape.BOX) {
|
2019-11-03 17:40:03 +00:00
|
|
|
final ISkinParam foo = new SkinParamColors(skinParam, Colors.empty().add(ColorType.BACK, backColor));
|
2021-07-25 10:41:36 +00:00
|
|
|
final TextBlock box = FtileBoxOld.createMindMap(styleBuilder, foo, label, getDefaultStyleDefinitionNode());
|
2020-05-07 14:12:08 +00:00
|
|
|
return TextBlockUtils.withMargin(box, 0, 0, marginTop, marginBottom);
|
2019-03-01 22:16:29 +00:00
|
|
|
}
|
2019-08-26 17:07:21 +00:00
|
|
|
|
2020-09-19 15:43:24 +00:00
|
|
|
assert shape == IdeaShape.NONE;
|
|
|
|
final Style styleNode = getDefaultStyleDefinitionNode().getMergedStyle(styleBuilder);
|
2021-05-06 21:23:05 +00:00
|
|
|
final TextBlock text = label.create0(
|
|
|
|
styleNode.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()),
|
2021-03-07 12:23:24 +00:00
|
|
|
styleNode.getHorizontalAlignment(), skinParam, styleNode.wrapWidth(), CreoleMode.FULL, null, null);
|
2019-08-26 17:07:21 +00:00
|
|
|
if (direction == Direction.RIGHT) {
|
|
|
|
return TextBlockUtils.withMargin(text, 3, 0, 1, 1);
|
|
|
|
}
|
|
|
|
return TextBlockUtils.withMargin(text, 0, 3, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getNailThickness(StringBounder stringBounder) {
|
|
|
|
return tetris(stringBounder).getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getNailElongation(StringBounder stringBounder) {
|
|
|
|
return tetris(stringBounder).getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getFullThickness(StringBounder stringBounder) {
|
|
|
|
final double thickness1 = getPhalanxThickness(stringBounder);
|
|
|
|
final double thickness2 = getNailThickness(stringBounder);
|
|
|
|
// System.err.println("thickness1=" + thickness1 + " thickness2=" + thickness2);
|
|
|
|
return Math.max(thickness1, thickness2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getFullElongation(StringBounder stringBounder) {
|
|
|
|
return getPhalanxElongation(stringBounder) + getNailElongation(stringBounder);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void doNotDrawFirstPhalanx() {
|
|
|
|
this.drawPhalanx = false;
|
2019-03-01 22:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|