1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-17 07:32:24 +00:00
plantuml/src/net/sourceforge/plantuml/svek/image/EntityImageTips.java

165 lines
5.9 KiB
Java
Raw Normal View History

2015-05-31 18:56:03 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, 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
*
* 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5183 $
*
*/
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;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
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;
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 int getShield() {
return 0;
}
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();
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();
2015-06-07 10:23:10 +00:00
final Rectangle2D memberPosition = shapeOther.getImage().getInnerPosition(ent.getKey(), stringBounder);
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();
if (position == Position.RIGHT) {
x += memberPosition.getMaxX();
} else {
x += 4;
}
2016-01-30 12:20:07 +00:00
if (memberPosition == null) {
return;
}
2015-06-07 10:23:10 +00:00
final double y = positionOther.getY() - positionMe.getY() - height + memberPosition.getCenterY();
final Point2D pp2 = new Point2D.Double(x, y);
opale.setOpale(position.reverseDirection(), 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,
2015-09-28 20:42:17 +00:00
new FontConfiguration(skinParam, FontParam.NOTE, null));
2015-06-07 10:23:10 +00:00
final Opale opale = new Opale(borderColor, noteBackgroundColor, textBlock, skinParam.shadowing(), true);
2015-05-31 18:56:03 +00:00
return opale;
}
}