Package javax.swing.text

Examples of javax.swing.text.Highlighter$Highlight


    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

  protected final void highlight(JTextComponent comp, int i, int j) {
    highlight(comp, i, j, true);
  }

  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));
        }
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

    public void paint(final Graphics g, final Shape shape) {
        Rectangle rc = shape.getBounds();

        // 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

    int dot = tc.getCaretPosition();
    int selStart = tc.getSelectionStart()-1; // Workaround for Java Highlight issues.
    Highlight currentPrev = null;
    int pos = 0;
    Highlighter h = tc.getHighlighter();
    Highlight[] highlights = h.getHighlights();
    for (int i=0; i<highlights.length; i++) {
      Highlight hl = highlights[i];
      if (hl.getPainter()==p) { // Only way to identify our own highlights
        if (currentPrev==null || currentPrev.getStartOffset()>=dot ||
            (hl.getStartOffset()<selStart &&
View Full Code Here

  /**
   * Removes the bounding boxes around parameters.
   */
  private void removeParameterHighlights() {
    JTextComponent tc = ac.getTextComponent();
    Highlighter h = tc.getHighlighter();
    for (int i=0; i<tags.size(); i++) {
      h.removeHighlight(tags.get(i));
    }
    tags.clear();
  }
View Full Code Here

      int paramCount = pc.getParamCount();
      List paramLocs = null;
      if (paramCount>0) {
        paramLocs = new ArrayList(paramCount);
      }
      Highlighter h = tc.getHighlighter();

      try {

        // Get the range in which the caret can move before we hide
        // this tooltip.
        minPos = dot;
        maxPos = tc.getDocument().createPosition(dot-sb.length());
        int firstParamLen = 0;

        // Create the text to insert (keep it one completion for
        // performance and simplicity of undo/redo).
        int start = dot;
        for (int i=0; i<paramCount; i++) {
          FunctionCompletion.Parameter param = pc.getParam(i);
          String paramText = getParamText(param);
          if (i==0) {
            firstParamLen = paramText.length();
          }
          sb.append(paramText);
          int end = start + paramText.length();
          paramLocs.add(new Point(start, end));
          if (i<paramCount-1) {
            sb.append(pc.getProvider().getParameterListSeparator());
            start = end + 2;
          }
        }
        sb.append(pc.getProvider().getParameterListEnd());

        // Insert the parameter text and add highlights around the
        // parameters.
        tc.replaceSelection(sb.toString());
        for (int i=0; i<paramCount; i++) {
          Point pt = (Point)paramLocs.get(i);
           // "-1" is a workaround for Java Highlight issues.
          tags.add(h.addHighlight(pt.x-1, pt.y, p));
        }

        // Go back and start at the first parameter.
        tc.setCaretPosition(dot);
        if (pc.getParamCount()>0) {
View Full Code Here

TOP

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

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.