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
|
|
|
*
|
|
|
|
* 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;
|
2015-06-07 10:23:10 +00:00
|
|
|
import java.awt.geom.Rectangle2D;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
import net.sourceforge.plantuml.ColorParam;
|
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
|
|
|
import net.sourceforge.plantuml.FontParam;
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
|
|
|
import net.sourceforge.plantuml.LineConfigurable;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.LineParam;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.SkinParamUtils;
|
|
|
|
import net.sourceforge.plantuml.Url;
|
|
|
|
import net.sourceforge.plantuml.creole.Stencil;
|
2015-06-07 10:23:10 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.ILeaf;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.PortionShower;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
|
2013-12-10 19:36:50 +00:00
|
|
|
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;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.AbstractEntityImage;
|
2016-07-04 19:06:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.Ports;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.ShapeType;
|
2016-07-04 19:06:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.WithPorts;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.Shadowable;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UChangeBackColor;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UChangeColor;
|
2016-07-25 19:25:28 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UComment;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphicStencil;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.URectangle;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UStroke;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
|
|
|
|
2016-07-04 19:06:50 +00:00
|
|
|
public class EntityImageClass extends AbstractEntityImage implements Stencil, WithPorts {
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
final private TextBlock body;
|
|
|
|
final private int shield;
|
|
|
|
final private EntityImageClassHeader2 header;
|
|
|
|
final private Url url;
|
|
|
|
final private double roundCorner;
|
|
|
|
|
|
|
|
final private LineConfigurable lineConfig;
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
public EntityImageClass(GraphvizVersion version, ILeaf entity, ISkinParam skinParam, PortionShower portionShower) {
|
2015-09-28 20:42:17 +00:00
|
|
|
super(entity, entity.getColors(skinParam).mute(skinParam));
|
2013-12-10 19:36:50 +00:00
|
|
|
this.lineConfig = entity;
|
2016-11-04 21:39:29 +00:00
|
|
|
this.roundCorner = getSkinParam().getRoundCorner("");
|
2015-04-07 18:18:37 +00:00
|
|
|
this.shield = version != null && version.useShield() && entity.hasNearDecoration() ? 16 : 0;
|
2015-06-07 10:23:10 +00:00
|
|
|
final boolean showMethods = portionShower.showPortion(EntityPortion.METHOD, entity);
|
|
|
|
final boolean showFields = portionShower.showPortion(EntityPortion.FIELD, entity);
|
2016-07-04 19:06:50 +00:00
|
|
|
this.body = entity.getBodier().getBody(FontParam.CLASS_ATTRIBUTE, getSkinParam(), showMethods, showFields,
|
|
|
|
entity.getStereotype());
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
header = new EntityImageClassHeader2(entity, getSkinParam(), portionShower);
|
2013-12-10 19:36:50 +00:00
|
|
|
this.url = entity.getUrl99();
|
|
|
|
}
|
|
|
|
|
|
|
|
// private int marginEmptyFieldsOrMethod = 13;
|
|
|
|
|
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
|
|
|
|
final Dimension2D dimBody = body == null ? new Dimension2DDouble(0, 0) : body.calculateDimension(stringBounder);
|
|
|
|
double width = Math.max(dimBody.getWidth(), dimHeader.getWidth());
|
|
|
|
if (width < getSkinParam().minClassWidth()) {
|
|
|
|
width = getSkinParam().minClassWidth();
|
|
|
|
}
|
|
|
|
final double height = dimBody.getHeight() + dimHeader.getHeight();
|
|
|
|
return new Dimension2DDouble(width, height);
|
|
|
|
}
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
@Override
|
|
|
|
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder) {
|
|
|
|
final Rectangle2D result = body.getInnerPosition(member, stringBounder);
|
|
|
|
if (result == null) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
|
|
|
|
final UTranslate translate = new UTranslate(0, dimHeader.getHeight());
|
|
|
|
return translate.apply(result);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
final public void drawU(UGraphic ug) {
|
2016-07-25 19:25:28 +00:00
|
|
|
ug.draw(new UComment("class " + getEntity().getCode().getFullName()));
|
2013-12-10 19:36:50 +00:00
|
|
|
if (url != null) {
|
|
|
|
ug.startUrl(url);
|
|
|
|
}
|
|
|
|
drawInternal(ug);
|
|
|
|
|
|
|
|
if (url != null) {
|
|
|
|
ug.closeAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void drawInternal(UGraphic ug) {
|
|
|
|
final StringBounder stringBounder = ug.getStringBounder();
|
|
|
|
final Dimension2D dimTotal = calculateDimension(stringBounder);
|
|
|
|
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
|
|
|
|
|
|
|
|
final double widthTotal = dimTotal.getWidth();
|
|
|
|
final double heightTotal = dimTotal.getHeight();
|
|
|
|
final Shadowable rect = new URectangle(widthTotal, heightTotal, roundCorner, roundCorner);
|
|
|
|
if (getSkinParam().shadowing()) {
|
|
|
|
rect.setDeltaShadow(4);
|
|
|
|
}
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
HtmlColor classBorder = lineConfig.getColors(getSkinParam()).getColor(ColorType.LINE);
|
2013-12-10 19:36:50 +00:00
|
|
|
if (classBorder == null) {
|
|
|
|
classBorder = SkinParamUtils.getColor(getSkinParam(), ColorParam.classBorder, getStereo());
|
|
|
|
}
|
|
|
|
ug = ug.apply(new UChangeColor(classBorder));
|
2015-09-28 20:42:17 +00:00
|
|
|
HtmlColor backcolor = getEntity().getColors(getSkinParam()).getColor(ColorType.BACK);
|
2013-12-10 19:36:50 +00:00
|
|
|
if (backcolor == null) {
|
|
|
|
backcolor = SkinParamUtils.getColor(getSkinParam(), ColorParam.classBackground, getStereo());
|
|
|
|
}
|
|
|
|
ug = ug.apply(new UChangeBackColor(backcolor));
|
|
|
|
|
|
|
|
final UStroke stroke = getStroke();
|
|
|
|
ug.apply(stroke).draw(rect);
|
|
|
|
|
2015-09-28 20:42:17 +00:00
|
|
|
HtmlColor headerBackcolor = getEntity().getColors(getSkinParam()).getColor(ColorType.HEADER);
|
|
|
|
if (headerBackcolor == null) {
|
|
|
|
headerBackcolor = getSkinParam().getHtmlColor(ColorParam.classHeaderBackground, getStereo(), false);
|
|
|
|
}
|
2015-04-20 19:45:13 +00:00
|
|
|
if (headerBackcolor != null) {
|
|
|
|
final Shadowable rect2 = new URectangle(widthTotal, dimHeader.getHeight());
|
|
|
|
ug.apply(new UChangeBackColor(headerBackcolor)).apply(stroke).draw(rect2);
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
header.drawU(ug, dimTotal.getWidth(), dimHeader.getHeight());
|
|
|
|
|
|
|
|
if (body != null) {
|
2016-12-01 20:29:25 +00:00
|
|
|
final UGraphic ug2 = UGraphicStencil.create(ug, this, stroke);
|
2015-06-07 10:23:10 +00:00
|
|
|
final UTranslate translate = new UTranslate(0, dimHeader.getHeight());
|
|
|
|
body.drawU(ug2.apply(translate));
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 19:06:50 +00:00
|
|
|
public Ports getPorts(StringBounder stringBounder) {
|
|
|
|
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
|
|
|
|
return ((WithPorts) body).getPorts(stringBounder).translateY(dimHeader.getHeight());
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private UStroke getStroke() {
|
2015-09-28 20:42:17 +00:00
|
|
|
UStroke stroke = lineConfig.getColors(getSkinParam()).getSpecificLineStroke();
|
2015-04-07 18:18:37 +00:00
|
|
|
if (stroke == null) {
|
|
|
|
stroke = getSkinParam().getThickness(LineParam.classBorder, getStereo());
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
if (stroke == null) {
|
|
|
|
stroke = new UStroke(1.5);
|
|
|
|
}
|
|
|
|
return stroke;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ShapeType getShapeType() {
|
2016-07-04 19:06:50 +00:00
|
|
|
if (((ILeaf) getEntity()).hasPort()) {
|
|
|
|
return ShapeType.RECTANGLE_HTML_FOR_PORTS;
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
return ShapeType.RECTANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getShield() {
|
|
|
|
return shield;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getStartingX(StringBounder stringBounder, double y) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getEndingX(StringBounder stringBounder, double y) {
|
|
|
|
return calculateDimension(stringBounder).getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|