//Copyright (c)2005 Holobloc Inc.
//Contributed to the OOONEIDA FBench project under the Common Public License.
package fbench.graph.model;
import java.util.Vector;
import fbench.graph.GraphElement;
import fbench.graph.InputPrimitive;
import fbench.graph.ServiceBounds;
import fbench.graph.ServiceLink;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* A GraphModel for an IEC 61499 ServiceSequence Element.
*
* @author JHC
* @version 20051103/JHC
*/
public class ServiceSequence extends GraphModel {
public ServiceSequence() {
super();
}
public ServiceSequence(Element el) {
super(el);
}
public Vector getGraph() {
Vector ans = new Vector();
fbench.graph.ServiceSequence ss = new fbench.graph.ServiceSequence(getElement());
ans.addElement(ss);
int w = ss.getComponent(1).getPreferredSize().width;
int x1 = w;
NodeList trans = getElement().getChildNodes();
InputPrimitive pred = null, succ = null;
for (int i = 0; i < trans.getLength(); i++) {
NodeList prims = trans.item(i).getChildNodes();
for (int j = 0; j < prims.getLength(); j++) {
succ = (InputPrimitive) GraphElement.forElement((Element) prims
.item(j));
ans.add(succ);
x1 = Math.max(x1, succ.getPreferredSize().width);
if (j > 0)
ans.add(new ServiceLink(pred, succ));
pred = succ;
}
}
ss.setPreferredLocation(x1 - w, 0);
int x2 = x1 + ss.getComponent(2).getPreferredSize().width;
int y = ss.getPreferredSize().height;
for (int i = 1; i < ans.size(); i++) {
Object el = ans.elementAt(i);
if (!(el instanceof InputPrimitive))
continue;
InputPrimitive prim = (InputPrimitive) el;
int x = prim.isLeftInterface() ? x1 - prim.getPreferredSize().width
: x2;
prim.setPreferredLocation(x, y);
y += prim.getPreferredSize().height;
}
ans.add(new ServiceBounds(ss,succ));
return ans;
}
}