return alignmentDeltaX;
}
@Override
public void paint(Graphics2D graphics) {
TextInput textInput = (TextInput)getComponent();
int width = getWidth();
int height = getHeight();
Color backgroundColorLocal;
Color borderColorLocal;
Color bevelColorLocal;
if (textInput.isEnabled()) {
if (textInput.isTextValid()) {
backgroundColorLocal = this.backgroundColor;
bevelColorLocal = this.bevelColor;
} else {
backgroundColorLocal = invalidBackgroundColor;
bevelColorLocal = invalidBevelColor;
}
borderColorLocal = this.borderColor;
} else {
backgroundColorLocal = disabledBackgroundColor;
borderColorLocal = disabledBorderColor;
bevelColorLocal = disabledBevelColor;
}
graphics.setStroke(new BasicStroke());
// Paint the background
graphics.setColor(backgroundColorLocal);
graphics.fillRect(0, 0, width, height);
// Paint the bevel
graphics.setColor(bevelColorLocal);
GraphicsUtilities.drawLine(graphics, 0, 0, width, Orientation.HORIZONTAL);
// Paint the content
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
LineMetrics lm = font.getLineMetrics("", fontRenderContext);
float ascent = lm.getAscent();
float textHeight = lm.getHeight();
String prompt = textInput.getPrompt();
Color caretColor;
int alignmentDeltaX = getAlignmentDeltaX();
int xpos = padding.left - scrollLeft + 1 + alignmentDeltaX;
if (glyphVector == null
&& prompt != null) {
graphics.setFont(font);
graphics.setColor(promptColor);
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
fontRenderContext.getAntiAliasingHint());
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
fontRenderContext.getFractionalMetricsHint());
graphics.drawString(prompt, xpos,
(height - textHeight) / 2 + ascent);
caretColor = color;
} else {
boolean textValid = textInput.isTextValid();
Color colorLocal;
if (textInput.isEnabled()) {
if (!textValid) {
colorLocal = invalidColor;
} else {
colorLocal = this.color;
}
} else {
colorLocal = disabledColor;
}
caretColor = colorLocal;
if (glyphVector != null) {
graphics.setFont(font);
if (selection == null) {
// Paint the text
graphics.setColor(colorLocal);
graphics.drawGlyphVector(glyphVector, xpos,
(height - textHeight) / 2 + ascent);
} else {
// Paint the unselected text
Area unselectedArea = new Area();
unselectedArea.add(new Area(new Rectangle(0, 0, width, height)));
unselectedArea.subtract(new Area(selection));
Graphics2D textGraphics = (Graphics2D)graphics.create();
textGraphics.setColor(colorLocal);
textGraphics.clip(unselectedArea);
textGraphics.drawGlyphVector(glyphVector, xpos,
(height - textHeight) / 2 + ascent);
textGraphics.dispose();
// Paint the selection
Color selectionColorLocal;
Color selectionBackgroundColorLocal;
if (textInput.isFocused() && textInput.isEditable()) {
selectionColorLocal = this.selectionColor;
selectionBackgroundColorLocal = this.selectionBackgroundColor;
} else {
selectionColorLocal = inactiveSelectionColor;
selectionBackgroundColorLocal = inactiveSelectionBackgroundColor;
}
graphics.setColor(selectionBackgroundColorLocal);
graphics.fill(selection);
Graphics2D selectedTextGraphics = (Graphics2D)graphics.create();
selectedTextGraphics.setColor(selectionColorLocal);
selectedTextGraphics.clip(selection.getBounds());
selectedTextGraphics.drawGlyphVector(glyphVector, xpos,
(height - textHeight) / 2 + ascent);
selectedTextGraphics.dispose();
}
}
}
// Paint the caret
if (selection == null
&& caretOn
&& textInput.isFocused()) {
graphics.setColor(caretColor);
graphics.fill(caret);
}
// Paint the border