use of javax.swing.text.Highlighter in project CCDD by nasa.
the class CcddUtilities method highlightSearchText.
/**
********************************************************************************************
* Highlight any text matching the search text 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 matching text
*
* @param searchPattern
* search pattern; can be a regular expression (Pattern)
*
* @return true if the supplied text contains a match to the specified search pattern
********************************************************************************************
*/
protected static boolean highlightSearchText(Component component, String text, Color hightlightColor, Pattern searchPattern) {
boolean hasHighlight = false;
// Check if the search pattern exists
if (searchPattern != null) {
int adjust = 0;
// Get the reference to the component's highlighter
Highlighter highlighter = ((JTextComponent) component).getHighlighter();
// Remove any existing highlighting from the text
highlighter.removeAllHighlights();
// Highlight matching search text instances. Create a highlighter painter
DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(hightlightColor);
// Check if the text is HTML tagged
if (text.startsWith("<html>")) {
// Remove the HTML tags and set the match index adjust
text = CcddUtilities.removeHTMLTags(text);
adjust = 1;
}
// Create the pattern matcher from the pattern
Matcher matcher = searchPattern.matcher(text);
// Check if there is a match in the cell value
while (matcher.find()) {
try {
// Highlight the matching text. Adjust the highlight color to account for the
// cell selection highlighting so that the matching search text is easily
// readable
highlighter.addHighlight(matcher.start() + adjust, matcher.end() + adjust, painter);
// Set the flag to indicate the text contains a match
hasHighlight = true;
} catch (BadLocationException ble) {
// Ignore highlighting failure
}
}
}
return hasHighlight;
}
use of javax.swing.text.Highlighter in project EditCalculateAndChart by mathhobbit.
the class TextAreaMouseListener method mouseExited.
@Override
public void mouseExited(MouseEvent e) {
JTextArea area = TEdit.getTextArea();
Highlighter hilite = area.getHighlighter();
Highlighter.Highlight[] hilites = hilite.getHighlights();
if (hilites != null && hilites.length > 0)
TEdit.getSwingPool().put("area.hilites", hilites);
/*
if(hilites != null&&hilites.length>0){
TEdit.setEnabled("Delete", true);
TEdit.setEnabled("Calc",true);
}
else{
TEdit.setEnabled("Delete", false);
TEdit.setEnabled("Calc",false);
}
*/
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
use of javax.swing.text.Highlighter in project constraintlayout by androidx.
the class Main2 method selectKey.
@Override
public void selectKey(String widget) throws CLParsingException {
CLKey key = CLScan.findCLKey(CLParser.parse(mMainText.getText()), widget);
clearSelectedKey();
if (key != null) {
Highlighter h = mMainText.getHighlighter();
try {
mSelectionHighlight = h.addHighlight((int) key.getStart(), (int) key.getEnd() + 1, new DefaultHighlighter.DefaultHighlightPainter(Color.PINK));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
use of javax.swing.text.Highlighter in project constraintlayout by androidx.
the class Main2 method clearSelectedKey.
@Override
public void clearSelectedKey() {
if (mSelectionHighlight == null) {
return;
}
Highlighter h = mMainText.getHighlighter();
h.removeHighlight(mSelectionHighlight);
}
use of javax.swing.text.Highlighter in project cayenne by apache.
the class JCayenneTextPane method setHighlightText.
public void setHighlightText(int lastIndex, int endIndex) throws BadLocationException {
Highlighter highlighter = pane.getHighlighter();
removeHighlightText(highlighter);
highlighter.addHighlight(lastIndex, endIndex, painter);
}
Aggregations