use of javax.swing.text.DefaultHighlighter.DefaultHighlightPainter in project CCDD by nasa.
the class CcddMacroHandler method highlightMacro.
/**
********************************************************************************************
* Highlight any macros in the the specified text component
*
* @param component
* reference to the table cell renderer component
*
* @param text
* cell value
*
* @param hightlightColor
* color used for highlighting the macro name
********************************************************************************************
*/
protected void highlightMacro(Component component, String text, Color hightlightColor) {
// Get a reference to the highlighter
Highlighter highlighter = ((JTextComponent) component).getHighlighter();
// Create a highlighter painter
DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(hightlightColor);
// Remove any existing highlighting
highlighter.removeAllHighlights();
// Step through each macro location
for (MacroLocation location : getMacroLocation(text)) {
try {
// Highlight the macro name in the text
highlighter.addHighlight(location.getStart(), location.getStart() + location.getMacroName().length(), painter);
} catch (BadLocationException ble) {
// Ignore highlighting failure
}
}
}
Aggregations