diff --git a/gradle.properties b/gradle.properties index f329e3bb0..0d4293c8e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ # Warning, "version" should be the same in gradle.properties and Version.java # Any idea anyone how to magically synchronize those :-) ? -version = 1.2023.9beta2 +version = 1.2023.9beta3 org.gradle.workers.max = 3 \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/PSystemBuilder.java b/src/net/sourceforge/plantuml/PSystemBuilder.java index f98ddebb1..0a58f6492 100644 --- a/src/net/sourceforge/plantuml/PSystemBuilder.java +++ b/src/net/sourceforge/plantuml/PSystemBuilder.java @@ -70,6 +70,7 @@ import net.sourceforge.plantuml.eggs.PSystemWelcomeFactory; import net.sourceforge.plantuml.emoji.PSystemListEmojiFactory; import net.sourceforge.plantuml.error.PSystemError; import net.sourceforge.plantuml.error.PSystemErrorUtils; +import net.sourceforge.plantuml.filesdiagram.FilesDiagramFactory; import net.sourceforge.plantuml.flowdiagram.FlowDiagramFactory; import net.sourceforge.plantuml.font.PSystemListFontsFactory; import net.sourceforge.plantuml.gitlog.GitDiagramFactory; @@ -101,7 +102,6 @@ import net.sourceforge.plantuml.sudoku.PSystemSudokuFactory; import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.timingdiagram.TimingDiagramFactory; import net.sourceforge.plantuml.utils.Log; -import net.sourceforge.plantuml.version.License; import net.sourceforge.plantuml.version.PSystemLicenseFactory; import net.sourceforge.plantuml.version.PSystemVersionFactory; import net.sourceforge.plantuml.wbs.WBSDiagramFactory; @@ -251,6 +251,7 @@ public class PSystemBuilder { factories.add(new JsonDiagramFactory()); factories.add(new GitDiagramFactory()); // ::comment when __CORE__ + factories.add(new FilesDiagramFactory()); factories.add(new BoardDiagramFactory()); // ::done factories.add(new YamlDiagramFactory()); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBox.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBox.java index d12cbcfe4..0a71ad6e0 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBox.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBox.java @@ -181,6 +181,8 @@ public class FtileBox extends AbstractFtile { @Override public String toString() { + if (print == null) + return super.toString(); return print; } diff --git a/src/net/sourceforge/plantuml/command/CommandFactorySprite.java b/src/net/sourceforge/plantuml/command/CommandFactorySprite.java index 8b3293699..807a04133 100644 --- a/src/net/sourceforge/plantuml/command/CommandFactorySprite.java +++ b/src/net/sourceforge/plantuml/command/CommandFactorySprite.java @@ -105,9 +105,9 @@ public final class CommandFactorySprite implements SingleMultiFactoryCommand strings) { final StringBuilder sb = new StringBuilder(); - for (String s : strings) { + for (String s : strings) sb.append(StringUtils.trin(s)); - } + return sb.toString(); } diff --git a/src/net/sourceforge/plantuml/core/DiagramType.java b/src/net/sourceforge/plantuml/core/DiagramType.java index bfa4977ad..2b0e4a4e7 100644 --- a/src/net/sourceforge/plantuml/core/DiagramType.java +++ b/src/net/sourceforge/plantuml/core/DiagramType.java @@ -40,7 +40,7 @@ import net.sourceforge.plantuml.utils.StartUtils; public enum DiagramType { // ::remove folder when __HAXE__ UML, BPM, DITAA, DOT, PROJECT, JCCKIT, SALT, FLOW, CREOLE, JUNGLE, CUTE, MATH, LATEX, DEFINITION, GANTT, NW, - MINDMAP, WBS, WIRE, JSON, GIT, BOARD, YAML, HCL, EBNF, REGEX, UNKNOWN; + MINDMAP, WBS, WIRE, JSON, GIT, BOARD, YAML, HCL, EBNF, REGEX, FILES, UNKNOWN; static public DiagramType getTypeFromArobaseStart(String s) { s = s.toLowerCase(); @@ -125,6 +125,9 @@ public enum DiagramType { if (StartUtils.startsWithSymbolAnd("startregex", s)) return REGEX; + if (StartUtils.startsWithSymbolAnd("startfiles", s)) + return FILES; + return UNKNOWN; } } diff --git a/src/net/sourceforge/plantuml/filesdiagram/FilesDiagram.java b/src/net/sourceforge/plantuml/filesdiagram/FilesDiagram.java new file mode 100644 index 000000000..4398a99a0 --- /dev/null +++ b/src/net/sourceforge/plantuml/filesdiagram/FilesDiagram.java @@ -0,0 +1,85 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2024, Arnaud Roques + * + * Project Info: https://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * https://plantuml.com/patreon (only 1$ per month!) + * https://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.filesdiagram; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; + +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.klimt.shape.TextBlock; +import net.sourceforge.plantuml.skin.UmlDiagramType; +import net.sourceforge.plantuml.text.StringLocated; + +public class FilesDiagram extends UmlDiagram { + + private final FilesListing list; + + public FilesDiagram(UmlSource source) { + super(source, UmlDiagramType.FILES, null); + this.list = new FilesListing(getSkinParam()); + + final Iterator it = source.iterator2(); + it.next(); + while (true) { + final String line = it.next().getString(); + if (it.hasNext() == false) + break; + this.list.add(line); + } + + } + + public DiagramDescription getDescription() { + return new DiagramDescription("(Files)"); + } + + @Override + protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption) + throws IOException { + + return createImageBuilder(fileFormatOption).drawable(getTextBlock()).write(os); + } + + @Override + protected TextBlock getTextBlock() { + return list; + } + +} diff --git a/src/net/sourceforge/plantuml/filesdiagram/FilesDiagramFactory.java b/src/net/sourceforge/plantuml/filesdiagram/FilesDiagramFactory.java new file mode 100644 index 000000000..6d89177e0 --- /dev/null +++ b/src/net/sourceforge/plantuml/filesdiagram/FilesDiagramFactory.java @@ -0,0 +1,56 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2024, Arnaud Roques + * + * Project Info: https://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * https://plantuml.com/patreon (only 1$ per month!) + * https://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.filesdiagram; + +import java.util.Map; + +import net.sourceforge.plantuml.command.PSystemAbstractFactory; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.DiagramType; +import net.sourceforge.plantuml.core.UmlSource; + +public class FilesDiagramFactory extends PSystemAbstractFactory { + + public FilesDiagramFactory() { + super(DiagramType.FILES); + } + + @Override + public Diagram createSystem(UmlSource source, Map skinParam) { + return new FilesDiagram(source); + } + +} diff --git a/src/net/sourceforge/plantuml/filesdiagram/FilesListing.java b/src/net/sourceforge/plantuml/filesdiagram/FilesListing.java new file mode 100644 index 000000000..99be97712 --- /dev/null +++ b/src/net/sourceforge/plantuml/filesdiagram/FilesListing.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2024, Arnaud Roques + * + * Project Info: https://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * https://plantuml.com/patreon (only 1$ per month!) + * https://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.filesdiagram; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.klimt.UTranslate; +import net.sourceforge.plantuml.klimt.creole.Display; +import net.sourceforge.plantuml.klimt.drawing.UGraphic; +import net.sourceforge.plantuml.klimt.font.FontConfiguration; +import net.sourceforge.plantuml.klimt.font.StringBounder; +import net.sourceforge.plantuml.klimt.font.UFont; +import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment; +import net.sourceforge.plantuml.klimt.geom.XDimension2D; +import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock; +import net.sourceforge.plantuml.klimt.shape.TextBlock; +import net.sourceforge.plantuml.style.ISkinParam; + +public class FilesListing extends AbstractTextBlock { + + private final ISkinParam skinParam; + private final FontConfiguration fontConfiguration = FontConfiguration.blackBlueTrue(UFont.courier(14)); + private final List tmp = new ArrayList<>(); + + public FilesListing(ISkinParam skinParam) { + this.skinParam = skinParam; + } + + @Override + public XDimension2D calculateDimension(StringBounder stringBounder) { + return new XDimension2D(200, 200); + } + + @Override + public void drawU(UGraphic ug) { + for (String s : tmp) { + final Display display = Display.getWithNewlines("<:1f4c4:>" + s); + TextBlock result = display.create(fontConfiguration, HorizontalAlignment.LEFT, skinParam); + result.drawU(ug); + ug = ug.apply(UTranslate.dy(result.calculateDimension(ug.getStringBounder()).getHeight())); + } + + } + + public void add(String line) { + if (line.startsWith("/")) + tmp.add(line.substring(1)); + } + +} diff --git a/src/net/sourceforge/plantuml/gitlog/Commit.java b/src/net/sourceforge/plantuml/gitlog/Commit.java index d43a1dbf0..40647c46f 100644 --- a/src/net/sourceforge/plantuml/gitlog/Commit.java +++ b/src/net/sourceforge/plantuml/gitlog/Commit.java @@ -49,9 +49,9 @@ public class Commit { this.name = name; this.position = position; this.comment = position.getCommentInLine(); - if (position.matches("* ") == false && position.matches("*-") == false) { + if (position.matches("* ") == false && position.matches("*-") == false) throw new IllegalArgumentException(); - } + } public String getComment() { @@ -94,15 +94,15 @@ public class Commit { } private static void addAbove(List result, CursorPosition here) { - if (here.move(0, 1).matches("|")) { + if (here.move(0, 1).matches("|")) result.add(here.move(0, 1)); - } - if (here.move(1, 1).matches("\\")) { + + if (here.move(1, 1).matches("\\")) result.add(here.move(1, 1)); - } - if (here.move(-1, 1).matches("/")) { + + if (here.move(-1, 1).matches("/")) result.add(here.move(-1, 1)); - } + } public List getAncestors() { diff --git a/src/net/sourceforge/plantuml/gitlog/CursorPosition.java b/src/net/sourceforge/plantuml/gitlog/CursorPosition.java index cba73e656..9d85e85f2 100644 --- a/src/net/sourceforge/plantuml/gitlog/CursorPosition.java +++ b/src/net/sourceforge/plantuml/gitlog/CursorPosition.java @@ -61,43 +61,43 @@ public class CursorPosition { } public boolean matches(String prefix) { - if (x < 0) { + if (x < 0) return false; - } + final String line = getCurrentLine(); - if (x > line.length()) { + if (x > line.length()) return false; - } + return line.substring(x).startsWith(prefix); } public String getCommentInLine() { final String line = getCurrentLine(); final int x = line.indexOf("*"); - if (x == -1) { + if (x == -1) return null; - } + final int y = line.indexOf("(", x); - if (y == -1) { + if (y == -1) return null; - } + final int z = line.indexOf(")", y); - if (z == -1) { + if (z == -1) return null; - } + return line.substring(y + 1, z); } public static String getCommitNameInLine(String s) { final int x = s.indexOf("*"); - if (x == -1) { + if (x == -1) return null; - } + s = s.replaceAll("[-.*|/\\\\]", "").trim(); final int space = s.indexOf(" "); - if (space == -1) { + if (space == -1) return s; - } + final String name = s.substring(0, space); return name; } @@ -116,9 +116,9 @@ public class CursorPosition { private static CursorPosition getDownFromInternal(CursorPosition current) { while (true) { - if (current.matches("* ")) { + if (current.matches("* ")) return current; - } + if (current.matches("/") && current.move(-2, 0).matches("_|/")) { current = current.move(-2, 0); continue; diff --git a/src/net/sourceforge/plantuml/gitlog/GNodeBuilder.java b/src/net/sourceforge/plantuml/gitlog/GNodeBuilder.java index 136d9a9fd..f6fe1cb35 100644 --- a/src/net/sourceforge/plantuml/gitlog/GNodeBuilder.java +++ b/src/net/sourceforge/plantuml/gitlog/GNodeBuilder.java @@ -44,7 +44,7 @@ import java.util.List; import java.util.Map; public class GNodeBuilder { - // ::remove folder when __HAXE__ + // ::remove folder when __HAXE__ private final List all = new ArrayList<>(); @@ -58,11 +58,9 @@ public class GNodeBuilder { tmp.put(commit.getName(), node); } - for (Commit commit : allCommits) { - for (Commit parent : commit.getAncestors()) { + for (Commit commit : allCommits) + for (Commit parent : commit.getAncestors()) GNode.link(tmp.get(commit.getName()), tmp.get(parent.getName())); - } - } this.all.addAll(tmp.values()); @@ -82,9 +80,9 @@ public class GNodeBuilder { break; } } - if (changed == false) { + if (changed == false) return; - } + } } diff --git a/src/net/sourceforge/plantuml/gitlog/GitCurve.java b/src/net/sourceforge/plantuml/gitlog/GitCurve.java index 7f3b7fd31..61abe0db9 100644 --- a/src/net/sourceforge/plantuml/gitlog/GitCurve.java +++ b/src/net/sourceforge/plantuml/gitlog/GitCurve.java @@ -57,25 +57,24 @@ public class GitCurve { public GitCurve(ST_Agedgeinfo_t data, Mirror xMirror) { this.xMirror = xMirror; final ST_splines splines = data.spl; - if (splines.size != 1) { + if (splines.size != 1) throw new IllegalStateException(); - } + final ST_bezier beziers = splines.list.get__(0); for (int i = 0; i < beziers.size; i++) { final XPoint2D pt = getPoint(splines, i); points.add(pt); } - if (beziers.sp.x == 0 && beziers.sp.y == 0) { + if (beziers.sp.x == 0 && beziers.sp.y == 0) sp = null; - } else { + else sp = new XPoint2D(beziers.sp.x, beziers.sp.y); - } - if (beziers.ep.x == 0 && beziers.ep.y == 0) { + + if (beziers.ep.x == 0 && beziers.ep.y == 0) ep = null; - } else { + else ep = new XPoint2D(beziers.ep.x, beziers.ep.y); - } } diff --git a/src/net/sourceforge/plantuml/gitlog/GitTextArea.java b/src/net/sourceforge/plantuml/gitlog/GitTextArea.java index f49e8d004..ef37478d0 100644 --- a/src/net/sourceforge/plantuml/gitlog/GitTextArea.java +++ b/src/net/sourceforge/plantuml/gitlog/GitTextArea.java @@ -55,9 +55,9 @@ public class GitTextArea { final String name = CursorPosition.getCommitNameInLine(s); final int x = s.indexOf("*"); assert (name == null) == (x == -1); - if (x == -1) { + if (x == -1) continue; - } + commits.add(new Commit(name, new CursorPosition(this, x, y))); } @@ -69,18 +69,17 @@ public class GitTextArea { } public String getLine(int y) { - if (y >= lines.size()) { + if (y >= lines.size()) return ""; - } + return lines.get(y); } public Commit getCommitByName(String name) { - for (Commit commit : getAllCommits()) { - if (commit.getName().equals(name)) { + for (Commit commit : getAllCommits()) + if (commit.getName().equals(name)) return commit; - } - } + return null; } diff --git a/src/net/sourceforge/plantuml/klimt/color/HColorGradient.java b/src/net/sourceforge/plantuml/klimt/color/HColorGradient.java index ab94e92ed..843192429 100644 --- a/src/net/sourceforge/plantuml/klimt/color/HColorGradient.java +++ b/src/net/sourceforge/plantuml/klimt/color/HColorGradient.java @@ -63,13 +63,13 @@ public class HColorGradient extends HColor { return color2; } - public final Color getColor(ColorMapper mapper, double coeff) { + public final Color getColor(ColorMapper mapper, double coeff, int alpha) { if (coeff > 1 || coeff < 0) throw new IllegalArgumentException("c=" + coeff); final Color c1 = color1.toColor(mapper); final Color c2 = color2.toColor(mapper); - + final int diffRed = c2.getRed() - c1.getRed(); final int diffGreen = c2.getGreen() - c1.getGreen(); final int diffBlue = c2.getBlue() - c1.getBlue(); @@ -77,12 +77,12 @@ public class HColorGradient extends HColor { final int vRed = (int) (coeff * diffRed); final int vGreen = (int) (coeff * diffGreen); final int vBlue = (int) (coeff * diffBlue); - + final int red = c1.getRed() + vRed; final int green = c1.getGreen() + vGreen; final int blue = c1.getBlue() + vBlue; - return new Color(red, green, blue); + return new Color(red, green, blue, alpha); } diff --git a/src/net/sourceforge/plantuml/klimt/sprite/SpriteColor.java b/src/net/sourceforge/plantuml/klimt/sprite/SpriteColor.java index 683d21c42..fbd3d4eb3 100644 --- a/src/net/sourceforge/plantuml/klimt/sprite/SpriteColor.java +++ b/src/net/sourceforge/plantuml/klimt/sprite/SpriteColor.java @@ -99,7 +99,7 @@ public class SpriteColor implements Sprite { } public UImage toUImage(ColorMapper colorMapper, HColor backcolor, HColor forecolor) { - final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); if (backcolor == null) { backcolor = HColors.WHITE; @@ -113,7 +113,7 @@ public class SpriteColor implements Sprite { final int localColor = color[line][col]; if (localColor == -1) { final double coef = 1.0 * gray[line][col] / (16 - 1); - final Color c = gradient.getColor(colorMapper, coef); + final Color c = gradient.getColor(colorMapper, coef, 255); im.setRGB(col, line, c.getRGB()); } else { im.setRGB(col, line, localColor); diff --git a/src/net/sourceforge/plantuml/klimt/sprite/SpriteMonochrome.java b/src/net/sourceforge/plantuml/klimt/sprite/SpriteMonochrome.java index 81dd8b4e8..9dd8d63f2 100644 --- a/src/net/sourceforge/plantuml/klimt/sprite/SpriteMonochrome.java +++ b/src/net/sourceforge/plantuml/klimt/sprite/SpriteMonochrome.java @@ -184,26 +184,23 @@ public class SpriteMonochrome implements Sprite { if (color == null || color.isTransparent()) color = HColors.BLACK.withDark(HColors.WHITE); - final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final HColorGradient gradient = HColors.gradient(backcolor, color, '\0'); - for (int col = 0; col < width; col++) { - for (int line = 0; line < height; line++) { - final double coef = 1.0 * gray[line][col] / (grayLevel - 1); - final Color c = gradient.getColor(colorMapper, coef); - im.setRGB(col, line, c.getRGB()); - } - } - return new UImage(new PixelImage(im, AffineTransformType.TYPE_BILINEAR)); - } + double maxCoef = 0; + for (int col = 0; col < width; col++) + for (int line = 0; line < height; line++) + maxCoef = Math.max(maxCoef, 1.0 * gray[line][col] / (grayLevel - 1)); - private UImage special(ColorMapper colorMapper, HColorGradient backcolor, HColor color) { - final BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int col = 0; col < width; col++) { for (int line = 0; line < height; line++) { - final HColor backColorLocal = HColors.simple(backcolor.getColor(colorMapper, 1.0 * line / height)); - final HColorGradient gradient = HColors.gradient(backColorLocal, color, '\0'); - final double coef = 1.0 * gray[line][col] / (grayLevel - 1); - final Color c = gradient.getColor(colorMapper, coef); + final int grayValue = gray[line][col]; + final double coef = 1.0 * grayValue / (grayLevel - 1); + final int alpha; + if (coef > maxCoef / 4) + alpha = 255; + else + alpha = (int) (255 * (coef * 4 / maxCoef)); + final Color c = gradient.getColor(colorMapper, coef, alpha); im.setRGB(col, line, c.getRGB()); } } diff --git a/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java b/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java index 1af87b529..2df339cd8 100644 --- a/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java +++ b/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java @@ -118,6 +118,8 @@ public class NwDiagram extends UmlDiagram { @Override public void makeDiagramReady() { super.makeDiagramReady(); + if (networks.size() == 0) + createNetwork("").goInvisible(); for (NServer server : servers.values()) { server.connectMeIfAlone(networks.get(0)); playField.addInPlayfield(server.getBar()); @@ -179,11 +181,26 @@ public class NwDiagram extends UmlDiagram { return veryFirstLink(name1, name2); return CommandExecutionResult.error("what about " + name1); } + + if (server1.isAlone()) { + if (networks.size() == 0) + createNetwork("").goInvisible(); + server1.connectMeIfAlone(networks.get(0)); + } + + final Network tmp1 = server1.getMainNetworkNext(); + final Network justAfter = justAfter(tmp1); + + final Network network; + if (justAfter != null && justAfter.isVisible() == false) + network = justAfter; + else + network = createNetwork(""); + NServer server2 = servers.get(name2); - final Network network = createNetwork(""); + network.goInvisible(); if (server2 == null) { - // server2 = NServer.create(name2, getSkinParam()); server2 = new NServer(name2, server1.getBar(), getSkinParam()); servers.put(name2, server2); server1.connectTo(network, ""); @@ -199,6 +216,13 @@ public class NwDiagram extends UmlDiagram { return CommandExecutionResult.ok(); } + private Network justAfter(Network n) { + final int x = networks.indexOf(n); + if (x != -1 && x < networks.size() - 1) + return networks.get(x + 1); + return null; + } + private CommandExecutionResult veryFirstLink(String name1, String name2) { Network network = createNetwork(name1); NServer server2 = NServer.create(name2, getSkinParam()); @@ -208,45 +232,6 @@ public class NwDiagram extends UmlDiagram { return CommandExecutionResult.ok(); } - private CommandExecutionResult linkOld(String name1, String name2) { - if (initDone == false) - return errorNoInit(); - - String existingAddress = ""; - final NServer server2; - Network created = null; - if (currentNetwork() == null && networks.size() == 0) { - created = createNetwork(name1); - server2 = NServer.create(name2, getSkinParam()); - } else { - final NServer server1 = servers.get(name1); - final NServer previous2 = servers.get(name2); - if (previous2 != null) - existingAddress = previous2.someAddress(); - created = createNetwork(""); - created.goInvisible(); - if (server1 != null) { - final Network someNetwork = server1.someNetwork(); - if (someNetwork != null && someNetwork.isVisible() == false && someNetwork.getUp() == null) { - final String tmp = server1.someAddress(); - server1.blankSomeAddress(); - server1.connectTo(created, tmp); - } else { - server1.connectTo(created, ""); - } - } - - server2 = new NServer(name2, server1.getBar(), getSkinParam()); - } - servers.put(name2, server2); - if (created == null) - server2.connectTo(currentNetwork(), existingAddress); - else - server2.connectTo(created, existingAddress); - playField.addInPlayfield(server2.getBar()); - return CommandExecutionResult.ok(); - } - public CommandExecutionResult addElement(String name, String definition) { if (initDone == false) return errorNoInit(); @@ -269,6 +254,13 @@ public class NwDiagram extends UmlDiagram { } } + if (networks.size() == 0 || currentNetwork() == null) { + server.updateProperties(props); + server.learnThisAddress(props.get("address")); + return CommandExecutionResult.ok(); + + } + if (networks.size() == 0) { final Network network = createNetwork(""); network.goInvisible(); @@ -291,46 +283,6 @@ public class NwDiagram extends UmlDiagram { return CommandExecutionResult.ok(); } - private CommandExecutionResult addElementOld(String name, String definition) { - if (initDone == false) - return errorNoInit(); - - if (currentGroup() != null) { - if (alreadyInSomeGroup(name)) - return CommandExecutionResult.error("Element already in another group."); - - currentGroup().addName(name); - } - - NServer server = null; - Network created = null; - if (currentNetwork() == null) { - if (currentGroup() != null) - return CommandExecutionResult.ok(); - - assert currentGroup() == null; - created = createNetwork(""); - created.goInvisible(); - server = NServer.create(name, getSkinParam()); - servers.put(name, server); - server.doNotPrintFirstLink(); - } else { - server = servers.get(name); - if (server == null) { - server = NServer.create(name, getSkinParam()); - servers.put(name, server); - } - } - final Map props = toSet(definition); - if (created == null) - server.connectTo(currentNetwork(), props.get("address")); - else - server.connectTo(created, props.get("address")); - server.updateProperties(props); - playField.addInPlayfield(server.getBar()); - return CommandExecutionResult.ok(); - } - private boolean alreadyInSomeGroup(String name) { for (NwGroup g : groups) if (g.names().contains(name)) diff --git a/src/net/sourceforge/plantuml/nwdiag/core/NServer.java b/src/net/sourceforge/plantuml/nwdiag/core/NServer.java index 7af581576..9bba897a5 100644 --- a/src/net/sourceforge/plantuml/nwdiag/core/NServer.java +++ b/src/net/sourceforge/plantuml/nwdiag/core/NServer.java @@ -79,13 +79,17 @@ public class NServer { } public void connectMeIfAlone(Network network) { - if (connections.size() == 0) { + if (isAlone()) { connectTo(network, ""); if (network.isVisible() == false) this.doNotPrintFirstLink(); } } + public boolean isAlone() { + return connections.size() == 0; + } + public String someAddress() { if (connections.size() > 0 && connections.values().iterator().next().length() > 0) return connections.values().iterator().next(); diff --git a/src/net/sourceforge/plantuml/skin/UmlDiagramType.java b/src/net/sourceforge/plantuml/skin/UmlDiagramType.java index 0a718878d..3beaf0691 100644 --- a/src/net/sourceforge/plantuml/skin/UmlDiagramType.java +++ b/src/net/sourceforge/plantuml/skin/UmlDiagramType.java @@ -39,7 +39,7 @@ import net.sourceforge.plantuml.style.SName; public enum UmlDiagramType { SEQUENCE, STATE, CLASS, OBJECT, ACTIVITY, DESCRIPTION, COMPOSITE, FLOW, TIMING, BPM, NWDIAG, MINDMAP, WBS, WIRE, - HELP, GANTT, SALT, JSON, GIT, BOARD, YAML, HCL, EBNF, REGEX; + HELP, GANTT, SALT, JSON, GIT, BOARD, YAML, HCL, EBNF, REGEX, FILES; public SName getStyleName() { if (this == SEQUENCE) diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 664779c98..6eec116d6 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -46,7 +46,7 @@ public class Version { // Warning, "version" should be the same in gradle.properties and Version.java // Any idea anyone how to magically synchronize those :-) ? - private static final String version = "1.2023.9beta2"; + private static final String version = "1.2023.9beta3"; public static String versionString() { return version; diff --git a/test/net/sourceforge/plantuml/PipeTest.java b/test/net/sourceforge/plantuml/PipeTest.java index eacfc5554..d88c0cca7 100644 --- a/test/net/sourceforge/plantuml/PipeTest.java +++ b/test/net/sourceforge/plantuml/PipeTest.java @@ -159,8 +159,8 @@ class PipeTest { // no links/invalid input => no pipemap to output (no error as of // https://forum.plantuml.net/10049/2019-pipemap-diagrams-containing-links-give-zero-exit-code // ) - l.add(TestCase.of("-pipemap", "@startuml\na->b\n@enduml", "\n\n\n", Verification.EXACT, false, false)); - l.add(TestCase.of("-pipemap", "@startuml\na\n@enduml", "\n\n\n", Verification.EXACT, false, false)); + l.add(TestCase.of("-pipemap", "@startuml\na->b\n@enduml", "\n", Verification.EXACT, false, false)); + l.add(TestCase.of("-pipemap", "@startuml\na\n@enduml", "\n", Verification.EXACT, false, false)); return l; }