BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int outputs = 1 << select.getWidth();
Port[] ps = new Port[outputs + (enable ? 2 : 1)];
if (outputs == 2) {
Location end0;
Location end1;
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
int y = facing == Direction.NORTH ? -10 : 10;
if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
end0 = Location.create(-30, y);
end1 = Location.create(-10, y);
} else {
end0 = Location.create(10, y);
end1 = Location.create(30, y);
}
} else {
int x = facing == Direction.WEST ? -10 : 10;
if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
end0 = Location.create(x, 10);
end1 = Location.create(x, 30);
} else {
end0 = Location.create(x, -30);
end1 = Location.create(x, -10);
}
}
ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, 1);
ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, 1);
} else {
int dx;
int ddx;
int dy;
int ddy;
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
dy = facing == Direction.NORTH ? -20 : 20;
ddy = 0;
dx = selectLoc == Plexers.SELECT_TOP_RIGHT ? -10 * outputs : 0;
ddx = 10;
} else {
dx = facing == Direction.WEST ? -20 : 20;
ddx = 0;
dy = selectLoc == Plexers.SELECT_TOP_RIGHT ? 0 : -10 * outputs;
ddy = 10;
}
for (int i = 0; i < outputs; i++) {
ps[i] = new Port(dx, dy, Port.OUTPUT, 1);
dx += ddx;
dy += ddy;
}
}
Location en = Location.create(0, 0).translate(facing, -10);
ps[outputs] = new Port(0, 0, Port.INPUT, select.getWidth());
if (enable) {
ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
}
for (int i = 0; i < outputs; i++) {
ps[i].setToolTip(Strings.getter("decoderOutTip", "" + i));
}
ps[outputs].setToolTip(Strings.getter("decoderSelectTip"));