use of javax.swing.text.Highlighter in project jabref by JabRef.
the class JEditorPaneWithHighlighting method highlightPattern.
public void highlightPattern(Optional<Pattern> highlightPattern) {
Highlighter highlighter = getHighlighter();
highlighter.removeAllHighlights();
if ((highlightPattern == null) || !highlightPattern.isPresent()) {
return;
}
String text = getDocumentText();
Matcher matcher = highlightPattern.get().matcher(text);
LayerPainter painter = DefaultHighlighter.DefaultPainter;
while (matcher.find()) {
try {
highlighter.addHighlight(matcher.start(), matcher.end(), painter);
} catch (BadLocationException ble) {
// should not occur if matcher works right
LOGGER.warn("Highlighting not possible, bad location", ble);
}
}
}
use of javax.swing.text.Highlighter in project jabref by JabRef.
the class JTextAreaWithHighlighting method highLight.
/**
* Highlight words in the Textarea
*
* @param words to highlight
*/
private void highLight() {
// highlight all characters that appear in charsToHighlight
Highlighter highlighter = getHighlighter();
highlighter.removeAllHighlights();
if ((highlightPattern == null) || !highlightPattern.isPresent()) {
return;
}
String content = getText();
if (content.isEmpty()) {
return;
}
highlightPattern.ifPresent(pattern -> {
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
try {
highlighter.addHighlight(matcher.start(), matcher.end(), DefaultHighlighter.DefaultPainter);
} catch (BadLocationException ble) {
LOGGER.warn("Highlighting not possible, bad location", ble);
}
}
});
}
use of javax.swing.text.Highlighter in project bytecode-viewer by Konloch.
the class ClassViewer method highlight.
public void highlight(int pane, JTextComponent textComp, String pattern) {
if (pattern.isEmpty()) {
textComp.getHighlighter().removeAllHighlights();
return;
}
try {
Highlighter hilite = textComp.getHighlighter();
hilite.removeAllHighlights();
javax.swing.text.Document doc = textComp.getDocument();
String text = doc.getText(0, doc.getLength());
int pos = 0;
if ((pane == 0 && !exacts.get(0).isSelected()) || pane == 1 && !exacts.get(1).isSelected() || pane == 2 && !exacts.get(2).isSelected()) {
pattern = pattern.toLowerCase();
text = text.toLowerCase();
}
// Search for pattern
while ((pos = text.indexOf(pattern, pos)) >= 0) {
// Create highlighter using private painter and apply around
// pattern
hilite.addHighlight(pos, pos + pattern.length(), painter);
pos += pattern.length();
}
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
use of javax.swing.text.Highlighter in project bytecode-viewer by Konloch.
the class PluginConsole method highlight.
public void highlight(JTextComponent textComp, String pattern) {
if (pattern.isEmpty()) {
textComp.getHighlighter().removeAllHighlights();
return;
}
try {
Highlighter hilite = textComp.getHighlighter();
hilite.removeAllHighlights();
javax.swing.text.Document doc = textComp.getDocument();
String text = doc.getText(0, doc.getLength());
int pos = 0;
if (!check.isSelected()) {
pattern = pattern.toLowerCase();
text = text.toLowerCase();
}
// Search for pattern
while ((pos = text.indexOf(pattern, pos)) >= 0) {
// Create highlighter using private painter and apply around
// pattern
hilite.addHighlight(pos, pos + pattern.length(), painter);
pos += pattern.length();
}
} catch (Exception e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
use of javax.swing.text.Highlighter in project zaproxy by zaproxy.
the class CustomScanDialog method getAddCustomButton.
private JButton getAddCustomButton() {
if (addCustomButton == null) {
addCustomButton = new JButton(Constant.messages.getString("ascan.custom.button.pt.add"));
addCustomButton.setEnabled(false);
addCustomButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
// Add the selected injection point
int userDefStart = getRequestField().getSelectionStart();
if (userDefStart >= 0) {
int userDefEnd = getRequestField().getSelectionEnd();
Highlighter hl = getRequestField().getHighlighter();
HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
try {
Highlight hlt = (Highlight) hl.addHighlight(userDefStart, userDefEnd, painter);
injectionPointModel.addElement(hlt);
// Unselect the text
getRequestField().setSelectionStart(userDefEnd);
getRequestField().setSelectionEnd(userDefEnd);
getRequestField().getCaret().setVisible(true);
} catch (BadLocationException e1) {
logger.error(e1.getMessage(), e1);
}
}
}
});
}
return addCustomButton;
}
Aggregations