// Get the width of the highlighted region
protected List<Rectangle> createHighlightAreas2(String fullText, String clippedText, FontMetrics fm, int xOffset, int yOffset, int height) {
        if (matchPattern == null) {
            return Collections.emptyList();
        }
        Matcher matcher = matchPattern.matcher(clippedText);
        List<Rectangle> highlightAreas = null;
        int startFrom = 0;
        while (startFrom < clippedText.length() && matcher.find(startFrom)) {
            if (highlightAreas == null) {
                highlightAreas = new ArrayList<Rectangle>();
            }
            int start = matcher.start();
            int end = matcher.end();
            if (start == end) {
                // empty matcher will cause infinite loop
                break;
            }
            startFrom = end;
            int highlightx;
            int highlightWidth;
            if (start == 0) {
                // start highlight from the start of the field
                highlightx = xOffset;
            } else {
                // Calculate the width of the unhighlighted text to get the
                // start of the highlighted region.
                String strToStart = clippedText.substring(0, start);
                highlightx = fm.stringWidth(strToStart) + xOffset;
            }
            // Get the width of the highlighted region
            String highlightText = clippedText.substring(start, end);
            highlightWidth = fm.stringWidth(highlightText);
            highlightAreas.add(new Rectangle(highlightx, yOffset, highlightWidth, height));
        }// while ( startFrom < text.length() && matcher.find( startFrom ) )
        if (highlightAreas == null) {
            highlightAreas = Collections.emptyList();
        } else {
            coalesceHighlightAreas(highlightAreas);
        }
        return highlightAreas;
    }
highlightx = fm.stringWidth(strToStart) + xOffset;
}
// Get the width of the highlighted region
String highlightText = clippedText.substring(start, end);
highlightWidth = fm.stringWidth(highlightText);
int highlightWidth;
if (start == 0) {
// start highlight from the start of the field
highlightx = xOffset;
} else {
// Calculate the width of the unhighlighted text to get the
// start of the highlighted region.
String strToStart = clippedText.substring(0, start);
highlightx = fm.stringWidth(strToStart) + xOffset;
}
// Get the width of the highlighted region
String highlightText = clippedText.substring(start, end);
highlightWidth = fm.stringWidth(highlightText);
highlightAreas.add(new Rectangle(highlightx, yOffset, highlightWidth, height));
}// while ( startFrom < text.length() && matcher.find( startFrom ) )
if (highlightAreas == null) {
highlightAreas = Collections.emptyList();
} else {
coalesceHighlightAreas(highlightAreas);
}
return highlightAreas;
highlightAreas = new ArrayList<Rectangle>();
}
int start = matcher.start();
int end = matcher.end();
if (start == end) {
// empty matcher will cause infinite loop
break;
}
startFrom = end;
int highlightx;
int highlightWidth;
if (start == 0) {
// start highlight from the start of the field
highlightx = xOffset;
} else {
// Calculate the width of the unhighlighted text to get the
// start of the highlighted region.
String strToStart = clippedText.substring(0, start);
highlightx = fm.stringWidth(strToStart) + xOffset;
}
// Get the width of the highlighted region
String highlightText = clippedText.substring(start, end);
highlightWidth = fm.stringWidth(highlightText);
highlightAreas.add(new Rectangle(highlightx, yOffset, highlightWidth, height));
}// while ( startFrom < text.length() && matcher.find( startFrom ) )
if (highlightAreas == null) {
highlightAreas = Collections.emptyList();
} else {
coalesceHighlightAreas(highlightAreas);
}
return highlightAreas;
}