From 690fa349bac4bbb01efb9267db3f72d7d003c2db Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Wed, 1 Mar 2023 18:05:03 +0100 Subject: [PATCH] wip --- .../plantuml/nwdiag/NwDiagram.java | 67 ++++++++++++------- .../plantuml/nwdiag/core/NServer.java | 31 ++++++++- .../sourceforge/plantuml/version/Version.java | 2 +- 3 files changed, 74 insertions(+), 26 deletions(-) diff --git a/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java b/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java index 833450a5d..1af87b529 100644 --- a/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java +++ b/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java @@ -86,7 +86,6 @@ public class NwDiagram extends UmlDiagram { private final List networks = new ArrayList<>(); private final List groups = new ArrayList<>(); private final List stack = new ArrayList(); - // private NwGroup currentGroup = null; private final NPlayField playField = new NPlayField(); @@ -116,6 +115,15 @@ public class NwDiagram extends UmlDiagram { return null; } + @Override + public void makeDiagramReady() { + super.makeDiagramReady(); + for (NServer server : servers.values()) { + server.connectMeIfAlone(networks.get(0)); + playField.addInPlayfield(server.getBar()); + } + } + public CommandExecutionResult openGroup(String name) { if (initDone == false) return errorNoInit(); @@ -169,19 +177,24 @@ public class NwDiagram extends UmlDiagram { if (server1 == null) { if (networks.size() == 0) return veryFirstLink(name1, name2); - return CommandExecutionResult.error("what " + name1); + return CommandExecutionResult.error("what about " + name1); } 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); - Network network = createNetwork(""); - network.goInvisible(); - server2.connectTo(network, ""); server1.connectTo(network, ""); - playField.addInPlayfield(server2.getBar()); + server2.connectTo(network, ""); + } else { + server1.blankSomeAddress(); + server1.connectTo(network, server1.someAddress()); + server2.connectTo(network, server2.someAddress()); + } + playField.addInPlayfield(server2.getBar()); return CommandExecutionResult.ok(); } @@ -195,7 +208,7 @@ public class NwDiagram extends UmlDiagram { return CommandExecutionResult.ok(); } - public CommandExecutionResult linkOld(String name1, String name2) { + private CommandExecutionResult linkOld(String name1, String name2) { if (initDone == false) return errorNoInit(); @@ -238,39 +251,47 @@ public class NwDiagram extends UmlDiagram { if (initDone == false) return errorNoInit(); - if (currentGroup() != null) { - if (alreadyInSomeGroup(name)) - return CommandExecutionResult.error("Element already in another group."); - - currentGroup().addName(name); - if (currentNetwork() == null) - return CommandExecutionResult.ok(); - } - + final Map props = toSet(definition); NServer server = servers.get(name); if (server == null) { server = NServer.create(name, getSkinParam()); servers.put(name, server); } - final Map props = toSet(definition); + if (currentGroup() != null) { + if (alreadyInSomeGroup(name)) + return CommandExecutionResult.error("Element already in another group."); + + currentGroup().addName(name); + if (currentNetwork() == null) { + server.updateProperties(props); + return CommandExecutionResult.ok(); + } + } + if (networks.size() == 0) { - Network network = createNetwork(""); + final Network network = createNetwork(""); network.goInvisible(); server.connectTo(network, props.get("address")); + playField.addInPlayfield(server.getBar()); server.doNotPrintFirstLink(); } else { - if (networks.size() == 1) - server.connectTo(networks.get(0), props.get("address")); - else if (currentNetwork() != null) + /* + * if (networks.size() == 1) server.connectTo(networks.get(0), + * props.get("address")); else + */ + if (currentNetwork() != null) { server.connectTo(currentNetwork(), props.get("address")); + playField.addInPlayfield(server.getBar()); + } else { + server.learnThisAddress(props.get("address")); + } } server.updateProperties(props); - playField.addInPlayfield(server.getBar()); return CommandExecutionResult.ok(); } - public CommandExecutionResult addElementOld(String name, String definition) { + private CommandExecutionResult addElementOld(String name, String definition) { if (initDone == false) return errorNoInit(); diff --git a/src/net/sourceforge/plantuml/nwdiag/core/NServer.java b/src/net/sourceforge/plantuml/nwdiag/core/NServer.java index 0f7bc5e39..7af581576 100644 --- a/src/net/sourceforge/plantuml/nwdiag/core/NServer.java +++ b/src/net/sourceforge/plantuml/nwdiag/core/NServer.java @@ -37,6 +37,7 @@ package net.sourceforge.plantuml.nwdiag.core; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import net.sourceforge.plantuml.decoration.symbol.USymbol; import net.sourceforge.plantuml.decoration.symbol.USymbols; @@ -69,6 +70,7 @@ public class NServer { private String backcolor; private final NBar bar; private final ISkinParam skinParam; + private String declaredAddress; private boolean printFirstLink = true; @@ -76,9 +78,19 @@ public class NServer { this.printFirstLink = false; } + public void connectMeIfAlone(Network network) { + if (connections.size() == 0) { + connectTo(network, ""); + if (network.isVisible() == false) + this.doNotPrintFirstLink(); + } + } + public String someAddress() { - if (connections.size() > 0) + if (connections.size() > 0 && connections.values().iterator().next().length() > 0) return connections.values().iterator().next(); + if (declaredAddress != null) + return declaredAddress; return ""; } @@ -95,6 +107,16 @@ public class NServer { } } + public void learnThisAddress(String address) { + for (Entry ent : connections.entrySet()) { + if (ent.getValue().length() == 0) { + connections.put(ent.getKey(), address); + return; + } + } + + } + public final boolean printFirstLink() { return printFirstLink; } @@ -164,7 +186,12 @@ public class NServer { public void updateProperties(Map props) { if (props.get("description") != null) this.description = props.get("description"); - this.backcolor = props.get("color"); + + if (props.get("color") != null) + this.backcolor = props.get("color"); + + if (props.get("address") != null) + this.declaredAddress = props.get("address"); final String shape = props.get("shape"); if (shape != null) { diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 1c42b5182..344474bff 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -82,7 +82,7 @@ public class Version { } public static int beta() { - final int beta = 2; + final int beta = 4; return beta; }