This commit is contained in:
Arnaud Roques 2022-06-06 14:36:58 +02:00
parent a5952259b7
commit 6e3ba0e4da
15 changed files with 135 additions and 93 deletions

View File

@ -72,15 +72,15 @@ public abstract class CommandMultilines<S extends Diagram> implements Command<S>
if (m1.matches() == false)
return CommandControl.OK_PARTIAL;
actionIfCommandValid();
return CommandControl.OK;
return finalVerification();
}
protected boolean isCommandForbidden() {
return false;
}
protected void actionIfCommandValid() {
protected CommandControl finalVerification() {
return CommandControl.OK;
}
protected final Pattern2 getStartingPattern() {

View File

@ -96,8 +96,7 @@ public abstract class CommandMultilines2<S extends Diagram> implements Command<S
if (m1.matches() == false)
return CommandControl.OK_PARTIAL;
actionIfCommandValid();
return CommandControl.OK;
return finalVerification(lines);
}
public final CommandExecutionResult execute(S system, BlocLines lines) {
@ -118,7 +117,8 @@ public abstract class CommandMultilines2<S extends Diagram> implements Command<S
return false;
}
protected void actionIfCommandValid() {
protected CommandControl finalVerification(BlocLines lines) {
return CommandControl.OK;
}
protected final IRegex getStartingPattern() {

View File

@ -81,8 +81,7 @@ public abstract class CommandMultilines3<S extends Diagram> implements Command<S
if (m1 == false)
return CommandControl.OK_PARTIAL;
actionIfCommandValid();
return CommandControl.OK;
return finalVerification();
}
public final CommandExecutionResult execute(S system, BlocLines lines) {
@ -96,7 +95,8 @@ public abstract class CommandMultilines3<S extends Diagram> implements Command<S
return false;
}
protected void actionIfCommandValid() {
protected CommandControl finalVerification() {
return CommandControl.OK;
}
protected final IRegex getStartingPattern() {

View File

@ -60,7 +60,8 @@ public abstract class CommandMultilinesBracket<S extends Diagram> implements Com
return new String[] { "BRACKET: " + starting.pattern() };
}
protected void actionIfCommandValid() {
protected CommandControl finalVerification() {
return CommandControl.OK;
}
protected final Pattern2 getStartingPattern() {
@ -98,8 +99,7 @@ public abstract class CommandMultilinesBracket<S extends Diagram> implements Com
if (level != 0)
return CommandControl.OK_PARTIAL;
actionIfCommandValid();
return CommandControl.OK;
return finalVerification();
}
protected abstract boolean isLineConsistent(String line, int level);

View File

@ -104,9 +104,9 @@ public abstract class SingleLineCommand2<S extends Diagram> implements Command<S
final boolean result = pattern.match(line2);
if (result)
actionIfCommandValid();
return finalVerification();
return result ? CommandControl.OK : CommandControl.NOT_OK;
return CommandControl.NOT_OK;
}
private CommandControl isValidBracket(BlocLines lines) {
@ -123,7 +123,8 @@ public abstract class SingleLineCommand2<S extends Diagram> implements Command<S
return false;
}
protected void actionIfCommandValid() {
protected CommandControl finalVerification() {
return CommandControl.OK;
}
public final CommandExecutionResult execute(S system, BlocLines lines) {

View File

@ -111,7 +111,7 @@ public class AtomImg extends AbstractAtom implements Atom {
try {
final byte bytes[] = Base64Coder.decode(data);
final String tmp = new String(bytes);
return new AtomImgSvg(new TileImageSvg(tmp));
return new AtomImgSvg(new TileImageSvg(tmp, scale));
} catch (Exception e) {
return AtomTextUtils.createLegacy("ERROR " + e.toString(), fc);
}
@ -137,7 +137,7 @@ public class AtomImg extends AbstractAtom implements Atom {
if (tmp == null)
return AtomTextUtils.createLegacy("(Cannot decode)", fc);
return new AtomImgSvg(new TileImageSvg(tmp));
return new AtomImgSvg(new TileImageSvg(tmp, scale));
}
final BufferedImage read = f.readRasterImageFromFile();
if (read == null) {
@ -186,7 +186,7 @@ public class AtomImg extends AbstractAtom implements Atom {
if (read == null) {
return AtomTextUtils.createLegacy("(Cannot decode SVG: " + text + ")", fc);
}
return new AtomImgSvg(new TileImageSvg(new String(read, UTF_8)));
return new AtomImgSvg(new TileImageSvg(new String(read, UTF_8), scale));
}
// End

View File

@ -132,8 +132,9 @@ public class CreoleParser implements SheetBuilder {
}
};
} else if (cs instanceof Stereotype) {
for (String st : ((Stereotype) cs).getLabels(skinParam.guillemet()))
sheet.add(createStripe(st, context, sheet.getLastStripe(), stereotype));
if (display.showStereotype())
for (String st : ((Stereotype) cs).getLabels(skinParam.guillemet()))
sheet.add(createStripe(st, context, sheet.getLastStripe(), stereotype));
continue;
} else {

View File

@ -77,6 +77,8 @@ import net.sourceforge.plantuml.sequencediagram.MessageNumber;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.Value;
import net.sourceforge.plantuml.style.ValueNull;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.color.HColor;
@ -88,27 +90,24 @@ public class Display implements Iterable<CharSequence> {
private final HorizontalAlignment naturalHorizontalAlignment;
private final boolean isNull;
private final CreoleMode defaultCreoleMode;
private final boolean showStereotype;
public final static Display NULL = new Display(null, null, true, CreoleMode.FULL);
public final static Display NULL = new Display(true, null, null, true, CreoleMode.FULL);
public boolean showStereotype() {
return showStereotype;
}
public Display withoutStereotypeIfNeeded(Style usedStyle) {
if (this == NULL)
return NULL;
final boolean showStereotype = usedStyle.value(PName.ShowStereotype).asBoolean();
if (showStereotype)
final Value showStereotype = usedStyle.value(PName.ShowStereotype);
if (showStereotype instanceof ValueNull || showStereotype.asBoolean())
return this;
final List<CharSequence> copy = new ArrayList<>(displayData);
final Display result = new Display(naturalHorizontalAlignment, isNull, defaultCreoleMode);
for (Iterator<CharSequence> it = copy.iterator(); it.hasNext();) {
final CharSequence cs = it.next();
if (cs instanceof Stereotype && usedStyle.getSignature().match(((Stereotype) cs)))
it.remove();
return new Display(false, this, this.defaultCreoleMode);
}
result.displayData.addAll(copy);
return result;
}
public Stereotype getStereotypeIfAny() {
@ -121,7 +120,7 @@ public class Display implements Iterable<CharSequence> {
}
public Display replaceBackslashT() {
final Display result = new Display(this, defaultCreoleMode);
final Display result = new Display(this.showStereotype, this, defaultCreoleMode);
for (int i = 0; i < result.displayData.size(); i++) {
final CharSequence s = displayData.get(i);
if (s.toString().contains("\\t"))
@ -138,7 +137,7 @@ public class Display implements Iterable<CharSequence> {
newDisplay.add(cs);
}
return new Display(newDisplay, naturalHorizontalAlignment, isNull, defaultCreoleMode);
return new Display(showStereotype, newDisplay, naturalHorizontalAlignment, isNull, defaultCreoleMode);
}
public boolean isWhite() {
@ -147,7 +146,7 @@ public class Display implements Iterable<CharSequence> {
}
public static Display empty() {
return new Display((HorizontalAlignment) null, false, CreoleMode.FULL);
return new Display(true, (HorizontalAlignment) null, false, CreoleMode.FULL);
}
public static Display create(CharSequence... s) {
@ -165,7 +164,7 @@ public class Display implements Iterable<CharSequence> {
}
public static Display create(Collection<? extends CharSequence> other) {
return new Display(other, null, false, CreoleMode.FULL);
return new Display(true, other, null, false, CreoleMode.FULL);
}
public static Display getWithNewlines(Code s) {
@ -221,24 +220,26 @@ public class Display implements Iterable<CharSequence> {
}
}
result.add(current.toString());
return new Display(result, naturalHorizontalAlignment, false, CreoleMode.FULL);
return new Display(true, result, naturalHorizontalAlignment, false, CreoleMode.FULL);
}
private Display(Display other, CreoleMode mode) {
this(other.naturalHorizontalAlignment, other.isNull, mode);
private Display(boolean showStereotype, Display other, CreoleMode mode) {
this(showStereotype, other.naturalHorizontalAlignment, other.isNull, mode);
this.displayData.addAll(other.displayData);
}
private Display(HorizontalAlignment naturalHorizontalAlignment, boolean isNull, CreoleMode defaultCreoleMode) {
private Display(boolean showStereotype, HorizontalAlignment naturalHorizontalAlignment, boolean isNull,
CreoleMode defaultCreoleMode) {
this.showStereotype = showStereotype;
this.defaultCreoleMode = defaultCreoleMode;
this.isNull = isNull;
this.displayData = isNull ? null : new ArrayList<CharSequence>();
this.naturalHorizontalAlignment = isNull ? null : naturalHorizontalAlignment;
}
private Display(Collection<? extends CharSequence> other, HorizontalAlignment naturalHorizontalAlignment,
boolean isNull, CreoleMode defaultCreoleMode) {
this(naturalHorizontalAlignment, isNull, defaultCreoleMode);
private Display(boolean showStereotype, Collection<? extends CharSequence> other,
HorizontalAlignment naturalHorizontalAlignment, boolean isNull, CreoleMode defaultCreoleMode) {
this(showStereotype, naturalHorizontalAlignment, isNull, defaultCreoleMode);
if (isNull == false)
this.displayData.addAll(manageEmbeddedDiagrams(other));
@ -284,7 +285,8 @@ public class Display implements Iterable<CharSequence> {
}
first = false;
}
return new Display(result, this.naturalHorizontalAlignment, this.isNull, this.defaultCreoleMode);
return new Display(showStereotype, result, this.naturalHorizontalAlignment, this.isNull,
this.defaultCreoleMode);
}
public Display withPage(int page, int lastpage) {
@ -297,7 +299,8 @@ public class Display implements Iterable<CharSequence> {
line = line.toString().replace("%lastpage%", "" + lastpage);
result.add(line);
}
return new Display(result, this.naturalHorizontalAlignment, this.isNull, this.defaultCreoleMode);
return new Display(showStereotype, result, this.naturalHorizontalAlignment, this.isNull,
this.defaultCreoleMode);
}
public Display removeEndingStereotype() {
@ -305,7 +308,8 @@ public class Display implements Iterable<CharSequence> {
if (m.matches()) {
final List<CharSequence> result = new ArrayList<>(this.displayData);
result.set(result.size() - 1, m.group(1));
return new Display(result, this.naturalHorizontalAlignment, this.isNull, this.defaultCreoleMode);
return new Display(showStereotype, result, this.naturalHorizontalAlignment, this.isNull,
this.defaultCreoleMode);
}
return this;
}
@ -325,7 +329,8 @@ public class Display implements Iterable<CharSequence> {
for (CharSequence line : displayData)
result.add("<u>" + line);
return new Display(result, this.naturalHorizontalAlignment, this.isNull, this.defaultCreoleMode);
return new Display(showStereotype, result, this.naturalHorizontalAlignment, this.isNull,
this.defaultCreoleMode);
}
public Display underlinedName() {
@ -342,14 +347,15 @@ public class Display implements Iterable<CharSequence> {
result.add("<u>" + line);
}
}
return new Display(result, this.naturalHorizontalAlignment, this.isNull, this.defaultCreoleMode);
return new Display(showStereotype, result, this.naturalHorizontalAlignment, this.isNull,
this.defaultCreoleMode);
}
public Display withCreoleMode(CreoleMode mode) {
if (isNull)
throw new IllegalArgumentException();
return new Display(this, mode);
return new Display(this.showStereotype, this, mode);
}
@Override
@ -371,25 +377,25 @@ public class Display implements Iterable<CharSequence> {
}
public Display addAll(Display other) {
final Display result = new Display(this, this.defaultCreoleMode);
final Display result = new Display(this.showStereotype, this, this.defaultCreoleMode);
result.displayData.addAll(other.displayData);
return result;
}
public Display addFirst(CharSequence s) {
final Display result = new Display(this, this.defaultCreoleMode);
final Display result = new Display(this.showStereotype, this, this.defaultCreoleMode);
result.displayData.add(0, s);
return result;
}
public Display add(CharSequence s) {
final Display result = new Display(this, this.defaultCreoleMode);
final Display result = new Display(this.showStereotype, this, this.defaultCreoleMode);
result.displayData.add(s);
return result;
}
public Display addGeneric(CharSequence s) {
final Display result = new Display(this, this.defaultCreoleMode);
final Display result = new Display(this.showStereotype, this, this.defaultCreoleMode);
final int size = displayData.size();
if (size == 0)
result.displayData.add("<" + s + ">");
@ -415,7 +421,7 @@ public class Display implements Iterable<CharSequence> {
}
public Display subList(int i, int size) {
return new Display(displayData.subList(i, size), this.naturalHorizontalAlignment, this.isNull,
return new Display(showStereotype, displayData.subList(i, size), this.naturalHorizontalAlignment, this.isNull,
this.defaultCreoleMode);
}
@ -448,7 +454,8 @@ public class Display implements Iterable<CharSequence> {
public List<Display> splitMultiline(Pattern2 separator) {
final List<Display> result = new ArrayList<>();
Display pending = new Display(this.naturalHorizontalAlignment, this.isNull, this.defaultCreoleMode);
Display pending = new Display(showStereotype, this.naturalHorizontalAlignment, this.isNull,
this.defaultCreoleMode);
result.add(pending);
for (CharSequence line : displayData) {
final Matcher2 m = separator.matcher(line);
@ -456,7 +463,8 @@ public class Display implements Iterable<CharSequence> {
final CharSequence s1 = line.subSequence(0, m.start());
pending.displayData.add(s1);
final CharSequence s2 = line.subSequence(m.end(), line.length());
pending = new Display(this.naturalHorizontalAlignment, this.isNull, this.defaultCreoleMode);
pending = new Display(showStereotype, this.naturalHorizontalAlignment, this.isNull,
this.defaultCreoleMode);
result.add(pending);
pending.displayData.add(s2);
} else {

View File

@ -63,17 +63,17 @@ public class Img implements HtmlCommand {
static int getVspace(String html) {
final Matcher2 m = vspacePattern.matcher(html);
if (m.find() == false) {
if (m.find() == false)
return 0;
}
return Integer.parseInt(m.group(1));
}
static ImgValign getValign(String html) {
final Matcher2 m = valignPattern.matcher(html);
if (m.find() == false) {
if (m.find() == false)
return ImgValign.TOP;
}
return ImgValign.valueOf(StringUtils.goUpperCase(m.group(1)));
}
@ -99,28 +99,28 @@ public class Img implements HtmlCommand {
// Check if valid URL
if (src.startsWith("http:") || src.startsWith("https:")) {
final SURL tmp = SURL.create(src);
if (tmp == null) {
if (tmp == null)
return new Text("(Cannot decode: " + src + ")");
}
final BufferedImage read = tmp.readRasterImageFromURL();
if (read == null) {
if (read == null)
return new Text("(Cannot decode: " + src + ")");
}
return new Img(new TileImage(read, valign, vspace));
}
return new Text("(Cannot decode: " + f + ")");
}
if (f.getName().endsWith(".svg")) {
final String tmp = FileUtils.readSvg(f);
if (tmp == null) {
if (tmp == null)
return new Text("(Cannot decode: " + f + ")");
}
return new Img(new TileImageSvg(tmp));
return new Img(new TileImageSvg(tmp, 1));
}
final BufferedImage read = f.readRasterImageFromFile();
if (read == null) {
if (read == null)
return new Text("(Cannot decode: " + f + ")");
}
return new Img(new TileImage(f.readRasterImageFromFile(), valign, vspace));
} catch (IOException e) {
e.printStackTrace();

View File

@ -43,9 +43,11 @@ import net.sourceforge.plantuml.ugraphic.UImageSvg;
public class TileImageSvg extends AbstractTextBlock implements TextBlock {
private final UImageSvg svg;
private final double scale;
public TileImageSvg(String svg) {
this.svg = new UImageSvg(svg, 1);
public TileImageSvg(String svg, double scale) {
this.svg = new UImageSvg(svg, scale);
this.scale = scale;
}
public Dimension2D calculateDimension(StringBounder stringBounder) {

View File

@ -39,6 +39,7 @@ import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.StringLocated;
import net.sourceforge.plantuml.UrlBuilder;
import net.sourceforge.plantuml.command.BlocLines;
import net.sourceforge.plantuml.command.CommandControl;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines2;
import net.sourceforge.plantuml.command.MultilinesStrategy;
@ -97,22 +98,46 @@ public class CommandCreateJson extends CommandMultilines2<AbstractClassOrObjectD
if (entity1 == null)
return CommandExecutionResult.error("No such entity");
final JsonValue json = getJsonValue(lines);
if (json == null)
return CommandExecutionResult.error("Bad data");
((BodierJSon) entity1.getBodier()).setJson(json);
return CommandExecutionResult.ok();
}
@Override
protected CommandControl finalVerification(BlocLines lines) {
final JsonValue json = getJsonValue(lines);
if (json == null)
return CommandControl.OK_PARTIAL;
return super.finalVerification(lines);
}
private JsonValue getJsonValue(BlocLines lines) {
try {
final String sb = getJsonString(lines);
final DefaultHandler handler = new DefaultHandler();
new JsonParser(handler).parse(sb);
final JsonValue json = handler.getValue();
return json;
} catch (Exception e) {
return null;
}
}
private String getJsonString(BlocLines lines) {
lines = lines.subExtract(1, 1);
final StringBuilder sb = new StringBuilder("{");
for (StringLocated sl : lines) {
final String line = sl.getString();
assert line.length() > 0;
System.err.println("l=" + line);
sb.append(line);
}
sb.append("}");
final DefaultHandler handler = new DefaultHandler();
new JsonParser(handler).parse(sb.toString());
final JsonValue json = handler.getValue();
((BodierJSon) entity1.getBodier()).setJson(json);
return CommandExecutionResult.ok();
return sb.toString();
}
private IEntity executeArg0(AbstractClassOrObjectDiagram diagram, RegexResult line0) throws NoSuchColorException {

View File

@ -55,8 +55,6 @@ import net.sourceforge.plantuml.ugraphic.color.HColorSet;
public abstract class AbstractTextualComponent extends AbstractComponent {
private final Display display;
private final int marginX1;
private final int marginX2;
private final int marginY;
@ -91,20 +89,18 @@ public abstract class AbstractTextualComponent extends AbstractComponent {
final UFont fontForStereotype = stereo.getUFont();
final HColor htmlColorForStereotype = stereo.value(PName.FontColor).asColor(spriteContainer.getThemeStyle(),
getIHtmlColorSet());
this.display = display.withoutStereotypeIfNeeded(style);
display = display.withoutStereotypeIfNeeded(style);
this.marginX1 = marginX1;
this.marginX2 = marginX2;
this.marginY = marginY;
// this.display = keepStereotype ? display : display.withoutStereotype();
if (this.display.size() == 1 && this.display.get(0).length() == 0)
if (display.size() == 1 && display.get(0).length() == 0)
textBlock = new TextBlockEmpty();
else if (enhanced)
textBlock = BodyFactory.create3(this.display, spriteContainer, horizontalAlignment, fc, maxMessageSize,
style);
textBlock = BodyFactory.create3(display, spriteContainer, horizontalAlignment, fc, maxMessageSize, style);
else
textBlock = this.display.create0(fc, horizontalAlignment, spriteContainer, maxMessageSize, CreoleMode.FULL,
textBlock = display.create0(fc, horizontalAlignment, spriteContainer, maxMessageSize, CreoleMode.FULL,
fontForStereotype, htmlColorForStereotype, marginX1, marginX2);
this.alignment = horizontalAlignment;

View File

@ -210,7 +210,16 @@ public class FromSkinparamToStyle {
addMagic(SName.usecase);
addMagic(SName.map);
addMagic(SName.archimate);
addConvert("IconPrivateColor", PName.LineColor, SName.visibilityIcon, SName.private_);
addConvert("IconPrivateBackgroundColor", PName.BackGroundColor, SName.visibilityIcon, SName.private_);
addConvert("IconPackageColor", PName.LineColor, SName.visibilityIcon, SName.package_);
addConvert("IconPackageBackgroundColor", PName.BackGroundColor, SName.visibilityIcon, SName.package_);
addConvert("IconProtectedColor", PName.LineColor, SName.visibilityIcon, SName.protected_);
addConvert("IconProtectedBackgroundColor", PName.BackGroundColor, SName.visibilityIcon, SName.protected_);
addConvert("IconPublicColor", PName.LineColor, SName.visibilityIcon, SName.public_);
addConvert("IconPublicBackgroundColor", PName.BackGroundColor, SName.visibilityIcon, SName.public_);
// addConvert("nodeStereotypeFontSize", PName.FontSize, SName.node, SName.stereotype);
// addConvert("sequenceStereotypeFontSize", PName.FontSize, SName.stereotype);

View File

@ -128,12 +128,12 @@ public class UImageSvg implements UShape {
throw new IllegalStateException("Cannot find " + name);
}
public int getHeight() {
return this.getData("height");
public double getHeight() {
return this.getData("height") * scale;
}
public int getWidth() {
return this.getData("width");
public double getWidth() {
return this.getData("width") * scale;
}
public double getScale() {

View File

@ -73,7 +73,7 @@ public class UPolygon extends AbstractShadowable {
(pt1.getY() + pt2.getY()) / 2);
final double delta = middle.distance(center);
if (delta < 1)
return all.get((i - 1) % all.size());
return all.get((i + all.size() - 1) % all.size());
}
return null;