1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-05 18:10:46 +00:00
This commit is contained in:
Arnaud Roques 2021-12-14 22:38:22 +01:00
parent 442d313a30
commit 5a1147b92e
23 changed files with 161 additions and 170 deletions

View File

@ -90,6 +90,7 @@ public class Body3 extends AbstractTextBlock implements TextBlock, WithPorts {
return foo;
}
@Override
public Ports getPorts(StringBounder stringBounder) {
return new Ports();
}

View File

@ -122,7 +122,7 @@ public class BodyEnhanced1 extends BodyEnhancedAbstract implements TextBlock, Wi
}
@Override
protected TextBlock getArea(StringBounder stringBounder) {
final protected TextBlock getArea(StringBounder stringBounder) {
if (area != null) {
return area;
}
@ -226,6 +226,7 @@ public class BodyEnhanced1 extends BodyEnhancedAbstract implements TextBlock, Wi
return s;
}
@Override
public Ports getPorts(StringBounder stringBounder) {
final TextBlock area = getArea(stringBounder);
if (area instanceof WithPorts) {

View File

@ -0,0 +1,56 @@
/* ========================================================================
* 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.cucadiagram;
class Elected {
private final String shortName;
private final int score;
public Elected(String shortName, int score) {
this.shortName = shortName;
this.score = score;
}
public final String getShortName() {
return shortName;
}
public final int getScore() {
return score;
}
}

View File

@ -1,100 +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.cucadiagram;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
class Election {
private final Map<String, CharSequence> all = new HashMap<String, CharSequence>();
public void addCandidate(String display, CharSequence candidate) {
all.put(display, candidate);
}
private CharSequence getCandidate(String shortName) {
List<CharSequence> list = getAllCandidateContains(shortName);
if (list.size() == 1) {
return list.get(0);
}
list = getAllCandidateContainsStrict(shortName);
if (list.size() == 1) {
return list.get(0);
}
return null;
}
private List<CharSequence> getAllCandidateContains(String shortName) {
final List<CharSequence> result = new ArrayList<>();
for (Map.Entry<String, CharSequence> ent : all.entrySet()) {
if (ent.getKey().contains(shortName)) {
result.add(ent.getValue());
}
}
return result;
}
private List<CharSequence> getAllCandidateContainsStrict(String shortName) {
final List<CharSequence> result = new ArrayList<>();
for (Map.Entry<String, CharSequence> ent : all.entrySet()) {
final String key = ent.getKey();
if (key.matches(".*\\b" + shortName + "\\b.*")) {
result.add(ent.getValue());
}
}
return result;
}
public Map<CharSequence, String> getAllElected(Collection<String> shortNames) {
final Map<CharSequence, String> memberWithPort = new HashMap<CharSequence, String>();
for (String shortName : new HashSet<>(shortNames)) {
final CharSequence m = getCandidate(shortName);
if (m != null) {
memberWithPort.put(m, shortName);
shortNames.remove(shortName);
}
}
return Collections.unmodifiableMap(memberWithPort);
}
}

View File

@ -37,7 +37,8 @@ package net.sourceforge.plantuml.cucadiagram;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.util.Map;
import java.util.Collection;
import java.util.HashSet;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.EmbeddedDiagram;
@ -108,9 +109,9 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlock,
if (cs instanceof Member == false)
continue;
final Member m = (Member) cs;
if (m.getVisibilityModifier() != null) {
if (m.getVisibilityModifier() != null)
return true;
}
}
return false;
}
@ -132,53 +133,68 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlock,
return new Dimension2DDouble(x, y);
}
@Override
public Ports getPorts(StringBounder stringBounder) {
final Ports result = new Ports();
double y = 0;
final Election election = new Election();
for (CharSequence cs : members) {
if (cs instanceof Member) {
final Member m = (Member) cs;
election.addCandidate(m.getDisplay(false), m);
} else {
election.addCandidate(cs.toString(), cs);
}
}
final Map<CharSequence, String> memberWithPort = election.getAllElected(leaf.getPortShortNames());
for (CharSequence cs : members) {
final TextBlock bloc = createTextBlock(cs);
final Dimension2D dim = bloc.calculateDimension(stringBounder);
final String port = memberWithPort.get(cs);
if (port != null) {
result.add(port, y, dim.getHeight());
}
final Elected port = getElected(leaf.getPortShortNames(), convert(cs));
if (port != null)
result.add(port.getShortName(), port.getScore(), y, dim.getHeight());
y += dim.getHeight();
}
return result;
}
private String convert(CharSequence cs) {
if (cs instanceof Member)
return ((Member) cs).getDisplay(false);
return cs.toString();
}
public Elected getElected(Collection<String> shortNames, String cs) {
for (String shortName : new HashSet<>(shortNames)) {
final int score = getScore(shortName, cs);
if (score > 0)
return new Elected(shortName, score);
}
return null;
}
private int getScore(String shortName, String cs) {
if (cs.matches(".*\\b" + shortName + "\\b.*"))
return 100;
if (cs.contains(shortName))
return 50;
return 0;
}
private TextBlock createTextBlock(CharSequence cs) {
FontConfiguration config;
if (style != null) {
if (style != null)
config = new FontConfiguration(skinParam, style);
} else {
else
config = new FontConfiguration(skinParam, fontParam, stereotype);
}
if (cs instanceof Member) {
final Member m = (Member) cs;
final boolean withVisibilityChar = skinParam.classAttributeIconSize() == 0;
String s = m.getDisplay(withVisibilityChar);
if (withVisibilityChar && s.startsWith("#")) {
if (withVisibilityChar && s.startsWith("#"))
s = CharHidder.addTileAtBegin(s);
}
if (m.isAbstract()) {
if (m.isAbstract())
config = config.italic();
}
if (m.isStatic()) {
if (m.isStatic())
config = config.underline();
}
TextBlock bloc = Display.getWithNewlines(s).create8(config, align, skinParam, CreoleMode.SIMPLE_LINE,
skinParam.wrapWidth());
@ -206,13 +222,13 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlock,
}
public void drawU(UGraphic ug) {
if (url != null) {
if (url != null)
ug.startUrl(url);
}
bloc.drawU(ug);
if (url != null) {
if (url != null)
ug.closeUrl();
}
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
@ -256,9 +272,9 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlock,
public boolean contains(String member) {
for (CharSequence cs : members) {
final Member att = (Member) cs;
if (att.getDisplay(false).startsWith(member)) {
if (att.getDisplay(false).startsWith(member))
return true;
}
}
return false;
}
@ -288,13 +304,13 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlock,
}
} else {
final PlacementStrategy placementStrategy;
if (align == HorizontalAlignment.LEFT) {
if (align == HorizontalAlignment.LEFT)
placementStrategy = new PlacementStrategyY1Y2Left(stringBounder);
} else if (align == HorizontalAlignment.CENTER) {
else if (align == HorizontalAlignment.CENTER)
placementStrategy = new PlacementStrategyY1Y2Center(stringBounder);
} else {
else
placementStrategy = new PlacementStrategyY1Y2Right(stringBounder);
}
group = new ULayoutGroup(placementStrategy);
for (CharSequence cs : members) {
final TextBlock bloc = createTextBlock(cs);

View File

@ -84,6 +84,7 @@ public class TextBlockMap extends AbstractTextBlock implements WithPorts {
}
}
@Override
public Ports getPorts(StringBounder stringBounder) {
final Ports ports = new Ports();
int i = 0;
@ -92,7 +93,7 @@ public class TextBlockMap extends AbstractTextBlock implements WithPorts {
final TextBlock key = ent.getKey();
final TextBlock value = ent.getValue();
final double height = getHeightOfRow(stringBounder, key, value);
ports.add(keys.get(i), y, height);
ports.add(keys.get(i), 100, y, height);
y += height;
i++;
}

View File

@ -730,8 +730,7 @@ final public class EntityImpl implements ILeaf, IGroup {
public Collection<String> getPortShortNames() {
checkNotGroup();
// return Collections.unmodifiableCollection(portShortNames);
return portShortNames;
return Collections.unmodifiableCollection(portShortNames);
}
public void addPortShortName(String portShortName) {

View File

@ -96,6 +96,7 @@ public class TextBlockLineBefore extends AbstractTextBlock implements TextBlock,
return textBlock.getInnerPosition(member, stringBounder, strategy);
}
@Override
public Ports getPorts(StringBounder stringBounder) {
return ((WithPorts) textBlock).getPorts(stringBounder);
}

View File

@ -96,6 +96,7 @@ class TextBlockMarged extends AbstractTextBlock implements TextBlock, WithPorts
return translate.apply(parent);
}
@Override
public Ports getPorts(StringBounder stringBounder) {
return ((WithPorts) textBlock).getPorts(stringBounder).translateY(top);
}

View File

@ -122,6 +122,7 @@ public class TextBlockVertical2 extends AbstractTextBlock implements TextBlock,
}
}
@Override
public Ports getPorts(StringBounder stringBounder) {
double y = 0;
// final Dimension2D dimtotal = calculateDimension(stringBounder);

View File

@ -54,6 +54,7 @@ public abstract class AbstractEntityImage extends AbstractTextBlock implements I
this.skinParam = Objects.requireNonNull(skinParam);
}
@Override
public boolean isHidden() {
return entity.isHidden();
}
@ -66,6 +67,7 @@ public abstract class AbstractEntityImage extends AbstractTextBlock implements I
return skinParam;
}
@Override
public final HColor getBackcolor() {
return skinParam.getBackgroundColor();
}
@ -74,10 +76,12 @@ public abstract class AbstractEntityImage extends AbstractTextBlock implements I
return entity.getStereotype();
}
@Override
public Margins getShield(StringBounder stringBounder) {
return Margins.NONE;
}
@Override
public double getOverscanX(StringBounder stringBounder) {
return 0;
}

View File

@ -81,11 +81,11 @@ public final class ConcurrentStateImage extends AbstractTextBlock implements IEn
Dimension2D add(Dimension2D orig, Dimension2D other) {
if (this == VERTICAL) {
return new Dimension2DDouble(orig.getWidth() + other.getWidth(), Math.max(orig.getHeight(),
other.getHeight()));
return new Dimension2DDouble(orig.getWidth() + other.getWidth(),
Math.max(orig.getHeight(), other.getHeight()));
}
return new Dimension2DDouble(Math.max(orig.getWidth(), other.getWidth()), orig.getHeight()
+ other.getHeight());
return new Dimension2DDouble(Math.max(orig.getWidth(), other.getWidth()),
orig.getHeight() + other.getHeight());
}
void drawSeparator(UGraphic ug, Dimension2D dimTotal) {
@ -155,7 +155,7 @@ public final class ConcurrentStateImage extends AbstractTextBlock implements IEn
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
public double getOverscanX(StringBounder stringBounder) {
return 0;
}

View File

@ -80,11 +80,11 @@ public final class CucaDiagramFileMakerSvek2InternalImage extends AbstractTextBl
Dimension2D add(Dimension2D orig, Dimension2D other) {
if (this == VERTICAL) {
return new Dimension2DDouble(orig.getWidth() + other.getWidth(), Math.max(orig.getHeight(),
other.getHeight()));
return new Dimension2DDouble(orig.getWidth() + other.getWidth(),
Math.max(orig.getHeight(), other.getHeight()));
}
return new Dimension2DDouble(Math.max(orig.getWidth(), other.getWidth()), orig.getHeight()
+ other.getHeight());
return new Dimension2DDouble(Math.max(orig.getWidth(), other.getWidth()),
orig.getHeight() + other.getHeight());
}
void drawSeparator(UGraphic ug, Dimension2D dimTotal) {
@ -141,7 +141,7 @@ public final class CucaDiagramFileMakerSvek2InternalImage extends AbstractTextBl
public HColor getBackcolor() {
return skinParam.getBackgroundColor();
}
public double getOverscanX(StringBounder stringBounder) {
return 0;
}
@ -157,4 +157,5 @@ public final class CucaDiagramFileMakerSvek2InternalImage extends AbstractTextBl
public ShapeType getShapeType() {
return ShapeType.RECTANGLE;
}
}

View File

@ -53,12 +53,11 @@ public class EntityImageProtected extends AbstractTextBlock implements IEntityIm
private final double border;
private final Bibliotekon bibliotekon;
private final Neighborhood neighborhood;
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
throw new UnsupportedOperationException();
}
public EntityImageProtected(IEntityImage orig, double border, Neighborhood neighborhood, Bibliotekon bibliotekon) {
this.orig = orig;
this.border = border;
@ -94,10 +93,9 @@ public class EntityImageProtected extends AbstractTextBlock implements IEntityIm
public Margins getShield(StringBounder stringBounder) {
return orig.getShield(stringBounder);
}
public double getOverscanX(StringBounder stringBounder) {
return orig.getOverscanX(stringBounder);
}
}

View File

@ -47,7 +47,7 @@ public interface IEntityImage extends Hideable, TextBlockBackcolored {
public ShapeType getShapeType();
public Margins getShield(StringBounder stringBounder);
public double getOverscanX(StringBounder stringBounder);
}

View File

@ -63,8 +63,7 @@ public final class InnerActivity extends AbstractTextBlock implements IEntityIma
public void drawU(UGraphic ug) {
final Dimension2D total = calculateDimension(ug.getStringBounder());
ug = ug.apply(backColor.bg()).apply(borderColor)
.apply(new UStroke(THICKNESS_BORDER));
ug = ug.apply(backColor.bg()).apply(borderColor).apply(new UStroke(THICKNESS_BORDER));
final URectangle rect = new URectangle(total.getWidth(), total.getHeight()).rounded(IEntityImage.CORNER);
rect.setDeltaShadow(shadowing);
ug.draw(rect);

View File

@ -39,14 +39,16 @@ public class PortGeometry {
private final double position;
private final double height;
private final int score;
public PortGeometry(double position, double height) {
public PortGeometry(double position, double height, int score) {
this.position = position;
this.height = height;
this.score = score;
}
public PortGeometry translateY(double deltaY) {
return new PortGeometry(position + deltaY, height);
return new PortGeometry(position + deltaY, height, score);
}
@Override
@ -66,4 +68,8 @@ public class PortGeometry {
return position + height;
}
public final int getScore() {
return score;
}
}

View File

@ -37,6 +37,7 @@ package net.sourceforge.plantuml.svek;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import net.sourceforge.plantuml.SignatureUtils;
@ -45,10 +46,6 @@ public class Ports {
private final Map<String, PortGeometry> ids = new LinkedHashMap<String, PortGeometry>();
public void addThis(Ports other) {
ids.putAll(other.ids);
}
public static String encodePortNameToId(String portName) {
return "p" + SignatureUtils.getMD5Hex(portName);
}
@ -66,9 +63,20 @@ public class Ports {
return result;
}
public void add(String portName, double position, double height) {
public void add(String portName, int score, double position, double height) {
final String id = encodePortNameToId(Objects.requireNonNull(portName));
ids.put(id, new PortGeometry(position, height));
final PortGeometry already = ids.get(id);
if (already == null || already.getScore() < score)
ids.put(id, new PortGeometry(position, height, score));
}
public void addThis(Ports other) {
for (Entry<String, PortGeometry> ent : other.ids.entrySet()) {
final String key = ent.getKey();
final PortGeometry already = ids.get(key);
if (already == null || already.getScore() < ent.getValue().getScore())
ids.put(key, ent.getValue());
}
}
public Map<String, PortGeometry> getAllWithEncodedPortId() {

View File

@ -232,6 +232,7 @@ public class EntityImageClass extends AbstractEntityImage implements Stencil, Wi
}
}
@Override
public Ports getPorts(StringBounder stringBounder) {
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
if (body instanceof WithPorts)

View File

@ -129,6 +129,7 @@ public class EntityImageMap extends AbstractEntityImage implements Stencil, With
}
@Override
public Ports getPorts(StringBounder stringBounder) {
final Dimension2D dimTitle = getTitleDimension(stringBounder);
return ((WithPorts) entries).getPorts(stringBounder).translateY(dimTitle.getHeight());

View File

@ -49,9 +49,6 @@ import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleSignature;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UGroupType;

View File

@ -39,7 +39,6 @@ import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.LineConfigurable;
import net.sourceforge.plantuml.SkinParamUtils;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.cucadiagram.BodyFactory;

View File

@ -80,7 +80,7 @@ public class Version {
}
public static int beta() {
final int beta = 1;
final int beta = 2;
return beta;
}