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/EntityImageComponent.java

130 lines
4.8 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2015-04-07 18:18:37 +00:00
* (C) Copyright 2009-2014, Arnaud Roques
2013-12-10 19:36:50 +00:00
*
* Project Info: http://plantuml.sourceforge.net
*
* 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;
import net.sourceforge.plantuml.svek.AbstractEntityImage;
import net.sourceforge.plantuml.svek.ShapeType;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UStroke;
public class EntityImageComponent extends AbstractEntityImage {
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-04-07 18:18:37 +00:00
public EntityImageComponent(ILeaf entity, ISkinParam skinParam, PortionShower portionShower) {
2013-12-10 19:36:50 +00:00
super(entity, skinParam);
final Stereotype stereotype = entity.getStereotype();
2015-04-07 18:18:37 +00:00
final USymbol symbol = entity.getUSymbol() == null ? (skinParam.useUml2ForComponent() ? USymbol.COMPONENT2
: USymbol.COMPONENT1) : entity.getUSymbol();
if (symbol == null) {
throw new IllegalArgumentException();
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
final TextBlock desc = entity.getDisplay().isWhite() ? TextBlockUtils.empty(0, 0) : new BodyEnhanced(
entity.getDisplay(), symbol.getFontParam(), skinParam, 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-04-07 18:18:37 +00:00
HtmlColor backcolor = getEntity().getSpecificBackColor();
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);
if (stereotype != null && stereotype.getLabel(false) != null
&& portionShower.showPortion(EntityPortion.STEREOTYPE, entity)) {
stereo = TextBlockUtils.create(
Display.getWithNewlines(stereotype.getLabel(getSkinParam().useGuillemet())),
new FontConfiguration(SkinParamUtils.getFont(getSkinParam(), symbol.getFontParamStereotype(),
stereotype), SkinParamUtils.getFontColor(getSkinParam(), symbol.getFontParamStereotype(),
null), getSkinParam().getHyperlinkColor(), getSkinParam().useUnderlineForHyperlink()),
HorizontalAlignment.CENTER, skinParam);
2013-12-10 19:36:50 +00:00
}
2015-04-07 18:18:37 +00:00
asSmall = symbol.asSmall(desc, stereo, ctx);
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() {
return ShapeType.RECTANGLE;
}
public int getShield() {
return 0;
}
}