Package javax.swing.text

Examples of javax.swing.text.Highlighter$HighlightPainter


    return false;
  }
 
  @Override
  public void update(PseucoObservable obj, Object ... args) {
    Highlighter hLiter= input.getHighlighter();
    Highlighter.HighlightPainter painter= new DefaultHighlighter.DefaultHighlightPainter(Color.GREEN);
    input.getHighlighter().removeAllHighlights();
   
    String file= (String) args[0];
    int line= (int) args[1];
    int startPos= 0, endPos= 0;
    String text= input.getText();
   
    if (line == -1 || file == null)
      return;
   
    for (int i= 0; i < line; i++) {
      startPos= text.indexOf('\n', startPos) + 1;
    }
    endPos= text.indexOf('\n', startPos) + 1;

    try {
      hLiter.addHighlight(startPos, endPos, painter);
    } catch (BadLocationException e) {
      // ignore it, but clear everything. This has to do with
      // not knowing the actual pseuco file
      input.getHighlighter().removeAllHighlights();
    }
View Full Code Here


  }

  private void updateHighlights() {
    removeHighlights();

    Highlighter h = textComponent.getHighlighter();
    ArrayList<Span> spellErrors = new ArrayList();
    ArrayList<Span> grammarErrors = new ArrayList();

    for (Span span : documentSpans) {
      if (span.start == span.end) {
        continue;
      }
      if (span.spelling) {
        spellErrors.add(span);
      } else {
        grammarErrors.add(span);
      }
    }



    for (Span span : grammarErrors) {
      try {
        h.addHighlight(span.start, span.end, bhp);
      } catch (BadLocationException ex) {
        //Tools.showError(ex);
      }
    }
    for (Span span : spellErrors) {
      try {
        h.addHighlight(span.start, span.end, rhp);
      } catch (BadLocationException ex) {
        //Tools.showError(ex);
      }
    }
  }
View Full Code Here

        findAndHighlight(pattern, highlighter);
    }

    public void setHighlightedLine(int pos) {
        try {
            Highlighter h = this.getTextComponent().getHighlighter();
            int start = this.getTextComponent().getLineStartOffset(pos);
            int end = this.getTextComponent().getLineEndOffset(pos);
            h.addHighlight(start, end, highlighter);
        } catch (BadLocationException ex) {
            Logger.getLogger(TextHighlighter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here

        }
    }

    private void findAndHighlight(String pattern, Highlighter.HighlightPainter highlighter) {
        try {
            Highlighter hilite = this.getTextComponent().getHighlighter();
            Document doc = this.getTextComponent().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(), highlighter);
                pos += pattern.length();
            }
        } catch (BadLocationException e) {
        }
    }
View Full Code Here

    /**
     * Remove the defined highlights
     */
    public void removeHighlights() {
        Highlighter hilite = this.getTextComponent().getHighlighter();
        Highlighter.Highlight[] hilites = hilite.getHighlights();
        for (int i = 0; i < hilites.length; i++) {
            if (hilites[i].getPainter() instanceof UnderlineHighlighter) {
                hilite.removeHighlight(hilites[i]);
            }
        }
    }
View Full Code Here

      if (dic == null || loc == null) {
        return;
      }
      final Tokenizer tok = new Tokenizer(jText, dic, loc, i, j, options);
      String word;
      final Highlighter highlighter = jText.getHighlighter();
      while ((word = tok.nextInvalidWord()) != null) {
        final int wordOffset = tok.getWordOffset();
        highlighter.addHighlight(wordOffset, wordOffset + word.length(), painter);
      }
    }
    catch (final BadLocationException e) {
      e.printStackTrace();
    }
View Full Code Here

  private void removeHighlighters(final javax.swing.text.Element element) {
      {
        final int i = element.getStartOffset();
        final int j = element.getEndOffset();
        final Highlighter highlighter = jText.getHighlighter();
        final Highlight[] highlights = highlighter.getHighlights();
        for (int k = highlights.length; --k >= 0;) {
          final Highlight highlight = highlights[k];
          final int hlStartOffset = highlight.getStartOffset();
          final int hlEndOffset = highlight.getEndOffset();
          if ((i <= hlStartOffset && hlStartOffset <= j) || (i <= hlEndOffset && hlEndOffset <= j)) {
            if (highlight.getPainter() == painter) {
              highlighter.removeHighlight(highlight);
            }
          }
        }
      }
    }
View Full Code Here

    removeHighlights();
   
    // use a default highlight painter with color Yellow to mark the words
    // in the text view
    DefaultHighlightPainter painter = new DefaultHighlightPainter(Color.YELLOW);
    Highlighter highlighter = _editorPane.getHighlighter();
   
    for(WordPosition pos : positions) {
     
      try {
       
        if (pos.getEndPosition() > Integer.MAX_VALUE)
          break;
       
        highlighter.addHighlight((int) pos.getStartPosition(),
                 (int) pos.getEndPosition(), painter);
       
      } catch (BadLocationException e) {
      }
    }
View Full Code Here

   *
   * @author andreas.gerlach
   */
  void removeHighlights() {
   
    Highlighter highlighter = _editorPane.getHighlighter();
    highlighter.removeAllHighlights();
  }
View Full Code Here

   * @see #markAll
   * @see #getMarkAllHighlightColor
   * @see #setMarkAllHighlightColor
   */
  public void clearMarkAllHighlights() {
    Highlighter h = getHighlighter();
    if (h!=null && markAllHighlights!=null) {
      int count = markAllHighlights.size();
      for (int i=0; i<count; i++)
        h.removeHighlight(markAllHighlights.get(i));
      markAllHighlights.clear();
    }
    markedWord = null;
    repaint();
  }
View Full Code Here

TOP

Related Classes of javax.swing.text.Highlighter$HighlightPainter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.