Example usage for javax.swing.text JTextComponent getToolkit

List of usage examples for javax.swing.text JTextComponent getToolkit

Introduction

In this page you can find the example usage for javax.swing.text JTextComponent getToolkit.

Prototype

public Toolkit getToolkit() 

Source Link

Document

Gets the toolkit of this component.

Usage

From source file:net.sf.jabref.gui.keyboard.EmacsKeyBindings.java

private static void doCopyOrCut(JTextComponent jtc, boolean copy) {
    if (jtc != null) {
        int caretPosition = jtc.getCaretPosition();
        String text = jtc.getSelectedText();
        if (text != null) {
            // user has manually marked a text without using CTRL+W
            // we obey that selection and copy it.
        } else if (SetMarkCommandAction.isMarked(jtc)) {
            int beginPos = caretPosition;
            int endPos = SetMarkCommandAction.getCaretPosition();
            if (beginPos > endPos) {
                int tmp = endPos;
                endPos = beginPos;//from w  ww .  j  a  v a 2s. c o  m
                beginPos = tmp;
            }
            jtc.select(beginPos, endPos);
            SetMarkCommandAction.reset();
        }
        text = jtc.getSelectedText();
        if (text == null) {
            jtc.getToolkit().beep();
        } else {
            if (copy) {
                jtc.copy();
                // clear the selection
                jtc.select(caretPosition, caretPosition);
            } else {
                int newCaretPos = jtc.getSelectionStart();
                jtc.cut();
                // put the cursor to the beginning of the text to cut
                jtc.setCaretPosition(newCaretPos);
            }
            KillRing.getInstance().add(text);
        }
    }
}