mirror of
https://github.com/octoleo/plantuml.git
synced 2025-01-31 11:08:33 +00:00
Add entities, attributes and relations to graph
This commit is contained in:
parent
4e3d8c94f6
commit
07b25de38a
@ -34,32 +34,21 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.cheneer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.sourceforge.plantuml.FileFormatOption;
|
||||
import net.sourceforge.plantuml.TitledDiagram;
|
||||
import net.atmp.CucaDiagram;
|
||||
import net.sourceforge.plantuml.abel.Entity;
|
||||
import net.sourceforge.plantuml.core.DiagramDescription;
|
||||
import net.sourceforge.plantuml.core.ImageData;
|
||||
import net.sourceforge.plantuml.core.UmlSource;
|
||||
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
|
||||
import net.sourceforge.plantuml.klimt.font.StringBounder;
|
||||
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
|
||||
import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock;
|
||||
import net.sourceforge.plantuml.klimt.shape.TextBlock;
|
||||
import net.sourceforge.plantuml.klimt.shape.TextBlockUtils;
|
||||
import net.sourceforge.plantuml.skin.UmlDiagramType;
|
||||
|
||||
public class ChenEerDiagram extends TitledDiagram {
|
||||
public class ChenEerDiagram extends CucaDiagram {
|
||||
|
||||
public ChenEerDiagram(UmlSource source, Map<String, String> skinParam) {
|
||||
super(source, UmlDiagramType.CHEN_EER, skinParam);
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,26 +57,30 @@ public class ChenEerDiagram extends TitledDiagram {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImageData exportDiagramNow(OutputStream os, int index, FileFormatOption fileFormatOption)
|
||||
throws IOException {
|
||||
return createImageBuilder(fileFormatOption).drawable(getTextBlock()).write(os);
|
||||
protected final List<String> getDotStrings() {
|
||||
return Arrays.asList("nodesep=.20;", "ranksep=0.4;", "edge [fontsize=11,labelfontsize=11];",
|
||||
"node [fontsize=11];");
|
||||
}
|
||||
|
||||
private void drawInternal(UGraphic ug) {
|
||||
// TODO
|
||||
private final Stack<Entity> ownerStack = new Stack<Entity>();
|
||||
|
||||
public void pushOwner(Entity group) {
|
||||
ownerStack.push(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextBlock getTextBlock() {
|
||||
return new AbstractTextBlock() {
|
||||
public void drawU(UGraphic ug) {
|
||||
drawInternal(ug);
|
||||
}
|
||||
public boolean popOwner() {
|
||||
if (ownerStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
ownerStack.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
public XDimension2D calculateDimension(StringBounder stringBounder) {
|
||||
return TextBlockUtils.getMinMax(getTextBlock(), stringBounder, true).getDimension();
|
||||
}
|
||||
};
|
||||
public Entity peekOwner() {
|
||||
if (ownerStack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return ownerStack.peek();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,10 +35,14 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.cheneer.command;
|
||||
|
||||
import net.sourceforge.plantuml.abel.Entity;
|
||||
import net.sourceforge.plantuml.abel.LeafType;
|
||||
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||
import net.sourceforge.plantuml.command.SingleLineCommand2;
|
||||
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||
import net.sourceforge.plantuml.klimt.creole.Display;
|
||||
import net.sourceforge.plantuml.plasma.Quark;
|
||||
import net.sourceforge.plantuml.regex.IRegex;
|
||||
import net.sourceforge.plantuml.regex.RegexConcat;
|
||||
import net.sourceforge.plantuml.regex.RegexLeaf;
|
||||
@ -84,11 +88,26 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandExecutionResult executeArg(ChenEerDiagram system, LineLocation location, RegexResult arg)
|
||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
||||
throws NoSuchColorException {
|
||||
final String name = arg.get("NAME", 0);
|
||||
final LeafType type = LeafType.OBJECT;
|
||||
final String name = diagram.cleanId(arg.get("NAME", 0));
|
||||
final boolean composite = arg.get("COMPOSITE") != null;
|
||||
|
||||
System.out.println("attribute " + name);
|
||||
final Quark<Entity> quark = diagram.quarkInContext(true, name);
|
||||
Entity entity = quark.getData();
|
||||
|
||||
if (entity == null) {
|
||||
Display display = Display.getWithNewlines(name);
|
||||
entity = diagram.reallyCreateLeaf(quark, display, type, null);
|
||||
} else {
|
||||
if (entity.muteToType(type, null) == false)
|
||||
return CommandExecutionResult.error("Bad name");
|
||||
}
|
||||
|
||||
if (composite) {
|
||||
diagram.pushOwner(entity);
|
||||
}
|
||||
|
||||
return CommandExecutionResult.ok();
|
||||
}
|
||||
|
@ -35,10 +35,14 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.cheneer.command;
|
||||
|
||||
import net.sourceforge.plantuml.abel.Entity;
|
||||
import net.sourceforge.plantuml.abel.LeafType;
|
||||
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||
import net.sourceforge.plantuml.command.SingleLineCommand2;
|
||||
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||
import net.sourceforge.plantuml.klimt.creole.Display;
|
||||
import net.sourceforge.plantuml.plasma.Quark;
|
||||
import net.sourceforge.plantuml.regex.IRegex;
|
||||
import net.sourceforge.plantuml.regex.RegexConcat;
|
||||
import net.sourceforge.plantuml.regex.RegexLeaf;
|
||||
@ -62,11 +66,23 @@ public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandExecutionResult executeArg(ChenEerDiagram system, LineLocation location, RegexResult arg)
|
||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
||||
throws NoSuchColorException {
|
||||
final String name = arg.get("NAME", 0);
|
||||
final LeafType type = LeafType.OBJECT;
|
||||
final String name = diagram.cleanId(arg.get("NAME", 0));
|
||||
|
||||
System.out.println("entity " + name);
|
||||
final Quark<Entity> quark = diagram.quarkInContext(true, name);
|
||||
Entity entity = quark.getData();
|
||||
|
||||
if (entity == null) {
|
||||
Display display = Display.getWithNewlines(name);
|
||||
entity = diagram.reallyCreateLeaf(quark, display, type, null);
|
||||
} else {
|
||||
if (entity.muteToType(type, null) == false)
|
||||
return CommandExecutionResult.error("Bad name");
|
||||
}
|
||||
|
||||
diagram.pushOwner(entity);
|
||||
|
||||
return CommandExecutionResult.ok();
|
||||
}
|
||||
|
@ -35,10 +35,14 @@
|
||||
*/
|
||||
package net.sourceforge.plantuml.cheneer.command;
|
||||
|
||||
import net.sourceforge.plantuml.abel.Entity;
|
||||
import net.sourceforge.plantuml.abel.LeafType;
|
||||
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||
import net.sourceforge.plantuml.command.SingleLineCommand2;
|
||||
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||
import net.sourceforge.plantuml.klimt.creole.Display;
|
||||
import net.sourceforge.plantuml.plasma.Quark;
|
||||
import net.sourceforge.plantuml.regex.IRegex;
|
||||
import net.sourceforge.plantuml.regex.RegexConcat;
|
||||
import net.sourceforge.plantuml.regex.RegexLeaf;
|
||||
@ -62,11 +66,23 @@ public class CommandCreateRelationship extends SingleLineCommand2<ChenEerDiagram
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandExecutionResult executeArg(ChenEerDiagram system, LineLocation location, RegexResult arg)
|
||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
|
||||
throws NoSuchColorException {
|
||||
final String name = arg.get("NAME", 0);
|
||||
final LeafType type = LeafType.OBJECT;
|
||||
final String name = diagram.cleanId(arg.get("NAME", 0));
|
||||
|
||||
System.out.println("relationship " + name);
|
||||
final Quark<Entity> quark = diagram.quarkInContext(true, name);
|
||||
Entity entity = quark.getData();
|
||||
|
||||
if (entity == null) {
|
||||
Display display = Display.getWithNewlines(name);
|
||||
entity = diagram.reallyCreateLeaf(quark, display, type, null);
|
||||
} else {
|
||||
if (entity.muteToType(type, null) == false)
|
||||
return CommandExecutionResult.error("Bad name");
|
||||
}
|
||||
|
||||
diagram.pushOwner(entity);
|
||||
|
||||
return CommandExecutionResult.ok();
|
||||
}
|
||||
|
@ -58,7 +58,9 @@ public class CommandEndGroup extends SingleLineCommand2<ChenEerDiagram> {
|
||||
|
||||
@Override
|
||||
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg) {
|
||||
// TODO
|
||||
if (!diagram.popOwner()) {
|
||||
return CommandExecutionResult.error("Unbalanced brackets");
|
||||
}
|
||||
return CommandExecutionResult.ok();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user