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 zaproxy by zaproxy.
the class CustomScanDialog method getRemoveCustomButton.
private JButton getRemoveCustomButton() {
if (removeCustomButton == null) {
removeCustomButton = new JButton(Constant.messages.getString("ascan.custom.button.pt.rem"));
removeCustomButton.setEnabled(false);
removeCustomButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
// Remove any selected injection points
int userDefStart = getRequestField().getSelectionStart();
if (userDefStart >= 0) {
int userDefEnd = getRequestField().getSelectionEnd();
Highlighter hltr = getRequestField().getHighlighter();
Highlight[] hls = hltr.getHighlights();
if (hls != null && hls.length > 0) {
for (Highlight hl : hls) {
if (selectionIncludesHighlight(userDefStart, userDefEnd, hl)) {
hltr.removeHighlight(hl);
injectionPointModel.removeElement(hl);
}
}
}
// Unselect the text
getRequestField().setSelectionStart(userDefEnd);
getRequestField().setSelectionEnd(userDefEnd);
getRequestField().getCaret().setVisible(true);
}
}
});
}
return removeCustomButton;
}
use of javax.swing.text.Highlighter in project zaproxy by zaproxy.
the class HttpPanelTextArea method highlightEntryParser.
// Parse the TextArea data and search the HighlightEntry strings
// Highlight all found strings
private void highlightEntryParser(HighlightSearchEntry entry) {
String text;
int lastPos = 0;
text = this.getText();
Highlighter hilite = this.getHighlighter();
HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(entry.getColor());
while ((lastPos = text.indexOf(entry.getToken(), lastPos)) > -1) {
try {
hilite.addHighlight(lastPos, lastPos + entry.getToken().length(), painter);
lastPos += entry.getToken().length();
} catch (BadLocationException e) {
log.warn("Could not highlight entry", e);
}
}
}
use of javax.swing.text.Highlighter in project zaproxy by zaproxy.
the class HttpPanelTextArea method removeAllHighlights.
private void removeAllHighlights() {
Highlighter hilite = this.getHighlighter();
hilite.removeAllHighlights();
}
Aggregations