Package javax.swing.text

Examples of javax.swing.text.Highlighter


            // First remove all old highlights
            removeHighlights(textComp);
        }

        try {
            final Highlighter hilite = textComp.getHighlighter();
            final Document doc = textComp.getDocument();
            String text = doc.getText(0, doc.getLength());
            if( matchAnyCase ) {
                text = text.toLowerCase();
            }
            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(), myHighlightPainter);
                pos += pattern.length();
            }
        } catch (final BadLocationException e) {
        }
    }
View Full Code Here


            // First remove all old highlights
            removeHighlights(textComp);
        }

        try {
            final Highlighter hilite = textComp.getHighlighter();
            hilite.addHighlight(pos, pos+len, myHighlightPainter);
        } catch (final BadLocationException e) {
        }
    }
View Full Code Here

        }
    }

    // Removes only our private highlights
    public void removeHighlights(final JTextComponent textComp) {
        final Highlighter hilite = textComp.getHighlighter();
        final Highlighter.Highlight[] hilites = hilite.getHighlights();

        for( final Highlight element : hilites ) {
            if (element.getPainter() instanceof MyHighlightPainter) {
                hilite.removeHighlight(element);
            }
        }
    }
View Full Code Here

      highlight(m.template, r.a, r.b);
    }
  }

  protected void highlight(JTextComponent comp, int i, int j) {
    Highlighter highlighter = comp.getHighlighter();
    highlighter.removeAllHighlights();

    try {
      highlighter.addHighlight(i, j+1, DefaultHighlighter.DefaultPainter);
    }
    catch (BadLocationException ble) {
      errMgr.internalError(tmodel.root.event.scope.st, "bad highlight location", ble);
    }
  }
View Full Code Here

    MyHighlightPainter myHighlightPainter = new MyHighlightPainter(Color.yellow);
   
    removeHighlights(textComp);
    if (pattern.length() > 0)
      try {
        Highlighter hilite = textComp.getHighlighter();
        Document doc = textComp.getDocument();
        String text = doc.getText(0, doc.getLength());
        text = text.toUpperCase();
        pattern = pattern.toUpperCase();
        int pos = textComp.getCaretPosition();
        if ((pos = text.indexOf(pattern, pos)) != -1)
          if (findAll == 0) {
            hilite.addHighlight(pos, pos + pattern.length(), myHighlightPainter);
            textComp.setCaretPosition(pos + pattern.length());
            textComp.setSelectionStart(pos);
            textComp.setSelectionEnd(pos + pattern.length());
          } else {
            for (; (pos = text.indexOf(pattern, pos)) >= 0; pos += pattern.length())
              hilite.addHighlight(pos, pos + pattern.length(), myHighlightPainter);

          }
      } catch (BadLocationException badlocationexception) {
      }
  }
View Full Code Here

  }

  private static void removeHighlights(JTextComponent textComp) {
    @SuppressWarnings("unused")
    MyHighlightPainter myHighlightPainter = new MyHighlightPainter(Color.yellow);
    Highlighter hilite = textComp.getHighlighter();
    javax.swing.text.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

        if (textToHighlight.equals("")) {
            return;
        }

        // remove previous higlights
        Highlighter highlighter = editorPane.getHighlighter();
        highlighter.removeAllHighlights();

        // get the text desplayed on the pane
        String text = "";
        Document doc = editorPane.getDocument();
        try {
            text = doc.getText(0, doc.getLength()).toLowerCase();
        } catch (BadLocationException e1) {
            Debug.error(e1);
            return;
        }

        // find the indexes of the given text in the document
        ArrayList<Integer> result = indexesOf(text, textToHighlight);

        // set the highlights depending on the indexies has been found
        for (Iterator iter = result.iterator(); iter.hasNext();) {
            Integer element = (Integer) iter.next();
            try {
                highlighter.addHighlight(element.intValue(), element.intValue() + textToHighlight.length(), new DefaultHighlighter.DefaultHighlightPainter(Color.yellow));
            } catch (BadLocationException e) {
                Debug.error(e);
            }
        }
    }
View Full Code Here

    public void testGetComponent() {
        assertEquals(jta, ((BasicTextUI) jta.getUI()).getComponent());
    }

    public void testCreateHighlighter() {
        Highlighter highlighter = basicTextUI.createHighlighter();
        assertTrue(highlighter instanceof BasicTextUI.BasicHighlighter);
    }
View Full Code Here

        new javax.swing.JTextPane().updateUI();           
    }

    public void testInstallUI() throws Exception {
        Caret caret = jta.getCaret();
        Highlighter highlighter = jta.getHighlighter();
        String prefix = ((BasicTextUI) tf.getUI()).getPropertyPrefix();
        (jta.getUI()).uninstallUI(jta);
        TextUI ui = jta.getUI();
        assertTrue(ui instanceof TextAreaUI);
        TextAreaUI.callOrder = "";
View Full Code Here

        assertTrue(caret instanceof DefaultCaret);
        assertTrue(caret instanceof UIResource);
    }

    public void testBasicHighlighter() {
        Highlighter highlighter = new BasicTextUI.BasicHighlighter();
        assertTrue(highlighter instanceof DefaultHighlighter);
        assertTrue(highlighter instanceof UIResource);
    }
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.