use of javax.swing.text.Highlighter in project hextractor by sewave.
the class HexViewer method refreshSelection.
/**
* Refresh selection.
*/
private void refreshSelection() {
hexTextArea.setCaretPosition(asciiTextArea.getCaretPosition() * Constants.HEX_VALUE_SIZE);
Highlighter highlighterHex = hexTextArea.getHighlighter();
highlighterHex.removeAllHighlights();
try {
highlighterHex.addHighlight(hexTextArea.getCaretPosition(), hexTextArea.getCaretPosition() + Constants.HEX_VALUE_SIZE - 1, BLUE_PAINTER);
} catch (BadLocationException e1) {
// Do nothing
}
Highlighter highlighterAscii = asciiTextArea.getHighlighter();
highlighterAscii.removeAllHighlights();
try {
highlighterAscii.addHighlight(asciiTextArea.getCaretPosition(), asciiTextArea.getCaretPosition() + 1, BLUE_PAINTER);
for (OffsetEntry entry : offEntries) {
drawOffsetEntry(entry, highlighterAscii, LGRAY_PAINTER, ORANGE_PAINTER);
}
if (currEntry.getStart() > 0 && currEntry.getStart() - offset >= 0) {
highlighterAscii.addHighlight(currEntry.getStart() - offset, currEntry.getStart() - offset + 1, YELLOW_PAINTER);
}
if (currEntry.getEnd() > 0 && currEntry.getEnd() - offset >= 0) {
highlighterAscii.addHighlight(currEntry.getEnd() - offset, currEntry.getEnd() - offset + 1, ORANGE_PAINTER);
}
} catch (BadLocationException e1) {
Utils.log("Bad location.");
}
offsetLabelValue.setText(getOffsetLabelValue());
}
use of javax.swing.text.Highlighter in project netbeans-rcp-lite by outersky.
the class ColorHighlighter method highlight.
public int highlight(String word) {
Highlighter highlighter = comp.getHighlighter();
// remove old highlight before applying new one
for (Highlighter.Highlight h : highlighter.getHighlights()) {
if (h.getPainter() instanceof ColorHighlightPainter) {
highlighter.removeHighlight(h);
}
}
if (word == null || word.equals("")) {
return -1;
}
// search for the word, case insentitive
String content = null;
try {
Document d = comp.getDocument();
content = d.getText(0, d.getLength()).toLowerCase();
} catch (BadLocationException e) {
return -1;
}
word = word.toLowerCase();
int lastIndex = 0;
int firstOffset = -1;
int wordSize = word.length();
while ((lastIndex = content.indexOf(word, lastIndex)) != -1) {
int endIndex = lastIndex + wordSize;
try {
highlighter.addHighlight(lastIndex, endIndex, painter);
} catch (BadLocationException ex) {
// ignore
}
if (firstOffset == -1) {
firstOffset = lastIndex;
}
lastIndex = endIndex;
}
return firstOffset;
}
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);
}
}
Aggregations