Skip to content

Commit

Permalink
feat: timing set background color of concise
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Feb 27, 2024
1 parent 2a49ef0 commit a0be1ed
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(":"), //
Expand Down
9 changes: 8 additions & 1 deletion src/net/sourceforge/plantuml/timingdiagram/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -75,6 +78,10 @@ public boolean isCompact() {
return compact;
}

public HColor getGeneralBackgroundColor() {
return generalBackgroundColor;
}

protected abstract StyleSignature getStyleSignature();

final protected Style getStyle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class PlayerBinary extends Player {
private final List<TimingNote> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@

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;
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
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;
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 14 additions & 2 deletions src/net/sourceforge/plantuml/timingdiagram/TimingDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@
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;
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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));
}

}
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/version/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a0be1ed

Please sign in to comment.