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 iris by mnit-rtmc.
the class WMsgMultiPanel method highlightErrors.
/**
* Highlight any error-producing tokens
*/
public void highlightErrors(WEditorErrorManager errMan) {
if (errMan.hasErrors()) {
Highlighter h = textBox.getHighlighter();
HighlightPainter hp = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
String txt = textBox.getText();
Iterator<WEditorError> it = errMan.iterator();
while (it.hasNext()) {
WEditorError e = it.next();
if (e.hasToken()) {
String ts = e.getToken().toString();
// if this error has a token, highlight it
int a = txt.indexOf(ts);
if (a < 0)
continue;
int b = a + ts.length();
String s = txt.substring(a, b);
if (s == ts) {
try {
h.addHighlight(a, b, hp);
} catch (BadLocationException ex) {
// just ignore this
ex.printStackTrace();
}
}
}
}
}
}
use of javax.swing.text.Highlighter in project phon by phon-ca.
the class RecordDataEditorView method addSelectionHighlights.
private void addSelectionHighlights(JTextComponent textComp, int recordIndex, String tierName, int groupIndex) {
final List<SessionEditorSelection> selections = getEditor().getSelectionModel().getSelectionsForGroup(recordIndex, tierName, groupIndex);
final Highlighter hl = new GroupFieldHighlighter();
final Highlighter origHighlighter = textComp.getHighlighter();
textComp.setHighlighter(hl);
if (origHighlighter != null && origHighlighter.getHighlights().length > 0) {
for (Highlight hilight : origHighlighter.getHighlights()) try {
hl.addHighlight(hilight.getStartOffset(), hilight.getEndOffset(), hilight.getPainter());
} catch (BadLocationException e) {
LOGGER.info(e.getLocalizedMessage(), e);
}
}
for (SessionEditorSelection selection : selections) {
final Range r = selection.getGroupRange();
try {
HighlightPainter painter = selection.getExtension(HighlightPainter.class);
if (painter == null)
painter = new DefaultHighlighter.DefaultHighlightPainter(PhonGuiConstants.PHON_SELECTED);
hl.addHighlight(r.getFirst(), r.getLast() + 1, painter);
} catch (BadLocationException e) {
LOGGER.info(e.getLocalizedMessage(), e);
}
}
}
use of javax.swing.text.Highlighter in project Weasis by nroduit.
the class TagSearchDocumentPanel method showCurrentSearch.
public void showCurrentSearch(String pattern) {
if (!searchPositions.isEmpty() && StringUtil.hasText(pattern)) {
removeHighlights(textComponent);
try {
if (currentSearchIndex < 0 || currentSearchIndex >= searchPositions.size()) {
currentSearchIndex = 0;
}
int curPos = searchPositions.get(currentSearchIndex);
Highlighter highlighter = textComponent.getHighlighter();
for (Integer pos : searchPositions) {
if (pos == curPos) {
highlighter.addHighlight(pos, pos + pattern.length(), searchHighlightPainter);
} else {
highlighter.addHighlight(pos, pos + pattern.length(), searchResultHighlightPainter);
}
}
textComponent.scrollRectToVisible(textComponent.modelToView(curPos));
} catch (BadLocationException e) {
LOGGER.error("Highlight result of search", e);
}
}
}
use of javax.swing.text.Highlighter in project stringtemplate4 by antlr.
the class STViz method highlight.
protected void highlight(JTextComponent comp, int i, int j, boolean scroll) {
Highlighter highlighter = comp.getHighlighter();
highlighter.removeAllHighlights();
try {
i = toComponentPosition(comp, i);
j = toComponentPosition(comp, j);
highlighter.addHighlight(i, j + 1, DefaultHighlighter.DefaultPainter);
if (scroll) {
if (comp.getCaretPosition() < i || comp.getCaretPosition() > j) {
comp.moveCaretPosition(i);
comp.scrollRectToVisible(comp.modelToView(i));
}
}
} catch (BadLocationException ble) {
errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
}
}
Aggregations