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);
47 final Transferable trans = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(textArea);
50 final DataFlavor dataFlavor =
new DataFlavor(
"text/plain; charset=unicode");
51 final StringBuilder buff =
new StringBuilder();
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) {