Java 类javax.swing.text.Highlighter.HighlightPainter 实例源码

项目:codebuff    文件:GUIController.java   
@Override
public void caretUpdate(CaretEvent e) {
    int cursor = e.getDot();
    JTextPane textPane = (JTextPane)e.getSource();
    TokenPositionAnalysis analysis = getAnalysisForCharIndex(cursor);
    Highlighter highlighter = textPane.getHighlighter();
    HighlightPainter painter = new DefaultHighlightPainter(Color.orange);
    try {
        highlighter.removeAllHighlights();
        if ( analysis!=null ) {
            highlighter.addHighlight(analysis.charIndexStart, analysis.charIndexStop+1, painter);
        }
        scope.injectNLConsole.setText(analysis!=null ? analysis.wsAnalysis : "");
        scope.injectNLConsole.setCaretPosition(0);
        scope.alignConsole.setText(analysis!=null ? analysis.alignAnalysis : "");
        scope.alignConsole.setCaretPosition(0);
    }
    catch (Exception ex) {
        ex.printStackTrace(System.err);
    }
}
项目:sos-importer    文件:Step2Panel.java   
public void setCSVFileHighlight(final int number) {
    if (logger.isTraceEnabled()) {
        logger.trace("setCSVFileHighlight()");
    }
    try {
        csvFileTextArea.getHighlighter().removeAllHighlights();
        if (number >= 0) {
            final int lineStart = csvFileTextArea.getLineStartOffset(number);
            final int lineEnd = csvFileTextArea.getLineEndOffset(csvFileRowCount-1);
            final HighlightPainter painter = new DefaultHighlighter.
                    DefaultHighlightPainter(
                            Constants.DEFAULT_HIGHLIGHT_COLOR);
            csvFileTextArea.getHighlighter().addHighlight(lineStart, lineEnd, painter);
        }
    } catch (final BadLocationException e1) {
        logger.error("Exception thrown: " + e1.getMessage(), e1);
    }
}
项目:powertext    文件:ParameterizedCompletionContext.java   
public List<Highlight> getParameterHighlights() {
    List<Highlight> paramHighlights = new ArrayList<Highlight>(2);
    JTextComponent tc = ac.getTextComponent();
    Highlight[] highlights = tc.getHighlighter().getHighlights();
    for (int i=0; i<highlights.length; i++) {
        HighlightPainter painter = highlights[i].getPainter();
        if (painter==p || painter==endingP) {
            paramHighlights.add(highlights[i]);
        }
    }
    return paramHighlights;
}
项目:powertext    文件:Main.java   
private void jMenuItem60ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem60ActionPerformed
    try {
        int selectedIndex = jTabbedPane1.getSelectedIndex();
        RSyntaxTextArea textPane = (RSyntaxTextArea) Editor.get(selectedIndex).getTextPane();
        Highlighter h = textPane.getHighlighter();
        String select = textPane.getSelectedText();String context = textPane.getText();
        String words[] = select.split(" ");
        for (int i = 0 ; i < words.length; i++) {
            String temp = words[i];
            if (temp.equals(select)){
        h.addHighlight(i, temp.length(), (HighlightPainter) Color.RED);}
    }} catch (BadLocationException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:enigma-vk    文件:CodeReader.java   
public void setHighlightedToken(Token token, HighlightPainter painter) {
    try {
        getHighlighter().addHighlight(token.start, token.end, painter);
    } catch (BadLocationException ex) {
        throw new IllegalArgumentException(ex);
    }
}
项目:Code-Glosser    文件:MarkupView.java   
public void setMarkupColor(Bounds bounds, Color color) {
    // Save the currently selected offsets
    int start = textCode.getSelectionStart();
    int end = textCode.getSelectionEnd();

    // Remove selection
    SwingUtilities.invokeLater(() -> {
        textCode.setSelectionStart(start);
        textCode.setSelectionEnd(start);
    });


    Stream.of(highlighter.getHighlights())
            // Obtain highlights which are within the requested bounds
            .filter(h -> Bounds.of(h.getStartOffset(), h.getEndOffset()).collidesWith(bounds))
            // For each highlight, we need to remove it and add it again as another color. There is no
            // way to directly change the color of a highlight once set.
            .forEach(h -> {
                Bounds b = Bounds.of(h.getStartOffset(), h.getEndOffset());

                // TODO: Race Condition!!! highlightMap is added to from UI Thread
                SwingUtilities.invokeLater(() -> {
                    highlighter.removeHighlight(h);
                    HighlightPainter hp = new DefaultHighlightPainter(ColorUtils.makeTransparent(color));
                    try {
                        Highlight h1 = (Highlight) highlighter.addHighlight(b.getStart(), b.getEnd(), hp);
                        highlightMap.put(b, h1);
                    } catch (BadLocationException ex) {
                        ex.printStackTrace();
                    }
                });
            });

    // Restore saved offsets
    if (start != 0 || end != 0) {
        SwingUtilities.invokeLater(() -> setSelection(Bounds.of(start, end)));
    }
}
项目:ftc    文件:ParameterizedCompletionContext.java   
public List<Highlight> getParameterHighlights() {
    List<Highlight> paramHighlights = new ArrayList<Highlight>(2);
    JTextComponent tc = ac.getTextComponent();
    Highlight[] highlights = tc.getHighlighter().getHighlights();
    for (int i = 0; i < highlights.length; i++) {
        HighlightPainter painter = highlights[i].getPainter();
        if (!isGftErrorHighlighting(painter) && (painter == p || painter == endingP))
            paramHighlights.add(highlights[i]);

    }

    return paramHighlights;
}
项目:ESPlorer    文件:ParameterizedCompletionContext.java   
public List<Highlight> getParameterHighlights() {
    List<Highlight> paramHighlights = new ArrayList<Highlight>(2);
    JTextComponent tc = ac.getTextComponent();
    Highlight[] highlights = tc.getHighlighter().getHighlights();
    for (int i=0; i<highlights.length; i++) {
        HighlightPainter painter = highlights[i].getPainter();
        if (painter==p || painter==endingP) {
            paramHighlights.add(highlights[i]);
        }
    }
    return paramHighlights;
}
项目:Wurst-Enigma    文件:CodeReader.java   
public void setHighlightedToken(Token token, HighlightPainter painter)
{
    try
    {
        getHighlighter().addHighlight(token.start, token.end, painter);
    }catch(BadLocationException ex)
    {
        throw new IllegalArgumentException(ex);
    }
}
项目:ESPlorer    文件:ParameterizedCompletionContext.java   
public List<Highlight> getParameterHighlights() {
    List<Highlight> paramHighlights = new ArrayList<Highlight>(2);
    JTextComponent tc = ac.getTextComponent();
    Highlight[] highlights = tc.getHighlighter().getHighlights();
    for (int i=0; i<highlights.length; i++) {
        HighlightPainter painter = highlights[i].getPainter();
        if (painter==p || painter==endingP) {
            paramHighlights.add(highlights[i]);
        }
    }
    return paramHighlights;
}
项目:twister.github.io    文件:Log.java   
public void highlite(String toFind,int rangeStart,int rangeEnd)throws Exception{
HighlightPainter myHighlighter = new MyHighlightPainter(Color.RED);
int index = textarea.getText(rangeStart, 
                                rangeEnd-rangeStart).indexOf(toFind);
textarea.setCaretPosition(0);
textarea.setCaretPosition(rangeStart);
Highlighter hilite = textarea.getHighlighter(); 
hilite.removeAllHighlights();
hilite.addHighlight(rangeStart+index,
                    rangeStart+index+toFind.length(),
                    myHighlighter);  
hilite.paint(textarea.getGraphics());}
项目:enigma-vk    文件:CodeReader.java   
public void setHighlightedTokens(Iterable<Token> tokens, HighlightPainter painter) {
    for (Token token : tokens) {
        setHighlightedToken(token, painter);
    }
}
项目:pumpernickel    文件:TextComponentHighlighter.java   
/** This reapplies highlights and AttributeSets to this text component.
 * 
 * @param text the text to format.
 * @param selectionStart the current selection start.
 * @param selectionEnd the current selection end.
 */
protected void rehighlightText(String text,int selectionStart,int selectionEnd) {
    for(Object oldHighlight : allHighlights) {
        jtc.getHighlighter().removeHighlight(oldHighlight);
    }
    allHighlights.clear();

    Token[] tokens = getTokens(text, true);
    final Map<Token, AttributeSet> tokenAttributes = new TreeMap<Token, AttributeSet>();
    Runnable changeStylesRunnable = new Runnable() {
        public void run() {                 
            removeDocumentListeners();
            try {
                Document doc = jtc.getDocument();
                if(! (doc instanceof StyledDocument)) {
                    printOnce("TextComponentHighlighter: Attributes were provided but the document does not support styled attributes.");
                    return;
                }
                SimpleAttributeSet defaultAttributes = getDefaultAttributes();

                StyledDocument d = (StyledDocument)doc;
                d.setCharacterAttributes(0, d.getLength(), defaultAttributes, true);
                if(active) {
                    for(Token token : tokenAttributes.keySet()) {
                        AttributeSet attr = tokenAttributes.get(token);
                        d.setCharacterAttributes(token.getDocumentStartIndex(), token.getLength(), attr, true);
                    }
                }
            } finally {
                addDocumentListeners();
            }
        }
    };
    try {
        if(active) {
            for(int index = 0; index<tokens.length; index++) {
                HighlightPainter painter = getHighlightPainter(tokens, index, selectionStart, selectionEnd);
                if(painter!=null) {
                    allHighlights.add(
                            jtc.getHighlighter().addHighlight( tokens[index].getDocumentStartIndex(), 
                                    tokens[index].getDocumentEndIndex(), painter) );
                }
                AttributeSet attributes = getAttributes(tokens, index, selectionStart, selectionEnd);
                if(attributes!=null) {
                    tokenAttributes.put(tokens[index], attributes);
                }
            }
        }
        SwingUtilities.invokeLater(changeStylesRunnable);
    } catch(BadLocationException e) {
        throw new RuntimeException(e);
    }
}
项目:pumpernickel    文件:TextComponentHighlighter.java   
/** @return the HighlightPainter for tokenIndex in the list of tokens. */
protected HighlightPainter getHighlightPainter(Token[] allToken,int tokenIndex,int selectionStart,int selectionEnd) {
    return null;
}
项目:ftc    文件:ParameterizedCompletionContext.java   
private boolean isGftErrorHighlighting(HighlightPainter painter) {
    return painter instanceof UnderlineHighlightPainter;
}
项目:Wurst-Enigma    文件:CodeReader.java   
public void setHighlightedTokens(Iterable<Token> tokens,
    HighlightPainter painter)
{
    for(Token token : tokens)
        setHighlightedToken(token, painter);
}
项目:jpexs-decompiler    文件:LineMarkedEditorPane.java   
@Override
public HighlightPainter linkPainter() {
    return underLinePainter;
}
项目:freeVM    文件:InstrumentedDefaultCaret.java   
protected HighlightPainter getSelectionPainter() {
    InstrumentedUILog
            .add(new Object[] { "DefaultCaret.getSelectionPainter" });
    return super.getSelectionPainter();
}
项目:ClipsMonitor    文件:ConsoleTopComponent.java   
private void SetPaneStyle(){

        painters = new HashMap<String,HighlightPainter>();

        painters.put("[ERROR]", new DefaultHighlighter.DefaultHighlightPainter(Color.red));
        painters.put("[WARN]",  new DefaultHighlighter.DefaultHighlightPainter(Color.orange));
        painters.put("[INFO]",  new DefaultHighlighter.DefaultHighlightPainter(Color.green));
        painters.put("[CLIPS]", new DefaultHighlighter.DefaultHighlightPainter(Color.blue));
        painters.put("[INTERNAL]", new DefaultHighlighter.DefaultHighlightPainter(Color.cyan));


    }