ps[CS].setToolTip(Strings.getter("memCSTip"));
}
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
// draw boundary
painter.drawBounds();
// draw contents
if (painter.getShowState()) {
MemState state = getState(painter);
state.paint(painter.getGraphics(), bds.getX(), bds.getY());
} else {
BitWidth addr = painter.getAttributeValue(ADDR_ATTR);
int addrBits = addr.getWidth();
int bytes = 1 << addrBits;
String label;
if (this instanceof Rom) {
if (addrBits >= 30) {
label = StringUtil.format(Strings.get("romGigabyteLabel"), ""
+ (bytes >>> 30));
} else if (addrBits >= 20) {
label = StringUtil.format(Strings.get("romMegabyteLabel"), ""
+ (bytes >> 20));
} else if (addrBits >= 10) {
label = StringUtil.format(Strings.get("romKilobyteLabel"), ""
+ (bytes >> 10));
} else {
label = StringUtil.format(Strings.get("romByteLabel"), ""
+ bytes);
}
} else {
if (addrBits >= 30) {
label = StringUtil.format(Strings.get("ramGigabyteLabel"), ""
+ (bytes >>> 30));
} else if (addrBits >= 20) {
label = StringUtil.format(Strings.get("ramMegabyteLabel"), ""
+ (bytes >> 20));
} else if (addrBits >= 10) {
label = StringUtil.format(Strings.get("ramKilobyteLabel"), ""
+ (bytes >> 10));
} else {
label = StringUtil.format(Strings.get("ramByteLabel"), ""
+ bytes);
}
}
GraphicsUtil.drawCenteredText(g, label, bds.getX() + bds.getWidth()
/ 2, bds.getY() + bds.getHeight() / 2);
}
// draw input and output ports
painter.drawPort(DATA, Strings.get("ramDataLabel"), Direction.WEST);
painter.drawPort(ADDR, Strings.get("ramAddrLabel"), Direction.EAST);
g.setColor(Color.GRAY);
painter.drawPort(CS, Strings.get("ramCSLabel"), Direction.SOUTH);
}