plantuml/src/net/sourceforge/plantuml/ebnf/PSystemEbnf.java

121 lines
4.4 KiB
Java
Raw Normal View History

2022-09-23 16:53:33 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2022-09-23 16:53:33 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2022-09-23 16:53:33 +00:00
*
* If you like this project or if you find it useful, you can support us at:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2022-09-23 16:53:33 +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.ebnf;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.TitledDiagram;
2022-10-18 20:57:44 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FloatingNote;
import net.sourceforge.plantuml.command.CommandExecutionResult;
2022-09-23 16:53:33 +00:00
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.core.UmlSource;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.color.Colors;
import net.sourceforge.plantuml.klimt.creole.Display;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.klimt.shape.TextBlockUtils;
import net.sourceforge.plantuml.skin.UmlDiagramType;
import net.sourceforge.plantuml.style.ISkinParam;
2022-10-18 20:57:44 +00:00
import net.sourceforge.plantuml.style.SName;
2022-10-05 20:32:57 +00:00
import net.sourceforge.plantuml.style.Style;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.BlocLines;
import net.sourceforge.plantuml.utils.CharInspector;
2022-09-23 16:53:33 +00:00
public class PSystemEbnf extends TitledDiagram {
2022-10-18 20:57:44 +00:00
private final List<TextBlockable> expressions = new ArrayList<>();
2022-09-23 16:53:33 +00:00
public PSystemEbnf(UmlSource source) {
super(source, UmlDiagramType.EBNF, null);
}
public DiagramDescription getDescription() {
return new DiagramDescription("(EBNF)");
}
2022-10-18 20:57:44 +00:00
public CommandExecutionResult addBlocLines(BlocLines blines, String commentAbove, String commentBelow) {
final boolean isCompact = getPragma().isDefine("compact");
2022-12-17 11:01:10 +00:00
final CharInspector it = blines.inspector();
2022-10-18 20:57:44 +00:00
final EbnfExpression tmp1 = EbnfExpression.create(it, isCompact, commentAbove, commentBelow);
if (tmp1.isEmpty())
return CommandExecutionResult.error("Unparsable expression");
expressions.add(tmp1);
return CommandExecutionResult.ok();
}
public CommandExecutionResult addNote(final Display note, Colors colors) {
expressions.add(new TextBlockable() {
@Override
public TextBlock getUDrawable(ISkinParam skinParam) {
final FloatingNote f = FloatingNote.create(note, skinParam, SName.ebnf);
return TextBlockUtils.withMargin(f, 0, 0, 5, 15);
}
});
return CommandExecutionResult.ok();
2022-09-23 16:53:33 +00:00
}
@Override
protected ImageData exportDiagramNow(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException {
return createImageBuilder(fileFormatOption).drawable(getTextBlock()).write(os);
}
2023-02-22 18:43:48 +00:00
@Override
2023-02-26 18:51:17 +00:00
protected TextBlock getTextBlock() {
2022-10-18 20:57:44 +00:00
if (expressions.size() == 0) {
2022-10-05 20:32:57 +00:00
final Style style = ETile.getStyleSignature().getMergedStyle(getSkinParam().getCurrentStyleBuilder());
final FontConfiguration fc = style.getFontConfiguration(getSkinParam().getIHtmlColorSet());
final TextBlock tmp = EbnfEngine.syntaxError(fc, getSkinParam());
return TextBlockUtils.addBackcolor(tmp, null);
}
2022-10-18 20:57:44 +00:00
TextBlock result = expressions.get(0).getUDrawable(getSkinParam());
for (int i = 1; i < expressions.size(); i++)
result = TextBlockUtils.mergeTB(result, expressions.get(i).getUDrawable(getSkinParam()),
HorizontalAlignment.LEFT);
2022-09-27 16:12:38 +00:00
return TextBlockUtils.addBackcolor(result, null);
2022-09-23 16:53:33 +00:00
}
2022-10-18 20:57:44 +00:00
2022-09-23 16:53:33 +00:00
}