From 66520f0a355e353885bf2e63f22acb6a2d92d15e Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Thu, 4 Mar 2021 19:11:16 +0100 Subject: [PATCH] Add interactive functionality for Usecase diagrams exported to SVG --- build.xml | 6 + pom.xml | 7 +- skin/plantuml.skin | 37 ++++ src/net/sourceforge/plantuml/FileUtils.java | 5 + .../plantuml/asciiart/ComponentTextActor.java | 8 +- .../plantuml/asciiart/ComponentTextArrow.java | 8 +- .../plantuml/asciiart/ComponentTextNote.java | 4 +- .../asciiart/ComponentTextParticipant.java | 4 +- .../asciiart/ComponentTextSelfArrow.java | 9 +- .../plantuml/asciiart/ComponentTextShape.java | 4 +- .../command/CommandAddMethod.java | 3 +- .../command/CommandCreateClassMultilines.java | 2 +- .../plantuml/command/BlocLines.java | 13 +- .../plantuml/creole/legacy/AtomTextUtils.java | 2 +- .../plantuml/cucadiagram/Bodier.java | 3 +- .../cucadiagram/BodierLikeClassOrObject.java | 6 +- .../plantuml/cucadiagram/BodierSimple.java | 10 +- .../plantuml/cucadiagram/BodyEnhanced1.java | 14 +- .../plantuml/cucadiagram/BodyFactory.java | 12 +- .../plantuml/cucadiagram/Display.java | 2 +- .../cucadiagram/MethodsOrFieldsArea.java | 3 +- .../cucadiagram/dot/CucaDiagramTxtMaker.java | 2 +- .../descdiagram/EntityImageRequirement.java | 4 +- .../plantuml/donors/PSystemDonors.java | 45 +++-- .../plantuml/eggs/PSystemWelcome.java | 11 +- .../plantuml/graphic/HorizontalAlignment.java | 6 +- .../plantuml/graphic/TextBlockUtils.java | 7 + .../sourceforge/plantuml/json/JsonString.java | 2 +- .../plantuml/jsondiagram/JsonDiagram.java | 6 +- .../jsondiagram/JsonDiagramFactory.java | 10 +- .../plantuml/jsondiagram/SmetanaForJson.java | 34 ++-- .../plantuml/jsondiagram/StyleExtractor.java | 85 ++++++++ .../plantuml/jsondiagram/TextBlockJson.java | 64 +++--- .../objectdiagram/command/CommandAddData.java | 3 +- .../plantuml/picoweb/PicoWebServer.java | 35 ++-- .../plantuml/picoweb/PicoWebServerTest.java | 11 +- src/net/sourceforge/plantuml/preproc/Sub.java | 1 - .../plantuml/sequencediagram/LinkAnchor.java | 9 +- .../plantuml/sequencediagram/Message.java | 13 ++ .../sequencediagram/command/CommandArrow.java | 78 ++++++-- .../graphic/SequenceDiagramTxtMaker.java | 4 +- .../sequencediagram/teoz/AbstractTile.java | 17 +- .../sequencediagram/teoz/Bordered.java | 1 - ...eWithUpdateStairs.java => CommonTile.java} | 19 +- .../teoz/CommunicationExoTile.java | 42 ++-- .../teoz/CommunicationTile.java | 123 +++++++----- .../teoz/CommunicationTileNoteBottom.java | 57 +++--- .../teoz/CommunicationTileNoteLeft.java | 44 ++--- .../teoz/CommunicationTileNoteRight.java | 48 +++-- .../teoz/CommunicationTileNoteTop.java | 54 +++-- .../teoz/CommunicationTileSelf.java | 44 +++-- .../teoz/CommunicationTileSelfNoteRight.java | 44 +++-- .../sequencediagram/teoz/DelayTile.java | 28 +-- .../sequencediagram/teoz/DividerTile.java | 17 +- .../sequencediagram/teoz/ElseTile.java | 31 +-- .../sequencediagram/teoz/EmptyTile.java | 14 +- .../sequencediagram/teoz/Englobers.java | 4 +- .../sequencediagram/teoz/EventsHistory.java | 9 +- .../sequencediagram/teoz/GroupingTile.java | 76 +++---- .../sequencediagram/teoz/HSpaceTile.java | 10 +- .../sequencediagram/teoz/LifeEventTile.java | 29 +-- .../sequencediagram/teoz/LiveBoxFinder.java | 127 ------------ .../sequencediagram/teoz/LiveBoxesDrawer.java | 15 +- .../sequencediagram/teoz/NewpageTile.java | 17 +- .../sequencediagram/teoz/NoteTile.java | 26 +-- .../sequencediagram/teoz/NotesTile.java | 32 +-- .../sequencediagram/teoz/PlayingSpace.java | 12 +- .../teoz/PlayingSpaceWithParticipants.java | 7 +- .../sequencediagram/teoz/ReferenceTile.java | 21 +- .../teoz/SequenceDiagramFileMakerTeoz.java | 2 +- .../sequencediagram/teoz/Stairs2.java | 3 +- .../plantuml/sequencediagram/teoz/Tile.java | 22 +-- .../{TileWithCallbackY.java => Tile2.java} | 4 +- .../sequencediagram/teoz/TileArguments.java | 4 +- .../sequencediagram/teoz/TileBuilder.java | 34 ++-- .../sequencediagram/teoz/TileMarged.java | 18 +- .../sequencediagram/teoz/TileParallel.java | 53 +++-- .../teoz/UGraphicInterceptorTile.java | 2 +- .../sequencediagram/teoz/YPositionedTile.java | 22 +-- .../plantuml/skin/ArrowComponent.java | 2 + .../skin/rose/ComponentRoseArrow.java | 37 ++-- .../skin/rose/ComponentRoseSelfArrow.java | 5 + .../statediagram/command/CommandAddField.java | 3 +- src/net/sourceforge/plantuml/style/SName.java | 3 +- .../plantuml/style/StyleSignature.java | 4 + .../svek/extremity/MiddleCircleCircled.java | 6 +- .../svek/image/EntityImageDescription.java | 4 +- .../EntityImageLollipopInterfaceEye2.java | 5 +- .../svek/image/EntityImageState2.java | 5 +- .../svek/image/EntityImageUseCase.java | 19 +- .../sourceforge/plantuml/svg/SvgGraphics.java | 160 ++++----------- .../sourceforge/plantuml/tim/TContext.java | 42 ++-- .../plantuml/timingdiagram/TimingRuler.java | 67 +++++-- .../ugraphic/AbstractCommonUGraphic.java | 3 +- .../ugraphic/PlacementStrategyY1Y2Right.java | 66 +++++++ .../ugraphic/svg/DriverEllipseSvg.java | 2 +- .../plantuml/ugraphic/svg/DriverTextSvg.java | 3 +- .../plantuml/ugraphic/svg/UGraphicSvg.java | 3 +- .../plantuml/version/LicenseInfo.java | 15 +- .../sourceforge/plantuml/version/Version.java | 4 +- .../plantuml/yaml/SimpleYamlParser.java | 155 ++++++--------- .../plantuml/yaml/YamlDiagramFactory.java | 15 +- .../sourceforge/plantuml/yaml/YamlLines.java | 186 ++++++++++++++++++ stdlib/c4-abx.repx | Bin 3262 -> 3189 bytes svg/default.css | 3 + svg/default.js | 110 +++++++++++ 106 files changed, 1561 insertions(+), 1090 deletions(-) create mode 100644 src/net/sourceforge/plantuml/jsondiagram/StyleExtractor.java rename src/net/sourceforge/plantuml/sequencediagram/teoz/{TileWithUpdateStairs.java => CommonTile.java} (78%) delete mode 100644 src/net/sourceforge/plantuml/sequencediagram/teoz/LiveBoxFinder.java rename src/net/sourceforge/plantuml/sequencediagram/teoz/{TileWithCallbackY.java => Tile2.java} (93%) create mode 100644 src/net/sourceforge/plantuml/ugraphic/PlacementStrategyY1Y2Right.java create mode 100644 src/net/sourceforge/plantuml/yaml/YamlLines.java create mode 100644 svg/default.css create mode 100644 svg/default.js diff --git a/build.xml b/build.xml index e96a52bed..16900bd0b 100644 --- a/build.xml +++ b/build.xml @@ -76,6 +76,12 @@ + + + + + + diff --git a/pom.xml b/pom.xml index e08768e32..d85939c05 100644 --- a/pom.xml +++ b/pom.xml @@ -30,12 +30,13 @@ Script Author: Julien Eluard --> - + 4.0.0 net.sourceforge.plantuml plantuml - 1.2021.2-SNAPSHOT + 1.2021.1-SNAPSHOT jar PlantUML @@ -114,6 +115,8 @@ stdlib/**/*.repx skin/**/*.skin + svg/**/*.css + svg/**/*.js diff --git a/skin/plantuml.skin b/skin/plantuml.skin index 94e3fe514..20452bd5d 100644 --- a/skin/plantuml.skin +++ b/skin/plantuml.skin @@ -278,3 +278,40 @@ ganttDiagram { Shadowing 0.0 } } + + +usecase { + HorizontalAlignment center +} + +yamlDiagram { + arrow { + LineThickness 1 + LineStyle 3;3 + } + node { + LineThickness 1.5 + RoundCorner 10 + separator { + LineThickness 1 + LineColor #A80036 + } + } +} + +jsonDiagram { + arrow { + LineThickness 1 + LineStyle 3;3 + } + node { + LineThickness 1.5 + RoundCorner 10 + separator { + LineThickness 1 + LineColor #A80036 + } + } +} + + diff --git a/src/net/sourceforge/plantuml/FileUtils.java b/src/net/sourceforge/plantuml/FileUtils.java index 2bfd60584..39e16a870 100644 --- a/src/net/sourceforge/plantuml/FileUtils.java +++ b/src/net/sourceforge/plantuml/FileUtils.java @@ -160,6 +160,11 @@ public class FileUtils { return readSvg(br, false, false); } + static public String readText(InputStream is) throws IOException { + final BufferedReader br = new BufferedReader(new InputStreamReader(is)); + return readSvg(br, true, true); + } + static public String readFile(SFile svgFile) throws IOException { final BufferedReader br = svgFile.openBufferedReader(); if (br == null) { diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java index 4f4253007..8529c4e82 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java @@ -71,18 +71,18 @@ public class ComponentTextActor extends AbstractComponentText { final int xman = width / 2 - 1; if (type == ComponentType.ACTOR_HEAD) { if (fileFormat == FileFormat.UTXT) { - charArea.drawStringsLRUnicode(stringsToDisplay.as(), 1, getHeight()); + charArea.drawStringsLRUnicode(stringsToDisplay.asList(), 1, getHeight()); charArea.drawShape(AsciiShape.STICKMAN_UNICODE, xman, 0); } else { - charArea.drawStringsLRSimple(stringsToDisplay.as(), 1, getHeight()); + charArea.drawStringsLRSimple(stringsToDisplay.asList(), 1, getHeight()); charArea.drawShape(AsciiShape.STICKMAN, xman, 0); } } else if (type == ComponentType.ACTOR_TAIL) { if (fileFormat == FileFormat.UTXT) { - charArea.drawStringsLRUnicode(stringsToDisplay.as(), 1, 0); + charArea.drawStringsLRUnicode(stringsToDisplay.asList(), 1, 0); charArea.drawShape(AsciiShape.STICKMAN_UNICODE, xman, 1); } else { - charArea.drawStringsLRSimple(stringsToDisplay.as(), 1, 0); + charArea.drawStringsLRSimple(stringsToDisplay.asList(), 1, 0); charArea.drawShape(AsciiShape.STICKMAN, xman, 1); } } else { diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextArrow.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextArrow.java index fdaa3c459..84d4c9d58 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextArrow.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextArrow.java @@ -135,9 +135,9 @@ public class ComponentTextArrow extends AbstractComponentText implements ArrowCo // final int position = Math.max(0, (width - textWidth) / 2); if (fileFormat == FileFormat.UTXT) { - charArea.drawStringsLRUnicode(stringsToDisplay.as(), (width - textWidth) / 2, 0); + charArea.drawStringsLRUnicode(stringsToDisplay.asList(), (width - textWidth) / 2, 0); } else { - charArea.drawStringsLRSimple(stringsToDisplay.as(), (width - textWidth) / 2, 0); + charArea.drawStringsLRSimple(stringsToDisplay.asList(), (width - textWidth) / 2, 0); } } @@ -169,4 +169,8 @@ public class ComponentTextArrow extends AbstractComponentText implements ArrowCo throw new UnsupportedOperationException(); } + public double getPosArrow(StringBounder stringBounder) { + throw new UnsupportedOperationException(); + } + } diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java index c8119a709..39c18d741 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java @@ -79,9 +79,9 @@ public class ComponentTextNote extends AbstractComponentText { } } if (fileFormat == FileFormat.UTXT) { - charArea.drawStringsLRUnicode(stringsToDisplay.as(), 3, 1); + charArea.drawStringsLRUnicode(stringsToDisplay.asList(), 3, 1); } else { - charArea.drawStringsLRSimple(stringsToDisplay.as(), 3, 1); + charArea.drawStringsLRSimple(stringsToDisplay.asList(), 3, 1); } } diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextParticipant.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextParticipant.java index 63998a3e8..0c1404b27 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextParticipant.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextParticipant.java @@ -83,9 +83,9 @@ public class ComponentTextParticipant extends AbstractComponentText { } } if (fileFormat == FileFormat.UTXT) { - charArea.drawStringsLRUnicode(stringsToDisplay.as(), 1, 1); + charArea.drawStringsLRUnicode(stringsToDisplay.asList(), 1, 1); } else { - charArea.drawStringsLRSimple(stringsToDisplay.as(), 1, 1); + charArea.drawStringsLRSimple(stringsToDisplay.asList(), 1, 1); } } diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java index ec03d56ce..c2fb3ca42 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java @@ -97,9 +97,9 @@ public class ComponentTextSelfArrow extends AbstractComponentText implements Arr } if (fileFormat == FileFormat.UTXT) { - charArea.drawStringsLRUnicode(stringsToDisplay.as(), 6, 1); + charArea.drawStringsLRUnicode(stringsToDisplay.asList(), 6, 1); } else { - charArea.drawStringsLRSimple(stringsToDisplay.as(), 6, 1); + charArea.drawStringsLRSimple(stringsToDisplay.asList(), 6, 1); } } @@ -126,5 +126,10 @@ public class ComponentTextSelfArrow extends AbstractComponentText implements Arr public double getYPoint(StringBounder stringBounder) { throw new UnsupportedOperationException(); } + + public double getPosArrow(StringBounder stringBounder) { + throw new UnsupportedOperationException(); + } + } diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextShape.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextShape.java index faf903bb1..812cdad6f 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextShape.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextShape.java @@ -67,10 +67,10 @@ public class ComponentTextShape extends AbstractComponentText { final int xman = width / 2 - shape.getWidth() / 2 + 1; if (type.name().endsWith("_HEAD")) { - charArea.drawStringsLRSimple(stringsToDisplay.as(), 1, getHeight()); + charArea.drawStringsLRSimple(stringsToDisplay.asList(), 1, getHeight()); charArea.drawShape(shape, xman, 0); } else { - charArea.drawStringsLRSimple(stringsToDisplay.as(), 1, 0); + charArea.drawStringsLRSimple(stringsToDisplay.asList(), 1, 0); charArea.drawShape(shape, xman, 1); } } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandAddMethod.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandAddMethod.java index 3e1bcc603..5229da045 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandAddMethod.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandAddMethod.java @@ -47,6 +47,7 @@ import net.sourceforge.plantuml.cucadiagram.Code; import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Ident; import net.sourceforge.plantuml.skin.VisibilityModifier; +import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException; public class CommandAddMethod extends SingleLineCommand2 { @@ -65,7 +66,7 @@ public class CommandAddMethod extends SingleLineCommand2 { } @Override - protected CommandExecutionResult executeArg(ClassDiagram diagram, LineLocation location, RegexResult arg) { + protected CommandExecutionResult executeArg(ClassDiagram diagram, LineLocation location, RegexResult arg) throws NoSuchColorException { final String idShort = arg.get("NAME", 0); final Ident ident = diagram.buildLeafIdent(idShort); final Code code = diagram.V1972() ? ident : diagram.buildCode(idShort); diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java index e73d14777..6d94185b4 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java @@ -92,7 +92,7 @@ public class CommandCreateClassMultilines extends CommandMultilines2 { return loadInternal(br, location); } + public static BlocLines from(List lines) { + return new BlocLines(lines); + } + private static BlocLines loadInternal(final BufferedReader br, LineLocation location) throws IOException { final List result = new ArrayList(); String s; - while ((s = br.readLine()) != null) { - result.add(new StringLocated(s, location)); + try { + while ((s = br.readLine()) != null) { + result.add(new StringLocated(s, location)); + } + } finally { + br.close(); } - br.close(); return new BlocLines(result); } diff --git a/src/net/sourceforge/plantuml/creole/legacy/AtomTextUtils.java b/src/net/sourceforge/plantuml/creole/legacy/AtomTextUtils.java index aa89fbdcc..d056e4d9b 100644 --- a/src/net/sourceforge/plantuml/creole/legacy/AtomTextUtils.java +++ b/src/net/sourceforge/plantuml/creole/legacy/AtomTextUtils.java @@ -80,7 +80,7 @@ public class AtomTextUtils { final Display display = Display.getWithNewlines(url.getLabel()); if (display.size() > 1) { final List all = new ArrayList(); - for (CharSequence s : display.as()) { + for (CharSequence s : display.asList()) { all.add(createAtomText(s.toString(), url, fontConfiguration, skinSimple)); } return new AtomVerticalTexts(all); diff --git a/src/net/sourceforge/plantuml/cucadiagram/Bodier.java b/src/net/sourceforge/plantuml/cucadiagram/Bodier.java index 30e7cfce7..0e0f763e4 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Bodier.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Bodier.java @@ -41,6 +41,7 @@ import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException; public interface Bodier { @@ -50,7 +51,7 @@ public interface Bodier { public Display getMethodsToDisplay(); - public void addFieldOrMethod(String s); + public void addFieldOrMethod(String s) throws NoSuchColorException; public TextBlock getBody(FontParam fontParam, ISkinParam skinParam, boolean showMethods, boolean showFields, Stereotype stereotype, Style style); diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodierLikeClassOrObject.java b/src/net/sourceforge/plantuml/cucadiagram/BodierLikeClassOrObject.java index 8c30400f2..5ffb535ae 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/BodierLikeClassOrObject.java +++ b/src/net/sourceforge/plantuml/cucadiagram/BodierLikeClassOrObject.java @@ -211,7 +211,8 @@ public class BodierLikeClassOrObject implements Bodier { if (type.isLikeClass() && isBodyEnhanced()) { if (showMethods || showFields) { - return BodyFactory.create1(rawBodyWithoutHidden(), fontParam, skinParam, stereotype, leaf, style); + return BodyFactory.create1(skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), + rawBodyWithoutHidden(), fontParam, skinParam, stereotype, leaf, style); } return null; } @@ -222,7 +223,8 @@ public class BodierLikeClassOrObject implements Bodier { if (showFields == false) { return new TextBlockLineBefore(TextBlockUtils.empty(0, 0)); } - return BodyFactory.create1(rawBodyWithoutHidden(), fontParam, skinParam, stereotype, leaf, style); + return BodyFactory.create1(skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), + rawBodyWithoutHidden(), fontParam, skinParam, stereotype, leaf, style); } assert type.isLikeClass(); diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodierSimple.java b/src/net/sourceforge/plantuml/cucadiagram/BodierSimple.java index 43d6fa2e4..f72435de4 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/BodierSimple.java +++ b/src/net/sourceforge/plantuml/cucadiagram/BodierSimple.java @@ -41,8 +41,10 @@ import java.util.List; import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException; public class BodierSimple implements Bodier { @@ -63,8 +65,9 @@ public class BodierSimple implements Bodier { this.leaf = leaf; } - public void addFieldOrMethod(String s) { - rawBody.add(s); + public void addFieldOrMethod(String s) throws NoSuchColorException { + final Display display = Display.getWithNewlines2(s); + rawBody.addAll(display.asList()); } public Display getMethodsToDisplay() { @@ -85,7 +88,8 @@ public class BodierSimple implements Bodier { public TextBlock getBody(FontParam fontParam, ISkinParam skinParam, boolean showMethods, boolean showFields, Stereotype stereotype, Style style) { - return BodyFactory.create1(rawBody, fontParam, skinParam, stereotype, leaf, style); + return BodyFactory.create1(skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), rawBody, fontParam, + skinParam, stereotype, leaf, style); } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced1.java b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced1.java index d7970bf2d..c0ccea182 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced1.java +++ b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced1.java @@ -74,10 +74,9 @@ public class BodyEnhanced1 extends BodyEnhancedAbstract implements TextBlock, Wi private final boolean inEllipse; private final Style style; - BodyEnhanced1(List rawBody, FontParam fontParam, ISkinParam skinParam, Stereotype stereotype, - ILeaf entity, Style style) { - super(skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), - new FontConfiguration(skinParam, fontParam, stereotype)); + BodyEnhanced1(HorizontalAlignment align, List rawBody, FontParam fontParam, ISkinParam skinParam, + Stereotype stereotype, ILeaf entity, Style style) { + super(align, new FontConfiguration(skinParam, fontParam, stereotype)); this.style = style; this.rawBody2 = Display.create(rawBody); this.stereotype = stereotype; @@ -90,11 +89,10 @@ public class BodyEnhanced1 extends BodyEnhancedAbstract implements TextBlock, Wi this.inEllipse = false; } - BodyEnhanced1(Display display, FontParam fontParam, ISkinParam skinParam, HorizontalAlignment align, + BodyEnhanced1(HorizontalAlignment align, Display display, FontParam fontParam, ISkinParam skinParam, Stereotype stereotype, ILeaf entity, Style style) { - super(skinParam.getDefaultTextAlignment(align), - style == null ? new FontConfiguration(skinParam, fontParam, stereotype) - : style.getFontConfiguration(skinParam.getIHtmlColorSet())); + super(align, style == null ? new FontConfiguration(skinParam, fontParam, stereotype) + : style.getFontConfiguration(skinParam.getIHtmlColorSet())); this.style = style; this.entity = entity; diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodyFactory.java b/src/net/sourceforge/plantuml/cucadiagram/BodyFactory.java index aabb8a95b..8a0cfe046 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/BodyFactory.java +++ b/src/net/sourceforge/plantuml/cucadiagram/BodyFactory.java @@ -63,14 +63,14 @@ public class BodyFactory { return new BodierSimple(); } - public static TextBlock create1(List rawBody, FontParam fontParam, ISkinParam skinParam, - Stereotype stereotype, ILeaf entity, Style style) { - return new BodyEnhanced1(rawBody, fontParam, skinParam, stereotype, entity, style); + public static TextBlock create1(HorizontalAlignment align, List rawBody, FontParam fontParam, + ISkinParam skinParam, Stereotype stereotype, ILeaf entity, Style style) { + return new BodyEnhanced1(align, rawBody, fontParam, skinParam, stereotype, entity, style); } - public static TextBlock create2(Display display, FontParam fontParam, ISkinParam skinParam, - HorizontalAlignment align, Stereotype stereotype, ILeaf entity, Style style) { - return new BodyEnhanced1(display, fontParam, skinParam, align, stereotype, entity, style); + public static TextBlock create2(HorizontalAlignment align, Display display, FontParam fontParam, + ISkinParam skinParam, Stereotype stereotype, ILeaf entity, Style style) { + return new BodyEnhanced1(align, display, fontParam, skinParam, stereotype, entity, style); } public static TextBlock create3(Display rawBody, FontParam fontParam, ISkinSimple skinParam, diff --git a/src/net/sourceforge/plantuml/cucadiagram/Display.java b/src/net/sourceforge/plantuml/cucadiagram/Display.java index a9facdeed..e1a5a2095 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Display.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Display.java @@ -418,7 +418,7 @@ public class Display implements Iterable { this.defaultCreoleMode); } - public List as() { + public List asList() { return Collections.unmodifiableList(displayData); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/MethodsOrFieldsArea.java b/src/net/sourceforge/plantuml/cucadiagram/MethodsOrFieldsArea.java index a72e56b24..13c471788 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/MethodsOrFieldsArea.java +++ b/src/net/sourceforge/plantuml/cucadiagram/MethodsOrFieldsArea.java @@ -62,6 +62,7 @@ import net.sourceforge.plantuml.ugraphic.PlacementStrategy; import net.sourceforge.plantuml.ugraphic.PlacementStrategyVisibility; import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2Center; import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2Left; +import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2Right; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULayoutGroup; import net.sourceforge.plantuml.ugraphic.color.HColor; @@ -284,7 +285,7 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlock, } else if (align == HorizontalAlignment.CENTER) { placementStrategy = new PlacementStrategyY1Y2Center(stringBounder); } else { - placementStrategy = new PlacementStrategyY1Y2Left(stringBounder); + placementStrategy = new PlacementStrategyY1Y2Right(stringBounder); } group = new ULayoutGroup(placementStrategy); for (CharSequence cs : members) { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java index 668703a97..2ca09c28e 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java @@ -131,7 +131,7 @@ public final class CucaDiagramTxtMaker { final int w = getWidth(ent); final int h = getHeight(ent); ug.getCharArea().drawBoxSimple(0, 0, w, h); - ug.getCharArea().drawStringsLRSimple(ent.getDisplay().as(), 1, 1); + ug.getCharArea().drawStringsLRSimple(ent.getDisplay().asList(), 1, 1); if (showMember(ent)) { int y = 2; ug.getCharArea().drawHLine('-', y, 1, w - 1); diff --git a/src/net/sourceforge/plantuml/descdiagram/EntityImageRequirement.java b/src/net/sourceforge/plantuml/descdiagram/EntityImageRequirement.java index 04f5cd4e0..3df4d0bc7 100644 --- a/src/net/sourceforge/plantuml/descdiagram/EntityImageRequirement.java +++ b/src/net/sourceforge/plantuml/descdiagram/EntityImageRequirement.java @@ -77,8 +77,8 @@ public class EntityImageRequirement extends AbstractEntityImage { super(entity, skinParam); final Stereotype stereotype = entity.getStereotype(); - final TextBlock tmp = BodyFactory.create2(entity.getDisplay(), FontParam.REQUIREMENT, skinParam, - HorizontalAlignment.CENTER, stereotype, entity, null); + final TextBlock tmp = BodyFactory.create2(skinParam.getDefaultTextAlignment(HorizontalAlignment.CENTER), + entity.getDisplay(), FontParam.REQUIREMENT, skinParam, stereotype, entity, null); if (stereotype == null || stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR) == null) { this.desc = tmp; diff --git a/src/net/sourceforge/plantuml/donors/PSystemDonors.java b/src/net/sourceforge/plantuml/donors/PSystemDonors.java index 6a54711d6..1d0ce2624 100644 --- a/src/net/sourceforge/plantuml/donors/PSystemDonors.java +++ b/src/net/sourceforge/plantuml/donors/PSystemDonors.java @@ -77,29 +77,28 @@ public class PSystemDonors extends AbstractPSystem { private static final int COLS = 6; private static final int FREE_LINES = 6; - public static final String DONORS = - "6-KC0AmFkBap0wp4H6CjU-RENbb-8cPf4i7oFA4uiOZJNK3y0UwT7lSRwI-YAxltJJEYrckJSWPHVH3q"+ - "W7UtXVQXzBy-27EYV0Z-tGWU80D4ITH6ZIpt9Djjcof3Il3lEr_v9UWTth51ehbAgiMHwq-_8GFlEsFp"+ - "x3GsNZsQe2y2FmRsrV-REbkNLuKmItShC0AZeX4owzXZ_1_Lei8fs7Seq6EhCPrAK1qELLHYiytVvB1A"+ - "6l12LJil5PfCYb5JfFXQ8GsVtfXGavF6HyX67vn_g1_2cyqLbZBE1E9eGnrTN_-tPTk8zkTAl0XoXrXG"+ - "M60Ef1m9YoX-Rdhmmos0eMeMWx45XJLFOY6H0YtapH_gIS4ZvSpfSF73um4G-3o32YIjg4OJpfPN0ygF"+ - "P8iMIrnrSTnOwiTXUIfz90sF9nOU5jG2QWZoF-Y2JeirFfewszNWIEffadkzfQXV1M_csape6roQ9Aot"+ - "jPTczhYYb2LIJTlu7EqrZm3SBRLon9VHH2W7QFQRLw6iVhH0VWIwgYPioPzbNrd8XAYsOHzwrxdyy1X4"+ - "s2T3fecr_swslPR-GjUCOLF22h1epvYlYqrmi8MkJ1u1dj3AvxBE1v2qj7g_wF6mTfzmJRx4lI7HUXzX"+ - "AVttgpxC3CK1sbDc5dJZ1KjdDAsQYos8O8_GqG4tXUHAE7VNvTXzNAIF_0J0cqiFkiD6e1RY-MOgJKSX"+ - "KaFghaWp0PWzhTJ53wyb38gr2ReQLOBfPRNQutGrfYyRC_T96rpN6enH7DEPwWlBtQiYBGppLQCvVRDs"+ - "WEOKF9MN_RpgNQLS1RYqy1xmmJt_o82VwPM1I97fxjis_2DBimgBMQovRbQbkweV73nq_O4xMZI96MNo"+ - "aAL1SIWHDVKhaP-M37zBa4tpUpdQQrYThZD2X1bfS7jfSavDZldXDftbEDWWHA9QlEAK99nViDjb9Td2"+ - "faXvnkfUICXldqyYKYKib1hiQky2FADv5EJXl6jMBQlN9amke99i9WXA2rQr53hIrm8P6AlNCz4QiVrf"+ - "WGLZQOzHCt4elcAYjSeD15DWfeJpXK4aaaAzb5xc9161__bpbthQK0SxlZE6JyP1ieSa0geWzHadgeRQ"+ - "wz5j6Eib_dwzb9kFuC-_zcYJKwtTyrE2Q1t41Q275t0fzmizU1huQsoO13Z42YvwaN3begMdWOG5w_7E"+ - "8khIEADn4vFbXkIYLUI7ol_zkHOkvaDio77n73fQBAdIoyrgK6csht_NuIY7Zh-BAdqYkVmtFPEHq4aO"+ - "nBauzjM6eQbA2bXG7RK9hDtrsscMkyQSTo3L3oT0ljoGKwaMeOKrDItk2u7bOYplRTfFEIt-au5-ajRf"+ - "nruzr1navxfs4mtVjX3Q4Js9uI9nGuJ-bI4d6dZune-yg1PAmzAw6NQkO8NyUbx62mcxxE03arfUfQno"+ - "Guw-XUmjrS2F0A9AQ203YoMwUh5Gol50YgHWpi4odY7beBKukIS0foZOt-zh42uzqNo7Pktj6OLaBjlS"+ - "J0OGwN1-MebD-cpLo85zDNFPwXMvBRL8X-txTdp7-Vf7rDM324WWgadm6btarOszPcdO9CERMHp7PMOU"+ - "J7uEkwATfGniDPCjo5ms0mLF0X0x42eaT-5NyH5ppZdox_r6NnXemlF0QNJZkH9iGBRSY9GqeEOeYppt"+ - "lNsJ4m00"; + public static final String DONORS = "6neD0AmFkBap0wp4H6CjU-RENbb-8cPf4i7oFA4uiOZJNK3y0UwT7lSRwI-YAxltJJEYrckJSaPHV13q" + + "W7UtXVQXzBy-27EYV0Z-tGWU80D4ITH6ZIpt9Djjcof3Il3lEr_v9UWTth51ehbAgiMHwq-_8GFlEsFp" + + "x3GsNZsQe2y2FmRsrPzVStLjuA5OdYSeWP8k4zg9ecxlNzf8nq_W_vEaQXTjwOuqQQIX0ZigyDXNVjMr" + + "yr6ZoQeOCKMAhnNIyEcD2GqvwNs2RD2Wy4Fz4Dvihh2KSIOGHniYT7szjcFRYE4NIdpOvGwnm93074Wv" + + "qXTHzDnGK70BOAYRnMniIUN8anHGP4CBUVE7UbBnI3bpEbmKF1u0WSypg42aDMhGXBFvmu2A8zcYmn9N" + + "dHatbkPnM9xIHjBmD6BXOK4he8OW_uCkyBHOuwEfirqDZgIU9hbtMudwiztRkJOh-aRN9WdhQ-kbMMnS" + + "KSeIgQvjV8xscaS0xfPQEUBBw2EK0pJxpQkAh7wqGFm8T5zDs98_otwma0bXRSC-KDUv-l2OHJWcGwQ9" + + "TVnkjhsclT35TZOWOGLOfFVahpDDS50BNOay0ZoXLSnbdGyKqjBg_QB7mzfzmZN54lU6HEzzXANqtw_w" + + "C3CK1-X0cLdGJHCidT6qQY-s889wX8uEk2aaLyAvkox7xkCYVUGd0DvKUa0E6pkD4CylKsaw2g4QqdLD" + + "cXN0v6cbBGfUInYKQnDqCwe4GsMrskDqTQOl6nFtIHyyRpKO8t5CPwelB7UlYhGmB5QDPcspTe3c55pX" + + "upYlUizShWAqjl0UyS4z_yY0dkcLWKYH8VTj6_wHfLc5nIpMN3UhqbtL3suUkld0NIoQnOmoUSXKQ1nA" + + "H4lzIkId9SFV76HLVwqkzWusf-kC46567DnUcbnJasCARjDPZeCDGcIenIjESSBv1NjOLf8jR0gLPwmU" + + "XOJyZlaa8bNwGcd0hk6km3EIHq4UpdjWrR9wRIh91LIHpGH1QS6gbYgEzBL01iQQzCoqHcn_Mc31MDfZ" + + "T2mx5BrYegtA3JAcm4mJwXS6aIWrr4lfPKuI4VYVFtUf9yrraECxO_Xa74Jsa4I0AkJkZ1DLJztjw3QC" + + "zH9_lrxApKVmvrzxjCcfqUxvQOBGEeWAG0ylu5Bk5thmDF3Ns30JS8WLLFGYuSfLIuy32GisuvrTrBbb" + + "HkCc9ikDoKMlo0zL_5lS2XVJ8JRek0YcE5eigTBBpMfGSRPlVjVX8eUEVuagGoAvhDKo6GaUXLcScsDV" + + "RHYQjd834bH7RG9hT_rsckMkCUSha9g6oq2-tP1JgHQXXMfgMjuN0gl5sD_Rj9zoMlmd0_quhRNZgXuQ" + + "3d9qVRk9XczRsDiPFOdX8cP3XFwLEISSUFZ6Zxoe5ah3qhOPTgvWXVm6NiOB2OViu0EJMbwbh793Zhw5" + + "x1tLA3y1H3N1WGmiLkYQn48fnmCfae8vPyjeXfI3Fk2idW2Sec1_Vsz1E2tH_8ncxUqPXMGksznDPX3n" + + "S7u6YPfCsUgH0_jYvhBDAt8xQf4EE_Rj-8xpxO-ecmSHo84e9i5hTQ4FD_QQfM5JVAxJu3ukS_DcyWku" + + "5EqyPM1hc6n1bh8Pg7WIWDX1faBvrVwh-OWjvnJvztvZAWmquNdYDBhnN0is8rjjH4eQq7AHXT_wViTD" + + "JWvCd1BPydFDONPw64xHwHK0"; /* * Special thanks to our sponsors and donors: diff --git a/src/net/sourceforge/plantuml/eggs/PSystemWelcome.java b/src/net/sourceforge/plantuml/eggs/PSystemWelcome.java index 456e9e9e3..ec8cf2097 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemWelcome.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemWelcome.java @@ -5,12 +5,12 @@ * (C) Copyright 2009-2020, Arnaud Roques * * Project Info: http://plantuml.com - * + * * 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 - * + * * This file is part of PlantUML. * * PlantUML is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ * * * Original Author: Arnaud Roques - * + * * */ package net.sourceforge.plantuml.eggs; @@ -73,8 +73,9 @@ public class PSystemWelcome extends AbstractPSystem { strings.add(" "); strings.add("You will find more information about PlantUML syntax on https://plantuml.com"); strings.add(" "); - strings.add("If you use this software, you accept its license."); + 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) { strings.add(" "); strings.add(" "); diff --git a/src/net/sourceforge/plantuml/graphic/HorizontalAlignment.java b/src/net/sourceforge/plantuml/graphic/HorizontalAlignment.java index e0c453ebc..29658da8d 100644 --- a/src/net/sourceforge/plantuml/graphic/HorizontalAlignment.java +++ b/src/net/sourceforge/plantuml/graphic/HorizontalAlignment.java @@ -77,15 +77,15 @@ public enum HorizontalAlignment { return toString().substring(0, 1).toLowerCase(); } - public void draw(UGraphic ug, TextBlock tb, double padding, Dimension2D dimTotal) { + public void draw(UGraphic ug, TextBlock tb, double padding, double width) { if (this == HorizontalAlignment.LEFT) { tb.drawU(ug.apply(new UTranslate(padding, padding))); } else if (this == HorizontalAlignment.RIGHT) { final Dimension2D dimTb = tb.calculateDimension(ug.getStringBounder()); - tb.drawU(ug.apply(new UTranslate(dimTotal.getWidth() - dimTb.getWidth() - padding, padding))); + tb.drawU(ug.apply(new UTranslate(width - dimTb.getWidth() - padding, padding))); } else if (this == HorizontalAlignment.CENTER) { final Dimension2D dimTb = tb.calculateDimension(ug.getStringBounder()); - tb.drawU(ug.apply(new UTranslate((dimTotal.getWidth() - dimTb.getWidth()) / 2, padding))); + tb.drawU(ug.apply(new UTranslate((width - dimTb.getWidth()) / 2, padding))); } } diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java b/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java index bced6c58d..a013ad4c8 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java @@ -135,6 +135,11 @@ public class TextBlockUtils { public Dimension2D calculateDimension(StringBounder stringBounder) { return new Dimension2DDouble(width, height); } + + public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) { + return null; + } + }; } @@ -227,6 +232,8 @@ public class TextBlockUtils { } return null; } + + }; } diff --git a/src/net/sourceforge/plantuml/json/JsonString.java b/src/net/sourceforge/plantuml/json/JsonString.java index 408cae3b2..6b551f33b 100644 --- a/src/net/sourceforge/plantuml/json/JsonString.java +++ b/src/net/sourceforge/plantuml/json/JsonString.java @@ -25,7 +25,7 @@ import java.io.IOException; @SuppressWarnings("serial") // use default serial UID -class JsonString extends JsonValue { +public class JsonString extends JsonValue { private final String string; diff --git a/src/net/sourceforge/plantuml/jsondiagram/JsonDiagram.java b/src/net/sourceforge/plantuml/jsondiagram/JsonDiagram.java index bdb919d59..d58268131 100644 --- a/src/net/sourceforge/plantuml/jsondiagram/JsonDiagram.java +++ b/src/net/sourceforge/plantuml/jsondiagram/JsonDiagram.java @@ -45,7 +45,7 @@ import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.Scale; import net.sourceforge.plantuml.SkinParam; -import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.TitledDiagram; import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.UseStyle; import net.sourceforge.plantuml.core.DiagramDescription; @@ -69,7 +69,7 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.color.HColor; -public class JsonDiagram extends UmlDiagram { +public class JsonDiagram extends TitledDiagram { private final JsonValue root; private final List highlighted; @@ -93,7 +93,7 @@ public class JsonDiagram extends UmlDiagram { } @Override - protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption) + protected ImageData exportDiagramNow(OutputStream os, int index, FileFormatOption fileFormatOption, long seed) throws IOException { final Scale scale = getScale(); diff --git a/src/net/sourceforge/plantuml/jsondiagram/JsonDiagramFactory.java b/src/net/sourceforge/plantuml/jsondiagram/JsonDiagramFactory.java index a4c55391b..1d0996e13 100644 --- a/src/net/sourceforge/plantuml/jsondiagram/JsonDiagramFactory.java +++ b/src/net/sourceforge/plantuml/jsondiagram/JsonDiagramFactory.java @@ -40,7 +40,6 @@ import java.util.Iterator; import java.util.List; import net.sourceforge.plantuml.BackSlash; -import net.sourceforge.plantuml.StringLocated; import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.command.PSystemAbstractFactory; import net.sourceforge.plantuml.core.Diagram; @@ -58,13 +57,15 @@ public class JsonDiagramFactory extends PSystemAbstractFactory { public Diagram createSystem(UmlSource source) { final List highlighted = new ArrayList(); + StyleExtractor styleExtractor = null; JsonValue json; try { final StringBuilder sb = new StringBuilder(); - final Iterator it = source.iterator2(); + styleExtractor = new StyleExtractor(source.iterator2()); + final Iterator it = styleExtractor.getIterator(); it.next(); while (true) { - final String line = it.next().getString(); + final String line = it.next(); if (it.hasNext() == false) { break; } @@ -83,6 +84,9 @@ public class JsonDiagramFactory extends PSystemAbstractFactory { json = null; } final JsonDiagram result = new JsonDiagram(UmlDiagramType.JSON, json, highlighted); + if (styleExtractor != null) { + styleExtractor.applyStyles(result.getSkinParam()); + } result.setSource(source); return result; } diff --git a/src/net/sourceforge/plantuml/jsondiagram/SmetanaForJson.java b/src/net/sourceforge/plantuml/jsondiagram/SmetanaForJson.java index 74277b3f2..48222c6f0 100644 --- a/src/net/sourceforge/plantuml/jsondiagram/SmetanaForJson.java +++ b/src/net/sourceforge/plantuml/jsondiagram/SmetanaForJson.java @@ -53,6 +53,7 @@ import h.ST_Agnodeinfo_t; import h.ST_Agraph_s; import h.ST_GVC_s; import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.style.PName; @@ -60,7 +61,6 @@ import net.sourceforge.plantuml.style.SName; import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.StyleSignature; import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; import smetana.core.CString; @@ -106,16 +106,21 @@ public class SmetanaForJson { public SmetanaForJson(UGraphic ug, ISkinParam skinParam) { this.stringBounder = ug.getStringBounder(); this.skinParam = skinParam; - this.ug = getStyle().applyStrokeAndLineColor(ug, skinParam.getIHtmlColorSet()); + this.ug = ug; } - private Style getStyle() { - return StyleSignature.of(SName.root, SName.element, SName.jsonDiagram) + private UGraphic getUgFor(SName name) { + return getStyle(name).applyStrokeAndLineColor(ug, skinParam.getIHtmlColorSet()); + } + + private Style getStyle(SName name) { + return StyleSignature.of(SName.root, SName.element, + skinParam.getUmlDiagramType() == UmlDiagramType.YAML ? SName.yamlDiagram : SName.jsonDiagram, name) .getMergedStyle(skinParam.getCurrentStyleBuilder()); } private ST_Agnode_s manageOneNode(JsonValue current, List highlighted) { - final TextBlockJson block = new TextBlockJson(skinParam, current, highlighted); + final TextBlockJson block = new TextBlockJson(skinParam, current, highlighted, getStyle(SName.node)); final ST_Agnode_s node1 = createNode(block.calculateDimension(stringBounder), block.size(), current.isArray(), (int) block.getWidthColA(stringBounder), (int) block.getWidthColB(stringBounder)); nodes.add(new InternalNode(block, node1)); @@ -157,14 +162,15 @@ public class SmetanaForJson { xMirror = new Mirror(max); for (InternalNode node : nodes) { - node.block.drawU(ug.apply(getPosition(node.node))); + node.block.drawU(getUgFor(SName.node).apply(getPosition(node.node))); } - final HColor color = getStyle().value(PName.LineColor).asColor(skinParam.getIHtmlColorSet()); + final HColor color = getStyle(SName.arrow).value(PName.LineColor).asColor(skinParam.getIHtmlColorSet()); for (ST_Agedge_s edge : edges) { final JsonCurve curve = getCurve(edge, 13); - curve.drawCurve(color, ug.apply(new UStroke(3, 3, 1))); - curve.drawSpot(ug.apply(color.bg())); + // curve.drawCurve(color, getUgFor(SName.arrow).apply(new UStroke(3, 3, 1))); + curve.drawCurve(color, getUgFor(SName.arrow)); + curve.drawSpot(getUgFor(SName.arrow).apply(color.bg())); } } @@ -235,7 +241,8 @@ public class SmetanaForJson { agsafeset(node, new CString("height"), new CString("" + width), new CString("")); agsafeset(node, new CString("width"), new CString("" + height), new CString("")); - final String dotLabel = getDotLabel(size, isArray, colAwidth - 8, colBwidth - 8); + final int lineHeight = 0; + final String dotLabel = getDotLabel(size, isArray, colAwidth - 8, colBwidth - 8, lineHeight); if (size > 0) { agsafeset(node, new CString("label"), new CString(dotLabel), new CString("")); } @@ -250,14 +257,15 @@ public class SmetanaForJson { return node; } - private String getDotLabel(int size, boolean isArray, int widthA, int widthB) { + private String getDotLabel(int size, boolean isArray, int widthA, int widthB, int height) { final StringBuilder sb = new StringBuilder(""); if (isArray == false) { - sb.append("{_dim_0_" + widthA + "_|{"); + // "+height+" + sb.append("{_dim_" + height + "_" + widthA + "_|{"); } for (int i = 0; i < size; i++) { sb.append(""); - sb.append("_dim_0_" + widthB + "_"); + sb.append("_dim_" + height + "_" + widthB + "_"); if (i < size - 1) sb.append("|"); } diff --git a/src/net/sourceforge/plantuml/jsondiagram/StyleExtractor.java b/src/net/sourceforge/plantuml/jsondiagram/StyleExtractor.java new file mode 100644 index 000000000..697e9f4b9 --- /dev/null +++ b/src/net/sourceforge/plantuml/jsondiagram/StyleExtractor.java @@ -0,0 +1,85 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.jsondiagram; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringLocated; +import net.sourceforge.plantuml.command.BlocLines; +import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.style.StyleBuilder; +import net.sourceforge.plantuml.style.StyleLoader; + +public class StyleExtractor { + + private final List list = new ArrayList(); + private final List style = new ArrayList(); + + public StyleExtractor(Iterator data) { + while (data.hasNext()) { + StringLocated line = data.next(); + if (line.getString().trim().equals("")) { + break; + } + line = data.next(); + } + } else { + list.add(line.getString()); + } + } + } + + public void applyStyles(ISkinParam skinParam) { + if (style.size() > 0) { + final StyleBuilder styleBuilder = skinParam.getCurrentStyleBuilder(); + final BlocLines blocLines = BlocLines.from(style); + for (Style modifiedStyle : StyleLoader.getDeclaredStyles(blocLines.subExtract(1, 1), styleBuilder)) { + skinParam.muteStyle(modifiedStyle); + } + } + } + + public Iterator getIterator() { + return list.iterator(); + } + +} diff --git a/src/net/sourceforge/plantuml/jsondiagram/TextBlockJson.java b/src/net/sourceforge/plantuml/jsondiagram/TextBlockJson.java index b69d64027..bab6b506d 100644 --- a/src/net/sourceforge/plantuml/jsondiagram/TextBlockJson.java +++ b/src/net/sourceforge/plantuml/jsondiagram/TextBlockJson.java @@ -42,6 +42,7 @@ import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.LineBreakStrategy; import net.sourceforge.plantuml.creole.CreoleMode; import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.AbstractTextBlock; @@ -54,14 +55,13 @@ import net.sourceforge.plantuml.json.JsonArray; import net.sourceforge.plantuml.json.JsonObject; import net.sourceforge.plantuml.json.JsonObject.Member; import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.SName; import net.sourceforge.plantuml.style.Style; -import net.sourceforge.plantuml.style.StyleSignature; import net.sourceforge.plantuml.svek.TextBlockBackcolored; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.URectangle; -import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; @@ -70,6 +70,7 @@ public class TextBlockJson extends AbstractTextBlock implements TextBlockBackcol private final List lines = new ArrayList(); + private final Style style; private final ISkinParam skinParam; private double totalWidth; private final JsonValue root; @@ -99,8 +100,9 @@ public class TextBlockJson extends AbstractTextBlock implements TextBlockBackcol } - public TextBlockJson(ISkinParam skinParam, JsonValue root, List highlighted) { + public TextBlockJson(ISkinParam skinParam, JsonValue root, List highlighted, Style style) { this.skinParam = skinParam; + this.style = style; this.root = root; if (root instanceof JsonObject) for (Member member : (JsonObject) root) { @@ -230,17 +232,37 @@ public class TextBlockJson extends AbstractTextBlock implements TextBlockBackcol return width; } - public void drawU(UGraphic ug) { + public void drawU(final UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); final Dimension2D fullDim = calculateDimension(stringBounder); double trueWidth = Math.max(fullDim.getWidth(), totalWidth); final double widthColA = getWidthColA(stringBounder); + final double widthColB = getWidthColB(stringBounder); double y = 0; - ug = getStyle().applyStrokeAndLineColor(ug, skinParam.getIHtmlColorSet()); + final UGraphic ugNode = style.applyStrokeAndLineColor(ug, skinParam.getIHtmlColorSet()); for (Line line : lines) { - final UGraphic ugline = ug.apply(UTranslate.dy(y)); + final double heightOfRow = line.getHeightOfRow(stringBounder); + y += heightOfRow; + } + if (y == 0) + y = 15; + if (trueWidth == 0) + trueWidth = 30; + + final double round = style.value(PName.RoundCorner).asDouble(); + final URectangle fullNodeRectangle = new URectangle(trueWidth, y).rounded(round); + final HColor backColor = style.value(PName.BackGroundColor).asColor(skinParam.getIHtmlColorSet()); + ugNode.apply(backColor.bg()).apply(backColor).draw(fullNodeRectangle); + + final Style styleSeparator = style.getSignature().add(SName.separator) + .getMergedStyle(skinParam.getCurrentStyleBuilder()); + final UGraphic ugSeparator = styleSeparator.applyStrokeAndLineColor(ug, skinParam.getIHtmlColorSet()); + + y = 0; + for (Line line : lines) { + final UGraphic ugline = ugSeparator.apply(UTranslate.dy(y)); final double heightOfRow = line.getHeightOfRow(stringBounder); if (line.highlighted) { final URectangle back = new URectangle(trueWidth - 2, heightOfRow).rounded(4); @@ -251,24 +273,19 @@ public class TextBlockJson extends AbstractTextBlock implements TextBlockBackcol if (y > 0) ugline.draw(ULine.hline(trueWidth)); - final double posColA = (widthColA - line.b1.calculateDimension(stringBounder).getWidth()) / 2; - line.b1.drawU(ugline.apply(UTranslate.dx(posColA))); + final HorizontalAlignment horizontalAlignment = style.getHorizontalAlignment(); + horizontalAlignment.draw(ugline, line.b1, 0, widthColA); if (line.b2 != null) { - line.b2.drawU(ugline.apply(UTranslate.dx(widthColA))); - ugline.apply(UTranslate.dx(widthColA)).draw(ULine.vline(heightOfRow)); + final UGraphic uglineColB = ugline.apply(UTranslate.dx(widthColA)); + horizontalAlignment.draw(uglineColB, line.b2, 0, widthColB); + uglineColB.draw(ULine.vline(heightOfRow)); } y += heightOfRow; } + ugNode.draw(fullNodeRectangle); - if (y == 0) - y = 15; - if (trueWidth == 0) - trueWidth = 30; - - final URectangle full = new URectangle(trueWidth, y).rounded(10); - ug.apply(new UStroke(1.5)).draw(full); } private double getTotalHeight(StringBounder stringBounder) { @@ -281,18 +298,15 @@ public class TextBlockJson extends AbstractTextBlock implements TextBlockBackcol private TextBlock getTextBlock(String key) { final Display display = Display.getWithNewlines(key); - final FontConfiguration fontConfiguration = getStyle().getFontConfiguration(skinParam.getIHtmlColorSet()); - TextBlock result = display.create7(fontConfiguration, HorizontalAlignment.LEFT, skinParam, - CreoleMode.NO_CREOLE); + final FontConfiguration fontConfiguration = style.getFontConfiguration(skinParam.getIHtmlColorSet()); + final LineBreakStrategy wrap = style.wrapWidth(); + final HorizontalAlignment horizontalAlignment = style.getHorizontalAlignment(); + TextBlock result = display.create0(fontConfiguration, horizontalAlignment, skinParam, wrap, + CreoleMode.NO_CREOLE, null, null); result = TextBlockUtils.withMargin(result, 5, 2); return result; } - private Style getStyle() { - return StyleSignature.of(SName.root, SName.element, SName.jsonDiagram) - .getMergedStyle(skinParam.getCurrentStyleBuilder()); - } - public void setTotalWidth(double totalWidth) { this.totalWidth = totalWidth; } diff --git a/src/net/sourceforge/plantuml/objectdiagram/command/CommandAddData.java b/src/net/sourceforge/plantuml/objectdiagram/command/CommandAddData.java index 7ae3b7a9e..6adf633b5 100644 --- a/src/net/sourceforge/plantuml/objectdiagram/command/CommandAddData.java +++ b/src/net/sourceforge/plantuml/objectdiagram/command/CommandAddData.java @@ -45,6 +45,7 @@ import net.sourceforge.plantuml.command.regex.RegexResult; import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram; import net.sourceforge.plantuml.skin.VisibilityModifier; +import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException; public class CommandAddData extends SingleLineCommand2 { @@ -63,7 +64,7 @@ public class CommandAddData extends SingleLineCommand2emptyList() - ); - imageData = ssr.noStartumlFound(os, option.getFileFormatOption(),42); + system = PSystemErrorUtils.buildV2(null, + new ErrorUml(SYNTAX_ERROR, "No @startuml/@enduml found", 0, new LineLocationImpl("", null)), null, + Collections.emptyList()); + imageData = ssr.noStartumlFound(os, option.getFileFormatOption(), 42); } else { system = ssr.getBlocks().get(0).getDiagram(); imageData = system.exportDiagram(os, 0, option.getFileFormatOption()); @@ -201,9 +198,9 @@ public class PicoWebServer implements Runnable { sendDiagram(out, system, option.getFileFormatOption(), "200", imageData, os.toByteArray()); } - private void sendDiagram(final BufferedOutputStream out, final Diagram system, final FileFormatOption fileFormatOption, - final String returnCode, final ImageData imageData, final byte[] fileData) - throws IOException { + private void sendDiagram(final BufferedOutputStream out, final Diagram system, + final FileFormatOption fileFormatOption, final String returnCode, final ImageData imageData, + final byte[] fileData) throws IOException { write(out, "HTTP/1.1 " + returnCode); write(out, "Cache-Control: no-cache"); diff --git a/src/net/sourceforge/plantuml/picoweb/PicoWebServerTest.java b/src/net/sourceforge/plantuml/picoweb/PicoWebServerTest.java index 6696f884d..31242f9c5 100644 --- a/src/net/sourceforge/plantuml/picoweb/PicoWebServerTest.java +++ b/src/net/sourceforge/plantuml/picoweb/PicoWebServerTest.java @@ -248,11 +248,16 @@ public class PicoWebServerTest { } private static String httpRaw(String request) throws Exception { - try (Socket socket = socketConnection()) { + Socket socket = null; + try { + socket = socketConnection(); socket.getOutputStream().write(request.getBytes(UTF_8)); socket.shutdownOutput(); - return readStreamAsString(socket.getInputStream()) - .replaceAll("\r\n", "\n"); + return readStreamAsString(socket.getInputStream()).replaceAll("\r\n", "\n"); + } finally { + if (socket != null) { + socket.close(); + } } } diff --git a/src/net/sourceforge/plantuml/preproc/Sub.java b/src/net/sourceforge/plantuml/preproc/Sub.java index b8095c968..2764ca628 100644 --- a/src/net/sourceforge/plantuml/preproc/Sub.java +++ b/src/net/sourceforge/plantuml/preproc/Sub.java @@ -102,7 +102,6 @@ public class Sub { result.add(s); } } - reader.close(); return result; } diff --git a/src/net/sourceforge/plantuml/sequencediagram/LinkAnchor.java b/src/net/sourceforge/plantuml/sequencediagram/LinkAnchor.java index 38b677d05..c8ad626ef 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/LinkAnchor.java +++ b/src/net/sourceforge/plantuml/sequencediagram/LinkAnchor.java @@ -82,11 +82,10 @@ public class LinkAnchor { public void drawAnchor(UGraphic ug, YPositionedTile tile1, YPositionedTile tile2, ISkinParam param) { - final StringBounder stringBounder = ug.getStringBounder(); - final double y1 = tile1.getY(stringBounder); - final double y2 = tile2.getY(stringBounder); - final double xx1 = tile1.getMiddleX(stringBounder); - final double xx2 = tile2.getMiddleX(stringBounder); + final double y1 = tile1.getY(); + final double y2 = tile2.getY(); + final double xx1 = tile1.getMiddleX(); + final double xx2 = tile2.getMiddleX(); final double x = (xx1 + xx2) / 2; final double ymin = Math.min(y1, y2); final double ymax = Math.max(y1, y2); diff --git a/src/net/sourceforge/plantuml/sequencediagram/Message.java b/src/net/sourceforge/plantuml/sequencediagram/Message.java index 05305ace9..d9a3660b7 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/Message.java +++ b/src/net/sourceforge/plantuml/sequencediagram/Message.java @@ -35,6 +35,9 @@ */ package net.sourceforge.plantuml.sequencediagram; +import java.util.Collections; +import java.util.List; + import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.skin.ArrowConfiguration; import net.sourceforge.plantuml.style.StyleBuilder; @@ -79,4 +82,14 @@ public final class Message extends AbstractMessage { return p1 == p2; } + private List multicast = Collections.emptyList(); + + public void setMulticast(List multicast) { + this.multicast = multicast; + } + + public List getMulticast() { + return multicast; + } + } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandArrow.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandArrow.java index 333931914..09111537b 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandArrow.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandArrow.java @@ -35,6 +35,9 @@ */ package net.sourceforge.plantuml.sequencediagram.command; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.StringTokenizer; import net.sourceforge.plantuml.LineLocation; @@ -48,6 +51,7 @@ import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.IRegex; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexOptional; import net.sourceforge.plantuml.command.regex.RegexOr; import net.sourceforge.plantuml.command.regex.RegexResult; import net.sourceforge.plantuml.cucadiagram.Display; @@ -106,9 +110,10 @@ public class CommandArrow extends SingleLineCommand2 { new RegexLeaf("PART2LONG", "[%g]([^%g]+)[%g]"), // new RegexLeaf("PART2LONGCODE", "[%g]([^%g]+)[%g][%s]*as[%s]+([\\p{L}0-9_.@]+)"), // new RegexLeaf("PART2CODELONG", "([\\p{L}0-9_.@]+)[%s]+as[%s]*[%g]([^%g]+)[%g]")), // + new RegexLeaf("MULTICAST", "((?:\\s&\\s[\\p{L}0-9_.@]+)*)"), // new RegexLeaf("PART2ANCHOR", ANCHOR), // RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("ACTIVATION", "(?:([+*!-]+)?)"), // + new RegexLeaf("ACTIVATION", "(?:(\\+\\+|\\*\\*|!!|--|--\\+\\+|\\+\\+--)?)"), // RegexLeaf.spaceZeroOrMore(), // new RegexLeaf("LIFECOLOR", "(?:(#\\w+)?)"), // RegexLeaf.spaceZeroOrMore(), // @@ -118,6 +123,25 @@ public class CommandArrow extends SingleLineCommand2 { RegexLeaf.end()); } + private List getMulticasts(SequenceDiagram system, RegexResult arg2) { + final String multicast = arg2.get("MULTICAST", 0); + if (multicast != null) { + final List result = new ArrayList(); + for (String s : multicast.split("&")) { + s = s.trim(); + if (s.length() == 0) { + continue; + } + final Participant participant = system.getOrCreateParticipant(s); + if (participant != null) { + result.add(participant); + } + } + return Collections.unmodifiableList(result); + } + return Collections.emptyList(); + } + private Participant getOrCreateParticipant(SequenceDiagram system, RegexResult arg2, String n) { final String code; final Display display; @@ -157,7 +181,8 @@ public class CommandArrow extends SingleLineCommand2 { } @Override - protected CommandExecutionResult executeArg(SequenceDiagram diagram, LineLocation location, RegexResult arg) throws NoSuchColorException { + protected CommandExecutionResult executeArg(SequenceDiagram diagram, LineLocation location, RegexResult arg) + throws NoSuchColorException { Participant p1; Participant p2; @@ -251,6 +276,7 @@ public class CommandArrow extends SingleLineCommand2 { final String messageNumber = diagram.getNextMessageNumber(); final Message msg = new Message(diagram.getSkinParam().getCurrentStyleBuilder(), p1, p2, diagram.manageVariable(labels), config, messageNumber); + msg.setMulticast(getMulticasts(diagram, arg)); final String url = arg.get("URL", 0); if (url != null) { final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); @@ -272,31 +298,44 @@ public class CommandArrow extends SingleLineCommand2 { } final String s = arg.get("LIFECOLOR", 0); - final HColor activationColor = s == null ? null - : diagram.getSkinParam().getIHtmlColorSet().getColor(s); + final HColor activationColor = s == null ? null : diagram.getSkinParam().getIHtmlColorSet().getColor(s); if (activationSpec != null) { - switch (activationSpec.charAt(0)) { + return manageActivations(activationSpec, diagram, p1, p2, activationColor); + } + + if (diagram.isAutoactivate() && (config.getHead() == ArrowHead.NORMAL || config.getHead() == ArrowHead.ASYNC)) { + if (config.isDotted()) { + diagram.activate(p1, LifeEventType.DEACTIVATE, null); + } else { + diagram.activate(p2, LifeEventType.ACTIVATE, activationColor); + } + } + return CommandExecutionResult.ok(); + } + + private CommandExecutionResult manageActivations(String spec, SequenceDiagram diagram, Participant p1, + Participant p2, HColor activationColor) { + switch (spec.charAt(0)) { + case '+': + diagram.activate(p2, LifeEventType.ACTIVATE, activationColor); + break; + case '-': + diagram.activate(p1, LifeEventType.DEACTIVATE, null); + break; + case '!': + diagram.activate(p2, LifeEventType.DESTROY, null); + break; + } + if (spec.length() == 4) { + switch (spec.charAt(2)) { case '+': diagram.activate(p2, LifeEventType.ACTIVATE, activationColor); break; case '-': diagram.activate(p1, LifeEventType.DEACTIVATE, null); break; - case '!': - diagram.activate(p2, LifeEventType.DESTROY, null); - break; - default: - break; } - } else if (diagram.isAutoactivate() - && (config.getHead() == ArrowHead.NORMAL || config.getHead() == ArrowHead.ASYNC)) { - if (config.isDotted()) { - diagram.activate(p1, LifeEventType.DEACTIVATE, null); - } else { - diagram.activate(p2, LifeEventType.ACTIVATE, activationColor); - } - } return CommandExecutionResult.ok(); } @@ -313,7 +352,8 @@ public class CommandArrow extends SingleLineCommand2 { return sa.length() + sb.length(); } - public static ArrowConfiguration applyStyle(String arrowStyle, ArrowConfiguration config) throws NoSuchColorException { + public static ArrowConfiguration applyStyle(String arrowStyle, ArrowConfiguration config) + throws NoSuchColorException { if (arrowStyle == null) { return config; } diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramTxtMaker.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramTxtMaker.java index df18bb5eb..682a30030 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramTxtMaker.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramTxtMaker.java @@ -113,13 +113,13 @@ public class SequenceDiagramTxtMaker implements FileMaker { if (title.isWhite()) { ug2 = ug; } else { - ug2 = (UGraphicTxt) ug.apply(UTranslate.dy(title.as().size() + 1)); + ug2 = (UGraphicTxt) ug.apply(UTranslate.dy(title.asList().size() + 1)); } drawableSet.drawU22(ug2, 0, fullDimension.getWidth(), page, diagram.isShowFootbox()); if (title.isWhite() == false) { final int widthTitle = StringUtils.getWcWidth(title); final UmlCharArea charArea = ug.getCharArea(); - charArea.drawStringsLRSimple(title.as(), (int) ((fullDimension.getWidth() - widthTitle) / 2), 0); + charArea.drawStringsLRSimple(title.asList(), (int) ((fullDimension.getWidth() - widthTitle) / 2), 0); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/AbstractTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/AbstractTile.java index 72f1e4b58..c35be02f3 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/AbstractTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/AbstractTile.java @@ -39,18 +39,22 @@ import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.sequencediagram.AbstractMessage; import net.sourceforge.plantuml.sequencediagram.Event; -public abstract class AbstractTile implements Tile { +public abstract class AbstractTile extends CommonTile implements Tile { - public double getYPoint(StringBounder stringBounder) { - throw new UnsupportedOperationException(getClass().toString()); + public AbstractTile(StringBounder stringBounder) { + super(stringBounder); } - final public double getZ(StringBounder stringBounder) { - final double result = getPreferredHeight(stringBounder) - getYPoint(stringBounder); + public double getContactPointRelative() { + return -1; + } + + final public double getZZZ() { + final double result = getPreferredHeight() - getContactPointRelative(); assert result >= 0; return result; } - + public boolean matchAnchorV1(String anchor) { final Event event = this.getEvent(); if (event instanceof AbstractMessage) { @@ -62,5 +66,4 @@ public abstract class AbstractTile implements Tile { return false; } - } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/Bordered.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/Bordered.java index 4bc5d0d66..13815a30d 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/Bordered.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/Bordered.java @@ -35,7 +35,6 @@ */ package net.sourceforge.plantuml.sequencediagram.teoz; - public interface Bordered { public double getBorder1(); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileWithUpdateStairs.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommonTile.java similarity index 78% rename from src/net/sourceforge/plantuml/sequencediagram/teoz/TileWithUpdateStairs.java rename to src/net/sourceforge/plantuml/sequencediagram/teoz/CommonTile.java index 14a1edb10..7abb4015c 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileWithUpdateStairs.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommonTile.java @@ -37,10 +37,23 @@ package net.sourceforge.plantuml.sequencediagram.teoz; import net.sourceforge.plantuml.graphic.StringBounder; -public interface TileWithUpdateStairs extends Tile { +public abstract class CommonTile implements Tile { - public void updateStairs(StringBounder stringBounder, double y); + private final StringBounder stringBounder; - public double getYPoint(StringBounder stringBounder); + public CommonTile(StringBounder stringBounder) { + this.stringBounder = stringBounder; + } + + final public void callbackY(double y) { + callbackY_internal(y); + } + + public void callbackY_internal(double y) { + } + + protected final StringBounder getStringBounder() { + return stringBounder; + } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationExoTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationExoTile.java index b277feb3a..8455ecc5a 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationExoTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationExoTile.java @@ -54,7 +54,7 @@ import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class CommunicationExoTile extends AbstractTile implements TileWithUpdateStairs { +public class CommunicationExoTile extends AbstractTile { private final LivingSpace livingSpace; private final MessageExo message; @@ -68,6 +68,7 @@ public class CommunicationExoTile extends AbstractTile implements TileWithUpdate public CommunicationExoTile(LivingSpace livingSpace, MessageExo message, Rose skin, ISkinParam skinParam, TileArguments tileArguments) { + super(tileArguments.getStringBounder()); this.tileArguments = tileArguments; this.livingSpace = livingSpace; this.message = message; @@ -76,8 +77,8 @@ public class CommunicationExoTile extends AbstractTile implements TileWithUpdate } @Override - public double getYPoint(StringBounder stringBounder) { - return getComponent(stringBounder).getYPoint(stringBounder); + public double getContactPointRelative() { + return getComponent(getStringBounder()).getYPoint(getStringBounder()); } private ArrowComponent getComponent(StringBounder stringBounder) { @@ -129,9 +130,9 @@ public class CommunicationExoTile extends AbstractTile implements TileWithUpdate return message.isShortArrow(); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); return dim.getHeight(); } @@ -141,15 +142,15 @@ public class CommunicationExoTile extends AbstractTile implements TileWithUpdate return dim.getWidth(); } - public void addConstraints(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public void addConstraints() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); final double width = dim.getWidth(); if (message.getType().isRightBorder()) { } else { - livingSpace.getPosC(stringBounder).ensureBiggerThan(tileArguments.getOrigin().addFixed(width)); + livingSpace.getPosC(getStringBounder()).ensureBiggerThan(tileArguments.getOrigin().addFixed(width)); } // final Real point1 = getPoint1(stringBounder); @@ -165,10 +166,11 @@ public class CommunicationExoTile extends AbstractTile implements TileWithUpdate // } } - public void updateStairs(StringBounder stringBounder, double y) { - final ArrowComponent comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - final double arrowY = comp.getStartPoint(stringBounder, dim).getY(); + @Override + public void callbackY_internal(double y) { + final ArrowComponent comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + final double arrowY = comp.getStartPoint(getStringBounder(), dim).getY(); livingSpace.addStepForLivebox(getEvent(), y + arrowY); @@ -201,15 +203,15 @@ public class CommunicationExoTile extends AbstractTile implements TileWithUpdate return livingSpace.getPosC(stringBounder).getCurrentValue(); } - public Real getMinX(StringBounder stringBounder) { - return getPoint1(stringBounder); + public Real getMinX() { + return getPoint1(getStringBounder()); } - public Real getMaxX(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public Real getMaxX() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); final double width = dim.getWidth(); - return getPoint1(stringBounder).addFixed(width); + return getPoint1(getStringBounder()).addFixed(width); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTile.java index 0efc9b38a..89dd70cf1 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTile.java @@ -39,12 +39,14 @@ import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.LineParam; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.VerticalAlignment; import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.sequencediagram.Message; +import net.sourceforge.plantuml.sequencediagram.Participant; import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.ArrowComponent; import net.sourceforge.plantuml.skin.ArrowConfiguration; @@ -56,10 +58,11 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class CommunicationTile extends AbstractTile implements TileWithUpdateStairs, TileWithCallbackY { +public class CommunicationTile extends AbstractTile { private final LivingSpace livingSpace1; private final LivingSpace livingSpace2; + private final LivingSpaces livingSpaces; private final Message message; private final Rose skin; private final ISkinParam skinParam; @@ -73,13 +76,12 @@ public class CommunicationTile extends AbstractTile implements TileWithUpdateSta return super.toString() + " " + message; } - public CommunicationTile(LivingSpace livingSpace1, LivingSpace livingSpace2, Message message, Rose skin, + public CommunicationTile(StringBounder stringBounder, LivingSpaces livingSpaces, Message message, Rose skin, ISkinParam skinParam) { - if (livingSpace1 == livingSpace2) { - throw new IllegalArgumentException(); - } - this.livingSpace1 = livingSpace1; - this.livingSpace2 = livingSpace2; + super(stringBounder); + this.livingSpace1 = livingSpaces.get(message.getParticipant1()); + this.livingSpace2 = livingSpaces.get(message.getParticipant2()); + this.livingSpaces = livingSpaces; this.message = message; this.skin = skin; this.skinParam = skinParam; @@ -87,11 +89,6 @@ public class CommunicationTile extends AbstractTile implements TileWithUpdateSta if (message.isCreate()) { livingSpace2.goCreate(); } - // for (LifeEvent lifeEvent : message.getLiveEvents()) { - // System.err.println("lifeEvent = " + lifeEvent); - // // livingSpace1.addLifeEvent(this, lifeEvent); - // // livingSpace2.addLifeEvent(this, lifeEvent); - // } } public boolean isReverse(StringBounder stringBounder) { @@ -117,37 +114,45 @@ public class CommunicationTile extends AbstractTile implements TileWithUpdateSta private ArrowComponent getComponent(StringBounder stringBounder) { ArrowConfiguration arrowConfiguration = message.getArrowConfiguration(); - /* - * if (isSelf()) { arrowConfiguration = arrowConfiguration.self(); } else - */ if (isReverse(stringBounder)) { arrowConfiguration = arrowConfiguration.reverse(); } arrowConfiguration = arrowConfiguration.withThickness(getArrowThickness()); - final ArrowComponent comp = skin.createComponentArrow(message.getUsedStyles(), arrowConfiguration, skinParam, + return skin.createComponentArrow(message.getUsedStyles(), arrowConfiguration, skinParam, message.getLabelNumbered()); - return comp; + } + + private ArrowComponent getComponentMulticast(StringBounder stringBounder, boolean reverse) { + ArrowConfiguration arrowConfiguration = message.getArrowConfiguration(); + if (reverse) { + arrowConfiguration = arrowConfiguration.reverse(); + } + arrowConfiguration = arrowConfiguration.withThickness(getArrowThickness()); + + return skin.createComponentArrow(message.getUsedStyles(), arrowConfiguration, skinParam, Display.NULL); } @Override - public double getYPoint(StringBounder stringBounder) { - return getComponent(stringBounder).getYPoint(stringBounder); + public double getContactPointRelative() { + return getComponent(getStringBounder()).getYPoint(getStringBounder()); } public static final double LIVE_DELTA_SIZE = 5; - public void updateStairs(StringBounder stringBounder, double y) { - final AbstractComponentRoseArrow comp = (AbstractComponentRoseArrow) getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - // final Point2D p2 = comp.getEndPoint(stringBounder, dim); - // System.err.println("CommunicationTile::updateStairs y=" + y + " p1=" + p1 + " p2=" + p2 + " dim=" + dim); - final double arrowY = comp.getStartPoint(stringBounder, dim).getY(); + @Override + public void callbackY_internal(double y) { + if (message.isCreate()) { + livingSpace2.goCreate(y); + } + + final AbstractComponentRoseArrow comp = (AbstractComponentRoseArrow) getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + + final double arrowY = comp.getStartPoint(getStringBounder(), dim).getY(); livingSpace1.addStepForLivebox(getEvent(), y + arrowY); livingSpace2.addStepForLivebox(getEvent(), y + arrowY); - - // System.err.println("CommunicationTile::updateStairs msg=" + message + " y=" + y + " arrowY=" + arrowY); } public void drawU(UGraphic ug) { @@ -161,6 +166,7 @@ public class CommunicationTile extends AbstractTile implements TileWithUpdateSta final Dimension2D dim = comp.getPreferredDimension(stringBounder); double x1 = getPoint1(stringBounder).getCurrentValue(); double x2 = getPoint2(stringBounder).getCurrentValue(); + drawMulticast(ug.apply(UTranslate.dy(comp.getPosArrow(stringBounder)))); final Area area; if (isReverse(stringBounder)) { @@ -193,24 +199,45 @@ public class CommunicationTile extends AbstractTile implements TileWithUpdateSta comp.drawU(ug, area, (Context2D) ug); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + private void drawMulticast(final UGraphic ug) { + if (message.getMulticast().size() == 0) { + return; + } + final StringBounder stringBounder = ug.getStringBounder(); + + final double x1 = getPoint1(stringBounder).getCurrentValue(); + double dy = 2; + for (Participant participant : message.getMulticast()) { + final double x2 = livingSpaces.get(participant).getPosC(stringBounder).getCurrentValue(); + final boolean reverse = x2 < x1; + final ArrowComponent comp = getComponentMulticast(stringBounder, reverse); + final Dimension2D dim = comp.getPreferredDimension(stringBounder); + final Area area = new Area(Math.abs(x2 - x1), dim.getHeight()); + final UGraphic ug2 = ug.apply(UTranslate.dx(Math.min(x1, x2))).apply(UTranslate.dy(dy)); + dy += 2; + comp.drawU(ug2, area, (Context2D) ug2); + } + + } + + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); double height = dim.getHeight(); if (isCreate()) { - height = Math.max(height, livingSpace2.getHeadPreferredDimension(stringBounder).getHeight()); + height = Math.max(height, livingSpace2.getHeadPreferredDimension(getStringBounder()).getHeight()); } return height; } - public void addConstraints(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public void addConstraints() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); final double width = dim.getWidth(); - Real point1 = getPoint1(stringBounder); - Real point2 = getPoint2(stringBounder); - if (isReverse(stringBounder)) { + Real point1 = getPoint1(getStringBounder()); + Real point2 = getPoint2(getStringBounder()); + if (isReverse(getStringBounder())) { final int level1 = livingSpace1.getLevelAt(this, EventsHistoryMode.IGNORE_FUTURE_DEACTIVATE); final int level2 = livingSpace2.getLevelAt(this, EventsHistoryMode.IGNORE_FUTURE_DEACTIVATE); if (level1 > 0) { @@ -241,24 +268,18 @@ public class CommunicationTile extends AbstractTile implements TileWithUpdateSta return livingSpace2.getPosC(stringBounder); } - public Real getMinX(StringBounder stringBounder) { - if (isReverse(stringBounder)) { - return getPoint2(stringBounder); + public Real getMinX() { + if (isReverse(getStringBounder())) { + return getPoint2(getStringBounder()); } - return getPoint1(stringBounder); + return getPoint1(getStringBounder()); } - public Real getMaxX(StringBounder stringBounder) { - if (isReverse(stringBounder)) { - return getPoint1(stringBounder); - } - return getPoint2(stringBounder); - } - - public void callbackY(double y) { - if (message.isCreate()) { - livingSpace2.goCreate(y); + public Real getMaxX() { + if (isReverse(getStringBounder())) { + return getPoint1(getStringBounder()); } + return getPoint2(getStringBounder()); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteBottom.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteBottom.java index d323aff3f..7137eb44f 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteBottom.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteBottom.java @@ -55,9 +55,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; -public class CommunicationTileNoteBottom extends AbstractTile implements TileWithUpdateStairs, TileWithCallbackY { +public class CommunicationTileNoteBottom extends AbstractTile { - private final TileWithUpdateStairs tile; + private final Tile tile; private final AbstractMessage message; private final Rose skin; private final ISkinParam skinParam; @@ -68,12 +68,13 @@ public class CommunicationTileNoteBottom extends AbstractTile implements TileWit } @Override - public double getYPoint(StringBounder stringBounder) { - return tile.getYPoint(stringBounder); + public double getContactPointRelative() { + return tile.getContactPointRelative(); } - public CommunicationTileNoteBottom(TileWithUpdateStairs tile, AbstractMessage message, Rose skin, - ISkinParam skinParam, Note noteOnMessage) { + public CommunicationTileNoteBottom(Tile tile, AbstractMessage message, Rose skin, ISkinParam skinParam, + Note noteOnMessage) { + super(((AbstractTile) tile).getStringBounder()); this.tile = tile; this.message = message; this.skin = skin; @@ -81,8 +82,9 @@ public class CommunicationTileNoteBottom extends AbstractTile implements TileWit this.noteOnMessage = noteOnMessage; } - public void updateStairs(StringBounder stringBounder, double y) { - tile.updateStairs(stringBounder, y); + @Override + public void callbackY_internal(double y) { + tile.callbackY(y); } private Component getComponent(StringBounder stringBounder) { @@ -92,7 +94,7 @@ public class CommunicationTileNoteBottom extends AbstractTile implements TileWit } private Real getNotePosition(StringBounder stringBounder) { - final Real minX = tile.getMinX(stringBounder); + final Real minX = tile.getMinX(); return minX; } @@ -103,15 +105,15 @@ public class CommunicationTileNoteBottom extends AbstractTile implements TileWit final Area area = new Area(dim.getWidth(), dim.getHeight()); tile.drawU(ug); - final double middleMsg = (tile.getMinX(stringBounder).getCurrentValue() + tile.getMaxX(stringBounder).getCurrentValue()) / 2; + final double middleMsg = (tile.getMinX().getCurrentValue() + tile.getMaxX().getCurrentValue()) / 2; final double xNote = getNotePosition(stringBounder).getCurrentValue(); - final double yNote = tile.getPreferredHeight(stringBounder); + final double yNote = tile.getPreferredHeight(); comp.drawU(ug.apply(new UTranslate(xNote, yNote + spacey)), area, (Context2D) ug); - drawLine(ug, middleMsg, tile.getYPoint(stringBounder), xNote + dim.getWidth() / 2, yNote + spacey - + Rose.paddingY); + drawLine(ug, middleMsg, tile.getContactPointRelative(), xNote + dim.getWidth() / 2, + yNote + spacey + Rose.paddingY); } @@ -123,33 +125,26 @@ public class CommunicationTileNoteBottom extends AbstractTile implements TileWit final double dx = x2 - x1; final double dy = y2 - y1; - ug.apply(new UTranslate(x1, y1)).apply(color).apply(new UStroke(2, 2, 1)) - .draw(new ULine(dx, dy)); + ug.apply(new UTranslate(x1, y1)).apply(color).apply(new UStroke(2, 2, 1)).draw(new ULine(dx, dy)); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - return tile.getPreferredHeight(stringBounder) + dim.getHeight() + spacey; + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + return tile.getPreferredHeight() + dim.getHeight() + spacey; } - public void addConstraints(StringBounder stringBounder) { - tile.addConstraints(stringBounder); + public void addConstraints() { + tile.addConstraints(); } - public Real getMinX(StringBounder stringBounder) { - return tile.getMinX(stringBounder); + public Real getMinX() { + return tile.getMinX(); } - public Real getMaxX(StringBounder stringBounder) { - return tile.getMaxX(stringBounder); - } - - public void callbackY(double y) { - if (tile instanceof TileWithCallbackY) { - ((TileWithCallbackY) tile).callbackY(y); - } + public Real getMaxX() { + return tile.getMaxX(); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteLeft.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteLeft.java index 96b5cf6bc..960864cf5 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteLeft.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteLeft.java @@ -51,9 +51,9 @@ import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class CommunicationTileNoteLeft extends AbstractTile implements TileWithUpdateStairs, TileWithCallbackY { +public class CommunicationTileNoteLeft extends AbstractTile { - private final TileWithUpdateStairs tile; + private final Tile tile; private final AbstractMessage message; private final Rose skin; private final ISkinParam skinParam; @@ -65,12 +65,13 @@ public class CommunicationTileNoteLeft extends AbstractTile implements TileWithU } @Override - public double getYPoint(StringBounder stringBounder) { - return tile.getYPoint(stringBounder); + public double getContactPointRelative() { + return tile.getContactPointRelative(); } - public CommunicationTileNoteLeft(TileWithUpdateStairs tile, AbstractMessage message, Rose skin, - ISkinParam skinParam, LivingSpace livingSpace, Note noteOnMessage) { + public CommunicationTileNoteLeft(Tile tile, AbstractMessage message, Rose skin, ISkinParam skinParam, + LivingSpace livingSpace, Note noteOnMessage) { + super(((AbstractTile) tile).getStringBounder()); this.tile = tile; this.message = message; this.skin = skin; @@ -79,8 +80,9 @@ public class CommunicationTileNoteLeft extends AbstractTile implements TileWithU this.livingSpace = livingSpace; } - public void updateStairs(StringBounder stringBounder, double y) { - tile.updateStairs(stringBounder, y); + @Override + public void callbackY_internal(double y) { + tile.callbackY(y); } private Component getComponent(StringBounder stringBounder) { @@ -106,28 +108,22 @@ public class CommunicationTileNoteLeft extends AbstractTile implements TileWithU comp.drawU(ug.apply(UTranslate.dx(p.getCurrentValue())), area, (Context2D) ug); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - return Math.max(tile.getPreferredHeight(stringBounder), dim.getHeight()); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + return Math.max(tile.getPreferredHeight(), dim.getHeight()); } - public void addConstraints(StringBounder stringBounder) { - tile.addConstraints(stringBounder); + public void addConstraints() { + tile.addConstraints(); } - public Real getMinX(StringBounder stringBounder) { - return getNotePosition(stringBounder); + public Real getMinX() { + return getNotePosition(getStringBounder()); } - public Real getMaxX(StringBounder stringBounder) { - return tile.getMaxX(stringBounder); - } - - public void callbackY(double y) { - if (tile instanceof TileWithCallbackY) { - ((TileWithCallbackY) tile).callbackY(y); - } + public Real getMaxX() { + return tile.getMaxX(); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteRight.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteRight.java index 9c35dae9f..75bdbf274 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteRight.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteRight.java @@ -51,9 +51,9 @@ import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class CommunicationTileNoteRight extends AbstractTile implements TileWithUpdateStairs, TileWithCallbackY { +public class CommunicationTileNoteRight extends AbstractTile { - private final TileWithUpdateStairs tile; + private final Tile tile; private final AbstractMessage message; private final Rose skin; private final ISkinParam skinParam; @@ -69,12 +69,13 @@ public class CommunicationTileNoteRight extends AbstractTile implements TileWith } @Override - public double getYPoint(StringBounder stringBounder) { - return tile.getYPoint(stringBounder); + public double getContactPointRelative() { + return tile.getContactPointRelative(); } - public CommunicationTileNoteRight(TileWithUpdateStairs tile, AbstractMessage message, Rose skin, - ISkinParam skinParam, LivingSpace livingSpace, Note noteOnMessage) { + public CommunicationTileNoteRight(Tile tile, AbstractMessage message, Rose skin, ISkinParam skinParam, + LivingSpace livingSpace, Note noteOnMessage) { + super(((AbstractTile) tile).getStringBounder()); this.tile = tile; this.message = message; this.skin = skin; @@ -83,8 +84,9 @@ public class CommunicationTileNoteRight extends AbstractTile implements TileWith this.livingSpace = livingSpace; } - public void updateStairs(StringBounder stringBounder, double y) { - tile.updateStairs(stringBounder, y); + @Override + public void callbackY_internal(double y) { + tile.callbackY(y); } private Component getComponent(StringBounder stringBounder) { @@ -114,30 +116,24 @@ public class CommunicationTileNoteRight extends AbstractTile implements TileWith comp.drawU(ug.apply(UTranslate.dx(p.getCurrentValue())), area, (Context2D) ug); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - return Math.max(tile.getPreferredHeight(stringBounder), dim.getHeight()); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + return Math.max(tile.getPreferredHeight(), dim.getHeight()); } - public void addConstraints(StringBounder stringBounder) { - tile.addConstraints(stringBounder); + public void addConstraints() { + tile.addConstraints(); } - public Real getMinX(StringBounder stringBounder) { - return tile.getMinX(stringBounder); + public Real getMinX() { + return tile.getMinX(); } - public Real getMaxX(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - return getNotePosition(stringBounder).addFixed(dim.getWidth()); - } - - public void callbackY(double y) { - if (tile instanceof TileWithCallbackY) { - ((TileWithCallbackY) tile).callbackY(y); - } + public Real getMaxX() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + return getNotePosition(getStringBounder()).addFixed(dim.getWidth()); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteTop.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteTop.java index 2b2152ac2..f8371bbc3 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteTop.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileNoteTop.java @@ -55,9 +55,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; -public class CommunicationTileNoteTop extends AbstractTile implements TileWithUpdateStairs, TileWithCallbackY { +public class CommunicationTileNoteTop extends AbstractTile { - private final TileWithUpdateStairs tile; + private final Tile tile; private final AbstractMessage message; private final Rose skin; private final ISkinParam skinParam; @@ -68,12 +68,13 @@ public class CommunicationTileNoteTop extends AbstractTile implements TileWithUp } @Override - public double getYPoint(StringBounder stringBounder) { - return tile.getYPoint(stringBounder); + public double getContactPointRelative() { + return tile.getContactPointRelative(); } - public CommunicationTileNoteTop(TileWithUpdateStairs tile, AbstractMessage message, Rose skin, - ISkinParam skinParam, Note noteOnMessage) { + public CommunicationTileNoteTop(Tile tile, AbstractMessage message, Rose skin, ISkinParam skinParam, + Note noteOnMessage) { + super(((AbstractTile) tile).getStringBounder()); this.tile = tile; this.message = message; this.skin = skin; @@ -81,8 +82,9 @@ public class CommunicationTileNoteTop extends AbstractTile implements TileWithUp this.noteOnMessage = noteOnMessage; } - public void updateStairs(StringBounder stringBounder, double y) { - tile.updateStairs(stringBounder, y); + @Override + public void callbackY_internal(double y) { + tile.callbackY(y); } private Component getComponent(StringBounder stringBounder) { @@ -92,7 +94,7 @@ public class CommunicationTileNoteTop extends AbstractTile implements TileWithUp } private Real getNotePosition(StringBounder stringBounder) { - final Real minX = tile.getMinX(stringBounder); + final Real minX = tile.getMinX(); return minX; } @@ -104,14 +106,13 @@ public class CommunicationTileNoteTop extends AbstractTile implements TileWithUp tile.drawU(ug.apply(UTranslate.dy(dim.getHeight() + spacey))); - final double middleMsg = (tile.getMinX(stringBounder).getCurrentValue() + tile.getMaxX(stringBounder) - .getCurrentValue()) / 2; + final double middleMsg = (tile.getMinX().getCurrentValue() + tile.getMaxX().getCurrentValue()) / 2; final double xNote = getNotePosition(stringBounder).getCurrentValue(); comp.drawU(ug.apply(UTranslate.dx(xNote)), area, (Context2D) ug); - drawLine(ug, middleMsg, tile.getYPoint(stringBounder) + dim.getHeight() + spacey, xNote + dim.getWidth() / 2, + drawLine(ug, middleMsg, tile.getContactPointRelative() + dim.getHeight() + spacey, xNote + dim.getWidth() / 2, dim.getHeight() - 2 * Rose.paddingY); } @@ -124,33 +125,26 @@ public class CommunicationTileNoteTop extends AbstractTile implements TileWithUp final double dx = x2 - x1; final double dy = y2 - y1; - ug.apply(new UTranslate(x1, y1)).apply(color).apply(new UStroke(2, 2, 1)) - .draw(new ULine(dx, dy)); + ug.apply(new UTranslate(x1, y1)).apply(color).apply(new UStroke(2, 2, 1)).draw(new ULine(dx, dy)); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - return tile.getPreferredHeight(stringBounder) + dim.getHeight() + spacey; + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + return tile.getPreferredHeight() + dim.getHeight() + spacey; } - public void addConstraints(StringBounder stringBounder) { - tile.addConstraints(stringBounder); + public void addConstraints() { + tile.addConstraints(); } - public Real getMinX(StringBounder stringBounder) { - return tile.getMinX(stringBounder); + public Real getMinX() { + return tile.getMinX(); } - public Real getMaxX(StringBounder stringBounder) { - return tile.getMaxX(stringBounder); - } - - public void callbackY(double y) { - if (tile instanceof TileWithCallbackY) { - ((TileWithCallbackY) tile).callbackY(y); - } + public Real getMaxX() { + return tile.getMaxX(); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileSelf.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileSelf.java index 3c959ca0c..c9c1e5cc9 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileSelf.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileSelf.java @@ -54,7 +54,7 @@ import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class CommunicationTileSelf extends AbstractTile implements TileWithUpdateStairs { +public class CommunicationTileSelf extends AbstractTile { private final LivingSpace livingSpace1; private final Message message; @@ -67,12 +67,13 @@ public class CommunicationTileSelf extends AbstractTile implements TileWithUpdat } @Override - public double getYPoint(StringBounder stringBounder) { - return getComponent(stringBounder).getYPoint(stringBounder); + public double getContactPointRelative() { + return getComponent(getStringBounder()).getYPoint(getStringBounder()); } - public CommunicationTileSelf(LivingSpace livingSpace1, Message message, Rose skin, ISkinParam skinParam, - LivingSpaces livingSpaces) { + public CommunicationTileSelf(StringBounder stringBounder, LivingSpace livingSpace1, Message message, Rose skin, + ISkinParam skinParam, LivingSpaces livingSpaces) { + super(stringBounder); this.livingSpace1 = livingSpace1; this.livingSpaces = livingSpaces; this.message = message; @@ -98,11 +99,12 @@ public class CommunicationTileSelf extends AbstractTile implements TileWithUpdat return comp; } - public void updateStairs(StringBounder stringBounder, double y) { - final ArrowComponent comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - final Point2D p1 = comp.getStartPoint(stringBounder, dim); - final Point2D p2 = comp.getEndPoint(stringBounder, dim); + @Override + public void callbackY_internal(double y) { + final ArrowComponent comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + final Point2D p1 = comp.getStartPoint(getStringBounder(), dim); + final Point2D p2 = comp.getEndPoint(getStringBounder(), dim); if (message.isActivate()) { livingSpace1.addStepForLivebox(getEvent(), y + p2.getY()); @@ -139,20 +141,20 @@ public class CommunicationTileSelf extends AbstractTile implements TileWithUpdat comp.drawU(ug, area, (Context2D) ug); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); return dim.getHeight(); } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { // final Component comp = getComponent(stringBounder); // final Dimension2D dim = comp.getPreferredDimension(stringBounder); // final double width = dim.getWidth(); final LivingSpace next = getNext(); if (next != null) { - next.getPosC(stringBounder).ensureBiggerThan(getMaxX(stringBounder)); + next.getPosC(getStringBounder()).ensureBiggerThan(getMaxX()); } } @@ -174,15 +176,15 @@ public class CommunicationTileSelf extends AbstractTile implements TileWithUpdat return livingSpace1.getPosC(stringBounder); } - public Real getMinX(StringBounder stringBounder) { - return getPoint1(stringBounder); + public Real getMinX() { + return getPoint1(getStringBounder()); } - public Real getMaxX(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public Real getMaxX() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); final double width = dim.getWidth(); - return livingSpace1.getPosC2(stringBounder).addFixed(width); + return livingSpace1.getPosC2(getStringBounder()).addFixed(width); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileSelfNoteRight.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileSelfNoteRight.java index 546bcf7cc..4e20330d0 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileSelfNoteRight.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTileSelfNoteRight.java @@ -51,7 +51,7 @@ import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class CommunicationTileSelfNoteRight extends AbstractTile implements TileWithUpdateStairs { +public class CommunicationTileSelfNoteRight extends AbstractTile { private final CommunicationTileSelf tile; private final Message message; @@ -62,14 +62,15 @@ public class CommunicationTileSelfNoteRight extends AbstractTile implements Tile public Event getEvent() { return message; } - + @Override - public double getYPoint(StringBounder stringBounder) { - return tile.getYPoint(stringBounder); + public double getContactPointRelative() { + return tile.getContactPointRelative(); } public CommunicationTileSelfNoteRight(CommunicationTileSelf tile, Message message, Rose skin, ISkinParam skinParam, Note noteOnMessage) { + super(((AbstractTile) tile).getStringBounder()); this.tile = tile; this.message = message; this.skin = skin; @@ -77,18 +78,19 @@ public class CommunicationTileSelfNoteRight extends AbstractTile implements Tile this.noteOnMessage = noteOnMessage; } - public void updateStairs(StringBounder stringBounder, double y) { - tile.updateStairs(stringBounder, y); + @Override + public void callbackY_internal(double y) { + tile.callbackY(y); } private Component getComponent(StringBounder stringBounder) { - final Component comp = skin.createComponent(null, ComponentType.NOTE, - null, noteOnMessage.getSkinParamBackcolored(skinParam), noteOnMessage.getStrings()); + final Component comp = skin.createComponent(null, ComponentType.NOTE, null, + noteOnMessage.getSkinParamBackcolored(skinParam), noteOnMessage.getStrings()); return comp; } private Real getNotePosition(StringBounder stringBounder) { - return tile.getMaxX(stringBounder); + return tile.getMaxX(); } public void drawU(UGraphic ug) { @@ -102,24 +104,24 @@ public class CommunicationTileSelfNoteRight extends AbstractTile implements Tile comp.drawU(ug.apply(UTranslate.dx(p.getCurrentValue())), area, (Context2D) ug); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - return Math.max(tile.getPreferredHeight(stringBounder), dim.getHeight()); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + return Math.max(tile.getPreferredHeight(), dim.getHeight()); } - public void addConstraints(StringBounder stringBounder) { - tile.addConstraints(stringBounder); + public void addConstraints() { + tile.addConstraints(); } - public Real getMinX(StringBounder stringBounder) { - return tile.getMinX(stringBounder); + public Real getMinX() { + return tile.getMinX(); } - public Real getMaxX(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - return getNotePosition(stringBounder).addFixed(dim.getWidth()); + public Real getMaxX() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + return getNotePosition(getStringBounder()).addFixed(dim.getWidth()); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/DelayTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/DelayTile.java index d7e59329c..ba3420141 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/DelayTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/DelayTile.java @@ -49,7 +49,7 @@ import net.sourceforge.plantuml.skin.Context2D; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class DelayTile extends AbstractTile implements Tile, TileWithCallbackY { +public class DelayTile extends AbstractTile implements Tile { private final Delay delay; private final TileArguments tileArguments; @@ -62,11 +62,13 @@ public class DelayTile extends AbstractTile implements Tile, TileWithCallbackY { return delay; } - public void callbackY(double y) { + @Override + public void callbackY_internal(double y) { this.y = y; } public DelayTile(Delay delay, TileArguments tileArguments) { + super(tileArguments.getStringBounder()); this.delay = delay; this.tileArguments = tileArguments; } @@ -102,27 +104,27 @@ public class DelayTile extends AbstractTile implements Tile, TileWithCallbackY { final Area area = new Area(getPreferredWidth(stringBounder), dim.getHeight()); tileArguments.getLivingSpaces().delayOn(y, dim.getHeight()); - ug = ug.apply(UTranslate.dx(getMinX(stringBounder).getCurrentValue())); + ug = ug.apply(UTranslate.dx(getMinX().getCurrentValue())); comp.drawU(ug, area, (Context2D) ug); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); return dim.getHeight(); } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { } - public Real getMinX(StringBounder stringBounder) { - init(stringBounder); - return this.middle.addFixed(-getPreferredWidth(stringBounder) / 2); + public Real getMinX() { + init(getStringBounder()); + return this.middle.addFixed(-getPreferredWidth(getStringBounder()) / 2); } - public Real getMaxX(StringBounder stringBounder) { - init(stringBounder); - return this.middle.addFixed(getPreferredWidth(stringBounder) / 2); + public Real getMaxX() { + init(getStringBounder()); + return this.middle.addFixed(getPreferredWidth(getStringBounder()) / 2); } // private double startingY; diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/DividerTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/DividerTile.java index f7795fb7b..db5411c7a 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/DividerTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/DividerTile.java @@ -63,6 +63,7 @@ public class DividerTile extends AbstractTile implements Tile { } public DividerTile(Divider divider, TileArguments tileArguments) { + super(tileArguments.getStringBounder()); this.tileArguments = tileArguments; this.divider = divider; this.skin = tileArguments.getSkin(); @@ -87,25 +88,25 @@ public class DividerTile extends AbstractTile implements Tile { comp.drawU(ug, area, (Context2D) ug); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); return dim.getHeight(); } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { // final Component comp = getComponent(stringBounder); // final Dimension2D dim = comp.getPreferredDimension(stringBounder); // final double width = dim.getWidth(); } - public Real getMinX(StringBounder stringBounder) { + public Real getMinX() { return origin; } - public Real getMaxX(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public Real getMaxX() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); return origin.addFixed(dim.getWidth()); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/ElseTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/ElseTile.java index fcb6d3391..42c35d104 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/ElseTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/ElseTile.java @@ -49,7 +49,7 @@ import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UGraphic; -public class ElseTile extends AbstractTile implements TileWithCallbackY { +public class ElseTile extends AbstractTile { private final Rose skin; private final ISkinParam skinParam; @@ -61,11 +61,12 @@ public class ElseTile extends AbstractTile implements TileWithCallbackY { } @Override - public double getYPoint(StringBounder stringBounder) { + public double getContactPointRelative() { return 0; } public ElseTile(GroupingLeaf anElse, Rose skin, ISkinParam skinParam, Tile parent) { + super(((AbstractTile) parent).getStringBounder()); this.anElse = anElse; this.skin = skin; this.skinParam = skinParam; @@ -96,14 +97,15 @@ public class ElseTile extends AbstractTile implements TileWithCallbackY { // // final double totalParentHeight = parent.getPreferredHeight(stringBounder); // // height = totalParentHeight - (startingY - y); // // } - // final Area area = new Area(max.getCurrentValue() - min.getCurrentValue(), height); + // final Area area = new Area(max.getCurrentValue() - min.getCurrentValue(), + // height); // ug = ug.apply(new UTranslate(min.getCurrentValue(), 0)); // comp.drawU(ug, area, context); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); double height = dim.getHeight(); if (anElse.getComment() != null) { @@ -112,25 +114,26 @@ public class ElseTile extends AbstractTile implements TileWithCallbackY { return height; } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { // final Component comp = getComponent(stringBounder); // final Dimension2D dim = comp.getPreferredDimension(stringBounder); // final double width = dim.getWidth(); } - public Real getMinX(StringBounder stringBounder) { - return parent.getMinX(stringBounder); + public Real getMinX() { + return parent.getMinX(); } - public Real getMaxX(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); - return getMinX(stringBounder).addFixed(dim.getWidth()); + public Real getMaxX() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); + return getMinX().addFixed(dim.getWidth()); } private double y; - public void callbackY(double y) { + @Override + public void callbackY_internal(double y) { this.y = y; } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/EmptyTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/EmptyTile.java index b13982755..72b424e9e 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/EmptyTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/EmptyTile.java @@ -36,7 +36,6 @@ package net.sourceforge.plantuml.sequencediagram.teoz; import net.sourceforge.plantuml.Url; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.sequencediagram.Participant; @@ -48,6 +47,7 @@ public class EmptyTile extends AbstractTile implements Tile { private final Tile position; public EmptyTile(double height, Tile position) { + super(((AbstractTile) position).getStringBounder()); this.height = height; this.position = position; } @@ -55,19 +55,19 @@ public class EmptyTile extends AbstractTile implements Tile { public void drawU(UGraphic ug) { } - public double getPreferredHeight(StringBounder stringBounder) { + public double getPreferredHeight() { return height; } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { } - public Real getMinX(StringBounder stringBounder) { - return position.getMinX(stringBounder); + public Real getMinX() { + return position.getMinX(); } - public Real getMaxX(StringBounder stringBounder) { - return position.getMaxX(stringBounder); + public Real getMaxX() { + return position.getMaxX(); } public Event getEvent() { diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/Englobers.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/Englobers.java index ce5e8f401..c537118d8 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/Englobers.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/Englobers.java @@ -64,8 +64,8 @@ public class Englobers { pending.add(p); continue; } - pending = Englober.createTeoz(englober, p, tileArguments, tileArguments.getSkinParam() - .getCurrentStyleBuilder()); + pending = Englober.createTeoz(englober, p, tileArguments, + tileArguments.getSkinParam().getCurrentStyleBuilder()); englobers.add(pending); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/EventsHistory.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/EventsHistory.java index f03da25ce..40bebd6e2 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/EventsHistory.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/EventsHistory.java @@ -69,7 +69,8 @@ public class EventsHistory { public int getLevelAt(Event event, EventsHistoryMode mode) { final int result = getLevelAtInternal(event, mode); - // System.err.println("EventsHistory::getLevelAt " + mode + " " + result + " " + event); + // System.err.println("EventsHistory::getLevelAt " + mode + " " + result + " " + + // event); return result; } @@ -181,7 +182,8 @@ public class EventsHistory { int value = 0; for (Event event : events) { final Double position = ys3.get(event); - // System.err.println("EventsHistory::getStairs event=" + event + " position=" + position); + // System.err.println("EventsHistory::getStairs event=" + event + " position=" + + // position); if (position != null) { assert position <= totalHeight : "position=" + position + " totalHeight=" + totalHeight; value = getLevelAt(event, EventsHistoryMode.CONSIDERE_FUTURE_DEACTIVATE); @@ -190,7 +192,8 @@ public class EventsHistory { activateColor); } } - // System.err.println("EventsHistory::getStairs finishing totalHeight=" + totalHeight); + // System.err.println("EventsHistory::getStairs finishing totalHeight=" + + // totalHeight); result.addStep(new StairsPosition(totalHeight, false), value, null); // System.err.println("EventsHistory::getStairs " + p + " result=" + result); return result; diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/GroupingTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/GroupingTile.java index 500f66ab0..b73926b24 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/GroupingTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/GroupingTile.java @@ -59,12 +59,13 @@ import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class GroupingTile extends AbstractTile implements TileWithCallbackY { +public class GroupingTile extends AbstractTile { private static final int EXTERNAL_MARGINX1 = 3; private static final int EXTERNAL_MARGINX2 = 9; private static final int MARGINX = 16; - private static final int MARGINY = 10; + // private static final int MARGINY = 10; + private static final int MARGINY_MAGIC = 20; private List tiles = new ArrayList(); private final Real min; private final Real max; @@ -83,24 +84,27 @@ public class GroupingTile extends AbstractTile implements TileWithCallbackY { } @Override - public double getYPoint(StringBounder stringBounder) { + public double getContactPointRelative() { return 0; } - public GroupingTile(Iterator it, GroupingStart start, TileArguments tileArgumentsBachColorChanged, + public GroupingTile(Iterator it, GroupingStart start, TileArguments tileArgumentsBackColorChanged, TileArguments tileArgumentsOriginal) { + super(tileArgumentsBackColorChanged.getStringBounder()); final StringBounder stringBounder = tileArgumentsOriginal.getStringBounder(); this.start = start; this.display = start.getTitle().equals("group") ? Display.create(start.getComment()) : Display.create(start.getTitle(), start.getComment()); this.skin = tileArgumentsOriginal.getSkin(); // this.skinParam = tileArgumentsOriginal.getSkinParam(); - this.skinParam = tileArgumentsBachColorChanged.getSkinParam(); + this.skinParam = tileArgumentsBackColorChanged.getSkinParam(); final List min2 = new ArrayList(); final List max2 = new ArrayList(); final List allElses = new ArrayList(); + final Dimension2D dim1 = getPreferredDimensionIfEmpty(stringBounder); + while (it.hasNext()) { final Event ev = it.next(); if (ev instanceof GroupingLeaf && ((Grouping) ev).getType() == GroupingType.END) { @@ -110,31 +114,31 @@ public class GroupingTile extends AbstractTile implements TileWithCallbackY { tiles.add(tile); } } - tiles = mergeParallel(tiles); + + tiles = mergeParallel(getStringBounder(), tiles); + for (Tile tile : tiles) { - bodyHeight += tile.getPreferredHeight(stringBounder); + bodyHeight += tile.getPreferredHeight(); final Event ev = tile.getEvent(); if (ev instanceof GroupingLeaf && ((Grouping) ev).getType() == GroupingType.ELSE) { allElses.add(tile); continue; } - min2.add(tile.getMinX(stringBounder).addFixed(-MARGINX)); - final Real m = tile.getMaxX(stringBounder); + min2.add(tile.getMinX().addFixed(-MARGINX)); + final Real m = tile.getMaxX(); // max2.add(m == tileArgumentsOriginal.getOmega() ? m : m.addFixed(MARGINX)); max2.add(m.addFixed(MARGINX)); } - final Dimension2D dim1 = getPreferredDimensionIfEmpty(stringBounder); final double width = dim1.getWidth(); if (min2.size() == 0) { min2.add(tileArgumentsOriginal.getOrigin()); } this.min = RealUtils.min(min2); for (Tile anElse : allElses) { - max2.add(anElse.getMaxX(stringBounder)); + max2.add(anElse.getMaxX()); } max2.add(this.min.addFixed(width + 16)); this.max = RealUtils.max(max2); - } private Component getComponent(StringBounder stringBounder) { @@ -154,36 +158,31 @@ public class GroupingTile extends AbstractTile implements TileWithCallbackY { final Dimension2D dim1 = getPreferredDimensionIfEmpty(stringBounder); final Area area = new Area(max.getCurrentValue() - min.getCurrentValue(), getTotalHeight(stringBounder)); - if (ug instanceof LiveBoxFinder == false) { - comp.drawU(ug.apply(UTranslate.dx(min.getCurrentValue())), area, (Context2D) ug); - drawAllElses(ug); - } - // ug.apply(UChangeBackColor.nnn(HtmlColorUtils.LIGHT_GRAY)).draw(new - // URectangle(area.getDimensionToUse())); + comp.drawU(ug.apply(UTranslate.dx(min.getCurrentValue())), area, (Context2D) ug); + drawAllElses(ug); - double h = dim1.getHeight() + MARGINY / 2; + double h = dim1.getHeight() + MARGINY_MAGIC / 2; for (Tile tile : tiles) { - ug.apply(UTranslate.dy(h)).draw(tile); - final double preferredHeight = tile.getPreferredHeight(stringBounder); + tile.drawU(ug.apply(UTranslate.dy(h))); + final double preferredHeight = tile.getPreferredHeight(); h += preferredHeight; } } private double getTotalHeight(StringBounder stringBounder) { final Dimension2D dimIfEmpty = getPreferredDimensionIfEmpty(stringBounder); - return bodyHeight + dimIfEmpty.getHeight() + MARGINY / 2; + return bodyHeight + dimIfEmpty.getHeight() + MARGINY_MAGIC / 2; } private void drawAllElses(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); final double totalHeight = getTotalHeight(stringBounder); - // final double suppHeight = - // getPreferredDimensionIfEmpty(stringBounder).getHeight() + MARGINY / 2; + final List ys = new ArrayList(); for (Tile tile : tiles) { if (tile instanceof ElseTile) { final ElseTile elseTile = (ElseTile) tile; - ys.add(elseTile.getCallbackY() - y + MARGINY / 2/* suppHeight */); + ys.add(elseTile.getCallbackY() - y + MARGINY_MAGIC / 2); } } ys.add(totalHeight); @@ -199,34 +198,35 @@ public class GroupingTile extends AbstractTile implements TileWithCallbackY { } } - public double getPreferredHeight(StringBounder stringBounder) { - final Dimension2D dim1 = getPreferredDimensionIfEmpty(stringBounder); - return dim1.getHeight() + bodyHeight + MARGINY; + public double getPreferredHeight() { + final Dimension2D dim1 = getPreferredDimensionIfEmpty(getStringBounder()); + return dim1.getHeight() + bodyHeight + MARGINY_MAGIC; } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { for (Tile tile : tiles) { - tile.addConstraints(stringBounder); + tile.addConstraints(); } } - public Real getMinX(StringBounder stringBounder) { + public Real getMinX() { return min.addFixed(-EXTERNAL_MARGINX1); } - public Real getMaxX(StringBounder stringBounder) { + public Real getMaxX() { return max.addFixed(EXTERNAL_MARGINX2); } private double y; - public void callbackY(double y) { + @Override + public void callbackY_internal(double y) { this.y = y; } public static double fillPositionelTiles(StringBounder stringBounder, double y, List tiles, final List local, List full) { - for (Tile tile : mergeParallel(tiles)) { + for (Tile tile : mergeParallel(stringBounder, tiles)) { final YPositionedTile ytile = new YPositionedTile(tile, y); local.add(ytile); full.add(ytile); @@ -236,7 +236,7 @@ public class GroupingTile extends AbstractTile implements TileWithCallbackY { final ArrayList local2 = new ArrayList(); fillPositionelTiles(stringBounder, y + headerHeight, groupingTile.tiles, local2, full); } - y += tile.getPreferredHeight(stringBounder); + y += tile.getPreferredHeight(); } return y; @@ -246,14 +246,14 @@ public class GroupingTile extends AbstractTile implements TileWithCallbackY { return getPreferredDimensionIfEmpty(stringBounder).getHeight() + 10; } - private static List mergeParallel(List tiles) { + private static List mergeParallel(StringBounder stringBounder, List tiles) { TileParallel pending = null; tiles = removeEmptyCloseToParallel(tiles); final List result = new ArrayList(); for (Tile tile : tiles) { if (isParallel(tile)) { if (pending == null) { - pending = new TileParallel(); + pending = new TileParallel(stringBounder); final Tile tmp = result.get(result.size() - 1); if (tmp instanceof LifeEventTile) { pending.add(result.get(result.size() - 2)); @@ -293,7 +293,7 @@ public class GroupingTile extends AbstractTile implements TileWithCallbackY { } } - private static boolean isParallel(Tile tile) { + public static boolean isParallel(Tile tile) { return tile instanceof TileParallel == false && tile.getEvent().isParallel(); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/HSpaceTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/HSpaceTile.java index 818f19a3a..7e02df7c5 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/HSpaceTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/HSpaceTile.java @@ -35,7 +35,6 @@ */ package net.sourceforge.plantuml.sequencediagram.teoz; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.sequencediagram.HSpace; @@ -51,6 +50,7 @@ public class HSpaceTile extends AbstractTile implements Tile { } public HSpaceTile(HSpace hspace, TileArguments tileArguments) { + super(tileArguments.getStringBounder()); this.hspace = hspace; this.origin = tileArguments.getOrigin(); } @@ -58,18 +58,18 @@ public class HSpaceTile extends AbstractTile implements Tile { public void drawU(UGraphic ug) { } - public double getPreferredHeight(StringBounder stringBounder) { + public double getPreferredHeight() { return hspace.getPixel(); } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { } - public Real getMinX(StringBounder stringBounder) { + public Real getMinX() { return origin; } - public Real getMaxX(StringBounder stringBounder) { + public Real getMaxX() { return origin.addFixed(10); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/LifeEventTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/LifeEventTile.java index 5ed13a66d..ad1bd3613 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/LifeEventTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/LifeEventTile.java @@ -38,7 +38,6 @@ package net.sourceforge.plantuml.sequencediagram.teoz; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.real.RealUtils; import net.sourceforge.plantuml.sequencediagram.Event; @@ -51,7 +50,7 @@ import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class LifeEventTile extends AbstractTile implements TileWithUpdateStairs { +public class LifeEventTile extends AbstractTile { private final LifeEvent lifeEvent; private final TileArguments tileArguments; @@ -59,22 +58,25 @@ public class LifeEventTile extends AbstractTile implements TileWithUpdateStairs private final Rose skin; private final ISkinParam skinParam; - public void updateStairs(StringBounder stringBounder, double y) { - // System.err.println("LifeEventTile::updateStairs " + lifeEvent + " " + livingSpace.getParticipant() + " y=" + y); + @Override + public void callbackY_internal(double y) { + // System.err.println("LifeEventTile::updateStairs " + lifeEvent + " " + + // livingSpace.getParticipant() + " y=" + y); livingSpace.addStepForLivebox(getEvent(), y); } public Event getEvent() { return lifeEvent; } - + @Override - public double getYPoint(StringBounder stringBounder) { + public double getContactPointRelative() { return 0; } public LifeEventTile(LifeEvent lifeEvent, TileArguments tileArguments, LivingSpace livingSpace, Rose skin, ISkinParam skinParam) { + super(tileArguments.getStringBounder()); this.lifeEvent = lifeEvent; this.tileArguments = tileArguments; this.livingSpace = livingSpace; @@ -95,29 +97,30 @@ public class LifeEventTile extends AbstractTile implements TileWithUpdateStairs return lifeEvent.getMessage() == null && lifeEvent.getType() == LifeEventType.DESTROY; } - public double getPreferredHeight(StringBounder stringBounder) { + public double getPreferredHeight() { // if (lifeEvent.isActivate()) { // return 20; // } if (isDestroyWithoutMessage()) { final Component cross = skin.createComponent(null, ComponentType.DESTROY, null, skinParam, null); - final Dimension2D dimCross = cross.getPreferredDimension(stringBounder); + final Dimension2D dimCross = cross.getPreferredDimension(getStringBounder()); return dimCross.getHeight(); } return 0; } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { } - public Real getMinX(StringBounder stringBounder) { + public Real getMinX() { // return tileArguments.getLivingSpace(lifeEvent.getParticipant()).getPosB(); return livingSpace.getPosB(); } - public Real getMaxX(StringBounder stringBounder) { - // final LivingSpace livingSpace2 = tileArguments.getLivingSpace(lifeEvent.getParticipant()); - return RealUtils.max(livingSpace.getPosD(stringBounder), livingSpace.getPosC2(stringBounder)); + public Real getMaxX() { + // final LivingSpace livingSpace2 = + // tileArguments.getLivingSpace(lifeEvent.getParticipant()); + return RealUtils.max(livingSpace.getPosD(getStringBounder()), livingSpace.getPosC2(getStringBounder())); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/LiveBoxFinder.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/LiveBoxFinder.java deleted file mode 100644 index 50ef30d5a..000000000 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/LiveBoxFinder.java +++ /dev/null @@ -1,127 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009-2020, Arnaud Roques - * - * Project Info: http://plantuml.com - * - * 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 - * - * 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.sequencediagram.teoz; - -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.ugraphic.UBackground; -import net.sourceforge.plantuml.ugraphic.UChange; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.UGraphicNo; -import net.sourceforge.plantuml.ugraphic.UParam; -import net.sourceforge.plantuml.ugraphic.UParamNull; -import net.sourceforge.plantuml.ugraphic.UShape; -import net.sourceforge.plantuml.ugraphic.UStroke; -import net.sourceforge.plantuml.ugraphic.UTranslate; -import net.sourceforge.plantuml.ugraphic.color.ColorMapper; -import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity; -import net.sourceforge.plantuml.ugraphic.color.HColor; - -public class LiveBoxFinder extends UGraphicNo implements UGraphic { - - public boolean matchesProperty(String propertyName) { - return false; - } - - public double dpiFactor() { - return 1; - } - - public UGraphic apply(UChange change) { - if (change instanceof UTranslate) { - return new LiveBoxFinder(stringBounder, translate.compose((UTranslate) change)); - } else if (change instanceof UStroke) { - return new LiveBoxFinder(this); - } else if (change instanceof UBackground) { - return new LiveBoxFinder(this); - } else if (change instanceof HColor) { - return new LiveBoxFinder(this); - } - throw new UnsupportedOperationException(); - } - - private final StringBounder stringBounder; - private final UTranslate translate; - - public LiveBoxFinder(StringBounder stringBounder) { - this(stringBounder, new UTranslate()); - } - - private LiveBoxFinder(StringBounder stringBounder, UTranslate translate) { - this.stringBounder = stringBounder; - this.translate = translate; - } - - private LiveBoxFinder(LiveBoxFinder other) { - this(other.stringBounder, other.translate); - } - - public StringBounder getStringBounder() { - return stringBounder; - } - - public UParam getParam() { - return new UParamNull(); - } - - public void draw(UShape shape) { - final double x = translate.getDx(); - final double y = translate.getDy(); - if (shape instanceof GroupingTile) { - ((GroupingTile) shape).drawU(this); - } else if (shape instanceof TileWithUpdateStairs) { - ((TileWithUpdateStairs) shape).updateStairs(stringBounder, y); - // } else if (shape instanceof EmptyTile) { - // // Nothing ? - // } else if (shape instanceof TileParallel) { - // // Nothing ? - // } else if (shape instanceof NotesTile) { - // // Nothing ? - // } else if (shape instanceof Tile) { - // Log.info("OtherTile " + shape); - } else { - // Nothing ? - // throw new UnsupportedOperationException(shape.getClass().getName()); - } - } - - public ColorMapper getColorMapper() { - return new ColorMapperIdentity(); - } - - public void flushUg() { - } - -} diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/LiveBoxesDrawer.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/LiveBoxesDrawer.java index 8f6866133..36e7df992 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/LiveBoxesDrawer.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/LiveBoxesDrawer.java @@ -68,10 +68,13 @@ public class LiveBoxesDrawer { private final Collection delays; public LiveBoxesDrawer(Context2D context, Rose skin, ISkinParam skinParam, Map delays) { - this.cross = skin.createComponent(new Style[] { ComponentType.DESTROY.getDefaultStyleDefinition() - .getMergedStyle(skinParam.getCurrentStyleBuilder()) }, ComponentType.DESTROY, null, skinParam, null); - this.compForWidth = skin.createComponent(new Style[] { ComponentType.ALIVE_BOX_CLOSE_CLOSE - .getDefaultStyleDefinition().getMergedStyle(skinParam.getCurrentStyleBuilder()) }, + this.cross = skin.createComponent( + new Style[] { ComponentType.DESTROY.getDefaultStyleDefinition() + .getMergedStyle(skinParam.getCurrentStyleBuilder()) }, + ComponentType.DESTROY, null, skinParam, null); + this.compForWidth = skin.createComponent( + new Style[] { ComponentType.ALIVE_BOX_CLOSE_CLOSE.getDefaultStyleDefinition() + .getMergedStyle(skinParam.getCurrentStyleBuilder()) }, ComponentType.ALIVE_BOX_CLOSE_CLOSE, null, skinParam, null); this.context = context; this.skin = skin; @@ -121,8 +124,8 @@ public class LiveBoxesDrawer { private void drawInternal(UGraphic ug, StairsPosition yposition, double ya, double yb, ComponentType type) { final double width = getWidth(ug.getStringBounder()); final Area area = new Area(width, yb - ya); - ISkinParam skinParam2 = new SkinParamBackcolored(skinParam, symbolContext == null ? null - : symbolContext.getBackColor()); + ISkinParam skinParam2 = new SkinParamBackcolored(skinParam, + symbolContext == null ? null : symbolContext.getBackColor()); Style style = type.getDefaultStyleDefinition().getMergedStyle(skinParam.getCurrentStyleBuilder()); if (style != null) { style = style.eventuallyOverride(symbolContext); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/NewpageTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/NewpageTile.java index 81b72c67a..f287336ee 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/NewpageTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/NewpageTile.java @@ -35,23 +35,23 @@ */ package net.sourceforge.plantuml.sequencediagram.teoz; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.sequencediagram.Newpage; import net.sourceforge.plantuml.ugraphic.UGraphic; -public class NewpageTile extends AbstractTile implements TileWithCallbackY { +public class NewpageTile extends AbstractTile { private final Newpage newpage; private final TileArguments tileArguments; @Override - public double getYPoint(StringBounder stringBounder) { + public double getContactPointRelative() { return 0; } public NewpageTile(Newpage newpage, TileArguments tileArguments) { + super(tileArguments.getStringBounder()); this.newpage = newpage; this.tileArguments = tileArguments; } @@ -59,24 +59,25 @@ public class NewpageTile extends AbstractTile implements TileWithCallbackY { public void drawU(UGraphic ug) { } - public double getPreferredHeight(StringBounder stringBounder) { + public double getPreferredHeight() { return 0; } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { } - public Real getMinX(StringBounder stringBounder) { + public Real getMinX() { return tileArguments.getOrigin(); } - public Real getMaxX(StringBounder stringBounder) { + public Real getMaxX() { return tileArguments.getOrigin(); } private double y; - public void callbackY(double y) { + @Override + public void callbackY_internal(double y) { this.y = y; } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/NoteTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/NoteTile.java index 17348cc28..12bd884aa 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/NoteTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/NoteTile.java @@ -66,11 +66,13 @@ public class NoteTile extends AbstractTile implements Tile { } @Override - public double getYPoint(StringBounder stringBounder) { - return getComponent(stringBounder).getPreferredHeight(stringBounder) / 2; + public double getContactPointRelative() { + return getComponent(getStringBounder()).getPreferredHeight(getStringBounder()) / 2; } - public NoteTile(LivingSpace livingSpace1, LivingSpace livingSpace2, Note note, Rose skin, ISkinParam skinParam) { + public NoteTile(StringBounder stringBounder, LivingSpace livingSpace1, LivingSpace livingSpace2, Note note, + Rose skin, ISkinParam skinParam) { + super(stringBounder); this.livingSpace1 = livingSpace1; this.livingSpace2 = livingSpace2; this.note = note; @@ -140,20 +142,20 @@ public class NoteTile extends AbstractTile implements Tile { } } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); return dim.getHeight(); } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { // final Component comp = getComponent(stringBounder); // final Dimension2D dim = comp.getPreferredDimension(stringBounder); // final double width = dim.getWidth(); } - public Real getMinX(StringBounder stringBounder) { - final Real result = getX(stringBounder); + public Real getMinX() { + final Real result = getX(getStringBounder()); if (note.getPosition() == NotePosition.OVER_SEVERAL) { final Real x1 = livingSpace1.getPosB(); return RealUtils.min(result, x1); @@ -161,10 +163,10 @@ public class NoteTile extends AbstractTile implements Tile { return result; } - public Real getMaxX(StringBounder stringBounder) { - final Real result = getX(stringBounder).addFixed(getUsedWidth(stringBounder)); + public Real getMaxX() { + final Real result = getX(getStringBounder()).addFixed(getUsedWidth(getStringBounder())); if (note.getPosition() == NotePosition.OVER_SEVERAL) { - final Real x2 = livingSpace2.getPosD(stringBounder); + final Real x2 = livingSpace2.getPosD(getStringBounder()); return RealUtils.max(result, x2); } return result; diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/NotesTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/NotesTile.java index e85f37948..9752edc73 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/NotesTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/NotesTile.java @@ -67,7 +67,9 @@ public class NotesTile extends AbstractTile implements Tile { return notes; } - public NotesTile(LivingSpaces livingSpaces, Notes notes, Rose skin, ISkinParam skinParam) { + public NotesTile(StringBounder stringBounder, LivingSpaces livingSpaces, Notes notes, Rose skin, + ISkinParam skinParam) { + super(stringBounder); this.livingSpaces = livingSpaces; this.notes = notes; this.skin = skin; @@ -138,39 +140,39 @@ public class NotesTile extends AbstractTile implements Tile { } } - public double getPreferredHeight(StringBounder stringBounder) { + public double getPreferredHeight() { double result = 0; for (Note note : notes) { - final Component comp = getComponent(stringBounder, note); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + final Component comp = getComponent(getStringBounder(), note); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); result = Math.max(result, dim.getHeight()); } return result; } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { final List all = notes.asList(); for (int i = 0; i < all.size() - 1; i++) { for (int j = i + 1; j < all.size(); j++) { - final double center1 = getXcenter(stringBounder, all.get(i)).getCurrentValue(); - final double center2 = getXcenter(stringBounder, all.get(j)).getCurrentValue(); + final double center1 = getXcenter(getStringBounder(), all.get(i)).getCurrentValue(); + final double center2 = getXcenter(getStringBounder(), all.get(j)).getCurrentValue(); if (center2 > center1) { - final Real point1b = getX2(stringBounder, all.get(i)); - final Real point2 = getX(stringBounder, all.get(j)); + final Real point1b = getX2(getStringBounder(), all.get(i)); + final Real point2 = getX(getStringBounder(), all.get(j)); point2.ensureBiggerThan(point1b); } else { - final Real point1 = getX(stringBounder, all.get(i)); - final Real point2b = getX2(stringBounder, all.get(j)); + final Real point1 = getX(getStringBounder(), all.get(i)); + final Real point2b = getX2(getStringBounder(), all.get(j)); point1.ensureBiggerThan(point2b); } } } } - public Real getMinX(StringBounder stringBounder) { + public Real getMinX() { final List reals = new ArrayList(); for (Note note : notes) { - reals.add(getX(stringBounder, note)); + reals.add(getX(getStringBounder(), note)); } return RealUtils.min(reals); } @@ -179,10 +181,10 @@ public class NotesTile extends AbstractTile implements Tile { return getX(stringBounder, note).addFixed(getUsedWidth(stringBounder, note)); } - public Real getMaxX(StringBounder stringBounder) { + public Real getMaxX() { final List reals = new ArrayList(); for (Note note : notes) { - reals.add(getX2(stringBounder, note)); + reals.add(getX2(getStringBounder(), note)); } return RealUtils.max(reals); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/PlayingSpace.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/PlayingSpace.java index 8986a1bc7..1578fc61f 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/PlayingSpace.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/PlayingSpace.java @@ -79,8 +79,8 @@ public class PlayingSpace implements Bordered { tiles.addAll(TileBuilder.buildSeveral(diagram.events().iterator(), tileArguments, null)); for (Tile tile : tiles) { - min2.add(tile.getMinX(tileArguments.getStringBounder())); - max2.add(tile.getMaxX(tileArguments.getStringBounder())); + min2.add(tile.getMinX()); + max2.add(tile.getMaxX()); } for (LivingSpace livingSpace : livingSpaces.values()) { @@ -95,10 +95,6 @@ public class PlayingSpace implements Bordered { } public void drawBackground(UGraphic ug) { - final StringBounder stringBounder = ug.getStringBounder(); - final LiveBoxFinder liveBoxFinder = new LiveBoxFinder(stringBounder); - - drawUInternal(liveBoxFinder, false); final UGraphicInterceptorTile interceptor = new UGraphicInterceptorTile(ug, true); drawUInternal(interceptor, false); } @@ -146,9 +142,9 @@ public class PlayingSpace implements Bordered { return result; } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { for (Tile tile : tiles) { - tile.addConstraints(stringBounder); + tile.addConstraints(); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/PlayingSpaceWithParticipants.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/PlayingSpaceWithParticipants.java index 3c8f800b2..468bbc692 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/PlayingSpaceWithParticipants.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/PlayingSpaceWithParticipants.java @@ -72,8 +72,8 @@ public class PlayingSpaceWithParticipants extends AbstractTextBlock implements T - playingSpace.getMinX(stringBounder).getCurrentValue(); final int factor = playingSpace.isShowFootbox() ? 2 : 1; - final double height = playingSpace.getPreferredHeight(stringBounder) + factor - * playingSpace.getLivingSpaces().getHeadHeight(stringBounder); + final double height = playingSpace.getPreferredHeight(stringBounder) + + factor * playingSpace.getLivingSpaces().getHeadHeight(stringBounder); cacheDimension = new Dimension2DDouble(width, height); } @@ -106,7 +106,8 @@ public class PlayingSpaceWithParticipants extends AbstractTextBlock implements T playingSpace.drawForeground(ug.apply(UTranslate.dy(headHeight))); } else { final UClip clip = new UClip(-1000, ymin, Double.MAX_VALUE, ymax - ymin + 1); - // playingSpace.drawForeground(new UGraphicNewpages(ug.apply(UTranslate.dy(headHeight)), ymin, ymax)); + // playingSpace.drawForeground(new + // UGraphicNewpages(ug.apply(UTranslate.dy(headHeight)), ymin, ymax)); playingSpace.drawForeground(ug.apply(UTranslate.dy(headHeight)).apply(clip)); } // drawNewPages(ug.apply(UTranslate.dy(headHeight))); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/ReferenceTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/ReferenceTile.java index 39bb1e6e7..b04a9cf1b 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/ReferenceTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/ReferenceTile.java @@ -62,6 +62,7 @@ public class ReferenceTile extends AbstractTile implements Tile { } public ReferenceTile(Reference reference, TileArguments tileArguments) { + super(tileArguments.getStringBounder()); this.reference = reference; this.tileArguments = tileArguments; } @@ -94,8 +95,8 @@ public class ReferenceTile extends AbstractTile implements Tile { strings = strings.add("ref"); strings = strings.addAll(reference.getStrings()); - final Component comp = tileArguments.getSkin().createComponent(null, ComponentType.REFERENCE, - null, tileArguments.getSkinParam(), strings); + final Component comp = tileArguments.getSkin().createComponent(null, ComponentType.REFERENCE, null, + tileArguments.getSkinParam(), strings); return comp; } @@ -110,22 +111,22 @@ public class ReferenceTile extends AbstractTile implements Tile { comp.drawU(ug, area, (Context2D) ug); } - public double getPreferredHeight(StringBounder stringBounder) { - final Component comp = getComponent(stringBounder); - final Dimension2D dim = comp.getPreferredDimension(stringBounder); + public double getPreferredHeight() { + final Component comp = getComponent(getStringBounder()); + final Dimension2D dim = comp.getPreferredDimension(getStringBounder()); return dim.getHeight(); } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { } - public Real getMinX(StringBounder stringBounder) { - init(stringBounder); + public Real getMinX() { + init(getStringBounder()); return this.first; } - public Real getMaxX(StringBounder stringBounder) { - init(stringBounder); + public Real getMaxX() { + init(getStringBounder()); return this.last; } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/SequenceDiagramFileMakerTeoz.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/SequenceDiagramFileMakerTeoz.java index ccbbdfc76..bf25878d4 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/SequenceDiagramFileMakerTeoz.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/SequenceDiagramFileMakerTeoz.java @@ -227,7 +227,7 @@ public class SequenceDiagramFileMakerTeoz implements FileMaker { this.englobers = new Englobers(tileArguments); final PlayingSpace mainTile = new PlayingSpace(diagram, englobers, tileArguments); this.livingSpaces.addConstraints(stringBounder); - mainTile.addConstraints(stringBounder); + mainTile.addConstraints(); this.englobers.addConstraints(stringBounder); origin.compileNow(); tileArguments.setBordered(mainTile); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/Stairs2.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/Stairs2.java index b80dff41b..8ec3634bd 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/Stairs2.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/Stairs2.java @@ -58,7 +58,8 @@ public class Stairs2 { if (value < 0) { throw new IllegalArgumentException(); } - // System.err.println("Stairs2::addStep " + position + " " + value + " color=" + color); + // System.err.println("Stairs2::addStep " + position + " " + value + " color=" + + // color); assert ys.size() == values.size(); if (ys.size() > 0) { final double lastY = ys.get(ys.size() - 1).getValue(); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/Tile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/Tile.java index 447d71c49..e72797b74 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/Tile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/Tile.java @@ -35,29 +35,27 @@ */ package net.sourceforge.plantuml.sequencediagram.teoz; -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.UDrawable; import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.sequencediagram.Event; -import net.sourceforge.plantuml.ugraphic.UShape; -public interface Tile extends UDrawable, UShape { +public interface Tile extends Tile2 { - public double getPreferredHeight(StringBounder stringBounder); + public double getPreferredHeight(); - public void addConstraints(StringBounder stringBounder); + public void callbackY(double y); - public Real getMinX(StringBounder stringBounder); + public void addConstraints(); - public Real getMaxX(StringBounder stringBounder); + public Real getMinX(); + + public Real getMaxX(); public Event getEvent(); - public double getYPoint(StringBounder stringBounder); + public double getContactPointRelative(); + + public double getZZZ(); - public double getZ(StringBounder stringBounder); - public boolean matchAnchorV1(String anchor); - } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileWithCallbackY.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/Tile2.java similarity index 93% rename from src/net/sourceforge/plantuml/sequencediagram/teoz/TileWithCallbackY.java rename to src/net/sourceforge/plantuml/sequencediagram/teoz/Tile2.java index 2e24e8b76..34f2b39dc 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileWithCallbackY.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/Tile2.java @@ -35,8 +35,8 @@ */ package net.sourceforge.plantuml.sequencediagram.teoz; +import net.sourceforge.plantuml.graphic.UDrawable; -public interface TileWithCallbackY extends Tile { +public interface Tile2 extends UDrawable { - public void callbackY(double y); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileArguments.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/TileArguments.java index c658416df..158aefe2f 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileArguments.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/TileArguments.java @@ -62,8 +62,8 @@ public class TileArguments implements Bordered { } public TileArguments withBackColorGeneral(HColor backColorElement, HColor backColorGeneral) { - return new TileArguments(stringBounder, livingSpaces, skin, new SkinParamBackcolored(skinParam, - backColorElement, backColorGeneral), origin); + return new TileArguments(stringBounder, livingSpaces, skin, + new SkinParamBackcolored(skinParam, backColorElement, backColorGeneral), origin); } public TileArguments withBackColor(Reference reference) { diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileBuilder.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/TileBuilder.java index 4c703a64b..cd5d2b693 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileBuilder.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/TileBuilder.java @@ -68,7 +68,7 @@ public class TileBuilder { final Event ev = it.next(); for (Tile tile : TileBuilder.buildOne(it, tileArguments, ev, parent)) { tiles.add(tile); - final Real tmpMax = tile.getMaxX(tileArguments.getStringBounder()); + final Real tmpMax = tile.getMaxX(); } } return Collections.unmodifiableList(tiles); @@ -90,29 +90,27 @@ public class TileBuilder { boolean reverse = false; Tile result = null; if (msg.isSelfMessage()) { - result = new CommunicationTileSelf(livingSpace1, msg, skin, skinParam, livingSpaces); + result = new CommunicationTileSelf(tileArguments.getStringBounder(), livingSpace1, msg, skin, skinParam, + livingSpaces); } else { - // System.err.println("msg=" + msg); - result = new CommunicationTile(livingSpace1, livingSpace2, msg, skin, skinParam); + result = new CommunicationTile(tileArguments.getStringBounder(), livingSpaces, msg, skin, skinParam); reverse = ((CommunicationTile) result).isReverse(stringBounder); } for (Note noteOnMessage : msg.getNoteOnMessages()) { final NotePosition notePosition = noteOnMessage.getPosition(); if (notePosition == NotePosition.LEFT) { - result = new CommunicationTileNoteLeft((TileWithUpdateStairs) result, msg, skin, skinParam, + result = new CommunicationTileNoteLeft(result, msg, skin, skinParam, reverse ? livingSpace2 : livingSpace1, noteOnMessage); } else if (notePosition == NotePosition.RIGHT && msg.isSelfMessage()) { result = new CommunicationTileSelfNoteRight((CommunicationTileSelf) result, msg, skin, skinParam, noteOnMessage); } else if (notePosition == NotePosition.RIGHT) { - result = new CommunicationTileNoteRight((TileWithUpdateStairs) result, msg, skin, skinParam, + result = new CommunicationTileNoteRight(result, msg, skin, skinParam, reverse ? livingSpace1 : livingSpace2, noteOnMessage); } else if (notePosition == NotePosition.BOTTOM) { - result = new CommunicationTileNoteBottom((TileWithUpdateStairs) result, msg, skin, skinParam, - noteOnMessage); + result = new CommunicationTileNoteBottom(result, msg, skin, skinParam, noteOnMessage); } else if (notePosition == NotePosition.TOP) { - result = new CommunicationTileNoteTop((TileWithUpdateStairs) result, msg, skin, skinParam, - noteOnMessage); + result = new CommunicationTileNoteTop(result, msg, skin, skinParam, noteOnMessage); } } tiles.add(result); @@ -124,11 +122,9 @@ public class TileBuilder { for (Note noteOnMessage : exo.getNoteOnMessages()) { final NotePosition notePosition = exo.getNoteOnMessages().get(0).getPosition(); if (notePosition == NotePosition.LEFT) { - result = new CommunicationTileNoteLeft((TileWithUpdateStairs) result, exo, skin, skinParam, - livingSpace1, noteOnMessage); + result = new CommunicationTileNoteLeft(result, exo, skin, skinParam, livingSpace1, noteOnMessage); } else if (notePosition == NotePosition.RIGHT) { - result = new CommunicationTileNoteRight((TileWithUpdateStairs) result, exo, skin, skinParam, - livingSpace1, noteOnMessage); + result = new CommunicationTileNoteRight(result, exo, skin, skinParam, livingSpace1, noteOnMessage); } } tiles.add(result); @@ -140,17 +136,19 @@ public class TileBuilder { livingSpace1 = tileArguments.getFirstLivingSpace(); livingSpace2 = tileArguments.getLastLivingSpace(); } - tiles.add(new NoteTile(livingSpace1, livingSpace2, note, skin, skinParam)); + tiles.add( + new NoteTile(tileArguments.getStringBounder(), livingSpace1, livingSpace2, note, skin, skinParam)); } else if (ev instanceof Notes) { final Notes notes = (Notes) ev; - tiles.add(new NotesTile(livingSpaces, notes, skin, skinParam)); + tiles.add(new NotesTile(tileArguments.getStringBounder(), livingSpaces, notes, skin, skinParam)); } else if (ev instanceof Divider) { final Divider divider = (Divider) ev; tiles.add(new DividerTile(divider, tileArguments)); } else if (ev instanceof GroupingStart) { final GroupingStart start = (GroupingStart) ev; - final GroupingTile groupingTile = new GroupingTile(it, start, tileArguments.withBackColorGeneral( - start.getBackColorElement(), start.getBackColorGeneral()), tileArguments); + final GroupingTile groupingTile = new GroupingTile(it, start, + tileArguments.withBackColorGeneral(start.getBackColorElement(), start.getBackColorGeneral()), + tileArguments); tiles.add(new EmptyTile(4, groupingTile)); tiles.add(groupingTile); tiles.add(new EmptyTile(4, groupingTile)); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileMarged.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/TileMarged.java index 00c871317..f797caa1d 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileMarged.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/TileMarged.java @@ -35,7 +35,6 @@ */ package net.sourceforge.plantuml.sequencediagram.teoz; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.real.Real; import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -50,6 +49,7 @@ public class TileMarged extends AbstractTile implements Tile { private final double y2; public TileMarged(Tile tile, double x1, double x2, double y1, double y2) { + super(((AbstractTile) tile).getStringBounder()); this.tile = tile; this.x1 = x1; this.x2 = x2; @@ -62,20 +62,20 @@ public class TileMarged extends AbstractTile implements Tile { } - public double getPreferredHeight(StringBounder stringBounder) { - return tile.getPreferredHeight(stringBounder) + y1 + y2; + public double getPreferredHeight() { + return tile.getPreferredHeight() + y1 + y2; } - public void addConstraints(StringBounder stringBounder) { - tile.addConstraints(stringBounder); + public void addConstraints() { + tile.addConstraints(); } - public Real getMinX(StringBounder stringBounder) { - return tile.getMinX(stringBounder); + public Real getMinX() { + return tile.getMinX(); } - public Real getMaxX(StringBounder stringBounder) { - return tile.getMaxX(stringBounder).addFixed(x1 + x2); + public Real getMaxX() { + return tile.getMaxX().addFixed(x1 + x2); } public Event getEvent() { diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileParallel.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/TileParallel.java index 1f52d07bf..99754facd 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/TileParallel.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/TileParallel.java @@ -47,23 +47,18 @@ import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class TileParallel implements Tile, TileWithUpdateStairs, TileWithCallbackY { +public class TileParallel extends CommonTile { + + public TileParallel(StringBounder stringBounder) { + super(stringBounder); + } private final List tiles = new ArrayList(); - public void callbackY(double y) { + @Override + public void callbackY_internal(double y) { for (Tile tile : tiles) { - if (tile instanceof TileWithCallbackY) { - ((TileWithCallbackY) tile).callbackY(y); - } - } - } - - public void updateStairs(StringBounder stringBounder, double y) { - for (Tile tile : tiles) { - if (tile instanceof TileWithUpdateStairs) { - ((TileWithUpdateStairs) tile).updateStairs(stringBounder, y); - } + tile.callbackY(y); } } @@ -72,44 +67,40 @@ public class TileParallel implements Tile, TileWithUpdateStairs, TileWithCallbac } public void drawU(UGraphic ug) { - final StringBounder stringBounder = ug.getStringBounder(); - // final double totalHeight = getPreferredHeight(stringBounder); - final double yPointAll = getYPoint(stringBounder); + final double yPointAll = getContactPointRelative(); for (Tile tile : tiles) { - final double yPoint = tile.getYPoint(stringBounder); - // tile.drawU(ug.apply(UTranslate.dy(totalHeight - - // tile.getPreferredHeight(stringBounder)))); + final double yPoint = tile.getContactPointRelative(); tile.drawU(ug.apply(UTranslate.dy(yPointAll - yPoint))); } } - public double getYPoint(StringBounder stringBounder) { + public double getContactPointRelative() { double result = 0; for (Tile tile : tiles) { - result = Math.max(result, tile.getYPoint(stringBounder)); + result = Math.max(result, tile.getContactPointRelative()); } return result; } - public double getZ(StringBounder stringBounder) { + public double getZZZ() { double result = 0; for (Tile tile : tiles) { - result = Math.max(result, tile.getZ(stringBounder)); + result = Math.max(result, tile.getZZZ()); } return result; } - public double getPreferredHeight(StringBounder stringBounder) { - return getYPoint(stringBounder) + getZ(stringBounder); + public double getPreferredHeight() { + return getContactPointRelative() + getZZZ(); } - public void addConstraints(StringBounder stringBounder) { + public void addConstraints() { for (Tile tile : tiles) { - tile.addConstraints(stringBounder); + tile.addConstraints(); } } - public Real getMinX(final StringBounder stringBounder) { + public Real getMinX() { return RealUtils.min(new AbstractCollection() { public Iterator iterator() { return new Iterator() { @@ -120,7 +111,7 @@ public class TileParallel implements Tile, TileWithUpdateStairs, TileWithCallbac } public Real next() { - return source.next().getMinX(stringBounder); + return source.next().getMinX(); } public void remove() { @@ -135,7 +126,7 @@ public class TileParallel implements Tile, TileWithUpdateStairs, TileWithCallbac }); } - public Real getMaxX(final StringBounder stringBounder) { + public Real getMaxX() { return RealUtils.max(new AbstractCollection() { public Iterator iterator() { return new Iterator() { @@ -146,7 +137,7 @@ public class TileParallel implements Tile, TileWithUpdateStairs, TileWithCallbac } public Real next() { - return source.next().getMaxX(stringBounder); + return source.next().getMaxX(); } public void remove() { diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/UGraphicInterceptorTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/UGraphicInterceptorTile.java index c6149c9cb..15eaf0359 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/UGraphicInterceptorTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/UGraphicInterceptorTile.java @@ -42,7 +42,7 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UShape; public class UGraphicInterceptorTile extends UGraphicDelegator implements Context2D { - + private final boolean isBackground; public UGraphicInterceptorTile(UGraphic ug, boolean isBackground) { diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/YPositionedTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/YPositionedTile.java index 391939abb..0089213a4 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/YPositionedTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/YPositionedTile.java @@ -35,7 +35,6 @@ */ package net.sourceforge.plantuml.sequencediagram.teoz; -import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; @@ -44,16 +43,10 @@ public class YPositionedTile { private final Tile tile; private final double y; - public boolean inArea(double ymin, double ymax) { - return y >= ymin && y < ymax; - } - public YPositionedTile(Tile tile, double y) { this.tile = tile; this.y = y; - if (tile instanceof TileWithCallbackY) { - ((TileWithCallbackY) tile).callbackY(y); - } + tile.callbackY(y); } @Override @@ -63,7 +56,7 @@ public class YPositionedTile { public void drawInArea(UGraphic ug) { // System.err.println("YPositionedTile::drawU y=" + y + " " + tile); - ug.apply(UTranslate.dy(y)).draw(tile); + tile.drawU(ug.apply(UTranslate.dy(y))); } public boolean matchAnchorV2(String anchor) { @@ -71,14 +64,13 @@ public class YPositionedTile { return result; } - public final double getY(StringBounder stringBounder) { - final TileWithUpdateStairs communicationTile = (TileWithUpdateStairs) tile; - return y + communicationTile.getYPoint(stringBounder); + public final double getY() { + return y + tile.getContactPointRelative(); } - public double getMiddleX(StringBounder stringBounder) { - final double max = tile.getMaxX(stringBounder).getCurrentValue(); - final double min = tile.getMinX(stringBounder).getCurrentValue(); + public double getMiddleX() { + final double max = tile.getMaxX().getCurrentValue(); + final double min = tile.getMinX().getCurrentValue(); return (min + max) / 2; } diff --git a/src/net/sourceforge/plantuml/skin/ArrowComponent.java b/src/net/sourceforge/plantuml/skin/ArrowComponent.java index 758a857ff..7002bdcb6 100644 --- a/src/net/sourceforge/plantuml/skin/ArrowComponent.java +++ b/src/net/sourceforge/plantuml/skin/ArrowComponent.java @@ -49,6 +49,8 @@ public interface ArrowComponent extends Component { double getPaddingY(); public double getYPoint(StringBounder stringBounder); + + public double getPosArrow(StringBounder stringBounder); } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseArrow.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseArrow.java index aaf5daba0..9dbdc030f 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseArrow.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseArrow.java @@ -103,14 +103,17 @@ public class ComponentRoseArrow extends AbstractComponentRoseArrow { final double pos1 = start + 1; final double pos2 = len - 1; - if (getArrowConfiguration().getDecoration2() == ArrowDecoration.CIRCLE && dressing2.getHead() == ArrowHead.NONE) { + if (getArrowConfiguration().getDecoration2() == ArrowDecoration.CIRCLE + && dressing2.getHead() == ArrowHead.NONE) { len -= diamCircle / 2; } - if (getArrowConfiguration().getDecoration2() == ArrowDecoration.CIRCLE && dressing2.getHead() != ArrowHead.NONE) { + if (getArrowConfiguration().getDecoration2() == ArrowDecoration.CIRCLE + && dressing2.getHead() != ArrowHead.NONE) { len -= diamCircle / 2 + thinCircle; } - if (getArrowConfiguration().getDecoration1() == ArrowDecoration.CIRCLE && dressing1.getHead() == ArrowHead.NONE) { + if (getArrowConfiguration().getDecoration1() == ArrowDecoration.CIRCLE + && dressing1.getHead() == ArrowHead.NONE) { start += diamCircle / 2; len -= diamCircle / 2; } @@ -161,12 +164,20 @@ public class ComponentRoseArrow extends AbstractComponentRoseArrow { - (direction2 == ArrowDirection.LEFT_TO_RIGHT_NORMAL ? getArrowDeltaX() : 0); } else { textPos = getMarginX1() - + (direction2 == ArrowDirection.RIGHT_TO_LEFT_REVERSE - || direction2 == ArrowDirection.BOTH_DIRECTION ? getArrowDeltaX() : 0); + + (direction2 == ArrowDirection.RIGHT_TO_LEFT_REVERSE || direction2 == ArrowDirection.BOTH_DIRECTION + ? getArrowDeltaX() + : 0); } getTextBlock().drawU(ug.apply(new UTranslate(textPos, yText))); } + public double getPosArrow(StringBounder stringBounder) { + if (isBelowForResponse()) { + return 0; + } + return getTextHeight(stringBounder) - 2 * getMarginY(); + } + private boolean isBelowForResponse() { return belowForResponse && getDirection2() == ArrowDirection.RIGHT_TO_LEFT_REVERSE; } @@ -192,10 +203,10 @@ public class ComponentRoseArrow extends AbstractComponentRoseArrow { } } else if (dressing.getHead() == ArrowHead.CROSSX) { ug = ug.apply(new UStroke(2)); - ug.apply(new UTranslate(spaceCrossX, -getArrowDeltaX() / 2)).draw( - new ULine(getArrowDeltaX(), getArrowDeltaX())); - ug.apply(new UTranslate(spaceCrossX, getArrowDeltaX() / 2)).draw( - new ULine(getArrowDeltaX(), -getArrowDeltaX())); + ug.apply(new UTranslate(spaceCrossX, -getArrowDeltaX() / 2)) + .draw(new ULine(getArrowDeltaX(), getArrowDeltaX())); + ug.apply(new UTranslate(spaceCrossX, getArrowDeltaX() / 2)) + .draw(new ULine(getArrowDeltaX(), -getArrowDeltaX())); } else if (dressing.getHead() == ArrowHead.NORMAL) { final UPolygon polygon = getPolygonReverse(dressing.getPart()); ug.apply(getForegroundColor().bg()).apply(UTranslate.dx(x)).draw(polygon); @@ -224,10 +235,10 @@ public class ComponentRoseArrow extends AbstractComponentRoseArrow { } } else if (dressing.getHead() == ArrowHead.CROSSX) { ug = ug.apply(new UStroke(2)); - ug.apply(new UTranslate(x - spaceCrossX - getArrowDeltaX(), -getArrowDeltaX() / 2)).draw( - new ULine(getArrowDeltaX(), getArrowDeltaX())); - ug.apply(new UTranslate(x - spaceCrossX - getArrowDeltaX(), getArrowDeltaX() / 2)).draw( - new ULine(getArrowDeltaX(), -getArrowDeltaX())); + ug.apply(new UTranslate(x - spaceCrossX - getArrowDeltaX(), -getArrowDeltaX() / 2)) + .draw(new ULine(getArrowDeltaX(), getArrowDeltaX())); + ug.apply(new UTranslate(x - spaceCrossX - getArrowDeltaX(), getArrowDeltaX() / 2)) + .draw(new ULine(getArrowDeltaX(), -getArrowDeltaX())); ug = ug.apply(new UStroke()); } else if (dressing.getHead() == ArrowHead.NORMAL) { final UPolygon polygon = getPolygonNormal(dressing.getPart(), x); diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseSelfArrow.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseSelfArrow.java index 276698081..4f6f59070 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseSelfArrow.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseSelfArrow.java @@ -194,5 +194,10 @@ public class ComponentRoseSelfArrow extends AbstractComponentRoseArrow { public double getPreferredWidth(StringBounder stringBounder) { return Math.max(getTextWidth(stringBounder), arrowWidth); } + + public double getPosArrow(StringBounder stringBounder) { + throw new UnsupportedOperationException(); + } + } diff --git a/src/net/sourceforge/plantuml/statediagram/command/CommandAddField.java b/src/net/sourceforge/plantuml/statediagram/command/CommandAddField.java index bc704d1eb..c5c7b1923 100644 --- a/src/net/sourceforge/plantuml/statediagram/command/CommandAddField.java +++ b/src/net/sourceforge/plantuml/statediagram/command/CommandAddField.java @@ -47,6 +47,7 @@ import net.sourceforge.plantuml.cucadiagram.Code; import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Ident; import net.sourceforge.plantuml.statediagram.StateDiagram; +import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException; public class CommandAddField extends SingleLineCommand2 { @@ -66,7 +67,7 @@ public class CommandAddField extends SingleLineCommand2 { } @Override - protected CommandExecutionResult executeArg(StateDiagram diagram, LineLocation location, RegexResult arg) { + protected CommandExecutionResult executeArg(StateDiagram diagram, LineLocation location, RegexResult arg) throws NoSuchColorException { final String codeString = arg.getLazzy("CODE", 0); final String field = arg.get("FIELD", 0); diff --git a/src/net/sourceforge/plantuml/style/SName.java b/src/net/sourceforge/plantuml/style/SName.java index 53e5c5f2d..52d8b683e 100644 --- a/src/net/sourceforge/plantuml/style/SName.java +++ b/src/net/sourceforge/plantuml/style/SName.java @@ -105,7 +105,8 @@ public enum SName { task, // title, // usecase, // - wbsDiagram; // + wbsDiagram, // + yamlDiagram; // public static String depth(int level) { return "depth(" + level + ")"; diff --git a/src/net/sourceforge/plantuml/style/StyleSignature.java b/src/net/sourceforge/plantuml/style/StyleSignature.java index 7e572fb59..4c89bb442 100644 --- a/src/net/sourceforge/plantuml/style/StyleSignature.java +++ b/src/net/sourceforge/plantuml/style/StyleSignature.java @@ -90,6 +90,10 @@ public class StyleSignature { return new StyleSignature(result); } + public StyleSignature add(SName name) { + return add(name.name().toLowerCase().replace("_", "")); + } + public StyleSignature addStar() { final Set result = new HashSet(names); result.add("*"); diff --git a/src/net/sourceforge/plantuml/svek/extremity/MiddleCircleCircled.java b/src/net/sourceforge/plantuml/svek/extremity/MiddleCircleCircled.java index 515c60235..86dbd8758 100644 --- a/src/net/sourceforge/plantuml/svek/extremity/MiddleCircleCircled.java +++ b/src/net/sourceforge/plantuml/svek/extremity/MiddleCircleCircled.java @@ -42,7 +42,7 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; -import net.sourceforge.plantuml.ugraphic.color.HColorUtils; +import net.sourceforge.plantuml.ugraphic.color.HColorNone; class MiddleCircleCircled extends Extremity { @@ -80,11 +80,11 @@ class MiddleCircleCircled extends Extremity { final double d = 0; if (mode == MiddleCircleCircledMode.MODE1 || mode == MiddleCircleCircledMode.BOTH) { final UEllipse arc1 = new UEllipse(2 * radius2, 2 * radius2, angle, 90); - ug.apply(new UTranslate(-radius2 + d, -radius2 + d)).draw(arc1); + ug.apply(new HColorNone().bg()).apply(new UTranslate(-radius2 + d, -radius2 + d)).draw(arc1); } if (mode == MiddleCircleCircledMode.MODE2 || mode == MiddleCircleCircledMode.BOTH) { final UEllipse arc2 = new UEllipse(2 * radius2, 2 * radius2, angle + 180, 90); - ug.apply(new UTranslate(-radius2 + d, -radius2 + d)).draw(arc2); + ug.apply(new HColorNone().bg()).apply(new UTranslate(-radius2 + d, -radius2 + d)).draw(arc2); } ug.apply(new UTranslate(-radius1, -radius1)).draw(circle); } diff --git a/src/net/sourceforge/plantuml/svek/image/EntityImageDescription.java b/src/net/sourceforge/plantuml/svek/image/EntityImageDescription.java index 18c3e38d0..6b15ebf03 100644 --- a/src/net/sourceforge/plantuml/svek/image/EntityImageDescription.java +++ b/src/net/sourceforge/plantuml/svek/image/EntityImageDescription.java @@ -200,8 +200,8 @@ public class EntityImageDescription extends AbstractEntityImage { HorizontalAlignment.CENTER, getSkinParam()); } - name = BodyFactory.create2(codeDisplay, symbol.getFontParam(), getSkinParam(), HorizontalAlignment.CENTER, - stereotype, entity, style); + name = BodyFactory.create2(skinParam.getDefaultTextAlignment(HorizontalAlignment.CENTER), codeDisplay, + symbol.getFontParam(), getSkinParam(), stereotype, entity, style); if (hideText) { asSmall = symbol.asSmall(TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0), diff --git a/src/net/sourceforge/plantuml/svek/image/EntityImageLollipopInterfaceEye2.java b/src/net/sourceforge/plantuml/svek/image/EntityImageLollipopInterfaceEye2.java index b26e27463..48a9f2984 100644 --- a/src/net/sourceforge/plantuml/svek/image/EntityImageLollipopInterfaceEye2.java +++ b/src/net/sourceforge/plantuml/svek/image/EntityImageLollipopInterfaceEye2.java @@ -85,8 +85,9 @@ public class EntityImageLollipopInterfaceEye2 extends AbstractEntityImage { throw new IllegalArgumentException(); } - this.desc = BodyFactory.create2(entity.getDisplay(), symbol.getFontParam(), skinParam, - HorizontalAlignment.CENTER, stereotype, entity, getStyle(symbol.getFontParam())); + this.desc = BodyFactory.create2(skinParam.getDefaultTextAlignment(HorizontalAlignment.CENTER), + entity.getDisplay(), symbol.getFontParam(), skinParam, stereotype, entity, + getStyle(symbol.getFontParam())); this.url = entity.getUrl99(); diff --git a/src/net/sourceforge/plantuml/svek/image/EntityImageState2.java b/src/net/sourceforge/plantuml/svek/image/EntityImageState2.java index 04ffbfda4..adf31d6c4 100644 --- a/src/net/sourceforge/plantuml/svek/image/EntityImageState2.java +++ b/src/net/sourceforge/plantuml/svek/image/EntityImageState2.java @@ -94,8 +94,9 @@ public class EntityImageState2 extends AbstractEntityImage { this.url = entity.getUrl99(); TextBlock stereo = TextBlockUtils.empty(0, 0); - final TextBlock desc = BodyFactory.create2(entity.getDisplay(), symbol.getFontParam(), skinParam, - HorizontalAlignment.CENTER, stereotype, entity, getStyle(symbol.getFontParam())); + final TextBlock desc = BodyFactory.create2(skinParam.getDefaultTextAlignment(HorizontalAlignment.CENTER), + entity.getDisplay(), symbol.getFontParam(), skinParam, stereotype, entity, + getStyle(symbol.getFontParam())); asSmall = symbol.asSmall(null, desc, stereo, ctx, skinParam.getStereotypeAlignment()); diff --git a/src/net/sourceforge/plantuml/svek/image/EntityImageUseCase.java b/src/net/sourceforge/plantuml/svek/image/EntityImageUseCase.java index e739855dd..4887d3ab0 100644 --- a/src/net/sourceforge/plantuml/svek/image/EntityImageUseCase.java +++ b/src/net/sourceforge/plantuml/svek/image/EntityImageUseCase.java @@ -5,12 +5,12 @@ * (C) Copyright 2009-2020, Arnaud Roques * * Project Info: http://plantuml.com - * + * * 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 - * + * * This file is part of PlantUML. * * PlantUML is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ * * * Original Author: Arnaud Roques - * + * * */ package net.sourceforge.plantuml.svek.image; @@ -87,8 +87,15 @@ public class EntityImageUseCase extends AbstractEntityImage { super(entity, skinParam); final Stereotype stereotype = entity.getStereotype(); - final TextBlock tmp = BodyFactory.create2(entity.getDisplay(), FontParam.USECASE, skinParam, - HorizontalAlignment.CENTER, stereotype, entity, getStyle()); + final HorizontalAlignment align; + if (UseStyle.useBetaStyle()) { + final Style style = getStyle(); + align = style.getHorizontalAlignment(); + } else { + align = HorizontalAlignment.CENTER; + } + final TextBlock tmp = BodyFactory.create2(skinParam.getDefaultTextAlignment(align), entity.getDisplay(), + FontParam.USECASE, skinParam, stereotype, entity, getStyle()); if (stereotype == null || stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR) == null || portionShower.showPortion(EntityPortion.STEREOTYPE, entity) == false) { diff --git a/src/net/sourceforge/plantuml/svg/SvgGraphics.java b/src/net/sourceforge/plantuml/svg/SvgGraphics.java index d8d00d6c6..ecbaabe8f 100644 --- a/src/net/sourceforge/plantuml/svg/SvgGraphics.java +++ b/src/net/sourceforge/plantuml/svg/SvgGraphics.java @@ -5,12 +5,12 @@ * (C) Copyright 2009-2020, Arnaud Roques * * Project Info: http://plantuml.com - * + * * 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 - * + * * This file is part of PlantUML. * * PlantUML is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ * * * Original Author: Arnaud Roques - * + * * */ package net.sourceforge.plantuml.svg; @@ -40,6 +40,7 @@ import java.awt.geom.PathIterator; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; @@ -64,6 +65,7 @@ import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; +import net.sourceforge.plantuml.FileUtils; import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.SignatureUtils; import net.sourceforge.plantuml.code.Base64Coder; @@ -159,9 +161,15 @@ public class SvgGraphics { defs.appendChild(getPathHover(hover)); } - // Add styles and script for interactive SVG - defs.appendChild(getStylesForInteractiveMode()); - defs.appendChild(getScriptForInteractiveMode()); + final Element styles = getStylesForInteractiveMode(); + if (styles != null) { + defs.appendChild(styles); + } + + final Element script = getScriptForInteractiveMode(); + if (script != null) { + defs.appendChild(script); + } } catch (ParserConfigurationException e) { e.printStackTrace(); throw new IllegalStateException(e); @@ -170,11 +178,11 @@ public class SvgGraphics { private Element getStylesForInteractiveMode() { final Element style = simpleElement("style"); - final CDATASection cdata = document.createCDATASection( - ".elem {cursor: pointer;} " + "\n" + - ".elem, .link {opacity: 0.3;}" + "\n" + - ".elem.selected, .link.selected {opacity: 1;}" - ); + final String text = getData("default.css"); + if (text == null) { + return null; + } + final CDATASection cdata = document.createCDATASection(text); style.setAttribute("type", "text/css"); style.appendChild(cdata); return style; @@ -182,121 +190,24 @@ public class SvgGraphics { private Element getScriptForInteractiveMode() { final Element script = document.createElement("script"); - script.setTextContent( - "function addItemToMapOfLists(mapOfLists, name, item) {" + "\n" + - " // mapOfLists = {" + "\n" + - " // 'key1': [item1, item2, ...]," + "\n" + - " // 'key2': [item3, item4, ...]," + "\n" + - " // }" + "\n" + - " if (mapOfLists[name].length > 0) {" + "\n" + - " if (!mapOfLists[name].includes(item)) {" + "\n" + - " mapOfLists[name].push(item);" + "\n" + - " }" + "\n" + - " } else {" + "\n" + - " mapOfLists[name] = [item];" + "\n" + - " }" + "\n" + - "}" + "\n" + - "" + "\n" + - "function main() {" + "\n" + - " let elems = Array.from(document.getElementsByClassName('elem'));" + "\n" + - " let links = Array.from(document.getElementsByClassName('link'));" + "\n" + - "" + "\n" + - " let elemsMap = {};" + "\n" + - " let linkedElems = {};" + "\n" + - " let linkedLinks = {};" + "\n" + - "" + "\n" + - " elems.forEach(elem => {" + "\n" + - " let name = elem.classList[1];" + "\n" + - " elemsMap[name] = elem;" + "\n" + - " linkedElems[name] = [];" + "\n" + - " linkedLinks[name] = [];" + "\n" + - " });" + "\n" + - "" + "\n" + - " links.forEach(link => {" + "\n" + - " if (elemsMap[name1]) {" + "\n" + - " if (elemsMap[name2]) {" + "\n" + - " let name1 = link.classList[1];" + "\n" + - " let name2 = link.classList[2];" + "\n" + - "" + "\n" + - " let elem1 = elemsMap[name1];" + "\n" + - " let elem2 = elemsMap[name2];" + "\n" + - "" + "\n" + - " addItemToMapOfLists(linkedElems, name1, elem2);" + "\n" + - " addItemToMapOfLists(linkedElems, name2, elem1);" + "\n" + - "" + "\n" + - " addItemToMapOfLists(linkedLinks, name1, link);" + "\n" + - " addItemToMapOfLists(linkedLinks, name2, link);" + "\n" + - " }" + "\n" + - " }" + "\n" + - " });" + "\n" + - "" + "\n" + - " let selectedElems = [];" + "\n" + - " let selectedLinks = [];" + "\n" + - " let selectedElemName = null;" + "\n" + - "" + "\n" + - " function clearSelected() {" + "\n" + - " selectedElems.forEach(item => {" + "\n" + - " item.classList.remove('selected');" + "\n" + - " });" + "\n" + - " selectedElems = [];" + "\n" + - "" + "\n" + - " selectedLinks.forEach(item => {" + "\n" + - " item.classList.remove('selected');" + "\n" + - " });" + "\n" + - " selectedLinks = [];" + "\n" + - " }" + "\n" + - "" + "\n" + - " function selectAll() {" + "\n" + - " selectedElemName = null;" + "\n" + - "" + "\n" + - " selectedElems = Array.from(elems);" + "\n" + - " selectedElems.forEach(item => {" + "\n" + - " item.classList.add('selected');" + "\n" + - " });" + "\n" + - "" + "\n" + - " selectedLinks = Array.from(links);" + "\n" + - " selectedLinks.forEach(item => {" + "\n" + - " item.classList.add('selected');" + "\n" + - " });" + "\n" + - " }" + "\n" + - "" + "\n" + - " function selectElem(elemName) {" + "\n" + - " if (elemName === selectedElemName) {" + "\n" + - " selectAll();" + "\n" + - "" + "\n" + - " } else {" + "\n" + - " clearSelected();" + "\n" + - " selectedElemName = elemName;" + "\n" + - "" + "\n" + - " elemsMap[elemName].classList.add('selected');" + "\n" + - " selectedElems.push(elemsMap[elemName]);" + "\n" + - "" + "\n" + - " linkedElems[elemName].forEach(linkedElem => {" + "\n" + - " selectedElems.push(linkedElem);" + "\n" + - " linkedElem.classList.add('selected');" + "\n" + - " });" + "\n" + - "" + "\n" + - " linkedLinks[elemName].forEach(linkedLink => {" + "\n" + - " selectedLinks.push(linkedLink);" + "\n" + - " linkedLink.classList.add('selected');" + "\n" + - " });" + "\n" + - " }" + "\n" + - " }" + "\n" + - "" + "\n" + - " Object.keys(elemsMap).forEach(name => {" + "\n" + - " elemsMap[name].onclick = () => { selectElem(name); };" + "\n" + - " });" + "\n" + - "" + "\n" + - " selectAll();" + "\n" + - "}" + "\n" + - "" + "\n" + - "document.addEventListener('DOMContentLoaded', (event) => {" + "\n" + - " main();" + "\n" + - "});" - ); + final String text = getData("default.js"); + if (text == null) { + return null; + } + script.setTextContent(text); return script; } + private static String getData(final String name) { + try { + final InputStream is = SvgGraphics.class.getResourceAsStream("/svg/" + name); + return FileUtils.readText(is); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + private Element getPathHover(String hover) { final Element style = simpleElement("style"); final CDATASection cdata = document.createCDATASection("path:hover { stroke: " + hover + " !important;}"); @@ -1066,6 +977,7 @@ public class SvgGraphics { } public void startGroupWithClass(String groupClasses) { + pendingAction.add(0, (Element) document.createElement("g")); pendingAction.get(0).setAttribute("class", groupClasses); } diff --git a/src/net/sourceforge/plantuml/tim/TContext.java b/src/net/sourceforge/plantuml/tim/TContext.java index e263c4970..585158bf9 100644 --- a/src/net/sourceforge/plantuml/tim/TContext.java +++ b/src/net/sourceforge/plantuml/tim/TContext.java @@ -50,7 +50,6 @@ import net.sourceforge.plantuml.LineLocation; import net.sourceforge.plantuml.StringLocated; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.json.Json; -import net.sourceforge.plantuml.json.JsonObject; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.preproc.Defines; import net.sourceforge.plantuml.preproc.FileWithSuffix; @@ -197,17 +196,6 @@ public class TContext { } } - private TValue fromJsonOld(TMemory memory, String name) { - final int x = name.indexOf('.'); - final TValue data = memory.getVariable(name.substring(0, x)); - if (data == null) { - return null; - } - final JsonObject json = (JsonObject) data.toJson(); - final JsonValue result = json.get(name.substring(x + 1)); - return TValue.fromJson(result); - } - private CodeIterator buildCodeIterator(TMemory memory, List body) { final CodeIterator it10 = new CodeIteratorImpl(body); final CodeIterator it20 = new CodeIteratorLongComment(it10, debug); @@ -498,9 +486,13 @@ public class TContext { if (reader == null) { throw EaterException.located("cannot include " + location); } - ReadLine readerline = ReadLineReader.create(reader, location, s.getLocation()); - readerline = new UncommentReadLine(readerline); - sub = Sub.fromFile(readerline, blocname, this, memory); + try { + ReadLine readerline = ReadLineReader.create(reader, location, s.getLocation()); + readerline = new UncommentReadLine(readerline); + sub = Sub.fromFile(readerline, blocname, this, memory); + } finally { + reader.close(); + } } } catch (IOException e) { e.printStackTrace(); @@ -526,7 +518,7 @@ public class TContext { include.analyze(this, memory); final String definitionName = include.getLocation(); final List definition = definitionsContainer.getDefinition(definitionName); - ReadLine reader2 = new ReadLineList(definition, s.getLocation()); + final ReadLine reader2 = new ReadLineList(definition, s.getLocation()); try { final List body = new ArrayList(); @@ -541,6 +533,12 @@ public class TContext { } catch (IOException e) { e.printStackTrace(); throw EaterException.located("" + e); + } finally { + try { + reader2.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } @@ -565,9 +563,7 @@ public class TContext { throw EaterException.located("Cannot open URL"); } reader2 = PreprocessorUtils.getReaderIncludeUrl2(url, s, suf, charset); - - } - if (location.startsWith("<") && location.endsWith(">")) { + } else if (location.startsWith("<") && location.endsWith(">")) { reader2 = PreprocessorUtils.getReaderStdlibInclude(s, location.substring(1, location.length() - 1)); } else { final FileWithSuffix f2 = importedFiles.getFile(location, suf); @@ -614,6 +610,14 @@ public class TContext { } catch (IOException e) { e.printStackTrace(); throw EaterException.located("cannot include " + e); + } finally { + if (reader2 != null) { + try { + reader2.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } throw EaterException.located("cannot include " + location); diff --git a/src/net/sourceforge/plantuml/timingdiagram/TimingRuler.java b/src/net/sourceforge/plantuml/timingdiagram/TimingRuler.java index 137b1984b..40a8091ab 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/TimingRuler.java +++ b/src/net/sourceforge/plantuml/timingdiagram/TimingRuler.java @@ -37,6 +37,8 @@ package net.sourceforge.plantuml.timingdiagram; import java.awt.geom.Dimension2D; import java.math.BigDecimal; import java.util.Collection; +import java.util.Comparator; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -76,6 +78,9 @@ public class TimingRuler { if (times.size() == 0) { this.times.add(new TimeTick(BigDecimal.ZERO, TimingFormat.DECIMAL)); } + if (getMax().getTime().signum() > 0 && getMin().getTime().signum() < 0) { + this.times.add(new TimeTick(BigDecimal.ZERO, TimingFormat.DECIMAL)); + } } public TimingRuler(ISkinParam skinParam) { @@ -99,22 +104,39 @@ public class TimingRuler { private long highestCommonFactor() { if (highestCommonFactorInternal == -1) { - for (TimeTick time : times) { - long tick = time.getTime().longValue(); - if (tick > 0) { - if (highestCommonFactorInternal == -1) { - highestCommonFactorInternal = time.getTime().longValue(); - } else { - highestCommonFactorInternal = computeHighestCommonFactor(highestCommonFactorInternal, - Math.abs(time.getTime().longValue())); + for (long tick : getAbsolutesTicks()) { + if (highestCommonFactorInternal == -1) { + highestCommonFactorInternal = tick; + } else { + final long candidate = computeHighestCommonFactor(highestCommonFactorInternal, tick); + final double size = (getMax().getTime().doubleValue() - getMin().getTime().doubleValue()) + / candidate; + if (size > 200) { + return highestCommonFactorInternal; } + highestCommonFactorInternal = candidate; } } } return highestCommonFactorInternal; } - private int getNbTick(boolean capped) { + private Set getAbsolutesTicks() { + final Set result = new TreeSet(new Comparator() { + public int compare(Long o1, Long o2) { + return o2.compareTo(o1); + } + }); + for (TimeTick time : times) { + final long value = Math.abs(time.getTime().longValue()); + if (value > 0) { + result.add(value); + } + } + return result; + } + + private int getNbTick() { if (times.size() == 0) { return 1; } @@ -123,7 +145,9 @@ public class TimingRuler { } public double getWidth() { - return getNbTick(false) * tickIntervalInPixels; + final double delta = getMax().getTime().doubleValue() - getMin().getTime().doubleValue(); + + return (delta / tickUnitary() + 1) * tickIntervalInPixels; } public final double getPosInPixel(TimeTick when) { @@ -160,11 +184,13 @@ public class TimingRuler { ug = ug.apply(new UStroke(2.0)).apply(HColorUtils.BLACK); final double tickHeight = 5; final ULine line = ULine.vline(tickHeight); - final int nb = getNbTick(true); - for (int i = 0; i <= nb; i++) { - ug.apply(UTranslate.dx(tickIntervalInPixels * i)).draw(line); + final double firstTickPosition = getPosInPixelInternal(getFirstPositiveOrZeroValue().doubleValue()); + int nb = 0; + while (firstTickPosition + nb * tickIntervalInPixels <= getWidth()) { + ug.apply(UTranslate.dx(firstTickPosition + nb * tickIntervalInPixels)).draw(line); + nb++; } - ug.draw(ULine.hline(nb * tickIntervalInPixels)); + ug.apply(UTranslate.dx(firstTickPosition)).draw(ULine.hline((nb - 1) * tickIntervalInPixels)); for (long round : roundValues()) { final TextBlock text = getTimeTextBlock(round); @@ -173,6 +199,15 @@ public class TimingRuler { } } + private BigDecimal getFirstPositiveOrZeroValue() { + for (TimeTick time : times) { + if (time.getTime().signum() >= 0) { + return time.getTime(); + } + } + throw new IllegalStateException(); + } + private Collection roundValues() { final SortedSet result = new TreeSet(); if (tickUnitary == 0) { @@ -181,7 +216,7 @@ public class TimingRuler { result.add(round); } } else { - final int nb = getNbTick(true); + final int nb = getNbTick(); for (int i = 0; i <= nb; i++) { final long round = tickToTime(i); result.add(round); @@ -196,7 +231,7 @@ public class TimingRuler { public void drawVlines(UGraphic ug, double height) { ug = applyForVLines(ug); final ULine line = ULine.vline(height); - final int nb = getNbTick(true); + final int nb = getNbTick(); for (int i = 0; i <= nb; i++) { ug.apply(UTranslate.dx(tickIntervalInPixels * i)).draw(line); } diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java index 6149ecefe..5a8c62885 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java @@ -172,10 +172,11 @@ public abstract class AbstractCommonUGraphic implements UGraphic { public void startGroup(String groupId) { } - + public void startGroupWithClass(String groupClasses) { } + public void closeGroup() { } diff --git a/src/net/sourceforge/plantuml/ugraphic/PlacementStrategyY1Y2Right.java b/src/net/sourceforge/plantuml/ugraphic/PlacementStrategyY1Y2Right.java new file mode 100644 index 000000000..b2eae23a9 --- /dev/null +++ b/src/net/sourceforge/plantuml/ugraphic/PlacementStrategyY1Y2Right.java @@ -0,0 +1,66 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.ugraphic; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.LinkedHashMap; +import java.util.Map; + +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; + +public class PlacementStrategyY1Y2Right extends AbstractPlacementStrategy { + + public PlacementStrategyY1Y2Right(StringBounder stringBounder) { + super(stringBounder); + } + + public Map getPositions(double width, double height) { + final double usedHeight = getSumHeight(); + + final double space = (height - usedHeight) / (getDimensions().size() + 1); + final Map result = new LinkedHashMap(); + double y = space; + for (Map.Entry ent : getDimensions().entrySet()) { + final double x = width - ent.getValue().getWidth(); + result.put(ent.getKey(), new Point2D.Double(x, y)); + y += ent.getValue().getHeight() + space; + } + return result; + } + +} diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverEllipseSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverEllipseSvg.java index 0e9440d41..dc62aa8a5 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverEllipseSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverEllipseSvg.java @@ -76,7 +76,7 @@ public class DriverEllipseSvg implements UDriver { gr.getPolicy()); svg.setFillColor("url(#" + id + ")"); } else if (back == null || back instanceof HColorBackground) { - svg.setFillColor("none"); + svg.setFillColor("#00000000"); } else { final String backcolor = mapper.toSvg(back); svg.setFillColor(backcolor); diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextSvg.java index 1ff12319c..1d970e3af 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextSvg.java @@ -87,7 +87,8 @@ public class DriverTextSvg implements UDriver { } else if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { textDecoration = "line-through"; } else if (fontConfiguration.containsStyle(FontStyle.WAVE)) { - // Beware that some current SVG implementations do not render the wave properly (e.g. Chrome just draws a straight line) + // Beware that some current SVG implementations do not render the wave properly + // (e.g. Chrome just draws a straight line) // Works ok on Firefox 85. textDecoration = "wavy underline"; } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java index 794d66f68..fb2838d19 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java @@ -179,12 +179,13 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo public void startGroup(String groupId) { getGraphicObject().startGroup(groupId); } - + @Override public void startGroupWithClass(String groupClasses) { getGraphicObject().startGroupWithClass(groupClasses); } + @Override public void closeGroup() { getGraphicObject().closeGroup(); diff --git a/src/net/sourceforge/plantuml/version/LicenseInfo.java b/src/net/sourceforge/plantuml/version/LicenseInfo.java index 695d35eb9..33103540c 100644 --- a/src/net/sourceforge/plantuml/version/LicenseInfo.java +++ b/src/net/sourceforge/plantuml/version/LicenseInfo.java @@ -217,13 +217,16 @@ public class LicenseInfo { if (br == null) { return null; } - final String s = br.readLine(); - br.close(); - final LicenseInfo result = retrieveNamed(s); - if (result != null) { - Log.info("Reading license from " + f.getAbsolutePath()); + try { + final String s = br.readLine(); + final LicenseInfo result = retrieveNamed(s); + if (result != null) { + Log.info("Reading license from " + f.getAbsolutePath()); + } + return result; + } finally { + br.close(); } - return result; } public static void main(String[] args) { diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 0777873f7..3d8667921 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -68,7 +68,7 @@ public class Version { private static String dotted(int nb) { final String minor = "" + nb % MAJOR_SEPARATOR; final String major = "" + nb / MAJOR_SEPARATOR; - return major + "." + minor.substring(0, 4) + "." + minor.substring(4); + return major + "." + minor.substring(0, 4) + "." + Integer.parseInt(minor.substring(4)); } public static String versionString(int size) { @@ -80,7 +80,7 @@ public class Version { } public static int beta() { - final int beta = 0; + final int beta = 11; return beta; } diff --git a/src/net/sourceforge/plantuml/yaml/SimpleYamlParser.java b/src/net/sourceforge/plantuml/yaml/SimpleYamlParser.java index f9c630c32..0667e5ba6 100644 --- a/src/net/sourceforge/plantuml/yaml/SimpleYamlParser.java +++ b/src/net/sourceforge/plantuml/yaml/SimpleYamlParser.java @@ -42,65 +42,28 @@ import java.util.regex.Pattern; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.json.JsonArray; import net.sourceforge.plantuml.json.JsonObject; +import net.sourceforge.plantuml.json.JsonString; import net.sourceforge.plantuml.json.JsonValue; public class SimpleYamlParser { - private static final String KEY = "([_0-9\\w][- _0-9\\w./]*)"; - - private JsonObject result; + private JsonValue result; private final List pendingIndents = new ArrayList(); - public JsonObject parse(List lines) { - List tmp = new ArrayList(); - for (String s : lines) { - if (s.trim().length() == 0) - continue; - if (s.trim().startsWith("#")) - continue; - tmp.add(s); - } - tmp = mergeMultiline(tmp); + public JsonValue parse(List lines) { result = new JsonObject(); pendingIndents.clear(); pendingIndents.add(0); - for (String s : tmp) { + final YamlLines yamlLines = new YamlLines(lines); + for (String s : yamlLines) { parseSingleLine(s); } return result; } - private List mergeMultiline(List tmp) { - final List result = new ArrayList(); - for (int i = 0; i < tmp.size(); i++) { - if (nameOnly(tmp.get(i)) != null && textOnly(tmp.get(i + 1))) { - final StringBuilder sb = new StringBuilder(tmp.get(i)); - while (textOnly(tmp.get(i + 1))) { - sb.append(" " + tmp.get(i + 1).trim()); - i++; - } - result.add(sb.toString()); - } else { - result.add(tmp.get(i)); - } - } - return result; - } - - private String[] dashNameAndValue(String s) { - final Pattern p1 = Pattern.compile("^\\s*[-]\\s*" + KEY + "\\s*:\\s*(\\S.*)$"); - final Matcher m1 = p1.matcher(s); - if (m1.matches()) { - final String name = m1.group(1); - final String data = m1.group(2).trim(); - return new String[] { name, data }; - } - return null; - } - private String[] nameAndValue(String s) { - final Pattern p1 = Pattern.compile("^\\s*" + KEY + "\\s*:\\s*(\\S.*)$"); + final Pattern p1 = Pattern.compile("^\\s*" + YamlLines.KEY + "\\s*: \\s*(\\S.*)$"); final Matcher m1 = p1.matcher(s); if (m1.matches()) { final String name = m1.group(1); @@ -110,45 +73,12 @@ public class SimpleYamlParser { return null; } - private String nameOnly(String s) { - final Pattern p1 = Pattern.compile("^\\s*" + KEY + "\\s*:\\s*\\|?\\s*$"); - final Matcher m1 = p1.matcher(s); - if (m1.matches()) { - final String name = m1.group(1); - return name; - } - return null; - } - - private String listedValue(String s) { - final Pattern p1 = Pattern.compile("^\\s*[-]\\s*(\\S.*)$"); - final Matcher m1 = p1.matcher(s); - if (m1.matches()) { - final String name = m1.group(1).trim(); - return name; - } - return null; - } - - private boolean textOnly(String s) { - if (isList(s)) - return false; - return s.indexOf(':') == -1; - } - private void parseSingleLine(String s) { - // System.err.println("s=" + s); final int indent = getIndent(s); +// System.err.println("s=" + s); if (isListStrict(s)) { - muteToArray(indent); - return; - } - - final String[] dashNameAndValue = dashNameAndValue(s); - if (dashNameAndValue != null) { - muteToArray(indent); - parseSingleLine(s.replaceFirst("[-]", " ")); + strictMuteToArray(indent); return; } @@ -159,7 +89,7 @@ public class SimpleYamlParser { return; } - final JsonObject working = getWorking(indent); + final JsonObject working = (JsonObject) getWorking(indent); if (working == null) { System.err.println("ERROR: ignoring " + s); return; @@ -173,7 +103,7 @@ public class SimpleYamlParser { return; } - final String nameOnly = nameOnly(s); + final String nameOnly = YamlLines.nameOnly(s); if (nameOnly != null) { working.add(nameOnly, new JsonObject()); return; @@ -182,11 +112,27 @@ public class SimpleYamlParser { throw new UnsupportedOperationException(s); } + private String listedValue(String s) { + final Pattern p1 = Pattern.compile("^\\s*[-]\\s*(\\S.*)$"); + final Matcher m1 = p1.matcher(s); + if (m1.matches()) { + final String name = m1.group(1).trim(); + return name; + } + return null; + } + private JsonArray getForceArray(int indent) { + if (indent == 0 && getLastIndent() == 0) { + if (result instanceof JsonArray == false) { + result = new JsonArray(); + } + return (JsonArray) result; + } while (getLastIndent() > indent - 1) pendingIndents.remove(pendingIndents.size() - 1); - final JsonObject last = search(result, pendingIndents.size()); + final JsonObject last = (JsonObject) search(result, pendingIndents.size()); final String field = last.names().get(last.size() - 1); if (last.get(field) instanceof JsonArray == false) { last.set(field, new JsonArray()); @@ -194,11 +140,22 @@ public class SimpleYamlParser { return (JsonArray) last.get(field); } - private void muteToArray(int indent) { + private void strictMuteToArray(int indent) { + if (indent == 0 && getLastIndent() == 0) { + if (result instanceof JsonArray == false) { + result = new JsonArray(); + } + return; + } while (getLastIndent() > indent) pendingIndents.remove(pendingIndents.size() - 1); - final JsonObject last = search(result, pendingIndents.size()); + if (result instanceof JsonArray) { + ((JsonArray) result).add(new JsonObject()); + return; + } + + final JsonObject last = (JsonObject) search(result, pendingIndents.size()); final String field = last.names().get(last.size() - 1); if (last.get(field) instanceof JsonArray == false) { last.set(field, new JsonArray()); @@ -207,10 +164,6 @@ public class SimpleYamlParser { } } - private boolean isList(String s) { - return s.trim().startsWith("-"); - } - private boolean isListStrict(String s) { return s.trim().equals("-"); } @@ -219,7 +172,7 @@ public class SimpleYamlParser { return pendingIndents.get(pendingIndents.size() - 1); } - private JsonObject getWorking(int indent) { + private JsonValue getWorking(int indent) { if (indent > getLastIndent()) { pendingIndents.add(indent); return search(result, pendingIndents.size()); @@ -238,10 +191,24 @@ public class SimpleYamlParser { return search(result, pendingIndents.size()); } - private static JsonObject search(JsonObject current, int size) { - if (size <= 1) { - return current; + private static JsonValue search(JsonValue current1, int size) { + if (current1 instanceof JsonArray) { + JsonArray array = (JsonArray) current1; + + final JsonValue tmp; + if (array.size() == 0) { + tmp = new JsonObject(); + array.add(tmp); + } else { + tmp = array.get(array.size() - 1); + } + return tmp; } + if (size <= 1) { + return current1; + } + + final JsonObject current = (JsonObject) current1; final String last = current.names().get(current.size() - 1); // System.err.println("last=" + last); JsonValue tmp = current.get(last); @@ -254,7 +221,11 @@ public class SimpleYamlParser { tmp = array.get(array.size() - 1); } } - return search((JsonObject) tmp, size - 1); + if (tmp instanceof JsonString) { + System.err.println("JsonString? " + tmp); + return null; + } + return search(tmp, size - 1); } private int getIndent(String s) { diff --git a/src/net/sourceforge/plantuml/yaml/YamlDiagramFactory.java b/src/net/sourceforge/plantuml/yaml/YamlDiagramFactory.java index f351ab708..9081cd650 100644 --- a/src/net/sourceforge/plantuml/yaml/YamlDiagramFactory.java +++ b/src/net/sourceforge/plantuml/yaml/YamlDiagramFactory.java @@ -39,14 +39,14 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import net.sourceforge.plantuml.StringLocated; import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.command.PSystemAbstractFactory; import net.sourceforge.plantuml.core.Diagram; import net.sourceforge.plantuml.core.DiagramType; import net.sourceforge.plantuml.core.UmlSource; -import net.sourceforge.plantuml.json.JsonObject; +import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.jsondiagram.JsonDiagram; +import net.sourceforge.plantuml.jsondiagram.StyleExtractor; public class YamlDiagramFactory extends PSystemAbstractFactory { @@ -55,13 +55,15 @@ public class YamlDiagramFactory extends PSystemAbstractFactory { } public Diagram createSystem(UmlSource source) { - JsonObject yaml = null; + JsonValue yaml = null; + StyleExtractor styleExtractor = null; try { final List list = new ArrayList(); - final Iterator it = source.iterator2(); + styleExtractor = new StyleExtractor(source.iterator2()); + final Iterator it = styleExtractor.getIterator(); it.next(); while (true) { - final String line = it.next().getString(); + final String line = it.next(); if (it.hasNext() == false) { break; } @@ -72,6 +74,9 @@ public class YamlDiagramFactory extends PSystemAbstractFactory { e.printStackTrace(); } final JsonDiagram result = new JsonDiagram(UmlDiagramType.YAML, yaml, new ArrayList()); + if (styleExtractor != null) { + styleExtractor.applyStyles(result.getSkinParam()); + } result.setSource(source); return result; } diff --git a/src/net/sourceforge/plantuml/yaml/YamlLines.java b/src/net/sourceforge/plantuml/yaml/YamlLines.java new file mode 100644 index 000000000..4913fffa9 --- /dev/null +++ b/src/net/sourceforge/plantuml/yaml/YamlLines.java @@ -0,0 +1,186 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.yaml; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class YamlLines implements Iterable { + + public static final String KEY = "([_0-9\\w].*)"; + + private List lines = new ArrayList(); + + public YamlLines(List rawLines) { + for (String s : rawLines) { + if (s.startsWith("#")) { + continue; + } + s = removeDiese(s); + if (s.trim().length() == 0) + continue; + lines.add(s); + } + mergeMultiline(); + manageSpaceTwoPoints(); + manageList(); + final int startingEmptyCols = startingEmptyCols(); + removeFirstCols(startingEmptyCols); + } + + private void manageSpaceTwoPoints() { + for (ListIterator it = lines.listIterator(); it.hasNext();) { + String s = it.next(); + if (s.contains("\"") == false && s.contains("'") == false && s.contains(":") + && s.indexOf(':') == s.lastIndexOf(':') && s.contains(": ") == false) { + s = s.replace(":", ": "); + it.set(s); + } + } + + } + + private String removeDiese(String s) { + final int idx = s.indexOf(" #"); + if (idx == -1) { + return s; + } + return s.substring(0, idx); + } + + private void manageList() { + final List result = new ArrayList(); + for (String s : lines) { + final Pattern p1 = Pattern.compile("^(\\s*[-])(\\s*\\S.*)$"); + final Matcher m1 = p1.matcher(s); + if (s.contains(": ") && m1.matches()) { + result.add(m1.group(1)); + result.add(s.replaceFirst("[-]", " ")); + } else if (m1.matches()) { + result.add(" " + s); + } else { + result.add(s); + } + + } + this.lines = result; + } + + private void removeFirstCols(int startingEmptyCols) { + if (startingEmptyCols == 0) { + return; + } + for (ListIterator it = lines.listIterator(); it.hasNext();) { + final String s = it.next().substring(startingEmptyCols); + it.set(s); + } + } + + private int startingEmptyCols() { + int result = Integer.MAX_VALUE; + for (String s : lines) { + result = Math.min(result, startingSpaces(s)); + if (result == 0) { + return 0; + } + } + return result; + } + + private static int startingSpaces(String s) { + final Pattern p1 = Pattern.compile("^(\\s*).*"); + final Matcher m1 = p1.matcher(s); + if (m1.matches()) { + return m1.group(1).length(); + } + return 0; + } + + private void mergeMultiline() { + final List result = new ArrayList(); + for (int i = 0; i < lines.size(); i++) { + final String init = isMultilineStart(i); + if (init != null) { + final StringBuilder sb = new StringBuilder(init); + while (i + 1 < lines.size() && textOnly(lines.get(i + 1))) { + sb.append(" " + lines.get(i + 1).trim()); + i++; + } + result.add(sb.toString()); + } else { + result.add(lines.get(i)); + } + } + this.lines = result; + } + + private String isMultilineStart(int i) { + if (nameOnly(lines.get(i)) != null && textOnly(lines.get(i + 1))) { + final int idx = lines.get(i).indexOf(':'); + return lines.get(i).substring(0, idx + 1); + } + return null; + } + + public static String nameOnly(String s) { + final Pattern p1 = Pattern.compile("^\\s*" + KEY + "\\s*:\\s*[|>]?\\s*$"); + final Matcher m1 = p1.matcher(s); + if (m1.matches()) { + final String name = m1.group(1); + return name; + } + return null; + } + + private boolean textOnly(String s) { + if (isList(s)) + return false; + return s.indexOf(':') == -1; + } + + private boolean isList(String s) { + return s.trim().startsWith("-"); + } + + public Iterator iterator() { + return Collections.unmodifiableList(lines).iterator(); + } + +} \ No newline at end of file diff --git a/stdlib/c4-abx.repx b/stdlib/c4-abx.repx index 86f12fdf50fbf070eef11bfd53349d87a6d31c9c..91d855d1e759fb0d7515877737b511c989b870e5 100644 GIT binary patch literal 3189 zcmV-*42ts`7jB}c8*=a_z~aDmL(vd(4tzVJaK$2Ft%Egp6W4q3nRrC35m~5|04We7 zr_F5M`MivSWNN!TKW0zMpVw*!qF{q?p1Av^UY>=s=keNcl!wzOL*U*LF6-U?jrulKl*&l;^RBW`B0d zl}tiwx>}4dbD>4Z6B3CKn*Fi#UwYWTIgcGhau^T+qqe^X+OHSzcw}it({lFG6$g&Y zbW7JS53dIfJL{gs^M=cwj`Ug29JSWfrJIZDjJ)H3iJ-qP1ArD!JNd&PNznNy3wn@? zRa^L%Ie4HguYNH9uSt6F`I4wl+HvHT^{YmCm8g!3Sb&Kuw_*S~f;ItpK0WJ5E)4PE zEH_^^d{D-8+hke*kkS;joHx?uDp;x_o!Yp{ME7*9;4w#vu5yE3vkU`*Pma9oKUA9Y zeFjX|n79INt7u2r$>fugy)5FnEznn?Ql1H_WVjBU{_+U@B>-?u^Q{v-E_>EJQ}hkK zC|c-5hw#N7Y4Qgxa6GMbdZ=ez+1cknb_d|}&#HPtZiP0rVwB*2CCM}m?>ROtm9BGd zbOl^d2n$c;S%6D>8y1t=P2o2Fmp|heebZD`nRt0fZ;;UBj5@&sPz?EG1-DB2Y&q@c z2YMorgReFuRyKXXSW1r%Ym^jK#Q>pMI{Lrsq@}=8k z-LC%?o9wqhW^y@WnEFCd6ltD;-x)`VW*v#+!`lNH7+G4%^yY=x@X{aAde3HbvBoX| zQ)hdt1i6Z5SE7lYVw-PmtNm7*6RK8AY!Ma9t$Xc~CFI02}S{8c|Ri}d(;U=nk}091QKfcnbq%^M0lZKaLd9| zYr5^^$bE}U;#(s7wJ4LjPB1s>&l_aIO?j!WU-Ql~*sEf_?mg)Lja5j-fdvE(Y=(-MPLK7Xiv1NpZ z_+`*W&5h^TuT{dT8pl|~aeXokWHBTHfvH4vRltZG1=*KM`v)-o5@GnT<*<~y7>bJZ zqW}cOs#7Lq<|3kn##}^G9x5P;4Jdo|a;xMIABL#|M#?hmxr!-gF%l_r4qVb<^B7^M z8d~Voc}4W?0Adf$`2!};s0(v}kcW8a5W~>%!h|C-yfgL;MN}?_j{)FgGuqtioYqWY zXD#3=cTpSzH&n{RtIwvnj81)!3xnYX8h?$=bpvl=C@NMMH;IukSbpg7E*$Q{4Ltc; zo9hPN#4vQsP+=k?gV5se<6ShYg)3;XUf~q%hO4-vR*5Ds_Y3Y^A4 ztbxHMw}z2U8iH{va9#!!0q6Jq6rHHTnn_nNeD}w6}_mFyf&Tm(8 z^|>};h#tb53LAJ`VGXas)su?<-#;*RoYwlnW6&YJGJ`5uX930rOae~S&I?9fXKF5U z6#TJb_K7fabR4jDuq6h7ARgA$@T#OnH}-}$qP9b>vL{h0tSid`R@hKiyNY|rH`;xc zzS!>J840Z|lGT>j;8~+s(@Rt-aJse|e+D*Q5j%t1q)7V1&ivV)5vr|_hB^gJGa|8z zy7-sg7Lquh9@hiKtzqc==JZ!n61ZtvR!gfh*pXc+KS+W+C=~4J?PSuTXv#(r2+2+r zEw0YA94Df%I6PkBhdHL&5Vmwr&4(zY+6jqkOb&C*B=_UXiMul0d~afRoikT(uK{~KizZy7n=I7uw; zH+tumZ5bjmRvA*3xqcp{qEA|TZH@z{t3;@GSp9^ce-9&!KbqPRyVtc*1QqycjM6Nr z21;rQ0jv9*?AMwf9_Lp}U$>v|Rb%f^^yBP&S?cuyUw+cI_*ibkT~q`U4H7(9*196z zoj>b~|4-viam0tS2jy{o#S9Y6K5zg*?;ZNFG=X?q-or;|I+-Mx#X-JdRte-dz;&hv zQg8x-KWO0SWVTA$Gk;6Xf5e?z%Bd~!T>QEDAV2hffSc^ThrXMUL(c_tJTS5kXizEE*pNxX}n3(oKcKs0VYkbkYkGH3iR z-IyO>p1BcZ%Q;^fw|5n|Sw-?#f@1egj>_`mhSPB!e9vELc5YJJ6{vSVin~+# z78{tlZR%=>jl;8=dT#^Psjk}F;?-i1BJbnP4*w`qDoninTI`(vb$ zO%jfzgs{Iplx&x8X_NCEhHs}{xk_Uo*1x@SU|@SDD_4SKoFE)Y0q1bYAJvcwDZ`Hs z$id+PWQ7ms18Ms6{5s!%|63>ca01=*?)qM71_nH@4|`j)-G)7TO&j(qtFvq2^Pwut z7yXJBu*W7uOUex_nQu-etB~;$cXhBZo055`ja_q$$h=vLkIW1q*?LGJr;z3+r1f`q z*SNUh?j}Yl2YSN3V~;vqBjHk5@eCJJY*K@*q}M7!Og>Nn7ypug)ad}5!oqUi+X`GL zpY64fc#q^VudpQ>fJrhTVvVGdH-r_&1=GJir{nYR`Lf}H!umltR9p2^H!gM77?t2k zVzti&7c|!T(oHrUQJ&A)OgPi-st7DV} z@)U=l@aT*L%bVRIdgtf^ul!H96pusE<$b9rwrX6?MOzANiPfR$Z?nhA6FI_Tn&}Ud%yD&5LC`RAg zi64ky$DKV<@M#~9F|c~yT(!+n0S>jSi2*0)D8Z@a+ZBrvXWqWlDhp%Q4N0=L#`?LD zcG#?rEfX{T$kxYp8I;w5DKdkA9$gEN0V&Ty1(?yVmT<7HdE99J}sRakO)#x1Fm_u;Rg6~u^cSX;ot6?6{7;;P2U(?Uwo9n zyMa4M6Gtzi$#S3^c0vNOOpYV`+siX!WWl?m(Zm0T8!(P@ce^8AbVyZX}sS)m`RV^p! z1c4iA_V^XZ00SEI2Ynlp23A4Q8lzfN0k5mb5vkF!MyW3g4HK36^3aVhV(K^^$&qfW bsH-V325>XYBF{4EZAgWGxzwYkB)R?p*A^Ww literal 3262 zcmV;v3_IH~jZ#ge|0lry*2D$BDF%m$mDf?e6>x#>@Qb+q|<~!bp&m1OpA= z@c_WGFH^s#40s=-Cnd>igLg?=TfWB$|=wnoHHpq_f3x*IvD0q$*8pD_H zNRhwWgr1j`PVcD)S$6hqQ1t_#*S}oVSsqE3Oc*i$w<)_H$75ZWlFCfX9X$zs2!(|& zH98QN^0thV+M>|6@qhM;)98z)@q#LYJS?n}(6&d@FaW3+=8L2H<*LsWCx>fAC5a;V zDnnw!vtyKt>BV)8y*v!oimSz?w?T3@bgb)ad7}LWXyc+Rr;_2x@Izh0IgFzif3i8_rW;=|_$F)#{gNzJ%$E5>K&@!yq$7HgYk=V>RaDstN zB~JnZvgp`(Rp?0o(elY3ke{Rra}Oa8@z_Ha#U3wAUnO_Pz+M1D73J_I0JPZ5a_&{0 z)J)4R*uzD3SyUI?K+_a2KbxURbo_(AFqlp#eiHl}#lhoB@n{=sV)Ob0YB^LjkCaActlh+&4vfr^F0fCMsjE`5i@bbtwV z{#rOPYqn6qYEZ=Sa2oOpVZ7Y#2k6Z87Kh7J7ZqHU#fcaGb*BgRsL=Nhdy(#(^V@WR zzE(txrH61fu>waESK*#M|6tAkzyF{$Z->?w_Cv^(kmtpZM;{Lls|Zq*cIpyKd8PN3 zy7iq|&t+HVc0Z++Y_|S+OL(PYpSk;MAWwQpi!E3wLRd)Yaw7MRuCYDaaIpQou|z}YOrMKkSkZ*;Hno0yh1eaYRwdPSklOMR8G zH}q^$txRUrS}1g#Z(rKAeT=ccxyvxpOrBhHe$uIVoj0tu&|VQ4d%^QxK%9tp%0B9Y zDA6q=&KKv(%_ipLa-~#Ro+OXi4e?l(6NLdeP7c?RqVi-?^v?&RFw#owMP;N|65O{rT41~|x^MU8vaaP- zN(MaPElsx%mCp}4lQ@Mnw z{KS-##iIf*#%P^IRdP`c5wNN+ zlKryYk3KppOW$a};49LkqSw#%;<7Z>8+`d=P1gVX=-rNr;7WrJ9zs@i#e3J;)|dFd z0xOE+eQ0kePvm#ZgTd^Be;@3@YN3;xlwpZPeW&1}%#Al;$>+jg9*Xq?^I{;IJy_0F zK?)`y^$!|p%JXg1(FGK2y@0q)Yd^x8(3W5m(vqiKnngxNijB<&I`+nb^2iGqEB6zt zsS1YJ7Aq8-64^14S@MIeyjRNWnKCvgrgPSqzS-iM&K|dTZaBjwfMjzU2>ebs!i|LH*{u9pY7cJ=IPyXbU)ndnQa@XVftRrmy!a&dirSl(7^n!FS7#9kk3BZmS`nVMVYn<; zASY=jMjZJs=@V)VJH9@RFP1O0J^od?XXV^dS}8zC*vHC20PP)FnP%Csg7gU$aF&Ps zQ4MWD*-?7=d%{0T^Ltm+J;7H5~?bwpccUpd{xJ zkXX*gmNHCpja@ogJ~OI@SJ+xx$5Aq|#F|l3-dLnW*S7sPP>7~(y!x#=7?L3AW5TK; zyK%3!KB8bcJKE=kK9JTD)x+1?48*7msv9rXo|}#K})gX9-FKZ95Dpv0N zO;~O!_(YmFv?j0h5#?zdWyEV&6pX9Rs_4zZ@4C1{v*JAN2_k;$F`f{UlYF}2>Yy=Z zWxnT^oo+ajyDaaq>kiz?t~hGR($ wlfhAbSuj{3<(CI 0) { + if (!mapOfLists[name].includes(item)) { + mapOfLists[name].push(item); + } + } else { + mapOfLists[name] = [item]; + } +} + +function main() { + let elems = Array.from(document.getElementsByClassName('elem')); + let links = Array.from(document.getElementsByClassName('link')); + + let elemsMap = {}; + let linkedElems = {}; + let linkedLinks = {}; + + elems.forEach(elem => { + let name = elem.classList[1]; + elemsMap[name] = elem; + linkedElems[name] = []; + linkedLinks[name] = []; + }); + + links.forEach(link => { + if (elemsMap[name1]) { + if (elemsMap[name2]) { + let name1 = link.classList[1]; + let name2 = link.classList[2]; + + let elem1 = elemsMap[name1]; + let elem2 = elemsMap[name2]; + + addItemToMapOfLists(linkedElems, name1, elem2); + addItemToMapOfLists(linkedElems, name2, elem1); + + addItemToMapOfLists(linkedLinks, name1, link); + addItemToMapOfLists(linkedLinks, name2, link); + } + } + }); + + let selectedElems = []; + let selectedLinks = []; + let selectedElemName = null; + + function clearSelected() { + selectedElems.forEach(item => { + item.classList.remove('selected'); + }); + selectedElems = []; + + selectedLinks.forEach(item => { + item.classList.remove('selected'); + }); + selectedLinks = []; + } + + function selectAll() { + selectedElemName = null; + + selectedElems = Array.from(elems); + selectedElems.forEach(item => { + item.classList.add('selected'); + }); + + selectedLinks = Array.from(links); + selectedLinks.forEach(item => { + item.classList.add('selected'); + }); + } + + function selectElem(elemName) { + if (elemName === selectedElemName) { + selectAll(); + + } else { + clearSelected(); + selectedElemName = elemName; + + elemsMap[elemName].classList.add('selected'); + selectedElems.push(elemsMap[elemName]); + + linkedElems[elemName].forEach(linkedElem => { + selectedElems.push(linkedElem); + linkedElem.classList.add('selected'); + }); + + linkedLinks[elemName].forEach(linkedLink => { + selectedLinks.push(linkedLink); + linkedLink.classList.add('selected'); + }); + } + } + + Object.keys(elemsMap).forEach(name => { + elemsMap[name].onclick = () => { selectElem(name); }; + }); + + selectAll(); +} + +document.addEventListener('DOMContentLoaded', (event) => { + main(); +}); \ No newline at end of file