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

150 lines
4.9 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, 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;
import java.awt.geom.Dimension2D;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.FontParam;
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;
2015-07-11 09:32:49 +00:00
import net.sourceforge.plantuml.creole.CreoleMode;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.BodyEnhanced2;
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;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.graphic.HtmlColor;
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;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UFont;
2010-11-15 20:35:36 +00:00
public abstract class AbstractTextualComponent extends AbstractComponent {
2013-12-10 19:36:50 +00:00
private final Display strings;
2010-11-15 20:35:36 +00:00
private final int marginX1;
private final int marginX2;
private final int marginY;
private final TextBlock textBlock;
2011-08-08 17:48:29 +00:00
private final UFont font;
private final HtmlColor fontColor;
2010-11-15 20:35:36 +00:00
2018-03-09 21:37:34 +00:00
public AbstractTextualComponent(LineBreakStrategy maxMessageSize, CharSequence label, FontConfiguration font,
HorizontalAlignment horizontalAlignment, int marginX1, int marginX2, int marginY,
ISkinSimple spriteContainer, UFont fontForStereotype, HtmlColor htmlColorForStereotype) {
2017-02-26 16:26:11 +00:00
this(maxMessageSize, Display.getWithNewlines(label == null ? "" : label.toString()), font, horizontalAlignment,
marginX1, marginX2, marginY, spriteContainer, false, fontForStereotype, htmlColorForStereotype);
2010-11-15 20:35:36 +00:00
}
2017-02-26 16:26:11 +00:00
public AbstractTextualComponent(LineBreakStrategy maxMessageSize, Display strings, FontConfiguration font,
2018-03-09 21:37:34 +00:00
HorizontalAlignment horizontalAlignment, int marginX1, int marginX2, int marginY,
ISkinSimple spriteContainer, boolean enhanced, UFont fontForStereotype, HtmlColor htmlColorForStereotype) {
2015-04-20 19:45:13 +00:00
this.font = font.getFont();
this.fontColor = font.getColor();
2010-11-15 20:35:36 +00:00
this.marginX1 = marginX1;
this.marginX2 = marginX2;
this.marginY = marginY;
this.strings = strings;
2011-01-05 18:23:06 +00:00
if (strings.size() == 1 && strings.get(0).length() == 0) {
textBlock = new TextBlockEmpty();
2013-12-10 19:36:50 +00:00
} else if (enhanced) {
2018-07-27 21:56:46 +00:00
textBlock = new BodyEnhanced2(strings, FontParam.NOTE, spriteContainer, horizontalAlignment, font,
2018-03-09 21:37:34 +00:00
maxMessageSize);
2011-01-05 18:23:06 +00:00
} else {
2015-07-11 09:32:49 +00:00
textBlock = strings.create(font, horizontalAlignment, spriteContainer, maxMessageSize, CreoleMode.FULL,
fontForStereotype, htmlColorForStereotype);
2011-01-05 18:23:06 +00:00
}
2010-11-15 20:35:36 +00:00
}
final protected TextBlock getTextBlock() {
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;
}
2013-12-10 19:36:50 +00:00
// // For cache
// private Dimension2D size;
//
// private Dimension2D getSize(StringBounder stringBounder, final TextBlock textBlock) {
// if (size == null) {
// size = textBlock.calculateDimension(stringBounder);
// }
// return size;
// }
2010-11-15 20:35:36 +00:00
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;
}
2013-12-10 19:36:50 +00:00
final protected Display getLabels() {
2010-11-15 20:35:36 +00:00
return strings;
}
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;
}
2011-08-08 17:48:29 +00:00
protected HtmlColor getFontColor() {
2010-11-15 20:35:36 +00:00
return fontColor;
}
}