From 24bd088e01d848394bd232eee46506dad280d445 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Fri, 7 Jan 2022 19:04:36 +0100 Subject: [PATCH] Emoji color fix --- src/net/sourceforge/plantuml/Splash.java | 4 +- .../ftile/CollisionDetector.java | 2 +- .../plantuml/activitydiagram3/ftile/Zad.java | 2 +- src/net/sourceforge/plantuml/emoji/Emoji.java | 66 +++- .../sourceforge/plantuml/emoji/EmojiTmp.java | 364 ------------------ .../plantuml/sequencediagram/Doll.java | 207 +++++----- .../sequencediagram/DollAbstract.java | 98 ----- .../sequencediagram/ParticipantEnglober.java | 16 +- .../sequencediagram/SequenceDiagram.java | 4 +- .../teoz/CommunicationTile.java | 2 +- .../plantuml/sequencediagram/teoz/Dolls.java | 97 ++--- .../sequencediagram/teoz/LifeEventTile.java | 2 +- .../sequencediagram/teoz/LivingSpace.java | 25 +- .../sequencediagram/teoz/LivingSpaces.java | 6 +- .../sequencediagram/teoz/NoteTile.java | 4 +- .../sequencediagram/teoz/ReferenceTile.java | 2 +- .../plantuml/sprite/SpriteColor.java | 12 +- .../plantuml/sprite/SpriteColorBuilder.java | 2 +- .../plantuml/sprite/SpriteGrayLevel.java | 18 +- .../plantuml/sprite/SpriteMonochrome.java | 36 +- .../sourceforge/plantuml/ugraphic/MinMax.java | 2 +- .../plantuml/ugraphic/PixelImage.java | 4 +- .../color/ColorChangerMonochrome.java | 11 +- .../plantuml/ugraphic/color/ColorUtils.java | 4 +- .../plantuml/ugraphic/color/HColorSimple.java | 12 +- .../sourceforge/plantuml/version/Version.java | 2 +- 26 files changed, 294 insertions(+), 710 deletions(-) delete mode 100644 src/net/sourceforge/plantuml/emoji/EmojiTmp.java delete mode 100644 src/net/sourceforge/plantuml/sequencediagram/DollAbstract.java diff --git a/src/net/sourceforge/plantuml/Splash.java b/src/net/sourceforge/plantuml/Splash.java index e1d5701e3..e5f1a4150 100644 --- a/src/net/sourceforge/plantuml/Splash.java +++ b/src/net/sourceforge/plantuml/Splash.java @@ -212,8 +212,8 @@ public class Splash extends Window implements MouseListener, MouseMotionListener final int y = 33; final int barWidth = 170; final int barHeight = (int) (rect.getHeight() + 2); - final int grey = 230; - g.setColor(new Color(grey, grey, grey)); + final int gray = 230; + g.setColor(new Color(gray, gray, gray)); final int value = barWidth * intValue / totalValue; g.fillRect(x, y, value, barHeight); g.setColor(Color.BLACK); diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/CollisionDetector.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/CollisionDetector.java index d002184d2..f048dd417 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/CollisionDetector.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/CollisionDetector.java @@ -91,7 +91,7 @@ public class CollisionDetector extends UGraphicNo { public void drawDebug(UGraphic ug) { for (MinMax minmax : rectangles) { if (collision(minmax)) { - minmax.drawGrey(ug); + minmax.drawGray(ug); } } final HColor color = HColorUtils.BLACK; diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Zad.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Zad.java index 89cabfc25..f63d13ed1 100644 --- a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Zad.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Zad.java @@ -56,7 +56,7 @@ public class Zad { ug = ug.apply(HColorUtils.BLUE.bg()).apply(HColorUtils.RED_LIGHT); for (MinMax minMax : rectangles) { System.err.println("minmax=" + minMax); - minMax.drawGrey(ug); + minMax.drawGray(ug); } } diff --git a/src/net/sourceforge/plantuml/emoji/Emoji.java b/src/net/sourceforge/plantuml/emoji/Emoji.java index cd6520a52..919c45482 100644 --- a/src/net/sourceforge/plantuml/emoji/Emoji.java +++ b/src/net/sourceforge/plantuml/emoji/Emoji.java @@ -1,5 +1,6 @@ package net.sourceforge.plantuml.emoji; +import java.awt.Color; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -19,6 +20,7 @@ import net.sourceforge.plantuml.ugraphic.UEllipse; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UTranslate; +import net.sourceforge.plantuml.ugraphic.color.ColorChangerMonochrome; import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColorNone; import net.sourceforge.plantuml.ugraphic.color.HColorSet; @@ -48,6 +50,8 @@ public class Emoji { } private final List data = new ArrayList<>(); + private int minGray = 999; + private int maxGray = -1; private final String unicode; private final String shortcut; @@ -116,6 +120,12 @@ public class Emoji { e.printStackTrace(); } UGraphicWithScale ugs = new UGraphicWithScale(ug, scale); + + synchronized (this) { + if (colorForMonochrome != null && maxGray == -1) + computeMinMaxGray(); + } + final List stack = new ArrayList<>(); for (String s : data) { if (s.contains("")) { + // Nothing + } else if (s.contains("")) { + // Nothing + } else if (s.contains(" ALL = new HashMap<>(); - - static { - final InputStream is = Dummy.class.getResourceAsStream("emoji.txt"); - try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { - String s = null; - while ((s = br.readLine()) != null) { - new EmojiTmp(s); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static Map getAll() { - return Collections.unmodifiableMap(new TreeMap<>(ALL)); - } - - private final List data = new ArrayList<>(); - private final String unicode; - private final String shortcut; - - private EmojiTmp(String unicode) { - final int x = unicode.indexOf(';'); - if (x == -1) { - this.shortcut = null; - } else { - this.shortcut = unicode.substring(x + 1); - ALL.put(this.shortcut, this); - unicode = unicode.substring(0, x); - } - this.unicode = unicode; - ALL.put(unicode, this); - } - - public static String pattern() { - final StringBuilder sb = new StringBuilder("\\<(#\\w+)?:("); - for (String s : ALL.keySet()) { - if (sb.toString().endsWith("(") == false) - sb.append("|"); - sb.append(s); - } - sb.append("):\\>"); - return sb.toString(); - } - - public static EmojiTmp retrieve(String name) { - return ALL.get(name.toLowerCase()); - } - - private String extractData(String name, String s) { - final Pattern p = Pattern.compile(name + "=\"([^\"]+)\""); - final Matcher m = p.matcher(s); - if (m.find()) - return m.group(1); - - return null; - } - - private synchronized void loadIfNeed() throws IOException { - if (data.size() > 0) - return; - - try (BufferedReader br = new BufferedReader( - new InputStreamReader(Dummy.class.getResourceAsStream(unicode + ".svg")))) { - final String singleLine = br.readLine(); - - final Pattern p = Pattern.compile("\\<[^<>]+\\>"); - final Matcher m = p.matcher(singleLine); - while (m.find()) { - final String s = m.group(0); - if (s.contains("") || s.contains("") - || s.contains("")) { - ugs = stack.remove(0); - } else if (s.contains("")) { - stack.add(0, ugs); - } else if (s.contains(" participants = new ArrayList<>(); - private final List leafs = new ArrayList<>(); - - final private Real core1; - final private Real core2; - private double marginX = 0; - - public static Doll createGroup(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, - boolean isTeoz) { - return new Doll(englober, tileArguments, styleBuilder, isTeoz); - } + final private ParticipantEnglober englober; + final private StyleBuilder styleBuilder; + final private TileArguments tileArguments; public static Doll createPuma(ParticipantEnglober englober, Participant first, ISkinParam skinParam, Rose skin, StringBounder stringBounder, StyleBuilder styleBuilder) { - return new Doll(englober, convertFunctionToBeRemoved(skinParam, skin, stringBounder), styleBuilder, false, - first); + return new Doll(englober, convertFunctionToBeRemoved(skinParam, skin, stringBounder), styleBuilder, first); } - public static Doll createTeoz(ParticipantEnglober englober, Participant first, TileArguments tileArguments, - StyleBuilder styleBuilder) { - final Doll result = new Doll(englober, tileArguments, styleBuilder, true, first); - return result; + public static Doll createTeoz(ParticipantEnglober englober, TileArguments tileArguments) { + return new Doll(englober, tileArguments, tileArguments.getSkinParam().getCurrentStyleBuilder(), null); } private static TileArguments convertFunctionToBeRemoved(ISkinParam skinParam, Rose skin, @@ -84,24 +82,47 @@ public class Doll extends DollAbstract { return new TileArguments(stringBounder, null, skin, skinParam, null); } - private Doll(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz, + private Doll(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, Participant first) { - super(englober, tileArguments, styleBuilder, isTeoz); - this.participants.add(first); - final double preferredWidth = getPreferredWidth(); - if (tileArguments.getLivingSpaces() == null) { - this.core1 = null; - this.core2 = null; - } else { - this.core1 = getMiddle().addFixed(-preferredWidth / 2); - this.core2 = getMiddle().addFixed(preferredWidth / 2); + this.englober = Objects.requireNonNull(englober); + this.styleBuilder = styleBuilder; + this.tileArguments = Objects.requireNonNull(tileArguments); + + if (first != null) { + this.participants.add(first); } + } - private Doll(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz) { - super(englober, tileArguments, styleBuilder, isTeoz); - this.core1 = null; - this.core2 = null; + final public StyleSignature getDefaultStyleDefinition() { + return ComponentType.ENGLOBER.getDefaultStyleDefinition(); + } + + final public Style[] getUsedStyles() { + Style tmp = getDefaultStyleDefinition().with(englober.getStereotype()).getMergedStyle(styleBuilder); + final HColor backColor = englober.getBoxColor(); + if (tmp != null) + tmp = tmp.eventuallyOverride(PName.BackGroundColor, backColor); + + return new Style[] { tmp }; + } + + final public ParticipantEnglober getParticipantEnglober() { + return englober; + } + + private Component getComponent() { + final ParticipantEnglober englober = getParticipantEnglober(); + final ISkinParam s = englober.getBoxColor() == null ? tileArguments.getSkinParam() + : new SkinParamBackcolored(tileArguments.getSkinParam(), englober.getBoxColor()); + return tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, s, + englober.getTitle()); + } + + public double getTitlePreferredHeight() { + final Component comp = tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, + tileArguments.getSkinParam(), getParticipantEnglober().getTitle()); + return comp.getPreferredHeight(tileArguments.getStringBounder()); } public final Participant getFirst2TOBEPRIVATE() { @@ -112,33 +133,28 @@ public class Doll extends DollAbstract { return participants.get(participants.size() - 1); } - private Real getMiddle() { - return RealUtils.middle(getPosB(), getPosD()); + private Real getPosA(StringBounder stringBounder) { + return getFirstLivingSpace().getPosA(stringBounder); } - private Real getPosB() { - return getFirstLivingSpace().getPosB(); + private Real getPosB(StringBounder stringBounder) { + return getFirstLivingSpace().getPosB(stringBounder); } - private Real getPosD() { - return getLastLivingSpace().getPosD(tileArguments.getStringBounder()); + private Real getPosD(StringBounder stringBounder) { + return getLastLivingSpace().getPosD(stringBounder); } - private Real getPosAA() { + private Real getPosE(StringBounder stringBounder) { + return getLastLivingSpace().getPosE(stringBounder); + } + + private Real getPosAA(StringBounder stringBounder) { final LivingSpace previous = tileArguments.getLivingSpaces().previous(getFirstLivingSpace()); if (previous == null) { return tileArguments.getOrigin(); } - return previous.getPosD(tileArguments.getStringBounder()); - } - - private Real getPosZZ() { - final LivingSpace next = tileArguments.getLivingSpaces().next(getLastLivingSpace()); - if (next == null) { - // return tileArguments.getMaxAbsolute(); - return null; - } - return next.getPosB(); + return previous.getPosD(stringBounder); } private LivingSpace getFirstLivingSpace() { @@ -154,58 +170,22 @@ public class Doll extends DollAbstract { } public void addParticipant(Participant p) { - if (participants.contains(p)) - throw new IllegalArgumentException(); - - participants.add(p); - } - - public void addDoll(Doll doll) { - this.leafs.add(doll); + participants.add(Objects.requireNonNull(p)); } @Override public String toString() { - return "DollLeaf:" + englober.getTitle().toString() + " " + participants; - } - - private double getPreferredWidth() { - if (isTeoz) { - return 10; - } - return getTitleWidth(); + return "Doll:" + englober.getTitle().toString() + " " + participants; } private double getTitleWidth() { return getComponent().getPreferredWidth(tileArguments.getStringBounder()); } - public void drawGroup(UGraphic ug, double height, Context2D context) { - if (leafs.size() == 0) - throw new IllegalArgumentException(); - final double x1 = getGroupX1(); - final double x2 = getGroupX2(); - final Dimension2DDouble dim = new Dimension2DDouble(x2 - x1, height); - getComponent().drawU(ug.apply(new UTranslate(x1, 1)), new Area(dim), context); - } - - private double getGroupX1() { - double result = leafs.get(0).getX1().getCurrentValue() - 6; - if (participants.size() > 0) - result = Math.min(result, getX1().getCurrentValue() - 6); - return result; - } - - private double getGroupX2() { - double result = leafs.get(leafs.size() - 1).getX2().getCurrentValue() + 6; - if (participants.size() > 0) - result = Math.max(result, getX2().getCurrentValue() + 6); - return result; - } - public void drawMe(UGraphic ug, double height, Context2D context, Doll group) { - final double x1 = getX1().getCurrentValue() - 4; - final double x2 = getX2().getCurrentValue() + 4; + final StringBounder stringBounder = ug.getStringBounder(); + final double x1 = getPosA(stringBounder).getCurrentValue() - 4; + final double x2 = getPosE(stringBounder).getCurrentValue() + 4; if (group != null) { final double titlePreferredHeight = group.getTitlePreferredHeight(); @@ -217,49 +197,38 @@ public class Doll extends DollAbstract { getComponent().drawU(ug.apply(new UTranslate(x1, 1)), new Area(dim), context); } - private Real getX1() { - if (core1 == null) - return getPosB().addFixed(-marginX); - return RealUtils.min(getPosB(), core1).addFixed(-marginX); - } - - private Real getX2() { - if (core2 == null) - return getPosD().addFixed(marginX); - return RealUtils.max(getPosD(), core2).addFixed(marginX); - } - - public void addInternalConstraints() { - assert isTeoz; + public void addInternalConstraints(StringBounder stringBounder) { final double titleWidth = getTitleWidth(); - final double x1 = getX1().getCurrentValue(); - final double x2 = getX2().getCurrentValue(); + final double x1 = getPosB(stringBounder).getCurrentValue(); + final double x2 = getPosD(stringBounder).getCurrentValue(); final double actualWidth = x2 - x1; - if (titleWidth > actualWidth + 20) - this.marginX = (titleWidth - actualWidth - 20) / 2; + final double marginX = (titleWidth + 10 - actualWidth) / 2; + if (marginX > 0) { + getFirstLivingSpace().ensureMarginBefore(marginX); + getLastLivingSpace().ensureMarginAfter(marginX); + } + getPosA(stringBounder).ensureBiggerThan(getPosAA(stringBounder).addFixed(10 + padding())); - getX1().ensureBiggerThan(getPosAA().addFixed(10 + padding())); - final Real posZZ = getPosZZ(); - final Real limit = getX2().addFixed(10 + padding()); - if (posZZ != null) - posZZ.ensureBiggerThan(limit); + } + public void addConstraintAfter(StringBounder stringBounder) { + final LivingSpace next = tileArguments.getLivingSpaces().next(getLastLivingSpace()); + if (next == null) + return; + + next.getPosA(stringBounder).ensureBiggerThan(getPosE(stringBounder).addFixed(20 + 2 * padding())); } private double padding() { return tileArguments.getSkinParam().getPadding(PaddingParam.BOX); } - public void addConstraintAfter(Doll current) { - current.getX1().ensureBiggerThan(getX2().addFixed(10 + 2 * padding())); - } - public Real getMinX(StringBounder stringBounder) { - return getX1(); + return getPosA(stringBounder); } public Real getMaxX(StringBounder stringBounder) { - return getX2().addFixed(10); + return getPosE(stringBounder).addFixed(10); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/DollAbstract.java b/src/net/sourceforge/plantuml/sequencediagram/DollAbstract.java deleted file mode 100644 index 0d08ea964..000000000 --- a/src/net/sourceforge/plantuml/sequencediagram/DollAbstract.java +++ /dev/null @@ -1,98 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009-2020, Arnaud Roques - * - * Project Info: http://plantuml.com - * - * If you like this project or if you find it useful, you can support us at: - * - * http://plantuml.com/patreon (only 1$ per month!) - * http://plantuml.com/paypal - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * - * Original Author: Arnaud Roques - * - * - */ -package net.sourceforge.plantuml.sequencediagram; - -import java.util.Objects; - -import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.SkinParamBackcolored; -import net.sourceforge.plantuml.sequencediagram.teoz.TileArguments; -import net.sourceforge.plantuml.skin.Component; -import net.sourceforge.plantuml.skin.ComponentType; -import net.sourceforge.plantuml.style.PName; -import net.sourceforge.plantuml.style.Style; -import net.sourceforge.plantuml.style.StyleBuilder; -import net.sourceforge.plantuml.style.StyleSignature; -import net.sourceforge.plantuml.style.WithStyle; -import net.sourceforge.plantuml.ugraphic.color.HColor; - -public abstract class DollAbstract implements WithStyle { - - final protected ParticipantEnglober englober; - final protected StyleBuilder styleBuilder; - final protected boolean isTeoz; - final protected TileArguments tileArguments; - - DollAbstract(ParticipantEnglober englober, TileArguments tileArguments, StyleBuilder styleBuilder, boolean isTeoz) { - this.englober = Objects.requireNonNull(englober); - this.styleBuilder = styleBuilder; - this.isTeoz = isTeoz; - this.tileArguments = Objects.requireNonNull(tileArguments); - } - - final public StyleSignature getDefaultStyleDefinition() { - return ComponentType.ENGLOBER.getDefaultStyleDefinition(); - } - - final public Style[] getUsedStyles() { - Style tmp = getDefaultStyleDefinition().with(englober.getStereotype()).getMergedStyle(styleBuilder); - final HColor backColor = englober.getBoxColor(); - if (tmp != null) - tmp = tmp.eventuallyOverride(PName.BackGroundColor, backColor); - - return new Style[] { tmp }; - } - - final public ParticipantEnglober getParticipantEnglober() { - return englober; - } - - final protected Component getComponent() { - final ParticipantEnglober englober = getParticipantEnglober(); - final ISkinParam s = englober.getBoxColor() == null ? tileArguments.getSkinParam() - : new SkinParamBackcolored(tileArguments.getSkinParam(), englober.getBoxColor()); - return tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, s, - englober.getTitle()); - } - - public double getTitlePreferredHeight() { - final Component comp = tileArguments.getSkin().createComponent(getUsedStyles(), ComponentType.ENGLOBER, null, - tileArguments.getSkinParam(), getParticipantEnglober().getTitle()); - return comp.getPreferredHeight(tileArguments.getStringBounder()); - } - - -} diff --git a/src/net/sourceforge/plantuml/sequencediagram/ParticipantEnglober.java b/src/net/sourceforge/plantuml/sequencediagram/ParticipantEnglober.java index f39dbf2f6..2760f77dc 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/ParticipantEnglober.java +++ b/src/net/sourceforge/plantuml/sequencediagram/ParticipantEnglober.java @@ -35,6 +35,10 @@ */ package net.sourceforge.plantuml.sequencediagram; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.Stereotype; import net.sourceforge.plantuml.ugraphic.color.HColor; @@ -45,7 +49,7 @@ public class ParticipantEnglober { final private Display title; final private HColor boxColor; final private Stereotype stereotype; - + @Override public String toString() { return title.toString(); @@ -82,4 +86,14 @@ public class ParticipantEnglober { return parent; } + public final List getGenealogy() { + final LinkedList result = new LinkedList<>(); + ParticipantEnglober current = this; + while (current != null) { + result.addFirst(current); + current = current.getParent(); + } + return Collections.unmodifiableList(result); + } + } diff --git a/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagram.java b/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagram.java index 275bde7d7..c01713f24 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagram.java +++ b/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagram.java @@ -256,9 +256,9 @@ public class SequenceDiagram extends UmlDiagram { if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) return new SequenceDiagramTxtMaker(this, fileFormat); - if (fileFormat.name().startsWith("XMI")) + if (fileFormat.name().startsWith("XMI")) return new SequenceDiagramXmiMaker(this, fileFormat); - + if (modeTeoz()) return new SequenceDiagramFileMakerTeoz(this, skin2, fileFormatOption, index); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTile.java index d7521e38d..18c9cf20e 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationTile.java @@ -263,7 +263,7 @@ public class CommunicationTile extends AbstractTile { if (isReverse(stringBounder)) { return livingSpace2.getPosD(stringBounder); } - return livingSpace2.getPosB(); + return livingSpace2.getPosB(stringBounder); } return livingSpace2.getPosC(stringBounder); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/Dolls.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/Dolls.java index 53c77c5bc..6676ec375 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/Dolls.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/Dolls.java @@ -36,7 +36,7 @@ package net.sourceforge.plantuml.sequencediagram.teoz; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -51,50 +51,42 @@ import net.sourceforge.plantuml.ugraphic.UGraphic; public class Dolls { - private final List dolls = new ArrayList<>(); - - private final Map groups = new HashMap<>(); + private final Map alls = new LinkedHashMap<>(); public Dolls(TileArguments tileArguments) { - Doll pending = null; + for (Participant p : tileArguments.getLivingSpaces().participants()) { final ParticipantEnglober englober = tileArguments.getLivingSpaces().get(p).getEnglober(); - if (englober == null) { - pending = null; - continue; - } - assert englober != null; - if (pending != null && englober == pending.getParticipantEnglober()) { - pending.addParticipant(p); - continue; - } + if (englober != null) + for (ParticipantEnglober pe : englober.getGenealogy()) + addParticipant(p, pe, tileArguments); - if (groups.containsKey(englober)) { - groups.get(englober).addParticipant(p); - continue; - } - - final ParticipantEnglober parent = englober.getParent(); - pending = Doll.createTeoz(englober, p, tileArguments, - tileArguments.getSkinParam().getCurrentStyleBuilder()); - if (parent != null && groups.containsKey(parent) == false) - groups.put(parent, Doll.createGroup(parent, tileArguments, - tileArguments.getSkinParam().getCurrentStyleBuilder(), true)); - - if (parent != null) - getParent(pending).addDoll(pending); - - dolls.add(pending); } } + private void addParticipant(Participant p, ParticipantEnglober englober, TileArguments tileArguments) { + Doll already = alls.get(englober); + if (already == null) { + already = Doll.createTeoz(englober, tileArguments); + alls.put(englober, already); + } + already.addParticipant(p); + } + + private Doll getParent(Doll doll) { + final ParticipantEnglober parent = doll.getParticipantEnglober().getParent(); + if (parent == null) + return null; + return alls.get(parent); + } + public int size() { - return dolls.size(); + return alls.size(); } public double getOffsetForEnglobers(StringBounder stringBounder) { double result = 0; - for (Doll doll : dolls) { + for (Doll doll : alls.values()) { double height = doll.getTitlePreferredHeight(); final Doll group = getParent(doll); if (group != null) @@ -108,41 +100,18 @@ public class Dolls { } public void addConstraints(StringBounder stringBounder) { - Doll last = null; - for (Doll doll : dolls) { - doll.addInternalConstraints(); - if (last != null) - last.addConstraintAfter(doll); - - last = doll; + for (Doll doll : alls.values()) { + doll.addInternalConstraints(stringBounder); + } + + for (Doll doll : alls.values()) { + doll.addConstraintAfter(stringBounder); } - } - private Doll getParent(Doll doll) { - final ParticipantEnglober parent = doll.getParticipantEnglober().getParent(); - if (parent == null) - return null; - return groups.get(parent); } public void drawEnglobers(UGraphic ug, double height, Context2D context) { - for (Doll group : groups.values()) { - group.drawGroup(ug, height, context); - - } -// DollGroup pending = null; -// for (DollLeaf doll : dolls) { -// final DollGroup group = doll.getGroup(); -// if (group==null) { -// -// } -// // if (pending==null || pending.equals(group)) -// if (group != null) { -// // group.drawMe(ug, height, context, doll.getX1().getCurrentValue(), doll.getX2().getCurrentValue()); -// } -// } - - for (Doll doll : dolls) + for (Doll doll : alls.values()) doll.drawMe(ug, height, context, getParent(doll)); } @@ -152,7 +121,7 @@ public class Dolls { throw new IllegalStateException(); final List result = new ArrayList<>(); - for (Doll doll : dolls) + for (Doll doll : alls.values()) result.add(doll.getMinX(stringBounder)); return RealUtils.min(result); @@ -163,7 +132,7 @@ public class Dolls { throw new IllegalStateException(); final List result = new ArrayList<>(); - for (Doll doll : dolls) + for (Doll doll : alls.values()) result.add(doll.getMaxX(stringBounder)); return RealUtils.max(result); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/LifeEventTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/LifeEventTile.java index 3bb32ae85..1ac6ff251 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/LifeEventTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/LifeEventTile.java @@ -114,7 +114,7 @@ public class LifeEventTile extends AbstractTile { public Real getMinX() { // return tileArguments.getLivingSpace(lifeEvent.getParticipant()).getPosB(); - return livingSpace.getPosB(); + return livingSpace.getPosB(getStringBounder()); } public Real getMaxX() { diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/LivingSpace.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/LivingSpace.java index 7c8be6007..137c0776a 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/LivingSpace.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/LivingSpace.java @@ -221,7 +221,7 @@ public class LivingSpace { return posD; } - public Real getPosB() { + public Real getPosB(StringBounder stringBounder) { return posB; } @@ -247,4 +247,27 @@ public class LivingSpace { return englober; } + private double marginBefore; + private double marginAfter; + + public void ensureMarginBefore(double margin) { + if (margin < 0) + throw new IllegalArgumentException(); + this.marginBefore = Math.max(marginBefore, margin); + } + + public void ensureMarginAfter(double margin) { + if (margin < 0) + throw new IllegalArgumentException(); + this.marginAfter = Math.max(marginAfter, margin); + } + + public Real getPosA(StringBounder stringBounder) { + return getPosB(stringBounder).addFixed(-marginBefore); + } + + public Real getPosE(StringBounder stringBounder) { + return getPosD(stringBounder).addFixed(marginAfter); + } + } diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/LivingSpaces.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/LivingSpaces.java index 8e8a0017a..b200f2c78 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/LivingSpaces.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/LivingSpaces.java @@ -62,8 +62,8 @@ public class LivingSpaces { LivingSpace previous = null; for (LivingSpace current : all.values()) { if (previous != null) { - final Real point1 = previous.getPosD(stringBounder); - final Real point2 = current.getPosB(); + final Real point1 = previous.getPosE(stringBounder); + final Real point2 = current.getPosA(stringBounder); point2.ensureBiggerThan(point1.addFixed(10)); } previous = current; @@ -108,7 +108,7 @@ public class LivingSpaces { final StringBounder stringBounder = ug.getStringBounder(); final double headHeight = getHeadHeight(stringBounder); for (LivingSpace livingSpace : values()) { - final double x = livingSpace.getPosB().getCurrentValue(); + final double x = livingSpace.getPosB(stringBounder).getCurrentValue(); double y = 0; if (verticalAlignment == VerticalAlignment.BOTTOM) { final Dimension2D dimHead = livingSpace.getHeadPreferredDimension(stringBounder); diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/NoteTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/NoteTile.java index fd9a01e7b..8691d07ab 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/NoteTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/NoteTile.java @@ -112,7 +112,7 @@ public class NoteTile extends AbstractTile implements Tile { final Dimension2D dim = comp.getPreferredDimension(stringBounder); final double width = dim.getWidth(); if (note.getPosition() == NotePosition.OVER_SEVERAL) { - final double x1 = livingSpace1.getPosB().getCurrentValue(); + final double x1 = livingSpace1.getPosB(stringBounder).getCurrentValue(); final double x2 = livingSpace2.getPosD(stringBounder).getCurrentValue(); final double w = x2 - x1; if (width < w) { @@ -157,7 +157,7 @@ public class NoteTile extends AbstractTile implements Tile { public Real getMinX() { final Real result = getX(getStringBounder()); if (note.getPosition() == NotePosition.OVER_SEVERAL) { - final Real x1 = livingSpace1.getPosB(); + final Real x1 = livingSpace1.getPosB(getStringBounder()); return RealUtils.min(result, x1); } return result; diff --git a/src/net/sourceforge/plantuml/sequencediagram/teoz/ReferenceTile.java b/src/net/sourceforge/plantuml/sequencediagram/teoz/ReferenceTile.java index aa44f9e96..4c40c81e4 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/teoz/ReferenceTile.java +++ b/src/net/sourceforge/plantuml/sequencediagram/teoz/ReferenceTile.java @@ -75,7 +75,7 @@ public class ReferenceTile extends AbstractTile implements Tile { final LivingSpace livingSpace = tileArguments.getLivingSpace(p); final Real pos = livingSpace.getPosC(stringBounder); if (first == null || pos.getCurrentValue() < first.getCurrentValue()) { - this.first = livingSpace.getPosB(); + this.first = livingSpace.getPosB(stringBounder); } if (last == null || pos.getCurrentValue() > last.getCurrentValue()) { this.last = livingSpace.getPosD(stringBounder); diff --git a/src/net/sourceforge/plantuml/sprite/SpriteColor.java b/src/net/sourceforge/plantuml/sprite/SpriteColor.java index 4ecbb9601..1d71b60e0 100644 --- a/src/net/sourceforge/plantuml/sprite/SpriteColor.java +++ b/src/net/sourceforge/plantuml/sprite/SpriteColor.java @@ -56,17 +56,17 @@ public class SpriteColor implements Sprite { private final int width; private final int height; - private final int grey[][]; + private final int gray[][]; private final int color[][]; public SpriteColor(int width, int height) { this.width = width; this.height = height; - this.grey = new int[height][width]; + this.gray = new int[height][width]; this.color = new int[height][width]; } - public void setGrey(int x, int y, int level) { + public void setGray(int x, int y, int level) { if (x < 0 || x >= width) { return; } @@ -76,7 +76,7 @@ public class SpriteColor implements Sprite { if (level < 0 || level >= 16) { throw new IllegalArgumentException(); } - grey[y][x] = level; + gray[y][x] = level; color[y][x] = -1; } @@ -87,7 +87,7 @@ public class SpriteColor implements Sprite { if (y < 0 || y >= height) { return; } - grey[y][x] = -1; + gray[y][x] = -1; color[y][x] = col; } @@ -113,7 +113,7 @@ public class SpriteColor implements Sprite { for (int line = 0; line < height; line++) { final int localColor = color[line][col]; if (localColor == -1) { - final double coef = 1.0 * grey[line][col] / (16 - 1); + final double coef = 1.0 * gray[line][col] / (16 - 1); final Color c = gradient.getColor(colorMapper, coef); im.setRGB(col, line, c.getRGB()); } else { diff --git a/src/net/sourceforge/plantuml/sprite/SpriteColorBuilder.java b/src/net/sourceforge/plantuml/sprite/SpriteColorBuilder.java index 058a7d946..aa6c8f43a 100644 --- a/src/net/sourceforge/plantuml/sprite/SpriteColorBuilder.java +++ b/src/net/sourceforge/plantuml/sprite/SpriteColorBuilder.java @@ -55,7 +55,7 @@ public class SpriteColorBuilder { final char charColor = strings.get(line).charAt(col); final int idx = "0123456789ABCDEF".indexOf(charColor); if (idx != -1) { - result.setGrey(col, line, idx); + result.setGray(col, line, idx); } else { final Color rgb = COLOR_PALETTE.getColorFor(charColor); result.setColor(col, line, rgb.getRGB() & 0xFFFFFF); diff --git a/src/net/sourceforge/plantuml/sprite/SpriteGrayLevel.java b/src/net/sourceforge/plantuml/sprite/SpriteGrayLevel.java index e6d39a17c..2a429672c 100644 --- a/src/net/sourceforge/plantuml/sprite/SpriteGrayLevel.java +++ b/src/net/sourceforge/plantuml/sprite/SpriteGrayLevel.java @@ -166,8 +166,8 @@ public enum SpriteGrayLevel { return 0; } final Color g = mono.getChangedColor(new Color(img.getRGB(x, y))); - final int grey = 255 - g.getRed(); - return grey / 16; + final int gray = 255 - g.getRed(); + return gray / 16; } public Sprite buildSprite(int width, int height, List strings) { @@ -193,7 +193,7 @@ public enum SpriteGrayLevel { if (strings.get(line).charAt(col) != '0') { final String s = "" + strings.get(line).charAt(col); final int x = Integer.parseInt(StringUtils.goUpperCase(s), 16); - result.setGrey(col, line, x); + result.setGray(col, line, x); } } } @@ -210,8 +210,8 @@ public enum SpriteGrayLevel { final int v = AsciiEncoder.decode6bit(strings.get(line).charAt(col)); final int w1 = v / 8; final int w2 = v % 8; - result.setGrey(col, line * 2, w1); - result.setGrey(col, line * 2 + 1, w2); + result.setGray(col, line * 2, w1); + result.setGray(col, line * 2 + 1, w2); } } @@ -230,9 +230,9 @@ public enum SpriteGrayLevel { v = v % 16; final int w2 = v / 4; final int w3 = v % 4; - result.setGrey(col, line * 3, w1); - result.setGrey(col, line * 3 + 1, w2); - result.setGrey(col, line * 3 + 2, w3); + result.setGray(col, line * 3, w1); + result.setGray(col, line * 3 + 1, w2); + result.setGray(col, line * 3 + 2, w3); } } @@ -290,7 +290,7 @@ public enum SpriteGrayLevel { int cpt = 0; for (int line = 0; line < result.getHeight(); line++) { for (int col = 0; col < result.getWidth(); col++) { - result.setGrey(col, line, img.getByteAt(cpt++)); + result.setGray(col, line, img.getByteAt(cpt++)); } } diff --git a/src/net/sourceforge/plantuml/sprite/SpriteMonochrome.java b/src/net/sourceforge/plantuml/sprite/SpriteMonochrome.java index 4dd69971a..b905f90ed 100644 --- a/src/net/sourceforge/plantuml/sprite/SpriteMonochrome.java +++ b/src/net/sourceforge/plantuml/sprite/SpriteMonochrome.java @@ -60,7 +60,7 @@ public class SpriteMonochrome implements Sprite { private final int width; private final int height; private final int grayLevel; - private final int grey[][]; + private final int gray[][]; public boolean isSameKind(SpriteMonochrome other) { if (this.width != other.width) { @@ -81,7 +81,7 @@ public class SpriteMonochrome implements Sprite { } for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - if (this.grey[j][i] != other.grey[j][i]) { + if (this.gray[j][i] != other.gray[j][i]) { return false; } } @@ -102,7 +102,7 @@ public class SpriteMonochrome implements Sprite { final SpriteMonochrome result = new SpriteMonochrome(width, height, grayLevel); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - result.grey[j][i] = this.grey[j][i] ^ other.grey[j][i]; + result.gray[j][i] = this.gray[j][i] ^ other.gray[j][i]; } } return result; @@ -115,21 +115,21 @@ public class SpriteMonochrome implements Sprite { this.width = width; this.height = height; this.grayLevel = grayLevel; - this.grey = new int[height][width]; + this.gray = new int[height][width]; } public SpriteMonochrome xSymetric() { final SpriteMonochrome result = new SpriteMonochrome(width, height, grayLevel); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - result.setGrey(i, j, this.getGrey(i, j)); + result.setGray(i, j, this.getGray(i, j)); } } for (int j = 0; j < height; j++) { for (int i = 0; i < width / 2; i++) { final int i2 = width - 1 - i; - final int level = result.getGrey(i, j) ^ result.getGrey(i2, j); - result.setGrey(i2, j, level); + final int level = result.getGray(i, j) ^ result.getGray(i2, j); + result.setGray(i2, j, level); } } return result; @@ -139,20 +139,20 @@ public class SpriteMonochrome implements Sprite { final SpriteMonochrome result = new SpriteMonochrome(width, height, grayLevel); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - result.setGrey(i, j, this.getGrey(i, j)); + result.setGray(i, j, this.getGray(i, j)); } } for (int i = 0; i < width; i++) { for (int j = 0; j < height / 2; j++) { final int j2 = height - 1 - j; - final int level = result.getGrey(i, j) ^ result.getGrey(i, j2); - result.setGrey(i, j2, level); + final int level = result.getGray(i, j) ^ result.getGray(i, j2); + result.setGray(i, j2, level); } } return result; } - public void setGrey(int x, int y, int level) { + public void setGray(int x, int y, int level) { if (x < 0 || x >= width) { return; } @@ -162,17 +162,17 @@ public class SpriteMonochrome implements Sprite { if (level < 0 || level >= grayLevel) { throw new IllegalArgumentException("level=" + level + " grayLevel=" + grayLevel); } - grey[y][x] = level; + gray[y][x] = level; } - public int getGrey(int x, int y) { + public int getGray(int x, int y) { if (x >= width) { throw new IllegalArgumentException("x=" + x + " width=" + width); } if (y >= height) { throw new IllegalArgumentException("y=" + y + " height=" + height); } - return grey[y][x]; + return gray[y][x]; } public int getHeight() { @@ -198,7 +198,7 @@ public class SpriteMonochrome implements Sprite { final HColorGradient gradient = new HColorGradient(backcolor, color, '\0'); for (int col = 0; col < width; col++) { for (int line = 0; line < height; line++) { - final double coef = 1.0 * grey[line][col] / (grayLevel - 1); + final double coef = 1.0 * gray[line][col] / (grayLevel - 1); final Color c = gradient.getColor(colorMapper, coef); im.setRGB(col, line, c.getRGB()); } @@ -213,7 +213,7 @@ public class SpriteMonochrome implements Sprite { final HColor backColorLocal = new HColorSimple(backcolor.getColor(colorMapper, 1.0 * line / height), false); final HColorGradient gradient = new HColorGradient(backColorLocal, color, '\0'); - final double coef = 1.0 * grey[line][col] / (grayLevel - 1); + final double coef = 1.0 * gray[line][col] / (grayLevel - 1); final Color c = gradient.getColor(colorMapper, coef); im.setRGB(col, line, c.getRGB()); } @@ -238,8 +238,8 @@ public class SpriteMonochrome implements Sprite { public void exportSprite1(OutputStream fos) throws IOException { for (int y = 0; y < this.getHeight(); y += 2) { for (int x = 0; x < this.getWidth(); x += 1) { - int b1 = this.getGrey(x, y); - int b2 = y + 1 < this.getHeight() ? this.getGrey(x, y + 1) : b1; + int b1 = this.getGray(x, y); + int b2 = y + 1 < this.getHeight() ? this.getGray(x, y + 1) : b1; fos.write(b1 * 16 + b2); } } diff --git a/src/net/sourceforge/plantuml/ugraphic/MinMax.java b/src/net/sourceforge/plantuml/ugraphic/MinMax.java index deeb9480e..8907a20d3 100644 --- a/src/net/sourceforge/plantuml/ugraphic/MinMax.java +++ b/src/net/sourceforge/plantuml/ugraphic/MinMax.java @@ -153,7 +153,7 @@ public class MinMax { return new Dimension2DDouble(maxX - minX, maxY - minY); } - public void drawGrey(UGraphic ug) { + public void drawGray(UGraphic ug) { draw(ug, HColorUtils.GRAY); } diff --git a/src/net/sourceforge/plantuml/ugraphic/PixelImage.java b/src/net/sourceforge/plantuml/ugraphic/PixelImage.java index d128166c2..124124805 100644 --- a/src/net/sourceforge/plantuml/ugraphic/PixelImage.java +++ b/src/net/sourceforge/plantuml/ugraphic/PixelImage.java @@ -129,8 +129,8 @@ public class PixelImage implements MutableImage { // if (isTransparent(color)) { // continue; // } - final int grey = ColorUtils.getGrayScale(rgb); - if (darkerRgb == -1 || grey < ColorUtils.getGrayScale(darkerRgb)) { + final int gray = ColorUtils.getGrayScale(rgb); + if (darkerRgb == -1 || gray < ColorUtils.getGrayScale(darkerRgb)) { darkerRgb = rgb; } } diff --git a/src/net/sourceforge/plantuml/ugraphic/color/ColorChangerMonochrome.java b/src/net/sourceforge/plantuml/ugraphic/color/ColorChangerMonochrome.java index bc6ddb609..7a3fef932 100644 --- a/src/net/sourceforge/plantuml/ugraphic/color/ColorChangerMonochrome.java +++ b/src/net/sourceforge/plantuml/ugraphic/color/ColorChangerMonochrome.java @@ -40,11 +40,18 @@ import java.awt.Color; public class ColorChangerMonochrome { public Color getChangedColor(Color color) { - if (color == null) { + if (color == null) return null; - } + final int grayScale = ColorUtils.getGrayScale(color); return new Color(grayScale, grayScale, grayScale); } + public Color getChangedColor(HColor color) { + if (color == null) + return null; + + return getChangedColor(((HColorSimple) color).getColor999()); + } + } diff --git a/src/net/sourceforge/plantuml/ugraphic/color/ColorUtils.java b/src/net/sourceforge/plantuml/ugraphic/color/ColorUtils.java index 1d1710938..ae6848642 100644 --- a/src/net/sourceforge/plantuml/ugraphic/color/ColorUtils.java +++ b/src/net/sourceforge/plantuml/ugraphic/color/ColorUtils.java @@ -97,7 +97,7 @@ public class ColorUtils { return new Color(red2, green2, blue2); } - public static Color greyToColor(Color color, int grey) { + public static Color grayToColor(double coef, Color color) { final int red = color.getRed(); final int green = color.getGreen(); final int blue = color.getBlue(); @@ -108,7 +108,7 @@ public class ColorUtils { final double s = hsluv[1]; double l = hsluv[2]; - l = l + (100 - l) * (grey / 255.0); + l = l + (100 - l) * coef; final double rgb[] = HUSLColorConverter.hsluvToRgb(new double[] { h, s, l }); diff --git a/src/net/sourceforge/plantuml/ugraphic/color/HColorSimple.java b/src/net/sourceforge/plantuml/ugraphic/color/HColorSimple.java index 4caaf1b9c..d7d916d05 100644 --- a/src/net/sourceforge/plantuml/ugraphic/color/HColorSimple.java +++ b/src/net/sourceforge/plantuml/ugraphic/color/HColorSimple.java @@ -122,12 +122,14 @@ public class HColorSimple extends HColorAbstract implements HColor { return new HColorSimple(new ColorChangerMonochrome().getChangedColor(color), monochrome); } - public HColor asMonochrome(HColorSimple colorForMonochrome) { + public HColor asMonochrome(HColorSimple colorForMonochrome, double minGray, double maxGray) { final Color tmp = new ColorChangerMonochrome().getChangedColor(color); - final int grey = tmp.getGreen(); - assert grey == tmp.getBlue(); - assert grey == tmp.getRed(); - Color result = ColorUtils.greyToColor(colorForMonochrome.color, grey); + final int gray = tmp.getGreen(); + assert gray == tmp.getBlue(); + assert gray == tmp.getRed(); + + final double coef = (gray - minGray) / 256.0; + final Color result = ColorUtils.grayToColor(coef, colorForMonochrome.color); return new HColorSimple(result, monochrome); } diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 1bce724d7..87b8f86ed 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 = 9; + final int beta = 10; return beta; }