Package javax.swing.text

Examples of javax.swing.text.Highlighter


//        // First remove all old highlights
//        removeHighlights(textComp);
   
        try {
            String pattern = highlight.getPatron();
            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(), highlight);
                pos += pattern.length();
            }
        } catch (BadLocationException e) {
        }
    }
View Full Code Here


    }
   
   
//  Removes only our private highlights
    public void removeHighlights(JTextComponent textComp) {
        Highlighter hilite = textComp.getHighlighter();
        Highlighter.Highlight[] hilites = hilite.getHighlights();
   
        for (int i=0; i<hilites.length; i++) {
            if (hilites[i].getPainter() instanceof MyHighlightPainter) {
                hilite.removeHighlight(hilites[i]);
            }
        }
    }
View Full Code Here

        textPane = _textPane;
    }

    public void selectPosition(int apos, int epos) {
        textPane.setCaretPosition(apos);
        Highlighter hl = textPane.getHighlighter();

        try {
            if (lastMarkierung != null) {
                hl.removeHighlight(lastMarkierung);
            }
            lastMarkierung = hl.addHighlight(apos, epos, DefaultHighlighter.DefaultPainter);
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    }
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

   * @see #getMarkAllHighlightColor
   * @see #setMarkAllHighlightColor
   */
  public int markAll(String toMark, boolean matchCase, boolean wholeWord,
          boolean regex) {
    Highlighter h = getHighlighter();
    int numMarked = 0;
    if (toMark!=null && !toMark.equals(markedWord) && h!=null) {
      if (markAllHighlights!=null)
        clearMarkAllHighlights();
      else
        markAllHighlights = new ArrayList(10);
      int caretPos = getCaretPosition();
      markedWord = toMark;
      setCaretPosition(0);
      boolean found = SearchEngine.find(this, toMark, true, matchCase,
                    wholeWord, regex);
      while (found) {
        int start = getSelectionStart();
        int end = getSelectionEnd();
        try {
          markAllHighlights.add(h.addHighlight(start, end,
                    markAllHighlightPainter));
        } catch (BadLocationException ble) {
          ble.printStackTrace();
        }
        numMarked++;
View Full Code Here

            return linkPos != -1 ? doc.getCharacterElement(linkPos) : null;
        }

        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) {
            }
View Full Code Here

            } catch (final BadLocationException e) {
            }
        }

        static void removeHighlight(final JEditorPane editor) {
            Highlighter highlighter = editor.getHighlighter();
            Object tag = highlightTags.get(highlighter);
            if (tag != null) {
                highlighter.removeHighlight(tag);
                highlightTags.remove(highlighter);
            }
        }
View Full Code Here

       
        final Document doc = document;
       
        readLock(doc);
        try {
            Highlighter highlighter = component.getHighlighter();
            Caret caret = component.getCaret();
            if (component.isOpaque()) {
                paintBackground(g);
            }
            if (highlighter != null) {
                highlighter.paint(g);
            }
            Rectangle visibleRect = getVisibleEditorRect();
            if (visibleRect != null) {
                getRootView().setSize(visibleRect.width, visibleRect.height);
                getRootView().paint(g, visibleRect);
View Full Code Here

       
       
       
        // TODO change layered highlight painting code
        JTextComponent tc = (JTextComponent)getContainer();
        Highlighter hl = tc.getHighlighter();
        if (hl instanceof LayeredHighlighter) {
            ((LayeredHighlighter)hl).paintLayeredHighlights(g,
                                                            getStartOffset(),
                                                            getEndOffset(),
                                                            shape, tc, this);
View Full Code Here

       
        errorOffsets.add(offset);
        sidePanel.repaint();
               
        try {
            Highlighter highlighter = getEditor().getHighlighter();
            highlighter.addHighlight(offset.getStartOffset(), offset.getEndOffset(), new ErrorUnderlineHighlightPainter());
           
        } catch (BadLocationException ex) {
            throw new IllegalStateException("bad location adding highlight");
        }
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.Highlighter

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.