Search in sources :

Example 6 with DefaultHighlightPainter

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
        }
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent) DefaultHighlightPainter(javax.swing.text.DefaultHighlighter.DefaultHighlightPainter) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Aggregations

DefaultHighlightPainter (javax.swing.text.DefaultHighlighter.DefaultHighlightPainter)6 BadLocationException (javax.swing.text.BadLocationException)5 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)3 DefaultHighlighter (javax.swing.text.DefaultHighlighter)3 JTextComponent (javax.swing.text.JTextComponent)3 Component (java.awt.Component)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JScrollPane (javax.swing.JScrollPane)2 Highlighter (javax.swing.text.Highlighter)2 ArrayListMultiple (CCDD.CcddClassesComponent.ArrayListMultiple)1 AutoCompleteTextField (CCDD.CcddClassesComponent.AutoCompleteTextField)1 MultilineLabel (CCDD.CcddClassesComponent.MultilineLabel)1 AssociatedColumns (CCDD.CcddClassesDataTable.AssociatedColumns)1 CCDDException (CCDD.CcddClassesDataTable.CCDDException)1 MinMaxPair (CCDD.CcddClassesDataTable.MinMaxPair)1 InputDataType (CCDD.CcddConstants.InputDataType)1 InputTypeFormat (CCDD.CcddConstants.InputTypeFormat)1 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)1