1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 15:40:48 +00:00
This commit is contained in:
Arnaud Roques 2022-08-30 21:15:53 +02:00
parent 401f44bf3c
commit 0dd8e23270
22 changed files with 321 additions and 102 deletions

View File

@ -38,6 +38,7 @@ package net.sourceforge.plantuml.asciiart;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.color.Colors;
import net.sourceforge.plantuml.sequencediagram.NotePosition;
import net.sourceforge.plantuml.skin.ArrowComponent;
import net.sourceforge.plantuml.skin.ArrowConfiguration;
@ -61,104 +62,103 @@ public class TextSkin extends Rose {
Display stringsToDisplay) {
if (config.getArrowDirection() == ArrowDirection.LEFT_TO_RIGHT_NORMAL
|| config.getArrowDirection() == ArrowDirection.RIGHT_TO_LEFT_REVERSE
|| config.getArrowDirection() == ArrowDirection.BOTH_DIRECTION) {
|| config.getArrowDirection() == ArrowDirection.BOTH_DIRECTION)
return new ComponentTextArrow(ComponentType.ARROW, config, stringsToDisplay, fileFormat,
param.maxAsciiMessageLength());
}
if (config.isSelfArrow()) {
if (config.isSelfArrow())
return new ComponentTextSelfArrow(ComponentType.ARROW, config, stringsToDisplay, fileFormat);
}
throw new UnsupportedOperationException();
}
@Override
public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param, Display stringsToDisplay,
NotePosition notePosition) {
if (type == ComponentType.NOTE || type == ComponentType.NOTE_BOX) {
Colors colors, NotePosition notePosition) {
if (type == ComponentType.NOTE || type == ComponentType.NOTE_BOX)
return new ComponentTextNote(type, stringsToDisplay, fileFormat);
}
throw new UnsupportedOperationException(type.toString());
}
@Override
public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param,
Display stringsToDisplay) {
return createComponentNote(styles, type, param, stringsToDisplay, null);
public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param, Display stringsToDisplay,
Colors colors) {
return createComponentNote(styles, type, param, stringsToDisplay, colors, null);
}
@Override
public Component createComponent(Style style[], ComponentType type, ArrowConfiguration config, ISkinParam param,
Display stringsToDisplay) {
if (type == ComponentType.ACTOR_HEAD || type == ComponentType.ACTOR_TAIL) {
if (type == ComponentType.ACTOR_HEAD || type == ComponentType.ACTOR_TAIL)
return new ComponentTextActor(type, stringsToDisplay, fileFormat,
fileFormat == FileFormat.UTXT ? AsciiShape.STICKMAN_UNICODE : AsciiShape.STICKMAN);
}
if (type == ComponentType.BOUNDARY_HEAD || type == ComponentType.BOUNDARY_TAIL) {
if (type == ComponentType.BOUNDARY_HEAD || type == ComponentType.BOUNDARY_TAIL)
return new ComponentTextShape(type, stringsToDisplay, AsciiShape.BOUNDARY);
}
if (type == ComponentType.DATABASE_HEAD || type == ComponentType.DATABASE_TAIL) {
if (type == ComponentType.DATABASE_HEAD || type == ComponentType.DATABASE_TAIL)
return new ComponentTextShape(type, stringsToDisplay, AsciiShape.DATABASE);
}
if (type.name().endsWith("_HEAD") || type.name().endsWith("_TAIL")) {
if (type.name().endsWith("_HEAD") || type.name().endsWith("_TAIL"))
return new ComponentTextParticipant(type, stringsToDisplay, fileFormat);
}
if (type.isArrow() && (config.getArrowDirection() == ArrowDirection.LEFT_TO_RIGHT_NORMAL
|| config.getArrowDirection() == ArrowDirection.RIGHT_TO_LEFT_REVERSE
|| config.getArrowDirection() == ArrowDirection.BOTH_DIRECTION)) {
|| config.getArrowDirection() == ArrowDirection.BOTH_DIRECTION))
return new ComponentTextArrow(type, config, stringsToDisplay, fileFormat, param.maxAsciiMessageLength());
}
if (type.isArrow() && config.isSelfArrow()) {
if (type.isArrow() && config.isSelfArrow())
return new ComponentTextSelfArrow(type, config, stringsToDisplay, fileFormat);
}
if (type == ComponentType.PARTICIPANT_LINE) {
if (type == ComponentType.PARTICIPANT_LINE)
return new ComponentTextLine(type, fileFormat);
}
if (type == ComponentType.CONTINUE_LINE) {
if (type == ComponentType.CONTINUE_LINE)
return new ComponentTextLine(type, fileFormat);
}
if (type == ComponentType.DELAY_LINE) {
if (type == ComponentType.DELAY_LINE)
return new ComponentTextLine(type, fileFormat);
}
if (type == ComponentType.ALIVE_BOX_CLOSE_CLOSE) {
if (type == ComponentType.ALIVE_BOX_CLOSE_CLOSE)
return new ComponentTextActiveLine(fileFormat);
}
if (type == ComponentType.ALIVE_BOX_CLOSE_OPEN) {
if (type == ComponentType.ALIVE_BOX_CLOSE_OPEN)
return new ComponentTextActiveLine(fileFormat);
}
if (type == ComponentType.ALIVE_BOX_OPEN_CLOSE) {
if (type == ComponentType.ALIVE_BOX_OPEN_CLOSE)
return new ComponentTextActiveLine(fileFormat);
}
if (type == ComponentType.ALIVE_BOX_OPEN_OPEN) {
if (type == ComponentType.ALIVE_BOX_OPEN_OPEN)
return new ComponentTextActiveLine(fileFormat);
}
if (type == ComponentType.DIVIDER) {
if (type == ComponentType.DIVIDER)
return new ComponentTextDivider(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.GROUPING_HEADER) {
if (type == ComponentType.GROUPING_HEADER)
return new ComponentTextGroupingHeader(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.GROUPING_SPACE) {
if (type == ComponentType.GROUPING_SPACE)
return new ComponentRoseGroupingSpace(1);
}
if (type == ComponentType.GROUPING_ELSE) {
if (type == ComponentType.GROUPING_ELSE)
return new ComponentTextGroupingElse(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.DELAY_TEXT) {
if (type == ComponentType.DELAY_TEXT)
return new ComponentTextDelay(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.DESTROY) {
if (type == ComponentType.DESTROY)
return new ComponentTextDestroy();
}
if (type == ComponentType.REFERENCE) {
if (type == ComponentType.REFERENCE)
return new ComponentTextReference(stringsToDisplay, fileFormat);
}
throw new UnsupportedOperationException(type.toString());
}
@Override
public Component createComponentNewPage(ISkinParam param) {
return new ComponentTextNewpage(fileFormat);
}
}

View File

@ -69,7 +69,6 @@ public class PSystemWelcome extends PlainDiagram {
strings.add(" ");
strings.add("You will find more information about PlantUML syntax on <u>https://plantuml.com</u>");
strings.add(" ");
strings.add("(If you use this software, you accept its license)");
strings.add("(Details by typing \"\"license\"\" keyword)");
strings.add(" ");
if (position == GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT) {

View File

@ -39,7 +39,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import net.sourceforge.plantuml.AlignmentParam;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.OptionFlags;
@ -47,7 +46,6 @@ import net.sourceforge.plantuml.PaddingParam;
import net.sourceforge.plantuml.SkinParamBackcolored;
import net.sourceforge.plantuml.SkinParamBackcoloredReference;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.sequencediagram.AbstractMessage;
import net.sourceforge.plantuml.sequencediagram.Delay;
@ -65,7 +63,6 @@ import net.sourceforge.plantuml.sequencediagram.Message;
import net.sourceforge.plantuml.sequencediagram.MessageExo;
import net.sourceforge.plantuml.sequencediagram.Newpage;
import net.sourceforge.plantuml.sequencediagram.Note;
import net.sourceforge.plantuml.sequencediagram.NotePosition;
import net.sourceforge.plantuml.sequencediagram.Notes;
import net.sourceforge.plantuml.sequencediagram.Participant;
import net.sourceforge.plantuml.sequencediagram.ParticipantEnglober;
@ -409,7 +406,8 @@ class DrawableSetInitializer {
for (Note noteOnMessage : m.getNoteOnMessages()) {
final ISkinParam sk = noteOnMessage.getSkinParamBackcolored(drawableSet.getSkinParam());
final Component note = drawableSet.getSkin().createComponentNote(noteOnMessage.getUsedStyles(),
noteOnMessage.getNoteStyle().getNoteComponentType(), sk, noteOnMessage.getStrings());
noteOnMessage.getNoteStyle().getNoteComponentType(), sk, noteOnMessage.getStrings(),
noteOnMessage.getColors());
notes.add(note);
}
if (m.isParallel())
@ -467,7 +465,7 @@ class DrawableSetInitializer {
}
final Component component = drawableSet.getSkin().createComponentNote(n.getUsedStyles(), type, skinParam,
n.getStrings(), n.getPosition());
n.getStrings(), n.getColors(), n.getPosition());
final NoteBox noteBox = new NoteBox(freeY2.getFreeY(range), component, p1, p2, n.getPosition(), n.getUrl());
return noteBox;
}

View File

@ -85,8 +85,10 @@ class Step1Message extends Step1Abstract {
final List<Note> noteOnMessages = message.getNoteOnMessages();
for (Note noteOnMessage : noteOnMessages) {
final ISkinParam skinParam = noteOnMessage.getSkinParamBackcolored(drawingSet.getSkinParam());
addNote(drawingSet.getSkin().createComponentNote(noteOnMessage.getUsedStyles(),
noteOnMessage.getNoteStyle().getNoteComponentType(), skinParam, noteOnMessage.getStrings()));
final Component note = drawingSet.getSkin().createComponentNote(noteOnMessage.getUsedStyles(),
noteOnMessage.getNoteStyle().getNoteComponentType(), skinParam, noteOnMessage.getStrings(),
noteOnMessage.getColors());
addNote(note);
}
}

View File

@ -68,8 +68,9 @@ class Step1MessageExo extends Step1Abstract {
final List<Note> noteOnMessages = message.getNoteOnMessages();
for (Note noteOnMessage : noteOnMessages) {
final ISkinParam skinParam = noteOnMessage.getSkinParamBackcolored(drawingSet.getSkinParam());
addNote(drawingSet.getSkin().createComponentNote(noteOnMessage.getUsedStyles(), ComponentType.NOTE, skinParam,
noteOnMessage.getStrings()));
final Component note = drawingSet.getSkin().createComponentNote(noteOnMessage.getUsedStyles(),
ComponentType.NOTE, skinParam, noteOnMessage.getStrings(), noteOnMessage.getColors());
addNote(note);
}
}
@ -132,11 +133,11 @@ class Step1MessageExo extends Step1Abstract {
final MessageExoType type = m.getType();
ArrowConfiguration result = null;
if (type.getDirection() == 1)
if (type.getDirection() == 1)
result = m.getArrowConfiguration();
else
else
result = m.getArrowConfiguration().reverse();
// result = result.withDecoration1(m.getArrowConfiguration().getDecoration1());
// result = result.withDecoration2(m.getArrowConfiguration().getDecoration2());
return result;

View File

@ -92,7 +92,7 @@ public abstract class CommunicationTileNoteBottomTopAbstract extends AbstractTil
final protected Component getComponent(StringBounder stringBounder) {
final Component comp = skin.createComponentNote(noteOnMessage.getUsedStyles(), ComponentType.NOTE,
noteOnMessage.getSkinParamBackcolored(skinParam), noteOnMessage.getStrings());
noteOnMessage.getSkinParamBackcolored(skinParam), noteOnMessage.getStrings(), noteOnMessage.getColors());
return comp;
}

View File

@ -35,9 +35,8 @@
*/
package net.sourceforge.plantuml.sequencediagram.teoz;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.UDrawable;
import net.sourceforge.plantuml.real.Real;
@ -87,8 +86,8 @@ public class CommunicationTileNoteLeft extends AbstractTile {
}
private Component getComponent(StringBounder stringBounder) {
final Component comp = skin.createComponentNote(noteOnMessage.getUsedStyles(), ComponentType.NOTE, noteOnMessage.getSkinParamBackcolored(skinParam),
noteOnMessage.getStrings());
final Component comp = skin.createComponentNote(noteOnMessage.getUsedStyles(), ComponentType.NOTE,
noteOnMessage.getSkinParamBackcolored(skinParam), noteOnMessage.getStrings(), noteOnMessage.getColors());
return comp;
}

View File

@ -91,8 +91,9 @@ public class CommunicationTileNoteRight extends AbstractTile {
}
private Component getComponent(StringBounder stringBounder) {
final Component comp = skin.createComponentNote(noteOnMessage.getUsedStyles(), ComponentType.NOTE, noteOnMessage.getSkinParamBackcolored(skinParam),
noteOnMessage.getStrings());
final Component comp = skin.createComponentNote(noteOnMessage.getUsedStyles(), ComponentType.NOTE,
noteOnMessage.getSkinParamBackcolored(skinParam), noteOnMessage.getStrings(),
noteOnMessage.getColors());
return comp;
}

View File

@ -85,7 +85,8 @@ public class CommunicationTileSelfNoteRight extends AbstractTile {
private Component getComponent(StringBounder stringBounder) {
final Component comp = skin.createComponentNote(noteOnMessage.getUsedStyles(), ComponentType.NOTE,
noteOnMessage.getSkinParamBackcolored(skinParam), noteOnMessage.getStrings());
noteOnMessage.getSkinParamBackcolored(skinParam), noteOnMessage.getStrings(),
noteOnMessage.getColors());
return comp;
}

View File

@ -82,7 +82,7 @@ public class NoteTile extends AbstractTile implements Tile {
private Component getComponent(StringBounder stringBounder) {
final Component comp = skin.createComponentNote(note.getUsedStyles(), getNoteComponentType(note.getNoteStyle()),
note.getSkinParamBackcolored(skinParam), note.getStrings(), note.getPosition());
note.getSkinParamBackcolored(skinParam), note.getStrings(), note.getColors(), note.getPosition());
return comp;
}

View File

@ -78,7 +78,7 @@ public class NotesTile extends AbstractTile implements Tile {
private Component getComponent(StringBounder stringBounder, Note note) {
final Component comp = skin.createComponentNote(note.getUsedStyles(), getNoteComponentType(note.getNoteStyle()),
note.getSkinParamBackcolored(skinParam), note.getStrings(), note.getPosition());
note.getSkinParamBackcolored(skinParam), note.getStrings(), note.getColors(), note.getPosition());
return comp;
}

View File

@ -41,6 +41,7 @@ import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.SymbolContext;
import net.sourceforge.plantuml.graphic.color.Colors;
import net.sourceforge.plantuml.skin.AbstractTextualComponent;
import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.style.PName;
@ -61,13 +62,14 @@ final public class ComponentRoseNote extends AbstractTextualComponent implements
private final HorizontalAlignment position;
public ComponentRoseNote(Style style, Display strings, double paddingX, double paddingY,
ISkinSimple spriteContainer, HorizontalAlignment textAlignment, HorizontalAlignment position) {
super(style, spriteContainer.wrapWidth(), textAlignment == HorizontalAlignment.CENTER ? 15 : 6, 15, 5, spriteContainer,
strings, true);
ISkinSimple spriteContainer, HorizontalAlignment textAlignment, HorizontalAlignment position,
Colors colors) {
super(style, spriteContainer.wrapWidth(), textAlignment == HorizontalAlignment.CENTER ? 15 : 6, 15, 5,
spriteContainer, strings, true);
this.paddingX = paddingX;
this.paddingY = paddingY;
this.position = position;
this.symbolContext = style.getSymbolContext(spriteContainer.getThemeStyle(), getIHtmlColorSet());
this.symbolContext = style.getSymbolContext(spriteContainer.getThemeStyle(), getIHtmlColorSet(), colors);
this.roundCorner = style.value(PName.RoundCorner).asInt();
}

View File

@ -39,6 +39,7 @@ import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.SymbolContext;
import net.sourceforge.plantuml.graphic.color.Colors;
import net.sourceforge.plantuml.skin.AbstractTextualComponent;
import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.style.PName;
@ -53,10 +54,10 @@ final public class ComponentRoseNoteBox extends AbstractTextualComponent {
private final SymbolContext symbolContext;
private final double roundCorner;
public ComponentRoseNoteBox(Style style, Display strings, ISkinSimple spriteContainer) {
public ComponentRoseNoteBox(Style style, Display strings, ISkinSimple spriteContainer, Colors colors) {
super(style, spriteContainer.wrapWidth(), 4, 4, 4, spriteContainer, strings, false);
this.symbolContext = style.getSymbolContext(spriteContainer.getThemeStyle(), getIHtmlColorSet());
this.symbolContext = style.getSymbolContext(spriteContainer.getThemeStyle(), getIHtmlColorSet(), colors);
this.roundCorner = style.value(PName.RoundCorner).asInt();
}

View File

@ -39,6 +39,7 @@ import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.SymbolContext;
import net.sourceforge.plantuml.graphic.color.Colors;
import net.sourceforge.plantuml.skin.AbstractTextualComponent;
import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.style.Style;
@ -52,10 +53,10 @@ final public class ComponentRoseNoteHexagonal extends AbstractTextualComponent {
private final int cornersize = 10;
private final SymbolContext symbolContext;
public ComponentRoseNoteHexagonal(Style style, Display strings, ISkinSimple spriteContainer) {
public ComponentRoseNoteHexagonal(Style style, Display strings, ISkinSimple spriteContainer, Colors colors) {
super(style, spriteContainer.wrapWidth(), 12, 12, 4, spriteContainer, strings, false);
this.symbolContext = style.getSymbolContext(spriteContainer.getThemeStyle(), getIHtmlColorSet());
this.symbolContext = style.getSymbolContext(spriteContainer.getThemeStyle(), getIHtmlColorSet(), colors);
}

View File

@ -43,6 +43,7 @@ import net.sourceforge.plantuml.PaddingParam;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.color.Colors;
import net.sourceforge.plantuml.sequencediagram.NotePosition;
import net.sourceforge.plantuml.skin.ArrowComponent;
import net.sourceforge.plantuml.skin.ArrowConfiguration;
@ -75,12 +76,6 @@ public class Rose {
return colorParams[0].getDefaultValue();
}
public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param,
Display stringsToDisplay) {
checkRose();
return createComponentNote(styles, type, param, stringsToDisplay, null);
}
private void checkRose() {
// Quite ugly, but we want to ensure that TextSkin overrides those methods
if (this.getClass() != Rose.class)
@ -89,7 +84,13 @@ public class Rose {
}
public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param, Display stringsToDisplay,
NotePosition notePosition) {
Colors colors) {
checkRose();
return createComponentNote(styles, type, param, stringsToDisplay, colors, null);
}
public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param, Display stringsToDisplay,
Colors colors, NotePosition notePosition) {
checkRose();
final HorizontalAlignment textAlign;
final HorizontalAlignment position;
@ -109,13 +110,13 @@ public class Rose {
if (type == ComponentType.NOTE)
return new ComponentRoseNote(styles == null ? null : styles[0], stringsToDisplay, paddingX, paddingY, param,
textAlign, position);
textAlign, position, colors);
if (type == ComponentType.NOTE_HEXAGONAL)
return new ComponentRoseNoteHexagonal(styles == null ? null : styles[0], stringsToDisplay, param);
return new ComponentRoseNoteHexagonal(styles == null ? null : styles[0], stringsToDisplay, param, colors);
if (type == ComponentType.NOTE_BOX)
return new ComponentRoseNoteBox(styles == null ? null : styles[0], stringsToDisplay, param);
return new ComponentRoseNoteBox(styles == null ? null : styles[0], stringsToDisplay, param, colors);
throw new UnsupportedOperationException(type.toString());
}

View File

@ -200,13 +200,21 @@ public class Style {
return FontConfiguration.create(font, color, hyperlinkColor, true);
}
public SymbolContext getSymbolContext(ThemeStyle themeStyle, HColorSet set) {
final HColor backColor = value(PName.BackGroundColor).asColor(themeStyle, set);
final HColor foreColor = value(PName.LineColor).asColor(themeStyle, set);
public SymbolContext getSymbolContext(ThemeStyle themeStyle, HColorSet set, Colors colors) {
HColor backColor = colors == null ? null : colors.getColor(ColorType.BACK);
if (backColor == null)
backColor = value(PName.BackGroundColor).asColor(themeStyle, set);
HColor foreColor = colors == null ? null : colors.getColor(ColorType.LINE);
if (foreColor == null)
foreColor = value(PName.LineColor).asColor(themeStyle, set);
final double deltaShadowing = value(PName.Shadowing).asDouble();
return new SymbolContext(backColor, foreColor).withStroke(getStroke()).withDeltaShadow(deltaShadowing);
}
public SymbolContext getSymbolContext(ThemeStyle themeStyle, HColorSet set) {
return getSymbolContext(themeStyle, set, null);
}
public Style eventuallyOverride(UStroke stroke) {
if (stroke == null)
return this;
@ -269,7 +277,7 @@ public class Style {
final FontConfiguration fc = getFontConfiguration(spriteContainer.getThemeStyle(), set);
return display.create(fc, alignment, spriteContainer);
}
public static final String ID_TITLE = "_title";
public static final String ID_CAPTION = "_caption";
public static final String ID_LEGEND = "_legend";

View File

@ -63,7 +63,7 @@ public class EntityImageNoteLink extends AbstractTextBlock implements IEntityIma
final Rose skin = new Rose();
comp = skin.createComponentNote(
new Style[] { ComponentType.NOTE.getStyleSignature().getMergedStyle(styleBuilder) }, ComponentType.NOTE,
colors.mute(skinParam), note);
skinParam, note, colors);
}
public Dimension2D calculateDimension(StringBounder stringBounder) {

View File

@ -81,7 +81,7 @@ public class Version {
}
public static int beta() {
final int beta = 3;
final int beta = 4;
return beta;
}

View File

@ -0,0 +1,44 @@
package nonreg.scxml;
import java.io.IOException;
import org.junit.jupiter.api.Test;
/*
Test diagram MUST be put between triple quotes
"""
@startuml
state s1
state s2
[*] --> s1
s1 --> s2 : play
@enduml
"""
Expected result MUST be put between triple brackets
{{{
<?xml version="1.0" encoding="UTF-8"?><scxml xmlns="http://www.w3.org/2005/07/scxml" initial="start" version="1.0">
<state id="s1">
<transition event="play" target="s2"/>
</state>
<state id="s2"/>
<state id="start">
<transition target="s1"/>
</state>
</scxml>
}}}
*/
public class SCXML0001_Test extends ScXmlTest {
@Test
void testSimple() throws IOException {
checkXmlAndDescription("(3 entities)");
}
}

View File

@ -0,0 +1,61 @@
package nonreg.scxml;
import java.io.IOException;
import org.junit.jupiter.api.Test;
/*
https://github.com/plantuml/plantuml/issues/1100
Test diagram MUST be put between triple quotes
"""
@startuml
state counter{
state count_start
state count_done
state "count_val[3:0]"
[*] -> count_idle
count_idle --> count_ongoing: count_start
state count_idle: count_val := 0
state count_ongoing: count_val := count_val +1
count_ongoing -> count_finish: count_val != MAX_VAL
state count_finish: count_done:=1
count_finish -> count_idle
}
@enduml
"""
Expected result MUST be put between triple brackets
{{{
<?xml version="1.0" encoding="UTF-8"?><scxml xmlns="http://www.w3.org/2005/07/scxml" initial="startcounter" version="1.0">
<state id="count_start"/>
<state id="count_done"/>
<state id="count_val[3:0]"/>
<state id="startcounter">
<transition target="count_idle"/>
</state>
<state id="count_idle">
<transition event="count_start" target="count_ongoing"/>
</state>
<state id="count_ongoing">
<transition event="count_val != MAX_VAL" target="count_finish"/>
</state>
<state id="count_finish">
<transition target="count_idle"/>
</state>
</scxml>
}}}
*/
public class SCXML0002_Test extends ScXmlTest {
@Test
void testSimple() throws IOException {
checkXmlAndDescription("(7 entities)");
}
}

View File

@ -0,0 +1,100 @@
package nonreg.scxml;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.SourceStringReader;
import net.sourceforge.plantuml.core.DiagramDescription;
public class ScXmlTest {
private static final String TRIPLE_QUOTE = "\"\"\"";
protected void checkXmlAndDescription(final String expectedDescription)
throws IOException, UnsupportedEncodingException {
final String actual = runPlantUML(expectedDescription, FileFormat.SCXML);
final String expected = readStringFromSourceFile(getDiagramFile(), "{{{", "}}}");
if (sortString(actual).equals(sortString(expected)) == false) {
assertEquals(expected, actual, "Generated ScXml is not ok");
}
}
private String sortString(String s) {
final Map<Character, AtomicInteger> map = new TreeMap<>();
for (int i = 0; i < s.length(); i++) {
final char ch = s.charAt(i);
// We ignore non writable characters
if (ch <= ' ')
continue;
AtomicInteger count = map.get(ch);
if (count == null)
map.put(ch, new AtomicInteger(1));
else
count.addAndGet(1);
}
return map.toString();
}
private String getLocalFolder() {
return "test/" + getPackageName().replace(".", "/");
}
private String getPackageName() {
return getClass().getPackage().getName();
}
private Path getDiagramFile() {
return Paths.get(getLocalFolder(), getClass().getSimpleName() + ".java");
}
private String runPlantUML(String expectedDescription, FileFormat format)
throws IOException, UnsupportedEncodingException {
final String diagramText = readStringFromSourceFile(getDiagramFile(), TRIPLE_QUOTE, TRIPLE_QUOTE);
final SourceStringReader ssr = new SourceStringReader(diagramText, UTF_8);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final DiagramDescription diagramDescription = ssr.outputImage(baos, 0, new FileFormatOption(format));
assertEquals(expectedDescription, diagramDescription.getDescription(), "Bad description");
return new String(baos.toByteArray(), UTF_8);
}
private String readStringFromSourceFile(Path path, String startMarker, String endMarker) throws IOException {
assertTrue(Files.exists(path), "Cannot find " + path);
assertTrue(Files.isReadable(path), "Cannot read " + path);
final List<String> allLines = Files.readAllLines(path, UTF_8);
final int first = allLines.indexOf(startMarker);
final int last = allLines.lastIndexOf(endMarker);
assertTrue(first != -1);
assertTrue(last != -1);
assertTrue(last > first);
return packString(allLines.subList(first + 1, last));
}
private String packString(Collection<String> list) {
final StringBuilder sb = new StringBuilder();
for (String s : list) {
sb.append(s);
sb.append("\n");
}
return sb.toString();
}
}

View File

@ -28,15 +28,15 @@ public class XmiTest {
protected void checkXmlAndDescription(final String expectedDescription)
throws IOException, UnsupportedEncodingException {
final String star = runPlantUML(expectedDescription, FileFormat.XMI_STAR);
final String startExpected = readStringFromSourceFile(getDiagramFile(), "{{{star", "}}}star");
final String starExpected = readStringFromSourceFile(getDiagramFile(), "{{{star", "}}}star");
// This is really a hack. Since XML generation does not guarantee the order of
// attributes, we make an easy to do check by sorting characters.
// Of course, this is really incomplete: a faulty String may match the expected
// result if, for example, an attribute is moved from a node to another.
// However, we consider that it is a good start.
if (sortString(star).equals(sortString(startExpected)) == false) {
assertEquals(startExpected, star, "XmiStar: Generated GraphML is not ok");
if (sortString(star).equals(sortString(starExpected)) == false) {
assertEquals(starExpected, star, "XmiStar: Generated GraphML is not ok");
}
final String argo = runPlantUML(expectedDescription, FileFormat.XMI_ARGO);