From 637adfa6cb32adc52d073c404145941d70f1489c Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Thu, 7 Oct 2021 18:51:26 +0200 Subject: [PATCH] Stereotype refactoring --- .../command/CommandLinkActivity.java | 4 +- .../command/CommandLinkLongActivity.java | 4 +- .../command/CommandPartition.java | 2 +- .../command/CommandActivity3.java | 2 +- .../command/CommandPartition3.java | 2 +- .../command/CommandRepeat3.java | 2 +- .../ftile/vcompact/FtileRepeat.java | 11 +- .../vcompact/cond/ConditionalBuilder.java | 12 +- .../vcompact/cond/FtileIfWithDiamonds.java | 15 +- .../command/CommandCreateClass.java | 2 +- .../command/CommandCreateClassMultilines.java | 2 +- .../command/CommandCreateElementFull2.java | 2 +- .../command/CommandStereotype.java | 2 +- .../plantuml/command/CommandNamespace.java | 2 +- .../plantuml/command/CommandNamespace2.java | 2 +- .../command/CommandNamespaceEmpty.java | 2 +- .../plantuml/command/CommandPackage.java | 2 +- .../note/CommandFactoryNoteOnEntity.java | 2 +- .../FactorySequenceNoteAcrossCommand.java | 2 +- .../sequence/FactorySequenceNoteCommand.java | 2 +- .../FactorySequenceNoteOnArrowCommand.java | 2 +- ...FactorySequenceNoteOverSeveralCommand.java | 2 +- .../plantuml/cucadiagram/Stereotype.java | 209 +++++------------- .../cucadiagram/StereotypeDecoration.java | 175 +++++++++++++++ .../descdiagram/CommandCreateDomain.java | 2 +- .../descdiagram/command/CommandArchimate.java | 2 +- .../command/CommandArchimateMultilines.java | 2 +- .../command/CommandCreateElementFull.java | 2 +- .../CommandCreateElementMultilines.java | 2 +- .../CommandCreateElementParenthesis.java | 2 +- .../command/CommandLinkElement.java | 2 +- .../command/CommandPackageWithUSymbol.java | 2 +- .../command/CommandCreateEntityObject.java | 2 +- .../CommandCreateEntityObjectMultilines.java | 2 +- .../command/CommandCreateMap.java | 2 +- .../command/CommandBoxStart.java | 2 +- .../command/CommandParticipant.java | 2 +- .../command/CommandCreatePackageState.java | 2 +- .../command/CommandCreateState.java | 2 +- .../command/CommandLinkState.java | 4 +- .../plantuml/timingdiagram/PlayerClock.java | 81 +++---- 41 files changed, 330 insertions(+), 249 deletions(-) create mode 100644 src/net/sourceforge/plantuml/cucadiagram/StereotypeDecoration.java diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java index 0ec71fd60..dbcbd1904 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java @@ -129,7 +129,7 @@ public class CommandLinkActivity extends SingleLineCommand2 { return CommandExecutionResult.error("No such activity"); } if (arg.get("STEREOTYPE", 0) != null) { - entity1.setStereotype(new Stereotype(arg.get("STEREOTYPE", 0))); + entity1.setStereotype(Stereotype.build(arg.get("STEREOTYPE", 0))); } if (arg.get("BACKCOLOR", 0) != null) { String s = arg.get("BACKCOLOR", 0); @@ -147,7 +147,7 @@ public class CommandLinkActivity extends SingleLineCommand2 { diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), s)); } if (arg.get("STEREOTYPE2", 0) != null) { - entity2.setStereotype(new Stereotype(arg.get("STEREOTYPE2", 0))); + entity2.setStereotype(Stereotype.build(arg.get("STEREOTYPE2", 0))); } final Display linkLabel = Display.getWithNewlines(arg.get("BRACKET", 0)); diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java index 335eb8cf6..9372d9ff8 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java @@ -126,7 +126,7 @@ public class CommandLinkLongActivity extends CommandMultilines2 } if (line0.get("STEREOTYPE", 0) != null) { - entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE", 0))); + entity1.setStereotype(Stereotype.build(line0.get("STEREOTYPE", 0))); } final String stringColor = line0.get("BACKCOLOR", 0); if (stringColor != null) { @@ -196,7 +196,7 @@ public class CommandLinkLongActivity extends CommandMultilines2 } if (lineLast.get(2) != null) { - entity2.setStereotype(new Stereotype(lineLast.get(2))); + entity2.setStereotype(Stereotype.build(lineLast.get(2))); } if (lineLast.get(4) != null) { String s = lineLast.get(4); diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java index 66630899c..d8918b920 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java @@ -101,7 +101,7 @@ public class CommandPartition extends SingleLineCommand2 { p.setColors(colors); } if (arg.get("STEREOTYPE", 0) != null) { - p.setStereotype(new Stereotype(arg.get("STEREOTYPE", 0))); + p.setStereotype(Stereotype.build(arg.get("STEREOTYPE", 0))); } return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java index 1974bcc4e..833086306 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java @@ -118,7 +118,7 @@ public class CommandActivity3 extends SingleLineCommand2 { final String stereo = arg.get("STEREO", 0); Stereotype stereotype = null; if (stereo != null) { - stereotype = new Stereotype(stereo); + stereotype = Stereotype.build(stereo); colors = colors.applyStereotype(stereotype, diagram.getSkinParam(), ColorParam.activityBackground); } final BoxStyle style = BoxStyle.fromChar(arg.get("STYLE", 0).charAt(0)); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandPartition3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandPartition3.java index 48b462c85..03e1a628e 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandPartition3.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandPartition3.java @@ -129,7 +129,7 @@ public class CommandPartition3 extends SingleLineCommand2 { final USymbol symbol = getUSymbol(arg.get("TYPE", 0)); final String stereo = arg.get("STEREO", 0); - final Stereotype stereotype = stereo == null ? null : new Stereotype(stereo); + final Stereotype stereotype = stereo == null ? null : Stereotype.build(stereo); final HColor backColorInSkinparam = diagram.getSkinParam().getHtmlColor(getColorParamBack(symbol), stereotype, false); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java index 349ce431d..dfae89a2a 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java @@ -94,7 +94,7 @@ public class CommandRepeat3 extends SingleLineCommand2 { diagram.getSkinParam().getIHtmlColorSet()); final String stereo = arg.get("STEREO", 0); if (stereo != null) { - final Stereotype stereotype = new Stereotype(stereo); + final Stereotype stereotype = Stereotype.build(stereo); colors = colors.applyStereotype(stereotype, diagram.getSkinParam(), ColorParam.activityBackground); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java index c2dcc1885..86359f7c0 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java @@ -215,8 +215,15 @@ class FtileRepeat extends AbstractFtile { final StringBounder stringBounder = ug.getStringBounder(); final Snake snake = Snake.create(arrowColor, Arrows.asToDown()).withLabel(tbin, arrowHorizontalAlignment()); - snake.addPoint(getP1(stringBounder)); - snake.addPoint(getP2(stringBounder)); + final Point2D p1 = getP1(stringBounder); + final Point2D p2 = getP2(stringBounder); + snake.addPoint(p1); + if (p1.getX() != p2.getX()) { + final double my = (p1.getY() + p2.getY()) / 2; + snake.addPoint(new Point2D.Double(p1.getX(), my)); + snake.addPoint(new Point2D.Double(p2.getX(), my)); + } + snake.addPoint(p2); ug.draw(snake); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java index e830a976c..7654deb0a 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/ConditionalBuilder.java @@ -78,6 +78,8 @@ public class ConditionalBuilder { private final Swimlane swimlane; private final HColor borderColor; private final HColor backColor; + private final LineBreakStrategy diamondLineBreak; + private final LineBreakStrategy labelLineBreak; private final Rainbow arrowColor; private final FtileFactory ftileFactory; private final ConditionStyle conditionStyle; @@ -110,6 +112,8 @@ public class ConditionalBuilder { .getMergedStyle(skinParam.getCurrentStyleBuilder()); final Style styleDiamond = getDefaultStyleDefinitionDiamond() .getMergedStyle(skinParam.getCurrentStyleBuilder()); + this.diamondLineBreak = styleDiamond.wrapWidth(); + this.labelLineBreak = styleArrow.wrapWidth(); this.borderColor = styleDiamond.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); this.backColor = styleDiamond.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(), @@ -120,6 +124,8 @@ public class ConditionalBuilder { this.fontTest = styleDiamond.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); this.fontArrow = styleArrow.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); } else { + this.diamondLineBreak = LineBreakStrategy.NONE; + this.labelLineBreak = LineBreakStrategy.NONE; this.borderColor = borderColor; this.backColor = backColor; this.arrowColor = arrowColor; @@ -242,7 +248,7 @@ public class ConditionalBuilder { final Sheet sheet = Parser.build(fontTest, skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), skinParam, CreoleMode.FULL).createSheet(labelTest); - final SheetBlock1 sheetBlock1 = new SheetBlock1(sheet, LineBreakStrategy.NONE, skinParam.getPadding()); + final SheetBlock1 sheetBlock1 = new SheetBlock1(sheet, diamondLineBreak, skinParam.getPadding()); final TextBlock tbTest = new SheetBlock2(sheetBlock1, Diamond.asStencil(sheetBlock1), tile1.getThickness()); final Ftile diamond1; @@ -277,8 +283,8 @@ public class ConditionalBuilder { } private TextBlock getLabelPositive(Branch branch) { - return branch.getLabelPositive().create7(fontArrow, HorizontalAlignment.LEFT, ftileFactory.skinParam(), - CreoleMode.SIMPLE_LINE); + return branch.getLabelPositive().create0(fontArrow, HorizontalAlignment.LEFT, ftileFactory.skinParam(), + labelLineBreak, CreoleMode.SIMPLE_LINE, null, null); } private Ftile getDiamond2(Branch branch1, Branch branch2, boolean useNorth) { diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java index 8b277349b..73da00734 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/cond/FtileIfWithDiamonds.java @@ -65,16 +65,13 @@ public class FtileIfWithDiamonds extends FtileIfNude { } public int getYdelta1a(StringBounder stringBounder) { - // if (getSwimlanes().size() > 1 && hasTwoBranches(stringBounder)) { if (getSwimlanes().size() > 1) { return 20; } return 10; - // return hasTwoBranches(stringBounder) ? 6 : 6; } public int getYdelta1b(StringBounder stringBounder) { - // if (getSwimlanes().size() > 1 && hasTwoBranches(stringBounder)) { if (getSwimlanes().size() > 1) { return 10; } @@ -98,9 +95,6 @@ public class FtileIfWithDiamonds extends FtileIfNude { return all.addDim(0, getYdelta1a(stringBounder) + getYdelta1b(stringBounder)); - // final double height = dimNude.getHeight() + dim1.getHeight() + dim2.getHeight() + getYdelta1a(stringBounder) - // + getYdelta1b(stringBounder); - // return new Dimension2DDouble(width, height); } @Override @@ -115,22 +109,21 @@ public class FtileIfWithDiamonds extends FtileIfNude { @Override protected UTranslate getTranslate1(StringBounder stringBounder) { final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - return super.getTranslate1(stringBounder).compose( - UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); + return super.getTranslate1(stringBounder) + .compose(UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); } @Override protected UTranslate getTranslate2(StringBounder stringBounder) { final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - return super.getTranslate2(stringBounder).compose( - UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); + return super.getTranslate2(stringBounder) + .compose(UTranslate.dy(dimDiamond1.getHeight() + getYdelta1a(stringBounder))); } protected UTranslate getTranslateDiamond1(StringBounder stringBounder) { final double y1 = 0; final FtileGeometry dimTotal = calculateDimensionInternal(stringBounder); final FtileGeometry dimDiamond1 = diamond1.calculateDimension(stringBounder); - // final double x1 = getLeft(stringBounder) - dimDiamond1.getWidth() / 2; final double x1 = dimTotal.getLeft() - dimDiamond1.getLeft(); return new UTranslate(x1, y1); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java index e95e912fa..31f8a7c8d 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java @@ -157,7 +157,7 @@ public class CommandCreateClass extends SingleLineCommand2 { } } if (stereotype != null) { - entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), + entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram.getSkinParam().getFont(null, false, FontParam.CIRCLED_CHARACTER), diagram.getSkinParam().getIHtmlColorSet())); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java index 44177fc1d..a844f65f1 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java @@ -264,7 +264,7 @@ public class CommandCreateClassMultilines extends CommandMultilines2 entity.setDisplay(Display.getWithNewlines(display)); entity.setUSymbol(usymbol); if (stereotype != null) { - entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), + entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram.getSkinParam().getFont(null, false, FontParam.CIRCLED_CHARACTER), diagram.getSkinParam().getIHtmlColorSet())); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java index 458c54a67..f9c1ed2bd 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java @@ -71,7 +71,7 @@ public class CommandStereotype extends SingleLineCommand2 { final Code code = diagram.V1972() ? ident : diagram.buildCode(name); final String stereotype = arg.get("STEREO", 0); final IEntity entity = diagram.getOrCreateLeaf(ident, code, null, null); - entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram + entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram .getSkinParam().getFont(null, false, FontParam.CIRCLED_CHARACTER), diagram.getSkinParam() .getIHtmlColorSet())); return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/command/CommandNamespace.java b/src/net/sourceforge/plantuml/command/CommandNamespace.java index f83d9963f..e84f6cc47 100644 --- a/src/net/sourceforge/plantuml/command/CommandNamespace.java +++ b/src/net/sourceforge/plantuml/command/CommandNamespace.java @@ -98,7 +98,7 @@ public class CommandNamespace extends SingleLineCommand2 { final IEntity p = diagram.getCurrentGroup(); final String stereotype = arg.get("STEREOTYPE", 0); if (stereotype != null) { - p.setStereotype(new Stereotype(stereotype)); + p.setStereotype(Stereotype.build(stereotype)); } final String urlString = arg.get("URL", 0); diff --git a/src/net/sourceforge/plantuml/command/CommandNamespace2.java b/src/net/sourceforge/plantuml/command/CommandNamespace2.java index 83393d62f..c1fb4e84b 100644 --- a/src/net/sourceforge/plantuml/command/CommandNamespace2.java +++ b/src/net/sourceforge/plantuml/command/CommandNamespace2.java @@ -98,7 +98,7 @@ public class CommandNamespace2 extends SingleLineCommand2 { final IEntity p = diagram.getCurrentGroup(); final String stereotype = arg.get("STEREOTYPE", 0); if (stereotype != null) { - p.setStereotype(new Stereotype(stereotype)); + p.setStereotype(Stereotype.build(stereotype)); } final String urlString = arg.get("URL", 0); diff --git a/src/net/sourceforge/plantuml/command/CommandNamespaceEmpty.java b/src/net/sourceforge/plantuml/command/CommandNamespaceEmpty.java index 168c80672..8262332b9 100644 --- a/src/net/sourceforge/plantuml/command/CommandNamespaceEmpty.java +++ b/src/net/sourceforge/plantuml/command/CommandNamespaceEmpty.java @@ -92,7 +92,7 @@ public class CommandNamespaceEmpty extends SingleLineCommand2 { final IEntity p = diagram.getCurrentGroup(); final String stereotype = arg.get("STEREOTYPE", 0); if (stereotype != null) { - p.setStereotype(new Stereotype(stereotype)); + p.setStereotype(Stereotype.build(stereotype)); } final String urlString = arg.get("URL", 0); diff --git a/src/net/sourceforge/plantuml/command/CommandPackage.java b/src/net/sourceforge/plantuml/command/CommandPackage.java index d7fd97d6a..e051d0d9d 100644 --- a/src/net/sourceforge/plantuml/command/CommandPackage.java +++ b/src/net/sourceforge/plantuml/command/CommandPackage.java @@ -141,7 +141,7 @@ public class CommandPackage extends SingleLineCommand2 { final USymbol usymbol = USymbol.fromString(stereotype, diagram.getSkinParam().actorStyle(), diagram.getSkinParam().componentStyle(), diagram.getSkinParam().packageStyle()); if (usymbol == null) { - p.setStereotype(new Stereotype(stereotype)); + p.setStereotype(Stereotype.build(stereotype)); } else { p.setUSymbol(usymbol); } diff --git a/src/net/sourceforge/plantuml/command/note/CommandFactoryNoteOnEntity.java b/src/net/sourceforge/plantuml/command/note/CommandFactoryNoteOnEntity.java index 47ab4fe40..b1d28437c 100644 --- a/src/net/sourceforge/plantuml/command/note/CommandFactoryNoteOnEntity.java +++ b/src/net/sourceforge/plantuml/command/note/CommandFactoryNoteOnEntity.java @@ -242,7 +242,7 @@ public final class CommandFactoryNoteOnEntity implements SingleMultiFactoryComma final String stereotypeString = line0.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteAcrossCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteAcrossCommand.java index bcfb3baf9..e9f25f3f1 100644 --- a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteAcrossCommand.java +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteAcrossCommand.java @@ -159,7 +159,7 @@ public final class FactorySequenceNoteAcrossCommand implements SingleMultiFactor diagram.getSkinParam().getIHtmlColorSet()); final String stereotypeString = line0.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java index a5928fdf7..5b89d37f6 100644 --- a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java @@ -158,7 +158,7 @@ public final class FactorySequenceNoteCommand implements SingleMultiFactoryComma diagram.getSkinParam().getIHtmlColorSet()); final String stereotypeString = arg.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java index 91520773d..9f0ebffac 100644 --- a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java @@ -153,7 +153,7 @@ public final class FactorySequenceNoteOnArrowCommand implements SingleMultiFacto final Note note = new Note(display, position, style, diagram.getSkinParam().getCurrentStyleBuilder()); final String stereotypeString = line0.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java index b8928fce3..4f852cbcb 100644 --- a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java @@ -169,7 +169,7 @@ public final class FactorySequenceNoteOverSeveralCommand implements SingleMultiF diagram.getSkinParam().getIHtmlColorSet()); final String stereotypeString = line0.get("STEREO", 0); if (stereotypeString != null) { - final Stereotype stereotype = new Stereotype(stereotypeString); + final Stereotype stereotype = Stereotype.build(stereotypeString); colors = colors.applyStereotypeForNote(stereotype, diagram.getSkinParam(), FontParam.NOTE, ColorParam.noteBackground, ColorParam.noteBorder); note.setStereotype(stereotype); diff --git a/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java b/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java index 14a39fbd1..8b8d1f17e 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java @@ -45,191 +45,100 @@ import java.util.regex.Pattern; import net.sourceforge.plantuml.Guillemet; import net.sourceforge.plantuml.SpriteContainer; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.command.regex.Matcher2; -import net.sourceforge.plantuml.command.regex.MyPattern; -import net.sourceforge.plantuml.command.regex.Pattern2; -import net.sourceforge.plantuml.command.regex.RegexComposed; -import net.sourceforge.plantuml.command.regex.RegexConcat; -import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexOptional; -import net.sourceforge.plantuml.command.regex.RegexResult; -import net.sourceforge.plantuml.creole.Parser; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.sprite.Sprite; -import net.sourceforge.plantuml.sprite.SpriteUtils; import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.StyleBuilder; import net.sourceforge.plantuml.svek.PackageStyle; import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColorSet; -import net.sourceforge.plantuml.ugraphic.color.HColorUtils; import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException; public class Stereotype implements CharSequence { - private final static RegexComposed circleChar = new RegexConcat( // - new RegexLeaf("\\<\\<"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("\\(?"), // - new RegexLeaf("CHAR", "(\\S)"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf(","), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("COLOR", "(#[0-9a-fA-F]{6}|\\w+)"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexOptional(new RegexLeaf("LABEL", "[),](.*?)")), // - new RegexLeaf("\\>\\>") // - ); - - private final static RegexComposed circleSprite = new RegexConcat( // - new RegexLeaf("\\<\\<"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("\\(?\\$"), // - new RegexLeaf("NAME", "(" + SpriteUtils.SPRITE_NAME + ")"), // - new RegexLeaf("SCALE", "((?:\\{scale=|\\*)([0-9.]+)\\}?)?"), // - RegexLeaf.spaceZeroOrMore(), // - new RegexOptional( // - new RegexConcat( // - new RegexLeaf(","), // - RegexLeaf.spaceZeroOrMore(), // - new RegexLeaf("COLOR", "(#[0-9a-fA-F]{6}|\\w+)") // - )), // - RegexLeaf.spaceZeroOrMore(), // - new RegexOptional(new RegexLeaf("LABEL", "[),](.*?)")), // - new RegexLeaf("\\>\\>") // - ); private final double radius; private final UFont circledFont; private final boolean automaticPackageStyle; + private final StereotypeDecoration decoration; - private String label; - private HColor htmlColor; - private char character; - private String spriteName; - private double spriteScale; - - public Stereotype(String label, double radius, UFont circledFont, HColorSet htmlColorSet) throws NoSuchColorException { - this(label, radius, circledFont, true, htmlColorSet); - } - - public Stereotype(String label, boolean automaticPackageStyle) { - this.automaticPackageStyle = automaticPackageStyle; - this.label = label; - this.htmlColor = null; - this.character = '\0'; - this.radius = 0; - this.circledFont = null; - if (label.startsWith("<<$") && label.endsWith(">>")) { - final RegexResult mCircleSprite = circleSprite.matcher(label); - this.spriteName = mCircleSprite.get("NAME", 0); - this.spriteScale = Parser.getScale(mCircleSprite.get("SCALE", 0), 1); - } else { - this.spriteName = null; - } - } - - public Stereotype(String label, double radius, UFont circledFont, boolean automaticPackageStyle, - HColorSet htmlColorSet) throws NoSuchColorException { - Objects.requireNonNull(label); - if (label.startsWith("<<") == false || label.endsWith(">>") == false) { - throw new IllegalArgumentException(label); - } + private Stereotype(boolean automaticPackageStyle, String label, StereotypeDecoration decoration, double radius, + UFont circledFont) { this.automaticPackageStyle = automaticPackageStyle; this.radius = radius; this.circledFont = circledFont; + this.decoration = decoration; - final StringBuilder tmpLabel = new StringBuilder(); + } - final List list = cutLabels(label, Guillemet.DOUBLE_COMPARATOR); - for (String local : list) { - final RegexResult mCircleChar = circleChar.matcher(local); - final RegexResult mCircleSprite = circleSprite.matcher(local); - if (mCircleSprite != null) { - if (StringUtils.isNotEmpty(mCircleSprite.get("LABEL", 0))) { - local = "<<" + mCircleSprite.get("LABEL", 0) + ">>"; - } else { - local = null; - } - final String colName = mCircleSprite.get("COLOR", 0); - final HColor col = colName == null ? null : htmlColorSet.getColorLEGACY(colName); - this.htmlColor = col == null ? HColorUtils.BLACK : col; - this.spriteName = mCircleSprite.get("NAME", 0); - this.character = '\0'; - this.spriteScale = Parser.getScale(mCircleSprite.get("SCALE", 0), 1); - } else if (mCircleChar != null) { - if (StringUtils.isNotEmpty(mCircleChar.get("LABEL", 0))) { - local = "<<" + mCircleChar.get("LABEL", 0) + ">>"; - } else { - local = null; - } - final String colName = mCircleChar.get("COLOR", 0); - this.htmlColor = colName == null ? null : htmlColorSet.getColorLEGACY(colName); - this.character = mCircleChar.get("CHAR", 0).charAt(0); - this.spriteName = null; - } - if (local != null) { - tmpLabel.append(local); - } - } - if (tmpLabel.length() > 0) { - this.label = tmpLabel.toString(); + private static void checkLabel(String label) { + if (label.startsWith("<<") == false || label.endsWith(">>") == false) { + throw new IllegalArgumentException(label); } } - public Stereotype(String label) { - this(label, true); + public static Stereotype build(String label) { + return build(label, true); + } + + public static Stereotype build(String label, boolean automaticPackageStyle) { + checkLabel(label); + final StereotypeDecoration decoration = StereotypeDecoration.buildSimple(label); + return new Stereotype(automaticPackageStyle, label, decoration, 0, null); + } + + public static Stereotype build(String label, double radius, UFont circledFont, HColorSet htmlColorSet) + throws NoSuchColorException { + checkLabel(label); + final StereotypeDecoration decoration = StereotypeDecoration.buildComplex(label, htmlColorSet); + return new Stereotype(true, label, decoration, radius, circledFont); } public HColor getHtmlColor() { - return htmlColor; + return decoration.htmlColor; } public char getCharacter() { - return character; + return decoration.character; } public final TextBlock getSprite(SpriteContainer container) { - if (spriteName == null || container == null) { + if (decoration.spriteName == null || container == null) { return null; } - final Sprite tmp = container.getSprite(spriteName); + final Sprite tmp = container.getSprite(decoration.spriteName); if (tmp == null) { return null; } - return tmp.asTextBlock(getHtmlColor(), spriteScale); + return tmp.asTextBlock(getHtmlColor(), decoration.spriteScale); } public boolean isWithOOSymbol() { - return "<>".equalsIgnoreCase(label); + return "<>".equalsIgnoreCase(decoration.label); } public List getMultipleLabels() { final List result = new ArrayList<>(); - if (label != null) { - final Pattern p = Pattern.compile("\\<\\<\\s?((?:\\<&\\w+\\>|[^<>])+?)\\s?\\>\\>"); - final Matcher m = p.matcher(label); - while (m.find()) { - result.add(m.group(1)); - } + + final Pattern p = Pattern.compile("\\<\\<\\s?((?:\\<&\\w+\\>|[^<>])+?)\\s?\\>\\>"); + final Matcher m = p.matcher(decoration.label); + while (m.find()) { + result.add(m.group(1)); } + return Collections.unmodifiableList(result); } public boolean isSpotted() { - return character != 0; + return decoration.character != 0; } @Override public String toString() { - if (label == null) { - return "" + character; + if (decoration.character == 0) { + return decoration.label; } - if (character == 0) { - return label; - } - return character + " " + label; + return decoration.character + " " + decoration.label; } public char charAt(int arg0) { @@ -253,14 +162,13 @@ public class Stereotype implements CharSequence { } public String getLabel(Guillemet guillemet) { - assert label == null || label.length() > 0; if (isWithOOSymbol()) { return null; } - if (spriteName != null && spriteName.startsWith("archimate/")) { - return guillemet.manageGuillemet("<<" + spriteName.substring("archimate/".length()) + ">>"); + if (decoration.spriteName != null && decoration.spriteName.startsWith("archimate/")) { + return guillemet.manageGuillemet("<<" + decoration.spriteName.substring("archimate/".length()) + ">>"); } - return guillemet.manageGuillemet(label); + return guillemet.manageGuillemet(decoration.label); } public List getLabels(Guillemet guillemet) { @@ -268,7 +176,7 @@ public class Stereotype implements CharSequence { if (labelLocal == null) { return Collections.emptyList(); } - return cutLabels(labelLocal, guillemet); + return StereotypeDecoration.cutLabels(labelLocal, guillemet); } public List