2015-05-31 18:56:03 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2019-01-16 18:34:41 +00:00
|
|
|
* (C) Copyright 2009-2020, Arnaud Roques
|
2015-05-31 18:56:03 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2015-05-31 18:56:03 +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-05-31 18:56:03 +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.Point2D;
|
|
|
|
import java.awt.geom.Rectangle2D;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.ColorParam;
|
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
2017-02-26 16:26:11 +00:00
|
|
|
import net.sourceforge.plantuml.Direction;
|
2015-05-31 18:56:03 +00:00
|
|
|
import net.sourceforge.plantuml.FontParam;
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
2018-03-09 21:37:34 +00:00
|
|
|
import net.sourceforge.plantuml.LineBreakStrategy;
|
2015-06-07 10:23:10 +00:00
|
|
|
import net.sourceforge.plantuml.command.Position;
|
2015-05-31 18:56:03 +00:00
|
|
|
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.graphic.FontConfiguration;
|
|
|
|
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
|
|
|
|
import net.sourceforge.plantuml.graphic.HtmlColor;
|
2017-04-05 17:37:42 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.InnerStrategy;
|
2015-05-31 18:56:03 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
2015-09-28 20:42:17 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.color.ColorType;
|
2015-05-31 18:56:03 +00:00
|
|
|
import net.sourceforge.plantuml.skin.rose.Rose;
|
|
|
|
import net.sourceforge.plantuml.svek.AbstractEntityImage;
|
|
|
|
import net.sourceforge.plantuml.svek.Bibliotekon;
|
|
|
|
import net.sourceforge.plantuml.svek.Shape;
|
|
|
|
import net.sourceforge.plantuml.svek.ShapeType;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
|
|
|
|
|
|
|
public class EntityImageTips extends AbstractEntityImage {
|
|
|
|
|
|
|
|
final private Rose rose = new Rose();
|
|
|
|
private final ISkinParam skinParam;
|
|
|
|
|
|
|
|
private final HtmlColor noteBackgroundColor;
|
|
|
|
private final HtmlColor borderColor;
|
|
|
|
|
|
|
|
private final Bibliotekon bibliotekon;
|
|
|
|
|
|
|
|
private final double ySpacing = 10;
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
public EntityImageTips(ILeaf entity, ISkinParam skinParam, Bibliotekon bibliotekon) {
|
2015-05-31 18:56:03 +00:00
|
|
|
super(entity, EntityImageNote.getSkin(skinParam, entity));
|
|
|
|
this.skinParam = skinParam;
|
|
|
|
this.bibliotekon = bibliotekon;
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
if (entity.getColors(skinParam).getColor(ColorType.BACK) == null) {
|
2015-05-31 18:56:03 +00:00
|
|
|
noteBackgroundColor = rose.getHtmlColor(skinParam, ColorParam.noteBackground);
|
|
|
|
} else {
|
2015-09-28 20:42:17 +00:00
|
|
|
noteBackgroundColor = entity.getColors(skinParam).getColor(ColorType.BACK);
|
2015-05-31 18:56:03 +00:00
|
|
|
}
|
|
|
|
this.borderColor = rose.getHtmlColor(skinParam, ColorParam.noteBorder);
|
|
|
|
}
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
private Position getPosition() {
|
|
|
|
if (getEntity().getCode().getFullName().endsWith(Position.RIGHT.name())) {
|
|
|
|
return Position.RIGHT;
|
|
|
|
}
|
|
|
|
return Position.LEFT;
|
|
|
|
}
|
|
|
|
|
2015-05-31 18:56:03 +00:00
|
|
|
public ShapeType getShapeType() {
|
|
|
|
return ShapeType.RECTANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
double width = 0;
|
|
|
|
double height = 0;
|
|
|
|
for (Map.Entry<String, Display> ent : getEntity().getTips().entrySet()) {
|
|
|
|
final Display display = ent.getValue();
|
|
|
|
final Dimension2D dim = getOpale(display).calculateDimension(stringBounder);
|
|
|
|
height += dim.getHeight();
|
|
|
|
height += ySpacing;
|
|
|
|
width = Math.max(width, dim.getWidth());
|
|
|
|
}
|
|
|
|
return new Dimension2DDouble(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void drawU(UGraphic ug) {
|
|
|
|
final StringBounder stringBounder = ug.getStringBounder();
|
|
|
|
|
|
|
|
final IEntity other = bibliotekon.getOnlyOther(getEntity());
|
|
|
|
|
|
|
|
final Shape shapeMe = bibliotekon.getShape(getEntity());
|
|
|
|
final Shape shapeOther = bibliotekon.getShape(other);
|
2015-06-07 10:23:10 +00:00
|
|
|
final Point2D positionMe = shapeMe.getPosition();
|
|
|
|
final Point2D positionOther = shapeOther.getPosition();
|
2015-05-31 18:56:03 +00:00
|
|
|
bibliotekon.getShape(getEntity());
|
2015-06-07 10:23:10 +00:00
|
|
|
final Position position = getPosition();
|
2017-02-26 16:26:11 +00:00
|
|
|
Direction direction = position.reverseDirection();
|
2015-06-07 10:23:10 +00:00
|
|
|
double height = 0;
|
2015-05-31 18:56:03 +00:00
|
|
|
for (Map.Entry<String, Display> ent : getEntity().getTips().entrySet()) {
|
|
|
|
final Display display = ent.getValue();
|
2018-03-09 21:37:34 +00:00
|
|
|
final Rectangle2D memberPosition = shapeOther.getImage().getInnerPosition(ent.getKey(), stringBounder,
|
|
|
|
InnerStrategy.STRICT);
|
2016-05-31 19:41:55 +00:00
|
|
|
if (memberPosition == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-31 18:56:03 +00:00
|
|
|
final Opale opale = getOpale(display);
|
|
|
|
final Dimension2D dim = opale.calculateDimension(stringBounder);
|
2015-06-07 10:23:10 +00:00
|
|
|
final Point2D pp1 = new Point2D.Double(0, dim.getHeight() / 2);
|
|
|
|
double x = positionOther.getX() - positionMe.getX();
|
2017-02-26 16:26:11 +00:00
|
|
|
if (direction == Direction.RIGHT && x < 0) {
|
|
|
|
direction = direction.getInv();
|
|
|
|
}
|
|
|
|
if (direction == Direction.LEFT) {
|
2015-06-07 10:23:10 +00:00
|
|
|
x += memberPosition.getMaxX();
|
|
|
|
} else {
|
|
|
|
x += 4;
|
|
|
|
}
|
|
|
|
final double y = positionOther.getY() - positionMe.getY() - height + memberPosition.getCenterY();
|
|
|
|
final Point2D pp2 = new Point2D.Double(x, y);
|
2017-02-26 16:26:11 +00:00
|
|
|
opale.setOpale(direction, pp1, pp2);
|
2015-05-31 18:56:03 +00:00
|
|
|
opale.drawU(ug);
|
|
|
|
ug = ug.apply(new UTranslate(0, dim.getHeight() + ySpacing));
|
2015-06-07 10:23:10 +00:00
|
|
|
height += dim.getHeight();
|
|
|
|
height += ySpacing;
|
2015-05-31 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private Opale getOpale(final Display display) {
|
2015-09-28 20:42:17 +00:00
|
|
|
// final HtmlColor fontColor = rose.getFontColor(skinParam, FontParam.NOTE);
|
|
|
|
// final UFont fontNote = skinParam.getFont(FontParam.NOTE, null, false);
|
2015-05-31 18:56:03 +00:00
|
|
|
final TextBlock textBlock = new BodyEnhanced2(display, FontParam.NOTE, skinParam, HorizontalAlignment.LEFT,
|
2018-03-09 21:37:34 +00:00
|
|
|
new FontConfiguration(skinParam, FontParam.NOTE, null), LineBreakStrategy.NONE);
|
2019-08-26 17:07:21 +00:00
|
|
|
final double shadowing = skinParam.shadowing(getEntity().getStereotype())?4:0;
|
|
|
|
final Opale opale = new Opale(shadowing, borderColor, noteBackgroundColor, textBlock, true);
|
2015-05-31 18:56:03 +00:00
|
|
|
return opale;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|