Java Code Examples for javax.swing.JEditorPane#addCaretListener()

The following examples show how to use javax.swing.JEditorPane#addCaretListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ASTBrowserTopComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private ASTNode getCurrentRootNode () {
    Node[] ns = TopComponent.getRegistry ().getActivatedNodes ();
    if (ns.length != 1) return null;
    EditorCookie editorCookie = ns [0].getLookup ().
        lookup (EditorCookie.class);
    if (editorCookie == null) return null;
    if (editorCookie.getOpenedPanes () == null) return null;
    if (editorCookie.getOpenedPanes ().length < 1) return null;
    JEditorPane pane = editorCookie.getOpenedPanes () [0];
    if (caretListener == null)
        caretListener = new CListener ();
    if (lastPane != null && lastPane != pane) {
        lastPane.removeCaretListener (caretListener);
        lastPane = null;
    }
    if (lastPane == null) {
        pane.addCaretListener (caretListener);
        lastPane = pane;
    }
    Document document = editorCookie.getDocument ();
    if (document == null || !(document instanceof NbEditorDocument)) return null;
    return ParserManagerImpl.getImpl (document).getAST ();
}
 
Example 2
Source File: LineNumberBorder.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new <code>LineNumberBorder</code>.
 *
 * @param scrollPane The scroll pane using this border as the viewport
 *                   border.
 * @param editorPane The text component for which line numbers will be
 *                 displayed.
 * @param numberColor The color to use for the line numbers.  If
 *                    <code>null</code>, a default is used.
 */
public LineNumberBorder(JScrollPane scrollPane, JEditorPane editorPane,
		Color numberColor) {
	this.editorPane = editorPane;
	this.scrollPane = scrollPane;

	setForeground(numberColor != null ? numberColor : DEFAULT_FOREGROUND);
	Color bg = editorPane.getBackground();
	setBackground(bg == null ? Color.WHITE : bg);

	editorPane.addCaretListener(this);
	editorPane.addPropertyChangeListener(this);
	scrollPane.getViewport().addChangeListener(this);
	editorPane.getDocument().addDocumentListener(this);

	currentLine = 1;

	setFont(null); // default font.
	insets = new Insets(0, 0, 0, 0);

	updateCellHeights();
	updateCellWidths();
}
 
Example 3
Source File: LineNumbersRuler.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void install(final JEditorPane editor) {
    this.editor = editor;

    setFont(editor.getFont());

    // setMinimumDisplayDigits(3);
    editor.getDocument().addDocumentListener(this);
    editor.addCaretListener(this);
    editor.addPropertyChangeListener(this);
    JScrollPane sp = getScrollPane(editor);
    sp.setRowHeaderView(this);
    mouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            GotoLineDialog.showForEditor(editor);
        }
    };
    addMouseListener(mouseListener);
    status = Status.INSTALLING;
}
 
Example 4
Source File: StyledEditorKit.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 5
Source File: StyledEditorKit.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 6
Source File: StyledEditorKit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 7
Source File: StyledEditorKit.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 8
Source File: StyledEditorKit.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 9
Source File: StyledEditorKit.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 10
Source File: StyledEditorKit.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 11
Source File: StyledEditorKit.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 12
Source File: StyledEditorKit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 13
Source File: StyledEditorKit.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 14
Source File: StyledEditorKit.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 15
Source File: LanguagesEditorKit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void install (JEditorPane c) {
    super.install (c);
    HyperlinkListener hl = new HyperlinkListener ();
    c.addMouseMotionListener (hl);
    c.addMouseListener (hl);
    c.addKeyListener(hl);
    c.addCaretListener (new MarkOccurrencesSupport (c));
}
 
Example 16
Source File: StyledEditorKit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 17
Source File: StyledEditorKit.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 18
Source File: StyledEditorKit.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 19
Source File: StyledEditorKit.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}
 
Example 20
Source File: StyledEditorKit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when the kit is being installed into
 * a JEditorPane.
 *
 * @param c the JEditorPane
 */
public void install(JEditorPane c) {
    c.addCaretListener(inputAttributeUpdater);
    c.addPropertyChangeListener(inputAttributeUpdater);
    Caret caret = c.getCaret();
    if (caret != null) {
        inputAttributeUpdater.updateInputAttributes
                              (caret.getDot(), caret.getMark(), c);
    }
}