invalidate();
}
}
public void paint(Graphics2D graphics) {
TextArea textArea = (TextArea)textAreaSkin.getComponent();
int selectionStart = textArea.getSelectionStart();
int selectionLength = textArea.getSelectionLength();
Span selectionRange = new Span(selectionStart, selectionStart + selectionLength - 1);
int paragraphOffset = paragraph.getOffset();
Span characterRange = new Span(paragraphOffset, paragraphOffset
+ paragraph.getCharacters().length() - 1);
if (selectionLength > 0
&& characterRange.intersects(selectionRange)) {
boolean focused = textArea.isFocused();
boolean editable = textArea.isEditable();
// Determine the selected and unselected areas
Area selection = textAreaSkin.getSelection();
Area selectedArea = selection.createTransformedArea(AffineTransform.getTranslateInstance(-x, -y));
Area unselectedArea = new Area();
unselectedArea.add(new Area(new Rectangle2D.Float(0, 0, width, height)));
unselectedArea.subtract(new Area(selectedArea));
// Paint the unselected text
Graphics2D unselectedGraphics = (Graphics2D)graphics.create();
unselectedGraphics.clip(unselectedArea);
paint(unselectedGraphics, focused, editable, false);
unselectedGraphics.dispose();
// Paint the selected text
Graphics2D selectedGraphics = (Graphics2D)graphics.create();
selectedGraphics.clip(selectedArea);
paint(selectedGraphics, focused, editable, true);
selectedGraphics.dispose();
} else {
paint(graphics, textArea.isFocused(), textArea.isEditable(), false);
}
}