public void layout() {
// No-op
}
public void paint(Graphics2D graphics) {
TextInput textInput = (TextInput)getComponent();
int width = getWidth();
int height = getHeight();
Color backgroundColor;
Color borderColor;
Color bevelColor;
if (textInput.isEnabled()) {
if (textInput.isTextValid()) {
backgroundColor = this.backgroundColor;
bevelColor = this.bevelColor;
} else {
backgroundColor = invalidBackgroundColor;
bevelColor = invalidBevelColor;
}
borderColor = this.borderColor;
} else {
backgroundColor = disabledBackgroundColor;
borderColor = disabledBorderColor;
bevelColor = disabledBevelColor;
}
graphics.setStroke(new BasicStroke());
// Paint the background
graphics.setPaint(backgroundColor);
graphics.fillRect(0, 0, width, height);
// Paint the bevel
graphics.setPaint(bevelColor);
graphics.drawLine(1, 1, width - 2, 1);
// Paint the border
graphics.setPaint(borderColor);
graphics.drawRect(0, 0, width - 1, height - 1);
// Paint the content
String text = getText();
boolean prompt = false;
if (text.length() == 0
&& !textInput.isFocused()) {
text = textInput.getPrompt();
if (text == null) {
text = "";
} else {
prompt = true;
}
}
boolean textValid = textInput.isTextValid();
LineMetrics lm = font.getLineMetrics("", fontRenderContext);
int ascent = Math.round(lm.getAscent());
graphics.translate(padding.left - scrollLeft + 1, padding.top + ascent + 1);
if (text.length() > 0) {
// Paint the text
if (fontRenderContext.isAntiAliased()) {
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
Platform.getTextAntialiasingHint());
}
if (fontRenderContext.usesFractionalMetrics()) {
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}
Color color;
if (textInput.isEnabled()) {
if (prompt) {
color = promptColor;
} else if (!textValid) {
color = invalidColor;
} else {
color = this.color;
}
} else {
color = disabledColor;
}
graphics.setFont(font);
graphics.setPaint(color);
graphics.drawString(text, 0, 0);
if (textInput.getSelectionLength() > 0) {
// Paint the selection
Graphics2D selectionGraphics = (Graphics2D)graphics.create();
selectionGraphics.clip(logicalHighlightShape.getBounds());
Color selectionColor;
Color selectionBackgroundColor;
if (textInput.isFocused()) {
selectionColor = this.selectionColor;
selectionBackgroundColor = this.selectionBackgroundColor;
} else {
selectionColor = inactiveSelectionColor;
selectionBackgroundColor = inactiveSelectionBackgroundColor;
}
selectionGraphics.setPaint(selectionBackgroundColor);
selectionGraphics.fill(logicalHighlightShape);
selectionGraphics.setPaint(selectionColor);
selectionGraphics.drawString(text, 0, 0);
selectionGraphics.dispose();
}
}
if (textInput.getSelectionLength() == 0
&& textInput.isFocused()
&& caretOn) {
Color color;
if (!textValid) {
color = invalidColor;
} else {