From e1fe53457a75f7c315e8cb4981749268b2ace754 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Tue, 14 Sep 2021 19:26:18 +0200 Subject: [PATCH] Add shadowing for nwdiag and support for D+xx notation in gantt --- .../sourceforge/plantuml/UmlDiagramType.java | 3 + .../plantuml/nwdiag/NwDiagram.java | 30 +- .../plantuml/nwdiag/NwDiagramLegacy.java | 403 ------------------ .../plantuml/nwdiag/core/NServer.java | 49 ++- .../plantuml/nwdiag/core/Network.java | 2 +- .../plantuml/nwdiag/core/NwGroup.java | 8 +- .../plantuml/nwdiag/legacy/Footprint.java | 74 ---- .../plantuml/nwdiag/legacy/LinkedElement.java | 195 --------- .../plantuml/nwdiag/legacy/NServerLegacy.java | 98 ----- .../plantuml/nwdiag/legacy/NetworkLegacy.java | 88 ---- .../plantuml/nwdiag/legacy/NwArray.java | 91 ---- .../plantuml/nwdiag/legacy/NwGroupLegacy.java | 69 --- .../GridTextBlockDecorated.java | 67 ++- .../next/GridTextBlockDecoratedNext.java | 169 -------- .../{legacy => next}/GridTextBlockSimple.java | 16 +- .../nwdiag/next/GridTextBlockSimpleNext.java | 127 ------ ...kedElementNext.java => LinkedElement.java} | 10 +- .../plantuml/nwdiag/next/NPlayField.java | 2 +- .../next/{NwArrayNext.java => NwArray.java} | 14 +- .../plantuml/project/lang/ComplementDate.java | 28 +- .../project/lang/ComplementDates.java | 62 ++- .../project/lang/SubjectDayAsDate.java | 42 +- .../project/lang/SubjectDaysAsDates.java | 62 ++- src/net/sourceforge/plantuml/style/SName.java | 1 + .../sourceforge/plantuml/version/Version.java | 2 +- 25 files changed, 252 insertions(+), 1460 deletions(-) delete mode 100644 src/net/sourceforge/plantuml/nwdiag/NwDiagramLegacy.java delete mode 100644 src/net/sourceforge/plantuml/nwdiag/legacy/Footprint.java delete mode 100644 src/net/sourceforge/plantuml/nwdiag/legacy/LinkedElement.java delete mode 100644 src/net/sourceforge/plantuml/nwdiag/legacy/NServerLegacy.java delete mode 100644 src/net/sourceforge/plantuml/nwdiag/legacy/NetworkLegacy.java delete mode 100644 src/net/sourceforge/plantuml/nwdiag/legacy/NwArray.java delete mode 100644 src/net/sourceforge/plantuml/nwdiag/legacy/NwGroupLegacy.java rename src/net/sourceforge/plantuml/nwdiag/{legacy => next}/GridTextBlockDecorated.java (75%) delete mode 100644 src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockDecoratedNext.java rename src/net/sourceforge/plantuml/nwdiag/{legacy => next}/GridTextBlockSimple.java (94%) delete mode 100644 src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockSimpleNext.java rename src/net/sourceforge/plantuml/nwdiag/next/{LinkedElementNext.java => LinkedElement.java} (95%) rename src/net/sourceforge/plantuml/nwdiag/next/{NwArrayNext.java => NwArray.java} (87%) diff --git a/src/net/sourceforge/plantuml/UmlDiagramType.java b/src/net/sourceforge/plantuml/UmlDiagramType.java index a730bcb83..9c9bf6c89 100644 --- a/src/net/sourceforge/plantuml/UmlDiagramType.java +++ b/src/net/sourceforge/plantuml/UmlDiagramType.java @@ -84,6 +84,9 @@ public enum UmlDiagramType { if (this == TIMING) { return SName.timingDiagram; } + if (this == NWDIAG) { + return SName.nwdiagDiagram; + } return SName.activityDiagram; } } diff --git a/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java b/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java index fff7d9ae0..da88ab3df 100644 --- a/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java +++ b/src/net/sourceforge/plantuml/nwdiag/NwDiagram.java @@ -66,8 +66,8 @@ import net.sourceforge.plantuml.graphic.UDrawable; import net.sourceforge.plantuml.nwdiag.core.NServer; import net.sourceforge.plantuml.nwdiag.core.Network; import net.sourceforge.plantuml.nwdiag.core.NwGroup; -import net.sourceforge.plantuml.nwdiag.next.GridTextBlockDecoratedNext; -import net.sourceforge.plantuml.nwdiag.next.LinkedElementNext; +import net.sourceforge.plantuml.nwdiag.next.GridTextBlockDecorated; +import net.sourceforge.plantuml.nwdiag.next.LinkedElement; import net.sourceforge.plantuml.nwdiag.next.NBar; import net.sourceforge.plantuml.nwdiag.next.NPlayField; import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft; @@ -127,7 +127,7 @@ public class NwDiagram extends UmlDiagram { } private Network createNetwork(String name) { - final Network network = new Network(playField.getLast(), playField.createNewStage(), name, networks.size()); + final Network network = new Network(playField.getLast(), playField.createNewStage(), name); networks.add(network); return network; } @@ -139,7 +139,7 @@ public class NwDiagram extends UmlDiagram { final NServer element; if (currentNetwork() == null) { createNetwork(name1); - element = new NServer(name2, currentNetwork(), this.getSkinParam()); + element = new NServer(name2); } else { final NServer already = servers.get(name1); final Network network1 = createNetwork(""); @@ -147,7 +147,7 @@ public class NwDiagram extends UmlDiagram { if (already != null) { connect(already, toSet(null)); } - element = new NServer(name2, currentNetwork(), this.getSkinParam()); + element = new NServer(name2); } servers.put(name2, element); addInternal(element, toSet(null)); @@ -186,13 +186,13 @@ public class NwDiagram extends UmlDiagram { assert currentGroup == null; final Network network1 = createNetwork(""); network1.goInvisible(); - server = new NServer(name, currentNetwork(), this.getSkinParam()); + server = new NServer(name); servers.put(name, server); - server.doNotHaveItsOwnColumn(); + server.doNotPrintFirstLink(); } else { server = servers.get(name); if (server == null) { - server = new NServer(name, currentNetwork(), this.getSkinParam()); + server = new NServer(name); servers.put(name, server); } } @@ -291,7 +291,7 @@ public class NwDiagram extends UmlDiagram { double deltaX = 0; double deltaY = 0; - final GridTextBlockDecoratedNext grid = buildGrid(stringBounder); + final GridTextBlockDecorated grid = buildGrid(stringBounder); for (int i = 0; i < networks.size(); i++) { final Network current = networks.get(i); @@ -299,7 +299,7 @@ public class NwDiagram extends UmlDiagram { final TextBlock desc = toTextBlock(current.getDisplayName(), address); final Dimension2D dim = desc.calculateDimension(stringBounder); if (i == 0) { - deltaY = (dim.getHeight() - GridTextBlockDecoratedNext.NETWORK_THIN) / 2; + deltaY = (dim.getHeight() - GridTextBlockDecorated.NETWORK_THIN) / 2; } deltaX = Math.max(deltaX, dim.getWidth()); } @@ -335,11 +335,11 @@ public class NwDiagram extends UmlDiagram { return result; } - private GridTextBlockDecoratedNext buildGrid(StringBounder stringBounder) { + private GridTextBlockDecorated buildGrid(StringBounder stringBounder) { playField.fixGroups(groups, servers.values()); - final GridTextBlockDecoratedNext grid = new GridTextBlockDecoratedNext(networks.size(), servers.size(), groups, + final GridTextBlockDecorated grid = new GridTextBlockDecorated(networks.size(), servers.size(), groups, networks, getSkinParam()); final Map layout = playField.doLayout(); @@ -350,11 +350,11 @@ public class NwDiagram extends UmlDiagram { if (server.getMainNetworkNext() == current) { final Map conns = getLinks(server); final int col = layout.get(server.getBar()); - double topMargin = LinkedElementNext.MAGIC; + double topMargin = LinkedElement.MAGIC; NwGroup group = getGroupOf(server); if (group != null) topMargin += group.getTopHeaderHeight(stringBounder, getSkinParam()); - grid.add(i, col, server.asTextBlockNext(topMargin, conns, networks, getSkinParam())); + grid.add(i, col, server.asTextBlock(topMargin, conns, networks, getSkinParam())); } } } @@ -364,7 +364,7 @@ public class NwDiagram extends UmlDiagram { private NwGroup getGroupOf(NServer server) { for (NwGroup group : groups) { - if (group.containsNext(server)) { + if (group.contains(server)) { return group; } } diff --git a/src/net/sourceforge/plantuml/nwdiag/NwDiagramLegacy.java b/src/net/sourceforge/plantuml/nwdiag/NwDiagramLegacy.java deleted file mode 100644 index 32744a5a5..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/NwDiagramLegacy.java +++ /dev/null @@ -1,403 +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.nwdiag; - -import java.awt.geom.Dimension2D; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormatOption; -import net.sourceforge.plantuml.SpriteContainerEmpty; -import net.sourceforge.plantuml.UmlDiagram; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.core.DiagramDescription; -import net.sourceforge.plantuml.core.ImageData; -import net.sourceforge.plantuml.core.UmlSource; -import net.sourceforge.plantuml.cucadiagram.Display; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignment; -import net.sourceforge.plantuml.graphic.InnerStrategy; -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.graphic.TextBlockUtils; -import net.sourceforge.plantuml.graphic.UDrawable; -import net.sourceforge.plantuml.nwdiag.core.NServer; -import net.sourceforge.plantuml.nwdiag.core.Network; -import net.sourceforge.plantuml.nwdiag.core.NwGroup; -import net.sourceforge.plantuml.nwdiag.legacy.GridTextBlockDecorated; -import net.sourceforge.plantuml.nwdiag.legacy.NServerLegacy; -import net.sourceforge.plantuml.nwdiag.legacy.NetworkLegacy; -import net.sourceforge.plantuml.nwdiag.legacy.NwGroupLegacy; -import net.sourceforge.plantuml.nwdiag.next.NPlayField; -import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft; -import net.sourceforge.plantuml.svek.TextBlockBackcolored; -import net.sourceforge.plantuml.ugraphic.MinMax; -import net.sourceforge.plantuml.ugraphic.UEmpty; -import net.sourceforge.plantuml.ugraphic.UFont; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.UTranslate; -import net.sourceforge.plantuml.ugraphic.color.HColor; -import net.sourceforge.plantuml.ugraphic.color.HColorUtils; - -public class NwDiagramLegacy extends UmlDiagram { - - private boolean initDone; - private final Map servers = new LinkedHashMap<>(); - private final List networks = new ArrayList<>(); - private final List groups = new ArrayList<>(); - private NwGroup currentGroup = null; - - private final NPlayField playField = new NPlayField(); - - public DiagramDescription getDescription() { - return new DiagramDescription("(Nwdiag)"); - } - - public NwDiagramLegacy(UmlSource source) { - super(source, UmlDiagramType.NWDIAG); - } - - public void init() { - initDone = true; - } - - private Network currentNetwork() { - if (networks.size() == 0) { - return null; - } - return networks.get(networks.size() - 1); - } - - public CommandExecutionResult openGroup(String name) { - if (initDone == false) { - return errorNoInit(); - } - currentGroup = new NwGroupLegacy(name, currentNetwork()); - groups.add(currentGroup); - return CommandExecutionResult.ok(); - } - - public CommandExecutionResult openNetwork(String name) { - if (initDone == false) { - return errorNoInit(); - } - createNetwork(name); - return CommandExecutionResult.ok(); - } - - private Network createNetwork(String name) { - final Network network = new NetworkLegacy(playField.createNewStage(), name, networks.size()); - networks.add(network); - return network; - } - - public CommandExecutionResult link(String name1, String name2) { - if (initDone == false) { - return errorNoInit(); - } - final NServer element; - if (currentNetwork() == null) { - createNetwork(name1); - element = new NServerLegacy(name2, currentNetwork(), this.getSkinParam()); - } else { - final NServer already = servers.get(name1); - final Network network1 = createNetwork(""); - network1.goInvisible(); - if (already != null) { - connect(already, toSet(null)); - } - element = new NServerLegacy(name2, currentNetwork(), this.getSkinParam()); - ((NServerLegacy)element).sameColThan(already); - } - servers.put(name2, element); - addInternal(element, toSet(null)); - return CommandExecutionResult.ok(); - } - - private void addInternal(NServer server, Map props) { - connect(server, props); - final String description = props.get("description"); - if (description != null) { - server.setDescription(description); - } - final String shape = props.get("shape"); - if (shape != null) { - server.setShape(shape); - } - } - - private void connect(NServer server, final Map props) { - ((NetworkLegacy) currentNetwork()).addServer(Objects.requireNonNull((NServerLegacy) server), props); - server.connect(currentNetwork(), props); - } - - public CommandExecutionResult addElement(String name, String definition) { - if (initDone == false) { - return errorNoInit(); - } - if (currentGroup != null) { - currentGroup.addName(name); - } - NServer server = null; - if (currentNetwork() == null) { - if (currentGroup != null) { - return CommandExecutionResult.ok(); - } - assert currentGroup == null; - final Network network1 = createNetwork(""); - network1.goInvisible(); - server = new NServerLegacy(name, currentNetwork(), this.getSkinParam()); - servers.put(name, server); - ((NServerLegacy) server).doNotHaveItsOwnColumn(); - } else { - server = servers.get(name); - if (server == null) { - server = new NServerLegacy(name, currentNetwork(), this.getSkinParam()); - servers.put(name, server); - } - } - addInternal(server, toSet(definition)); - return CommandExecutionResult.ok(); - } - - public CommandExecutionResult endSomething() { - if (initDone == false) { - return errorNoInit(); - } - this.currentGroup = null; - return CommandExecutionResult.ok(); - } - - private CommandExecutionResult errorNoInit() { - return CommandExecutionResult.error("Maybe you forget 'nwdiag {' in your diagram ?"); - } - - private Map toSet(String definition) { - final Map result = new HashMap(); - if (definition == null) { - return result; - } - final Pattern p = Pattern.compile("\\s*(\\w+)\\s*=\\s*(\"([^\"]*)\"|[^\\s,]+)"); - final Matcher m = p.matcher(definition); - while (m.find()) { - final String name = m.group(1); - final String value = m.group(3) == null ? m.group(2) : m.group(3); - result.put(name, value); - } - return result; - - } - - @Override - protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption) - throws IOException { - - return createImageBuilder(fileFormatOption).drawable(getTextBlock()).write(os); - } - - private TextBlockBackcolored getTextBlock() { - return new TextBlockBackcolored() { - public void drawU(UGraphic ug) { - drawMe(ug); - } - - public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) { - return null; - } - - public Dimension2D calculateDimension(StringBounder stringBounder) { - return getTotalDimension(stringBounder); - } - - public MinMax getMinMax(StringBounder stringBounder) { - throw new UnsupportedOperationException(); - } - - public HColor getBackcolor() { - return null; - } - - }; - } - - private TextBlock toTextBlock(String name, String s) { - if (s != null) { - name += "\\n" + s; - } - return Display.getWithNewlines(name).create(getFontConfiguration(), HorizontalAlignment.RIGHT, - new SpriteContainerEmpty()); - } - - private FontConfiguration getFontConfiguration() { - final UFont font = UFont.serif(11); - return new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false); - } - - private Dimension2D getTotalDimension(StringBounder stringBounder) { - return TextBlockUtils.getMinMax(new UDrawable() { - public void drawU(UGraphic ug) { - drawMe(ug); - } - }, stringBounder, true).getDimension(); - } - - private final double margin = 5; - - private void drawMe(UGraphic ug) { - ug = ug.apply(new UTranslate(margin, margin)); - - final StringBounder stringBounder = ug.getStringBounder(); - final GridTextBlockDecorated grid = buildGrid(); - - double deltaX = 0; - double deltaY = 0; - for (int i = 0; i < networks.size(); i++) { - final Network current = networks.get(i); - final String address = current.getOwnAdress(); - final TextBlock desc = toTextBlock(current.getDisplayName(), address); - final Dimension2D dim = desc.calculateDimension(stringBounder); - if (i == 0) { - deltaY = (dim.getHeight() - GridTextBlockDecorated.NETWORK_THIN) / 2; - } - deltaX = Math.max(deltaX, dim.getWidth()); - } - double y = 0; - for (int i = 0; i < networks.size(); i++) { - final Network current = networks.get(i); - final String address = current.getOwnAdress(); - final TextBlock desc = toTextBlock(current.getDisplayName(), address); - final Dimension2D dim = desc.calculateDimension(stringBounder); - desc.drawU(ug.apply(new UTranslate(deltaX - dim.getWidth(), y))); - - y += grid.lineHeight(stringBounder, i); - } - deltaX += 5; - - grid.drawU(ug.apply(ColorParam.activityBorder.getDefaultValue()) - .apply(ColorParam.activityBackground.getDefaultValue().bg()).apply(new UTranslate(deltaX, deltaY))); - final Dimension2D dimGrid = grid.calculateDimension(stringBounder); - - ug.apply(new UTranslate(dimGrid.getWidth() + deltaX + margin, dimGrid.getHeight() + deltaY + margin)) - .draw(new UEmpty(1, 1)); - - } - - private Map getLinks(NServer element) { - final Map result = new LinkedHashMap<>(); - for (Network network1 : networks) { - final NetworkLegacy network = (NetworkLegacy) network1; - final String s = network.getAdress(element); - if (s != null) { - result.put(network, s); - } - } - return result; - } - - private GridTextBlockDecorated buildGrid() { - final GridTextBlockDecorated grid = new GridTextBlockDecorated(networks.size(), servers.size(), groups, - networks, getSkinParam()); - - for (int i = 0; i < networks.size(); i++) { - final NetworkLegacy current = (NetworkLegacy) networks.get(i); - int j = 0; - for (Map.Entry ent : servers.entrySet()) { - final NServerLegacy square = (NServerLegacy) ent.getValue(); - if (square.getMainNetwork() == current) { - final Map conns = getLinks(square); - final NServerLegacy sameCol = square.getSameCol(); - if (sameCol != null) { - square.setNumCol(sameCol.getNumCol()); - } else { - square.setNumCol(j); - } - grid.add(i, square.getNumCol(), square.asTextBlock(conns, networks)); - } - if (square.hasItsOwnColumn()) { - j++; - } - } - } - - grid.checkGroups(); - - return grid; - } - - public CommandExecutionResult setProperty(String property, String value) { - if (initDone == false) { - return errorNoInit(); - } - if ("address".equalsIgnoreCase(property) && currentNetwork() != null) { - currentNetwork().setOwnAdress(value); - } - if ("width".equalsIgnoreCase(property) && currentNetwork() != null) { - currentNetwork().setFullWidth("full".equalsIgnoreCase(value)); - } - if ("color".equalsIgnoreCase(property)) { - final HColor color = value == null ? null - : NwGroup.colors.getColorOrWhite(getSkinParam().getThemeStyle(), value); - if (currentGroup != null) { - currentGroup.setColor(color); - } else if (currentNetwork() != null) { - currentNetwork().setColor(color); - } - } - if ("description".equalsIgnoreCase(property)) { - if (currentGroup == null) { - currentNetwork().setDescription(value); - } else { - currentGroup.setDescription(value); - } - } - return CommandExecutionResult.ok(); - } - - @Override - public ClockwiseTopRightBottomLeft getDefaultMargins() { - return ClockwiseTopRightBottomLeft.none(); - } -} diff --git a/src/net/sourceforge/plantuml/nwdiag/core/NServer.java b/src/net/sourceforge/plantuml/nwdiag/core/NServer.java index 2d879587f..4109d47a9 100644 --- a/src/net/sourceforge/plantuml/nwdiag/core/NServer.java +++ b/src/net/sourceforge/plantuml/nwdiag/core/NServer.java @@ -41,6 +41,7 @@ import java.util.Map.Entry; import net.sourceforge.plantuml.ColorParam; import net.sourceforge.plantuml.ComponentStyle; +import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.ISkinSimple; import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.FontConfiguration; @@ -49,9 +50,15 @@ import net.sourceforge.plantuml.graphic.SymbolContext; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.USymbol; -import net.sourceforge.plantuml.nwdiag.next.LinkedElementNext; +import net.sourceforge.plantuml.mindmap.IdeaShape; +import net.sourceforge.plantuml.nwdiag.next.LinkedElement; import net.sourceforge.plantuml.nwdiag.next.NBar; import net.sourceforge.plantuml.skin.ActorStyle; +import net.sourceforge.plantuml.style.PName; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.style.StyleBuilder; +import net.sourceforge.plantuml.style.StyleSignature; import net.sourceforge.plantuml.svek.PackageStyle; import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.color.HColorUtils; @@ -65,15 +72,14 @@ public class NServer { private String description; private final NBar bar = new NBar(); - // To be renamed in "printFirstLink" - private boolean hasItsOwnColumn = true; + private boolean printFirstLink = true; - public void doNotHaveItsOwnColumn() { - this.hasItsOwnColumn = false; + public void doNotPrintFirstLink() { + this.printFirstLink = false; } - public final boolean hasItsOwnColumn() { - return hasItsOwnColumn; + public final boolean printFirstLink() { + return printFirstLink; } public Network getMainNetworkNext() { @@ -95,18 +101,30 @@ public class NServer { return Display.getWithNewlines(s).create(getFontConfiguration(), HorizontalAlignment.LEFT, spriteContainer); } - public LinkedElementNext asTextBlockNext(double topMargin, Map conns, List networks, - ISkinSimple spriteContainer) { + private StyleSignature getStyleDefinition() { + return StyleSignature.of(SName.root, SName.element, SName.nwdiagDiagram, SName.node); + } + + public LinkedElement asTextBlock(double topMargin, Map conns, List networks, + ISkinParam skinParam) { + double deltaShadow = 3; + final StyleBuilder styleBuilder = skinParam.getCurrentStyleBuilder(); + if (styleBuilder != null) { + final Style style = getStyleDefinition().getMergedStyle(styleBuilder); + deltaShadow = style.value(PName.Shadowing).asDouble(); + } + final Map conns2 = new LinkedHashMap(); for (Entry ent : conns.entrySet()) { - conns2.put(ent.getKey(), toTextBlock(ent.getValue(), spriteContainer)); + conns2.put(ent.getKey(), toTextBlock(ent.getValue(), skinParam)); } + final SymbolContext symbolContext = new SymbolContext(ColorParam.activityBackground.getDefaultValue(), - ColorParam.activityBorder.getDefaultValue()).withShadow(3); - final TextBlock desc = toTextBlock(getDescription(), spriteContainer); + ColorParam.activityBorder.getDefaultValue()).withShadow(deltaShadow); + final TextBlock desc = toTextBlock(getDescription(), skinParam); final TextBlock box = getShape().asSmall(TextBlockUtils.empty(0, 0), desc, TextBlockUtils.empty(0, 0), symbolContext, HorizontalAlignment.CENTER); - return new LinkedElementNext(topMargin, this, box, conns2, networks); + return new LinkedElement(topMargin, this, box, conns2, networks); } public void connect(Network network, Map props) { @@ -138,11 +156,6 @@ public class NServer { this.name = name; } - public NServer(String name, Object... unused) { - this.description = name; - this.name = name; - } - protected final FontConfiguration getFontConfiguration() { final UFont font = UFont.serif(11); return new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false); diff --git a/src/net/sourceforge/plantuml/nwdiag/core/Network.java b/src/net/sourceforge/plantuml/nwdiag/core/Network.java index fc7eb249f..b7bf8915d 100644 --- a/src/net/sourceforge/plantuml/nwdiag/core/Network.java +++ b/src/net/sourceforge/plantuml/nwdiag/core/Network.java @@ -72,7 +72,7 @@ public class Network { return up; } - public Network(NStage up, NStage nstage, String name, Object... unused) { + public Network(NStage up, NStage nstage, String name) { this.up = up; this.name = name; this.nstage = nstage; diff --git a/src/net/sourceforge/plantuml/nwdiag/core/NwGroup.java b/src/net/sourceforge/plantuml/nwdiag/core/NwGroup.java index 70e575ba9..c103b94aa 100644 --- a/src/net/sourceforge/plantuml/nwdiag/core/NwGroup.java +++ b/src/net/sourceforge/plantuml/nwdiag/core/NwGroup.java @@ -47,7 +47,6 @@ import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.nwdiag.next.LinkedElementNext; import net.sourceforge.plantuml.nwdiag.next.NBox; import net.sourceforge.plantuml.ugraphic.MinMax; import net.sourceforge.plantuml.ugraphic.UFont; @@ -129,12 +128,7 @@ public class NwGroup { return Collections.unmodifiableSet(names); } - public boolean matches(LinkedElementNext tested) { - // To be merged with containsNext - return names().contains(tested.getElement().getName()); - } - - public boolean containsNext(NServer server) { + public boolean contains(NServer server) { return names.contains(server.getName()); } diff --git a/src/net/sourceforge/plantuml/nwdiag/legacy/Footprint.java b/src/net/sourceforge/plantuml/nwdiag/legacy/Footprint.java deleted file mode 100644 index a17ab310e..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/legacy/Footprint.java +++ /dev/null @@ -1,74 +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.nwdiag.legacy; - -public class Footprint { - - private final int min; - private final int max; - - public Footprint(int min, int max) { - if (max < min) { - throw new IllegalArgumentException(); - } - assert max >= min; - this.min = min; - this.max = max; - } - - @Override - public String toString() { - return "" + min + " -> " + max; - } - - public Footprint intersection(Footprint other) { - if (this.max < other.min) { - return null; - } - if (this.min > other.max) { - return null; - } - return new Footprint(Math.max(this.min, other.min), Math.min(this.max, other.max)); - } - - public final int getMin() { - return min; - } - - public final int getMax() { - return max; - } - -} diff --git a/src/net/sourceforge/plantuml/nwdiag/legacy/LinkedElement.java b/src/net/sourceforge/plantuml/nwdiag/legacy/LinkedElement.java deleted file mode 100644 index 07b14f8c1..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/legacy/LinkedElement.java +++ /dev/null @@ -1,195 +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.nwdiag.legacy; - -import java.awt.geom.Dimension2D; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeSet; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.nwdiag.VerticalLine; -import net.sourceforge.plantuml.ugraphic.MinMax; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.UTranslate; -import net.sourceforge.plantuml.ugraphic.color.HColor; -import net.sourceforge.plantuml.utils.MathUtils; - -public class LinkedElement { - - private final TextBlock box; - private final NetworkLegacy network; - private final NServerLegacy square; - private final Map conns; - private final List networks; - - public LinkedElement(NServerLegacy square, TextBlock box, Map conns, List networks) { - this.networks = networks; - this.box = box; - this.network = square.getMainNetwork(); - this.square = square; - this.conns = conns; - } - - public boolean isLinkedTo(NetworkLegacy some) { - return conns.containsKey(some); - } - - private final double marginAd = 10; - private final double marginBox = 15; - - public MinMax getMinMax(StringBounder stringBounder, double width, double height) { - final double xMiddle = width / 2; - final double yMiddle = height / 2; - final Dimension2D dimBox = box.calculateDimension(stringBounder); - - final double x1 = xMiddle - dimBox.getWidth() / 2; - final double y1 = yMiddle - dimBox.getHeight() / 2; - final double x2 = xMiddle + dimBox.getWidth() / 2; - final double y2 = yMiddle + dimBox.getHeight() / 2; - return MinMax.getEmpty(false).addPoint(x1 - 5, y1 - 5).addPoint(x2 + 5, y2 + 5); - } - - public void drawMe(UGraphic ug, double width, double height) { - final double xMiddle = width / 2; - final double yMiddle = height / 2; - drawCenter(ug, box, xMiddle, yMiddle); - } - - public void drawLinks(UGraphic ug, double xstart, double width, double height) { - - ug = ug.apply(UTranslate.dx(xstart)); - - final double ynet1 = network.getY(); - final double yMiddle = height / 2; - final StringBounder stringBounder = ug.getStringBounder(); - final Dimension2D dimBox = box.calculateDimension(stringBounder); - - final double alpha = yMiddle - dimBox.getHeight() / 2; - - final HColor color = ColorParam.activityBorder.getDefaultValue(); - ug = ug.apply(color); - - final double xMiddle = width / 2; - - final TreeSet skip = new TreeSet<>(); - - for (NetworkLegacy n : networks) { - if (xstart + xMiddle > n.getXmin() && xstart + xMiddle < n.getXmax()) - skip.add(n.getY()); - } - - if (square.hasItsOwnColumn()) { - if (square.getMainNetwork().isVisible()) { - new VerticalLine(ynet1 + GridTextBlockDecorated.NETWORK_THIN, ynet1 + alpha, skip) - .drawU(ug.apply(UTranslate.dx(xMiddle))); - } else { - new VerticalLine(ynet1, ynet1 + alpha, Collections.emptySet()) - .drawU(ug.apply(UTranslate.dx(xMiddle))); - } - } - drawCenter(ug, link1(), xMiddle, ynet1 + alpha / 2); - - final double seven = 7.0; - double x = xMiddle - (conns.size() - 2) * seven / 2; - boolean first = true; - for (Entry ent : conns.entrySet()) { - if (ent.getKey() == network) { - continue; - } - final double ynet2 = ent.getKey().getY(); - new VerticalLine(ynet1 + yMiddle + dimBox.getHeight() / 2, ynet2, skip).drawU(ug.apply(UTranslate.dx(x))); - final double xtext; - if (first && conns.size() > 2) { - xtext = x - ent.getValue().calculateDimension(stringBounder).getWidth() / 2; - } else { - xtext = x; - } - drawCenter(ug, ent.getValue(), xtext, ynet2 - alpha / 2); - x += seven; - first = false; - - } - - } - - private TextBlock link1() { - return conns.get(network); - } - - private TextBlock link2() { - final int i = networks.indexOf(network); - if (i == networks.size() - 1) { - return null; - } - return conns.get(networks.get(i + 1)); - } - - private void drawCenter(UGraphic ug, TextBlock block, double x, double y) { - if (block == null) { - return; - } - final Dimension2D dim = block.calculateDimension(ug.getStringBounder()); - block.drawU(ug.apply(new UTranslate(x - dim.getWidth() / 2, y - dim.getHeight() / 2))); - - } - - public Dimension2D naturalDimension(StringBounder stringBounder) { - final Dimension2D dim1 = link1() == null ? new Dimension2DDouble(0, 0) - : link1().calculateDimension(stringBounder); - final Dimension2D dimBox = box.calculateDimension(stringBounder); - final Dimension2D dim2 = link2() == null ? new Dimension2DDouble(0, 0) - : link2().calculateDimension(stringBounder); - final double width = MathUtils.max(dim1.getWidth() + 2 * marginAd, dimBox.getWidth() + 2 * marginBox, - dim2.getWidth() + 2 * marginAd); - final double height = dim1.getHeight() + 2 * marginAd + dimBox.getHeight() + 2 * marginBox + dim2.getHeight() - + 2 * marginAd; - return new Dimension2DDouble(width, height); - } - - public final NetworkLegacy getNetwork() { - return network; - } - - public final NServerLegacy getElement() { - return square; - } - -} diff --git a/src/net/sourceforge/plantuml/nwdiag/legacy/NServerLegacy.java b/src/net/sourceforge/plantuml/nwdiag/legacy/NServerLegacy.java deleted file mode 100644 index 78ba99c96..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/legacy/NServerLegacy.java +++ /dev/null @@ -1,98 +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.nwdiag.legacy; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.ISkinSimple; -import net.sourceforge.plantuml.graphic.HorizontalAlignment; -import net.sourceforge.plantuml.graphic.SymbolContext; -import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.graphic.TextBlockUtils; -import net.sourceforge.plantuml.nwdiag.core.NServer; -import net.sourceforge.plantuml.nwdiag.core.Network; - -public class NServerLegacy extends NServer { - - private final NetworkLegacy mainNetwork; - private final ISkinSimple spriteContainer; - private NServerLegacy sameCol; - - public NServerLegacy(String name, Network network, ISkinSimple spriteContainer) { - super(name); - this.mainNetwork = (NetworkLegacy) network; - this.spriteContainer = spriteContainer; - } - - public LinkedElement asTextBlock(Map conns, List networks) { - final Map conns2 = new LinkedHashMap(); - for (Entry ent : conns.entrySet()) { - conns2.put(ent.getKey(), toTextBlock(ent.getValue(), spriteContainer)); - } - final SymbolContext symbolContext = new SymbolContext(ColorParam.activityBackground.getDefaultValue(), - ColorParam.activityBorder.getDefaultValue()).withShadow(3); - final TextBlock desc = toTextBlock(getDescription(), spriteContainer); - final TextBlock box = getShape().asSmall(TextBlockUtils.empty(0, 0), desc, TextBlockUtils.empty(0, 0), - symbolContext, HorizontalAlignment.CENTER); - return new LinkedElement(this, box, conns2, networks); - } - - public final NetworkLegacy getMainNetwork() { - return mainNetwork; - } - - public void sameColThan(NServer sameCol) { - this.sameCol = (NServerLegacy) sameCol; - } - - public final NServerLegacy getSameCol() { - return sameCol; - } - - private int numCol = -1; - - public void setNumCol(int j) { - this.numCol = j; - } - - public final int getNumCol() { - return numCol; - } - -} diff --git a/src/net/sourceforge/plantuml/nwdiag/legacy/NetworkLegacy.java b/src/net/sourceforge/plantuml/nwdiag/legacy/NetworkLegacy.java deleted file mode 100644 index 6e60be33c..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/legacy/NetworkLegacy.java +++ /dev/null @@ -1,88 +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.nwdiag.legacy; - -import java.util.LinkedHashMap; -import java.util.Map; - -import net.sourceforge.plantuml.nwdiag.core.NServer; -import net.sourceforge.plantuml.nwdiag.core.Network; -import net.sourceforge.plantuml.nwdiag.next.NStage; - -public class NetworkLegacy extends Network { - - private final Map localServers = new LinkedHashMap(); - private final int stage; - - @Override - public String toString() { - return super.toString() + "(" + stage + ")"; - } - - public NetworkLegacy(NStage nstage, String name, int stage) { - super(null, nstage, name); - this.stage = stage; - } - - public String getAdress(NServer server) { - return localServers.get(server); - } - - public void addServer(NServerLegacy server, Map props) { - String address = props.get("address"); - if (address == null) { - address = ""; - } - if (address.length() == 0 && localServers.containsKey(server)) { - return; - } - localServers.put(server, address); - } - - public boolean constainsLocally(String name) { - for (NServerLegacy server : localServers.keySet()) { - if (server.getName().equals(name)) { - return true; - } - } - return false; - } - - public final int getStage() { - return stage; - } - - -} diff --git a/src/net/sourceforge/plantuml/nwdiag/legacy/NwArray.java b/src/net/sourceforge/plantuml/nwdiag/legacy/NwArray.java deleted file mode 100644 index d04f9435f..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/legacy/NwArray.java +++ /dev/null @@ -1,91 +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.nwdiag.legacy; - -public class NwArray { - - private final LinkedElement data[][]; - - public NwArray(int lines, int cols) { - this.data = new LinkedElement[lines][cols]; - } - - public int getNbLines() { - return data.length; - } - - public int getNbCols() { - return data[0].length; - } - - public LinkedElement get(int i, int j) { - return data[i][j]; - } - - public LinkedElement[] getLine(int i) { - return data[i]; - } - - public void set(int i, int j, LinkedElement value) { - data[i][j] = value; - } - - public void swapCols(int col1, int col2) { - if (col1 == col2) { - throw new IllegalArgumentException(); - } - for (int i = 0; i < getNbLines(); i++) { - final LinkedElement tmp = data[i][col1]; - data[i][col1] = data[i][col2]; - data[i][col2] = tmp; - } - - } - - public Footprint getFootprint(NwGroupLegacy group) { - int min = Integer.MAX_VALUE; - int max = Integer.MIN_VALUE; - for (int i = 0; i < getNbLines(); i++) { - for (int j = 0; j < getNbCols(); j++) { - if (data[i][j] != null && group.matches(data[i][j])) { - min = Math.min(min, j); - max = Math.max(max, j); - } - } - } - return new Footprint(min, max); - } - -} diff --git a/src/net/sourceforge/plantuml/nwdiag/legacy/NwGroupLegacy.java b/src/net/sourceforge/plantuml/nwdiag/legacy/NwGroupLegacy.java deleted file mode 100644 index 1614a4024..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/legacy/NwGroupLegacy.java +++ /dev/null @@ -1,69 +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.nwdiag.legacy; - -import net.sourceforge.plantuml.nwdiag.core.Network; -import net.sourceforge.plantuml.nwdiag.core.NwGroup; - -public class NwGroupLegacy extends NwGroup { - - private final NetworkLegacy network; - - @Override - public String toString() { - return getName() + " " + network + " " + names(); - } - - public NwGroupLegacy(String name, Network network) { - super(name); - this.network = (NetworkLegacy) network; - } - - public int size() { - return names().size(); - } - - public boolean matches(LinkedElement tested) { - if (network != null && network != tested.getNetwork()) { - return false; - } - return names().contains(tested.getElement().getName()); - } - - public final NetworkLegacy getNetwork() { - return network; - } - -} diff --git a/src/net/sourceforge/plantuml/nwdiag/legacy/GridTextBlockDecorated.java b/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockDecorated.java similarity index 75% rename from src/net/sourceforge/plantuml/nwdiag/legacy/GridTextBlockDecorated.java rename to src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockDecorated.java index 797210efa..42e0919e1 100644 --- a/src/net/sourceforge/plantuml/nwdiag/legacy/GridTextBlockDecorated.java +++ b/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockDecorated.java @@ -32,12 +32,19 @@ * Original Author: Arnaud Roques * */ -package net.sourceforge.plantuml.nwdiag.legacy; +package net.sourceforge.plantuml.nwdiag.next; import java.util.List; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.nwdiag.core.Network; +import net.sourceforge.plantuml.nwdiag.core.NwGroup; +import net.sourceforge.plantuml.style.PName; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.style.StyleBuilder; +import net.sourceforge.plantuml.style.StyleSignature; import net.sourceforge.plantuml.ugraphic.MinMax; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.URectangle; @@ -47,11 +54,10 @@ public class GridTextBlockDecorated extends GridTextBlockSimple { public static final int NETWORK_THIN = 5; - private final List groups; - private final List networks; + private final List groups; + private final List networks; - @SuppressWarnings({ "unchecked", "rawtypes" }) - public GridTextBlockDecorated(int lines, int cols, List groups, List networks, + public GridTextBlockDecorated(int lines, int cols, List groups, List networks, ISkinParam skinparam) { super(lines, cols, skinparam); this.groups = groups; @@ -60,8 +66,8 @@ public class GridTextBlockDecorated extends GridTextBlockSimple { @Override protected void drawGrid(UGraphic ug) { - for (NwGroupLegacy group : groups) { - drawGroups(ug, group, skinparam); + for (NwGroup group : groups) { + drawGroups(ug, group, getSkinParam()); } drawNetworkTube(ug); drawLinks(ug); @@ -83,7 +89,7 @@ public class GridTextBlockDecorated extends GridTextBlockSimple { } - private void drawGroups(UGraphic ug, NwGroupLegacy group, ISkinParam skinParam) { + private void drawGroups(UGraphic ug, NwGroup group, ISkinParam skinParam) { final StringBounder stringBounder = ug.getStringBounder(); MinMax size = null; @@ -94,7 +100,7 @@ public class GridTextBlockDecorated extends GridTextBlockSimple { for (int j = 0; j < data.getNbCols(); j++) { final double colWidth = colWidth(stringBounder, j); final LinkedElement element = data.get(i, j); - if (element != null && group.matches(element)) { + if (element != null && group.contains(element.getServer())) { final MinMax minMax = element.getMinMax(stringBounder, colWidth, lineHeight) .translate(new UTranslate(x, y)); size = size == null ? minMax : size.addMinMax(minMax); @@ -109,7 +115,7 @@ public class GridTextBlockDecorated extends GridTextBlockSimple { } - private boolean isThereALink(int j, NetworkLegacy network) { + private boolean isThereALink(int j, Network network) { for (int i = 0; i < data.getNbLines(); i++) { final LinkedElement element = data.get(i, j); if (element != null && element.isLinkedTo(network)) { @@ -119,16 +125,27 @@ public class GridTextBlockDecorated extends GridTextBlockSimple { return false; } + private StyleSignature getStyleDefinition() { + return StyleSignature.of(SName.root, SName.element, SName.nwdiagDiagram, SName.node); + } + private void drawNetworkTube(final UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); double y = 0; for (int i = 0; i < data.getNbLines(); i++) { - final NetworkLegacy network = getNetwork(i); + final Network network = getNetwork(i); computeMixMax(data.getLine(i), stringBounder, network); final URectangle rect = new URectangle(network.getXmax() - network.getXmin(), NETWORK_THIN); - rect.setDeltaShadow(1.0); + double deltaShadow = 1.0; + final StyleBuilder styleBuilder = getSkinParam().getCurrentStyleBuilder(); + if (styleBuilder != null) { + final Style style = getStyleDefinition().getMergedStyle(styleBuilder); + deltaShadow = style.value(PName.Shadowing).asDouble(); + } + + rect.setDeltaShadow(deltaShadow); UGraphic ug2 = ug.apply(new UTranslate(network.getXmin(), y)); if (network != null && network.getColor() != null) { ug2 = ug2.apply(network.getColor().bg()); @@ -143,7 +160,7 @@ public class GridTextBlockDecorated extends GridTextBlockSimple { } } - private void computeMixMax(LinkedElement line[], StringBounder stringBounder, NetworkLegacy network) { + private void computeMixMax(LinkedElement line[], StringBounder stringBounder, Network network) { double x = 0; double xmin = network.isFullWidth() ? 0 : -1; double xmax = 0; @@ -161,30 +178,8 @@ public class GridTextBlockDecorated extends GridTextBlockSimple { } - private NetworkLegacy getNetwork(int i) { + private Network getNetwork(int i) { return networks.get(i); } - public void checkGroups() { - for (int i = 0; i < groups.size(); i++) { - for (int j = i + 1; j < groups.size(); j++) { - final NwGroupLegacy group1 = groups.get(i); - final NwGroupLegacy group2 = groups.get(j); - if (group1.size() == 0 || group2.size() == 0) { - continue; - } - if (group1.getNetwork() != group2.getNetwork()) { - continue; - } - final Footprint footprint1 = getFootprint(group1); - final Footprint footprint2 = getFootprint(group2); - final Footprint inter = footprint1.intersection(footprint2); - if (inter != null) { - data.swapCols(inter.getMin(), inter.getMax()); - return; - } - } - } - - } } diff --git a/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockDecoratedNext.java b/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockDecoratedNext.java deleted file mode 100644 index 4b2758124..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockDecoratedNext.java +++ /dev/null @@ -1,169 +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.nwdiag.next; - -import java.util.List; - -import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.nwdiag.core.Network; -import net.sourceforge.plantuml.nwdiag.core.NwGroup; -import net.sourceforge.plantuml.ugraphic.MinMax; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.URectangle; -import net.sourceforge.plantuml.ugraphic.UTranslate; - -public class GridTextBlockDecoratedNext extends GridTextBlockSimpleNext { - - public static final int NETWORK_THIN = 5; - - private final List groups; - private final List networks; - - public GridTextBlockDecoratedNext(int lines, int cols, List groups, List networks, - ISkinParam skinparam) { - super(lines, cols, skinparam); - this.groups = groups; - this.networks = networks; - } - - @Override - protected void drawGrid(UGraphic ug) { - for (NwGroup group : groups) { - drawGroups(ug, group, skinparam); - } - drawNetworkTube(ug); - drawLinks(ug); - } - - private void drawLinks(UGraphic ug) { - final StringBounder stringBounder = ug.getStringBounder(); - for (int i = 0; i < data.getNbLines(); i++) { - final double lineHeight = lineHeight(stringBounder, i); - double x = 0; - for (int j = 0; j < data.getNbCols(); j++) { - final double colWidth = colWidth(stringBounder, j); - if (data.get(i, j) != null) { - data.get(i, j).drawLinks(ug, x, colWidth, lineHeight); - } - x += colWidth; - } - } - - } - - private void drawGroups(UGraphic ug, NwGroup group, ISkinParam skinParam) { - final StringBounder stringBounder = ug.getStringBounder(); - - MinMax size = null; - double y = 0; - for (int i = 0; i < data.getNbLines(); i++) { - final double lineHeight = lineHeight(stringBounder, i); - double x = 0; - for (int j = 0; j < data.getNbCols(); j++) { - final double colWidth = colWidth(stringBounder, j); - final LinkedElementNext element = data.get(i, j); - if (element != null && group.matches(element)) { - final MinMax minMax = element.getMinMax(stringBounder, colWidth, lineHeight) - .translate(new UTranslate(x, y)); - size = size == null ? minMax : size.addMinMax(minMax); - } - x += colWidth; - } - y += lineHeight; - } - if (size != null) { - group.drawGroup(ug, size, skinParam); - } - - } - - private boolean isThereALink(int j, Network network) { - for (int i = 0; i < data.getNbLines(); i++) { - final LinkedElementNext element = data.get(i, j); - if (element != null && element.isLinkedTo(network)) { - return true; - } - } - return false; - } - - private void drawNetworkTube(final UGraphic ug) { - - final StringBounder stringBounder = ug.getStringBounder(); - double y = 0; - for (int i = 0; i < data.getNbLines(); i++) { - final Network network = getNetwork(i); - computeMixMax(data.getLine(i), stringBounder, network); - - final URectangle rect = new URectangle(network.getXmax() - network.getXmin(), NETWORK_THIN); - rect.setDeltaShadow(1.0); - UGraphic ug2 = ug.apply(new UTranslate(network.getXmin(), y)); - if (network != null && network.getColor() != null) { - ug2 = ug2.apply(network.getColor().bg()); - } - if (network != null) { - network.setY(y); - } - if (network.isVisible()) { - ug2.draw(rect); - } - y += lineHeight(stringBounder, i); - } - } - - private void computeMixMax(LinkedElementNext line[], StringBounder stringBounder, Network network) { - double x = 0; - double xmin = network.isFullWidth() ? 0 : -1; - double xmax = 0; - for (int j = 0; j < line.length; j++) { - final boolean hline = isThereALink(j, network); - if (hline && xmin < 0) { - xmin = x; - } - x += colWidth(stringBounder, j); - if (hline || network.isFullWidth()) { - xmax = x; - } - } - network.setMinMax(xmin, xmax); - - } - - private Network getNetwork(int i) { - return networks.get(i); - } - -} diff --git a/src/net/sourceforge/plantuml/nwdiag/legacy/GridTextBlockSimple.java b/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockSimple.java similarity index 94% rename from src/net/sourceforge/plantuml/nwdiag/legacy/GridTextBlockSimple.java rename to src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockSimple.java index 80df3b93d..e4c70d4cd 100644 --- a/src/net/sourceforge/plantuml/nwdiag/legacy/GridTextBlockSimple.java +++ b/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockSimple.java @@ -32,7 +32,7 @@ * Original Author: Arnaud Roques * */ -package net.sourceforge.plantuml.nwdiag.legacy; +package net.sourceforge.plantuml.nwdiag.next; import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; @@ -49,10 +49,10 @@ import net.sourceforge.plantuml.ugraphic.UTranslate; public class GridTextBlockSimple implements TextBlock { protected final NwArray data; - protected final ISkinParam skinparam; + private final ISkinParam skinParam; - public GridTextBlockSimple(int lines, int cols, ISkinParam skinparam) { - this.skinparam = skinparam; + public GridTextBlockSimple(int lines, int cols, ISkinParam skinParam) { + this.skinParam = skinParam; this.data = new NwArray(lines, cols); } @@ -123,9 +123,11 @@ public class GridTextBlockSimple implements TextBlock { public void add(int i, int j, LinkedElement value) { data.set(i, j, value); } - - public Footprint getFootprint(NwGroupLegacy group) { - return data.getFootprint(group); + + protected final ISkinParam getSkinParam() { + return skinParam; } + + } diff --git a/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockSimpleNext.java b/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockSimpleNext.java deleted file mode 100644 index 39b538db1..000000000 --- a/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockSimpleNext.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.nwdiag.next; - -import java.awt.geom.Dimension2D; -import java.awt.geom.Rectangle2D; - -import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.graphic.InnerStrategy; -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.ugraphic.MinMax; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.UTranslate; - -public class GridTextBlockSimpleNext implements TextBlock { - - protected final NwArrayNext data; - protected final ISkinParam skinparam; - - public GridTextBlockSimpleNext(int lines, int cols, ISkinParam skinparam) { - this.skinparam = skinparam; - this.data = new NwArrayNext(lines, cols); - } - - protected void drawGrid(UGraphic ug) { - } - - public void drawU(UGraphic ug) { - drawGrid(ug); - final StringBounder stringBounder = ug.getStringBounder(); - double y = 0; - for (int i = 0; i < data.getNbLines(); i++) { - final double lineHeight = lineHeight(stringBounder, i); - double x = 0; - for (int j = 0; j < data.getNbCols(); j++) { - final double colWidth = colWidth(stringBounder, j); - if (data.get(i, j) != null) { - data.get(i, j).drawMe(ug.apply(new UTranslate(x, y)), colWidth, lineHeight); - } - x += colWidth; - } - y += lineHeight; - } - } - - protected double colWidth(StringBounder stringBounder, final int j) { - double width = 0; - for (int i = 0; i < data.getNbLines(); i++) { - if (data.get(i, j) != null) { - width = Math.max(width, data.get(i, j).naturalDimension(stringBounder).getWidth()); - } - } - return width; - } - - public double lineHeight(StringBounder stringBounder, final int i) { - double height = 50; - for (int j = 0; j < data.getNbCols(); j++) { - if (data.get(i, j) != null) { - height = Math.max(height, data.get(i, j).naturalDimension(stringBounder).getHeight()); - } - } - return height; - } - - public Dimension2D calculateDimension(StringBounder stringBounder) { - if (data.getNbLines() == 0) { - return new Dimension2DDouble(0, 0); - } - double height = 0; - for (int i = 0; i < data.getNbLines(); i++) { - height += lineHeight(stringBounder, i); - } - double width = 0; - for (int j = 0; j < data.getNbCols(); j++) { - width += colWidth(stringBounder, j); - } - return new Dimension2DDouble(width, height); - } - - public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) { - throw new UnsupportedOperationException("member=" + member + " " + getClass().toString()); - } - - public MinMax getMinMax(StringBounder stringBounder) { - throw new UnsupportedOperationException(getClass().toString()); - } - - public void add(int i, int j, LinkedElementNext value) { - data.set(i, j, value); - } - -} diff --git a/src/net/sourceforge/plantuml/nwdiag/next/LinkedElementNext.java b/src/net/sourceforge/plantuml/nwdiag/next/LinkedElement.java similarity index 95% rename from src/net/sourceforge/plantuml/nwdiag/next/LinkedElementNext.java rename to src/net/sourceforge/plantuml/nwdiag/next/LinkedElement.java index c75170dd1..cb0efdb10 100644 --- a/src/net/sourceforge/plantuml/nwdiag/next/LinkedElementNext.java +++ b/src/net/sourceforge/plantuml/nwdiag/next/LinkedElement.java @@ -54,7 +54,7 @@ import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.utils.MathUtils; -public class LinkedElementNext { +public class LinkedElement { public static final int MAGIC = 15; @@ -65,7 +65,7 @@ public class LinkedElementNext { private final List networks; private final double topMargin; - public LinkedElementNext(double topMargin, NServer server, TextBlock box, Map conns, + public LinkedElement(double topMargin, NServer server, TextBlock box, Map conns, List networks) { this.topMargin = topMargin; this.networks = networks; @@ -132,9 +132,9 @@ public class LinkedElementNext { skip.add(n.getY()); } - if (server.hasItsOwnColumn()) { + if (server.printFirstLink()) { if (network.isVisible()) { - new VerticalLine(ynet1 + GridTextBlockDecoratedNext.NETWORK_THIN, ynet1 + alpha, skip) + new VerticalLine(ynet1 + GridTextBlockDecorated.NETWORK_THIN, ynet1 + alpha, skip) .drawU(ug.apply(UTranslate.dx(xLinkPos + network.magicDelta()))); } else { new VerticalLine(ynet1, ynet1 + alpha, Collections.emptySet()) @@ -205,7 +205,7 @@ public class LinkedElementNext { return network; } - public final NServer getElement() { + public final NServer getServer() { return server; } diff --git a/src/net/sourceforge/plantuml/nwdiag/next/NPlayField.java b/src/net/sourceforge/plantuml/nwdiag/next/NPlayField.java index da6281168..08d9a420d 100644 --- a/src/net/sourceforge/plantuml/nwdiag/next/NPlayField.java +++ b/src/net/sourceforge/plantuml/nwdiag/next/NPlayField.java @@ -104,7 +104,7 @@ public class NPlayField { public void fixGroups(List groups, Collection servers) { for (NwGroup group : groups) { for (NServer server : servers) { - if (group.containsNext(server)) { + if (group.contains(server)) { fixServerInGroup(server, group); } } diff --git a/src/net/sourceforge/plantuml/nwdiag/next/NwArrayNext.java b/src/net/sourceforge/plantuml/nwdiag/next/NwArray.java similarity index 87% rename from src/net/sourceforge/plantuml/nwdiag/next/NwArrayNext.java rename to src/net/sourceforge/plantuml/nwdiag/next/NwArray.java index 10be3cec0..bfb998054 100644 --- a/src/net/sourceforge/plantuml/nwdiag/next/NwArrayNext.java +++ b/src/net/sourceforge/plantuml/nwdiag/next/NwArray.java @@ -34,12 +34,12 @@ */ package net.sourceforge.plantuml.nwdiag.next; -public class NwArrayNext { +public class NwArray { - private final LinkedElementNext data[][]; + private final LinkedElement data[][]; - public NwArrayNext(int lines, int cols) { - this.data = new LinkedElementNext[lines][cols]; + public NwArray(int lines, int cols) { + this.data = new LinkedElement[lines][cols]; } public int getNbLines() { @@ -50,15 +50,15 @@ public class NwArrayNext { return data[0].length; } - public LinkedElementNext get(int i, int j) { + public LinkedElement get(int i, int j) { return data[i][j]; } - public LinkedElementNext[] getLine(int i) { + public LinkedElement[] getLine(int i) { return data[i]; } - public void set(int i, int j, LinkedElementNext value) { + public void set(int i, int j, LinkedElement value) { data[i][j] = value; } diff --git a/src/net/sourceforge/plantuml/project/lang/ComplementDate.java b/src/net/sourceforge/plantuml/project/lang/ComplementDate.java index 764e3a71b..0b828ef1d 100644 --- a/src/net/sourceforge/plantuml/project/lang/ComplementDate.java +++ b/src/net/sourceforge/plantuml/project/lang/ComplementDate.java @@ -48,7 +48,7 @@ import net.sourceforge.plantuml.project.time.Month; public class ComplementDate implements Something { public IRegex toRegex(String suffix) { - return new RegexOr(toRegexA(suffix), toRegexB(suffix), toRegexC(suffix), toRegexD(suffix)); + return new RegexOr(toRegexA(suffix), toRegexB(suffix), toRegexC(suffix), toRegexD(suffix), toRegexE(suffix)); } private IRegex toRegexA(String suffix) { @@ -90,6 +90,13 @@ public class ComplementDate implements Something { ); } + private IRegex toRegexE(String suffix) { + return new RegexConcat( // + new RegexLeaf("[dD]\\+"), // + new RegexLeaf("ECOUNT" + suffix, "([\\d]+)") // + ); + } + public Failable getMe(GanttDiagram system, RegexResult arg, String suffix) { if (arg.get("ADAY" + suffix, 0) != null) { return Failable.ok(resultA(arg, suffix)); @@ -103,14 +110,12 @@ public class ComplementDate implements Something { if (arg.get("DCOUNT" + suffix, 0) != null) { return Failable.ok(resultD(system, arg, suffix)); } + if (arg.get("ECOUNT" + suffix, 0) != null) { + return Failable.ok(resultE(system, arg, suffix)); + } throw new IllegalStateException(); } - private Day resultD(GanttDiagram system, RegexResult arg, String suffix) { - final int day = Integer.parseInt(arg.get("DCOUNT" + suffix, 0)); - return system.getStartingDate().addDays(day); - } - private Day resultA(RegexResult arg, String suffix) { final int day = Integer.parseInt(arg.get("ADAY" + suffix, 0)); final String month = arg.get("AMONTH" + suffix, 0); @@ -131,4 +136,15 @@ public class ComplementDate implements Something { final int year = Integer.parseInt(arg.get("CYEAR" + suffix, 0)); return Day.create(year, month, day); } + + private Day resultD(GanttDiagram system, RegexResult arg, String suffix) { + final int day = Integer.parseInt(arg.get("DCOUNT" + suffix, 0)); + return system.getStartingDate().addDays(day); + } + + private Day resultE(GanttDiagram system, RegexResult arg, String suffix) { + final int day = Integer.parseInt(arg.get("ECOUNT" + suffix, 0)); + return system.getStartingDate().addDays(day); + } + } diff --git a/src/net/sourceforge/plantuml/project/lang/ComplementDates.java b/src/net/sourceforge/plantuml/project/lang/ComplementDates.java index 8e512071d..978a58624 100644 --- a/src/net/sourceforge/plantuml/project/lang/ComplementDates.java +++ b/src/net/sourceforge/plantuml/project/lang/ComplementDates.java @@ -38,6 +38,7 @@ package net.sourceforge.plantuml.project.lang; 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.RegexOr; import net.sourceforge.plantuml.command.regex.RegexResult; import net.sourceforge.plantuml.project.DaysAsDates; import net.sourceforge.plantuml.project.Failable; @@ -47,37 +48,72 @@ import net.sourceforge.plantuml.project.time.Day; public class ComplementDates implements Something { public IRegex toRegex(String suffix) { + return new RegexOr(toRegexB(suffix), toRegexE(suffix)); + } + + private IRegex toRegexB(String suffix) { return new RegexConcat( // - new RegexLeaf("YEAR1" + suffix, "([\\d]{4})"), // + new RegexLeaf("BYEAR1" + suffix, "([\\d]{4})"), // new RegexLeaf("\\D"), // - new RegexLeaf("MONTH1" + suffix, "([\\d]{1,2})"), // + new RegexLeaf("BMONTH1" + suffix, "([\\d]{1,2})"), // new RegexLeaf("\\D"), // - new RegexLeaf("DAY1" + suffix, "([\\d]{1,2})"), // + new RegexLeaf("BDAY1" + suffix, "([\\d]{1,2})"), // RegexLeaf.spaceOneOrMore(), // new RegexLeaf("to"), // RegexLeaf.spaceOneOrMore(), // - new RegexLeaf("YEAR2" + suffix, "([\\d]{4})"), // + new RegexLeaf("BYEAR2" + suffix, "([\\d]{4})"), // new RegexLeaf("\\D"), // - new RegexLeaf("MONTH2" + suffix, "([\\d]{1,2})"), // + new RegexLeaf("BMONTH2" + suffix, "([\\d]{1,2})"), // new RegexLeaf("\\D"), // - new RegexLeaf("DAY2" + suffix, "([\\d]{1,2})") // + new RegexLeaf("BDAY2" + suffix, "([\\d]{1,2})") // + ); + } + private IRegex toRegexE(String suffix) { + return new RegexConcat( // + new RegexLeaf("[dD]\\+"), // + new RegexLeaf("ECOUNT1" + suffix, "([\\d]+)"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("to"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("[dD]\\+"), // + new RegexLeaf("ECOUNT2" + suffix, "([\\d]+)") // ); } public Failable getMe(GanttDiagram project, RegexResult arg, String suffix) { + if (arg.get("BDAY1" + suffix, 0) != null) { + return Failable.ok(resultB(arg, suffix)); + } + if (arg.get("ECOUNT1" + suffix, 0) != null) { + return Failable.ok(resultE(project, arg, suffix)); + } + throw new IllegalStateException(); - final int day1 = Integer.parseInt(arg.get("DAY1" + suffix, 0)); - final int month1 = Integer.parseInt(arg.get("MONTH1" + suffix, 0)); - final int year1 = Integer.parseInt(arg.get("YEAR1" + suffix, 0)); + } + + private DaysAsDates resultB(RegexResult arg, String suffix) { + final int day1 = Integer.parseInt(arg.get("BDAY1" + suffix, 0)); + final int month1 = Integer.parseInt(arg.get("BMONTH1" + suffix, 0)); + final int year1 = Integer.parseInt(arg.get("BYEAR1" + suffix, 0)); final Day date1 = Day.create(year1, month1, day1); - final int day2 = Integer.parseInt(arg.get("DAY2" + suffix, 0)); - final int month2 = Integer.parseInt(arg.get("MONTH2" + suffix, 0)); - final int year2 = Integer.parseInt(arg.get("YEAR2" + suffix, 0)); + final int day2 = Integer.parseInt(arg.get("BDAY2" + suffix, 0)); + final int month2 = Integer.parseInt(arg.get("BMONTH2" + suffix, 0)); + final int year2 = Integer.parseInt(arg.get("BYEAR2" + suffix, 0)); final Day date2 = Day.create(year2, month2, day2); - return Failable.ok(new DaysAsDates(date1, date2)); + return new DaysAsDates(date1, date2); + } + + private DaysAsDates resultE(GanttDiagram project, RegexResult arg, String suffix) { + final int day1 = Integer.parseInt(arg.get("ECOUNT1" + suffix, 0)); + final Day date1 = project.getStartingDate().addDays(day1); + + final int day2 = Integer.parseInt(arg.get("ECOUNT2" + suffix, 0)); + final Day date2 = project.getStartingDate().addDays(day2); + + return new DaysAsDates(date1, date2); } } diff --git a/src/net/sourceforge/plantuml/project/lang/SubjectDayAsDate.java b/src/net/sourceforge/plantuml/project/lang/SubjectDayAsDate.java index f8d043186..48e058db4 100644 --- a/src/net/sourceforge/plantuml/project/lang/SubjectDayAsDate.java +++ b/src/net/sourceforge/plantuml/project/lang/SubjectDayAsDate.java @@ -42,6 +42,7 @@ import net.sourceforge.plantuml.command.CommandExecutionResult; 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.RegexOr; import net.sourceforge.plantuml.command.regex.RegexResult; import net.sourceforge.plantuml.project.Failable; import net.sourceforge.plantuml.project.GanttDiagram; @@ -51,10 +52,26 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class SubjectDayAsDate implements Subject { public Failable getMe(GanttDiagram project, RegexResult arg) { - final int day = Integer.parseInt(arg.get("DAY", 0)); - final int month = Integer.parseInt(arg.get("MONTH", 0)); - final int year = Integer.parseInt(arg.get("YEAR", 0)); - return Failable.ok(Day.create(year, month, day)); + if (arg.get("BDAY", 0) != null) { + return Failable.ok(resultB(arg)); + } + if (arg.get("ECOUNT", 0) != null) { + return Failable.ok(resultE(project, arg)); + } + throw new IllegalStateException(); + + } + + private Day resultB(RegexResult arg) { + final int day = Integer.parseInt(arg.get("BDAY", 0)); + final int month = Integer.parseInt(arg.get("BMONTH", 0)); + final int year = Integer.parseInt(arg.get("BYEAR", 0)); + return Day.create(year, month, day); + } + + private Day resultE(GanttDiagram system, RegexResult arg) { + final int day = Integer.parseInt(arg.get("ECOUNT", 0)); + return system.getStartingDate().addDays(day); } public Collection getSentences() { @@ -102,12 +119,23 @@ public class SubjectDayAsDate implements Subject { } public IRegex toRegex() { + return new RegexOr(toRegexB(), toRegexE()); + } + + private IRegex toRegexB() { return new RegexConcat( // - new RegexLeaf("YEAR", "([\\d]{4})"), // + new RegexLeaf("BYEAR", "([\\d]{4})"), // new RegexLeaf("\\D"), // - new RegexLeaf("MONTH", "([\\d]{1,2})"), // + new RegexLeaf("BMONTH", "([\\d]{1,2})"), // new RegexLeaf("\\D"), // - new RegexLeaf("DAY", "([\\d]{1,2})")); + new RegexLeaf("BDAY", "([\\d]{1,2})")); + } + + private IRegex toRegexE() { + return new RegexConcat( // + new RegexLeaf("[dD]\\+"), // + new RegexLeaf("ECOUNT", "([\\d]+)") // + ); } } diff --git a/src/net/sourceforge/plantuml/project/lang/SubjectDaysAsDates.java b/src/net/sourceforge/plantuml/project/lang/SubjectDaysAsDates.java index 6fedb3ce8..d1b18ef2c 100644 --- a/src/net/sourceforge/plantuml/project/lang/SubjectDaysAsDates.java +++ b/src/net/sourceforge/plantuml/project/lang/SubjectDaysAsDates.java @@ -53,35 +53,46 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class SubjectDaysAsDates implements Subject { public IRegex toRegex() { - return new RegexOr(regexTo(), regexAnd(), regexThen()); - + return new RegexOr(toRegexB(), toRegexE(), andRegex(), thenRegex()); } - private IRegex regexTo() { + private IRegex toRegexB() { return new RegexConcat( // - new RegexLeaf("YEAR1", "([\\d]{4})"), // + new RegexLeaf("BYEAR1", "([\\d]{4})"), // new RegexLeaf("\\D"), // - new RegexLeaf("MONTH1", "([\\d]{1,2})"), // + new RegexLeaf("BMONTH1", "([\\d]{1,2})"), // new RegexLeaf("\\D"), // - new RegexLeaf("DAY1", "([\\d]{1,2})"), // + new RegexLeaf("BDAY1", "([\\d]{1,2})"), // RegexLeaf.spaceOneOrMore(), // new RegexLeaf("to"), // RegexLeaf.spaceOneOrMore(), // - new RegexLeaf("YEAR2", "([\\d]{4})"), // + new RegexLeaf("BYEAR2", "([\\d]{4})"), // new RegexLeaf("\\D"), // - new RegexLeaf("MONTH2", "([\\d]{1,2})"), // + new RegexLeaf("BMONTH2", "([\\d]{1,2})"), // new RegexLeaf("\\D"), // - new RegexLeaf("DAY2", "([\\d]{1,2})") // + new RegexLeaf("BDAY2", "([\\d]{1,2})") // ); } - private IRegex regexAnd() { + private IRegex toRegexE() { return new RegexConcat( // - new RegexLeaf("YEAR3", "([\\d]{4})"), // + new RegexLeaf("[dD]\\+"), // + new RegexLeaf("ECOUNT1", "([\\d]+)"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("to"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("[dD]\\+"), // + new RegexLeaf("ECOUNT2", "([\\d]+)") // + ); + } + + private IRegex andRegex() { + return new RegexConcat( // + new RegexLeaf("BYEAR3", "([\\d]{4})"), // new RegexLeaf("\\D"), // - new RegexLeaf("MONTH3", "([\\d]{1,2})"), // + new RegexLeaf("BMONTH3", "([\\d]{1,2})"), // new RegexLeaf("\\D"), // - new RegexLeaf("DAY3", "([\\d]{1,2})"), // + new RegexLeaf("BDAY3", "([\\d]{1,2})"), // RegexLeaf.spaceOneOrMore(), // new RegexLeaf("and"), // RegexLeaf.spaceOneOrMore(), // @@ -92,7 +103,7 @@ public class SubjectDaysAsDates implements Subject { ); } - private IRegex regexThen() { + private IRegex thenRegex() { return new RegexConcat( // new RegexLeaf("then"), // RegexLeaf.spaceOneOrMore(), // @@ -106,7 +117,7 @@ public class SubjectDaysAsDates implements Subject { public Failable getMe(GanttDiagram project, RegexResult arg) { final String countAnd = arg.get("COUNT_AND", 0); if (countAnd != null) { - final Day date3 = getDate(arg, "3"); + final Day date3 = getDate(project, arg, "3"); final int nb = Integer.parseInt(countAnd); return Failable.ok(new DaysAsDates(project, date3, nb)); } @@ -116,16 +127,23 @@ public class SubjectDaysAsDates implements Subject { final int nb = Integer.parseInt(countThen); return Failable.ok(new DaysAsDates(project, date3, nb)); } - final Day date1 = getDate(arg, "1"); - final Day date2 = getDate(arg, "2"); + final Day date1 = getDate(project, arg, "1"); + final Day date2 = getDate(project, arg, "2"); return Failable.ok(new DaysAsDates(date1, date2)); } - private Day getDate(RegexResult arg, String suffix) { - final int day = Integer.parseInt(arg.get("DAY" + suffix, 0)); - final int month = Integer.parseInt(arg.get("MONTH" + suffix, 0)); - final int year = Integer.parseInt(arg.get("YEAR" + suffix, 0)); - return Day.create(year, month, day); + private Day getDate(GanttDiagram project, RegexResult arg, String suffix) { + if (arg.get("BDAY" + suffix, 0) != null) { + final int day = Integer.parseInt(arg.get("BDAY" + suffix, 0)); + final int month = Integer.parseInt(arg.get("BMONTH" + suffix, 0)); + final int year = Integer.parseInt(arg.get("BYEAR" + suffix, 0)); + return Day.create(year, month, day); + } + if (arg.get("ECOUNT" + suffix, 0) != null) { + final int day = Integer.parseInt(arg.get("ECOUNT" + suffix, 0)); + return project.getStartingDate().addDays(day); + } + throw new IllegalStateException(); } public Collection getSentences() { diff --git a/src/net/sourceforge/plantuml/style/SName.java b/src/net/sourceforge/plantuml/style/SName.java index 11696fd17..a7730b9cd 100644 --- a/src/net/sourceforge/plantuml/style/SName.java +++ b/src/net/sourceforge/plantuml/style/SName.java @@ -89,6 +89,7 @@ public enum SName { mindmapDiagram, // node, // note, // + nwdiagDiagram, // objectDiagram, // package_, // participant, // diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 68237e16a..ea206d0a0 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -80,7 +80,7 @@ public class Version { } public static int beta() { - final int beta = 1; + final int beta = 2; return beta; }