1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-03 09:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java

84 lines
3.3 KiB
Java
Raw Normal View History

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-08-08 17:48:29 +00:00
* Revision $Revision: 6570 $
2010-11-15 20:35:36 +00:00
*
*/
package net.sourceforge.plantuml.graphic;
import java.util.List;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.sequencediagram.MessageNumber;
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-01-23 19:36:52 +00:00
final CircledCharacter circledCharacter = new CircledCharacter(stereotype.getCharacter(),
2011-08-08 17:48:29 +00:00
stereotype.getRadius(), stereotype.getCircledFont(), stereotype.getHtmlColor(), null,
2011-01-23 19:36:52 +00:00
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
}
// static private Font deriveForCircleCharacter(Font font) {
// final float size = font.getSize2D();
// return font.deriveFont(size - 1).deriveFont(Font.BOLD);
// }
}