private void configurePorts(Instance instance) {
BitWidth widthObj = instance.getAttributeValue(StdAttr.WIDTH);
int width = widthObj.getWidth();
Boolean parallelObj = instance.getAttributeValue(ATTR_LOAD);
Bounds bds = instance.getBounds();
Port[] ps;
if (parallelObj == null || parallelObj.booleanValue()) {
Integer lenObj = instance.getAttributeValue(ATTR_LENGTH);
int len = lenObj == null ? 8 : lenObj.intValue();
ps = new Port[6 + 2 * len];
ps[LD] = new Port(10, -20, Port.INPUT, 1);
ps[LD].setToolTip(Strings.getter("shiftRegLoadTip"));
for (int i = 0; i < len; i++) {
ps[6 + 2 * i] = new Port(20 + 10 * i, -20, Port.INPUT, width);
ps[6 + 2 * i + 1] = new Port(20 + 10 * i, 20, Port.OUTPUT, width);
}
} else {
ps = new Port[5];
}
ps[OUT] = new Port(bds.getWidth(), 0, Port.OUTPUT, width);
ps[SH] = new Port( 0, -10, Port.INPUT, 1);
ps[IN] = new Port( 0, 0, Port.INPUT, width);
ps[CK] = new Port( 0, 10, Port.INPUT, 1);
ps[CLR] = new Port(10, 20, Port.INPUT, 1);
ps[OUT].setToolTip(Strings.getter("shiftRegOutTip"));
ps[SH].setToolTip(Strings.getter("shiftRegShiftTip"));
ps[IN].setToolTip(Strings.getter("shiftRegInTip"));
ps[CK].setToolTip(Strings.getter("shiftRegClockTip"));
ps[CLR].setToolTip(Strings.getter("shiftRegClearTip"));
instance.setPorts(ps);
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT,
bds.getX() + bds.getWidth() / 2,
bds.getY() + bds.getHeight() / 4,
GraphicsUtil.H_CENTER, GraphicsUtil.V_CENTER);
}