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
|
|
|
*
|
|
|
|
* 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.graphic;
|
|
|
|
|
|
|
|
import java.awt.Font;
|
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.SpriteContainerEmpty;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Display;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.svek.IEntityImage;
|
|
|
|
import net.sourceforge.plantuml.svek.ShapeType;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.ColorMapper;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UChangeColor;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UFont;
|
2010-11-15 20:35:36 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UImage;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
public class GraphicStrings extends AbstractTextBlock implements IEntityImage {
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
private final HtmlColor background;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
private final UFont font;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
private final HtmlColor green;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
private final HtmlColor hyperlinkColor = HtmlColorUtils.BLUE;
|
2015-09-28 20:42:17 +00:00
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
private final boolean useUnderlineForHyperlink = true;
|
|
|
|
|
2010-11-15 20:35:36 +00:00
|
|
|
private final List<String> strings;
|
|
|
|
|
|
|
|
private final BufferedImage image;
|
|
|
|
|
|
|
|
private final GraphicPosition position;
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private final UAntiAliasing antiAliasing;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
private final ColorMapper colorMapper = new ColorMapperIdentity();
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
public static GraphicStrings createDefault(List<String> strings, boolean useRed) {
|
|
|
|
if (useRed) {
|
|
|
|
return new GraphicStrings(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColorUtils.BLACK,
|
|
|
|
HtmlColorUtils.RED_LIGHT, UAntiAliasing.ANTI_ALIASING_ON);
|
|
|
|
}
|
|
|
|
return new GraphicStrings(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColorSet.getInstance()
|
|
|
|
.getColorIfValid("#33FF02"), HtmlColorUtils.BLACK, UAntiAliasing.ANTI_ALIASING_ON);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
public GraphicStrings(List<String> strings, UFont font, HtmlColor green, HtmlColor background,
|
2013-12-10 19:36:50 +00:00
|
|
|
UAntiAliasing antiAliasing) {
|
2015-04-07 18:18:37 +00:00
|
|
|
this(strings, font, green, background, antiAliasing, null, null);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
public GraphicStrings(List<String> strings, UFont font, HtmlColor green, HtmlColor background,
|
|
|
|
UAntiAliasing antiAliasing, BufferedImage image, GraphicPosition position) {
|
2010-11-15 20:35:36 +00:00
|
|
|
this.strings = strings;
|
|
|
|
this.font = font;
|
|
|
|
this.green = green;
|
|
|
|
this.background = background;
|
|
|
|
this.image = image;
|
|
|
|
this.position = position;
|
2013-12-10 19:36:50 +00:00
|
|
|
this.antiAliasing = antiAliasing;
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private double minWidth;
|
|
|
|
|
|
|
|
public void setMinWidth(double minWidth) {
|
|
|
|
this.minWidth = minWidth;
|
|
|
|
}
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
private int maxLine = 0;
|
|
|
|
|
|
|
|
private TextBlock getTextBlock() {
|
|
|
|
TextBlock result = null;
|
|
|
|
if (maxLine == 0) {
|
2015-09-28 20:42:17 +00:00
|
|
|
result = Display.create(strings).create(
|
|
|
|
new FontConfiguration(font, green, hyperlinkColor, useUnderlineForHyperlink),
|
|
|
|
HorizontalAlignment.LEFT, new SpriteContainerEmpty());
|
2015-04-07 18:18:37 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < strings.size(); i += maxLine) {
|
|
|
|
final int n = Math.min(i + maxLine, strings.size());
|
2015-09-28 20:42:17 +00:00
|
|
|
final TextBlock textBlock1 = Display.create(strings.subList(i, n)).create(
|
|
|
|
new FontConfiguration(font, green, hyperlinkColor, useUnderlineForHyperlink),
|
|
|
|
HorizontalAlignment.LEFT, new SpriteContainerEmpty());
|
2015-04-07 18:18:37 +00:00
|
|
|
if (result == null) {
|
|
|
|
result = textBlock1;
|
|
|
|
} else {
|
|
|
|
result = TextBlockUtils.withMargin(result, 0, 10, 0, 0);
|
|
|
|
result = TextBlockUtils.mergeLR(result, textBlock1, VerticalAlignment.TOP);
|
|
|
|
}
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
result = DateEventUtils.addEvent(result, green);
|
|
|
|
return result;
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
public void drawU(UGraphic ug) {
|
|
|
|
final Dimension2D size = calculateDimension(ug.getStringBounder());
|
|
|
|
getTextBlock().drawU(ug.apply(new UChangeColor(green)));
|
2010-11-15 20:35:36 +00:00
|
|
|
|
|
|
|
if (image != null) {
|
|
|
|
if (position == GraphicPosition.BOTTOM) {
|
2015-04-07 18:18:37 +00:00
|
|
|
ug.apply(new UTranslate((size.getWidth() - image.getWidth()) / 2, size.getHeight() - image.getHeight()))
|
|
|
|
.draw(new UImage(image));
|
|
|
|
} else if (position == GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT) {
|
2013-12-10 19:36:50 +00:00
|
|
|
ug.apply(new UTranslate(size.getWidth() - image.getWidth(), size.getHeight() - image.getHeight()))
|
|
|
|
.draw(new UImage(image));
|
2015-04-07 18:18:37 +00:00
|
|
|
} else if (position == GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT) {
|
|
|
|
ug.apply(new UTranslate(size.getWidth() - image.getWidth() - 1, 1)).draw(new UImage(image));
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
2015-04-07 18:18:37 +00:00
|
|
|
Dimension2D dim = getTextBlock().calculateDimension(stringBounder);
|
|
|
|
if (dim.getWidth() < minWidth) {
|
|
|
|
dim = new Dimension2DDouble(minWidth, dim.getHeight());
|
|
|
|
}
|
|
|
|
if (image != null) {
|
|
|
|
if (position == GraphicPosition.BOTTOM) {
|
|
|
|
dim = new Dimension2DDouble(dim.getWidth(), dim.getHeight() + image.getHeight());
|
|
|
|
} else if (position == GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT) {
|
|
|
|
dim = new Dimension2DDouble(dim.getWidth() + image.getWidth(), dim.getHeight());
|
|
|
|
} else if (position == GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT) {
|
|
|
|
dim = new Dimension2DDouble(dim.getWidth() + image.getWidth(), dim.getHeight());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dim;
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public ShapeType getShapeType() {
|
|
|
|
return ShapeType.RECTANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HtmlColor getBackcolor() {
|
|
|
|
return background;
|
|
|
|
}
|
|
|
|
|
2011-09-07 20:41:58 +00:00
|
|
|
public int getShield() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public boolean isHidden() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
public final void setMaxLine(int maxLine) {
|
|
|
|
this.maxLine = maxLine;
|
|
|
|
}
|
|
|
|
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|