11 package net.sf.gridarta.textedit.textarea.actions;
13 import java.awt.Toolkit;
14 import java.awt.datatransfer.DataFlavor;
15 import java.awt.datatransfer.Transferable;
16 import java.awt.datatransfer.UnsupportedFlavorException;
17 import java.awt.event.ActionEvent;
18 import java.awt.event.ActionListener;
19 import java.io.BufferedReader;
20 import java.io.IOException;
21 import javax.swing.text.BadLocationException;
24 import org.apache.log4j.Category;
25 import org.apache.log4j.Logger;
31 public class Paste implements ActionListener {
36 private static final Category
LOG = Logger.getLogger(
Paste.class);
45 final StringBuilder buff =
new StringBuilder();
48 final Transferable trans = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(textArea);
51 final DataFlavor dataFlavor =
new DataFlavor(
"text/plain; charset=unicode");
52 try (BufferedReader bufferedReader =
new BufferedReader(dataFlavor.getReaderForText(trans))) {
56 final String line = bufferedReader.readLine();
70 if (selectedText != null && !selectedText.isEmpty()) {
75 }
catch (
final ClassNotFoundException ex) {
76 LOG.error(
"syntax.InputHandler: Paste action failed due to ClassNotFoundException");
77 }
catch (
final UnsupportedFlavorException ex) {
78 LOG.error(
"syntax.InputHandler: Paste action failed because clipboard data flavour is not supported.");
79 }
catch (
final IOException ex) {
80 LOG.error(
"syntax.InputHandler: Paste action failed due to IOException");
81 }
catch (
final BadLocationException ex) {
82 LOG.error(
"syntax.InputHandler: Paste action failed due to BadLocationException");
83 }
catch (
final NullPointerException ex) {
void setSelectedText(@NotNull final String selectedText)
Replaces the selection with the specified text.
Action listener for PASTE actions.
void actionPerformed(final ActionEvent e)
Get content of the system clipboard and insert it at caret position.
An input handler converts the user's key strokes into concrete actions.
Base package of all Gridarta classes.
String getSelectedText()
Returns the selected text, or null if no selection is active.
This package contains the other part of the script editor.
int getCaretPosition()
Returns the caret position.
Document getDocument()
Returns the document this text area is editing.
static JEditTextArea getTextArea(final EventObject evt)
Returns the text area that fired the specified event.
static final Category LOG
The Logger for printing log messages.
jEdit's text area component.