當前位置: 首頁>>代碼示例>>Java>>正文


Java Highlighter.addHighlight方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:TreePosTest.java

示例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);
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:CaretFloatingPointAPITest.java

示例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){

    }
}
 
開發者ID:fcpauldiaz,項目名稱:Compilador,代碼行數:22,代碼來源:TextPanel.java

示例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);
    }
}
 
開發者ID:antlr,項目名稱:codebuff,代碼行數:19,代碼來源:STViz.java

示例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();
	}
}
 
開發者ID:rkhatib,項目名稱:topotext,代碼行數:21,代碼來源:HighlighterImplementation.java

示例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;
    }
}
 
開發者ID:OgaworldEX,項目名稱:ORS,代碼行數:25,代碼來源:AttackResultFrame.java

示例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();
  }
}
 
開發者ID:argonium,項目名稱:jarman,代碼行數:32,代碼來源:TextPopup.java

示例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) {
    }
}
 
開發者ID:Blulab-Utah,項目名稱:ConText,代碼行數:17,代碼來源:smallFrame.java

示例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)
  {}
}
 
開發者ID:WollMux,項目名稱:WollMux,代碼行數:26,代碼來源:TextComponentTags.java

示例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();
            }
        }
    }        
}
 
開發者ID:sebbrudzinski,項目名稱:Open-LaTeX-Studio,代碼行數:25,代碼來源:SpellCheckService.java

示例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) {

    }
}
 
開發者ID:jindrapetrik,項目名稱:jpexs-decompiler,代碼行數:32,代碼來源:MyMarkers.java

示例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);
    }
}
 
開發者ID:jindrapetrik,項目名稱:jpexs-decompiler,代碼行數:32,代碼來源:Markers.java

示例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) {
    }
}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:17,代碼來源:HTMLEditorKit.java

示例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
        }
    }
}
 
開發者ID:oleksiyp,項目名稱:equal5,代碼行數:20,代碼來源:SyntaxErrorDisplay.java

示例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();
    }
}
 
開發者ID:janotav,項目名稱:ali-idea-plugin,代碼行數:24,代碼來源:SpellCheckDocumentListener.java


注:本文中的javax.swing.text.Highlighter.addHighlight方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。