1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 15:40:48 +00:00
plantuml/src/net/sourceforge/plantuml/creole/StripeTree.java

99 lines
2.9 KiB
Java
Raw Normal View History

2015-05-31 18:56:03 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2015-05-31 18:56:03 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2015-05-31 18:56:03 +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
*
2015-05-31 18:56:03 +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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 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.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.creole;
import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.graphic.FontConfiguration;
public class StripeTree implements Stripe {
private FontConfiguration fontConfiguration;
final private ISkinSimple skinParam;
final private AtomTree tree;
final private Atom marged;
final private StripeStyle stripeStyle = new StripeStyle(StripeStyleType.TREE, 0, '\0');
public StripeTree(FontConfiguration fontConfiguration, ISkinSimple skinParam, String line) {
this.fontConfiguration = fontConfiguration;
this.skinParam = skinParam;
this.tree = new AtomTree(fontConfiguration.getColor());
this.marged = new AtomWithMargin(tree, 2, 2);
analyzeAndAdd(line);
}
public List<Atom> getAtoms() {
return Collections.<Atom> singletonList(marged);
}
2019-09-22 17:20:16 +00:00
2019-01-16 18:34:41 +00:00
public Atom getHeader() {
return null;
}
2015-05-31 18:56:03 +00:00
public void analyzeAndAdd(String line) {
final List<String> lines = StripeTable.getWithNewlinesInternal(line);
for (String s : lines) {
final StripeSimple cell = new StripeSimple(fontConfiguration, stripeStyle, new CreoleContext(), skinParam,
2015-07-11 09:32:49 +00:00
CreoleMode.FULL);
2015-05-31 18:56:03 +00:00
final String text = s.replaceFirst("^\\s*\\|_", "");
2019-09-22 17:20:16 +00:00
final int level = computeLevel(s);
2015-05-31 18:56:03 +00:00
cell.analyzeAndAdd(text);
this.tree.addCell(StripeTable.asAtom(Collections.singletonList(cell), 0), level);
}
}
2019-09-22 17:20:16 +00:00
private int computeLevel(String s) {
int result = 1;
while (s.length() > 0) {
if (s.startsWith(" ")) {
result++;
s = s.substring(2);
continue;
} else if (s.startsWith("\t")) {
result++;
s = s.substring(1);
continue;
}
return result;
}
return result;
}
2015-05-31 18:56:03 +00:00
}