}
public DiagramElement returnConnection(DiagramElement from,
DiagramElement to, Object representing, Label fromLabel,
Label toLabel, boolean arrowHead, Direction d) {
DiagramElement out = representing == null ? null : contents
.get(representing);
if (out == null) {
if ((from instanceof Connected)
&& (to instanceof Connected)) {
Connected cfrom = (Connected) from;
Connected cto = (Connected) to;
out = new Link(cfrom, cto, null, fromLabel,
arrowHead ? LinkEndStyle.ARROW : null, toLabel,
d);
} else {
throw new Kite9ProcessingException(
"Could not link between: " + from + " and "
+ to);
}
}
contents.put(representing, out);
return out;
}
/**
* Looks for an existing diagram element, or returns a new glyph
*/
public DiagramElement returnGlyph(Container within,
Object representing, String label, String stereo) {
DiagramElement out = representing == null ? null : contents
.get(representing);
if (out == null) {
within = within == null ? getDiagram() : within;
String id = idHelper.getId(representing);
out = new Glyph(id, stereo, label, null, null);
contents.put(representing, out);
within.getContents().add((Glyph) out);
((Glyph) out).setContainer(within);
}
return out;
}
public DiagramElement returnContext(Container within,
Object representing, Label overrideLabel, boolean border,
Layout d) {
DiagramElement out = representing == null ? null : contents
.get(representing);
if (out == null) {
within = within == null ? getDiagram() : within;
String id = idHelper.getId(representing);
out = new Context(id, null, border, border ? overrideLabel
: null, d);
contents.put(representing, out);
within.getContents().add((Context) out);
((Context) out).setContainer(within);
}
return out;
}
public DiagramElement returnConnectionBody(Container within,
Object representing, String label) {
DiagramElement out = representing == null ? null : contents
.get(representing);
if (out == null) {
within = within == null ? getDiagram() : within;
String id = idHelper.getId(representing);
out = new Arrow(id, label);
contents.put(representing, out);
within.getContents().add((Arrow) out);
((Arrow) out).setContainer(within);
}
return out;
}
public DiagramElement returnSymbol(DiagramElement container,
Object representing, String text, String prefs) {
DiagramElement out = representing == null ? null : contents
.get(representing);
if (out == null) {
out = symbols.get(text);
if (out == null) {
Symbol s = kh.createSymbol(text, prefs);
symbols.put(text, s);
out = s;
}
SymbolTarget st = null;
if (container instanceof Context) {
st = (TextLine) ((Context) container).getLabel();
if (st == null) {
st = new TextLine();
((Context) container).setLabel((TextLine) st);
}
} else if (container instanceof SymbolTarget) {
st = (Glyph) container;
} else if (container instanceof Link) {
// add to a label, eventually.
}
// add the symbol to the container
if ((st != null) && (!st.getSymbols().contains(out))) {
st.getSymbols().add((Symbol) out);
}
}
return out;
}
public DiagramElement returnTextLine(Glyph container,
Object representing, String text) {
DiagramElement out = representing == null ? null : contents
.get(representing);
if (out == null) {
TextLine tl = new TextLine(text);
contents.put(representing, tl);
container.getText().add(tl);
return tl;
}
return out;
}
public DiagramElement extendTextLine(TextLine container,
Object representing, String text) {
DiagramElement out = representing == null ? null : contents
.get(representing);
if (out == null) {
StyledText st = container.getText();
container.setText(new StyledText(st.getText() + text, st.getStyle()));
contents.put(representing, container);