diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java index 7c70f3da4e7..4f8b8cce4d2 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java @@ -53,6 +53,7 @@ import net.sourceforge.plantuml.decoration.LinkDecor; import net.sourceforge.plantuml.decoration.LinkType; import net.sourceforge.plantuml.descdiagram.command.CommandLinkElement; +import net.sourceforge.plantuml.jaws.Jaws; import net.sourceforge.plantuml.klimt.color.ColorType; import net.sourceforge.plantuml.klimt.color.NoSuchColorException; import net.sourceforge.plantuml.klimt.creole.Display; @@ -140,7 +141,7 @@ protected CommandExecutionResult executeNow(final ActivityDiagram diagram, BlocL urlActivity = extractUrlString(diagram, desc0); if (urlActivity == null) { sb.append(desc0); - sb.append(BackSlash.BS_BS_N); + sb.append(Jaws.BLOCK_E1_NEWLINE); } } int i = 0; @@ -154,21 +155,21 @@ protected CommandExecutionResult executeNow(final ActivityDiagram diagram, BlocL } sb.append(cs.getString()); if (i < lines.size() - 2) - sb.append(BackSlash.BS_BS_N); + sb.append(Jaws.BLOCK_E1_NEWLINE); } final List lineLast = StringUtils.getSplit(MyPattern.cmpile(getPatternEnd()), lines.getLast().getString()); if (StringUtils.isNotEmpty(lineLast.get(0))) { - if (sb.length() > 0 && sb.toString().endsWith(BackSlash.BS_BS_N) == false) - sb.append(BackSlash.BS_BS_N); + if (sb.length() > 0 && sb.toString().endsWith("" + Jaws.BLOCK_E1_NEWLINE) == false) + sb.append(Jaws.BLOCK_E1_NEWLINE); sb.append(lineLast.get(0)); } - final String display = sb.toString(); - final String idShort = lineLast.get(1) == null ? display : lineLast.get(1); + final String displayString = sb.toString(); + final String idShort = lineLast.get(1) == null ? displayString : lineLast.get(1); String partition = null; if (lineLast.get(3) != null) { @@ -183,7 +184,7 @@ protected CommandExecutionResult executeNow(final ActivityDiagram diagram, BlocL Entity entity2 = ident.getData(); if (entity2 == null) - entity2 = diagram.reallyCreateLeaf(ident, Display.getWithNewlines(display), LeafType.ACTIVITY, null); + entity2 = diagram.reallyCreateLeaf(ident, Display.getWithNewlines(displayString), LeafType.ACTIVITY, null); diagram.setLastEntityConsulted(entity2); @@ -216,8 +217,7 @@ protected CommandExecutionResult executeNow(final ActivityDiagram diagram, BlocL type = type.goDotted(); final LinkArg linkArg = LinkArg.build(linkLabel, lenght, diagram.getSkinParam().classAttributeIconSize() > 0); - Link link = new Link(diagram, diagram.getSkinParam().getCurrentStyleBuilder(), entity1, - entity2, type, linkArg); + Link link = new Link(diagram, diagram.getSkinParam().getCurrentStyleBuilder(), entity1, entity2, type, linkArg); final Direction direction = StringUtils.getArrowDirection(arrowBody1 + arrowDirection + arrowBody2 + ">"); if (direction == Direction.LEFT || direction == Direction.UP) link = link.getInv(); diff --git a/src/net/sourceforge/plantuml/eggs/PSystemColors.java b/src/net/sourceforge/plantuml/eggs/PSystemColors.java index 042b7fcf1ea..7de6983c68a 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemColors.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemColors.java @@ -46,6 +46,7 @@ import net.sourceforge.plantuml.PlainDiagram; import net.sourceforge.plantuml.core.DiagramDescription; import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.jaws.JawsStrange; import net.sourceforge.plantuml.klimt.UStroke; import net.sourceforge.plantuml.klimt.UTranslate; import net.sourceforge.plantuml.klimt.color.HColor; @@ -161,6 +162,7 @@ private void drawOneHexa(UGraphic ug, String colorName, int i, int j, UPolygon h tt.drawU(ug.apply(new UTranslate(-dimText.getWidth() / 2, -dimText.getHeight() / 2))); } + @JawsStrange private String findShortest(StringBounder stringBounder, UFont font, String colorName) { String result = null; double min = Double.MAX_VALUE; diff --git a/src/net/sourceforge/plantuml/jaws/JawsStrange.java b/src/net/sourceforge/plantuml/jaws/JawsStrange.java new file mode 100644 index 00000000000..54cad57043c --- /dev/null +++ b/src/net/sourceforge/plantuml/jaws/JawsStrange.java @@ -0,0 +1,13 @@ +package net.sourceforge.plantuml.jaws; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target({ ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE, ElementType.FIELD }) +public @interface JawsStrange { + + String comment() default ""; +} diff --git a/src/net/sourceforge/plantuml/klimt/creole/Display.java b/src/net/sourceforge/plantuml/klimt/creole/Display.java index 0097302b6b5..7d9db77488f 100644 --- a/src/net/sourceforge/plantuml/klimt/creole/Display.java +++ b/src/net/sourceforge/plantuml/klimt/creole/Display.java @@ -46,6 +46,8 @@ import java.util.regex.Pattern; import net.sourceforge.plantuml.abel.Entity; +import net.sourceforge.plantuml.jaws.Jaws; +import net.sourceforge.plantuml.jaws.JawsStrange; import net.sourceforge.plantuml.klimt.LineBreakStrategy; import net.sourceforge.plantuml.klimt.UStroke; import net.sourceforge.plantuml.klimt.color.HColor; @@ -251,6 +253,9 @@ else if (c2 == 'l') current.append(c); current.append(c2); } + } else if (c == Jaws.BLOCK_E1_NEWLINE) { + result.add(current.toString()); + current.setLength(0); } else if (c == BackSlash.hiddenNewLine()) { result.add(current.toString()); current.setLength(0); @@ -619,6 +624,7 @@ public boolean hasSeveralGuideLines() { return hasSeveralGuideLines(displayData); } + @JawsStrange public static boolean hasSeveralGuideLines(String s) { final List splitted = Arrays.asList(s.split("\\\\n")); return hasSeveralGuideLines(splitted); diff --git a/src/net/sourceforge/plantuml/klimt/creole/command/PlainText.java b/src/net/sourceforge/plantuml/klimt/creole/command/PlainText.java index e844fea2326..608c6dae9b9 100644 --- a/src/net/sourceforge/plantuml/klimt/creole/command/PlainText.java +++ b/src/net/sourceforge/plantuml/klimt/creole/command/PlainText.java @@ -41,10 +41,11 @@ public class PlainText implements HtmlCommand { private final String text; - public static final PlainText TEXT_BS_BS_N = new PlainText(BackSlash.BS_BS_N); + // public static final PlainText TEXT_BS_BS_N = new PlainText(BackSlash.BS_BS_N); PlainText(String text) { - this.text = text.replaceAll("\\\\\\[", "[").replaceAll("\\\\\\]", "]"); + // this.text = text.replaceAll("\\\\\\[", "[").replaceAll("\\\\\\]", "]"); + this.text = text; if (text.indexOf(BackSlash.CHAR_NEWLINE) != -1) throw new IllegalArgumentException(); @@ -57,8 +58,4 @@ public String getText() { assert text.length() > 0; return text; } - - public boolean isNewline() { - return text.equals(BackSlash.BS_BS_N); - } } diff --git a/src/net/sourceforge/plantuml/klimt/creole/command/Splitter.java b/src/net/sourceforge/plantuml/klimt/creole/command/Splitter.java index cc614e5e75f..6553799ffb4 100644 --- a/src/net/sourceforge/plantuml/klimt/creole/command/Splitter.java +++ b/src/net/sourceforge/plantuml/klimt/creole/command/Splitter.java @@ -36,13 +36,13 @@ package net.sourceforge.plantuml.klimt.creole.command; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.List; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.emoji.Emoji; +import net.sourceforge.plantuml.jaws.JawsStrange; import net.sourceforge.plantuml.klimt.font.FontStyle; import net.sourceforge.plantuml.klimt.sprite.SpriteUtils; import net.sourceforge.plantuml.regex.Matcher2; @@ -147,34 +147,36 @@ public static String purgeAllTag(String s) { return s.replaceAll(htmlTag, ""); } + @JawsStrange public List getHtmlCommands(boolean newLineAlone) { final HtmlCommandFactory factory = new HtmlCommandFactory(); final List result = new ArrayList<>(); for (String s : getSplittedInternal()) { final HtmlCommand cmd = factory.getHtmlCommand(s); - if (newLineAlone && cmd instanceof PlainText) { - result.addAll(splitText((PlainText) cmd)); - } else { - result.add(cmd); - } +// if (newLineAlone && cmd instanceof PlainText) { +// result.addAll(splitText((PlainText) cmd)); +// } else { + result.add(cmd); +// } } return Collections.unmodifiableList(result); } - private Collection splitText(PlainText cmd) { - String s = cmd.getText(); - final Collection<PlainText> result = new ArrayList<>(); - while (true) { - final int x = s.indexOf(PlainText.TEXT_BS_BS_N.getText()); - if (x == -1) { - result.add(new PlainText(s)); - return result; - } - if (x > 0) { - result.add(new PlainText(s.substring(0, x))); - } - result.add(PlainText.TEXT_BS_BS_N); - s = s.substring(x + 2); - } - } +// @JawsStrange +// private Collection<PlainText> splitText(PlainText cmd) { +// String s = cmd.getText(); +// final Collection<PlainText> result = new ArrayList<>(); +// while (true) { +// final int x = s.indexOf(PlainText.TEXT_BS_BS_N.getText()); +// if (x == -1) { +// result.add(new PlainText(s)); +// return result; +// } +// if (x > 0) { +// result.add(new PlainText(s.substring(0, x))); +// } +// result.add(PlainText.TEXT_BS_BS_N); +// s = s.substring(x + 2); +// } +// } } diff --git a/src/net/sourceforge/plantuml/text/BackSlash.java b/src/net/sourceforge/plantuml/text/BackSlash.java index 4a1d6d92818..82da8bca83f 100644 --- a/src/net/sourceforge/plantuml/text/BackSlash.java +++ b/src/net/sourceforge/plantuml/text/BackSlash.java @@ -40,29 +40,35 @@ import java.util.List; import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.jaws.Jaws; +import net.sourceforge.plantuml.jaws.JawsStrange; public class BackSlash { + @JawsStrange(comment = "Ok because not really used") public static final String BS_BS_N = "\\n"; + public static final String NEWLINE = "\n"; public static final char CHAR_NEWLINE = '\n'; - + public static final String lineSeparator() { return System.lineSeparator(); } + @JawsStrange public static char hiddenNewLine() { - return StringUtils.PRIVATE_BLOCK + BackSlash.CHAR_NEWLINE; + return Jaws.BLOCK_E1_NEWLINE; } + @JawsStrange public static String manageNewLine(String string) { - return string.replace(hiddenNewLine(), BackSlash.CHAR_NEWLINE); + return string; } public static List<String> getWithNewlines(CharSequence s) { - if (s == null) + if (s == null) return null; - + final List<String> result = new ArrayList<>(); final StringBuilder current = new StringBuilder(); for (int i = 0; i < s.length(); i++) { @@ -87,9 +93,9 @@ public static List<String> getWithNewlines(CharSequence s) { } public static String translateBackSlashes(CharSequence s) { - if (s == null) + if (s == null) return null; - + // final String tmps = s.toString(); // if (tmps.indexOf('\\') == -1) { // return tmps; @@ -114,24 +120,24 @@ private static boolean isEnglishLetterOfBackSlash(char c) { } public static String untranslateBackSlashes(CharSequence s) { - if (s == null) + if (s == null) return null; - + final StringBuilder result = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); - if (c > StringUtils.PRIVATE_BLOCK && c < '\uE07F') + if (c > StringUtils.PRIVATE_BLOCK && c < '\uE07F') c = (char) (c - StringUtils.PRIVATE_BLOCK); - + result.append(c); } return result.toString(); } private static char translateChar(char c) { - if (c > 128) + if (c > 128) throw new IllegalArgumentException(); - + return (char) (StringUtils.PRIVATE_BLOCK + c); }