summaryrefslogtreecommitdiff
path: root/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java')
-rw-r--r--src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java187
1 files changed, 187 insertions, 0 deletions
diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java
new file mode 100644
index 0000000..1941f05
--- /dev/null
+++ b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java
@@ -0,0 +1,187 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.cucadiagram;
+
+import java.awt.geom.Dimension2D;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import net.sourceforge.plantuml.FontParam;
+import net.sourceforge.plantuml.ISkinParam;
+import net.sourceforge.plantuml.ISkinSimple;
+import net.sourceforge.plantuml.Url;
+import net.sourceforge.plantuml.graphic.FontConfiguration;
+import net.sourceforge.plantuml.graphic.HorizontalAlignment;
+import net.sourceforge.plantuml.graphic.StringBounder;
+import net.sourceforge.plantuml.graphic.TextBlock;
+import net.sourceforge.plantuml.graphic.TextBlockLineBefore;
+import net.sourceforge.plantuml.graphic.TextBlockUtils;
+import net.sourceforge.plantuml.graphic.TextBlockVertical2;
+import net.sourceforge.plantuml.skin.rose.Rose;
+import net.sourceforge.plantuml.ugraphic.UGraphic;
+import net.sourceforge.plantuml.StringUtils;
+
+public class BodyEnhanced implements TextBlock {
+
+ private TextBlock area2;
+ private final FontConfiguration titleConfig;
+ private final List<String> rawBody;
+ private final FontParam fontParam;
+ private final ISkinParam skinParam;
+ private final boolean lineFirst;
+ private final HorizontalAlignment align;
+ private final boolean manageHorizontalLine;
+ private final boolean manageModifier;
+ private final List<Url> urls = new ArrayList<Url>();
+
+ public BodyEnhanced(List<String> rawBody, FontParam fontParam, ISkinParam skinParam, boolean manageModifier) {
+ this.rawBody = new ArrayList<String>(rawBody);
+ this.fontParam = fontParam;
+ this.skinParam = skinParam;
+
+ this.titleConfig = new FontConfiguration(skinParam.getFont(fontParam, null, false), new Rose().getFontColor(skinParam,
+ fontParam), skinParam.getHyperlinkColor(), skinParam.useUnderlineForHyperlink());
+ this.lineFirst = true;
+ this.align = HorizontalAlignment.LEFT;
+ this.manageHorizontalLine = true;
+ this.manageModifier = manageModifier;
+ }
+
+ public BodyEnhanced(Display display, FontParam fontParam, ISkinParam skinParam, HorizontalAlignment align,
+ Stereotype stereotype, boolean manageHorizontalLine, boolean manageModifier) {
+ this.rawBody = new ArrayList<String>();
+ for (CharSequence s : display) {
+ this.rawBody.add(s.toString());
+ }
+ this.fontParam = fontParam;
+ this.skinParam = skinParam;
+
+ this.titleConfig = new FontConfiguration(skinParam, fontParam, stereotype);
+ this.lineFirst = false;
+ this.align = align;
+ this.manageHorizontalLine = manageHorizontalLine;
+ this.manageModifier = manageModifier;
+
+ }
+
+ private TextBlock decorate(StringBounder stringBounder, TextBlock b, char separator, TextBlock title) {
+ if (separator == 0) {
+ return b;
+ }
+ if (title == null) {
+ return new TextBlockLineBefore(TextBlockUtils.withMargin(b, 6, 4), separator);
+ }
+ final Dimension2D dimTitle = title.calculateDimension(stringBounder);
+ final TextBlock raw = new TextBlockLineBefore(TextBlockUtils.withMargin(b, 6, 6, dimTitle.getHeight() / 2, 4),
+ separator, title);
+ return TextBlockUtils.withMargin(raw, 0, 0, dimTitle.getHeight() / 2, 0);
+ }
+
+ public Dimension2D calculateDimension(StringBounder stringBounder) {
+ return getArea(stringBounder).calculateDimension(stringBounder);
+ }
+
+ private TextBlock getArea(StringBounder stringBounder) {
+ if (area2 != null) {
+ return area2;
+ }
+ urls.clear();
+ final List<TextBlock> blocks = new ArrayList<TextBlock>();
+
+ char separator = lineFirst ? '_' : 0;
+ TextBlock title = null;
+ List<Member> members = new ArrayList<Member>();
+ for (String s : rawBody) {
+ if (manageHorizontalLine && isBlockSeparator(s)) {
+ blocks.add(decorate(stringBounder, new MethodsOrFieldsArea(members, fontParam, skinParam, align),
+ separator, title));
+ separator = s.charAt(0);
+ title = getTitle(s, skinParam);
+ members = new ArrayList<Member>();
+ } else {
+ final Member m = new Member(s, StringUtils.isMethod(s), manageModifier);
+ members.add(m);
+ if (m.getUrl() != null) {
+ urls.add(m.getUrl());
+ }
+ }
+ }
+ blocks.add(decorate(stringBounder, new MethodsOrFieldsArea(members, fontParam, skinParam, align), separator,
+ title));
+
+ if (blocks.size() == 1) {
+ this.area2 = blocks.get(0);
+ } else {
+ this.area2 = new TextBlockVertical2(blocks, align);
+ }
+
+ return area2;
+ }
+
+ public static boolean isBlockSeparator(String s) {
+ if (s.startsWith("--") && s.endsWith("--")) {
+ return true;
+ }
+ if (s.startsWith("==") && s.endsWith("==")) {
+ return true;
+ }
+ if (s.startsWith("..") && s.endsWith("..") && s.equals("...") == false) {
+ return true;
+ }
+ if (s.startsWith("__") && s.endsWith("__")) {
+ return true;
+ }
+ return false;
+ }
+
+ private TextBlock getTitle(String s, ISkinSimple spriteContainer) {
+ if (s.length() <= 4) {
+ return null;
+ }
+ s = s.substring(2, s.length() - 2).trim();
+ return TextBlockUtils
+ .create(Display.getWithNewlines(s), titleConfig, HorizontalAlignment.LEFT, spriteContainer);
+ }
+
+ public void drawU(UGraphic ug) {
+ getArea(ug.getStringBounder()).drawU(ug);
+ }
+
+ public List<Url> getUrls() {
+ return Collections.unmodifiableList(urls);
+ }
+
+}