2013-12-10 19:36:50 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2016-01-09 12:15:40 +00:00
|
|
|
* (C) Copyright 2009-2017, Arnaud Roques
|
2013-12-10 19:36:50 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2013-12-10 19:36:50 +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
|
|
|
|
*
|
2013-12-10 19:36:50 +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.image;
|
|
|
|
|
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.awt.geom.Line2D;
|
|
|
|
import java.awt.geom.Point2D;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.ColorParam;
|
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
|
|
|
import net.sourceforge.plantuml.Direction;
|
|
|
|
import net.sourceforge.plantuml.FontParam;
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
2016-09-29 19:51:18 +00:00
|
|
|
import net.sourceforge.plantuml.LineParam;
|
2018-04-06 20:36:30 +00:00
|
|
|
import net.sourceforge.plantuml.CornerParam;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.SkinParamBackcolored;
|
2015-09-28 20:42:17 +00:00
|
|
|
import net.sourceforge.plantuml.SkinParamUtils;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.Url;
|
|
|
|
import net.sourceforge.plantuml.creole.Stencil;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.BodyEnhanced2;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Display;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.IEntity;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.ILeaf;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Stereotype;
|
|
|
|
import net.sourceforge.plantuml.graph2.GeomUtils;
|
2015-05-03 15:36:36 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.FontConfiguration;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
|
|
|
|
import net.sourceforge.plantuml.graphic.HtmlColor;
|
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlockEmpty;
|
2015-09-28 20:42:17 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.color.ColorType;
|
|
|
|
import net.sourceforge.plantuml.graphic.color.Colors;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.posimo.DotPath;
|
|
|
|
import net.sourceforge.plantuml.skin.rose.Rose;
|
|
|
|
import net.sourceforge.plantuml.svek.AbstractEntityImage;
|
|
|
|
import net.sourceforge.plantuml.svek.Line;
|
|
|
|
import net.sourceforge.plantuml.svek.Shape;
|
|
|
|
import net.sourceforge.plantuml.svek.ShapeType;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UChangeBackColor;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UChangeColor;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphicStencil;
|
2018-01-28 22:08:15 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UPath;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UStroke;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
|
|
|
|
|
|
|
public class EntityImageNote extends AbstractEntityImage implements Stencil {
|
|
|
|
|
|
|
|
private final HtmlColor noteBackgroundColor;
|
|
|
|
private final HtmlColor borderColor;
|
|
|
|
private final int marginX1 = 6;
|
|
|
|
private final int marginX2 = 15;
|
|
|
|
private final int marginY = 5;
|
|
|
|
private final boolean withShadow;
|
|
|
|
private final ISkinParam skinParam;
|
|
|
|
|
|
|
|
private final TextBlock textBlock;
|
|
|
|
|
|
|
|
public EntityImageNote(ILeaf entity, ISkinParam skinParam) {
|
2015-09-28 20:42:17 +00:00
|
|
|
super(entity, getSkin(getISkinParam(skinParam, entity), entity));
|
|
|
|
this.skinParam = getISkinParam(skinParam, entity);
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2018-09-23 12:15:14 +00:00
|
|
|
this.withShadow = getSkinParam().shadowing(getEntity().getStereotype());
|
2013-12-10 19:36:50 +00:00
|
|
|
final Display strings = entity.getDisplay();
|
|
|
|
|
|
|
|
final Rose rose = new Rose();
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
if (entity.getColors(getSkinParam()).getColor(ColorType.BACK) == null) {
|
|
|
|
noteBackgroundColor = rose.getHtmlColor(getSkinParam(), ColorParam.noteBackground);
|
2013-12-10 19:36:50 +00:00
|
|
|
} else {
|
2015-09-28 20:42:17 +00:00
|
|
|
noteBackgroundColor = entity.getColors(getSkinParam()).getColor(ColorType.BACK);
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2015-09-28 20:42:17 +00:00
|
|
|
// this.borderColor = rose.getHtmlColor(skinParam, ColorParam.noteBorder);
|
|
|
|
this.borderColor = SkinParamUtils.getColor(getSkinParam(), ColorParam.noteBorder, null);
|
|
|
|
// final HtmlColor fontColor = rose.getFontColor(getSkinParam(), FontParam.NOTE);
|
|
|
|
// final UFont fontNote = getSkinParam().getFont(FontParam.NOTE, null, false);
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
if (strings.size() == 1 && strings.get(0).length() == 0) {
|
|
|
|
textBlock = new TextBlockEmpty();
|
|
|
|
} else {
|
2015-09-28 20:42:17 +00:00
|
|
|
textBlock = new BodyEnhanced2(strings, FontParam.NOTE, getSkinParam(), HorizontalAlignment.LEFT,
|
2018-03-09 21:37:34 +00:00
|
|
|
new FontConfiguration(getSkinParam(), FontParam.NOTE, null), getSkinParam().wrapWidth());
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
private static ISkinParam getISkinParam(ISkinParam skinParam, IEntity entity) {
|
|
|
|
if (entity.getColors(skinParam) != null) {
|
|
|
|
return entity.getColors(skinParam).mute(skinParam);
|
|
|
|
}
|
|
|
|
return skinParam;
|
|
|
|
}
|
|
|
|
|
2015-05-31 18:56:03 +00:00
|
|
|
static ISkinParam getSkin(ISkinParam skinParam, IEntity entity) {
|
2013-12-10 19:36:50 +00:00
|
|
|
final Stereotype stereotype = entity.getStereotype();
|
2015-09-28 20:42:17 +00:00
|
|
|
HtmlColor back = entity.getColors(skinParam).getColor(ColorType.BACK);
|
2013-12-10 19:36:50 +00:00
|
|
|
if (back != null) {
|
|
|
|
return new SkinParamBackcolored(skinParam, back);
|
|
|
|
}
|
|
|
|
back = getColorStatic(skinParam, ColorParam.noteBackground, stereotype);
|
|
|
|
if (back != null) {
|
|
|
|
return new SkinParamBackcolored(skinParam, back);
|
|
|
|
}
|
|
|
|
return skinParam;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static HtmlColor getColorStatic(ISkinParam skinParam, ColorParam colorParam, Stereotype stereo) {
|
|
|
|
final Rose rose = new Rose();
|
2015-04-07 18:18:37 +00:00
|
|
|
return rose.getHtmlColor(skinParam, colorParam, stereo);
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final public double getPreferredWidth(StringBounder stringBounder) {
|
|
|
|
final double result = getTextWidth(stringBounder);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
final public double getPreferredHeight(StringBounder stringBounder) {
|
|
|
|
return getTextHeight(stringBounder);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Dimension2D getSize(StringBounder stringBounder, final TextBlock textBlock) {
|
|
|
|
return textBlock.calculateDimension(stringBounder);
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected double getTextHeight(StringBounder stringBounder) {
|
|
|
|
final TextBlock textBlock = getTextBlock();
|
|
|
|
final Dimension2D size = getSize(stringBounder, textBlock);
|
|
|
|
return size.getHeight() + 2 * marginY;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected TextBlock getTextBlock() {
|
|
|
|
return textBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
final protected double getPureTextWidth(StringBounder stringBounder) {
|
|
|
|
final TextBlock textBlock = getTextBlock();
|
|
|
|
final Dimension2D size = getSize(stringBounder, textBlock);
|
|
|
|
return size.getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
final public double getTextWidth(StringBounder stringBounder) {
|
|
|
|
return getPureTextWidth(stringBounder) + marginX1 + marginX2;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
final double height = getPreferredHeight(stringBounder);
|
|
|
|
final double width = getPreferredWidth(stringBounder);
|
|
|
|
return new Dimension2DDouble(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
final public void drawU(UGraphic ug) {
|
|
|
|
final Url url = getEntity().getUrl99();
|
|
|
|
if (url != null) {
|
|
|
|
ug.startUrl(url);
|
|
|
|
}
|
2016-12-01 20:29:25 +00:00
|
|
|
final UGraphic ug2 = UGraphicStencil.create(ug, this, new UStroke());
|
2013-12-10 19:36:50 +00:00
|
|
|
if (opaleLine == null || opaleLine.isOpale() == false) {
|
|
|
|
drawNormal(ug2);
|
|
|
|
} else {
|
|
|
|
final StringBounder stringBounder = ug.getStringBounder();
|
|
|
|
DotPath path = opaleLine.getDotPath();
|
|
|
|
path.moveSvek(-shape.getMinX(), -shape.getMinY());
|
|
|
|
Point2D p1 = path.getStartPoint();
|
|
|
|
Point2D p2 = path.getEndPoint();
|
|
|
|
final double textWidth = getTextWidth(stringBounder);
|
|
|
|
final double textHeight = getTextHeight(stringBounder);
|
|
|
|
final Point2D center = new Point2D.Double(textWidth / 2, textHeight / 2);
|
|
|
|
if (p1.distance(center) > p2.distance(center)) {
|
|
|
|
path = path.reverse();
|
|
|
|
p1 = path.getStartPoint();
|
2015-09-28 20:42:17 +00:00
|
|
|
// p2 = path.getEndPoint();
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
final Direction strategy = getOpaleStrategy(textWidth, textHeight, p1);
|
|
|
|
final Point2D pp1 = path.getStartPoint();
|
|
|
|
final Point2D pp2 = path.getEndPoint();
|
2015-09-28 20:42:17 +00:00
|
|
|
final Point2D newRefpp2 = move(pp2, shape.getMinX(), shape.getMinY());
|
|
|
|
final Point2D projection = move(other.projection(newRefpp2, stringBounder), -shape.getMinX(),
|
|
|
|
-shape.getMinY());
|
2018-09-23 12:15:14 +00:00
|
|
|
final Opale opale = new Opale(borderColor, noteBackgroundColor, textBlock, skinParam.shadowing(getEntity().getStereotype()), true);
|
2018-01-28 22:08:15 +00:00
|
|
|
opale.setRoundCorner(getRoundCorner());
|
2015-09-28 20:42:17 +00:00
|
|
|
opale.setOpale(strategy, pp1, projection);
|
2016-09-29 19:51:18 +00:00
|
|
|
final UGraphic stroked = applyStroke(ug2);
|
|
|
|
opale.drawU(Colors.applyStroke(stroked, getEntity().getColors(skinParam)));
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
if (url != null) {
|
|
|
|
ug.closeAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 22:08:15 +00:00
|
|
|
private double getRoundCorner() {
|
2018-04-06 20:36:30 +00:00
|
|
|
return skinParam.getRoundCorner(CornerParam.DEFAULT, null);
|
2018-01-28 22:08:15 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
private static Point2D move(Point2D pt, double dx, double dy) {
|
|
|
|
return new Point2D.Double(pt.getX() + dx, pt.getY() + dy);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private void drawNormal(UGraphic ug) {
|
|
|
|
final StringBounder stringBounder = ug.getStringBounder();
|
2018-01-28 22:08:15 +00:00
|
|
|
final UPath polygon = Opale.getPolygonNormal(getTextWidth(stringBounder), getTextHeight(stringBounder),
|
|
|
|
getRoundCorner());
|
2013-12-10 19:36:50 +00:00
|
|
|
if (withShadow) {
|
|
|
|
polygon.setDeltaShadow(4);
|
|
|
|
}
|
|
|
|
ug = ug.apply(new UChangeBackColor(noteBackgroundColor)).apply(new UChangeColor(borderColor));
|
2016-09-29 19:51:18 +00:00
|
|
|
final UGraphic stroked = applyStroke(ug);
|
|
|
|
stroked.draw(polygon);
|
2018-01-28 22:08:15 +00:00
|
|
|
ug.draw(Opale.getCorner(getTextWidth(stringBounder), getRoundCorner()));
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
getTextBlock().drawU(ug.apply(new UTranslate(marginX1, marginY)));
|
|
|
|
}
|
|
|
|
|
2016-09-29 19:51:18 +00:00
|
|
|
private UGraphic applyStroke(UGraphic ug) {
|
|
|
|
final UStroke stroke = skinParam.getThickness(LineParam.noteBorder, null);
|
|
|
|
if (stroke == null) {
|
|
|
|
return ug;
|
|
|
|
}
|
|
|
|
return ug.apply(stroke);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private Direction getOpaleStrategy(double width, double height, Point2D pt) {
|
|
|
|
final double d1 = GeomUtils.getOrthoDistance(new Line2D.Double(width, 0, width, height), pt);
|
|
|
|
final double d2 = GeomUtils.getOrthoDistance(new Line2D.Double(0, height, width, height), pt);
|
|
|
|
final double d3 = GeomUtils.getOrthoDistance(new Line2D.Double(0, 0, 0, height), pt);
|
|
|
|
final double d4 = GeomUtils.getOrthoDistance(new Line2D.Double(0, 0, width, 0), pt);
|
|
|
|
if (d3 <= d1 && d3 <= d2 && d3 <= d4) {
|
|
|
|
return Direction.LEFT;
|
|
|
|
}
|
|
|
|
if (d1 <= d2 && d1 <= d3 && d1 <= d4) {
|
|
|
|
return Direction.RIGHT;
|
|
|
|
}
|
|
|
|
if (d4 <= d1 && d4 <= d2 && d4 <= d3) {
|
|
|
|
return Direction.UP;
|
|
|
|
}
|
|
|
|
if (d2 <= d1 && d2 <= d3 && d2 <= d4) {
|
|
|
|
return Direction.DOWN;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public ShapeType getShapeType() {
|
|
|
|
return ShapeType.RECTANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Line opaleLine;
|
|
|
|
private Shape shape;
|
2015-09-28 20:42:17 +00:00
|
|
|
private Shape other;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
public void setOpaleLine(Line line, Shape shape, Shape other) {
|
2016-01-09 12:15:40 +00:00
|
|
|
if (other == null) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
this.opaleLine = line;
|
|
|
|
this.shape = shape;
|
2015-09-28 20:42:17 +00:00
|
|
|
this.other = other;
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public double getStartingX(StringBounder stringBounder, double y) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getEndingX(StringBounder stringBounder, double y) {
|
|
|
|
return calculateDimension(stringBounder).getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|