本文整理匯總了Java中javax.swing.text.Highlighter.addHighlight方法的典型用法代碼示例。如果您正苦於以下問題:Java Highlighter.addHighlight方法的具體用法?Java Highlighter.addHighlight怎麽用?Java Highlighter.addHighlight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.Highlighter
的用法示例。
在下文中一共展示了Highlighter.addHighlight方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addHighlight
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
int start = info.start;
int end = info.end;
if (start == -1 && end == -1)
return;
if (start == -1)
start = end;
if (end == -1)
end = start;
try {
h.addHighlight(info.start, info.end,
new DefaultHighlighter.DefaultHighlightPainter(c));
if (info.pos != -1) {
Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
h.addHighlight(info.pos, info.pos + 1,
new DefaultHighlighter.DefaultHighlightPainter(c2));
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
示例2: updateSelection
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void updateSelection() {
Highlighter h = component.getHighlighter();
if (h != null) {
int p0 = Math.min(dot, mark);
int p1 = Math.max(dot, mark);
if (p0 == p1 || !selectionVisible) {
if (selectionTag != null) {
h.removeHighlight(selectionTag);
selectionTag = null;
}
} else {
try {
if (selectionTag != null) {
h.changeHighlight(selectionTag, p0, p1);
} else {
Highlighter.HighlightPainter p = getSelectionPainter();
selectionTag = h.addHighlight(p0, p1, p);
}
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
}
}
}
示例3: highlight
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
public void highlight(String pattern){
JTextComponent textComp = this.textPane;
//First remove all old highlights
removeHighlights();
try{
Highlighter hilite = textComp.getHighlighter();
Document doc = textComp.getDocument();
String text = doc.getText(0, doc.getLength());
int pos = 0;
//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(), this.highlightPainter_yellow);
pos += pattern.length();
}
}catch(Exception exp){
}
}
示例4: highlight
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
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);
}
}
示例5: highlightLocation
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
public void highlightLocation(JTextComponent textComp, String location) {
//Highlights a single location throughout the text
Highlighter.HighlightPainter locationHighlighter= new MyHighlighPainter(Color.cyan);
try{
Highlighter highlighter= textComp.getHighlighter();
highlighter.removeAllHighlights();
Document doc = textComp.getDocument();
String text = doc.getText(0, doc.getLength()).toUpperCase();
int size= location.length();
LinkedList<Integer> indeces= allIndeces(text, location.toUpperCase());
for(int i=0; i<indeces.size(); i++){
int index=indeces.get(i);
highlighter.addHighlight(index, index+size, locationHighlighter);
}
}
catch(Exception e){
e.printStackTrace();
}
}
示例6: searchWord
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private synchronized void searchWord(JTextArea textArea,String serchpattern){
Document doc = textArea.getDocument();
String targetString = null;
try {
targetString = doc.getText(0, doc.getLength());
} catch (BadLocationException e1) {
logger.debug(e1);
}
int pos = targetString.indexOf(serchpattern, movePos);
if(pos > -1){
Highlighter highlighter = textArea.getHighlighter();
try {
highlighter.addHighlight(pos, pos + serchpattern.length(), DefaultHighlighter.DefaultPainter);
textArea.setCaretPosition(pos);
movePos = pos + serchpattern.length();
} catch (BadLocationException e) {
logger.debug(e);
}
}else{
movePos = 0;
}
}
示例7: handleMatchFound
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* A search match was found.
*
* @param h the highlighter
* @param i the index of the match
* @param searchLen the length of the search string
* @param editor the text editor
* @param tfSearch the search text field
*/
private void handleMatchFound(final Highlighter h,
final int i,
final int searchLen,
final JTextArea editor,
final JTextField tfSearch)
{
lastStart = i;
lastEnd = i + searchLen;
try
{
h.addHighlight(i, lastEnd, painter);
// When a match is found, make sure the position is visible
editor.requestFocusInWindow();
editor.setCaretPosition(lastStart);
tfSearch.requestFocusInWindow();
}
catch (BadLocationException ble)
{
ble.printStackTrace();
}
}
示例8: highlight
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
public void highlight(JTextComponent textComp, String pattern) {
//remove old
try {
Highlighter hilite = textComp.getHighlighter();
Document doc = textComp.getDocument();
String text = doc.getText(0, doc.getLength()).toLowerCase();
int pos = 0;
// Search for concepts and add into the highlighter
while ((pos = text.indexOf(pattern, pos)) >= 0) {
hilite.addHighlight(pos, pos+pattern.length(), appHighlightPainter);
pos += pattern.length();
}
} catch (BadLocationException e) {
}
}
示例9: extraHighlight
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* Highlightet den Textbereich zwischen pos1 und pos2
*
* @param pos1
* @param pos2
*
* @author Christoph Lutz (D-III-ITD-5.1)
*/
private void extraHighlight(int pos1, int pos2)
{
Highlighter hl = compo.getHighlighter();
try
{
if (extraHighlightTag == null)
{
Highlighter.HighlightPainter hp =
new DefaultHighlighter.DefaultHighlightPainter(new Color(0xddddff));
extraHighlightTag = hl.addHighlight(pos1, pos2, hp);
}
else
hl.changeHighlight(extraHighlightTag, pos1, pos2);
}
catch (BadLocationException e1)
{}
}
示例10: spellCheckAllText
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
public void spellCheckAllText() throws BadLocationException {
Document doc = etc.getrSyntaxTextArea().getDocument();
if (doc != null) {
String editorText = etc.getrSyntaxTextArea().getText(0, doc.getLength());
if (editorText != null) {
Highlighter highlighter = etc.getrSyntaxTextArea().getHighlighter();
if(etc.getEditorState().isHighlighted()) {
List<RuleMatch> matches = null;
try {
matches = etc.getLangTool().check(editorText);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
//Highlight the spelling check results
for (RuleMatch match : matches) {
highlighter.addHighlight(match.getFromPos(), match.getToPos(), etc.getPainter());
}
} else {
highlighter.removeAllHighlights();
}
}
}
}
示例11: markText
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* add highlights for the given region on the given pane
*
* @param pane Editor
* @param start Start index
* @param end End index
* @param marker Marker
*/
public static void markText(JTextComponent pane, int start, int end, Highlighter.HighlightPainter marker) {
try {
Highlighter hiliter = pane.getHighlighter();
int selStart = pane.getSelectionStart();
int selEnd = pane.getSelectionEnd();
// if there is no selection or selection does not overlap
if (selStart == selEnd || end < selStart || start > selStart) {
hiliter.addHighlight(start, end, marker);
return;
}
// selection starts within the highlight, highlight before slection
if (selStart > start && selStart < end) {
hiliter.addHighlight(start, selStart, marker);
}
// selection ends within the highlight, highlight remaining
if (selEnd > start && selEnd < end) {
hiliter.addHighlight(selEnd, end, marker);
}
} catch (BadLocationException ex) {
}
}
示例12: markText
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
/**
* add highlights for the given region on the given pane
* @param pane
* @param start
* @param end
* @param marker
*/
public static void markText(JTextComponent pane, int start, int end, SimpleMarker marker) {
try {
Highlighter hiliter = pane.getHighlighter();
int selStart = pane.getSelectionStart();
int selEnd = pane.getSelectionEnd();
// if there is no selection or selection does not overlap
if(selStart == selEnd || end < selStart || start > selStart) {
hiliter.addHighlight(start, end, marker);
return;
}
// selection starts within the highlight, highlight before slection
if(selStart > start && selStart < end ) {
hiliter.addHighlight(start, selStart, marker);
}
// selection ends within the highlight, highlight remaining
if(selEnd > start && selEnd < end ) {
hiliter.addHighlight(selEnd, end, marker);
}
} catch (BadLocationException ex) {
// nothing we can do if the request is out of bound
LOG.log(Level.SEVERE, null, ex);
}
}
示例13: moveHighlight
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private static void moveHighlight(final JEditorPane editor,
final int start, final int end) {
Highlighter highlighter = editor.getHighlighter();
Object tag = highlightTags.get(highlighter);
if (tag != null) {
highlighter.removeHighlight(tag);
highlightTags.remove(highlighter);
}
try {
tag = highlighter.addHighlight(start, end,
new LinkHighlightPainter());
highlightTags.put(highlighter, tag);
editor.getCaret().setDot(start);
} catch (final BadLocationException e) {
}
}
示例14: highlightErrors
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void highlightErrors(ParsingException e) {
int txtLen = equationPad.getText().length();
List<SyntaxError> errors = e.getErrors();
for (SyntaxError err : errors) {
try {
Highlighter highlighter = equationPad.getHighlighter();
int idx = err.getStartIndex();
if (idx >= txtLen) {
idx = txtLen - 1;
}
highlighter.addHighlight(
idx,
err.getEndIndex(),
new RedLineHighlightPainter());
} catch (BadLocationException e1) {
//skip
}
}
}
示例15: check
import javax.swing.text.Highlighter; //導入方法依賴的package包/類
private void check(Element element) {
Highlighter highlighter = comp.getHighlighter();
try {
int start = element.getStartOffset();
int end = element.getEndOffset();
clear(start, end);
String elementText = element.getDocument().getText(start, end - start);
SpellCheckTokenizer tokenizer = new SpellCheckTokenizer(elementText);
while (tokenizer.hasMoreTokens()) {
SpellCheckTokenizer.Token token = tokenizer.nextToken();
int startPos = start + token.getOffset();
int endPos = startPos + token.getLength();
if (spellCheckerManager.hasProblem(token.getWord())) {
highlighter.addHighlight(startPos, endPos, zigZagPainter);
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}