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

147 lines
5.6 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
*
* 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
* Modified by : Arno Peterson
*
* Revision $Revision: 5183 $
*
*/
package net.sourceforge.plantuml.svek.image;
import java.awt.geom.Dimension2D;
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;
import net.sourceforge.plantuml.svek.ShapeType;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UStroke;
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;
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();
2016-01-09 12:15:40 +00:00
USymbol symbol = entity.getUSymbol() == null ? (getSkinParam().useUml2ForComponent() ? USymbol.COMPONENT2
2015-04-07 18:18:37 +00:00
: USymbol.COMPONENT1) : entity.getUSymbol();
if (symbol == null) {
throw new IllegalArgumentException();
2013-12-10 19:36:50 +00:00
}
2015-09-28 20:42:17 +00:00
shapeType = symbol == USymbol.FOLDER ? ShapeType.FOLDER : ShapeType.RECTANGLE;
2013-12-10 19:36:50 +00:00
2015-07-11 09:32:49 +00:00
final Display codeDisplay = Display.getWithNewlines(entity.getCode());
final TextBlock desc = (entity.getDisplay().equals(codeDisplay) && symbol instanceof USymbolFolder)
|| entity.getDisplay().isWhite() ? TextBlockUtils.empty(0, 0) : new BodyEnhanced(entity.getDisplay(),
2015-09-28 20:42:17 +00:00
symbol.getFontParam(), getSkinParam(), HorizontalAlignment.CENTER, stereotype,
2015-05-31 18:56:03 +00:00
symbol.manageHorizontalLine(), false, false);
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
}
2015-04-07 18:18:37 +00:00
// backcolor = HtmlColorUtils.BLUE;
final HtmlColor forecolor = SkinParamUtils.getColor(getSkinParam(), symbol.getColorParamBorder(), getStereo());
final SymbolContext ctx = new SymbolContext(backcolor, forecolor).withStroke(new UStroke(1.5)).withShadow(
2015-05-03 15:36:36 +00:00
getSkinParam().shadowing2(symbol.getSkinParameter()));
2015-04-07 18:18:37 +00:00
TextBlock stereo = TextBlockUtils.empty(0, 0);
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,
stereotype, symbol.manageHorizontalLine(), false, false);
2015-07-11 09:32:49 +00:00
asSmall = symbol.asSmall(name, desc, stereo, ctx);
2013-12-10 19:36:50 +00:00
}
2015-09-28 20:42:17 +00:00
public Dimension2D getNameDimension(StringBounder stringBounder) {
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
}
final public void drawU(UGraphic ug) {
if (url != null) {
ug.startUrl(url);
}
2015-04-07 18:18:37 +00:00
asSmall.drawU(ug);
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
}
public int getShield() {
return 0;
}
}