diff --git a/src/net/sourceforge/plantuml/activitydiagram3/Branch.java b/src/net/sourceforge/plantuml/activitydiagram3/Branch.java index 7e645663d..33858f663 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/Branch.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/Branch.java @@ -198,6 +198,8 @@ public class Branch { } public ISkinParam skinParam() { + if (gtile != null) + return gtile.skinParam(); return ftile.skinParam(); } @@ -226,9 +228,11 @@ public class Branch { } public final Display getDisplayPositive() { - final LinkRendering in = ftile.getInLinkRendering(); - if (in != null && Display.isNull(in.getDisplay()) == false) { - return in.getDisplay(); + if (ftile != null) { + final LinkRendering in = ftile.getInLinkRendering(); + if (in != null && Display.isNull(in.getDisplay()) == false) { + return in.getDisplay(); + } } return labelPositive.getDisplay(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionEnd.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionEnd.java index a80106c95..a5620019b 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionEnd.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionEnd.java @@ -37,10 +37,15 @@ package net.sourceforge.plantuml.activitydiagram3; import java.util.Objects; +import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.gtile.Gtile; +import net.sourceforge.plantuml.activitydiagram3.gtile.GtileCircleStart; import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.color.HColorUtils; public class InstructionEnd extends MonoSwimable implements Instruction { @@ -51,24 +56,34 @@ public class InstructionEnd extends MonoSwimable implements Instruction { this.inlinkRendering = Objects.requireNonNull(inlinkRendering); } + @Override + public Gtile createGtile(ISkinParam skinParam, StringBounder stringBounder) { + return new GtileCircleStart(stringBounder, skinParam, HColorUtils.BLACK, getSwimlaneIn(), null); + } + + @Override public Ftile createFtile(FtileFactory factory) { Ftile result = factory.end(getSwimlaneIn()); result = eventuallyAddNote(factory, result, result.getSwimlaneIn()); return result; } + @Override public CommandExecutionResult add(Instruction other) { throw new UnsupportedOperationException(); } + @Override final public boolean kill() { return false; } + @Override public LinkRendering getInLinkRendering() { return inlinkRendering; } + @Override public boolean containsBreak() { return false; } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java index d7827801b..28a01d9ea 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java @@ -38,12 +38,15 @@ package net.sourceforge.plantuml.activitydiagram3; import java.util.Collections; import java.util.Set; +import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileWithNotes; +import net.sourceforge.plantuml.activitydiagram3.gtile.Gtile; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.USymbol; import net.sourceforge.plantuml.graphic.color.Colors; import net.sourceforge.plantuml.sequencediagram.NotePosition; @@ -64,6 +67,7 @@ public class InstructionGroup extends AbstractInstruction implements Instruction private final double roundCorner; private PositionedNote note = null; + @Override public boolean containsBreak() { return list.containsBreak(); } @@ -81,10 +85,18 @@ public class InstructionGroup extends AbstractInstruction implements Instruction this.roundCorner = roundCorner; } + @Override public CommandExecutionResult add(Instruction ins) { return list.add(ins); } + @Override + public Gtile createGtile(ISkinParam skinParam, StringBounder stringBounder) { + Gtile tmp = list.createGtile(skinParam, stringBounder); + return tmp; + } + + @Override public Ftile createFtile(FtileFactory factory) { Ftile tmp = list.createFtile(factory); if (note != null) { @@ -97,14 +109,17 @@ public class InstructionGroup extends AbstractInstruction implements Instruction return parent; } + @Override final public boolean kill() { return list.kill(); } + @Override public LinkRendering getInLinkRendering() { return linkRendering; } + @Override public boolean addNote(Display note, NotePosition position, NoteType type, Colors colors, Swimlane swimlaneNote) { if (list.isEmpty()) { this.note = new PositionedNote(note, position, type, colors, swimlaneNote); @@ -113,18 +128,22 @@ public class InstructionGroup extends AbstractInstruction implements Instruction return list.addNote(note, position, type, colors, swimlaneNote); } + @Override public Set getSwimlanes() { return list.getSwimlanes(); } + @Override public Swimlane getSwimlaneIn() { return list.getSwimlaneIn(); } + @Override public Swimlane getSwimlaneOut() { return list.getSwimlaneOut(); } + @Override public Instruction getLast() { return list.getLast(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf.java index 13a756cfb..a8656a443 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf.java @@ -52,6 +52,7 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.WeldingPoint; import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileWithNoteOpale; import net.sourceforge.plantuml.activitydiagram3.gtile.Gtile; import net.sourceforge.plantuml.activitydiagram3.gtile.GtileIfHexagon; +import net.sourceforge.plantuml.activitydiagram3.gtile.GtileIfAlone; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; @@ -123,6 +124,8 @@ public class InstructionIf extends WithNote implements Instruction, InstructionC branches.add(elseBranch); } + if (branches.size() == 1) + return new GtileIfAlone(swimlane, gtiles.get(0), branches.get(0)); return new GtileIfHexagon(swimlane, gtiles, branches); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java index ca0df0aba..420fe5092 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java @@ -40,14 +40,19 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.activitydiagram3.ftile.BoxStyle; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileKilled; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlanes; +import net.sourceforge.plantuml.activitydiagram3.gtile.Gtile; +import net.sourceforge.plantuml.activitydiagram3.gtile.GtileIfAlone; +import net.sourceforge.plantuml.activitydiagram3.gtile.GtileRepeat; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.color.Colors; import net.sourceforge.plantuml.sequencediagram.NotePosition; import net.sourceforge.plantuml.sequencediagram.NoteType; @@ -115,9 +120,17 @@ public class InstructionRepeat extends AbstractInstruction implements Instructio return this.backward != Display.NULL; } + @Override public CommandExecutionResult add(Instruction ins) { return repeatList.add(ins); } + + @Override + public Gtile createGtile(ISkinParam skinParam, StringBounder stringBounder) { + + final Gtile tile = repeatList.createGtile(skinParam, stringBounder); + return new GtileRepeat(swimlane, tile, null, test); + } public Ftile createFtile(FtileFactory factory) { final Ftile back = getBackward(factory); @@ -167,10 +180,12 @@ public class InstructionRepeat extends AbstractInstruction implements Instructio return repeatList.kill(); } + @Override public LinkRendering getInLinkRendering() { return nextLinkRenderer; } + @Override public boolean addNote(Display note, NotePosition position, NoteType type, Colors colors, Swimlane swimlaneNote) { if (Display.isNull(backward)) { return repeatList.addNote(note, position, type, colors, swimlaneNote); @@ -180,14 +195,17 @@ public class InstructionRepeat extends AbstractInstruction implements Instructio } + @Override public Set getSwimlanes() { return repeatList.getSwimlanes(); } + @Override public Swimlane getSwimlaneIn() { return parent.getSwimlaneOut(); } + @Override public Swimlane getSwimlaneOut() { return parent.getSwimlaneOut(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionSplit.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionSplit.java index c1ff730f1..ccd48090d 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/InstructionSplit.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionSplit.java @@ -40,14 +40,22 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.gtile.Gtile; +import net.sourceforge.plantuml.activitydiagram3.gtile.GtileColumns; +import net.sourceforge.plantuml.activitydiagram3.gtile.GtileSplit; +import net.sourceforge.plantuml.activitydiagram3.gtile.Gtiles; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.Rainbow; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.color.Colors; import net.sourceforge.plantuml.sequencediagram.NotePosition; import net.sourceforge.plantuml.sequencediagram.NoteType; +import net.sourceforge.plantuml.ugraphic.color.HColorUtils; public class InstructionSplit extends AbstractInstruction implements Instruction { @@ -65,6 +73,7 @@ public class InstructionSplit extends AbstractInstruction implements Instruction this.inlinkRendering = Objects.requireNonNull(inlinkRendering); } + @Override public boolean containsBreak() { for (InstructionList split : splits) { if (split.containsBreak()) { @@ -78,10 +87,33 @@ public class InstructionSplit extends AbstractInstruction implements Instruction return splits.get(splits.size() - 1); } + @Override public CommandExecutionResult add(Instruction ins) { return getLast().add(ins); } + @Override + public Gtile createGtile(ISkinParam skinParam, StringBounder stringBounder) { + final List all = new ArrayList<>(); + for (InstructionList list : splits) { + Gtile tmp = list.createGtile(skinParam, stringBounder); + tmp = Gtiles.withIncomingArrow(tmp, 20); + tmp = Gtiles.withOutgoingArrow(tmp, 20); + all.add(tmp); + } + +// final GtileColumns tmp = new GtileColumns(all, swimlaneIn); +// return new GtileSplit(tmp, getInLinkRenderingColor(skinParam).getColor()); + return new GtileSplit(all, swimlaneIn, getInLinkRenderingColor(skinParam).getColor()); + } + + private Rainbow getInLinkRenderingColor(ISkinParam skinParam) { + Rainbow color; + color = Rainbow.build(skinParam); + return color; + } + + @Override public Ftile createFtile(FtileFactory factory) { final List all = new ArrayList<>(); for (InstructionList list : splits) { @@ -110,26 +142,32 @@ public class InstructionSplit extends AbstractInstruction implements Instruction } + @Override final public boolean kill() { return getLast().kill(); } + @Override public LinkRendering getInLinkRendering() { return inlinkRendering; } + @Override public boolean addNote(Display note, NotePosition position, NoteType type, Colors colors, Swimlane swimlaneNote) { return getLast().addNote(note, position, type, colors, swimlaneNote); } + @Override public Set getSwimlanes() { return InstructionList.getSwimlanes2(splits); } + @Override public Swimlane getSwimlaneIn() { return parent.getSwimlaneOut(); } + @Override public Swimlane getSwimlaneOut() { return swimlaneOut; // return getLast().getSwimlaneOut(); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlanes.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlanes.java index 8edd4f9aa..5014411fe 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlanes.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlanes.java @@ -61,6 +61,7 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDele import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorWhile; import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.UGraphicInterceptorOneSwimlane; import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.VCompactFactory; +import net.sourceforge.plantuml.activitydiagram3.gtile.GConnection; import net.sourceforge.plantuml.activitydiagram3.gtile.Gtile; import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.AbstractTextBlock; @@ -195,6 +196,15 @@ public class Swimlanes extends AbstractTextBlock implements TextBlock, Styleable final ConnectionCross connectionCross = new ConnectionCross(connection); connectionCross.drawU(getUg()); } + } else if (shape instanceof Gtile) { + final Gtile tile = (Gtile) shape; + tile.drawU(this); + } else if (shape instanceof GConnection) { + final GConnection connection = (GConnection) shape; + System.err.println("CROSS IN SWIMLANES"); + connection.drawTranslatable(getUg()); + // connection.drawU(this); + // throw new UnsupportedOperationException(); } } @@ -236,9 +246,13 @@ public class Swimlanes extends AbstractTextBlock implements TextBlock, Styleable TextBlock full = root.createGtile(skinParam, ug.getStringBounder()); ug = new UGraphicForSnake(ug); - full = new TextBlockInterceptorUDrawable(full); - full.drawU(ug); - ug.flushUg(); + if (swimlanes().size() > 1) { + drawWhenSwimlanes(ug, full); + } else { + full = new TextBlockInterceptorUDrawable(full); + full.drawU(ug); + ug.flushUg(); + } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/UGraphicInterceptorUDrawable2.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/UGraphicInterceptorUDrawable2.java index ad9ee2f6d..42d582bc1 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/UGraphicInterceptorUDrawable2.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/UGraphicInterceptorUDrawable2.java @@ -66,10 +66,6 @@ public class UGraphicInterceptorUDrawable2 extends UGraphicDelegator { final Gtile gtile = (Gtile) shape; // System.err.println("gtile=" + gtile); gtile.drawU(this); - // FtileWithConnection - for (GConnection c : gtile.getInnerConnections()) { - this.draw(c); - } } else if (shape instanceof Ftile) { final Ftile ftile = (Ftile) shape; // System.err.println("ftile=" + ftile); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/UGraphicInterceptorOneSwimlane.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/UGraphicInterceptorOneSwimlane.java index 15d0a35c7..4f053013f 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/UGraphicInterceptorOneSwimlane.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/UGraphicInterceptorOneSwimlane.java @@ -42,6 +42,9 @@ import java.util.Set; import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.gtile.GConnection; +import net.sourceforge.plantuml.activitydiagram3.gtile.GPoint; +import net.sourceforge.plantuml.activitydiagram3.gtile.Gtile; import net.sourceforge.plantuml.graphic.UGraphicDelegator; import net.sourceforge.plantuml.ugraphic.UChange; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -70,6 +73,22 @@ public class UGraphicInterceptorOneSwimlane extends UGraphicDelegator { tile.drawU(this); // drawGoto(); } + } else if (shape instanceof Gtile) { + final Gtile tile = (Gtile) shape; + final Set swinlanes = tile.getSwimlanes(); + final boolean contained = swinlanes.contains(swimlane); + if (contained) + tile.drawU(this); + + } else if (shape instanceof GConnection) { + final GConnection connection = (GConnection) shape; + final List hooks = connection.getHooks(); + final GPoint point0 = hooks.get(0); + final GPoint point1 = hooks.get(1); + + if (point0.match(swimlane) && point1.match(swimlane)) + connection.drawU(this); + } else if (shape instanceof Connection) { final Connection connection = (Connection) shape; final Ftile tile1 = connection.getFtile1(); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/AbstractGtile.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/AbstractGtile.java index 6b87c04b0..c43b8e01d 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/AbstractGtile.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/AbstractGtile.java @@ -43,44 +43,24 @@ import java.util.Set; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.LineParam; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; -import net.sourceforge.plantuml.graphic.AbstractTextBlock; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.rose.Rose; import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; -import net.sourceforge.plantuml.ugraphic.color.HColorSet; -public abstract class AbstractGtile extends AbstractTextBlock implements Gtile { +public abstract class AbstractGtile extends AbstractGtileRoot implements Gtile { - protected final StringBounder stringBounder; - private final ISkinParam skinParam; - private final Swimlane singleSwimlane; + protected final Swimlane singleSwimlane; public AbstractGtile(StringBounder stringBounder, ISkinParam skinParam, Swimlane singleSwimlane) { - this.stringBounder = stringBounder; - this.skinParam = skinParam; + super(stringBounder, skinParam); this.singleSwimlane = singleSwimlane; } - public StringBounder getStringBounder() { - return stringBounder; - } - public AbstractGtile(StringBounder stringBounder, ISkinParam skinParam) { this(stringBounder, skinParam, null); } - final public ISkinParam skinParam() { - if (skinParam == null) { - throw new IllegalStateException(); - } - return skinParam; - } - - final public HColorSet getIHtmlColorSet() { - return skinParam.getIHtmlColorSet(); - } - // @Override // public UTranslate getTranslateFor(Gtile child) { // throw new UnsupportedOperationException(); @@ -92,7 +72,7 @@ public abstract class AbstractGtile extends AbstractTextBlock implements Gtile { // } @Override - public UTranslate getCoord(String name) { + protected UTranslate getCoordImpl(String name) { final Dimension2D dim = calculateDimension(stringBounder); if (name.equals(GPoint.NORTH_HOOK)) return new UTranslate(dim.getWidth() / 2, 0); @@ -105,14 +85,6 @@ public abstract class AbstractGtile extends AbstractTextBlock implements Gtile { throw new UnsupportedOperationException(); } - @Override - public GPoint getGPoint(String name) { - if (name.equals(GPoint.NORTH_HOOK) || name.equals(GPoint.SOUTH_HOOK) || name.equals(GPoint.WEST_HOOK) - || name.equals(GPoint.EAST_HOOK)) - return new GPoint(this, name); - throw new UnsupportedOperationException(); - } - @Override public Set getSwimlanes() { if (singleSwimlane == null) @@ -142,14 +114,14 @@ public abstract class AbstractGtile extends AbstractTextBlock implements Gtile { // } public final UStroke getThickness() { - UStroke thickness = skinParam.getThickness(LineParam.activityBorder, null); + UStroke thickness = skinParam().getThickness(LineParam.activityBorder, null); if (thickness == null) { thickness = new UStroke(1.5); } return thickness; } - private final Rose rose = new Rose(); + private static final Rose rose = new Rose(); protected final Rose getRose() { return rose; diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/AbstractGtileRoot.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/AbstractGtileRoot.java new file mode 100644 index 000000000..fd1fe2087 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/AbstractGtileRoot.java @@ -0,0 +1,114 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.graphic.AbstractTextBlock; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; +import net.sourceforge.plantuml.ugraphic.color.HColorSet; + +public abstract class AbstractGtileRoot extends AbstractTextBlock implements Gtile { + + protected final StringBounder stringBounder; + private final ISkinParam skinParam; + + public AbstractGtileRoot(StringBounder stringBounder, ISkinParam skinParam) { + this.stringBounder = stringBounder; + this.skinParam = skinParam; + } + + @Override + final public StringBounder getStringBounder() { + return stringBounder; + } + + final public ISkinParam skinParam() { + if (skinParam == null) { + throw new IllegalStateException(); + } + return skinParam; + } + + final public HColorSet getIHtmlColorSet() { + return skinParam.getIHtmlColorSet(); + } + + @Override + final public GPoint getGPoint(String name) { + if (name.equals(GPoint.NORTH_HOOK) || name.equals(GPoint.SOUTH_HOOK) || name.equals(GPoint.WEST_HOOK) + || name.equals(GPoint.EAST_HOOK) || name.equals(GPoint.NORTH_BORDER) || name.equals(GPoint.SOUTH_BORDER) + || name.equals(GPoint.WEST_BORDER) || name.equals(GPoint.EAST_BORDER)) + return new GPoint(this, name); + throw new UnsupportedOperationException(); + } + + @Override + public final UTranslate getCoord(String name) { + if (name.equals(GPoint.NORTH_BORDER)) { + final UTranslate tmp = getCoordImpl(GPoint.NORTH_HOOK); + return new UTranslate(tmp.getDx(), 0); + } + if (name.equals(GPoint.SOUTH_BORDER)) { + final UTranslate tmp = getCoordImpl(GPoint.SOUTH_HOOK); + return new UTranslate(tmp.getDx(), calculateDimension(stringBounder).getHeight()); + } + if (name.equals(GPoint.WEST_BORDER)) { + final UTranslate tmp = getCoordImpl(GPoint.WEST_HOOK); + return new UTranslate(0, tmp.getDy()); + } + if (name.equals(GPoint.EAST_BORDER)) { + final UTranslate tmp = getCoordImpl(GPoint.EAST_HOOK); + return new UTranslate(calculateDimension(stringBounder).getWidth(), tmp.getDy()); + } + return getCoordImpl(name); + } + + abstract protected UTranslate getCoordImpl(String name); + + @Override + final public void drawU(UGraphic ug) { + drawUInternal(ug); + for (GConnection connection : getInnerConnections()) { + ug.draw(connection); + } + + } + + abstract protected void drawUInternal(UGraphic ug); + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GAbstractConnection.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GAbstractConnection.java index 0edd17fe9..c2fbbbe9e 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GAbstractConnection.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GAbstractConnection.java @@ -38,6 +38,10 @@ package net.sourceforge.plantuml.activitydiagram3.gtile; import java.util.Arrays; import java.util.List; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + public abstract class GAbstractConnection implements GConnection { protected final GPoint gpoint1; @@ -58,4 +62,23 @@ public abstract class GAbstractConnection implements GConnection { return Arrays.asList(gpoint1, gpoint2); } + @Override + final public void drawTranslatable(UGraphic ug) { + final Swimlane swimlane1 = gpoint1.getSwimlane(); + final Swimlane swimlane2 = gpoint2.getSwimlane(); + + if (swimlane1 == swimlane2) + return; + + final UTranslate translate1 = swimlane1.getTranslate(); + final UTranslate translate2 = swimlane2.getTranslate(); + + drawTranslate(ug, translate1, translate2); + + } + + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { + throw new UnsupportedOperationException(); + } + } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnection.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnection.java index 34a5a92e4..5001f0a12 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnection.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnection.java @@ -38,10 +38,13 @@ package net.sourceforge.plantuml.activitydiagram3.gtile; import java.util.List; import net.sourceforge.plantuml.graphic.UDrawable; +import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UShape; public interface GConnection extends UDrawable, UShape { public List getHooks(); + public void drawTranslatable(UGraphic ug); + } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionHorizontalThenVerticalDown.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionHorizontalThenVerticalDown.java index b26f410ca..a1dc1fa93 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionHorizontalThenVerticalDown.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionHorizontalThenVerticalDown.java @@ -35,17 +35,23 @@ */ package net.sourceforge.plantuml.activitydiagram3.gtile; +import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Hexagon; +import net.sourceforge.plantuml.activitydiagram3.ftile.MergeStrategy; import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.Rainbow; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPolygon; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class GConnectionHorizontalThenVerticalDown extends GAbstractConnection implements GConnectionTranslatable { +public class GConnectionHorizontalThenVerticalDown extends GAbstractConnection { private final TextBlock textBlock; private final UTranslate pos1; @@ -62,13 +68,48 @@ public class GConnectionHorizontalThenVerticalDown extends GAbstractConnection i @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { - throw new UnsupportedOperationException(); +// final Snake snake = Snake.create(getInLinkRenderingColor(), Arrows.asToDown()).withLabel(textBlock, +// HorizontalAlignment.LEFT); + Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); + Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); + + final Direction originalDirection = Direction.leftOrRight(p1, p2); + p1 = translate1.getTranslated(p1); + p2 = translate2.getTranslated(p2); + final Direction newDirection = Direction.leftOrRight(p1, p2); + if (originalDirection != newDirection) { + final double delta = (originalDirection == Direction.RIGHT ? -1 : 1) * Hexagon.hexagonHalfSize; + // final Dimension2D dimDiamond1 = + // diamond1.calculateDimension(ug.getStringBounder()); + final Dimension2D dimDiamond1 = new Dimension2DDouble(0, 0); + final Snake small = Snake.create(getInLinkRenderingColor()).withLabel(textBlock, HorizontalAlignment.LEFT); + small.addPoint(p1); + small.addPoint(p1.getX() + delta, p1.getY()); + small.addPoint(p1.getX() + delta, p1.getY() + dimDiamond1.getHeight() * .75); + ug.draw(small); + p1 = small.getLast(); + } + UPolygon usingArrow = /* branch.isEmpty() ? null : */ Arrows.asToDown(); + + final Snake snake = Snake.create(getInLinkRenderingColor(), usingArrow) + .withLabel(textBlock, HorizontalAlignment.LEFT).withMerge(MergeStrategy.LIMITED); + snake.addPoint(p1); + snake.addPoint(p2.getX(), p1.getY()); + snake.addPoint(p2); + ug.draw(snake); } @Override public void drawU(UGraphic ug) { - ug.draw(getSimpleSnake()); + final Snake snake = Snake.create(getInLinkRenderingColor(), Arrows.asToDown()).withLabel(textBlock, + HorizontalAlignment.LEFT); + final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); + final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); + snake.addPoint(p1); + snake.addPoint(new Point2D.Double(p2.getX(), p1.getY())); + snake.addPoint(p2); + ug.draw(snake); } // public double getMaxX(StringBounder stringBounder) { @@ -102,17 +143,6 @@ public class GConnectionHorizontalThenVerticalDown extends GAbstractConnection i return color; } - private Snake getSimpleSnake() { - final Snake snake = Snake.create(getInLinkRenderingColor(), Arrows.asToDown()).withLabel(textBlock, - HorizontalAlignment.LEFT); - final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); - final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); - snake.addPoint(p1); - snake.addPoint(new Point2D.Double(p2.getX(), p1.getY())); - snake.addPoint(p2); - return snake; - } - // @Override // public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { // final Snake snake = Snake.create(color, Arrows.asToDown()).withLabel(textBlock, HorizontalAlignment.LEFT); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionLeftThenDownThenRight.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionLeftThenVerticalThenRight.java similarity index 91% rename from src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionLeftThenDownThenRight.java rename to src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionLeftThenVerticalThenRight.java index 3d957a829..43fc8430a 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionLeftThenDownThenRight.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionLeftThenVerticalThenRight.java @@ -46,7 +46,7 @@ import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class GConnectionLeftThenDownThenRight extends GAbstractConnection implements GConnectionTranslatable { +public class GConnectionLeftThenVerticalThenRight extends GAbstractConnection { private final TextBlock textBlock; private final UTranslate pos1; @@ -54,7 +54,7 @@ public class GConnectionLeftThenDownThenRight extends GAbstractConnection implem private final double xright; - public GConnectionLeftThenDownThenRight(UTranslate pos1, GPoint gpoint1, UTranslate pos2, GPoint gpoint2, + public GConnectionLeftThenVerticalThenRight(UTranslate pos1, GPoint gpoint1, UTranslate pos2, GPoint gpoint2, double xright, TextBlock textBlock) { super(gpoint1, gpoint2); this.textBlock = textBlock; @@ -72,7 +72,18 @@ public class GConnectionLeftThenDownThenRight extends GAbstractConnection implem @Override public void drawU(UGraphic ug) { - ug.draw(getSimpleSnake()); + final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); + final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); + final Direction direction = p1.getY() < p2.getY() ? Direction.DOWN : Direction.UP; + final Snake snake = Snake.create(getInLinkRenderingColor(), Arrows.asToLeft()).emphasizeDirection(direction) + .withLabel(textBlock, HorizontalAlignment.LEFT); + // final double maxX = Math.max(p1.getX(), p2.getX()); + final double maxX = xright; + snake.addPoint(p1); + snake.addPoint(new Point2D.Double(maxX, p1.getY())); + snake.addPoint(new Point2D.Double(maxX, p2.getY())); + snake.addPoint(p2); + ug.draw(snake); } // public double getMaxX(StringBounder stringBounder) { @@ -106,20 +117,6 @@ public class GConnectionLeftThenDownThenRight extends GAbstractConnection implem return color; } - private Snake getSimpleSnake() { - final Snake snake = Snake.create(getInLinkRenderingColor(), Arrows.asToLeft()) - .emphasizeDirection(Direction.DOWN).withLabel(textBlock, HorizontalAlignment.LEFT); - final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); - final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); - // final double maxX = Math.max(p1.getX(), p2.getX()); - final double maxX = xright; - snake.addPoint(p1); - snake.addPoint(new Point2D.Double(maxX, p1.getY())); - snake.addPoint(new Point2D.Double(maxX, p2.getY())); - snake.addPoint(p2); - return snake; - } - // @Override // public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { // final Snake snake = Snake.create(color, Arrows.asToDown()).withLabel(textBlock, HorizontalAlignment.LEFT); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionVerticalDown.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionVerticalDown.java index 8ee4d2996..ccb0b4fae 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionVerticalDown.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionVerticalDown.java @@ -45,7 +45,7 @@ import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class GConnectionVerticalDown extends GAbstractConnection implements GConnectionTranslatable { +public class GConnectionVerticalDown extends GAbstractConnection { private final TextBlock textBlock; private final UTranslate pos1; @@ -62,19 +62,32 @@ public class GConnectionVerticalDown extends GAbstractConnection implements GCon @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { - throw new UnsupportedOperationException(); + final Snake snake = Snake.create(getInLinkRenderingColor(), Arrows.asToDown()).withLabel(textBlock, + HorizontalAlignment.LEFT); + final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); + final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); + final Point2D mp1a = translate1.getTranslated(p1); + final Point2D mp2b = translate2.getTranslated(p2); + final double middle = (mp1a.getY() + mp2b.getY()) / 2.0; + snake.addPoint(mp1a); + snake.addPoint(mp1a.getX(), middle); + snake.addPoint(mp2b.getX(), middle); + snake.addPoint(mp2b); + ug.draw(snake); } @Override public void drawU(UGraphic ug) { - ug.draw(getSimpleSnake()); + final Snake snake = Snake.create(getInLinkRenderingColor(), Arrows.asToDown()).withLabel(textBlock, + HorizontalAlignment.LEFT); + final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); + final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); + snake.addPoint(p1); + snake.addPoint(p2); + ug.draw(snake); } -// public double getMaxX(StringBounder stringBounder) { -// return getSimpleSnake().getMaxX(stringBounder); -// } - private Rainbow getInLinkRenderingColor() { Rainbow color; color = Rainbow.build(gpoint1.getGtile().skinParam()); @@ -102,16 +115,6 @@ public class GConnectionVerticalDown extends GAbstractConnection implements GCon return color; } - private Snake getSimpleSnake() { - final Snake snake = Snake.create(getInLinkRenderingColor(), Arrows.asToDown()).withLabel(textBlock, - HorizontalAlignment.LEFT); - final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); - final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); - snake.addPoint(p1); - snake.addPoint(p2); - return snake; - } - // @Override // public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { // final Snake snake = Snake.create(color, Arrows.asToDown()).withLabel(textBlock, HorizontalAlignment.LEFT); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionVerticalDownThenHorizontal.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionVerticalDownThenHorizontal.java index 42ae4c1a7..633a381d1 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionVerticalDownThenHorizontal.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionVerticalDownThenHorizontal.java @@ -37,7 +37,10 @@ package net.sourceforge.plantuml.activitydiagram3.gtile; import java.awt.geom.Point2D; +import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Hexagon; +import net.sourceforge.plantuml.activitydiagram3.ftile.MergeStrategy; import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.Rainbow; @@ -46,7 +49,7 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UPolygon; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class GConnectionVerticalDownThenHorizontal extends GAbstractConnection implements GConnectionTranslatable { +public class GConnectionVerticalDownThenHorizontal extends GAbstractConnection { private final TextBlock textBlock; private final UTranslate pos1; @@ -63,13 +66,64 @@ public class GConnectionVerticalDownThenHorizontal extends GAbstractConnection i @Override public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { - throw new UnsupportedOperationException(); + Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); + Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); + + final Direction originalDirection = Direction.leftOrRight(p1, p2); + +// p1 = translate1.getTranslated(p1); +// p2 = translate2.getTranslated(p2); + + final double x1 = p1.getX(); + final double x2 = p2.getX(); + final Point2D mp1a = translate1.getTranslated(p1); + final Point2D mp2b = translate2.getTranslated(p2); + final Direction newDirection = Direction.leftOrRight(mp1a, mp2b); + final UPolygon arrow = x2 > x1 ? Arrows.asToRight() : Arrows.asToLeft(); + if (originalDirection == newDirection) { + final double delta = (x2 > x1 ? -1 : 1) * 1.5 * Hexagon.hexagonHalfSize; + final Point2D mp2bc = new Point2D.Double(mp2b.getX() + delta, mp2b.getY()); + final Snake snake = Snake.create(getInLinkRenderingColor()).withMerge(MergeStrategy.LIMITED); + final double middle = (mp1a.getY() + mp2b.getY()) / 2.0; + snake.addPoint(mp1a); + snake.addPoint(mp1a.getX(), middle); + snake.addPoint(mp2bc.getX(), middle); + snake.addPoint(mp2bc); + ug.draw(snake); + final Snake small = Snake.create(getInLinkRenderingColor(), arrow).withMerge(MergeStrategy.LIMITED); + small.addPoint(mp2bc); + small.addPoint(mp2bc.getX(), mp2b.getY()); + small.addPoint(mp2b); + ug.draw(small); + } else { + final double delta = (x2 > x1 ? -1 : 1) * 1.5 * Hexagon.hexagonHalfSize; + final Point2D mp2bb = new Point2D.Double(mp2b.getX() + delta, mp2b.getY() - 1.5 * Hexagon.hexagonHalfSize); + final Snake snake = Snake.create(getInLinkRenderingColor()).withMerge(MergeStrategy.LIMITED); + snake.addPoint(mp1a); + snake.addPoint(mp1a.getX(), mp2bb.getY()); + snake.addPoint(mp2bb); + ug.draw(snake); + final Snake small = Snake.create(getInLinkRenderingColor(), arrow).withMerge(MergeStrategy.LIMITED); + small.addPoint(mp2bb); + small.addPoint(mp2bb.getX(), mp2b.getY()); + small.addPoint(mp2b); + ug.draw(small); + + } } @Override public void drawU(UGraphic ug) { - ug.draw(getSimpleSnake()); + final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); + final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); + final UPolygon arrow = p1.getX() < p2.getX() ? Arrows.asToRight() : Arrows.asToLeft(); + final Snake snake = Snake.create(getInLinkRenderingColor(), arrow).withLabel(textBlock, + HorizontalAlignment.LEFT); + snake.addPoint(p1); + snake.addPoint(new Point2D.Double(p1.getX(), p2.getY())); + snake.addPoint(p2); + ug.draw(snake); } // public double getMaxX(StringBounder stringBounder) { @@ -103,18 +157,6 @@ public class GConnectionVerticalDownThenHorizontal extends GAbstractConnection i return color; } - private Snake getSimpleSnake() { - final Point2D p1 = pos1.getTranslated(gpoint1.getPoint2D()); - final Point2D p2 = pos2.getTranslated(gpoint2.getPoint2D()); - final UPolygon arrow = p1.getX() < p2.getX() ? Arrows.asToRight() : Arrows.asToLeft(); - final Snake snake = Snake.create(getInLinkRenderingColor(), arrow).withLabel(textBlock, - HorizontalAlignment.LEFT); - snake.addPoint(p1); - snake.addPoint(new Point2D.Double(p1.getX(), p2.getY())); - snake.addPoint(p2); - return snake; - } - // @Override // public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { // final Snake snake = Snake.create(color, Arrows.asToDown()).withLabel(textBlock, HorizontalAlignment.LEFT); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GPoint.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GPoint.java index fcb4e17f1..de135e851 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GPoint.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GPoint.java @@ -38,6 +38,7 @@ package net.sourceforge.plantuml.activitydiagram3.gtile; import java.awt.geom.Point2D; import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; import net.sourceforge.plantuml.ugraphic.UTranslate; public class GPoint { @@ -66,6 +67,11 @@ public class GPoint { this(gtile, name, LinkRendering.none()); } + @Override + public String toString() { + return gtile + "@" + name; + } + public Gtile getGtile() { return gtile; } @@ -86,4 +92,17 @@ public class GPoint { return linkRendering; } + public boolean match(Swimlane swimlane) { + final Swimlane tmp = gtile.getSwimlane(name); + return tmp == swimlane; + } + + public Swimlane getSwimlane() { + final Swimlane result = gtile.getSwimlane(name); + if (result == null) { + throw new IllegalStateException(name + " " + gtile.getClass().toString() + " " + gtile); + } + return result; + } + } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/Gtile.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/Gtile.java index 0b74b6d01..eba44eeca 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/Gtile.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/Gtile.java @@ -50,18 +50,15 @@ public interface Gtile extends Swimable2, TextBlock { public StringBounder getStringBounder(); - // public UTranslate getTranslateFor(Gtile child); - - // public Collection getMyChildren(); - public UTranslate getCoord(String name); public GPoint getGPoint(String name); public Collection getInnerConnections(); -// public List getWeldingPoints(); -// -// public HorizontalAlignment arrowHorizontalAlignment(); + // public UTranslate getTranslateFor(Gtile child); + // public Collection getMyChildren(); + // public List getWeldingPoints(); + // public HorizontalAlignment arrowHorizontalAlignment(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileAssembly.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileAssembly.java index c0c18b731..db2a3ff6c 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileAssembly.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileAssembly.java @@ -52,7 +52,7 @@ import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.StyleSignature; import net.sourceforge.plantuml.ugraphic.UTranslate; -public class GtileAssembly extends GtileAssemblySimple { +public class GtileAssembly extends GtileTopDown { private final TextBlock textBlock; diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileBox.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileBox.java index 21ff6d7a3..f30d357b7 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileBox.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileBox.java @@ -87,7 +87,7 @@ public class GtileBox extends AbstractGtile { private double minimumWidth = 0; private final LinkRendering inRendering; - private final Swimlane swimlane; + private final BoxStyle boxStyle; private final HColor borderColor; @@ -133,10 +133,10 @@ public class GtileBox extends AbstractGtile { private GtileBox(StringBounder stringBounder, ISkinParam skinParam, Display label, Swimlane swimlane, BoxStyle boxStyle, Style style, Style styleArrow) { - super(stringBounder, skinParam); + super(stringBounder, skinParam, swimlane); this.style = style; this.boxStyle = boxStyle; - this.swimlane = swimlane; + final FontConfiguration fc; final LineBreakStrategy wrapWidth; if (UseStyle.useBetaStyle()) { @@ -185,7 +185,8 @@ public class GtileBox extends AbstractGtile { return print; } - public void drawU(UGraphic ug) { + @Override + protected void drawUInternal(UGraphic ug) { final Dimension2D dimTotal = calculateDimension(ug.getStringBounder()); final double widthTotal = dimTotal.getWidth(); final double heightTotal = dimTotal.getHeight(); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileCircleStart.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileCircleStart.java index ad6c349ec..b7e1c72d1 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileCircleStart.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileCircleStart.java @@ -70,7 +70,8 @@ public class GtileCircleStart extends AbstractGtile { } - public void drawU(UGraphic ug) { + @Override + protected void drawUInternal(UGraphic ug) { final UEllipse circle = new UEllipse(SIZE, SIZE); circle.setDeltaShadow(shadowing); ug.apply(new HColorNone()).apply(backColor.bg()).draw(circle); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfSimple.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileColumns.java similarity index 86% rename from src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfSimple.java rename to src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileColumns.java index 77187e3af..9ec5a2d17 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfSimple.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileColumns.java @@ -36,9 +36,7 @@ package net.sourceforge.plantuml.activitydiagram3.gtile; import java.awt.geom.Dimension2D; -import java.awt.geom.Point2D; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -51,7 +49,7 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.utils.MathUtils; -public class GtileIfSimple extends AbstractGtile { +public class GtileColumns extends AbstractGtile { protected final List gtiles; private final List dims = new ArrayList<>(); @@ -62,8 +60,12 @@ public class GtileIfSimple extends AbstractGtile { return "GtileIfSimple " + gtiles; } - public GtileIfSimple(List gtiles) { - super(gtiles.get(0).getStringBounder(), gtiles.get(0).skinParam()); + public Gtile first() { + return gtiles.get(0); + } + + public GtileColumns(List gtiles, Swimlane singleSwimlane) { + super(gtiles.get(0).getStringBounder(), gtiles.get(0).skinParam(), singleSwimlane); this.gtiles = gtiles; double dx = 0; @@ -80,7 +82,8 @@ public class GtileIfSimple extends AbstractGtile { return 20; } - public void drawU(UGraphic ug) { + @Override + protected void drawUInternal(UGraphic ug) { for (int i = 0; i < gtiles.size(); i++) { final Gtile tile = gtiles.get(i); final UTranslate pos = positions.get(i); @@ -90,14 +93,14 @@ public class GtileIfSimple extends AbstractGtile { @Override public Dimension2D calculateDimension(StringBounder stringBounder) { - Point2D result = new Point2D.Double(); + Dimension2D result = new Dimension2DDouble(0, 0); for (int i = 0; i < dims.size(); i++) { final Dimension2D dim = dims.get(i); final UTranslate pos = positions.get(i); - final Point2D corner = pos.getTranslated(dim); + final Dimension2D corner = pos.getTranslated(dim); result = MathUtils.max(result, corner); } - return new Dimension2DDouble(result); + return result; } public Set getSwimlanes() { @@ -107,8 +110,8 @@ public class GtileIfSimple extends AbstractGtile { return Collections.unmodifiableSet(result); } - public Collection getMyChildren() { - return Collections.unmodifiableCollection(gtiles); - } +// public Collection getMyChildren() { +// return Collections.unmodifiableCollection(gtiles); +// } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileEmpty.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileEmpty.java index 9d7508ffa..02c46a8f6 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileEmpty.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileEmpty.java @@ -71,7 +71,8 @@ public class GtileEmpty extends AbstractGtile { return "FtileEmpty"; } - public void drawU(UGraphic ug) { + @Override + protected void drawUInternal(UGraphic ug) { } @Override diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileGroup.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileGroup.java new file mode 100644 index 000000000..89842d6b1 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileGroup.java @@ -0,0 +1,268 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.awt.geom.Dimension2D; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.LineParam; +import net.sourceforge.plantuml.UseStyle; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FloatingNote; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.graphic.USymbol; +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.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; +import net.sourceforge.plantuml.ugraphic.color.HColor; +import net.sourceforge.plantuml.ugraphic.color.HColorUtils; + +public class GtileGroup extends AbstractGtileRoot { + + private final double diffYY2 = 20; + private final Gtile inner; + private final TextBlock name; + private final TextBlock headerNote; + private final HColor borderColor; + private final HColor backColor; + private final double shadowing; + private final UStroke stroke; + private final USymbol type; + private final double roundCorner; + + final public StyleSignature getDefaultStyleDefinitionPartition() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.partition); + } + + public GtileGroup(Gtile inner, Display title, Display displayNote, HColor arrowColor, HColor backColor, + HColor titleColor, ISkinParam skinParam, HColor borderColor, USymbol type, double roundCorner) { + super(inner.getStringBounder(), skinParam); + this.roundCorner = roundCorner; + this.type = type; + this.backColor = backColor == null ? HColorUtils.WHITE : backColor; + this.inner = inner; + this.borderColor = borderColor == null ? HColorUtils.BLACK : borderColor; + + final FontConfiguration fc; + final Style style; + if (UseStyle.useBetaStyle()) { + style = getDefaultStyleDefinitionPartition().getMergedStyle(skinParam.getCurrentStyleBuilder()); + fc = style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); + this.shadowing = style.value(PName.Shadowing).asDouble(); + } else { + style = null; + final UFont font = skinParam.getFont(null, false, FontParam.PARTITION); + final HColor fontColor = skinParam.getFontHtmlColor(null, FontParam.PARTITION); + fc = new FontConfiguration(font, fontColor, skinParam.getHyperlinkColor(), + skinParam.useUnderlineForHyperlink(), skinParam.getTabSize()); + this.shadowing = skinParam().shadowing(null) ? 3 : 0; + } + if (title == null) { + this.name = TextBlockUtils.empty(0, 0); + } else { + this.name = title.create(fc, HorizontalAlignment.LEFT, skinParam); + } + if (Display.isNull(displayNote)) { + this.headerNote = TextBlockUtils.empty(0, 0); + } else { + this.headerNote = new FloatingNote(displayNote, skinParam, style); + } + + final UStroke thickness = skinParam.getThickness(LineParam.partitionBorder, null); + this.stroke = thickness == null ? new UStroke(2) : thickness; + } + + @Override + public Collection getInnerConnections() { + return Collections.emptyList(); + } + + @Override + public Set getSwimlanes() { + return inner.getSwimlanes(); + } + + @Override + public Swimlane getSwimlane(String point) { + return inner.getSwimlane(point); + } + + @Override + public Dimension2D calculateDimension(StringBounder stringBounder) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected UTranslate getCoordImpl(String name) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void drawUInternal(UGraphic ug) { + // TODO Auto-generated method stub + + } + +// @Override +// public Collection getMyChildren() { +// return inner.getMyChildren(); +// } +// +// @Override +// public LinkRendering getInLinkRendering() { +// return inner.getInLinkRendering(); +// } +// +// public Set getSwimlanes() { +// return inner.getSwimlanes(); +// } +// +// public Swimlane getSwimlaneIn() { +// return inner.getSwimlaneIn(); +// } +// +// public Swimlane getSwimlaneOut() { +// return inner.getSwimlaneOut(); +// } +// +// private double diffHeightTitle(StringBounder stringBounder) { +// final Dimension2D dimTitle = name.calculateDimension(stringBounder); +// return Math.max(25, dimTitle.getHeight() + 20); +// } +// +// private UTranslate getTranslate(StringBounder stringBounder) { +// final double suppWidth = suppWidth(stringBounder); +// return new UTranslate(suppWidth / 2, diffHeightTitle(stringBounder) + headerNoteHeight(stringBounder)); +// } +// +// private MinMax getInnerMinMax(StringBounder stringBounder) { +// final LimitFinder limitFinder = new LimitFinder(stringBounder, false); +// final UGraphicForSnake interceptor = new UGraphicForSnake(limitFinder); +// final UGraphicInterceptorUDrawable interceptor2 = new UGraphicInterceptorUDrawable(interceptor); +// +// inner.drawU(interceptor2); +// interceptor2.flushUg(); +// return limitFinder.getMinMax(); +// } +// +// public double suppWidth(StringBounder stringBounder) { +// final FtileGeometry orig = getInnerDimension(stringBounder); +// final Dimension2D dimTitle = name.calculateDimension(stringBounder); +// final Dimension2D dimHeaderNote = headerNote.calculateDimension(stringBounder); +// final double suppWidth = MathUtils.max(orig.getWidth(), dimTitle.getWidth() + 20, dimHeaderNote.getWidth() + 20) +// - orig.getWidth(); +// return suppWidth; +// } +// +// private FtileGeometry cachedInnerDimension; +// +// private FtileGeometry getInnerDimension(StringBounder stringBounder) { +// if (cachedInnerDimension == null) { +// cachedInnerDimension = getInnerDimensionSlow(stringBounder); +// } +// return cachedInnerDimension; +// +// } +// +// private FtileGeometry getInnerDimensionSlow(StringBounder stringBounder) { +// final FtileGeometry orig = inner.calculateDimension(stringBounder); +// final MinMax minMax = getInnerMinMax(stringBounder); +// final double missingWidth = minMax.getMaxX() - orig.getWidth(); +// if (missingWidth > 0) { +// return orig.addDim(missingWidth + 5, 0); +// } +// return orig; +// } +// +// @Override +// protected FtileGeometry calculateDimensionFtile(StringBounder stringBounder) { +// final FtileGeometry orig = getInnerDimension(stringBounder); +// final double suppWidth = suppWidth(stringBounder); +// final double width = orig.getWidth() + suppWidth; +// final double height = orig.getHeight() + diffHeightTitle(stringBounder) + diffYY2 +// + headerNoteHeight(stringBounder); +// final double titleAndHeaderNoteHeight = diffHeightTitle(stringBounder) + headerNoteHeight(stringBounder); +// if (orig.hasPointOut()) { +// return new FtileGeometry(width, height, orig.getLeft() + suppWidth / 2, +// orig.getInY() + titleAndHeaderNoteHeight, orig.getOutY() + titleAndHeaderNoteHeight); +// } +// return new FtileGeometry(width, height, orig.getLeft() + suppWidth / 2, +// orig.getInY() + titleAndHeaderNoteHeight); +// } +// +// private double headerNoteHeight(StringBounder stringBounder) { +// return headerNote.calculateDimension(stringBounder).getHeight(); +// } +// +// public void drawU(UGraphic ug) { +// final StringBounder stringBounder = ug.getStringBounder(); +// final Dimension2D dimTotal = calculateDimension(stringBounder); +// +// // final double roundCorner = +// // type.getSkinParameter().getRoundCorner(skinParam(), null); +// final SymbolContext symbolContext = new SymbolContext(backColor, borderColor).withShadow(shadowing) +// .withStroke(stroke).withCorner(roundCorner, 0); +// +// final HorizontalAlignment align = inner.skinParam().getHorizontalAlignment(AlignmentParam.packageTitleAlignment, +// null, false, null); +// type.asBig(name, align, TextBlockUtils.empty(0, 0), dimTotal.getWidth(), dimTotal.getHeight(), symbolContext, +// skinParam().getStereotypeAlignment()).drawU(ug); +// +// final Dimension2D dimHeaderNote = headerNote.calculateDimension(stringBounder); +// headerNote.drawU(ug.apply(new UTranslate(dimTotal.getWidth() - dimHeaderNote.getWidth() - 10, +// diffHeightTitle(ug.getStringBounder()) - 10))); +// +// ug.apply(getTranslate(stringBounder)).draw(inner); +// +// } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHLine.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHLine.java new file mode 100644 index 000000000..4dfa5b156 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHLine.java @@ -0,0 +1,73 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.StringBounder; +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; + +public class GtileHLine extends AbstractGtile { + + private final double start; + private final double width; + private final HColor lineColor; + + public GtileHLine(StringBounder stringBounder, ISkinParam skinParam, Swimlane swimlane, HColor lineColor) { + super(stringBounder, skinParam, swimlane); + this.start = 0; + this.width = 10; + this.lineColor = lineColor; + } + + @Override + protected void drawUInternal(UGraphic ug) { + ug.apply(lineColor).apply(new UStroke(1.5)).apply(UTranslate.dx(start)).draw(ULine.hline(width)); + } + + @Override + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, 1.5); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileDiamondInside.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHexagonInside.java similarity index 83% rename from src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileDiamondInside.java rename to src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHexagonInside.java index 31c5b88e8..8868db03d 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileDiamondInside.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHexagonInside.java @@ -44,6 +44,7 @@ import net.sourceforge.plantuml.activitydiagram3.ftile.Hexagon; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.SName; import net.sourceforge.plantuml.style.Style; @@ -52,7 +53,7 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.color.HColor; -public class GtileDiamondInside extends AbstractGtile { +public class GtileHexagonInside extends AbstractGtile { protected final HColor backColor; protected final HColor borderColor; @@ -67,7 +68,23 @@ public class GtileDiamondInside extends AbstractGtile { } // FtileDiamondInside - public GtileDiamondInside(StringBounder stringBounder, TextBlock label, ISkinParam skinParam, HColor backColor, + + public GtileHexagonInsideLabelled withEastLabel(TextBlock eastLabel) { + return new GtileHexagonInsideLabelled(this, TextBlockUtils.EMPTY_TEXT_BLOCK, eastLabel, + TextBlockUtils.EMPTY_TEXT_BLOCK); + } + + public GtileHexagonInsideLabelled withWestLabel(TextBlock westLabel) { + return new GtileHexagonInsideLabelled(this, TextBlockUtils.EMPTY_TEXT_BLOCK, TextBlockUtils.EMPTY_TEXT_BLOCK, + westLabel); + } + + public AbstractGtileRoot withSouthLabel(TextBlock southLabel) { + return new GtileHexagonInsideLabelled(this, southLabel, TextBlockUtils.EMPTY_TEXT_BLOCK, + TextBlockUtils.EMPTY_TEXT_BLOCK); + } + + public GtileHexagonInside(StringBounder stringBounder, TextBlock label, ISkinParam skinParam, HColor backColor, HColor borderColor, Swimlane swimlane) { super(stringBounder, skinParam, swimlane); if (UseStyle.useBetaStyle()) { @@ -100,16 +117,15 @@ public class GtileDiamondInside extends AbstractGtile { } @Override - public void drawU(UGraphic ug) { + protected void drawUInternal(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); final Dimension2D dimTotal = calculateDimension(stringBounder); ug = ug.apply(borderColor).apply(getThickness()).apply(backColor.bg()); ug.draw(Hexagon.asPolygon(shadowing, dimTotal.getWidth(), dimTotal.getHeight())); - + final double lx = (dimTotal.getWidth() - dimLabel.getWidth()) / 2; final double ly = (dimTotal.getHeight() - dimLabel.getHeight()) / 2; label.drawU(ug.apply(new UTranslate(lx, ly))); - } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHexagonInsideLabelled.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHexagonInsideLabelled.java new file mode 100644 index 000000000..5263e7c58 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileHexagonInsideLabelled.java @@ -0,0 +1,114 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; +import net.sourceforge.plantuml.utils.MathUtils; + +public class GtileHexagonInsideLabelled extends GtileWithMargin { + + private final TextBlock southLabel; + private final TextBlock eastLabel; + private final TextBlock westLabel; + + public GtileHexagonInsideLabelled(GtileHexagonInside diamond, TextBlock southLabel, TextBlock eastLabel, + TextBlock westLabel) { + super(diamond, getNorthMargin(diamond, eastLabel, westLabel), getSouthMargin(diamond, southLabel), 0); + this.eastLabel = eastLabel; + this.westLabel = westLabel; + this.southLabel = southLabel; + } + + public GtileHexagonInsideLabelled withSouthLabel(TextBlock eastLabel) { + return new GtileHexagonInsideLabelled((GtileHexagonInside) orig, southLabel, eastLabel, westLabel); + } + + public GtileHexagonInsideLabelled withEastLabel(TextBlock eastLabel) { + return new GtileHexagonInsideLabelled((GtileHexagonInside) orig, southLabel, eastLabel, westLabel); + } + + public GtileHexagonInsideLabelled withWestLabel(TextBlock westLabel) { + return new GtileHexagonInsideLabelled((GtileHexagonInside) orig, southLabel, eastLabel, westLabel); + } + + private static double getNorthMargin(GtileHexagonInside diamond, TextBlock eastLabel, TextBlock westLabel) { + final Dimension2D dimWest = westLabel.calculateDimension(diamond.getStringBounder()); + final Dimension2D dimEast = eastLabel.calculateDimension(diamond.getStringBounder()); + final UTranslate east = diamond.getCoord(GPoint.EAST_HOOK); + final UTranslate west = diamond.getCoord(GPoint.WEST_HOOK); + return MathUtils.max(0, dimWest.getHeight() - west.getDy(), dimEast.getHeight() - east.getDy()); + } + + private static double getSouthMargin(GtileHexagonInside diamond, TextBlock southLabel) { + final Dimension2D dimSouth = southLabel.calculateDimension(diamond.getStringBounder()); + return dimSouth.getHeight(); + } + + @Override + protected void drawUInternal(UGraphic ug) { + super.drawUInternal(ug); + + final UTranslate south = getCoord(GPoint.SOUTH_HOOK); + southLabel.drawU(ug.apply(south)); + + final UTranslate east = getCoord(GPoint.EAST_HOOK); + eastLabel.drawU( + ug.apply(east.compose(UTranslate.dy(-eastLabel.calculateDimension(getStringBounder()).getHeight())))); + + final Dimension2D tmp = westLabel.calculateDimension(getStringBounder()); + final UTranslate west = getCoord(GPoint.WEST_HOOK); + westLabel.drawU(ug.apply(west.compose(new UTranslate(-tmp.getWidth(), -tmp.getHeight())))); + + } + + @Override + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D tmp = super.calculateDimension(stringBounder); + final UTranslate south = getCoord(GPoint.SOUTH_HOOK); + final Dimension2D southCorner = south.getTranslated(southLabel.calculateDimension(stringBounder)); + + final UTranslate east = getCoord(GPoint.EAST_HOOK); + final Dimension2D eastCorner = east.getTranslated(eastLabel.calculateDimension(stringBounder)); + + return MathUtils.max(tmp, southCorner, eastCorner); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfAlone.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfAlone.java new file mode 100644 index 000000000..df79023a0 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfAlone.java @@ -0,0 +1,110 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.awt.geom.Dimension2D; +import java.util.Arrays; +import java.util.Collection; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.StyleSignature; +import net.sourceforge.plantuml.ugraphic.color.HColor; + +public class GtileIfAlone extends GtileTopDown3 { + + private static final double SUPP_WIDTH = 15; + + public GtileIfAlone(Swimlane swimlane, Gtile gtile, Branch branch0) { + super(getShape1(swimlane, branch0, gtile.getStringBounder(), gtile.skinParam()), gtile, + getShape2(swimlane, branch0.getColor(), gtile.getStringBounder(), gtile.skinParam())); + + } + + private static Gtile getShape1(Swimlane swimlane, Branch branch0, StringBounder stringBounder, + ISkinParam skinParam) { + GtileHexagonInside tmp = Gtiles.hexagonInside(swimlane, stringBounder, skinParam, + getDefaultStyleDefinitionDiamond(), branch0.getColor(), branch0.getLabelTest()); + final TextBlock tmp0 = branch0.getTextBlockPositive(); + return Gtiles.withSouthMargin(tmp.withSouthLabel(tmp0), 20); + } + + private static Gtile getShape2(Swimlane swimlane, HColor color, StringBounder stringBounder, ISkinParam skinParam) { + final AbstractGtileRoot tmp = Gtiles.diamondEmpty(swimlane, stringBounder, skinParam, + getDefaultStyleDefinitionDiamond(), color); + return Gtiles.withNorthMargin(tmp, 20); + } + + final public StyleSignature getDefaultStyleDefinitionActivity() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.activity); + } + + final static public StyleSignature getDefaultStyleDefinitionDiamond() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.activity, SName.diamond); + } + + final public StyleSignature getDefaultStyleDefinitionArrow() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.arrow); + } + + @Override + public Dimension2D calculateDimension(StringBounder stringBounder) { + return Dimension2DDouble.delta(super.calculateDimension(stringBounder), SUPP_WIDTH, 0); + } + + @Override + public Collection getInnerConnections() { + + final GConnection arrow1 = new GConnectionVerticalDown(getPos1(), tile1.getGPoint(GPoint.SOUTH_HOOK), getPos2(), + tile2.getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); + final GConnection arrow2 = new GConnectionVerticalDown(getPos2(), tile2.getGPoint(GPoint.SOUTH_HOOK), getPos3(), + tile3.getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); + + final double xright = calculateDimension(stringBounder).getWidth(); + + final GConnection arrow3 = new GConnectionLeftThenVerticalThenRight(getPos1(), tile1.getGPoint(GPoint.EAST_HOOK), + getPos3(), tile3.getGPoint(GPoint.EAST_HOOK), xright, TextBlockUtils.EMPTY_TEXT_BLOCK); + + return Arrays.asList(arrow1, arrow2, arrow3); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfHexagon.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfHexagon.java index 13c6491d9..17a3dc198 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfHexagon.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileIfHexagon.java @@ -38,43 +38,25 @@ package net.sourceforge.plantuml.activitydiagram3.gtile; import java.awt.geom.Dimension2D; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.ListIterator; -import net.sourceforge.plantuml.ColorParam; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.LineBreakStrategy; -import net.sourceforge.plantuml.UseStyle; import net.sourceforge.plantuml.activitydiagram3.Branch; -import net.sourceforge.plantuml.activitydiagram3.ftile.Hexagon; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; -import net.sourceforge.plantuml.creole.CreoleMode; -import net.sourceforge.plantuml.creole.Parser; -import net.sourceforge.plantuml.creole.Sheet; -import net.sourceforge.plantuml.creole.SheetBlock1; -import net.sourceforge.plantuml.creole.SheetBlock2; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; -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.ConditionEndStyle; -import net.sourceforge.plantuml.svek.ConditionStyle; import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; -import net.sourceforge.plantuml.ugraphic.color.HColor; +import net.sourceforge.plantuml.utils.MathUtils; -public class GtileIfHexagon extends GtileIfSimple { +public class GtileIfHexagon extends GtileColumns { - private final List branches; private final Gtile shape1; + private final List branches; private final Gtile shape2; private final UTranslate positionShape1; @@ -89,103 +71,59 @@ public class GtileIfHexagon extends GtileIfSimple { // FtileFactoryDelegatorIf public GtileIfHexagon(Swimlane swimlane, List gtiles, List branches) { - super(gtiles); - - final ConditionStyle conditionStyle = skinParam().getConditionStyle(); - final ConditionEndStyle conditionEndStyle = skinParam().getConditionEndStyle(); + super(gtiles, swimlane); + if (branches.size() <= 1) + throw new IllegalArgumentException(); this.branches = branches; - final Branch branch0 = branches.get(0); + this.shape1 = getShape1(swimlane); + this.shape2 = Gtiles.diamondEmpty(swimlane, getStringBounder(), skinParam(), getDefaultStyleDefinitionDiamond(), + branches.get(0).getColor()); - final HColor borderColor; - final HColor backColor; - final FontConfiguration fcTest; - - if (UseStyle.useBetaStyle()) { - final Style styleArrow = getDefaultStyleDefinitionArrow() - .getMergedStyle(skinParam().getCurrentStyleBuilder()); - final Style styleDiamond = getDefaultStyleDefinitionDiamond() - .getMergedStyle(skinParam().getCurrentStyleBuilder()); - borderColor = styleDiamond.value(PName.LineColor).asColor(skinParam().getThemeStyle(), - skinParam().getIHtmlColorSet()); - backColor = branch0.getColor() == null ? styleDiamond.value(PName.BackGroundColor) - .asColor(skinParam().getThemeStyle(), skinParam().getIHtmlColorSet()) : branch0.getColor(); -// arrowColor = Rainbow.build(styleArrow, skinParam().getIHtmlColorSet(), skinParam().getThemeStyle()); - fcTest = styleDiamond.getFontConfiguration(skinParam().getThemeStyle(), skinParam().getIHtmlColorSet()); -// fcArrow = styleArrow.getFontConfiguration(skinParam().getThemeStyle(), skinParam().getIHtmlColorSet()); - } else { - final FontParam testParam = conditionStyle == ConditionStyle.INSIDE_HEXAGON ? FontParam.ACTIVITY_DIAMOND - : FontParam.ARROW; - - borderColor = getRose().getHtmlColor(skinParam(), ColorParam.activityDiamondBorder); - backColor = branch0.getColor() == null - ? getRose().getHtmlColor(skinParam(), ColorParam.activityDiamondBackground) - : branch0.getColor(); -// arrowColor = Rainbow.build(skinParam()); - fcTest = new FontConfiguration(skinParam(), testParam, null) - .changeColor(fontColor(FontParam.ACTIVITY_DIAMOND)); -// fcArrow = new FontConfiguration(skinParam(), FontParam.ARROW, null); - } - - final Sheet sheet = Parser.build(fcTest, skinParam().getDefaultTextAlignment(HorizontalAlignment.LEFT), - skinParam(), CreoleMode.FULL).createSheet(branch0.getLabelTest()); - final SheetBlock1 sheetBlock1 = new SheetBlock1(sheet, LineBreakStrategy.NONE, skinParam().getPadding()); - final TextBlock tbTest = new SheetBlock2(sheetBlock1, Hexagon.asStencil(sheetBlock1), new UStroke()); - - this.shape1 = new GtileDiamondInside(getStringBounder(), tbTest, skinParam(), backColor, borderColor, swimlane); - this.shape2 = new GtileDiamondInside(getStringBounder(), TextBlockUtils.EMPTY_TEXT_BLOCK, skinParam(), - backColor, borderColor, swimlane); - - final double height1 = shape1.calculateDimension(stringBounder).getHeight() + getSuppHeightMargin(); - -// public GtileDiamondInside(StringBounder stringBounder, TextBlock label, ISkinParam skinParam, HColor backColor, -// HColor borderColor, Swimlane swimlane) { + final double height1 = shape1.calculateDimension(stringBounder).getHeight(); for (ListIterator it = positions.listIterator(); it.hasNext();) { final UTranslate tmp = it.next(); it.set(tmp.compose(UTranslate.dy(height1))); } - if (branches.size() == 1) { - final UTranslate tmp = positions.get(0); - positions.set(0, tmp.compose(UTranslate.dx(missingSpace()))); - } - - this.positionShape1 = this.getCoord(GPoint.NORTH_HOOK).compose(shape1.getCoord(GPoint.NORTH_HOOK).reverse()); - this.positionShape2 = this.getCoord(GPoint.SOUTH_HOOK).compose(shape2.getCoord(GPoint.SOUTH_HOOK).reverse()); + final Dimension2D totalDim = calculateDimensionRaw(stringBounder); + this.positionShape1 = UTranslate.dx(totalDim.getWidth() / 2) + .compose(shape1.getCoord(GPoint.NORTH_BORDER).reverse()); + this.positionShape2 = new UTranslate(totalDim.getWidth() / 2, totalDim.getHeight()) + .compose(shape2.getCoord(GPoint.SOUTH_BORDER).reverse()); } - private double missingSpace() { - if (branches.size() != 1) - throw new IllegalStateException(); - return 25; + @Override + protected UTranslate getCoordImpl(String name) { + if (name.equals(GPoint.NORTH_HOOK)) + return shape1.getCoord(name).compose(positionShape1); + if (name.equals(GPoint.SOUTH_HOOK)) + return shape2.getCoord(name).compose(positionShape2); + return super.getCoordImpl(name); } - private double getSuppHeightMargin() { - if (branches.size() == 1) - return 30; - return 10; + private Gtile getShape1(Swimlane swimlane) { + GtileHexagonInside tmp = Gtiles.hexagonInside(swimlane, getStringBounder(), skinParam(), + getDefaultStyleDefinitionDiamond(), branches.get(0).getColor(), branches.get(0).getLabelTest()); + final TextBlock tmp0 = branches.get(0).getTextBlockPositive(); + final TextBlock tmp1 = branches.get(1).getTextBlockPositive(); + return Gtiles.withSouthMargin(tmp.withWestLabel(tmp0).withEastLabel(tmp1), 10); } @Override public Dimension2D calculateDimension(StringBounder stringBounder) { - final double height2 = shape2.calculateDimension(stringBounder).getHeight() + getSuppHeightMargin(); + final Dimension2D toto1 = calculateDimensionRaw(stringBounder); + final Dimension2D toto2 = shape1.calculateDimension(stringBounder); + return MathUtils.max(toto1, toto2); + } + + private Dimension2D calculateDimensionRaw(StringBounder stringBounder) { + final double height2 = shape2.calculateDimension(stringBounder).getHeight(); final Dimension2D nude = super.calculateDimension(stringBounder); - if (branches.size() > 1) - return Dimension2DDouble.delta(nude, 0, height2); - return Dimension2DDouble.delta(nude, missingSpace(), height2); - } - - @Override - public UTranslate getCoord(String name) { - final UTranslate result = super.getCoord(name); - return result; - } - - private HColor fontColor(FontParam param) { - return skinParam().getFontHtmlColor(null, param); + return Dimension2DDouble.delta(nude, 0, height2); } final public StyleSignature getDefaultStyleDefinitionActivity() { @@ -201,30 +139,31 @@ public class GtileIfHexagon extends GtileIfSimple { } @Override - public void drawU(UGraphic ug) { - super.drawU(ug); + protected void drawUInternal(UGraphic ug) { + super.drawUInternal(ug); - shape1.drawU(ug.apply(positionShape1)); - shape2.drawU(ug.apply(positionShape2)); + ug.apply(positionShape1).draw(shape1); + ug.apply(positionShape2).draw(shape2); } +// private TextBlock getLabelPositive(Branch branch) { +// final LineBreakStrategy labelLineBreak = LineBreakStrategy.NONE; +// +// final FontConfiguration fontConfiguration; +// if (UseStyle.useBetaStyle()) { +// final Style style = getDefaultStyleDefinitionArrow().getMergedStyle(skinParam().getCurrentStyleBuilder()); +// fontConfiguration = style.getFontConfiguration(skinParam().getThemeStyle(), skinParam().getIHtmlColorSet()); +// } else { +// fontConfiguration = new FontConfiguration(skinParam(), FontParam.ARROW, null); +// } +// +// return branch.getDisplayPositive().create0(fontConfiguration, HorizontalAlignment.LEFT, skinParam(), +// labelLineBreak, CreoleMode.SIMPLE_LINE, null, null); +// } + @Override public Collection getInnerConnections() { - if (branches.size() == 1) { - final GConnection arrow1 = new GConnectionVerticalDown(positionShape1, shape1.getGPoint(GPoint.SOUTH_HOOK), - positions.get(0), gtiles.get(0).getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); - final GConnection arrow2 = new GConnectionVerticalDown(positions.get(0), - gtiles.get(0).getGPoint(GPoint.SOUTH_HOOK), positionShape2, shape2.getGPoint(GPoint.NORTH_HOOK), - TextBlockUtils.EMPTY_TEXT_BLOCK); - - final Dimension2D totalDim = calculateDimension(stringBounder); - - final GConnection arrow3 = new GConnectionLeftThenDownThenRight(positionShape1, - shape1.getGPoint(GPoint.EAST_HOOK), positionShape2, shape2.getGPoint(GPoint.EAST_HOOK), totalDim.getWidth(), - TextBlockUtils.EMPTY_TEXT_BLOCK); - return Arrays.asList(arrow1, arrow2, arrow3); - // return Arrays.asList(arrow3); - } else if (branches.size() == 2) { + if (branches.size() == 2) { final GConnection arrow1 = new GConnectionHorizontalThenVerticalDown(positionShape1, shape1.getGPoint(GPoint.WEST_HOOK), positions.get(0), gtiles.get(0).getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileRepeat.java new file mode 100644 index 000000000..0d49a661d --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileRepeat.java @@ -0,0 +1,112 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.awt.geom.Dimension2D; +import java.util.Arrays; +import java.util.Collection; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.StyleSignature; +import net.sourceforge.plantuml.ugraphic.color.HColor; + +public class GtileRepeat extends GtileTopDown3 { + + private static final double SUPP_WIDTH = 15; + + public GtileRepeat(Swimlane swimlane, Gtile gtile, HColor color, Display test) { + super(getShape1(swimlane, color, gtile.getStringBounder(), gtile.skinParam()), gtile, + getShape2(swimlane, color, gtile.getStringBounder(), gtile.skinParam(), test)); + + } + + private static Gtile getShape1(Swimlane swimlane, HColor color, StringBounder stringBounder, ISkinParam skinParam) { + final AbstractGtileRoot tmp = Gtiles.diamondEmpty(swimlane, stringBounder, skinParam, + getDefaultStyleDefinitionDiamond(), color); + return Gtiles.withSouthMargin(tmp, 20); +// GtileHexagonInside tmp = Gtiles.hexagonInside(stringBounder, skinParam, swimlane, +// getDefaultStyleDefinitionDiamond(), branch0); +// final TextBlock tmp0 = branch0.getTextBlockPositive(); +// return Gtiles.withSouthMargin(tmp.withSouthLabel(tmp0), 20); + } + + private static Gtile getShape2(Swimlane swimlane, HColor color, StringBounder stringBounder, ISkinParam skinParam, + Display test) { + final AbstractGtileRoot tmp = Gtiles.hexagonInside(swimlane, stringBounder, skinParam, + getDefaultStyleDefinitionDiamond(), color, test); + return Gtiles.withNorthMargin(tmp, 20); + } + + final public StyleSignature getDefaultStyleDefinitionActivity() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.activity); + } + + final static public StyleSignature getDefaultStyleDefinitionDiamond() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.activity, SName.diamond); + } + + final public StyleSignature getDefaultStyleDefinitionArrow() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.arrow); + } + + @Override + public Dimension2D calculateDimension(StringBounder stringBounder) { + return Dimension2DDouble.delta(super.calculateDimension(stringBounder), SUPP_WIDTH, 0); + } + + @Override + public Collection getInnerConnections() { + + final GConnection arrow1 = new GConnectionVerticalDown(getPos1(), tile1.getGPoint(GPoint.SOUTH_HOOK), getPos2(), + tile2.getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); + final GConnection arrow2 = new GConnectionVerticalDown(getPos2(), tile2.getGPoint(GPoint.SOUTH_HOOK), getPos3(), + tile3.getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); + + final double xright = calculateDimension(stringBounder).getWidth(); + + final GConnection arrow3 = new GConnectionLeftThenVerticalThenRight(getPos3(), tile3.getGPoint(GPoint.EAST_HOOK), + getPos1(), tile1.getGPoint(GPoint.EAST_HOOK), xright, TextBlockUtils.EMPTY_TEXT_BLOCK); + + return Arrays.asList(arrow1, arrow2, arrow3); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileSplit.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileSplit.java new file mode 100644 index 000000000..1c5dde47f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileSplit.java @@ -0,0 +1,117 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.awt.geom.Dimension2D; +import java.util.List; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.StyleSignature; +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; + +public class GtileSplit extends GtileColumns { + + private final HColor lineColor; + + public GtileSplit(List gtiles, Swimlane singleSwimlane, HColor lineColor) { + super(gtiles, singleSwimlane); + this.lineColor = lineColor; + + } + + private static Gtile getShape1(Swimlane swimlane, HColor color, StringBounder stringBounder, ISkinParam skinParam, + Gtile first) { + final double start = first.getCoord(GPoint.NORTH_HOOK).getDx(); + final GtileHLine tmp = new GtileHLine(stringBounder, skinParam, swimlane, color); + return tmp; + } + + private static Gtile getShape2(Swimlane swimlane, HColor color, StringBounder stringBounder, ISkinParam skinParam) { + final GtileHLine tmp = new GtileHLine(stringBounder, skinParam, swimlane, color); + return tmp; + } + + final public StyleSignature getDefaultStyleDefinitionActivity() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.activity); + } + + final static public StyleSignature getDefaultStyleDefinitionDiamond() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.activity, SName.diamond); + } + + final public StyleSignature getDefaultStyleDefinitionArrow() { + return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.arrow); + } + + @Override + protected void drawUInternal(UGraphic ug) { + super.drawUInternal(ug); + gtiles.get(0).getCoord(GPoint.NORTH_HOOK); + ug.apply(lineColor).apply(new UStroke(1.5)) + .apply(UTranslate.dx(gtiles.get(0).getCoord(GPoint.NORTH_HOOK).getDx())).apply(positions.get(0)) + .draw(ULine.hline(10)); + } + + @Override + public Dimension2D calculateDimension(StringBounder stringBounder) { + return Dimension2DDouble.delta(super.calculateDimension(stringBounder), 0, 0); + } + +// @Override +// public Collection getInnerConnections() { +// +// final GConnection arrow1 = new GConnectionVerticalDown(getPos1(), tile1.getGPoint(GPoint.SOUTH_HOOK), getPos2(), +// tile2.getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); +// final GConnection arrow2 = new GConnectionVerticalDown(getPos2(), tile2.getGPoint(GPoint.SOUTH_HOOK), getPos3(), +// tile3.getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); +// +// final double xright = calculateDimension(stringBounder).getWidth(); +// +// final GConnection arrow3 = new GConnectionLeftThenVerticalThenRight(getPos1(), tile1.getGPoint(GPoint.EAST_HOOK), +// getPos3(), tile3.getGPoint(GPoint.EAST_HOOK), xright, TextBlockUtils.EMPTY_TEXT_BLOCK); +// +// return Arrays.asList(arrow1, arrow2, arrow3); +// } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileAssemblySimple.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileTopDown.java similarity index 74% rename from src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileAssemblySimple.java rename to src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileTopDown.java index 408f584bf..c9e4629f2 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileAssemblySimple.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileTopDown.java @@ -36,21 +36,17 @@ package net.sourceforge.plantuml.activitydiagram3.gtile; import java.awt.geom.Dimension2D; -import java.awt.geom.Point2D; -import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.utils.MathUtils; -public class GtileAssemblySimple extends AbstractGtile { +public class GtileTopDown extends AbstractGtile { protected final Gtile tile1; protected final Gtile tile2; @@ -63,10 +59,10 @@ public class GtileAssemblySimple extends AbstractGtile { @Override public String toString() { - return "GtileAssemblySimple " + tile1 + " && " + tile2; + return "GtileTopDown(" + tile1 + " && " + tile2 + ")"; } - public GtileAssemblySimple(Gtile tile1, Gtile tile2) { + public GtileTopDown(Gtile tile1, Gtile tile2) { super(tile1.getStringBounder(), tile1.skinParam()); this.tile1 = tile1; this.tile2 = tile2; @@ -74,12 +70,8 @@ public class GtileAssemblySimple extends AbstractGtile { this.dim1 = tile1.calculateDimension(stringBounder); this.dim2 = tile2.calculateDimension(stringBounder); - final UTranslate vector1 = tile1.getCoord(GPoint.SOUTH_HOOK); - final UTranslate vector2 = tile2.getCoord(GPoint.NORTH_HOOK); - -// final UTranslate diff = vector1.compose(vector2.reverse()); -// this.pos1 = diff.getDx() > 0 ? UTranslate.none() : UTranslate.dx(-diff.getDx()); -// this.pos2 = diff.compose(this.pos1); + final UTranslate vector1 = tile1.getCoord(GPoint.SOUTH_BORDER); + final UTranslate vector2 = tile2.getCoord(GPoint.NORTH_BORDER); final double maxDx = Math.max(vector1.getDx(), vector2.getDx()); this.pos1 = UTranslate.dx(maxDx - vector1.getDx()); @@ -90,13 +82,8 @@ public class GtileAssemblySimple extends AbstractGtile { return new UTranslate(); } -// @Override -// public List getHooks() { -// return Arrays.asList(tile1.getGPoint(GPoint.SOUTH), tile2.getGPoint(GPoint.NORTH)); -// } - @Override - public UTranslate getCoord(String name) { + protected UTranslate getCoordImpl(String name) { if (name.equals(GPoint.NORTH_HOOK)) return getPos1().compose(tile1.getCoord(name)); if (name.equals(GPoint.SOUTH_HOOK)) @@ -104,6 +91,15 @@ public class GtileAssemblySimple extends AbstractGtile { throw new UnsupportedOperationException(); } + @Override + public Swimlane getSwimlane(String name) { + if (name.equals(GPoint.NORTH_HOOK)) + return tile1.getSwimlane(name); + if (name.equals(GPoint.SOUTH_HOOK)) + return tile2.getSwimlane(name); + throw new UnsupportedOperationException(); + } + protected UTranslate getPos1() { return pos1; } @@ -112,16 +108,17 @@ public class GtileAssemblySimple extends AbstractGtile { return pos2.compose(supplementaryMove()); } - public void drawU(UGraphic ug) { + @Override + protected void drawUInternal(UGraphic ug) { ug.apply(getPos1()).draw(tile1); ug.apply(getPos2()).draw(tile2); } @Override public Dimension2D calculateDimension(StringBounder stringBounder) { - final Point2D corner1 = getPos1().getTranslated(dim1); - final Point2D corner2 = getPos2().getTranslated(dim2); - return new Dimension2DDouble(MathUtils.max(corner1, corner2)); + final Dimension2D corner1 = getPos1().getTranslated(dim1); + final Dimension2D corner2 = getPos2().getTranslated(dim2); + return MathUtils.max(corner1, corner2); } public Set getSwimlanes() { @@ -131,8 +128,8 @@ public class GtileAssemblySimple extends AbstractGtile { return Collections.unmodifiableSet(result); } - public Collection getMyChildren() { - return Arrays.asList(tile1, tile2); - } +// public Collection getMyChildren() { +// return Arrays.asList(tile1, tile2); +// } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileTopDown3.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileTopDown3.java new file mode 100644 index 000000000..09c1c203e --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileTopDown3.java @@ -0,0 +1,140 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.awt.geom.Dimension2D; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; +import net.sourceforge.plantuml.utils.MathUtils; + +public class GtileTopDown3 extends AbstractGtile { + + protected final Gtile tile1; + protected final Gtile tile2; + protected final Gtile tile3; + + private final Dimension2D dim1; + private final Dimension2D dim2; + private final Dimension2D dim3; + + private final UTranslate pos1; + private final UTranslate pos2; + private final UTranslate pos3; + + public GtileTopDown3(Gtile tile1, Gtile tile2, Gtile tile3) { + super(tile1.getStringBounder(), tile1.skinParam()); + + final GtileTopDown tile12 = new GtileTopDown(tile1, tile2); + final GtileTopDown tile123 = new GtileTopDown(tile12, tile3); + + this.tile1 = tile1; + this.tile2 = tile2; + this.tile3 = tile3; + + this.dim1 = tile1.calculateDimension(stringBounder); + this.dim2 = tile2.calculateDimension(stringBounder); + this.dim3 = tile3.calculateDimension(stringBounder); + + this.pos1 = tile123.getPos1().compose(tile12.getPos1()); + this.pos2 = tile123.getPos1().compose(tile12.getPos2()); + this.pos3 = tile123.getPos2(); + } + + @Override + protected UTranslate getCoordImpl(String name) { + if (name.equals(GPoint.NORTH_HOOK)) + return getPos1().compose(tile1.getCoord(name)); + if (name.equals(GPoint.SOUTH_HOOK)) + return getPos3().compose(tile3.getCoord(name)); + throw new UnsupportedOperationException(); + } + + @Override + public Swimlane getSwimlane(String name) { + if (name.equals(GPoint.NORTH_HOOK)) + return tile1.getSwimlane(name); + if (name.equals(GPoint.SOUTH_HOOK)) + return tile3.getSwimlane(name); + throw new UnsupportedOperationException(); + } + + protected UTranslate getPos1() { + return pos1; + } + + protected UTranslate getPos2() { + return pos2; + } + + protected UTranslate getPos3() { + return pos3; + } + + @Override + protected void drawUInternal(UGraphic ug) { + ug.apply(getPos1()).draw(tile1); + ug.apply(getPos2()).draw(tile2); + ug.apply(getPos3()).draw(tile3); + } + + @Override + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D corner1 = getPos1().getTranslated(dim1); + final Dimension2D corner2 = getPos2().getTranslated(dim2); + final Dimension2D corner3 = getPos3().getTranslated(dim3); + return MathUtils.max(corner1, corner2, corner3); + } + + @Override + public Set getSwimlanes() { + final Set result = new HashSet<>(); + result.addAll(tile1.getSwimlanes()); + result.addAll(tile2.getSwimlanes()); + result.addAll(tile3.getSwimlanes()); + return Collections.unmodifiableSet(result); + } + +// public Collection getMyChildren() { +// return Arrays.asList(tile1, tile2); +// } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionTranslatable.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithIncomingArrow.java similarity index 68% rename from src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionTranslatable.java rename to src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithIncomingArrow.java index 8c6b3c5fa..d16183dcf 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GConnectionTranslatable.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithIncomingArrow.java @@ -35,11 +35,23 @@ */ package net.sourceforge.plantuml.activitydiagram3.gtile; -import net.sourceforge.plantuml.ugraphic.UGraphic; +import java.util.Collection; +import java.util.Collections; + +import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.ugraphic.UTranslate; -public interface GConnectionTranslatable extends GConnection { +public class GtileWithIncomingArrow extends GtileWithMargin implements Gtile { - public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2); + public GtileWithIncomingArrow(AbstractGtileRoot orig, double north) { + super(orig, north, 0, 0); + } + + @Override + public Collection getInnerConnections() { + final GConnection arrow = new GConnectionVerticalDown(UTranslate.dy(0), orig.getGPoint(GPoint.NORTH_HOOK), + UTranslate.dy(north), orig.getGPoint(GPoint.NORTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); + return Collections.singletonList(arrow); + } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithMargin.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithMargin.java new file mode 100644 index 000000000..d4556057f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithMargin.java @@ -0,0 +1,99 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.awt.geom.Dimension2D; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class GtileWithMargin extends AbstractGtileRoot implements Gtile { + + protected final AbstractGtileRoot orig; + protected final double north; + protected final double south; + private final double east; + + public GtileWithMargin(AbstractGtileRoot orig, double north, double south, double east) { + super(orig.stringBounder, orig.skinParam()); + this.orig = orig; + this.north = north; + this.south = south; + this.east = east; + } + + @Override + public Set getSwimlanes() { + return orig.getSwimlanes(); + } + + @Override + public Swimlane getSwimlane(String point) { + return orig.getSwimlane(point); + } + + @Override + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D result = orig.calculateDimension(stringBounder); + return Dimension2DDouble.delta(result, east, north + south); + } + + private UTranslate getTranslate() { + return new UTranslate(east, north); + } + + @Override + protected void drawUInternal(UGraphic ug) { + orig.drawU(ug.apply(getTranslate())); + } + + @Override + protected UTranslate getCoordImpl(String name) { + return orig.getCoordImpl(name).compose(getTranslate()); + } + + @Override + public Collection getInnerConnections() { + return Collections.emptyList(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithNoteOpale.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithNoteOpale.java index 9fce797e8..3c67aa855 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithNoteOpale.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithNoteOpale.java @@ -138,13 +138,19 @@ public class GtileWithNoteOpale extends AbstractGtile implements Stencil, Stylea final Dimension2D dimTotal = calculateDimension(stringBounder); - this.positionNote = new UTranslate(0, (dimTotal.getHeight() - dimNote.getHeight()) / 2); - this.positionTile = new UTranslate(dimNote.getWidth() + suppSpace, - (dimTotal.getHeight() - dimTile.getHeight()) / 2); + if (note.getNotePosition() == NotePosition.LEFT) { + this.positionNote = new UTranslate(0, (dimTotal.getHeight() - dimNote.getHeight()) / 2); + this.positionTile = new UTranslate(dimNote.getWidth() + suppSpace, + (dimTotal.getHeight() - dimTile.getHeight()) / 2); + } else { + this.positionNote = new UTranslate(dimTile.getWidth() + suppSpace, + (dimTotal.getHeight() - dimNote.getHeight()) / 2); + this.positionTile = new UTranslate(0, (dimTotal.getHeight() - dimTile.getHeight()) / 2); + } } @Override - public UTranslate getCoord(String name) { + protected UTranslate getCoordImpl(String name) { return tile.getCoord(name).compose(positionTile); } @@ -155,7 +161,7 @@ public class GtileWithNoteOpale extends AbstractGtile implements Stencil, Stylea } @Override - public void drawU(UGraphic ug) { + protected void drawUInternal(UGraphic ug) { ug.apply(positionNote).draw(opale); ug.apply(positionTile).draw(tile); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithOutgoingArrow.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithOutgoingArrow.java new file mode 100644 index 000000000..1c9bcbbf2 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/GtileWithOutgoingArrow.java @@ -0,0 +1,57 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import java.util.Collection; +import java.util.Collections; + +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class GtileWithOutgoingArrow extends GtileWithMargin implements Gtile { + + public GtileWithOutgoingArrow(AbstractGtileRoot orig, double south) { + super(orig, 0, south, 0); + } + + @Override + public Collection getInnerConnections() { + final GConnection arrow = new GConnectionVerticalDown(UTranslate.dy(0), orig.getGPoint(GPoint.SOUTH_HOOK), + UTranslate.dy(south), orig.getGPoint(GPoint.SOUTH_HOOK), TextBlockUtils.EMPTY_TEXT_BLOCK); + return Collections.singletonList(arrow); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/gtile/Gtiles.java b/src/net/sourceforge/plantuml/activitydiagram3/gtile/Gtiles.java new file mode 100644 index 000000000..8ac0968ac --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/gtile/Gtiles.java @@ -0,0 +1,142 @@ +/* ======================================================================== + * 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.activitydiagram3.gtile; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.LineBreakStrategy; +import net.sourceforge.plantuml.UseStyle; +import net.sourceforge.plantuml.activitydiagram3.ftile.Hexagon; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.creole.CreoleMode; +import net.sourceforge.plantuml.creole.Parser; +import net.sourceforge.plantuml.creole.Sheet; +import net.sourceforge.plantuml.creole.SheetBlock1; +import net.sourceforge.plantuml.creole.SheetBlock2; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.style.PName; +import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.style.StyleSignature; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.color.HColor; + +public class Gtiles { + + private static final Rose rose = new Rose(); + + static public GtileHexagonInside hexagonInside(Swimlane swimlane, StringBounder stringBounder, ISkinParam skinParam, + StyleSignature styleSignature, HColor color, Display label) { + final ConditionStyle conditionStyle = skinParam.getConditionStyle(); + + final HColor borderColor; + final HColor backColor; + final FontConfiguration fcTest; + + if (UseStyle.useBetaStyle()) { + final Style style = styleSignature.getMergedStyle(skinParam.getCurrentStyleBuilder()); + borderColor = style.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); + backColor = color == null ? style.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(), + skinParam.getIHtmlColorSet()) : color; + fcTest = style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); + } else { + final FontParam testParam = conditionStyle == ConditionStyle.INSIDE_HEXAGON ? FontParam.ACTIVITY_DIAMOND + : FontParam.ARROW; + + borderColor = rose.getHtmlColor(skinParam, ColorParam.activityDiamondBorder); + backColor = color == null ? rose.getHtmlColor(skinParam, ColorParam.activityDiamondBackground) : color; + fcTest = new FontConfiguration(skinParam, testParam, null) + .changeColor(fontColor(skinParam, FontParam.ACTIVITY_DIAMOND)); + } + + final Sheet sheet = Parser + .build(fcTest, skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), skinParam, CreoleMode.FULL) + .createSheet(label); + final SheetBlock1 sheetBlock1 = new SheetBlock1(sheet, LineBreakStrategy.NONE, skinParam.getPadding()); + final TextBlock tbTest = new SheetBlock2(sheetBlock1, Hexagon.asStencil(sheetBlock1), new UStroke()); + + return new GtileHexagonInside(stringBounder, tbTest, skinParam, backColor, borderColor, swimlane); + } + + static public AbstractGtileRoot diamondEmpty(Swimlane swimlane, StringBounder stringBounder, ISkinParam skinParam, + StyleSignature styleSignature, HColor color) { + final HColor borderColor; + final HColor backColor; + + if (UseStyle.useBetaStyle()) { + final Style style = styleSignature.getMergedStyle(skinParam.getCurrentStyleBuilder()); + borderColor = style.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); + backColor = color == null ? style.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(), + skinParam.getIHtmlColorSet()) : color; + } else { + borderColor = rose.getHtmlColor(skinParam, ColorParam.activityDiamondBorder); + backColor = color == null ? rose.getHtmlColor(skinParam, ColorParam.activityDiamondBackground) : color; + } + + return new GtileHexagonInside(stringBounder, TextBlockUtils.EMPTY_TEXT_BLOCK, skinParam, backColor, borderColor, + swimlane); + } + + private static HColor fontColor(ISkinParam skinParam, FontParam param) { + return skinParam.getFontHtmlColor(null, param); + } + + static public Gtile withSouthMargin(Gtile orig, double south) { + return new GtileWithMargin((AbstractGtileRoot) orig, 0, south, 0); + + } + + static public Gtile withNorthMargin(Gtile orig, double north) { + return new GtileWithMargin((AbstractGtileRoot) orig, north, 0, 0); + + } + + public static Gtile withIncomingArrow(Gtile orig, double margin) { + return new GtileWithIncomingArrow((AbstractGtileRoot) orig, margin); + } + + public static Gtile withOutgoingArrow(Gtile orig, double margin) { + return new GtileWithOutgoingArrow((AbstractGtileRoot) orig, margin); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/legacy/AtomText.java b/src/net/sourceforge/plantuml/creole/legacy/AtomText.java index 0353e1dcb..45839b682 100644 --- a/src/net/sourceforge/plantuml/creole/legacy/AtomText.java +++ b/src/net/sourceforge/plantuml/creole/legacy/AtomText.java @@ -225,6 +225,29 @@ public final class AtomText extends AbstractAtom implements Atom { } private final Collection splitted() { + final List result = new ArrayList<>(); + final StringBuilder pending = new StringBuilder(); + for (int i = 0; i < text.length(); i++) { + final char ch = text.charAt(i); + if (isSeparator(ch)) { + if (pending.length() > 0) + result.add(pending.toString()); + result.add("" + ch); + pending.setLength(0); + } else if (isChineseSentenceBoundary(ch)) { + pending.append(ch); + result.add(pending.toString()); + pending.setLength(0); + } else { + pending.append(ch); + } + } + if (pending.length() > 0) + result.add(pending.toString()); + return result; + } + + private final Collection splittedOld() { final List result = new ArrayList<>(); for (int i = 0; i < text.length(); i++) { final char ch = text.charAt(i); @@ -290,10 +313,13 @@ public final class AtomText extends AbstractAtom implements Atom { } private boolean isSeparator(char ch) { - return Character.isWhitespace(ch) // - || ch == '\uFF01' // U+FF01 FULLWIDTH EXCLAMATION MARK (!) - || ch == '\uFF08' // U+FF08 FULLWIDTH LEFT PARENTHESIS - || ch == '\uFF09' // U+FF09 FULLWIDTH RIGHT PARENTHESIS + return Character.isWhitespace(ch); + } + + private boolean isChineseSentenceBoundary(char ch) { + return ch == '\uFF01' // U+FF01 FULLWIDTH EXCLAMATION MARK (!) +// || ch == '\uFF08' // U+FF08 FULLWIDTH LEFT PARENTHESIS +// || ch == '\uFF09' // U+FF09 FULLWIDTH RIGHT PARENTHESIS || ch == '\uFF0C' // U+FF0C FULLWIDTH COMMA || ch == '\uFF1A' // U+FF1A FULLWIDTH COLON (:) || ch == '\uFF1B' // U+FF1B FULLWIDTH SEMICOLON (;) diff --git a/src/net/sourceforge/plantuml/graphic/AbstractTextBlock.java b/src/net/sourceforge/plantuml/graphic/AbstractTextBlock.java index 1feffa095..ad8918b2b 100644 --- a/src/net/sourceforge/plantuml/graphic/AbstractTextBlock.java +++ b/src/net/sourceforge/plantuml/graphic/AbstractTextBlock.java @@ -41,10 +41,12 @@ import net.sourceforge.plantuml.ugraphic.MinMax; public abstract class AbstractTextBlock implements TextBlock { + @Override public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) { throw new UnsupportedOperationException("member=" + member + " " + getClass().toString()); } + @Override public MinMax getMinMax(StringBounder stringBounder) { throw new UnsupportedOperationException(getClass().toString()); } diff --git a/src/net/sourceforge/plantuml/ugraphic/UTranslate.java b/src/net/sourceforge/plantuml/ugraphic/UTranslate.java index 00facf6d9..2735160bf 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UTranslate.java +++ b/src/net/sourceforge/plantuml/ugraphic/UTranslate.java @@ -39,6 +39,8 @@ import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import net.sourceforge.plantuml.Dimension2DDouble; + public class UTranslate implements UChange { private final double dx; @@ -93,8 +95,8 @@ public class UTranslate implements UChange { return new Point2D.Double(p.getX() + dx, p.getY() + dy); } - public Point2D getTranslated(Dimension2D dim) { - return new Point2D.Double(dim.getWidth() + dx, dim.getHeight() + dy); + public Dimension2D getTranslated(Dimension2D dim) { + return new Dimension2DDouble(dim.getWidth() + dx, dim.getHeight() + dy); } public UTranslate scaled(double scale) { diff --git a/src/net/sourceforge/plantuml/utils/MathUtils.java b/src/net/sourceforge/plantuml/utils/MathUtils.java index f4ae59e01..76079d2a2 100644 --- a/src/net/sourceforge/plantuml/utils/MathUtils.java +++ b/src/net/sourceforge/plantuml/utils/MathUtils.java @@ -94,8 +94,17 @@ public class MathUtils { Math.max(dim1.getHeight(), dim2.getHeight())); } + public static Dimension2D max(Dimension2D dim1, Dimension2D dim2, Dimension2D dim3) { + return new Dimension2DDouble(MathUtils.max(dim1.getWidth(), dim2.getWidth(), dim3.getWidth()), + MathUtils.max(dim1.getHeight(), dim2.getHeight(), dim3.getHeight())); + } + public static Point2D max(Point2D pt1, Point2D pt2) { return new Point2D.Double(Math.max(pt1.getX(), pt2.getX()), Math.max(pt1.getY(), pt2.getY())); } + public static Point2D max(Point2D pt1, Point2D pt2, Point2D pt3) { + return new Point2D.Double(max(pt1.getX(), pt2.getX(), pt3.getX()), max(pt1.getY(), pt2.getY(), pt3.getY())); + } + } diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index a961d2fc4..4ae5770a7 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -80,7 +80,7 @@ public class Version { } public static int beta() { - final int beta = 0; + final int beta = 2; return beta; }