1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 00:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/skin/AbstractTextualComponent.java

162 lines
5.6 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +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
*
2010-11-15 20:35:36 +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
2010-11-15 20:35:36 +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
*
*
*/
package net.sourceforge.plantuml.skin;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.ISkinParam;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ISkinSimple;
2017-02-26 16:26:11 +00:00
import net.sourceforge.plantuml.LineBreakStrategy;
2022-05-21 09:41:00 +00:00
import net.sourceforge.plantuml.awt.geom.Dimension2D;
2015-07-11 09:32:49 +00:00
import net.sourceforge.plantuml.creole.CreoleMode;
2020-12-14 18:31:06 +00:00
import net.sourceforge.plantuml.cucadiagram.BodyFactory;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2011-01-23 19:36:52 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
2011-01-05 18:23:06 +00:00
import net.sourceforge.plantuml.graphic.TextBlockEmpty;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.PName;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.style.Style;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UFont;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
2010-11-15 20:35:36 +00:00
public abstract class AbstractTextualComponent extends AbstractComponent {
private final int marginX1;
private final int marginX2;
private final int marginY;
private final TextBlock textBlock;
2019-07-14 20:09:26 +00:00
private final ISkinSimple spriteContainer;
2010-11-15 20:35:36 +00:00
2011-08-08 17:48:29 +00:00
private final UFont font;
2020-03-18 10:50:02 +00:00
private final HColor fontColor;
2021-06-27 16:50:40 +00:00
private final HorizontalAlignment alignment;
2010-11-15 20:35:36 +00:00
2022-05-21 09:41:00 +00:00
public AbstractTextualComponent(Style style, LineBreakStrategy maxMessageSize, int marginX1, int marginX2,
int marginY, ISkinSimple spriteContainer, CharSequence label) {
this(style, style, maxMessageSize, marginX1, marginX2, marginY, spriteContainer,
Display.getWithNewlines(label == null ? "" : label.toString()), false);
2010-11-15 20:35:36 +00:00
}
2022-05-21 09:41:00 +00:00
public AbstractTextualComponent(Style style, LineBreakStrategy maxMessageSize, int marginX1, int marginX2,
int marginY, ISkinSimple spriteContainer, Display display, boolean enhanced) {
this(style, style, maxMessageSize, marginX1, marginX2, marginY, spriteContainer, display, enhanced);
2019-07-14 20:09:26 +00:00
}
2022-05-21 09:41:00 +00:00
public AbstractTextualComponent(Style style, Style stereo, LineBreakStrategy maxMessageSize, int marginX1,
int marginX2, int marginY, ISkinSimple spriteContainer, Display display, boolean enhanced) {
2019-07-14 20:09:26 +00:00
super(style);
this.spriteContainer = spriteContainer;
2022-05-21 09:41:00 +00:00
final FontConfiguration fc = style.getFontConfiguration(spriteContainer.getThemeStyle(), getIHtmlColorSet());
this.font = style.getUFont();
this.fontColor = style.value(PName.FontColor).asColor(spriteContainer.getThemeStyle(), getIHtmlColorSet());
final HorizontalAlignment horizontalAlignment = style.getHorizontalAlignment();
final UFont fontForStereotype = stereo.getUFont();
final HColor htmlColorForStereotype = stereo.value(PName.FontColor).asColor(spriteContainer.getThemeStyle(),
getIHtmlColorSet());
2022-06-06 12:36:58 +00:00
display = display.withoutStereotypeIfNeeded(style);
2022-05-21 09:41:00 +00:00
2010-11-15 20:35:36 +00:00
this.marginX1 = marginX1;
this.marginX2 = marginX2;
this.marginY = marginY;
2022-06-06 12:36:58 +00:00
if (display.size() == 1 && display.get(0).length() == 0)
2011-01-05 18:23:06 +00:00
textBlock = new TextBlockEmpty();
2022-05-21 09:41:00 +00:00
else if (enhanced)
2022-06-06 12:36:58 +00:00
textBlock = BodyFactory.create3(display, spriteContainer, horizontalAlignment, fc, maxMessageSize, style);
2022-05-21 09:41:00 +00:00
else
2022-06-06 12:36:58 +00:00
textBlock = display.create0(fc, horizontalAlignment, spriteContainer, maxMessageSize, CreoleMode.FULL,
fontForStereotype, htmlColorForStereotype, marginX1, marginX2);
2022-05-21 09:41:00 +00:00
2021-06-27 16:50:40 +00:00
this.alignment = horizontalAlignment;
2010-11-15 20:35:36 +00:00
}
2020-03-18 10:50:02 +00:00
protected HColorSet getIHtmlColorSet() {
2019-07-14 20:09:26 +00:00
return ((ISkinParam) spriteContainer).getIHtmlColorSet();
}
protected TextBlock getTextBlock() {
2010-11-15 20:35:36 +00:00
return textBlock;
}
2016-06-19 14:16:41 +00:00
protected double getPureTextWidth(StringBounder stringBounder) {
2010-11-15 20:35:36 +00:00
final TextBlock textBlock = getTextBlock();
2013-12-10 19:36:50 +00:00
final Dimension2D size = textBlock.calculateDimension(stringBounder);
2010-11-15 20:35:36 +00:00
return size.getWidth();
}
final public double getTextWidth(StringBounder stringBounder) {
return getPureTextWidth(stringBounder) + marginX1 + marginX2;
}
final protected double getTextHeight(StringBounder stringBounder) {
final TextBlock textBlock = getTextBlock();
2013-12-10 19:36:50 +00:00
final Dimension2D size = textBlock.calculateDimension(stringBounder);
2010-11-15 20:35:36 +00:00
return size.getHeight() + 2 * marginY;
}
final protected int getMarginX1() {
return marginX1;
}
final protected int getMarginX2() {
return marginX2;
}
final protected int getMarginY() {
return marginY;
}
2011-08-08 17:48:29 +00:00
final protected UFont getFont() {
2010-11-15 20:35:36 +00:00
return font;
}
2020-03-18 10:50:02 +00:00
protected HColor getFontColor() {
2010-11-15 20:35:36 +00:00
return fontColor;
}
2019-07-14 20:09:26 +00:00
protected final ISkinSimple getISkinSimple() {
return spriteContainer;
}
2021-06-27 16:50:40 +00:00
public final HorizontalAlignment getHorizontalAlignment() {
return alignment;
}
2010-11-15 20:35:36 +00:00
}