2010-11-15 20:35:36 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
|
|
|
* (C) Copyright 2009, Arnaud Roques
|
|
|
|
*
|
|
|
|
* 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 Lesser 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
|
|
|
|
*
|
2011-09-07 20:41:58 +00:00
|
|
|
* Revision $Revision: 7157 $
|
2010-11-15 20:35:36 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.graphic;
|
|
|
|
|
2011-09-07 20:41:58 +00:00
|
|
|
import java.awt.Graphics2D;
|
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.awt.geom.Point2D;
|
2010-11-15 20:35:36 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Stereotype;
|
2011-09-07 20:41:58 +00:00
|
|
|
import net.sourceforge.plantuml.posimo.Positionable;
|
|
|
|
import net.sourceforge.plantuml.posimo.PositionableImpl;
|
2010-11-15 20:35:36 +00:00
|
|
|
import net.sourceforge.plantuml.sequencediagram.MessageNumber;
|
2011-09-07 20:41:58 +00:00
|
|
|
import net.sourceforge.plantuml.svek.IEntityImage;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.ColorMapper;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
|
|
|
public class TextBlockUtils {
|
|
|
|
|
2011-01-23 19:36:52 +00:00
|
|
|
public static TextBlock create(List<? extends CharSequence> texts, FontConfiguration fontConfiguration,
|
2010-11-15 20:35:36 +00:00
|
|
|
HorizontalAlignement horizontalAlignement) {
|
|
|
|
if (texts.size() > 0 && texts.get(0) instanceof Stereotype) {
|
2011-01-23 19:36:52 +00:00
|
|
|
return createStereotype(texts, fontConfiguration, horizontalAlignement);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
if (texts.size() > 0 && texts.get(0) instanceof MessageNumber) {
|
2011-01-23 19:36:52 +00:00
|
|
|
return createMessageNumber(texts, fontConfiguration, horizontalAlignement);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
2011-01-23 19:36:52 +00:00
|
|
|
return new TextBlockSimple(texts, fontConfiguration, horizontalAlignement);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 19:36:52 +00:00
|
|
|
private static TextBlock createMessageNumber(List<? extends CharSequence> texts,
|
|
|
|
FontConfiguration fontConfiguration, HorizontalAlignement horizontalAlignement) {
|
2010-11-15 20:35:36 +00:00
|
|
|
final MessageNumber number = (MessageNumber) texts.get(0);
|
2011-01-23 19:36:52 +00:00
|
|
|
return new TextBlockWithNumber(number.getNumber(), texts.subList(1, texts.size()), fontConfiguration,
|
2010-11-15 20:35:36 +00:00
|
|
|
horizontalAlignement);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:36:52 +00:00
|
|
|
private static TextBlock createStereotype(List<? extends CharSequence> texts, FontConfiguration fontConfiguration,
|
2010-11-15 20:35:36 +00:00
|
|
|
HorizontalAlignement horizontalAlignement) {
|
|
|
|
final Stereotype stereotype = (Stereotype) texts.get(0);
|
|
|
|
if (stereotype.isSpotted()) {
|
2011-09-07 20:41:58 +00:00
|
|
|
final CircledCharacter circledCharacter = new CircledCharacter(stereotype.getCharacter(), stereotype
|
|
|
|
.getRadius(), stereotype.getCircledFont(), stereotype.getHtmlColor(), null, fontConfiguration
|
|
|
|
.getColor());
|
2010-11-15 20:35:36 +00:00
|
|
|
if (stereotype.getLabel() == null) {
|
2011-01-23 19:36:52 +00:00
|
|
|
return new TextBlockSpotted(circledCharacter, texts.subList(1, texts.size()), fontConfiguration,
|
2010-11-15 20:35:36 +00:00
|
|
|
horizontalAlignement);
|
|
|
|
}
|
2011-01-23 19:36:52 +00:00
|
|
|
return new TextBlockSpotted(circledCharacter, texts, fontConfiguration, horizontalAlignement);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
2011-01-23 19:36:52 +00:00
|
|
|
return new TextBlockSimple(texts, fontConfiguration, horizontalAlignement);
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2011-09-07 20:41:58 +00:00
|
|
|
public static TextBlock withMargin(TextBlock textBlock, double marginX, double marginY) {
|
|
|
|
return new TextBlockMarged(textBlock, marginX, marginX, marginY, marginY);
|
|
|
|
}
|
|
|
|
|
2010-11-15 20:35:36 +00:00
|
|
|
// static private Font deriveForCircleCharacter(Font font) {
|
|
|
|
// final float size = font.getSize2D();
|
|
|
|
// return font.deriveFont(size - 1).deriveFont(Font.BOLD);
|
|
|
|
// }
|
|
|
|
|
2011-09-07 20:41:58 +00:00
|
|
|
public static Positionable asPositionable(TextBlock textBlock, StringBounder stringBounder, Point2D pt) {
|
|
|
|
return new PositionableImpl(pt, textBlock.calculateDimension(stringBounder));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TextBlock fromIEntityImage(final IEntityImage image) {
|
|
|
|
return new TextBlock() {
|
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
return image.getDimension(stringBounder);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void drawU(UGraphic ug, double x, double y) {
|
|
|
|
image.drawU(ug, x, y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TextBlock mergeLR(TextBlock b1, TextBlock b2) {
|
|
|
|
return new TextBlockHorizontal(b1, b2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TextBlock mergeTB(TextBlock b1, TextBlock b2) {
|
|
|
|
return new TextBlockVertical(b1, b2);
|
|
|
|
}
|
|
|
|
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|