}
@Override
public void paintInstance(InstancePainter painter) {
boolean showState = painter.getShowState();
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
painter.drawClock(CK, Direction.EAST);
if (painter.shouldDrawColor()) {
g.setColor(painter.getAttributeValue(Io.ATTR_BACKGROUND));
g.fillRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(),
10, 10);
}
GraphicsUtil.switchToWidth(g, 2);
g.setColor(Color.BLACK);
g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(),
2 * BORDER, 2 * BORDER);
GraphicsUtil.switchToWidth(g, 1);
painter.drawPort(CLR);
painter.drawPort(WE);
painter.drawPort(IN);
int rows = getRowCount(painter.getAttributeValue(ATTR_ROWS));
int cols = getColumnCount(painter.getAttributeValue(ATTR_COLUMNS));
if (showState) {
String[] rowData = new String[rows];
int curRow;
int curCol;
TtyState state = getTtyState(painter);
synchronized(state) {
for (int i = 0; i < rows; i++) {
rowData[i] = state.getRowString(i);
}
curRow = state.getCursorRow();
curCol = state.getCursorColumn();
}
g.setFont(DEFAULT_FONT);
g.setColor(painter.getAttributeValue(Io.ATTR_COLOR));
FontMetrics fm = g.getFontMetrics();
int x = bds.getX() + BORDER;
int y = bds.getY() + BORDER + (ROW_HEIGHT + fm.getAscent()) / 2;
for (int i = 0; i < rows; i++) {
g.drawString(rowData[i], x, y);
if (i == curRow) {
int x0 = x + fm.stringWidth(rowData[i].substring(0, curCol));
g.drawLine(x0, y - fm.getAscent(), x0, y);
}
y += ROW_HEIGHT;
}
} else {
String str = Strings.get("ttyDesc", "" + rows, "" + cols);
FontMetrics fm = g.getFontMetrics();
int strWidth = fm.stringWidth(str);
if (strWidth + BORDER > bds.getWidth()) {
str = Strings.get("ttyDescShort");
strWidth = fm.stringWidth(str);
}
int x = bds.getX() + (bds.getWidth() - strWidth) / 2;
int y = bds.getY() + (bds.getHeight() + fm.getAscent()) / 2;
g.drawString(str, x, y);
}
}