Java JTextComponent currentLineChanged(final JTextComponent c)

Here you can find the source of currentLineChanged(final JTextComponent c)

Description

Fetches the previous caret location, stores the current caret location.

License

LGPL

Parameter

Parameter Description
c the text component

Declaration

private static void currentLineChanged(final JTextComponent c) 

Method Source Code

//package com.java2s;
/* This file is part of the project "Hilbert II" - http://www.qedeq.org
 *
 * The main author is Santhosh Kumar T. Visit his great home page under:
 * http://www.jroller.com/santhosh//*from ww w  . j a v  a2 s .c o  m*/
 *
 * The original source for this file is:
 * http://www.jroller.com/santhosh/entry/currentlinehighlighter_contd
 *
 * It is distributed under the GNU Lesser General Public License:
 * http://www.gnu.org/copyleft/lesser.html
 */

import java.awt.Rectangle;

import javax.swing.text.BadLocationException;

import javax.swing.text.JTextComponent;

public class Main {
    /** NOI18N - used as client property. */
    private static final String PREVIOUS_CARET = "previousCaret";

    /**
     * Fetches the previous caret location, stores the current caret location. If the caret is on
     * another line, repaint the previous line and the current line
     *
     * @param c the text component
     */
    private static void currentLineChanged(final JTextComponent c) {
        if (null == c.getClientProperty(PREVIOUS_CARET)) {
            return;
        }
        try {
            final int previousCaret = ((Integer) c.getClientProperty(PREVIOUS_CARET)).intValue();
            final Rectangle prev = c.modelToView(previousCaret);
            final Rectangle r = c.modelToView(c.getCaretPosition());
            c.putClientProperty(PREVIOUS_CARET, new Integer(c.getCaretPosition()));

            if (prev.y != r.y) {
                c.repaint(0, prev.y, c.getWidth(), r.height);
                c.repaint(0, r.y, c.getWidth(), r.height);
            }
        } catch (final BadLocationException ignore) {
            // ignore
        }
    }
}

Related

  1. adjustForLineComment(JTextComponent editor, int iStart)
  2. appendToText(JTextComponent textComp, String s)
  3. applyDefaultProperties(final JTextComponent comp)
  4. biggestFont(final javax.swing.text.JTextComponent c)
  5. clear(JTextComponent... fields)
  6. enableJTextField(JTextComponent component, boolean enable, Color color)
  7. ensureCustomBackgroundStored(JTextComponent comp)
  8. ensureCustomBackgroundStored(JTextComponent comp)
  9. fillWith(String value, JTextComponent... fields)