Reputation: 1607
I am having list of nodes to be drawn.Here Node means RectangleFigure
. So, all these nodes are plotted first on canvas(FigureCanvas
)
Then I have a map maintained having dependency relations between nodes drawn earlier.
In the map, keys are the nodes and values are nothing but a list of nodes maintained.
e.g. There are 3 nodes, [ClassA, ClassB, InterfaceC]
I have them drawn on a canvas.
And my map is like below:
[ClassA=[ClassB], ClassB=[InterfaceC]]
So, it means ClassA extends ClassB
and ClassB implements InterfaceC
.
Now, I want to draw PolylineConnection
in between the nodes drawn already ,using the map maintained.
So, how can I proceed for this?
Any pointers are really appreciated, Thanks in advance!
Upvotes: 0
Views: 235
Reputation: 1607
Tried ways to solve the problem, and it worked. So, adding answer for the own question.
Steps are as below:-
1. Consider the example in the question itself.
There are 3 nodes, [ClassA, ClassB, InterfaceC]
and we have a map of relations in these nodes as
[ClassA=[ClassB], ClassB=[InterfaceC]]
means ClassA extends ClassB
and
ClassB implements InterfaceC
.
PolylineConnection
.Anchors
The logic for fetching node is as below:-
RectangleFigure
(node) then comparing the label given to it we can fetch the node required.Code snippet for more clarification
private RectangleFigure fetchNode(String node_label) {
RectangleFigure emptyNode = new RectangleFigure();
// get the list of nodes drawn on canvas
@SuppressWarnings("rawtypes")
List childrens = panel.getChildren(); //private IFigure panel;
for (int count = 0; count < childrens.size(); count++) {
if (childrens.get(count) instanceof RectangleFigure) {
RectangleFigure node = (RectangleFigure) childrens.get(count);
@SuppressWarnings("rawtypes")
List node_children = node.getChildren();
for (int count2 = 0; count2 < node_children.size(); count2++) {
if (node_children.get(count2) instanceof Label) {
Label lbl = (Label) node_children.get(count2);
if (lbl.getText().equals(node_label)) {
return node;
}
}
}
}
}
return emptyNode;
}
Upvotes: 1
Reputation: 6987
There are many examples as part of the draw2d project. Check the details here: http://nyssen.blogspot.de/2010/12/draw2d-examples-hidden-treasure.html
Upvotes: 1