mirror of
https://github.com/octoleo/plantuml.git
synced 2024-12-22 10:59:01 +00:00
wip
This commit is contained in:
parent
649a13e04b
commit
ac9d76cda6
@ -40,6 +40,11 @@ class Elected {
|
||||
private final String shortName;
|
||||
private final int score;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return shortName + "/" + score;
|
||||
}
|
||||
|
||||
public Elected(String shortName, int score) {
|
||||
this.shortName = shortName;
|
||||
this.score = score;
|
||||
|
@ -48,9 +48,9 @@ public class EntityPort {
|
||||
}
|
||||
|
||||
public String getFullString() {
|
||||
if (portId != null) {
|
||||
if (portId != null)
|
||||
return entityUid + ":" + portId;
|
||||
}
|
||||
|
||||
return entityUid;
|
||||
}
|
||||
|
||||
@ -59,9 +59,9 @@ public class EntityPort {
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
if (isShielded()) {
|
||||
if (isShielded())
|
||||
return entityUid.substring(0, entityUid.length() - 2);
|
||||
}
|
||||
|
||||
return entityUid;
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,11 @@
|
||||
package net.sourceforge.plantuml.cucadiagram;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.plantuml.Dimension2DDouble;
|
||||
import net.sourceforge.plantuml.EmbeddedDiagram;
|
||||
@ -130,21 +133,37 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlock,
|
||||
return new Dimension2DDouble(x, y);
|
||||
}
|
||||
|
||||
private Collection<String> sortBySize(Collection<String> all) {
|
||||
final List<String> result = new ArrayList<String>(all);
|
||||
Collections.sort(result, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String s1, String s2) {
|
||||
final int diff = s2.length() - s1.length();
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
return s1.compareTo(s2);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ports getPorts(StringBounder stringBounder) {
|
||||
final Ports result = new Ports();
|
||||
final Ports ports = new Ports();
|
||||
double y = 0;
|
||||
|
||||
final Collection<String> shortNames = sortBySize(leaf.getPortShortNames());
|
||||
|
||||
for (CharSequence cs : members) {
|
||||
final TextBlock bloc = createTextBlock(cs);
|
||||
final Dimension2D dim = bloc.calculateDimension(stringBounder);
|
||||
final Elected port = getElected(leaf.getPortShortNames(), convert(cs));
|
||||
if (port != null)
|
||||
result.add(port.getShortName(), port.getScore(), y, dim.getHeight());
|
||||
final Elected elected = getElected(convert(cs), shortNames);
|
||||
if (elected != null)
|
||||
ports.add(elected.getShortName(), elected.getScore(), y, dim.getHeight());
|
||||
|
||||
y += dim.getHeight();
|
||||
}
|
||||
return result;
|
||||
return ports;
|
||||
}
|
||||
|
||||
private String convert(CharSequence cs) {
|
||||
@ -153,16 +172,16 @@ public class MethodsOrFieldsArea extends AbstractTextBlock implements TextBlock,
|
||||
return cs.toString();
|
||||
}
|
||||
|
||||
public Elected getElected(Collection<String> shortNames, String cs) {
|
||||
for (String shortName : new HashSet<>(shortNames)) {
|
||||
final int score = getScore(shortName, cs);
|
||||
public Elected getElected(String cs, Collection<String> shortNames) {
|
||||
for (String shortName : shortNames) {
|
||||
final int score = getScore(cs, shortName);
|
||||
if (score > 0)
|
||||
return new Elected(shortName, score);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getScore(String shortName, String cs) {
|
||||
private int getScore(String cs, String shortName) {
|
||||
if (cs.matches(".*\\b" + shortName + "\\b.*"))
|
||||
return 100;
|
||||
|
||||
|
@ -41,6 +41,7 @@ public enum SName {
|
||||
activityDiagram, //
|
||||
actor, //
|
||||
agent, //
|
||||
analog, //
|
||||
archimate, //
|
||||
arrow, //
|
||||
artifact, //
|
||||
|
@ -35,6 +35,8 @@
|
||||
package net.sourceforge.plantuml.timingdiagram;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.SortedMap;
|
||||
@ -45,6 +47,7 @@ import net.sourceforge.plantuml.ISkinParam;
|
||||
import net.sourceforge.plantuml.awt.geom.Dimension2D;
|
||||
import net.sourceforge.plantuml.command.Position;
|
||||
import net.sourceforge.plantuml.cucadiagram.Display;
|
||||
import net.sourceforge.plantuml.cucadiagram.Stereotype;
|
||||
import net.sourceforge.plantuml.graphic.AbstractTextBlock;
|
||||
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
|
||||
import net.sourceforge.plantuml.graphic.StringBounder;
|
||||
@ -52,6 +55,7 @@ import net.sourceforge.plantuml.graphic.TextBlock;
|
||||
import net.sourceforge.plantuml.graphic.UDrawable;
|
||||
import net.sourceforge.plantuml.graphic.color.Colors;
|
||||
import net.sourceforge.plantuml.style.SName;
|
||||
import net.sourceforge.plantuml.style.StyleSignature;
|
||||
import net.sourceforge.plantuml.style.StyleSignatureBasic;
|
||||
import net.sourceforge.plantuml.timingdiagram.graphic.IntricatedPoint;
|
||||
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
||||
@ -61,14 +65,17 @@ import net.sourceforge.plantuml.ugraphic.UTranslate;
|
||||
public class PlayerAnalog extends Player {
|
||||
|
||||
private final SortedMap<TimeTick, Double> values = new TreeMap<TimeTick, Double>();
|
||||
|
||||
private final List<TimeConstraint> constraints = new ArrayList<>();
|
||||
|
||||
private final double ymargin = 8;
|
||||
private Double initialState;
|
||||
private Double start;
|
||||
private Double end;
|
||||
private Integer ticksEvery;
|
||||
|
||||
public PlayerAnalog(String code, ISkinParam skinParam, TimingRuler ruler, boolean compact) {
|
||||
super(code, skinParam, ruler, compact, null);
|
||||
public PlayerAnalog(String code, ISkinParam skinParam, TimingRuler ruler, boolean compact, Stereotype stereotype) {
|
||||
super(code, skinParam, ruler, compact, stereotype);
|
||||
this.suggestedHeight = 100;
|
||||
}
|
||||
|
||||
@ -94,16 +101,17 @@ public class PlayerAnalog extends Player {
|
||||
}
|
||||
|
||||
public double getFullHeight(StringBounder stringBounder) {
|
||||
return suggestedHeight;
|
||||
return getHeightForConstraints(stringBounder) + suggestedHeight;
|
||||
}
|
||||
|
||||
public IntricatedPoint getTimeProjection(StringBounder stringBounder, TimeTick tick) {
|
||||
final double x = ruler.getPosInPixel(tick);
|
||||
final double value = getValueAt(tick);
|
||||
return new IntricatedPoint(new Point2D.Double(x, getYpos(value)), new Point2D.Double(x, getYpos(value)));
|
||||
final double value = getValueAt(stringBounder, tick);
|
||||
return new IntricatedPoint(new Point2D.Double(x, getYpos(stringBounder, value)),
|
||||
new Point2D.Double(x, getYpos(stringBounder, value)));
|
||||
}
|
||||
|
||||
private double getValueAt(TimeTick tick) {
|
||||
private double getValueAt(StringBounder stringBounder, TimeTick tick) {
|
||||
final Double result = values.get(tick);
|
||||
if (result != null)
|
||||
return result;
|
||||
@ -155,14 +163,14 @@ public class PlayerAnalog extends Player {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createConstraint(TimeTick tick1, TimeTick tick2, String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
this.constraints.add(new TimeConstraint(tick1, tick2, message, skinParam));
|
||||
}
|
||||
|
||||
private double getYpos(double value) {
|
||||
final double fullHeight = getFullHeight(null);
|
||||
final double y = (value - getMin()) * (fullHeight - 2 * ymargin) / (getMax() - getMin());
|
||||
return fullHeight - ymargin - y;
|
||||
private double getYpos(StringBounder stringBounder, double value) {
|
||||
final double y = (value - getMin()) * (suggestedHeight - 2 * ymargin) / (getMax() - getMin());
|
||||
return getHeightForConstraints(stringBounder) + suggestedHeight - ymargin - y;
|
||||
}
|
||||
|
||||
public TextBlock getPart1(final double fullAvailableWidth, final double specialVSpace) {
|
||||
@ -224,7 +232,7 @@ public class PlayerAnalog extends Player {
|
||||
final TextBlock label = getTextBlock(value);
|
||||
final Dimension2D dim = label.calculateDimension(ug.getStringBounder());
|
||||
ug = ug.apply(UTranslate.dx(fullAvailableWidth - dim.getWidth() - 2));
|
||||
label.drawU(ug.apply(UTranslate.dy(getYpos(value) - dim.getHeight() / 2)));
|
||||
label.drawU(ug.apply(UTranslate.dy(getYpos(ug.getStringBounder(), value) - dim.getHeight() / 2)));
|
||||
}
|
||||
|
||||
private TextBlock getTextBlock(double value) {
|
||||
@ -239,7 +247,7 @@ public class PlayerAnalog extends Player {
|
||||
final ULine hline = ULine.hline(ruler.getWidth());
|
||||
for (int i = first; i <= last; i++)
|
||||
if (i % ticksEvery == 0)
|
||||
ug.apply(UTranslate.dy(getYpos(i))).draw(hline);
|
||||
ug.apply(UTranslate.dy(getYpos(ug.getStringBounder(), i))).draw(hline);
|
||||
|
||||
}
|
||||
|
||||
@ -253,14 +261,18 @@ public class PlayerAnalog extends Player {
|
||||
double lastx = 0;
|
||||
double lastValue = initialState == null ? 0 : initialState;
|
||||
for (Map.Entry<TimeTick, Double> ent : values.entrySet()) {
|
||||
final double y1 = getYpos(lastValue);
|
||||
final double y2 = getYpos(ent.getValue());
|
||||
final double y1 = getYpos(ug.getStringBounder(), lastValue);
|
||||
final double y2 = getYpos(ug.getStringBounder(), ent.getValue());
|
||||
final double x = ruler.getPosInPixel(ent.getKey());
|
||||
ug.apply(new UTranslate(lastx, y1)).draw(new ULine(x - lastx, y2 - y1));
|
||||
lastx = x;
|
||||
lastValue = ent.getValue();
|
||||
}
|
||||
ug.apply(new UTranslate(lastx, getYpos(lastValue))).draw(ULine.hline(ruler.getWidth() - lastx));
|
||||
ug.apply(new UTranslate(lastx, getYpos(ug.getStringBounder(), lastValue)))
|
||||
.draw(ULine.hline(ruler.getWidth() - lastx));
|
||||
|
||||
drawConstraints(ug.apply(UTranslate.dy(getHeightForConstraints(ug.getStringBounder()))));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -275,8 +287,19 @@ public class PlayerAnalog extends Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StyleSignatureBasic getStyleSignature() {
|
||||
return StyleSignatureBasic.of(SName.root, SName.element, SName.timingDiagram);
|
||||
protected StyleSignature getStyleSignature() {
|
||||
return StyleSignatureBasic.of(SName.root, SName.element, SName.timingDiagram, SName.analog)
|
||||
.withTOBECHANGED(stereotype);
|
||||
}
|
||||
|
||||
private void drawConstraints(final UGraphic ug) {
|
||||
for (TimeConstraint constraint : constraints) {
|
||||
constraint.drawU(ug, ruler);
|
||||
}
|
||||
}
|
||||
|
||||
private double getHeightForConstraints(StringBounder stringBounder) {
|
||||
return TimeConstraint.getHeightForConstraints(stringBounder, constraints);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -126,6 +126,7 @@ public class PlayerBinary extends Player {
|
||||
return LOW_STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createConstraint(TimeTick tick1, TimeTick tick2, String message) {
|
||||
this.constraints.add(new TimeConstraint(tick1, tick2, message, skinParam));
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ public class PlayerClock extends Player {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createConstraint(TimeTick tick1, TimeTick tick2, String message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@ -313,8 +313,8 @@ public class TimingDiagram extends UmlDiagram implements Clocks {
|
||||
return CommandExecutionResult.ok();
|
||||
}
|
||||
|
||||
public PlayerAnalog createAnalog(String code, String full, boolean compact) {
|
||||
final PlayerAnalog player = new PlayerAnalog(full, getSkinParam(), ruler, compactByDefault);
|
||||
public PlayerAnalog createAnalog(String code, String full, boolean compact, Stereotype stereotype) {
|
||||
final PlayerAnalog player = new PlayerAnalog(full, getSkinParam(), ruler, compactByDefault, stereotype);
|
||||
players.put(code, player);
|
||||
return player;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ import net.sourceforge.plantuml.command.regex.RegexConcat;
|
||||
import net.sourceforge.plantuml.command.regex.RegexLeaf;
|
||||
import net.sourceforge.plantuml.command.regex.RegexOptional;
|
||||
import net.sourceforge.plantuml.command.regex.RegexResult;
|
||||
import net.sourceforge.plantuml.cucadiagram.Stereotype;
|
||||
import net.sourceforge.plantuml.timingdiagram.PlayerAnalog;
|
||||
import net.sourceforge.plantuml.timingdiagram.TimingDiagram;
|
||||
|
||||
@ -61,6 +62,8 @@ public class CommandAnalog extends SingleLineCommand2<TimingDiagram> {
|
||||
new RegexLeaf("analog"), //
|
||||
RegexLeaf.spaceOneOrMore(), //
|
||||
new RegexLeaf("FULL", "[%g]([^%g]+)[%g]"), //
|
||||
RegexLeaf.spaceZeroOrMore(), //
|
||||
new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), //
|
||||
RegexLeaf.spaceOneOrMore(), //
|
||||
new RegexOptional(//
|
||||
new RegexConcat( //
|
||||
@ -74,7 +77,11 @@ public class CommandAnalog extends SingleLineCommand2<TimingDiagram> {
|
||||
RegexLeaf.spaceOneOrMore())), //
|
||||
new RegexLeaf("as"), //
|
||||
RegexLeaf.spaceOneOrMore(), //
|
||||
new RegexLeaf("CODE", "([%pLN_.@]+)"), RegexLeaf.end());
|
||||
new RegexLeaf("CODE", "([%pLN_.@]+)"), //
|
||||
RegexLeaf.spaceZeroOrMore(), //
|
||||
new RegexLeaf("STEREOTYPE2", "(\\<\\<.*\\>\\>)?"), //
|
||||
RegexLeaf.spaceZeroOrMore(), //
|
||||
RegexLeaf.end());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,7 +89,14 @@ public class CommandAnalog extends SingleLineCommand2<TimingDiagram> {
|
||||
final String compact = arg.get("COMPACT", 0);
|
||||
final String code = arg.get("CODE", 0);
|
||||
final String full = arg.get("FULL", 0);
|
||||
final PlayerAnalog player = diagram.createAnalog(code, full, compact != null);
|
||||
|
||||
Stereotype stereotype = null;
|
||||
if (arg.get("STEREOTYPE", 0) != null)
|
||||
stereotype = Stereotype.build(arg.get("STEREOTYPE", 0));
|
||||
else if (arg.get("STEREOTYPE2", 0) != null)
|
||||
stereotype = Stereotype.build(arg.get("STEREOTYPE2", 0));
|
||||
|
||||
final PlayerAnalog player = diagram.createAnalog(code, full, compact != null, stereotype);
|
||||
final String start = arg.get("START", 0);
|
||||
final String end = arg.get("END", 0);
|
||||
if (start != null && end != null) {
|
||||
|
@ -80,7 +80,7 @@ public class Version {
|
||||
}
|
||||
|
||||
public static int beta() {
|
||||
final int beta = 1;
|
||||
final int beta = 2;
|
||||
return beta;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user