1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-04 17:40:47 +00:00

Import version 1.2020.24

This commit is contained in:
Arnaud Roques 2020-12-19 22:21:54 +01:00
parent 56cd2269dd
commit 5dab086ba1
75 changed files with 2179 additions and 549 deletions

View File

@ -20,7 +20,7 @@
<target name="compile">
<delete dir="build" />
<mkdir dir="build" />
<javac target="1.6" srcdir="src" destdir="build" debug="on" />
<javac target="1.6" source="1.6" srcdir="src" destdir="build" debug="on" />
<copy file="src/net/sourceforge/plantuml/version/logo.png"
todir="build/net/sourceforge/plantuml/version" />
<copy file="src/net/sourceforge/plantuml/version/favicon.png"

20
pom.xml
View File

@ -35,7 +35,7 @@
<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
<version>1.2020.24-SNAPSHOT</version>
<version>1.2020.25-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PlantUML</name>
@ -49,7 +49,7 @@
* state diagram
* object diagram
</description>
<url>http://plantuml.sourceforge.net</url>
<url>https://plantuml.com</url>
<parent>
<groupId>org.sonatype.oss</groupId>
@ -93,18 +93,6 @@
</developer>
</developers>
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
</profiles>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<resources>
@ -158,7 +146,9 @@
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
<additionalparam>-Xdoclint:none</additionalparam>
<doclint>none</doclint>
</configuration>
</execution>
</executions>

View File

@ -6,9 +6,8 @@ import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import net.sourceforge.plantuml.security.ImageIO;
import ext.plantuml.com.ctreber.acearth.renderer.RenderTarget;
import net.sourceforge.plantuml.security.ImageIO;
/**
* <p>

View File

@ -80,7 +80,6 @@ import smetana.core.CFunction;
import smetana.core.CFunctionAbstract;
import smetana.core.CString;
import smetana.core.Z;
import smetana.core.debug.SmetanaDebug;
public class arrows__c {

View File

@ -62,7 +62,6 @@ import static smetana.core.JUtils.NEQ;
import static smetana.core.JUtils.atof;
import static smetana.core.JUtils.atoi;
import static smetana.core.JUtils.getenv;
import static smetana.core.JUtils.strstr;
import static smetana.core.Macro.AGNODE;
import static smetana.core.Macro.AGRAPH;
import static smetana.core.Macro.BOTTOM_IX;

View File

@ -112,7 +112,6 @@ import h.ST_Agraph_s;
import h.ST_pointf;
import smetana.core.CArrayOfStar;
import smetana.core.Z;
import smetana.core.debug.SmetanaDebug;
/* classify edges for mincross/nodepos/splines, using given ranks */
public class class2__c {

View File

@ -141,8 +141,8 @@ public class EmbeddedDiagram implements CharSequence {
final boolean isSvg = ug.matchesProperty("SVG");
if (isSvg) {
final String imageSvg = getImageSvg();
final SvgString svg = new SvgString(imageSvg, 1);
ug.draw(new UImageSvg(svg));
final UImageSvg svg = new UImageSvg(imageSvg, 1);
ug.draw(svg);
return;
}
final BufferedImage im = getImage();

View File

@ -43,7 +43,6 @@ import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
import net.sourceforge.plantuml.security.SFile;
import net.sourceforge.plantuml.security.SecurityUtils;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
public class OptionFlags {

View File

@ -43,6 +43,7 @@ import net.sourceforge.plantuml.acearth.PSystemXearthFactory;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory;
import net.sourceforge.plantuml.activitydiagram3.ActivityDiagramFactory3;
import net.sourceforge.plantuml.api.PSystemFactory;
import net.sourceforge.plantuml.board.BoardDiagramFactory;
import net.sourceforge.plantuml.bpm.BpmDiagramFactory;
import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory;
import net.sourceforge.plantuml.command.regex.RegexConcat;
@ -215,6 +216,7 @@ public class PSystemBuilder {
factories.add(new WireDiagramFactory());
factories.add(new JsonDiagramFactory());
factories.add(new GitDiagramFactory());
factories.add(new BoardDiagramFactory());
return factories;
}

View File

@ -110,6 +110,9 @@ public class SkinParam implements ISkinParam {
if (type == UmlDiagramType.GIT) {
UseStyle.setBetaStyle(true);
}
if (type == UmlDiagramType.BOARD) {
UseStyle.setBetaStyle(true);
}
if (type == UmlDiagramType.SEQUENCE) {
// skin = "debug.skin";
// USE_STYLE2.set(true);

View File

@ -1,116 +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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SvgString {
private final String svg;
private final double scale;
public SvgString(String svg, double scale) {
if (svg == null) {
throw new IllegalArgumentException();
}
this.svg = svg;
this.scale = scale;
}
public String getMD5Hex() {
return SignatureUtils.getMD5Hex(svg);
}
public String getSvg(boolean raw) {
String result = svg;
if (raw) {
return result;
}
if (result.startsWith("<?xml")) {
final int idx = result.indexOf("<svg");
result = result.substring(idx);
}
if (result.startsWith("<svg")) {
final int idx = result.indexOf(">");
result = "<svg>" + result.substring(idx + 1);
}
final String style = extractSvgStyle();
if (style != null) {
final String background = extractBackground(style);
if (background != null) {
result = result.replaceFirst("<g>", "<g><rect fill=\"" + background + "\" style=\"" + style + "\" /> ");
}
}
if (result.startsWith("<svg>") == false) {
throw new IllegalArgumentException();
}
return result;
}
private String extractBackground(String style) {
final Pattern p = Pattern.compile("background:([^;]+)");
final Matcher m = p.matcher(style);
if (m.find()) {
return m.group(1);
}
return null;
}
private String extractSvgStyle() {
final Pattern p = Pattern.compile("(?i)\\<svg[^>]+style=\"([^\">]+)\"");
final Matcher m = p.matcher(svg);
if (m.find()) {
return m.group(1);
}
return null;
}
public int getData(String name) {
final Pattern p = Pattern.compile("(?i)" + name + "\\W+(\\d+)");
final Matcher m = p.matcher(svg);
if (m.find()) {
final String s = m.group(1);
return Integer.parseInt(s);
}
throw new IllegalStateException("Cannot find " + name);
}
public double getScale() {
return scale;
}
}

View File

@ -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;
HELP, GANTT, SALT, JSON, GIT, BOARD;
public SName getStyleName() {
if (this == SEQUENCE) {

View File

@ -62,8 +62,8 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils;
import net.sourceforge.plantuml.activitydiagram3.ftile.Snake;
import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondSquare;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondSquare;
import net.sourceforge.plantuml.creole.CreoleMode;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.FontConfiguration;

View File

@ -61,8 +61,8 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.MergeStrategy;
import net.sourceforge.plantuml.activitydiagram3.ftile.Snake;
import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondSquare;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondSquare;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;

View File

@ -52,8 +52,8 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.FtileWithUrl;
import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileIfDown;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondSquare;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside;
import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondSquare;
import net.sourceforge.plantuml.creole.CreoleMode;
import net.sourceforge.plantuml.creole.Parser;
import net.sourceforge.plantuml.creole.Sheet;

View File

@ -0,0 +1,130 @@
/* ========================================================================
* 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.board;
import java.util.concurrent.atomic.AtomicInteger;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
public class Activity {
private final BNode node;
private final ISkinParam skinParam;
private BNode cursor;
private final BoardDiagram boardDiagram;
public Activity(BoardDiagram boardDiagram, String name, ISkinParam skinParam) {
this.boardDiagram = boardDiagram;
this.node = new BNode(0, name);
this.skinParam = skinParam;
this.cursor = this.node;
}
public TextBlock getBox() {
return new CardBox(Display.create(node.getName()), skinParam);
}
public void addRelease(int stage, String label) {
if (stage <= 0) {
throw new IllegalArgumentException();
}
final BNode newNode = new BNode(stage, label);
while (true) {
if (stage > cursor.getStage()) {
cursor.addChild(newNode);
cursor = newNode;
return;
}
cursor = cursor.getParent();
}
}
private BArray array;
private BArray getArray() {
if (array == null) {
node.computeX(new AtomicInteger());
array = new BArray();
node.initBarray(array);
}
return array;
}
public double getFullWidth() {
final BArray array = getArray();
return (array.getMaxX() + 1) * PostIt.getWidth();
}
public int getMaxStage() {
final BArray array = getArray();
return array.getMaxY();
}
public void drawMe(UGraphic ug) {
getBox().drawU(ug);
final BArray array = getArray();
for (BNode node : array) {
final double dx = node.getX() * PostIt.getWidth();
final double dy = node.getStage() * PostIt.getHeight();
ug.apply(new UTranslate(dx, dy));
CardBox box = new CardBox(Display.create(node.getName()), skinParam);
box.drawU(ug.apply(new UTranslate(dx, dy)));
}
// for (Entry<Integer, List<PostIt>> ent : postits.entrySet()) {
// final int line = ent.getKey();
// final List<PostIt> list = ent.getValue();
// double dy = boardDiagram.getStageY(ug.getStringBounder(), line);
// for (PostIt postit : list) {
// postit.getCard().drawU(ug.apply(UTranslate.dy(dy)));
// dy += PostIt.getHeight(ug.getStringBounder());
// }
//
// }
}
}

View File

@ -0,0 +1,80 @@
/* ========================================================================
* 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.board;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class BArray implements Iterable<BNode> {
private final Map<String, BNode> data = new HashMap<String, BNode>();
private int maxX;
private int maxY;
public void put(BNode node) {
final String key = getKey(node.getX(), node.getStage());
if (data.containsKey(key)) {
throw new IllegalArgumentException();
}
data.put(key, node);
this.maxX = Math.max(this.maxX, node.getX());
this.maxY = Math.max(this.maxY, node.getStage());
}
public BNode getCell(int x, int y) {
final String key = getKey(x, y);
return data.get(key);
}
private String getKey(int x, int y) {
return "" + x + ";" + y;
}
public Iterator<BNode> iterator() {
return Collections.unmodifiableCollection(data.values()).iterator();
}
public final int getMaxX() {
return maxX;
}
public final int getMaxY() {
return maxY;
}
}

View File

@ -0,0 +1,106 @@
/* ========================================================================
* 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.board;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class BNode {
private final String name;
private final int stage;
private int x = -1;
private BNode parent;
private final List<BNode> children = new ArrayList<BNode>();
public BNode(int stage, String name) {
this.name = name;
this.stage = stage;
}
public void addChild(BNode child) {
if (child.stage <= this.stage) {
throw new IllegalArgumentException();
}
this.children.add(child);
if (child.parent != null) {
throw new IllegalArgumentException();
}
child.parent = this;
}
public final String getName() {
return name;
}
public final int getStage() {
return stage;
}
public final BNode getParent() {
return parent;
}
@Override
public String toString() {
return name + "(" + stage + ") [" + x + "]";
}
public void computeX(AtomicInteger count) {
this.x = count.intValue();
for (int i = 0; i < children.size(); i++) {
final BNode child = children.get(i);
if (i > 0) {
count.addAndGet(1);
}
child.computeX(count);
}
}
public void initBarray(BArray array) {
array.put(this);
for (BNode child : children) {
child.initBarray(array);
}
}
public final int getX() {
return x;
}
}

View File

@ -0,0 +1,195 @@
/* ========================================================================
* 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.board;
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.List;
import net.sourceforge.plantuml.AnnotatedWorker;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.Scale;
import net.sourceforge.plantuml.SkinParam;
import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.InnerStrategy;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleSignature;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.ImageParameter;
import net.sourceforge.plantuml.ugraphic.MinMax;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class BoardDiagram extends UmlDiagram {
private final List<Activity> activities = new ArrayList<Activity>();
public DiagramDescription getDescription() {
return new DiagramDescription("Board");
}
@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.BOARD;
}
@Override
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException {
final Scale scale = getScale();
final double dpiFactor = scale == null ? getScaleCoef(fileFormatOption) : scale.getScale(100, 100);
final ISkinParam skinParam = getSkinParam();
final int margin1 = SkinParam.zeroMargin(10);
final int margin2 = SkinParam.zeroMargin(10);
final Style style = StyleSignature.of(SName.root, SName.document, SName.mindmapDiagram)
.getMergedStyle(skinParam.getCurrentStyleBuilder());
HColor backgroundColor = style.value(PName.BackGroundColor).asColor(skinParam.getIHtmlColorSet());
if (backgroundColor == null) {
backgroundColor = HColorUtils.transparent();
}
final ClockwiseTopRightBottomLeft margins = ClockwiseTopRightBottomLeft.margin1margin2(margin1, margin2);
final String metadata = fileFormatOption.isWithMetadata() ? getMetadata() : null;
final ImageParameter imageParameter = new ImageParameter(skinParam.getColorMapper(), skinParam.handwritten(),
null, dpiFactor, metadata, "", margins, backgroundColor);
final ImageBuilder imageBuilder = ImageBuilder.build(imageParameter);
TextBlock result = getTextBlock();
result = new AnnotatedWorker(this, skinParam, fileFormatOption.getDefaultStringBounder(getSkinParam()))
.addAdd(result);
imageBuilder.setUDrawable(result);
return imageBuilder.writeImageTOBEMOVED(fileFormatOption, seed(), 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) {
final double width = 200;
final double height = 200;
return new Dimension2DDouble(width, height);
}
public MinMax getMinMax(StringBounder stringBounder) {
throw new UnsupportedOperationException();
}
public HColor getBackcolor() {
return null;
}
};
}
private void drawMe(final UGraphic ug) {
UGraphic mug = ug;
for (Activity activity : activities) {
activity.drawMe(mug);
mug = mug.apply(UTranslate.dx(activity.getFullWidth()));
}
final ULine line = ULine.hline(getFullWidth());
for (int i = 0; i < getMaxStage(); i++) {
final double dy = (i + 1) * PostIt.getHeight() - 10;
ug.apply(HColorUtils.BLACK).apply(new UStroke(5, 5, 0.5)).apply(UTranslate.dy(dy)).draw(line);
}
}
private double getFullWidth() {
double width = 0;
for (Activity activity : activities) {
width += activity.getFullWidth();
}
return width;
}
private int getMaxStage() {
int max = 0;
for (Activity activity : activities) {
max = Math.max(max, activity.getMaxStage());
}
return max;
}
private Activity getLastActivity() {
return this.activities.get(this.activities.size() - 1);
}
public CommandExecutionResult addLine(String plus, String label) {
if (plus.length() == 0) {
final Activity activity = new Activity(this, label, getSkinParam());
this.activities.add(activity);
return CommandExecutionResult.ok();
}
getLastActivity().addRelease(plus.length(), label);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,72 @@
/* ========================================================================
* 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.board;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.core.DiagramType;
public class BoardDiagramFactory extends PSystemCommandFactory {
public BoardDiagramFactory() {
super(DiagramType.BOARD);
}
@Override
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<Command>();
addCommonCommands1(cmds);
cmds.add(new CommandBoardPlus());
// cmds.add(new CommandMindMapTabulation());
// cmds.add(new CommandMindMapOrgmode());
// cmds.add(new CommandMindMapOrgmodeMultiline());
// cmds.add(new CommandMindMapRoot());
// cmds.add(new CommandMindMapPlus());
// cmds.add(new CommandMindMapDirection());
return cmds;
}
@Override
public BoardDiagram createEmptyDiagram() {
return new BoardDiagram();
}
}

View File

@ -0,0 +1,82 @@
/* ========================================================================
* 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.board;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.AbstractTextBlock;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class CardBox extends AbstractTextBlock {
private final Display label;
private final ISkinParam skinParam;
public CardBox(Display label, ISkinParam skinParam) {
this.label = label;
this.skinParam = skinParam;
}
// private StyleSignature getDefaultStyleDefinitionNode() {
// return StyleSignature.of(SName.root, SName.element, SName.mindmapDiagram, SName.node);
// }
public Dimension2D calculateDimension(StringBounder stringBounder) {
return new Dimension2DDouble(150, 70);
}
public void drawU(UGraphic ug) {
final URectangle rect = new URectangle(calculateDimension(ug.getStringBounder()));
rect.setDeltaShadow(1);
ug.apply(HColorUtils.BLACK).apply(HColorUtils.LIGHT_GRAY.bg()).draw(rect);
label.create(FontConfiguration.blackBlueTrue(UFont.sansSerif(14)), HorizontalAlignment.LEFT, skinParam)
.drawU(ug.apply(new UTranslate(3, 3)));
}
}

View File

@ -33,7 +33,7 @@
*
*
*/
package net.sourceforge.plantuml.wire;
package net.sourceforge.plantuml.board;
import net.sourceforge.plantuml.LineLocation;
import net.sourceforge.plantuml.command.CommandExecutionResult;
@ -43,22 +43,24 @@ import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexResult;
public class CommandContainerEnd extends SingleLineCommand2<WireDiagram> {
public class CommandBoardPlus extends SingleLineCommand2<BoardDiagram> {
public CommandContainerEnd() {
public CommandBoardPlus() {
super(false, getRegexConcat());
}
static IRegex getRegexConcat() {
return RegexConcat.build(CommandContainerEnd.class.getName(), RegexLeaf.start(), //
return RegexConcat.build(CommandBoardPlus.class.getName(), RegexLeaf.start(), //
new RegexLeaf("PLUS", "([+]*)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\}"), //
RegexLeaf.end());
new RegexLeaf("LABEL", "([^%s].*)"), RegexLeaf.end());
}
@Override
protected CommandExecutionResult executeArg(WireDiagram diagram, LineLocation location, RegexResult arg) {
return diagram.componentEnd();
protected CommandExecutionResult executeArg(BoardDiagram diagram, LineLocation location, RegexResult arg) {
final String plus = arg.get("PLUS", 0);
final String label = arg.get("LABEL", 0);
return diagram.addLine(plus, label);
}
}

View File

@ -0,0 +1,67 @@
/* ========================================================================
* 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.board;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.TextBlock;
public class PostIt {
private final BNode node;
private final ISkinParam skinParam;
public PostIt(ISkinParam skinParam, BNode node) {
this.node = node;
this.skinParam = skinParam;
}
public static double getHeight() {
return 90;
}
public static double getWidth() {
return 170;
}
public TextBlock getCard() {
return new CardBox(Display.create(node.getName()), skinParam);
}
}

View File

@ -39,7 +39,7 @@ import net.sourceforge.plantuml.utils.StartUtils;
public enum DiagramType {
UML, BPM, DITAA, DOT, PROJECT, JCCKIT, SALT, FLOW, CREOLE, JUNGLE, CUTE, MATH, LATEX,
DEFINITION, GANTT, NW, MINDMAP, WBS, WIRE, JSON, GIT,
DEFINITION, GANTT, NW, MINDMAP, WBS, WIRE, JSON, GIT, BOARD,
UNKNOWN;
static public DiagramType getTypeFromArobaseStart(String s) {
@ -110,6 +110,9 @@ public enum DiagramType {
if (StartUtils.startsWithSymbolAnd("startgit", s)) {
return GIT;
}
if (StartUtils.startsWithSymbolAnd("startboard", s)) {
return BOARD;
}
return UNKNOWN;
}
}

View File

@ -40,7 +40,6 @@ import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.math.ScientificEquationSafe;
import net.sourceforge.plantuml.ugraphic.UGraphic;
@ -93,8 +92,8 @@ public class AtomMath extends AbstractAtom implements Atom {
final Color fore = getColor(foreground, Color.BLACK);
// final double dpiFactor = ug.dpiFactor();
if (isSvg) {
final SvgString svg = math.getSvg(1, fore, back);
ug.draw(new UImageSvg(svg));
final UImageSvg svg = math.getSvg(1, fore, back);
ug.draw(svg);
} else {
final UImage image = new UImage(math.getImage(fore, back)).withFormula(math.getFormula());
ug.draw(image);

View File

@ -56,14 +56,12 @@ import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UText;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorAutomatic;
import net.sourceforge.plantuml.ugraphic.color.HColorSimple;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
import net.sourceforge.plantuml.utils.CharHidder;
public final class AtomText extends AbstractAtom implements Atom {

View File

@ -76,7 +76,7 @@ public class BodierSimple implements Bodier {
}
public boolean hasUrl() {
throw new UnsupportedOperationException();
return false;
}
public List<CharSequence> getRawBody() {

View File

@ -53,7 +53,6 @@ import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.cucadiagram.PortionShower;
import net.sourceforge.plantuml.posimo.Block;
import net.sourceforge.plantuml.posimo.Cluster;

View File

@ -35,7 +35,6 @@
*/
package net.sourceforge.plantuml.descdiagram;
import net.sourceforge.plantuml.ComponentStyle;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagramType;

View File

@ -61,7 +61,6 @@ import net.sourceforge.plantuml.graphic.USymbol;
import net.sourceforge.plantuml.graphic.color.ColorParser;
import net.sourceforge.plantuml.graphic.color.ColorType;
import net.sourceforge.plantuml.graphic.color.Colors;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class CommandCreateElementMultilines extends CommandMultilines2<AbstractEntityDiagram> {

View File

@ -39,8 +39,8 @@ import net.sourceforge.plantuml.LineLocation;
import net.sourceforge.plantuml.NewpagedDiagram;
import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.IRegex;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;

View File

@ -38,7 +38,6 @@ package net.sourceforge.plantuml.graphic;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
@ -47,7 +46,7 @@ public class TileImageSvg extends AbstractTextBlock implements TextBlock {
private final UImageSvg svg;
public TileImageSvg(String svg) {
this.svg = new UImageSvg(new SvgString(svg, 1));
this.svg = new UImageSvg(svg, 1);
}
public Dimension2D calculateDimension(StringBounder stringBounder) {

View File

@ -80,8 +80,6 @@ import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.IGroup;
import net.sourceforge.plantuml.cucadiagram.ILeaf;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.cucadiagram.MethodsOrFieldsArea;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.cucadiagram.entity.EntityFactory;
import net.sourceforge.plantuml.graphic.AbstractTextBlock;
@ -90,7 +88,6 @@ import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.QuoteUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockEmpty;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.graphic.USymbol;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;

View File

@ -48,8 +48,8 @@ import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import net.sourceforge.plantuml.BackSlash;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.ugraphic.MutableImage;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
public class AsciiMath implements ScientificEquation {
@ -94,7 +94,7 @@ public class AsciiMath implements ScientificEquation {
return builder.getDimension();
}
public SvgString getSvg(double scale, Color foregroundColor, Color backgroundColor)
public UImageSvg getSvg(double scale, Color foregroundColor, Color backgroundColor)
throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException, InstantiationException, IOException {
return builder.getSvg(scale, foregroundColor, backgroundColor);

View File

@ -44,8 +44,8 @@ import java.lang.reflect.InvocationTargetException;
import javax.swing.Icon;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.ugraphic.MutableImage;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
public class LatexBuilder implements ScientificEquation {
@ -67,14 +67,14 @@ public class LatexBuilder implements ScientificEquation {
return new TeXIconBuilder(tex, foregroundColor).getIcon();
}
public SvgString getSvg(double scale, Color foregroundColor, Color backgroundColor)
public UImageSvg getSvg(double scale, Color foregroundColor, Color backgroundColor)
throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException, InstantiationException, IOException {
final Icon icon = buildIcon(foregroundColor);
final ConverterSvg converterSvg = new ConverterSvg(icon);
final String svg = converterSvg.getSvg(scale, true, backgroundColor);
dimension = converterSvg.getDimension();
return new SvgString(svg, scale);
return new UImageSvg(svg, scale);
}
public MutableImage getImage(Color foregroundColor, Color backgroundColor)

View File

@ -40,14 +40,14 @@ import java.awt.geom.Dimension2D;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.ugraphic.MutableImage;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
public interface ScientificEquation {
public Dimension2D getDimension();
public SvgString getSvg(double scale, Color foregroundColor, Color backgroundColor)
public UImageSvg getSvg(double scale, Color foregroundColor, Color backgroundColor)
throws ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException, InstantiationException, IOException;

View File

@ -46,7 +46,6 @@ import java.util.Arrays;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.eps.EpsGraphics;
@ -59,6 +58,7 @@ import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.ImageParameter;
import net.sourceforge.plantuml.ugraphic.MutableImage;
import net.sourceforge.plantuml.ugraphic.PixelImage;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity;
public class ScientificEquationSafe {
@ -93,9 +93,9 @@ public class ScientificEquationSafe {
private ImageData dimSvg;
public SvgString getSvg(double scale, Color foregroundColor, Color backgroundColor) {
public UImageSvg getSvg(double scale, Color foregroundColor, Color backgroundColor) {
try {
final SvgString svg = equation.getSvg(scale, foregroundColor, backgroundColor);
final UImageSvg svg = equation.getSvg(scale, foregroundColor, backgroundColor);
dimSvg = new ImageDataSimple(equation.getDimension());
return svg;
} catch (Exception e) {
@ -107,7 +107,7 @@ public class ScientificEquationSafe {
} catch (IOException e1) {
return null;
}
return new SvgString(new String(baos.toByteArray()), scale);
return new UImageSvg(new String(baos.toByteArray()), scale);
}
}

View File

@ -52,7 +52,7 @@ public class CommandProperty extends SingleLineCommand2<NwDiagram> {
static IRegex getRegexConcat() {
return RegexConcat.build(CommandProperty.class.getName(), RegexLeaf.start(), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("NAME", "(address|color|width)"), //
new RegexLeaf("NAME", "(address|color|width|description)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("="), //
RegexLeaf.spaceZeroOrMore(), //

View File

@ -34,49 +34,41 @@
*/
package net.sourceforge.plantuml.nwdiag;
import java.util.HashSet;
import java.util.Set;
public class Footprint {
import net.sourceforge.plantuml.ugraphic.color.HColor;
private final int min;
private final int max;
public class DiagGroup {
private final String name;
private final Network network;
private final Set<String> elements = new HashSet<String>();
private HColor color;
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 name + " " + network + " " + elements;
return "" + min + " -> " + max;
}
public DiagGroup(String name, Network network) {
this.name = name;
this.network = network;
}
public final String getName() {
return name;
}
public void addElement(String name) {
this.elements.add(name);
}
public boolean matches(LinkedElement tested) {
if (network != null && network != tested.getNetwork()) {
return false;
public Footprint intersection(Footprint other) {
if (this.max < other.min) {
return null;
}
return elements.contains(tested.getElement().getName());
if (this.min > other.max) {
return null;
}
return new Footprint(Math.max(this.min, other.min), Math.min(this.max, other.max));
}
public final HColor getColor() {
return color;
public final int getMin() {
return min;
}
public final void setColor(HColor color) {
this.color = color;
public final int getMax() {
return max;
}
}

View File

@ -34,52 +34,47 @@
*/
package net.sourceforge.plantuml.nwdiag;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.MinMax;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
public class GridTextBlockDecorated extends GridTextBlockSimple {
public static final HColorSet colors = HColorSet.instance();
public static final int NETWORK_THIN = 5;
private final Collection<DiagGroup> groups;
private final List<NwGroup> groups;
private final List<Network> networks;
public GridTextBlockDecorated(int lines, int cols, Collection<DiagGroup> groups, List<Network> networks) {
super(lines, cols);
public GridTextBlockDecorated(int lines, int cols, List<NwGroup> groups, List<Network> networks,
ISkinParam skinparam) {
super(lines, cols, skinparam);
this.groups = groups;
this.networks = networks;
}
@Override
protected void drawGrid(UGraphic ug) {
for (DiagGroup group : groups) {
drawGroups(ug, group);
for (NwGroup group : groups) {
drawGroups(ug, group, skinparam);
}
final Map<Network, Double> pos = drawNetworkTube(ug);
drawLinks(ug, pos);
drawNetworkTube(ug);
drawLinks(ug);
}
private void drawLinks(UGraphic ug, Map<Network, Double> pos) {
private void drawLinks(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
for (int i = 0; i < data.length; i++) {
for (int i = 0; i < data.getNbLines(); i++) {
final double lineHeight = lineHeight(stringBounder, i);
double x = 0;
for (int j = 0; j < data[i].length; j++) {
for (int j = 0; j < data.getNbCols(); j++) {
final double colWidth = colWidth(stringBounder, j);
if (data[i][j] != null) {
data[i][j].drawLinks(ug.apply(UTranslate.dx(x)), colWidth, lineHeight, pos);
if (data.get(i, j) != null) {
data.get(i, j).drawLinks(ug, x, colWidth, lineHeight);
}
x += colWidth;
}
@ -87,17 +82,17 @@ public class GridTextBlockDecorated extends GridTextBlockSimple {
}
private void drawGroups(UGraphic ug, DiagGroup group) {
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.length; i++) {
for (int i = 0; i < data.getNbLines(); i++) {
final double lineHeight = lineHeight(stringBounder, i);
double x = 0;
for (int j = 0; j < data[i].length; j++) {
for (int j = 0; j < data.getNbCols(); j++) {
final double colWidth = colWidth(stringBounder, j);
final LinkedElement element = data[i][j];
final LinkedElement element = data.get(i, j);
if (element != null && group.matches(element)) {
final MinMax minMax = element.getMinMax(stringBounder, colWidth, lineHeight)
.translate(new UTranslate(x, y));
@ -108,18 +103,14 @@ public class GridTextBlockDecorated extends GridTextBlockSimple {
y += lineHeight;
}
if (size != null) {
HColor color = group.getColor();
if (color == null) {
color = colors.getColorIfValid("#AAA");
}
size.draw(ug, color);
group.drawGroup(ug, size, skinParam);
}
}
private boolean isThereALink(int j, Network network) {
for (int i = 0; i < data.length; i++) {
final LinkedElement element = data[i][j];
for (int i = 0; i < data.getNbLines(); i++) {
final LinkedElement element = data.get(i, j);
if (element != null && element.isLinkedTo(network)) {
return true;
}
@ -127,44 +118,67 @@ public class GridTextBlockDecorated extends GridTextBlockSimple {
return false;
}
private Map<Network, Double> drawNetworkTube(final UGraphic ug) {
final Map<Network, Double> pos = new HashMap<Network, Double>();
private void drawNetworkTube(final UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
double y = 0;
for (int i = 0; i < data.length; i++) {
for (int i = 0; i < data.getNbLines(); i++) {
final Network network = getNetwork(i);
double x = 0;
double xmin = network.isFullWidth() ? 0 : -1;
double xmax = 0;
for (int j = 0; j < data[i].length; j++) {
final boolean hline = isThereALink(j, network);
if (hline && xmin < 0) {
xmin = x;
}
x += colWidth(stringBounder, j);
if (hline || network.isFullWidth()) {
xmax = x;
}
}
computeMixMax(data.getLine(i), stringBounder, network);
final URectangle rect = new URectangle(xmax - xmin, NETWORK_THIN);
final URectangle rect = new URectangle(network.getXmax() - network.getXmin(), NETWORK_THIN);
rect.setDeltaShadow(1.0);
UGraphic ug2 = ug.apply(new UTranslate(xmin, y));
UGraphic ug2 = ug.apply(new UTranslate(network.getXmin(), y));
if (network != null && network.getColor() != null) {
ug2 = ug2.apply(network.getColor().bg());
}
if (network != null) {
pos.put(network, y);
network.setY(y);
}
if (network.isVisible()) {
ug2.draw(rect);
}
y += lineHeight(stringBounder, i);
}
return pos;
}
private void computeMixMax(LinkedElement 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);
}
public void checkGroups() {
for (int i = 0; i < groups.size(); i++) {
for (int j = i + 1; j < groups.size(); j++) {
final NwGroup group1 = groups.get(i);
final NwGroup group2 = groups.get(j);
if (group1.getNetwork() != group2.getNetwork()) {
continue;
}
final Footprint footprint1 = getFootprint(group1);
final Footprint footprint2 = getFootprint(group2);
final Footprint inter = footprint1.intersection(footprint2);
data.swapCols(inter.getMin(), inter.getMax());
return;
}
}
}
}

View File

@ -38,6 +38,7 @@ 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;
@ -47,10 +48,12 @@ import net.sourceforge.plantuml.ugraphic.UTranslate;
public class GridTextBlockSimple implements TextBlock {
protected final LinkedElement data[][];
protected final NwArray data;
protected final ISkinParam skinparam;
public GridTextBlockSimple(int lines, int cols) {
this.data = new LinkedElement[lines][cols];
public GridTextBlockSimple(int lines, int cols, ISkinParam skinparam) {
this.skinparam = skinparam;
this.data = new NwArray(lines, cols);
}
protected void drawGrid(UGraphic ug) {
@ -60,13 +63,13 @@ public class GridTextBlockSimple implements TextBlock {
drawGrid(ug);
final StringBounder stringBounder = ug.getStringBounder();
double y = 0;
for (int i = 0; i < data.length; i++) {
for (int i = 0; i < data.getNbLines(); i++) {
final double lineHeight = lineHeight(stringBounder, i);
double x = 0;
for (int j = 0; j < data[i].length; j++) {
for (int j = 0; j < data.getNbCols(); j++) {
final double colWidth = colWidth(stringBounder, j);
if (data[i][j] != null) {
data[i][j].drawMe(ug.apply(new UTranslate(x, y)), colWidth, lineHeight);
if (data.get(i, j) != null) {
data.get(i, j).drawMe(ug.apply(new UTranslate(x, y)), colWidth, lineHeight);
}
x += colWidth;
}
@ -76,34 +79,34 @@ public class GridTextBlockSimple implements TextBlock {
protected double colWidth(StringBounder stringBounder, final int j) {
double width = 0;
for (int i = 0; i < data.length; i++) {
if (data[i][j] != null) {
width = Math.max(width, data[i][j].naturalDimension(stringBounder).getWidth());
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 = 0;
for (int j = 0; j < data[i].length; j++) {
if (data[i][j] != null) {
height = Math.max(height, data[i][j].naturalDimension(stringBounder).getHeight());
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.length == 0) {
if (data.getNbLines() == 0) {
return new Dimension2DDouble(0, 0);
}
double height = 0;
for (int i = 0; i < data.length; i++) {
for (int i = 0; i < data.getNbLines(); i++) {
height += lineHeight(stringBounder, i);
}
double width = 0;
for (int j = 0; j < data[0].length; j++) {
for (int j = 0; j < data.getNbCols(); j++) {
width += colWidth(stringBounder, j);
}
return new Dimension2DDouble(width, height);
@ -118,7 +121,11 @@ public class GridTextBlockSimple implements TextBlock {
}
public void add(int i, int j, LinkedElement value) {
data[i][j] = value;
data.set(i, j, value);
}
public Footprint getFootprint(NwGroup group) {
return data.getFootprint(group);
}
}

View File

@ -36,6 +36,7 @@ package net.sourceforge.plantuml.nwdiag;
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;
@ -54,17 +55,16 @@ public class LinkedElement {
private final TextBlock box;
private final Network network;
private final Network next;
private final DiagElement element;
private final Square square;
private final Map<Network, TextBlock> conns;
private final List<Network> networks;
public LinkedElement(DiagElement element, TextBlock box, Network network, Network next,
Map<Network, TextBlock> conns) {
public LinkedElement(Square square, TextBlock box, Map<Network, TextBlock> conns, List<Network> networks) {
this.networks = networks;
this.box = box;
this.network = network;
this.element = element;
this.network = square.getMainNetwork();
this.square = square;
this.conns = conns;
this.next = next;
}
public boolean isLinkedTo(Network some) {
@ -92,8 +92,11 @@ public class LinkedElement {
drawCenter(ug, box, xMiddle, yMiddle);
}
public void drawLinks(UGraphic ug, double width, double height, Map<Network, Double> pos) {
final double ynet1 = pos.get(network);
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);
@ -105,9 +108,15 @@ public class LinkedElement {
final double xMiddle = width / 2;
final TreeSet<Double> skip = new TreeSet<Double>(pos.values());
if (element.hasItsOwnColumn()) {
if (element.getMainNetwork().isVisible()) {
final TreeSet<Double> skip = new TreeSet<Double>();
for (Network 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 {
@ -124,7 +133,7 @@ public class LinkedElement {
if (ent.getKey() == network) {
continue;
}
final Double ynet2 = pos.get(ent.getKey());
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) {
@ -145,10 +154,11 @@ public class LinkedElement {
}
private TextBlock link2() {
if (next == null) {
final int i = networks.indexOf(network);
if (i == networks.size() - 1) {
return null;
}
return conns.get(next);
return conns.get(networks.get(i + 1));
}
private void drawCenter(UGraphic ug, TextBlock block, double x, double y) {
@ -177,8 +187,8 @@ public class LinkedElement {
return network;
}
public final DiagElement getElement() {
return element;
public final Square getElement() {
return square;
}
}

View File

@ -42,39 +42,41 @@ import net.sourceforge.plantuml.ugraphic.color.HColor;
public class Network {
private final String name;
private final Map<DiagElement, String> localElements = new LinkedHashMap<DiagElement, String>();
private final Map<Square, String> localSquare = new LinkedHashMap<Square, String>();
private HColor color;
private boolean visible = true;
private String ownAdress;
private boolean fullWidth;
private final int stage;
@Override
public String toString() {
return name;
return name + "(" + stage + ")";
}
public Network(String name) {
public Network(String name, int stage) {
this.name = name;
this.stage = stage;
}
public String getAdress(DiagElement element) {
return localElements.get(element);
public String getAdress(Square element) {
return localSquare.get(element);
}
public void addElement(DiagElement element, Map<String, String> props) {
public void addSquare(Square square, Map<String, String> props) {
String address = props.get("address");
if (address == null) {
address = "";
}
if (address.length() == 0 && localElements.containsKey(element)) {
if (address.length() == 0 && localSquare.containsKey(square)) {
return;
}
localElements.put(element, address);
localSquare.put(square, address);
}
public boolean constainsLocally(String name) {
for (DiagElement element : localElements.keySet()) {
if (element.getName().equals(name)) {
for (Square square : localSquare.keySet()) {
if (square.getName().equals(name)) {
return true;
}
}
@ -117,4 +119,34 @@ public class Network {
return fullWidth;
}
public final int getStage() {
return stage;
}
private double xmin;
private double xmax;
private double y;
public void setMinMax(double xmin, double xmax) {
this.xmin = xmin;
this.xmax = xmax;
}
public final double getXmin() {
return xmin;
}
public final double getXmax() {
return xmax;
}
public final double getY() {
return y;
}
public final void setY(double y) {
this.y = y;
}
}

View File

@ -0,0 +1,91 @@
/* ========================================================================
* 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;
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(NwGroup 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);
}
}

View File

@ -83,10 +83,10 @@ import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class NwDiagram extends UmlDiagram {
private boolean initDone;
private final Map<String, DiagElement> elements = new LinkedHashMap<String, DiagElement>();
private final Map<String, Square> squares = new LinkedHashMap<String, Square>();
private final List<Network> networks = new ArrayList<Network>();
private final List<DiagGroup> groups = new ArrayList<DiagGroup>();
private DiagGroup currentGroup = null;
private final List<NwGroup> groups = new ArrayList<NwGroup>();
private NwGroup currentGroup = null;
public DiagramDescription getDescription() {
return new DiagramDescription("(Nwdiag)");
@ -112,7 +112,7 @@ public class NwDiagram extends UmlDiagram {
if (initDone == false) {
return error();
}
currentGroup = new DiagGroup(name, currentNetwork());
currentGroup = new NwGroup(name, currentNetwork());
groups.add(currentGroup);
return CommandExecutionResult.ok();
}
@ -121,39 +121,42 @@ public class NwDiagram extends UmlDiagram {
if (initDone == false) {
return error();
}
final Network network = new Network(name);
networks.add(network);
createNetwork(name);
return CommandExecutionResult.ok();
}
private Network createNetwork(String name) {
final Network network = new Network(name, networks.size());
networks.add(network);
return network;
}
public CommandExecutionResult link(String name1, String name2) {
if (initDone == false) {
return error();
}
if (currentNetwork() == null) {
final Network network1 = new Network(name1);
networks.add(network1);
addElement(null, name2, toSet(null));
createNetwork(name1);
addSquare(null, name2, toSet(null));
return CommandExecutionResult.ok();
} else {
final DiagElement already = elements.get(name1);
final Network network1 = new Network("");
final Square already = squares.get(name1);
final Network network1 = createNetwork("");
network1.goInvisible();
networks.add(network1);
if (already != null) {
currentNetwork().addElement(already, toSet(null));
currentNetwork().addSquare(already, toSet(null));
}
addElement(null, name2, toSet(null));
addSquare(null, name2, toSet(null));
return CommandExecutionResult.ok();
}
}
private DiagElement addElement(DiagElement element, String name, Map<String, String> props) {
private Square addSquare(Square element, String name, Map<String, String> props) {
if (element == null) {
element = new DiagElement(name, currentNetwork(), this.getSkinParam());
elements.put(name, element);
element = new Square(name, currentNetwork(), this.getSkinParam());
squares.put(name, element);
}
currentNetwork().addElement(element, props);
currentNetwork().addSquare(element, props);
final String description = props.get("description");
if (description != null) {
element.setDescription(description);
@ -182,15 +185,14 @@ public class NwDiagram extends UmlDiagram {
}
if (currentNetwork() == null) {
if (currentGroup == null) {
final Network network1 = new Network("");
final Network network1 = createNetwork("");
network1.goInvisible();
networks.add(network1);
final DiagElement first = addElement(null, name, toSet(definition));
final Square first = addSquare(null, name, toSet(definition));
first.doNotHaveItsOwnColumn();
}
} else {
final DiagElement element = elements.get(name);
addElement(element, name, toSet(definition));
final Square element = squares.get(name);
addSquare(element, name, toSet(definition));
}
return CommandExecutionResult.ok();
}
@ -330,7 +332,7 @@ public class NwDiagram extends UmlDiagram {
}
private Map<Network, String> getLinks(DiagElement element) {
private Map<Network, String> getLinks(Square element) {
final Map<Network, String> result = new LinkedHashMap<Network, String>();
for (Network network : networks) {
final String s = network.getAdress(element);
@ -342,24 +344,26 @@ public class NwDiagram extends UmlDiagram {
}
private GridTextBlockDecorated buildGrid() {
final GridTextBlockDecorated grid = new GridTextBlockDecorated(networks.size(), elements.size(), groups,
networks);
final GridTextBlockDecorated grid = new GridTextBlockDecorated(networks.size(), squares.size(), groups,
networks, getSkinParam());
for (int i = 0; i < networks.size(); i++) {
final Network current = networks.get(i);
final Network next = i + 1 < networks.size() ? networks.get(i + 1) : null;
int j = 0;
for (Map.Entry<String, DiagElement> ent : elements.entrySet()) {
final DiagElement element = ent.getValue();
if (element.getMainNetwork() == current) {
final Map<Network, String> conns = getLinks(element);
grid.add(i, j, element.asTextBlock(conns, next));
for (Map.Entry<String, Square> ent : squares.entrySet()) {
final Square square = ent.getValue();
if (square.getMainNetwork() == current) {
final Map<Network, String> conns = getLinks(square);
grid.add(i, j, square.asTextBlock(conns, networks));
}
if (element.hasItsOwnColumn()) {
if (square.hasItsOwnColumn()) {
j++;
}
}
}
grid.checkGroups();
return grid;
}
@ -374,13 +378,18 @@ public class NwDiagram extends UmlDiagram {
currentNetwork().setFullWidth("full".equalsIgnoreCase(value));
}
if ("color".equalsIgnoreCase(property)) {
final HColor color = GridTextBlockDecorated.colors.getColorIfValid(value);
final HColor color = NwGroup.colors.getColorIfValid(value);
if (currentGroup != null) {
currentGroup.setColor(color);
} else if (currentNetwork() != null) {
currentNetwork().setColor(color);
}
}
if ("description".equalsIgnoreCase(property)) {
if (currentGroup != null) {
currentGroup.setDescription(value);
}
}
return CommandExecutionResult.ok();
}

View File

@ -0,0 +1,131 @@
/* ========================================================================
* 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.util.HashSet;
import java.util.Set;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.ugraphic.MinMax;
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.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class NwGroup {
public static final HColorSet colors = HColorSet.instance();
private final String name;
private final Network network;
private final Set<String> elements = new HashSet<String>();
private HColor color;
private String description;
@Override
public String toString() {
return name + " " + network + " " + elements;
}
public NwGroup(String name, Network network) {
this.name = name;
this.network = network;
}
public final String getName() {
return name;
}
public void addElement(String name) {
this.elements.add(name);
}
public boolean matches(LinkedElement tested) {
if (network != null && network != tested.getNetwork()) {
return false;
}
return elements.contains(tested.getElement().getName());
}
public final HColor getColor() {
return color;
}
public final void setColor(HColor color) {
this.color = color;
}
public void setDescription(String value) {
this.description = value;
}
public void drawGroup(UGraphic ug, MinMax size, ISkinParam skinParam) {
TextBlock block = null;
Dimension2D blockDim = null;
if (description != null) {
block = Display.getWithNewlines(description).create(getGroupDescriptionFontConfiguration(),
HorizontalAlignment.LEFT, skinParam);
blockDim = block.calculateDimension(ug.getStringBounder());
final double dy = size.getMinY() - blockDim.getHeight();
size = size.addPoint(size.getMinX(), dy);
}
HColor color = getColor();
if (color == null) {
color = colors.getColorIfValid("#AAA");
}
size.draw(ug, color);
if (block != null) {
block.drawU(ug.apply(new UTranslate(size.getMinX() + 5, size.getMinY())));
}
}
private FontConfiguration getGroupDescriptionFontConfiguration() {
final UFont font = UFont.serif(11);
return new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
}
public final Network getNetwork() {
return network;
}
}

View File

@ -35,6 +35,7 @@
package net.sourceforge.plantuml.nwdiag;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -53,7 +54,7 @@ import net.sourceforge.plantuml.svek.PackageStyle;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class DiagElement {
public class Square {
private USymbol shape = USymbol.RECTANGLE;
private final String name;
@ -67,7 +68,7 @@ public class DiagElement {
return name;
}
public DiagElement(String name, Network network, ISkinSimple spriteContainer) {
public Square(String name, Network network, ISkinSimple spriteContainer) {
this.description = name;
this.mainNetwork = network;
this.name = name;
@ -90,7 +91,7 @@ public class DiagElement {
return new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
}
public LinkedElement asTextBlock(Map<Network, String> conns, Network next) {
public LinkedElement asTextBlock(Map<Network, String> conns, List<Network> networks) {
final Map<Network, TextBlock> conns2 = new LinkedHashMap<Network, TextBlock>();
for (Entry<Network, String> ent : conns.entrySet()) {
conns2.put(ent.getKey(), toTextBlock(ent.getValue()));
@ -100,7 +101,7 @@ public class DiagElement {
final TextBlock desc = toTextBlock(description);
final TextBlock box = shape.asSmall(TextBlockUtils.empty(0, 0), desc, TextBlockUtils.empty(0, 0), symbolContext,
HorizontalAlignment.CENTER);
return new LinkedElement(this, box, mainNetwork, next, conns2);
return new LinkedElement(this, box, conns2, networks);
}
public String getDescription() {

View File

@ -79,10 +79,10 @@ public class PngIO {
public static void write(RenderedImage image, OutputStream os, String metadata, int dpi, String debugData)
throws IOException {
if (forceImageIO == false && metadata != null && checkPNGMetadata()) {
PngIOMetadata.writeWithMetadata(image, os, metadata, dpi, debugData);
} else {
if (metadata == null) {
ImageIO.write(image, "png", os);
} else {
PngIOMetadata.writeWithMetadata(image, os, metadata, dpi, debugData);
}
}
@ -124,23 +124,4 @@ public class PngIO {
// pngw.end();
// }
public static boolean forceImageIO = false;
static boolean checkPNGMetadata() {
try {
final Class cl = Class.forName("com.sun.imageio.plugins.png.PNGMetadata");
if (cl == null) {
Log.info("Cannot load com.sun.imageio.plugins.png.PNGMetadata");
forceImageIO = true;
return false;
}
Log.info("Ok for com.sun.imageio.plugins.png.PNGMetadata");
return true;
} catch (Exception e) {
Log.info("Error loading com.sun.imageio.plugins.png.PNGMetadata " + e);
forceImageIO = true;
return false;
}
}
}

View File

@ -35,17 +35,21 @@
*/
package net.sourceforge.plantuml.png;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import javax.imageio.IIOImage;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageOutputStream;
import com.sun.imageio.plugins.png.PNGMetadata;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.security.ImageIO;
@ -56,60 +60,44 @@ public class PngIOMetadata {
public static void writeWithMetadata(RenderedImage image, OutputStream os, String metadata, int dpi,
String debugData) throws IOException {
// Create & populate metadata
PNGMetadata pngMetadata = null;
try {
pngMetadata = new PNGMetadata();
} catch (Throwable e) {
Log.info("Cannot create com.sun.imageio.plugins.png.PNGMetadata");
PngIO.forceImageIO = true;
ImageIO.write(image, "png", os);
return;
}
writeInternal(image, os, metadata, dpi, debugData, pngMetadata);
// Log.info("Cannot create com.sun.imageio.plugins.png.PNGMetadata");
// PngIO.forceImageIO = true;
// ImageIO.write(image, "png", os);
writeInternal(image, os, metadata, dpi, debugData);
}
private static void writeInternal(RenderedImage image, OutputStream os, String metadata, int dpi, String debugData,
final PNGMetadata pngMetadata) throws IOException {
private static void writeInternal(RenderedImage image, OutputStream os, String metadata, int dpi, String debugData)
throws IOException {
final ImageWriter writer = javax.imageio.ImageIO.getImageWritersByFormatName("png").next();
final ImageWriteParam writeParam = writer.getDefaultWriteParam();
final ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier
.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
final IIOMetadata meta = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
if (dpi != 96) {
pngMetadata.pHYs_present = true;
pngMetadata.pHYs_unitSpecifier = PNGMetadata.PHYS_UNIT_METER;
pngMetadata.pHYs_pixelsPerUnitXAxis = (int) Math.round(dpi / .0254 + 0.5);
pngMetadata.pHYs_pixelsPerUnitYAxis = pngMetadata.pHYs_pixelsPerUnitXAxis;
}
if (metadata != null) {
// pngMetadata.zTXt_keyword.add("plantuml");
// pngMetadata.zTXt_compressionMethod.add(new Integer(0));
// pngMetadata.zTXt_text.add(metadata);
pngMetadata.iTXt_compressionFlag.add(new Boolean(true));
pngMetadata.iTXt_compressionMethod.add(new Integer(0));
pngMetadata.iTXt_keyword.add("plantuml");
pngMetadata.iTXt_languageTag.add("");
pngMetadata.iTXt_text.add(metadata);
pngMetadata.iTXt_translatedKeyword.add("");
addDpi(meta, dpi);
}
if (debugData != null) {
pngMetadata.tEXt_keyword.add("debug");
pngMetadata.tEXt_text.add(debugData);
addText(meta, "debug", debugData);
}
addText(meta, "copyleft", copyleft);
addiText(meta, "plantuml", metadata);
pngMetadata.tEXt_keyword.add("copyleft");
pngMetadata.tEXt_text.add(copyleft);
Log.debug("PngIOMetadata pngMetadata=" + pngMetadata);
Log.debug("PngIOMetadata pngMetadata=" + meta);
// Render the PNG to file
final IIOImage iioImage = new IIOImage(image, null, pngMetadata);
final IIOImage iioImage = new IIOImage(image, null, meta);
Log.debug("PngIOMetadata iioImage=" + iioImage);
// Attach the metadata
final ImageWriter imagewriter = getImageWriter();
Log.debug("PngIOMetadata imagewriter=" + imagewriter);
// See http://plantuml.sourceforge.net/qa/?qa=4367/sometimes-missing-response-headers-for-broken-png-images
// See
// http://plantuml.sourceforge.net/qa/?qa=4367/sometimes-missing-response-headers-for-broken-png-images
// Code provided by Michael Griffel
synchronized (imagewriter) {
final ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(os);
@ -131,6 +119,56 @@ public class PngIOMetadata {
}
}
private static void addDpi(IIOMetadata meta, double dpi) throws IIOInvalidTreeException {
final IIOMetadataNode dimension = new IIOMetadataNode("Dimension");
final IIOMetadataNode horizontalPixelSize = new IIOMetadataNode("HorizontalPixelSize");
final double value = dpi / 0.0254 / 1000;
horizontalPixelSize.setAttribute("value", Double.toString(value));
dimension.appendChild(horizontalPixelSize);
final IIOMetadataNode verticalPixelSize = new IIOMetadataNode("VerticalPixelSize");
verticalPixelSize.setAttribute("value", Double.toString(value));
dimension.appendChild(verticalPixelSize);
final IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
root.appendChild(dimension);
meta.mergeTree("javax_imageio_1.0", root);
}
private static void addiText(IIOMetadata meta, String key, String value) throws IIOInvalidTreeException {
final IIOMetadataNode text = new IIOMetadataNode("iTXt");
final IIOMetadataNode entry = new IIOMetadataNode("iTXtEntry");
entry.setAttribute("keyword", key);
entry.setAttribute("compressionFlag", "true");
entry.setAttribute("compressionMethod", "0");
entry.setAttribute("languageTag", "");
entry.setAttribute("translatedKeyword", "");
entry.setAttribute("text", value);
text.appendChild(entry);
final IIOMetadataNode root = new IIOMetadataNode("javax_imageio_png_1.0");
root.appendChild(text);
meta.mergeTree("javax_imageio_png_1.0", root);
}
private static void addText(IIOMetadata meta, String key, String value) throws IIOInvalidTreeException {
final IIOMetadataNode text = new IIOMetadataNode("tEXt");
final IIOMetadataNode entry = new IIOMetadataNode("tEXtEntry");
entry.setAttribute("keyword", key);
entry.setAttribute("value", value);
text.appendChild(entry);
final IIOMetadataNode root = new IIOMetadataNode("javax_imageio_png_1.0");
root.appendChild(text);
meta.mergeTree("javax_imageio_png_1.0", root);
}
private static ImageWriter getImageWriter() {
final Iterator<ImageWriter> iterator = ImageIO.getImageWritersBySuffix("png");
for (final Iterator<ImageWriter> it = ImageIO.getImageWritersBySuffix("png"); it.hasNext();) {

View File

@ -38,7 +38,6 @@ package net.sourceforge.plantuml.sprite;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.graphic.AbstractTextBlock;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
@ -48,13 +47,16 @@ import net.sourceforge.plantuml.ugraphic.color.HColor;
public class SpriteSvg implements Sprite {
private final UImageSvg img;
// private final UImageSvg img;
private final String svg;
public SpriteSvg(String svg) {
this.img = new UImageSvg(new SvgString(svg, 1));
this.svg = svg;
// this.img = new UImageSvg(new SvgString(svg, 1));
}
public TextBlock asTextBlock(final HColor color, final double scale) {
final UImageSvg img = new UImageSvg(svg, scale);
return new AbstractTextBlock() {
public void drawU(UGraphic ug) {

View File

@ -77,8 +77,6 @@ import net.sourceforge.plantuml.cucadiagram.IGroup;
import net.sourceforge.plantuml.cucadiagram.ILeaf;
import net.sourceforge.plantuml.cucadiagram.LeafType;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.cucadiagram.MethodsOrFieldsArea;
import net.sourceforge.plantuml.cucadiagram.PortionShower;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.cucadiagram.UnparsableGraphvizException;

View File

@ -47,7 +47,6 @@ import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.creole.CreoleMode;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;

View File

@ -44,9 +44,7 @@ import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.SkinParamUtils;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.creole.CreoleMode;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;

View File

@ -66,11 +66,11 @@ import org.w3c.dom.Element;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.SignatureUtils;
import net.sourceforge.plantuml.SvgString;
import net.sourceforge.plantuml.code.Base64Coder;
import net.sourceforge.plantuml.security.ImageIO;
import net.sourceforge.plantuml.security.SecurityUtils;
import net.sourceforge.plantuml.tikz.TikzGraphics;
import net.sourceforge.plantuml.ugraphic.UImageSvg;
import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.USegment;
import net.sourceforge.plantuml.ugraphic.USegmentType;
@ -768,7 +768,7 @@ public class SvgGraphics {
private final Map<String, String> images = new HashMap<String, String>();
public void svgImage(SvgString image, double x, double y) {
public void svgImage(UImageSvg image, double x, double y) {
if (hidden == false) {
String svg = manageScale(image);
final String pos = "<svg x=\"" + format(x) + "\" y=\"" + format(y) + "\">";
@ -782,14 +782,22 @@ public class SvgGraphics {
ensureVisible(x + image.getData("width"), y + image.getData("height"));
}
private String manageScale(SvgString svg) {
final double svgScale = svg.getScale();
private String manageScale(UImageSvg svgImage) {
final double svgScale = svgImage.getScale();
String svg = svgImage.getSvg(false);
if (svgScale * scale == 1) {
return svg.getSvg(false);
return svg;
}
final String svg2 = svg.replace('\n', ' ').replace('\r', ' ');
if (svg2.contains("<g ") == false && svg2.contains("<g>") == false) {
svg = svg.replaceFirst("\\<svg\\>", "<svg><g>");
svg = svg.replaceFirst("\\</svg\\>", "</g></svg>");
}
final String factor = format(svgScale);
final String s1 = "\\<g\\b";
final String s2 = "<g transform=\"scale(" + format(svgScale) + "," + format(svgScale) + ")\" ";
return svg.getSvg(false).replaceFirst(s1, s2);
final String s2 = "<g transform=\"scale(" + factor + "," + factor + ")\" ";
svg = svg.replaceFirst(s1, s2);
return svg;
}
private String toBase64(BufferedImage image) throws IOException {

View File

@ -387,7 +387,7 @@ public class TContext {
private String pendingAdd = null;
public String applyFunctionsAndVariables(TMemory memory, LineLocation location, String str)
public String applyFunctionsAndVariables(TMemory memory, LineLocation location, final String str)
throws EaterException, EaterExceptionLocated {
// https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore%E2%80%93Horspool_algorithm
// https://stackoverflow.com/questions/1326682/java-replacing-multiple-different-substring-in-a-string-at-once-or-in-the-most
@ -414,12 +414,17 @@ public class TContext {
}
if (function.getFunctionType() == TFunctionType.PROCEDURE) {
this.pendingAdd = result.toString();
executeVoid3(location, memory, sub, function);
executeVoid3(location, memory, sub, function, call);
i += call.getCurrentPosition();
final String remaining = str.substring(i);
if (remaining.length() > 0) {
appendToLastResult(remaining);
}
return null;
}
if (function.getFunctionType() == TFunctionType.LEGACY_DEFINELONG) {
this.pendingAdd = str.substring(0, i);
executeVoid3(location, memory, sub, function);
executeVoid3(location, memory, sub, function, call);
return null;
}
assert function.getFunctionType() == TFunctionType.RETURN_FUNCTION
@ -437,9 +442,16 @@ public class TContext {
return result.toString();
}
private void executeVoid3(LineLocation location, TMemory memory, String s, TFunction function)
throws EaterException, EaterExceptionLocated {
function.executeProcedure(this, memory, location, s);
private void appendToLastResult(String remaining) {
final StringLocated last = this.resultList.get(this.resultList.size() - 1);
this.resultList.set(this.resultList.size() - 1, last.append(remaining));
}
private void executeVoid3(LineLocation location, TMemory memory, String s, TFunction function,
EaterFunctionCall call) throws EaterException, EaterExceptionLocated {
function.executeProcedureInternal(this, memory, call.getValues(), call.getNamedArguments());
// function.executeProcedure(this, memory, location, s, call.getValues(),
// call.getNamedArguments());
}
private void executeImport(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated {

View File

@ -39,10 +39,8 @@ import java.util.Map;
import java.util.Set;
import net.sourceforge.plantuml.LineLocation;
import net.sourceforge.plantuml.StringLocated;
import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.EaterFunctionCall;
import net.sourceforge.plantuml.tim.TContext;
import net.sourceforge.plantuml.tim.TFunction;
import net.sourceforge.plantuml.tim.TFunctionSignature;
@ -66,22 +64,19 @@ public class InvokeProcedure implements TFunction {
public void executeProcedure(TContext context, TMemory memory, LineLocation location, String s)
throws EaterException, EaterExceptionLocated {
final EaterFunctionCall call = new EaterFunctionCall(new StringLocated(s, location), false, isUnquoted());
call.analyze((TContext) context, memory);
final List<TValue> values = call.getValues();
final String fname = values.get(0).toString();
final List<TValue> args = values.subList(1, values.size());
final TFunctionSignature signature = new TFunctionSignature(fname, args.size());
throw new UnsupportedOperationException();
}
public void executeProcedureInternal(TContext context, TMemory memory, List<TValue> args, Map<String, TValue> named)
throws EaterException, EaterExceptionLocated {
final String fname = args.get(0).toString();
final List<TValue> sublist = args.subList(1, args.size());
final TFunctionSignature signature = new TFunctionSignature(fname, sublist.size());
final TFunction func = context.getFunctionSmart(signature);
if (func == null) {
throw EaterException.located("Cannot find void function " + fname);
}
func.executeProcedureInternal(context, memory, args, call.getNamedArguments());
}
public void executeProcedureInternal(TContext context, TMemory memory, List<TValue> args,
Map<String, TValue> named) {
throw new UnsupportedOperationException();
func.executeProcedureInternal(context, memory, sublist, named);
}
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,

View File

@ -35,26 +35,93 @@
*/
package net.sourceforge.plantuml.ugraphic;
import net.sourceforge.plantuml.SvgString;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.SignatureUtils;
public class UImageSvg implements UShape {
private final SvgString svg;
private final String svg;
private final double scale;
public UImageSvg(SvgString tmp) {
this.svg = tmp;
public UImageSvg(String svg, double scale) {
if (svg == null) {
throw new IllegalArgumentException();
}
this.svg = svg;
this.scale = scale;
}
public final SvgString getSvg() {
return svg;
public String getMD5Hex() {
return SignatureUtils.getMD5Hex(svg);
}
public String getSvg(boolean raw) {
String result = svg;
if (raw) {
return result;
}
if (result.startsWith("<?xml")) {
final int idx = result.indexOf("<svg");
result = result.substring(idx);
}
if (result.startsWith("<svg")) {
final int idx = result.indexOf(">");
result = "<svg>" + result.substring(idx + 1);
}
final String style = extractSvgStyle();
if (style != null) {
final String background = extractBackground(style);
if (background != null) {
result = result.replaceFirst("<g>", "<g><rect fill=\"" + background + "\" style=\"" + style + "\" /> ");
}
}
if (result.startsWith("<svg>") == false) {
throw new IllegalArgumentException();
}
return result;
}
private String extractBackground(String style) {
final Pattern p = Pattern.compile("background:([^;]+)");
final Matcher m = p.matcher(style);
if (m.find()) {
return m.group(1);
}
return null;
}
private String extractSvgStyle() {
final Pattern p = Pattern.compile("(?i)\\<svg[^>]+style=\"([^\">]+)\"");
final Matcher m = p.matcher(svg);
if (m.find()) {
return m.group(1);
}
return null;
}
public int getData(String name) {
final Pattern p = Pattern.compile("(?i)" + name + "\\W+(\\d+)");
final Matcher m = p.matcher(svg);
if (m.find()) {
final String s = m.group(1);
return Integer.parseInt(s);
}
throw new IllegalStateException("Cannot find " + name);
}
public int getHeight() {
return svg.getData("height");
return this.getData("height");
}
public int getWidth() {
return svg.getData("width");
return this.getData("width");
}
public double getScale() {
return scale;
}
}

View File

@ -116,4 +116,8 @@ public class UTranslate implements UChange {
return new UTranslate(dy, dx);
}
public Point2D getPosition() {
return new Point2D.Double(dx, dy);
}
}

View File

@ -45,6 +45,6 @@ public class DriverImageSvgSvg implements UDriver<SvgGraphics> {
public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) {
final UImageSvg image = (UImageSvg) ushape;
svg.svgImage(image.getSvg(), x, y);
svg.svgImage(image, x, y);
}
}

View File

@ -44,7 +44,7 @@ public class Version {
private static final int MAJOR_SEPARATOR = 1000000;
public static int version() {
return 1202023;
return 1202024;
}
public static int versionPatched() {
@ -93,7 +93,7 @@ public class Version {
}
public static long compileTime() {
return 1607886898413L;
return 1608310836208L;
}
public static String compileTimeString() {

View File

@ -52,10 +52,8 @@ public class CommandComponent extends SingleLineCommand2<WireDiagram> {
static IRegex getRegexConcat() {
return RegexConcat.build(CommandComponent.class.getName(), RegexLeaf.start(), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("TYPE", "component"), //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("NAME", "([\\w]+)"), //
new RegexLeaf("INDENT", "([\\s\\t]*)"), //
new RegexLeaf("NAME", "\\$([\\w]+)"), //
new RegexOptional(new RegexConcat( //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("\\["), //
@ -64,19 +62,25 @@ public class CommandComponent extends SingleLineCommand2<WireDiagram> {
new RegexLeaf("HEIGHT", "([\\d]+)"), //
new RegexLeaf("\\]")) //
), //
RegexLeaf.spaceZeroOrMore(), //
RegexLeaf.end());
}
@Override
protected CommandExecutionResult executeArg(WireDiagram diagram, LineLocation location, RegexResult arg) {
final String indent = arg.get("INDENT", 0);
final String name = arg.get("NAME", 0);
final String width = arg.get("WIDTH", 0);
final String height = arg.get("HEIGHT", 0);
if (width != null) {
return diagram.addComponent(name, Integer.parseInt(width), Integer.parseInt(height));
} else {
return diagram.addComponent(name);
int width = 0;
int height = 0;
final String widthString = arg.get("WIDTH", 0);
final String heightString = arg.get("HEIGHT", 0);
if (widthString != null) {
width = Integer.parseInt(widthString);
height = Integer.parseInt(heightString);
}
return diagram.addComponent(indent, name, width, height);
}
}

View File

@ -43,27 +43,36 @@ import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexResult;
public class CommandContainer extends SingleLineCommand2<WireDiagram> {
public class CommandGoto extends SingleLineCommand2<WireDiagram> {
public CommandContainer() {
public CommandGoto() {
super(false, getRegexConcat());
}
static IRegex getRegexConcat() {
return RegexConcat.build(CommandContainer.class.getName(), RegexLeaf.start(), //
return RegexConcat.build(CommandGoto.class.getName(), RegexLeaf.start(), //
new RegexLeaf("INDENT", "([\\s\\t]*)"), //
new RegexLeaf("goto"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("TYPE", "component"), //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("NAME", "([\\w]+)"), //
new RegexLeaf("\\("), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("X", "(\\d+)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf(","), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("Y", "(\\d+)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\{"), //
RegexLeaf.end());
}
@Override
protected CommandExecutionResult executeArg(WireDiagram diagram, LineLocation location, RegexResult arg) {
final String name = arg.get("NAME", 0);
return diagram.addStartContainer(name);
final String indent = arg.get("INDENT", 0);
final double x = Double.parseDouble(arg.get("X", 0));
final double y = Double.parseDouble(arg.get("Y", 0));
return diagram.wgoto(indent, x, y);
}
}

View File

@ -37,43 +37,42 @@ package net.sourceforge.plantuml.wire;
import net.sourceforge.plantuml.LineLocation;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.Position;
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.IRegex;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexResult;
public class CommandPin extends SingleLineCommand2<WireDiagram> {
public class CommandMove extends SingleLineCommand2<WireDiagram> {
public CommandPin() {
public CommandMove() {
super(false, getRegexConcat());
}
static IRegex getRegexConcat() {
return RegexConcat.build(CommandPin.class.getName(), RegexLeaf.start(), //
return RegexConcat.build(CommandMove.class.getName(), RegexLeaf.start(), //
new RegexLeaf("INDENT", "([\\s\\t]*)"), //
new RegexLeaf("move"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\("), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("X", "(-?\\d+)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf(","), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("Y", "(-?\\d+)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexOr("POSITION", //
new RegexLeaf("top"), //
new RegexLeaf("bottom"), //
new RegexLeaf("left"), //
new RegexLeaf("right")), //
new RegexLeaf(":"), //
new RegexLeaf("PINS", "(.*)"), //
RegexLeaf.end());
}
@Override
protected CommandExecutionResult executeArg(WireDiagram diagram, LineLocation location, RegexResult arg) {
final Position position = Position.fromString(arg.get("POSITION", 0));
final String pins = arg.get("PINS", 0);
for (String s : pins.split(",")) {
diagram.addPin(position, s.trim());
}
return CommandExecutionResult.ok();
final String indent = arg.get("INDENT", 0);
final double x = Double.parseDouble(arg.get("X", 0));
final double y = Double.parseDouble(arg.get("Y", 0));
return diagram.wmove(indent, x, y);
}
}

View File

@ -51,14 +51,16 @@ public class CommandNewColumn extends SingleLineCommand2<WireDiagram> {
static IRegex getRegexConcat() {
return RegexConcat.build(CommandNewColumn.class.getName(), RegexLeaf.start(), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("INDENT", "([\\s\\t]*)"), //
new RegexLeaf("-+"), //
RegexLeaf.spaceZeroOrMore(), //
RegexLeaf.end());
}
@Override
protected CommandExecutionResult executeArg(WireDiagram diagram, LineLocation location, RegexResult arg) {
return diagram.newColumn();
final String indent = arg.get("INDENT", 0);
return diagram.newColumn(indent);
}
}

View File

@ -41,27 +41,55 @@ import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.IRegex;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexOptional;
import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
public class CommandVspace extends SingleLineCommand2<WireDiagram> {
public class CommandSpot extends SingleLineCommand2<WireDiagram> {
public CommandVspace() {
public CommandSpot() {
super(false, getRegexConcat());
}
static IRegex getRegexConcat() {
return RegexConcat.build(CommandVspace.class.getName(), RegexLeaf.start(), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("TYPE", "vspace"), //
return RegexConcat.build(CommandSpot.class.getName(), RegexLeaf.start(), //
new RegexLeaf("spot"), //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("HEIGHT", "([\\d]+)"), //
new RegexLeaf("NAME", "\\$([\\w][.\\w]*)"), //
new RegexOptional(new RegexConcat(//
new RegexLeaf("\\("), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("X", "(-?\\d+(%|%[-+]\\d+)?)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf(","), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("Y", "(-?\\d+(%|%[-+]\\d+)?)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\)") //
)), //
new RegexOptional(new RegexConcat( //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("COLOR", "(#\\w+)?"))), //
RegexLeaf.spaceZeroOrMore(), //
RegexLeaf.end());
}
@Override
protected CommandExecutionResult executeArg(WireDiagram diagram, LineLocation location, RegexResult arg) {
final String height = arg.get("HEIGHT", 0);
return diagram.vspace(Integer.parseInt(height));
final String name = arg.get("NAME", 0);
final String stringColor = arg.get("COLOR", 0);
HColor color = null;
if (stringColor != null) {
color = HColorSet.instance().getColorIfValid(stringColor);
}
final String x = arg.get("X", 0);
final String y = arg.get("Y", 0);
return diagram.spot(name, color, x, y);
}
}

View File

@ -41,31 +41,59 @@ import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.IRegex;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexOptional;
import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
public class CommandPinSpace extends SingleLineCommand2<WireDiagram> {
public class CommandWLink extends SingleLineCommand2<WireDiagram> {
public CommandPinSpace() {
public CommandWLink() {
super(false, getRegexConcat());
}
static IRegex getRegexConcat() {
return RegexConcat.build(CommandPinSpace.class.getName(), RegexLeaf.start(), //
return RegexConcat.build(CommandWLink.class.getName(), RegexLeaf.start(), //
new RegexLeaf("NAME1", "\\$([\\w][.\\w]*)"), //
new RegexOptional(new RegexConcat(//
new RegexLeaf("\\("), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("X1", "(-?\\d+(%|%[-+]\\d+)?)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf(","), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("Y1", "(-?\\d+(%|%[-+]\\d+)?)"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\)") //
)), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STYLE", "([-=])\\>"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("NAME2", "\\$([\\w][.\\w]*)"), //
new RegexOptional(new RegexConcat( //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("COLOR", "(#\\w+)?"))), //
RegexLeaf.spaceZeroOrMore(), //
new RegexOr("POSITION", //
new RegexLeaf("top"), //
new RegexLeaf("bottom"), //
new RegexLeaf("left"), //
new RegexLeaf("right")), //
new RegexLeaf(" "), //
new RegexLeaf(".*"), //
RegexLeaf.end());
}
@Override
protected CommandExecutionResult executeArg(WireDiagram diagram, LineLocation location, RegexResult arg) {
return CommandExecutionResult.ok();
final String name1 = arg.get("NAME1", 0);
final String x1 = arg.get("X1", 0);
final String y1 = arg.get("Y1", 0);
final String name2 = arg.get("NAME2", 0);
final WLinkType type = WLinkType.from(arg.get("STYLE", 0));
final String stringColor = arg.get("COLOR", 0);
HColor color = null;
if (stringColor != null) {
color = HColorSet.instance().getColorIfValid(stringColor);
}
return diagram.link(name1, x1, y1, name2, type, color);
}
}

View File

@ -0,0 +1,70 @@
/* ========================================================================
* 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.wire;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UShape;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class Spot {
private final WBlock block;
private final HColor color;
private final String x;
private final String y;
public Spot(WBlock block, HColor color, String x, String y) {
this.block = block;
this.color = color == null ? HColorUtils.RED : color;
this.x = x == null ? "0" : x;
this.y = y == null ? "0" : y;
}
public void drawMe(UGraphic ug) {
final UTranslate pos = block.getAbsolutePosition(x, y);
final UTranslate tr = pos.compose(new UTranslate(-2, -2));
final UShape circle = new UEllipse(5, 5);
ug = ug.apply(color).apply(color.bg());
ug.apply(tr).draw(circle);
}
}

View File

@ -0,0 +1,280 @@
/* ========================================================================
* 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.wire;
import java.awt.geom.Dimension2D;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.SpriteContainerEmpty;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class WBlock {
private final String name;
private final double forcedWidth;
private final double forcedHeight;
private final List<WBlock> children = new ArrayList<WBlock>();
private UTranslate position = new UTranslate();
private WBlock parent;
private UTranslate futureGoto;
private UTranslate futureMove = new UTranslate(0, 20);
public UTranslate getAbsolutePosition(String supx, String supy) {
if (parent == null) {
return position;
}
final UTranslate p = parent.getAbsolutePosition("0", "0");
final double x = position.getDx() + p.getDx() + parseWidth(supx);
final double y = position.getDy() + p.getDy() + parseHeight(supy);
return new UTranslate(x, y);
}
private double parseWidth(String value) {
if (value.endsWith("%")) {
final double p = Double.parseDouble(value.substring(0, value.length() - 1)) / 100.0;
return getMaxDimension().getWidth() * p;
}
if (value.contains("%")) {
final StringTokenizer st = new StringTokenizer(value, "%");
final String v1 = st.nextToken();
final String v2 = st.nextToken();
final double p = Double.parseDouble(v1) / 100.0;
return getMaxDimension().getWidth() * p + Double.parseDouble(v2);
}
return Double.parseDouble(value);
}
private double parseHeight(String value) {
if (value.endsWith("%")) {
final double p = Double.parseDouble(value.substring(0, value.length() - 1)) / 100.0;
return getMaxDimension().getHeight() * p;
}
if (value.contains("%")) {
final StringTokenizer st = new StringTokenizer(value, "%");
final String v1 = st.nextToken();
final String v2 = st.nextToken();
final double p = Double.parseDouble(v1) / 100.0;
return getMaxDimension().getHeight() * p + Double.parseDouble(v2);
}
return Double.parseDouble(value);
}
@Override
public String toString() {
return name + " " + position;
}
public WBlock(String name, double width, double height) {
this.name = name;
this.forcedWidth = width;
this.forcedHeight = height;
}
private WBlock getChildByName(String name) {
for (WBlock child : children) {
if (name.equals(child.getName())) {
return child;
}
}
return null;
}
public WBlock getBlock(String name) {
final int x = name.indexOf('.');
if (x == -1) {
return getChildByName(name);
}
final WBlock first = getChildByName(name.substring(0, x));
if (first == null) {
return null;
}
return first.getBlock(name.substring(x + 1));
}
private String getName() {
return name;
}
public CommandExecutionResult newColumn(int level) {
if (level == 0) {
final Dimension2D max = getNaturalDimension();
futureGoto = new UTranslate(max.getWidth() + 10, 20);
futureMove = new UTranslate();
return CommandExecutionResult.ok();
}
return getLastChild().newColumn(level - 1);
}
public CommandExecutionResult wgoto(int level, double x, double y) {
if (level == 0) {
futureGoto = new UTranslate(x, y);
futureMove = new UTranslate();
return CommandExecutionResult.ok();
}
return getLastChild().wgoto(level - 1, x, y);
}
public CommandExecutionResult wmove(int level, double x, double y) {
if (level == 0) {
futureMove = futureMove.compose(new UTranslate(x, y));
return CommandExecutionResult.ok();
}
return getLastChild().wmove(level - 1, x, y);
}
public CommandExecutionResult addComponent(int level, String name, double width, double height) {
if (name.contains(".")) {
throw new IllegalArgumentException();
}
if (getChildByName(name) != null) {
return CommandExecutionResult.error("Component exists already");
}
if (level == 0) {
final WBlock newBlock = new WBlock(name, width, height);
newBlock.position = getNextPosition();
children.add(newBlock);
newBlock.parent = this;
return CommandExecutionResult.ok();
}
final WBlock last = getLastChild();
return last.addComponent(level - 1, name, width, height);
}
private UTranslate getNextPosition() {
final UTranslate result;
if (futureGoto != null) {
result = futureGoto.compose(futureMove);
} else {
final WBlock last = getLastChild();
if (last == null) {
result = futureMove.compose(UTranslate.dx(10));
} else {
final Dimension2D dim = last.getMaxDimension();
result = last.position.compose(UTranslate.dy(dim.getHeight())).compose(futureMove);
}
}
futureGoto = null;
futureMove = new UTranslate(0, 20);
return result;
}
private WBlock getLastChild() {
if (children.size() == 0) {
return null;
}
return children.get(children.size() - 1);
}
public void drawMe(UGraphic ug) {
drawBox(ug);
final UFont font = UFont.sansSerif(12);
final FontConfiguration fc = new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
final Display display = Display.create(name.replace('_', ' '));
final TextBlock text = display.create(fc, HorizontalAlignment.LEFT, new SpriteContainerEmpty());
text.drawU(ug.apply(UTranslate.dx(5)));
}
private void drawBox(UGraphic ug) {
ug = ug.apply(HColorUtils.BLACK);
if (name.length() > 0) {
final URectangle rect = new URectangle(getMaxDimension());
ug.draw(rect);
}
for (WBlock child : children) {
child.drawMe(ug.apply(child.position));
}
}
private Dimension2D getMaxDimension() {
if (children.size() > 0) {
if (forcedWidth != 0) {
return new Dimension2DDouble(forcedWidth, forcedHeight);
}
return getNaturalDimension();
}
final double x = forcedWidth == 0 ? 100 : forcedWidth;
final double y = forcedHeight == 0 ? 100 : forcedHeight;
return new Dimension2DDouble(x, y);
}
private Dimension2D getNaturalDimension() {
double x = 0;
double y = 0;
for (WBlock child : children) {
final Dimension2D dim = child.getMaxDimension();
x = Math.max(x, child.position.getDx() + dim.getWidth() + 10);
y = Math.max(y, child.position.getDy() + dim.getHeight() + 10);
}
return new Dimension2DDouble(x, y);
}
private UTranslate futureOut;
public UTranslate getNextOut(String x1, String y1, WLinkType type) {
final UTranslate result;
if (x1 != null && y1 != null) {
result = getAbsolutePosition(x1, y1);
} else if (futureOut == null) {
result = getAbsolutePosition("100%", "5");
} else {
result = futureOut;
}
futureOut = result.compose(UTranslate.dy(type.ySpaceForNext()));
return result;
}
}

View File

@ -0,0 +1,54 @@
/* ========================================================================
* 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.wire;
import java.awt.geom.Point2D;
import net.sourceforge.plantuml.ugraphic.UTranslate;
public class WCursor {
private UTranslate position = new UTranslate();
public Point2D getPosition() {
return position.getPosition();
}
public void move(double dx, double dy) {
position = position.compose(new UTranslate(dx, dy));
}
}

View File

@ -0,0 +1,91 @@
/* ========================================================================
* 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.wire;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class WLink {
private final UTranslate pos1;
private final double pos2x;
private final WLinkType type;
private final HColor color;
public WLink(WBlock block1, String x1, String y1, WBlock block2, WLinkType type, HColor color) {
pos1 = block1.getNextOut(x1, y1, type);
pos2x = block2.getAbsolutePosition("0", "0").getDx();
this.type = type;
this.color = color == null ? HColorUtils.BLACK : color;
}
public void drawMe(UGraphic ug) {
final double dx = pos2x - pos1.getDx() - 2;
ug = ug.apply(color).apply(color.bg());
if (type == WLinkType.NORMAL) {
final UPath path = new UPath();
path.moveTo(0, 0);
path.lineTo(-5, -5);
path.lineTo(-5, 5);
path.lineTo(0, 0);
path.closePath();
ug.apply(pos1.compose(UTranslate.dx(dx))).draw(path);
ug.apply(pos1.compose(UTranslate.dx(1))).draw(ULine.hline(dx));
} else if (type == WLinkType.BUS) {
final UPath path = new UPath();
path.moveTo(0, 0);
path.lineTo(dx - 15, 0);
path.lineTo(dx - 15, -5);
path.lineTo(dx, 5);
path.lineTo(dx - 15, 15);
path.lineTo(dx - 15, 10);
path.lineTo(0, 10);
path.lineTo(0, 0);
path.closePath();
ug.apply(pos1.compose(UTranslate.dx(1))).draw(path);
}
}
}

View File

@ -0,0 +1,62 @@
/* ========================================================================
* 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.wire;
public enum WLinkType {
NORMAL, BUS;
static public WLinkType from(String arg) {
if (arg.equals("-")) {
return WLinkType.NORMAL;
}
if (arg.equals("=")) {
return WLinkType.BUS;
}
throw new IllegalArgumentException();
}
public double ySpaceForNext() {
switch (this) {
case NORMAL:
return 15;
case BUS:
return 25;
}
throw new IllegalArgumentException();
}
}

View File

@ -39,6 +39,8 @@ 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.List;
import net.sourceforge.plantuml.AnnotatedWorker;
import net.sourceforge.plantuml.FileFormatOption;
@ -49,7 +51,6 @@ import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.UseStyle;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.Position;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.graphic.InnerStrategy;
@ -65,9 +66,9 @@ import net.sourceforge.plantuml.ugraphic.color.HColor;
public class WireDiagram extends UmlDiagram {
private final Block root = new Block(getSkinParam());
private Block current = root;
private Block last;
private final WBlock root = new WBlock("", 0, 0);
private final List<Spot> spots = new ArrayList<Spot>();
private final List<WLink> links = new ArrayList<WLink>();
public DiagramDescription getDescription() {
return new DiagramDescription("Wire Diagram");
@ -124,7 +125,8 @@ public class WireDiagram extends UmlDiagram {
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return getDrawingElement().calculateDimension(stringBounder);
// return getDrawingElement().calculateDimension(stringBounder);
throw new UnsupportedOperationException();
}
@ -139,45 +141,59 @@ public class WireDiagram extends UmlDiagram {
}
private void drawMe(UGraphic ug) {
getDrawingElement().drawU(ug);
root.drawMe(ug);
for (Spot spot : spots) {
spot.drawMe(ug);
}
for (WLink link : links) {
link.drawMe(ug);
}
}
private TextBlock getDrawingElement() {
return current;
public CommandExecutionResult addComponent(String indent, String name, int width, int height) {
final int level = indent.replace(" ", "\t").length();
return this.root.addComponent(level, name, width, height);
}
public CommandExecutionResult addComponent(String name) {
return addComponent(name, 100, 100);
public CommandExecutionResult newColumn(String indent) {
final int level = indent.replace(" ", "\t").length();
return this.root.newColumn(level);
}
public CommandExecutionResult addComponent(String name, int width, int height) {
this.last = current.addNewBlock(name, width, height);
public CommandExecutionResult spot(String name, HColor color, String x, String y) {
final WBlock block = this.root.getBlock(name);
if (block == null) {
return CommandExecutionResult.error("No such element " + name);
}
final Spot spot = new Spot(block, color, x, y);
this.spots.add(spot);
return CommandExecutionResult.ok();
}
public CommandExecutionResult vspace(int vspace) {
current.vspace(vspace);
return CommandExecutionResult.ok();
public CommandExecutionResult wgoto(String indent, double x, double y) {
final int level = indent.replace(" ", "\t").length();
return this.root.wgoto(level, x, y);
}
public CommandExecutionResult newColumn() {
current.newColumn();
return CommandExecutionResult.ok();
public CommandExecutionResult wmove(String indent, double x, double y) {
final int level = indent.replace(" ", "\t").length();
return this.root.wmove(level, x, y);
}
public CommandExecutionResult addStartContainer(String name) {
current = current.createContainer(name);
return CommandExecutionResult.ok();
}
public CommandExecutionResult link(String name1, String x1, String y1, String name2, WLinkType type, HColor color) {
final WBlock block1 = this.root.getBlock(name1);
if (block1 == null) {
return CommandExecutionResult.error("No such element " + name1);
}
final WBlock block2 = this.root.getBlock(name2);
if (block2 == null) {
return CommandExecutionResult.error("No such element " + name2);
}
final WLink link = new WLink(block1, x1, y1, block2, type, color);
this.links.add(link);
public CommandExecutionResult componentEnd() {
current = current.componentEnd();
return CommandExecutionResult.ok();
}
public void addPin(Position position, String pin) {
last.addPin(position, pin);
}
}

View File

@ -54,11 +54,10 @@ public class WireDiagramFactory extends PSystemCommandFactory {
final List<Command> cmds = new ArrayList<Command>();
addCommonCommands1(cmds);
cmds.add(new CommandComponent());
cmds.add(new CommandContainer());
cmds.add(new CommandContainerEnd());
cmds.add(new CommandPin());
cmds.add(new CommandPinSpace());
cmds.add(new CommandVspace());
cmds.add(new CommandSpot());
cmds.add(new CommandGoto());
cmds.add(new CommandMove());
cmds.add(new CommandWLink());
cmds.add(new CommandNewColumn());
return cmds;

View File

@ -58,7 +58,6 @@ import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.IGroup;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.descdiagram.DescriptionDiagram;
import net.sourceforge.plantuml.utils.UniqueSequence;
import net.sourceforge.plantuml.version.Version;

View File

@ -58,7 +58,6 @@ import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.IGroup;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.statediagram.StateDiagram;
import net.sourceforge.plantuml.utils.UniqueSequence;
import net.sourceforge.plantuml.version.Version;