1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-03 09:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/svek/image/EntityImageDescription.java

201 lines
7.7 KiB
Java
Raw Normal View History

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
* Modified by : Arno Peterson
*
*
*/
package net.sourceforge.plantuml.svek.image;
import java.awt.geom.Dimension2D;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.Dimension2DDouble;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.SkinParamUtils;
import net.sourceforge.plantuml.Url;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.BodyEnhanced;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.ILeaf;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.PortionShower;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
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.SymbolContext;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.graphic.USymbol;
2015-07-11 09:32:49 +00:00
import net.sourceforge.plantuml.graphic.USymbolFolder;
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;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.svek.Margins;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.ShapeType;
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.UStroke;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.utils.MathUtils;
2013-12-10 19:36:50 +00:00
2015-07-11 09:32:49 +00:00
public class EntityImageDescription extends AbstractEntityImage {
2013-12-10 19:36:50 +00:00
2015-09-28 20:42:17 +00:00
private final ShapeType shapeType;
2013-12-10 19:36:50 +00:00
final private Url url;
2015-04-07 18:18:37 +00:00
private final TextBlock asSmall;
2013-12-10 19:36:50 +00:00
2015-09-28 20:42:17 +00:00
private final TextBlock name;
2017-04-05 17:37:42 +00:00
private final TextBlock desc;
private TextBlock stereo;
private final boolean hideText;
2015-09-28 20:42:17 +00:00
2015-07-11 09:32:49 +00:00
public EntityImageDescription(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
final Stereotype stereotype = entity.getStereotype();
2017-04-05 17:37:42 +00:00
USymbol symbol = getUSymbol(entity);
this.shapeType = symbol == USymbol.FOLDER ? ShapeType.FOLDER : ShapeType.RECTANGLE;
this.hideText = symbol == USymbol.INTERFACE;
2013-12-10 19:36:50 +00:00
2015-07-11 09:32:49 +00:00
final Display codeDisplay = Display.getWithNewlines(entity.getCode());
2017-04-05 17:37:42 +00:00
desc = (entity.getDisplay().equals(codeDisplay) && symbol instanceof USymbolFolder)
2015-07-11 09:32:49 +00:00
|| entity.getDisplay().isWhite() ? TextBlockUtils.empty(0, 0) : new BodyEnhanced(entity.getDisplay(),
2017-02-15 21:34:36 +00:00
symbol.getFontParam(), getSkinParam(), HorizontalAlignment.LEFT, stereotype,
2017-03-12 17:22:02 +00:00
symbol.manageHorizontalLine(), false, entity);
2013-12-10 19:36:50 +00:00
2015-04-07 18:18:37 +00:00
this.url = entity.getUrl99();
2013-12-10 19:36:50 +00:00
2015-09-28 20:42:17 +00:00
HtmlColor backcolor = getEntity().getColors(getSkinParam()).getColor(ColorType.BACK);
2015-04-07 18:18:37 +00:00
if (backcolor == null) {
backcolor = SkinParamUtils.getColor(getSkinParam(), symbol.getColorParamBack(), getStereo());
2013-12-10 19:36:50 +00:00
}
2017-04-05 17:37:42 +00:00
2016-12-21 22:10:29 +00:00
assert getStereo() == stereotype;
final HtmlColor forecolor = SkinParamUtils.getColor(getSkinParam(), symbol.getColorParamBorder(), stereotype);
2016-12-14 21:01:03 +00:00
final double roundCorner = symbol.getSkinParameter().getRoundCorner(getSkinParam(), stereotype);
2016-12-21 22:10:29 +00:00
final UStroke stroke = symbol.getSkinParameter().getStroke(getSkinParam(), stereotype);
final SymbolContext ctx = new SymbolContext(backcolor, forecolor).withStroke(stroke)
2016-12-14 21:01:03 +00:00
.withShadow(getSkinParam().shadowing2(symbol.getSkinParameter())).withRoundCorner(roundCorner);
2015-04-07 18:18:37 +00:00
2017-04-05 17:37:42 +00:00
stereo = TextBlockUtils.empty(0, 0);
2015-04-07 18:18:37 +00:00
2016-01-09 12:15:40 +00:00
if (stereotype != null && stereotype.getSprite() != null
&& getSkinParam().getSprite(stereotype.getSprite()) != null) {
symbol = symbol.withStereoAlignment(HorizontalAlignment.RIGHT);
2016-04-04 19:05:10 +00:00
stereo = getSkinParam().getSprite(stereotype.getSprite()).asTextBlock(stereotype.getHtmlColor(), 1);
2016-01-09 12:15:40 +00:00
} else if (stereotype != null && stereotype.getLabel(false) != null
2015-04-07 18:18:37 +00:00
&& portionShower.showPortion(EntityPortion.STEREOTYPE, entity)) {
2015-07-11 09:32:49 +00:00
stereo = Display.getWithNewlines(stereotype.getLabel(getSkinParam().useGuillemet())).create(
2015-09-28 20:42:17 +00:00
new FontConfiguration(getSkinParam(), symbol.getFontParamStereotype(), stereotype),
HorizontalAlignment.CENTER, getSkinParam());
2013-12-10 19:36:50 +00:00
}
2015-09-28 20:42:17 +00:00
name = new BodyEnhanced(codeDisplay, symbol.getFontParam(), getSkinParam(), HorizontalAlignment.CENTER,
2017-03-12 17:22:02 +00:00
stereotype, symbol.manageHorizontalLine(), false, entity);
2015-07-11 09:32:49 +00:00
2017-04-05 17:37:42 +00:00
if (hideText) {
asSmall = symbol.asSmall(TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0),
TextBlockUtils.empty(0, 0), ctx);
} else {
asSmall = symbol.asSmall(name, desc, stereo, ctx);
}
}
private USymbol getUSymbol(ILeaf entity) {
final USymbol result = entity.getUSymbol() == null ? (getSkinParam().useUml2ForComponent() ? USymbol.COMPONENT2
: USymbol.COMPONENT1) : entity.getUSymbol();
if (result == null) {
throw new IllegalArgumentException();
}
return result;
2013-12-10 19:36:50 +00:00
}
2015-09-28 20:42:17 +00:00
public Dimension2D getNameDimension(StringBounder stringBounder) {
2017-04-05 17:37:42 +00:00
if (hideText) {
return new Dimension2DDouble(0, 0);
}
2015-09-28 20:42:17 +00:00
return name.calculateDimension(stringBounder);
}
2013-12-10 19:36:50 +00:00
public Dimension2D calculateDimension(StringBounder stringBounder) {
2015-04-07 18:18:37 +00:00
return asSmall.calculateDimension(stringBounder);
2013-12-10 19:36:50 +00:00
}
2017-04-05 17:37:42 +00:00
@Override
public Margins getShield(StringBounder stringBounder) {
if (hideText) {
final Dimension2D dimStereo = stereo.calculateDimension(stringBounder);
final Dimension2D dimDesc = desc.calculateDimension(stringBounder);
final Dimension2D dimSmall = asSmall.calculateDimension(stringBounder);
final double x = Math.max(dimStereo.getWidth(), dimDesc.getWidth());
double suppX = x - dimSmall.getWidth();
if (suppX < 1) {
suppX = 1;
}
final double y = MathUtils.max(1, dimDesc.getHeight(), dimStereo.getHeight());
return new Margins(suppX / 2, suppX / 2, y, y);
}
return Margins.NONE;
}
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("entity " + getEntity().getCode().getFullName()));
2013-12-10 19:36:50 +00:00
if (url != null) {
ug.startUrl(url);
}
2015-04-07 18:18:37 +00:00
asSmall.drawU(ug);
2017-04-05 17:37:42 +00:00
if (hideText) {
final double space = 8;
final Dimension2D dimSmall = asSmall.calculateDimension(ug.getStringBounder());
final Dimension2D dimDesc = desc.calculateDimension(ug.getStringBounder());
desc.drawU(ug.apply(new UTranslate((dimSmall.getWidth() - dimDesc.getWidth()) / 2, space
+ dimSmall.getHeight())));
final Dimension2D dimStereo = stereo.calculateDimension(ug.getStringBounder());
stereo.drawU(ug.apply(new UTranslate((dimSmall.getWidth() - dimStereo.getWidth()) / 2, -space
- dimStereo.getHeight())));
}
2015-04-07 18:18:37 +00:00
2013-12-10 19:36:50 +00:00
if (url != null) {
ug.closeAction();
}
}
public ShapeType getShapeType() {
2015-09-28 20:42:17 +00:00
return shapeType;
2013-12-10 19:36:50 +00:00
}
}