if (showState) {
String str;
int dispStart;
int dispEnd;
ArrayList<Integer> specials = new ArrayList<Integer>();
FontMetrics fm = null;
KeyboardData state = getKeyboardState(painter);
synchronized(state) {
str = state.toString();
for (int i = state.getNextSpecial(0); i >= 0; i = state.getNextSpecial(i + 1)) {
char c = state.getChar(i);
specials.add(Integer.valueOf(c << 16 | i));
}
if (!state.isDisplayValid()) {
fm = g.getFontMetrics(DEFAULT_FONT);
state.updateDisplay(fm);
}
dispStart = state.getDisplayStart();
dispEnd = state.getDisplayEnd();
}
if (str.length() > 0) {
Bounds bds = painter.getBounds();
drawBuffer(g, fm, str, dispStart, dispEnd, specials, bds);
}
} else {
Bounds bds = painter.getBounds();
int len = getBufferLength(painter.getAttributeValue(ATTR_BUFFER));
String str = Strings.get("keybDesc", "" + len);
FontMetrics fm = g.getFontMetrics();
int x = bds.getX() + (WIDTH - fm.stringWidth(str)) / 2;
int y = bds.getY() + (HEIGHT + fm.getAscent()) / 2;
g.drawString(str, x, y);
}
}