From a0be1ed677c45b3f21ba7aebd8173789df1f6bd4 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Tue, 27 Feb 2024 20:39:02 +0100 Subject: [PATCH] feat: timing set background color of concise https://forum.plantuml.net/18682/timing-set-background-color-of-concise https://forum.plantuml.net/18676/supporting-markdown-syntax --- gradle.properties | 2 +- .../command/CommandCreateClassMultilines.java | 10 ++++++++-- .../mindmap/CommandMindMapDirection.java | 6 +++--- .../mindmap/CommandMindMapOrgmode.java | 2 +- .../CommandMindMapOrgmodeMultiline.java | 2 +- .../plantuml/timingdiagram/Player.java | 9 ++++++++- .../plantuml/timingdiagram/PlayerAnalog.java | 2 +- .../plantuml/timingdiagram/PlayerBinary.java | 2 +- .../plantuml/timingdiagram/PlayerClock.java | 2 +- .../timingdiagram/PlayerRobustConcise.java | 6 ++++-- .../plantuml/timingdiagram/TimingDiagram.java | 16 ++++++++++++++-- .../command/CommandRobustConcise.java | 19 +++++++++++++++++-- .../sourceforge/plantuml/version/Version.java | 2 +- 13 files changed, 61 insertions(+), 19 deletions(-) diff --git a/gradle.properties b/gradle.properties index ddbe9ba1daf..4b0a7467348 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ # Warning, "version" should be the same in gradle.properties and Version.java # Any idea anyone how to magically synchronize those :-) ? -version = 1.2024.4beta5 +version = 1.2024.4beta6 org.gradle.workers.max = 3 \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java index dc171999047..ac36c36852d 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java @@ -127,10 +127,16 @@ private static IRegex getRegexConcat() { new RegexLeaf("LINECOLOR", "(?:\\[(dotted|dashed|bold)\\])?(\\w+)?"))), // new RegexOptional(new RegexConcat(RegexLeaf.spaceOneOrMore(), new RegexLeaf("EXTENDS", - "(extends)[%s]+(" + CommandCreateClassMultilines.CODES + "|[%g]([^%g]+)[%g])"))), // + "(extends)[%s]+(" + CommandCreateClassMultilines.CODES + "|[%g]([^%g]+)[%g])"), + new RegexOptional(new RegexConcat(RegexLeaf.spaceZeroOrMore(), + new RegexLeaf("\\<(" + GenericRegexProducer.PATTERN + ")\\>"))) // + )), // new RegexOptional(new RegexConcat(RegexLeaf.spaceOneOrMore(), new RegexLeaf("IMPLEMENTS", - "(implements)[%s]+(" + CommandCreateClassMultilines.CODES + "|[%g]([^%g]+)[%g])"))), // + "(implements)[%s]+(" + CommandCreateClassMultilines.CODES + "|[%g]([^%g]+)[%g])"), + new RegexOptional(new RegexConcat(RegexLeaf.spaceZeroOrMore(), + new RegexLeaf("\\<(" + GenericRegexProducer.PATTERN + ")\\>"))) // + )), // RegexLeaf.spaceZeroOrMore(), // new RegexLeaf("\\{"), // RegexLeaf.spaceZeroOrMore(), // diff --git a/src/net/sourceforge/plantuml/mindmap/CommandMindMapDirection.java b/src/net/sourceforge/plantuml/mindmap/CommandMindMapDirection.java index 27f658495cf..d23e8f8ea03 100644 --- a/src/net/sourceforge/plantuml/mindmap/CommandMindMapDirection.java +++ b/src/net/sourceforge/plantuml/mindmap/CommandMindMapDirection.java @@ -53,13 +53,13 @@ public CommandMindMapDirection() { static IRegex getRegexConcat() { return RegexConcat.build(CommandMindMapDirection.class.getName(), RegexLeaf.start(), // - new RegexLeaf("[^*]*"), // + new RegexLeaf("[^*#]*"), // new RegexLeaf("\\b"), // new RegexLeaf("DIRECTION", "(left|right|top|bottom)"), // new RegexLeaf("\\b"), // - new RegexLeaf("[^*]*"), // + new RegexLeaf("[^*#]*"), // new RegexLeaf("(side|direction)"), // - new RegexLeaf("[^*]*"), // + new RegexLeaf("[^*#]*"), // RegexLeaf.end()); } diff --git a/src/net/sourceforge/plantuml/mindmap/CommandMindMapOrgmode.java b/src/net/sourceforge/plantuml/mindmap/CommandMindMapOrgmode.java index 8c53a685351..e462044745c 100644 --- a/src/net/sourceforge/plantuml/mindmap/CommandMindMapOrgmode.java +++ b/src/net/sourceforge/plantuml/mindmap/CommandMindMapOrgmode.java @@ -55,7 +55,7 @@ public CommandMindMapOrgmode() { static IRegex getRegexConcat() { return RegexConcat.build(CommandMindMapOrgmode.class.getName(), RegexLeaf.start(), // - new RegexLeaf("TYPE", "([ \t]*\\*+)"), // + new RegexLeaf("TYPE", "([ \t]*[*#]+)"), // new RegexOptional(new RegexLeaf("BACKCOLOR", "\\[(#\\w+)\\]")), // new RegexLeaf("SHAPE", "(_)?"), // RegexLeaf.spaceOneOrMore(), // diff --git a/src/net/sourceforge/plantuml/mindmap/CommandMindMapOrgmodeMultiline.java b/src/net/sourceforge/plantuml/mindmap/CommandMindMapOrgmodeMultiline.java index 79fd1936a43..7d03529bcf5 100644 --- a/src/net/sourceforge/plantuml/mindmap/CommandMindMapOrgmodeMultiline.java +++ b/src/net/sourceforge/plantuml/mindmap/CommandMindMapOrgmodeMultiline.java @@ -60,7 +60,7 @@ public CommandMindMapOrgmodeMultiline() { static IRegex getRegexConcat() { return RegexConcat.build(CommandMindMapOrgmodeMultiline.class.getName(), RegexLeaf.start(), // - new RegexLeaf("TYPE", "(\\*+)"), // + new RegexLeaf("TYPE", "([*#]+)"), // new RegexOptional(new RegexLeaf("BACKCOLOR", "\\[(#\\w+)\\]")), // new RegexLeaf("SHAPE", "(_)?"), // new RegexLeaf(":"), // diff --git a/src/net/sourceforge/plantuml/timingdiagram/Player.java b/src/net/sourceforge/plantuml/timingdiagram/Player.java index 7216c830d3e..3b271bdc391 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/Player.java +++ b/src/net/sourceforge/plantuml/timingdiagram/Player.java @@ -62,8 +62,11 @@ public abstract class Player implements TimeProjected { private final Display title; protected int suggestedHeight; protected final Stereotype stereotype; + private final HColor generalBackgroundColor; - public Player(String title, ISkinParam skinParam, TimingRuler ruler, boolean compact, Stereotype stereotype) { + public Player(String title, ISkinParam skinParam, TimingRuler ruler, boolean compact, Stereotype stereotype, + HColor generalBackgroundColor) { + this.generalBackgroundColor = generalBackgroundColor; this.stereotype = stereotype; this.skinParam = skinParam; this.compact = compact; @@ -75,6 +78,10 @@ public boolean isCompact() { return compact; } + public HColor getGeneralBackgroundColor() { + return generalBackgroundColor; + } + protected abstract StyleSignature getStyleSignature(); final protected Style getStyle() { diff --git a/src/net/sourceforge/plantuml/timingdiagram/PlayerAnalog.java b/src/net/sourceforge/plantuml/timingdiagram/PlayerAnalog.java index 88d37427a5f..874002e4408 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/PlayerAnalog.java +++ b/src/net/sourceforge/plantuml/timingdiagram/PlayerAnalog.java @@ -76,7 +76,7 @@ public class PlayerAnalog extends Player { private Integer ticksEvery; public PlayerAnalog(String code, ISkinParam skinParam, TimingRuler ruler, boolean compact, Stereotype stereotype) { - super(code, skinParam, ruler, compact, stereotype); + super(code, skinParam, ruler, compact, stereotype, null); this.suggestedHeight = 100; } diff --git a/src/net/sourceforge/plantuml/timingdiagram/PlayerBinary.java b/src/net/sourceforge/plantuml/timingdiagram/PlayerBinary.java index c34f5d48627..feb26832c42 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/PlayerBinary.java +++ b/src/net/sourceforge/plantuml/timingdiagram/PlayerBinary.java @@ -76,7 +76,7 @@ public class PlayerBinary extends Player { private final List notes = new ArrayList<>(); public PlayerBinary(String code, ISkinParam skinParam, TimingRuler ruler, boolean compact, Stereotype stereotype) { - super(code, skinParam, ruler, compact, stereotype); + super(code, skinParam, ruler, compact, stereotype, null); this.suggestedHeight = 30; } diff --git a/src/net/sourceforge/plantuml/timingdiagram/PlayerClock.java b/src/net/sourceforge/plantuml/timingdiagram/PlayerClock.java index ac5a3188055..134e67620f8 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/PlayerClock.java +++ b/src/net/sourceforge/plantuml/timingdiagram/PlayerClock.java @@ -65,7 +65,7 @@ public class PlayerClock extends Player { public PlayerClock(String title, ISkinParam skinParam, TimingRuler ruler, int period, int pulse, int offset, boolean compact) { - super(title, skinParam, ruler, compact, null); + super(title, skinParam, ruler, compact, null, null); this.displayTitle = title.length() > 0; this.period = period; this.pulse = pulse; diff --git a/src/net/sourceforge/plantuml/timingdiagram/PlayerRobustConcise.java b/src/net/sourceforge/plantuml/timingdiagram/PlayerRobustConcise.java index 194e9dfe3ea..3f97badd174 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/PlayerRobustConcise.java +++ b/src/net/sourceforge/plantuml/timingdiagram/PlayerRobustConcise.java @@ -43,6 +43,7 @@ import net.sourceforge.plantuml.klimt.UTranslate; import net.sourceforge.plantuml.klimt.color.Colors; +import net.sourceforge.plantuml.klimt.color.HColor; import net.sourceforge.plantuml.klimt.creole.Display; import net.sourceforge.plantuml.klimt.drawing.UGraphic; import net.sourceforge.plantuml.klimt.font.StringBounder; @@ -50,6 +51,7 @@ import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock; import net.sourceforge.plantuml.klimt.shape.TextBlock; import net.sourceforge.plantuml.klimt.shape.UDrawable; +import net.sourceforge.plantuml.klimt.shape.URectangle; import net.sourceforge.plantuml.skin.ArrowConfiguration; import net.sourceforge.plantuml.stereo.Stereotype; import net.sourceforge.plantuml.style.ISkinParam; @@ -77,8 +79,8 @@ public final class PlayerRobustConcise extends Player { private Colors initialColors; public PlayerRobustConcise(TimingStyle type, String full, ISkinParam skinParam, TimingRuler ruler, boolean compact, - Stereotype stereotype) { - super(full, skinParam, ruler, compact, stereotype); + Stereotype stereotype, HColor generalBackgroundColor) { + super(full, skinParam, ruler, compact, stereotype, generalBackgroundColor); this.type = type; this.suggestedHeight = 0; } diff --git a/src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java b/src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java index 03d10d12785..4edc5cd04d3 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java +++ b/src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java @@ -55,6 +55,7 @@ import net.sourceforge.plantuml.klimt.UTranslate; import net.sourceforge.plantuml.klimt.color.Colors; import net.sourceforge.plantuml.klimt.color.HColor; +import net.sourceforge.plantuml.klimt.color.HColors; import net.sourceforge.plantuml.klimt.creole.Display; import net.sourceforge.plantuml.klimt.drawing.UGraphic; import net.sourceforge.plantuml.klimt.font.StringBounder; @@ -62,6 +63,7 @@ import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock; import net.sourceforge.plantuml.klimt.shape.TextBlock; import net.sourceforge.plantuml.klimt.shape.ULine; +import net.sourceforge.plantuml.klimt.shape.URectangle; import net.sourceforge.plantuml.skin.UmlDiagramType; import net.sourceforge.plantuml.stereo.Stereotype; import net.sourceforge.plantuml.style.PName; @@ -133,6 +135,15 @@ private void drawInternal(UGraphic ug) { ruler.ensureNotEmpty(); final StringBounder stringBounder = ug.getStringBounder(); final double part1MaxWidth = getPart1MaxWidth(stringBounder); + + for (Player player : players.values()) { + final UGraphic ugPlayer = ug.apply(getUTranslateForPlayer(player, stringBounder)); + final HColor generalBackgroundColor = player.getGeneralBackgroundColor(); + if (generalBackgroundColor != null) + ugPlayer.apply(generalBackgroundColor).apply(generalBackgroundColor.bg()) + .draw(URectangle.build(getWidthTotal(stringBounder), player.getFullHeight(stringBounder))); + } + final UTranslate widthPart1 = UTranslate.dx(part1MaxWidth); if (compactByDefault == false) drawBorder(ug); @@ -146,6 +157,7 @@ private void drawInternal(UGraphic ug) { for (Player player : players.values()) { final UGraphic ugPlayer = ug.apply(getUTranslateForPlayer(player, stringBounder)); final double caption = getHeightForCaptions(stringBounder); + if (first) { if (player.isCompact() == false) drawHorizontalSeparator(ugPlayer); @@ -279,9 +291,9 @@ private UTranslate getUTranslateForPlayer(Player candidat, StringBounder stringB } public CommandExecutionResult createRobustConcise(String code, String full, TimingStyle type, boolean compact, - Stereotype stereotype) { + Stereotype stereotype, HColor backColor) { final Player player = new PlayerRobustConcise(type, full, getSkinParam(), ruler, compactByDefault || compact, - stereotype); + stereotype, backColor); players.put(code, player); lastPlayer = player; return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/timingdiagram/command/CommandRobustConcise.java b/src/net/sourceforge/plantuml/timingdiagram/command/CommandRobustConcise.java index 51716350c3f..159ad26ff53 100644 --- a/src/net/sourceforge/plantuml/timingdiagram/command/CommandRobustConcise.java +++ b/src/net/sourceforge/plantuml/timingdiagram/command/CommandRobustConcise.java @@ -37,10 +37,15 @@ import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.klimt.color.ColorParser; +import net.sourceforge.plantuml.klimt.color.ColorType; +import net.sourceforge.plantuml.klimt.color.Colors; +import net.sourceforge.plantuml.klimt.color.NoSuchColorException; import net.sourceforge.plantuml.regex.IRegex; import net.sourceforge.plantuml.regex.RegexConcat; import net.sourceforge.plantuml.regex.RegexLeaf; import net.sourceforge.plantuml.regex.RegexOptional; +import net.sourceforge.plantuml.regex.RegexOr; import net.sourceforge.plantuml.regex.RegexResult; import net.sourceforge.plantuml.stereo.Stereotype; import net.sourceforge.plantuml.stereo.StereotypePattern; @@ -70,11 +75,18 @@ private static IRegex getRegexConcat() { RegexLeaf.spaceOneOrMore())), // new RegexLeaf("CODE", "([%pLN_.@]+)"), // StereotypePattern.optional("STEREOTYPE2"), // + RegexLeaf.spaceZeroOrMore(), // + new RegexOr(color().getRegex()), // RegexLeaf.end()); } + private static ColorParser color() { + return ColorParser.simpleColor(ColorType.BACK); + } + @Override - final protected CommandExecutionResult executeArg(TimingDiagram diagram, LineLocation location, RegexResult arg) { + final protected CommandExecutionResult executeArg(TimingDiagram diagram, LineLocation location, RegexResult arg) + throws NoSuchColorException { final String compact = arg.get("COMPACT", 0); final String code = arg.get("CODE", 0); String full = arg.get("FULL", 0); @@ -88,7 +100,10 @@ else if (arg.get("STEREOTYPE2", 0) != null) stereotype = Stereotype.build(arg.get("STEREOTYPE2", 0)); final TimingStyle type = TimingStyle.valueOf(arg.get("TYPE", 0).toUpperCase()); - return diagram.createRobustConcise(code, full, type, compact != null, stereotype); + final Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()); + + return diagram.createRobustConcise(code, full, type, compact != null, stereotype, + colors.getColor(ColorType.BACK)); } } diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 61bcf79714f..700fba39c01 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -46,7 +46,7 @@ public class Version { // Warning, "version" should be the same in gradle.properties and Version.java // Any idea anyone how to magically synchronize those :-) ? - private static final String version = "1.2024.4beta5"; + private static final String version = "1.2024.4beta6"; public static String versionString() { return version;