net.sourceforge.plantuml.klimt.creole.legacy.StripeTree Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.klimt.creole.legacy;
import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.klimt.creole.CreoleContext;
import net.sourceforge.plantuml.klimt.creole.CreoleMode;
import net.sourceforge.plantuml.klimt.creole.Stripe;
import net.sourceforge.plantuml.klimt.creole.StripeStyle;
import net.sourceforge.plantuml.klimt.creole.StripeStyleType;
import net.sourceforge.plantuml.klimt.creole.atom.Atom;
import net.sourceforge.plantuml.klimt.creole.atom.AtomTree;
import net.sourceforge.plantuml.klimt.creole.atom.AtomWithMargin;
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.style.ISkinSimple;
public class StripeTree implements Stripe {
// ::remove folder when __HAXE__
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 getAtoms() {
return Collections.singletonList(marged);
}
public Atom getLHeader() {
return null;
}
public void analyzeAndAdd(String line) {
final List lines = StripeTable.getWithNewlinesInternal(line);
for (String s : lines) {
final StripeSimple cell = new StripeSimple(fontConfiguration, stripeStyle, new CreoleContext(), skinParam,
CreoleMode.FULL);
final String text = s.replaceFirst("^\\s*\\|_", "");
final int level = computeLevel(s);
cell.analyzeAndAdd(text);
this.tree.addCell(StripeTable.asAtom(Collections.singletonList(cell), 0), level);
}
}
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;
}
}