plantuml/src/net/sourceforge/plantuml/svek/image/EntityImageArcCircle.java

115 lines
4.1 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2011-08-08 17:48:29 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2011-08-08 17:48:29 +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
*
2011-08-08 17:48:29 +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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2011-08-08 17:48:29 +00:00
* 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
*
*
*/
2013-12-10 19:36:50 +00:00
package net.sourceforge.plantuml.svek.image;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.FontParam;
2019-03-29 22:14:07 +00:00
import net.sourceforge.plantuml.Guillemet;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ISkinParam;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.awt.geom.Dimension2D;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.ILeaf;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.FontConfiguration;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.AbstractEntityImage;
import net.sourceforge.plantuml.svek.ShapeType;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
public class EntityImageArcCircle extends AbstractEntityImage {
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
// private static final int SIZE = 16;
2011-08-08 17:48:29 +00:00
private final TextBlock name;
private final TextBlock stereo;
2013-12-10 19:36:50 +00:00
public EntityImageArcCircle(ILeaf entity, ISkinParam skinParam) {
2011-08-08 17:48:29 +00:00
super(entity, skinParam);
final Stereotype stereotype = entity.getStereotype();
2022-03-19 12:48:23 +00:00
this.name = entity.getDisplay().create(FontConfiguration.create(getSkinParam(), FontParam.COMPONENT, stereotype),
2015-09-28 20:42:17 +00:00
HorizontalAlignment.CENTER, skinParam);
2011-08-08 17:48:29 +00:00
2019-03-29 22:14:07 +00:00
if (stereotype == null || stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR) == null) {
2011-08-08 17:48:29 +00:00
this.stereo = null;
} else {
2019-03-29 22:14:07 +00:00
this.stereo = Display.getWithNewlines(stereotype.getLabel(getSkinParam().guillemet())).create(
2022-03-19 12:48:23 +00:00
FontConfiguration.create(getSkinParam(), FontParam.COMPONENT_STEREOTYPE, stereotype),
2015-09-28 20:42:17 +00:00
HorizontalAlignment.CENTER, skinParam);
2011-08-08 17:48:29 +00:00
}
}
2013-12-10 19:36:50 +00:00
public Dimension2D calculateDimension(StringBounder stringBounder) {
2011-08-08 17:48:29 +00:00
final Dimension2D dimName = name.calculateDimension(stringBounder);
final Dimension2D dimStereo = getStereoDimension(stringBounder);
2013-12-10 19:36:50 +00:00
// final Dimension2D circle = new Dimension2DDouble(SIZE, SIZE);
return Dimension2DDouble.mergeTB(dimStereo, dimName);
2011-08-08 17:48:29 +00:00
}
private Dimension2D getStereoDimension(StringBounder stringBounder) {
if (stereo == null) {
return new Dimension2DDouble(0, 0);
}
return stereo.calculateDimension(stringBounder);
}
2013-12-10 19:36:50 +00:00
final public void drawU(UGraphic ug) {
2011-08-08 17:48:29 +00:00
final StringBounder stringBounder = ug.getStringBounder();
final Dimension2D dimStereo = getStereoDimension(stringBounder);
2013-12-10 19:36:50 +00:00
final Dimension2D dimTotal = calculateDimension(stringBounder);
2011-08-08 17:48:29 +00:00
final Dimension2D dimName = name.calculateDimension(stringBounder);
final double nameX = (dimTotal.getWidth() - dimName.getWidth()) / 2;
2013-12-10 19:36:50 +00:00
final double nameY = dimStereo.getHeight();
name.drawU(ug.apply(new UTranslate(nameX, nameY)));
2011-08-08 17:48:29 +00:00
if (stereo != null) {
final double stereoX = (dimTotal.getWidth() - dimStereo.getWidth()) / 2;
2020-03-18 10:50:02 +00:00
stereo.drawU(ug.apply(UTranslate.dx(stereoX)));
2011-08-08 17:48:29 +00:00
}
}
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
2013-12-10 19:36:50 +00:00
2011-08-08 17:48:29 +00:00
}