diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBoxOld.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBoxOld.java index ff82a7c2f..d87d95cfd 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBoxOld.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBoxOld.java @@ -68,7 +68,6 @@ import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft; import net.sourceforge.plantuml.style.PName; import net.sourceforge.plantuml.style.SName; import net.sourceforge.plantuml.style.Style; -import net.sourceforge.plantuml.style.StyleBuilder; import net.sourceforge.plantuml.style.StyleSignatureBasic; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UStroke; @@ -139,11 +138,8 @@ public class FtileBoxOld extends AbstractFtile { return new FtileBoxOld(skinParam, label, null, BoxStyle.PLAIN, style, styleArrow); } - public static TextBlock createMindMap(StyleBuilder styleBuilder, ISkinParam skinParam, Display label, - StyleSignatureBasic styleDefinition) { - final Style style = styleDefinition.getMergedStyle(styleBuilder); - final Style styleArrow = style; - return new FtileBoxOld(skinParam, label, null, BoxStyle.PLAIN, style, styleArrow); + public static TextBlock createMindMap(Style style, ISkinParam skinParam, Display label) { + return new FtileBoxOld(skinParam, label, null, BoxStyle.PLAIN, style, style); } private FtileBoxOld(ISkinParam skinParam, Display label, Swimlane swimlane, BoxStyle boxStyle, Style style, diff --git a/src/net/sourceforge/plantuml/mindmap/FingerImpl.java b/src/net/sourceforge/plantuml/mindmap/FingerImpl.java index 0496ef5bf..015e46d39 100644 --- a/src/net/sourceforge/plantuml/mindmap/FingerImpl.java +++ b/src/net/sourceforge/plantuml/mindmap/FingerImpl.java @@ -35,7 +35,6 @@ */ package net.sourceforge.plantuml.mindmap; -import net.sourceforge.plantuml.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.List; @@ -44,19 +43,17 @@ import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.SkinParamColors; import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileBoxOld; +import net.sourceforge.plantuml.awt.geom.Dimension2D; import net.sourceforge.plantuml.creole.CreoleMode; -import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.UDrawable; import net.sourceforge.plantuml.graphic.color.ColorType; import net.sourceforge.plantuml.graphic.color.Colors; +import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft; import net.sourceforge.plantuml.style.PName; -import net.sourceforge.plantuml.style.SName; import net.sourceforge.plantuml.style.Style; -import net.sourceforge.plantuml.style.StyleBuilder; -import net.sourceforge.plantuml.style.StyleSignatureBasic; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.UStroke; @@ -65,55 +62,16 @@ import net.sourceforge.plantuml.ugraphic.color.HColor; public class FingerImpl implements Finger, UDrawable { - private final Display label; - private final HColor backColor; - private final String stereotype; + private final Idea idea; private final ISkinParam skinParam; - private final StyleBuilder styleBuilder; - private final IdeaShape shape; private final Direction direction; - private final int level; private boolean drawPhalanx = true; - private double marginLeft = 10; - private double marginRight = 10; - private double marginTop = 10; - private double marginBottom = 10; private final List nail = new ArrayList<>(); private Tetris tetris = null; - private StyleSignatureBasic getDefaultStyleDefinitionNode() { - final String depth = SName.depth(level); - if (level == 0) { - return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.rootNode) - .add(stereotype).add(depth); - } - if (shape == IdeaShape.NONE && nail.size() == 0) { - return StyleSignatureBasic - .of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode, SName.boxless) - .add(stereotype).add(depth); - } - if (shape == IdeaShape.NONE) { - return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.boxless) - .add(stereotype).add(depth); - } - if (nail.size() == 0) { - return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode) - .add(stereotype).add(depth); - } - return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node).add(stereotype) - .add(depth); - } - - public StyleSignatureBasic getDefaultStyleDefinitionArrow() { - final String depth = SName.depth(level); - return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.arrow).add(stereotype) - .add(depth); - } - public static FingerImpl build(Idea idea, ISkinParam skinParam, Direction direction) { - final FingerImpl result = new FingerImpl(idea.getStyleBuilder(), idea.getBackColor(), idea.getLabel(), - skinParam, idea.getShape(), direction, idea.getLevel(), idea.getStereotype()); + final FingerImpl result = new FingerImpl(idea, skinParam, direction); for (Idea child : idea.getChildren()) result.addInNail(build(child, skinParam, direction)); @@ -124,21 +82,14 @@ public class FingerImpl implements Finger, UDrawable { nail.add(child); } - private FingerImpl(StyleBuilder styleBuilder, HColor backColor, Display label, ISkinParam skinParam, - IdeaShape shape, Direction direction, int level, String stereotype) { - this.backColor = backColor; - this.stereotype = stereotype; - this.level = level; - this.label = label; + private FingerImpl(Idea idea, ISkinParam skinParam, Direction direction) { + this.idea = idea; this.skinParam = skinParam; - this.shape = shape; - this.styleBuilder = styleBuilder; this.direction = direction; - final Style styleNode = getDefaultStyleDefinitionNode().getMergedStyle(styleBuilder); - this.marginLeft = styleNode.getMargin().getLeft(); - this.marginRight = styleNode.getMargin().getRight(); - this.marginTop = styleNode.getMargin().getTop(); - this.marginBottom = styleNode.getMargin().getBottom(); + } + + private ClockwiseTopRightBottomLeft getMargin() { + return getStyle().getMargin(); } public void drawU(final UGraphic ug) { @@ -166,12 +117,12 @@ public class FingerImpl implements Finger, UDrawable { } private HColor getLinkColor() { - final Style styleArrow = getDefaultStyleDefinitionArrow().getMergedStyle(styleBuilder); + final Style styleArrow = getStyleArrow(); return styleArrow.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); } private UStroke getUStroke() { - final Style styleArrow = getDefaultStyleDefinitionArrow().getMergedStyle(styleBuilder); + final Style styleArrow = getStyleArrow(); return styleArrow.getStroke(); } @@ -190,7 +141,7 @@ public class FingerImpl implements Finger, UDrawable { private Tetris getTetris(StringBounder stringBounder) { if (tetris == null) { - tetris = new Tetris(label.toString()); + tetris = new Tetris(idea.getLabel().toString()); for (FingerImpl child : nail) tetris.add(child.asSymetricalTee(stringBounder)); @@ -211,11 +162,11 @@ public class FingerImpl implements Finger, UDrawable { } private double getX1() { - return marginLeft; + return getMargin().getLeft(); } private double getX2() { - return marginRight + 30; + return getMargin().getRight() + 30; } public double getX12() { @@ -234,23 +185,37 @@ public class FingerImpl implements Finger, UDrawable { if (drawPhalanx == false) return TextBlockUtils.empty(0, 0); - if (shape == IdeaShape.BOX) { - final ISkinParam foo = new SkinParamColors(skinParam, Colors.empty().add(ColorType.BACK, backColor)); - final TextBlock box = FtileBoxOld.createMindMap(styleBuilder, foo, label, getDefaultStyleDefinitionNode()); - return TextBlockUtils.withMargin(box, 0, 0, marginTop, marginBottom); + final Style style = getStyle(); + + if (idea.getShape() == IdeaShape.BOX) { + final ISkinParam foo = new SkinParamColors(skinParam, + Colors.empty().add(ColorType.BACK, idea.getBackColor())); + final TextBlock box = FtileBoxOld.createMindMap(style, foo, idea.getLabel()); + final ClockwiseTopRightBottomLeft margin = getMargin(); + return TextBlockUtils.withMargin(box, 0, 0, margin.getTop(), margin.getBottom()); } - assert shape == IdeaShape.NONE; - final Style styleNode = getDefaultStyleDefinitionNode().getMergedStyle(styleBuilder); - final TextBlock text = label.create0( - styleNode.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()), - styleNode.getHorizontalAlignment(), skinParam, styleNode.wrapWidth(), CreoleMode.FULL, null, null); + assert idea.getShape() == IdeaShape.NONE; + final TextBlock text = idea.getLabel().create0( + style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()), + style.getHorizontalAlignment(), skinParam, style.wrapWidth(), CreoleMode.FULL, null, null); if (direction == Direction.RIGHT) return TextBlockUtils.withMargin(text, 3, 0, 1, 1); return TextBlockUtils.withMargin(text, 0, 3, 1, 1); } + private Style getStyle() { + if (nail.size() != idea.getChildren().size()) + throw new IllegalStateException(); + + return idea.getStyle(); + } + + private Style getStyleArrow() { + return idea.getStyleArrow(); + } + public double getNailThickness(StringBounder stringBounder) { return getTetris(stringBounder).getHeight(); } diff --git a/src/net/sourceforge/plantuml/mindmap/Idea.java b/src/net/sourceforge/plantuml/mindmap/Idea.java index 39a870fa3..ed2fa3cda 100644 --- a/src/net/sourceforge/plantuml/mindmap/Idea.java +++ b/src/net/sourceforge/plantuml/mindmap/Idea.java @@ -41,8 +41,13 @@ import java.util.Collections; import java.util.List; import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.style.MergeStrategy; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.Style; import net.sourceforge.plantuml.style.StyleBuilder; +import net.sourceforge.plantuml.style.StyleSignatureBasic; import net.sourceforge.plantuml.ugraphic.color.HColor; +import net.sourceforge.plantuml.wbs.WElement; class Idea { @@ -55,6 +60,50 @@ class Idea { private final StyleBuilder styleBuilder; private final String stereotype; + private StyleSignatureBasic getDefaultStyleDefinitionNode(int level) { + final String depth = SName.depth(level); + if (level == 0) { + return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.rootNode) + .add(stereotype).add(depth); + } + if (shape == IdeaShape.NONE && children.size() == 0) { + return StyleSignatureBasic + .of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode, SName.boxless) + .add(stereotype).add(depth); + } + if (shape == IdeaShape.NONE) { + return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.boxless) + .add(stereotype).add(depth); + } + if (children.size() == 0) { + return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node, SName.leafNode) + .add(stereotype).add(depth); + } + return StyleSignatureBasic.of(SName.root, SName.element, SName.mindmapDiagram, SName.node).add(stereotype) + .add(depth); + } + + private static final int STEP_BY_PARENT = WElement.STEP_BY_PARENT; + + public Style getStyle() { + int deltaPriority = STEP_BY_PARENT * 1000; + Style result = styleBuilder.getMergedStyleSpecial(getDefaultStyleDefinitionNode(level), deltaPriority); + for (Idea up = parent; up != null; up = up.parent) { + final StyleSignatureBasic ss = up.getDefaultStyleDefinitionNode(level).addStar(); + deltaPriority -= STEP_BY_PARENT; + final Style styleParent = styleBuilder.getMergedStyleSpecial(ss, deltaPriority); + result = result.mergeWith(styleParent, MergeStrategy.OVERWRITE_EXISTING_VALUE); + } + return result; + } + + public Style getStyleArrow() { + final String depth = SName.depth(level); + final StyleSignatureBasic defaultStyleDefinitionArrow = StyleSignatureBasic + .of(SName.root, SName.element, SName.mindmapDiagram, SName.arrow).add(stereotype).add(depth); + return defaultStyleDefinitionArrow.getMergedStyle(styleBuilder); + } + public static Idea createIdeaSimple(StyleBuilder styleBuilder, HColor backColor, Display label, IdeaShape shape, String stereotype) { return new Idea(styleBuilder, backColor, 0, null, label, shape, stereotype); diff --git a/src/net/sourceforge/plantuml/style/StyleSignatureBasic.java b/src/net/sourceforge/plantuml/style/StyleSignatureBasic.java index e05642b96..de697cd15 100644 --- a/src/net/sourceforge/plantuml/style/StyleSignatureBasic.java +++ b/src/net/sourceforge/plantuml/style/StyleSignatureBasic.java @@ -132,20 +132,45 @@ public class StyleSignatureBasic implements StyleSignature { } public boolean matchAll(StyleSignatureBasic other) { - if (other.isStarred() && names.contains("*") == false) + final boolean namesContainsStar = names.contains("*"); + if (other.isStarred() && namesContainsStar == false) return false; + final int depthInNames = depthFromTokens(other.names); + for (String token : names) { if (token.equals("*")) continue; - if (other.names.contains(token) == false) - return false; + if (namesContainsStar && depthInNames != -1 && depthFromToken(token) != -1) { + // depth comparaison + if (depthInNames < depthFromToken(token)) + return false; + } else { + if (other.names.contains(token) == false) + return false; + } } return true; } + private static int depthFromToken(String token) { + if (token.startsWith("depth(")) + return Integer.parseInt(token.substring("depth(".length(), token.length() - 1)); + return -1; + } + + private static int depthFromTokens(Collection tokens) { + for (String token : tokens) { + final int depth = depthFromToken(token); + if (depth != -1) + return depth; + } + return -1; + + } + public final Set getNames() { return Collections.unmodifiableSet(names); } @@ -159,7 +184,7 @@ public class StyleSignatureBasic implements StyleSignature { } public StyleSignature forStereotypeItself(Stereotype stereotype) { - if (stereotype == null || stereotype.getStyleNames().size()==0) + if (stereotype == null || stereotype.getStyleNames().size() == 0) return this; final StyleSignatures result = new StyleSignatures(); @@ -175,7 +200,7 @@ public class StyleSignatureBasic implements StyleSignature { @Override public StyleSignature withTOBECHANGED(Stereotype stereotype) { - if (stereotype == null || stereotype.getStyleNames().size()==0) + if (stereotype == null || stereotype.getStyleNames().size() == 0) return this; final StyleSignatures result = new StyleSignatures(); diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 6abbcaaf0..b62f4aedb 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -80,7 +80,7 @@ public class Version { } public static int beta() { - final int beta = 5; + final int beta = 6; return beta; } diff --git a/src/net/sourceforge/plantuml/wbs/CommandWBSItem.java b/src/net/sourceforge/plantuml/wbs/CommandWBSItem.java index c0fd9ab11..0d196a9a2 100644 --- a/src/net/sourceforge/plantuml/wbs/CommandWBSItem.java +++ b/src/net/sourceforge/plantuml/wbs/CommandWBSItem.java @@ -71,18 +71,16 @@ public class CommandWBSItem extends SingleLineCommand2 { final String label = arg.get("LABEL", 0); final String stringColor = arg.get("BACKCOLOR", 0); HColor backColor = null; - if (stringColor != null) { + if (stringColor != null) backColor = diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), stringColor); - } Direction dir = type.contains("-") ? Direction.LEFT : Direction.RIGHT; final String direction = arg.get("DIRECTION", 0); - if ("<".equals(direction)) { + if ("<".equals(direction)) dir = Direction.LEFT; - } else if (">".equals(direction)) { + else if (">".equals(direction)) dir = Direction.RIGHT; - } return diagram.addIdea(backColor, diagram.getSmartLevel(type), label, dir, IdeaShape.fromDesc(arg.get("SHAPE", 0))); diff --git a/src/net/sourceforge/plantuml/wbs/WBSDiagram.java b/src/net/sourceforge/plantuml/wbs/WBSDiagram.java index 76842c532..9fbfc1fb0 100644 --- a/src/net/sourceforge/plantuml/wbs/WBSDiagram.java +++ b/src/net/sourceforge/plantuml/wbs/WBSDiagram.java @@ -35,7 +35,6 @@ */ package net.sourceforge.plantuml.wbs; -import net.sourceforge.plantuml.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.OutputStream; @@ -45,6 +44,7 @@ import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.UmlDiagram; import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.api.ThemeStyle; +import net.sourceforge.plantuml.awt.geom.Dimension2D; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.regex.Matcher2; import net.sourceforge.plantuml.command.regex.MyPattern; @@ -134,9 +134,9 @@ public class WBSDiagram extends UmlDiagram { Direction direction, IdeaShape shape) { try { if (level == 0) { - if (root != null) { + if (root != null) return CommandExecutionResult.error("Error 44"); - } + initRoot(backColor, display, stereotype, shape); return CommandExecutionResult.ok(); } @@ -158,9 +158,9 @@ public class WBSDiagram extends UmlDiagram { private WElement getParentOfLast(int nb) { WElement result = last; - for (int i = 0; i < nb; i++) { + for (int i = 0; i < nb; i++) result = result.getParent(); - } + return result; } @@ -171,18 +171,18 @@ public class WBSDiagram extends UmlDiagram { return 0; } type = type.replace('\t', ' '); - if (type.contains(" ") == false) { + if (type.contains(" ") == false) return type.length() - 1; - } - if (type.endsWith(first)) { + + if (type.endsWith(first)) return type.length() - first.length(); - } - if (type.trim().length() == 1) { + + if (type.trim().length() == 1) return type.length() - 1; - } - if (type.startsWith(first)) { + + if (type.startsWith(first)) return type.length() - first.length(); - } + throw new UnsupportedOperationException("type=<" + type + ">[" + first + "]"); } diff --git a/src/net/sourceforge/plantuml/wbs/WElement.java b/src/net/sourceforge/plantuml/wbs/WElement.java index 5dd9b7ba8..6a0804f5c 100644 --- a/src/net/sourceforge/plantuml/wbs/WElement.java +++ b/src/net/sourceforge/plantuml/wbs/WElement.java @@ -54,7 +54,7 @@ import net.sourceforge.plantuml.style.StyleBuilder; import net.sourceforge.plantuml.style.StyleSignatureBasic; import net.sourceforge.plantuml.ugraphic.color.HColor; -final class WElement { +final public class WElement { private final HColor backColor; private final Display label; @@ -95,7 +95,7 @@ final class WElement { return new SkinParamColors(skinParam, Colors.empty().add(ColorType.BACK, backColor)); } - private static final int STEP_BY_PARENT = 1000_1000; + public static final int STEP_BY_PARENT = 1000_1000; public Style getStyle() { int deltaPriority = STEP_BY_PARENT * 1000;